-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add out
and where
args for ht.div
#945
Merged
ClaudiaComito
merged 16 commits into
helmholtz-analytics:main
from
neosunhan:features/870-divide-kwargs
Apr 22, 2022
Merged
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1b865c9
Add out and where args for ht.div
neosunhan ecb28cc
Merge branch 'helmholtz-analytics:main' into features/870-divide-kwargs
neosunhan 2755448
Add out and where args for ht.div
neosunhan 28dcca7
Merge branch 'features/870-divide-kwargs' of https://github.com/neosu…
neosunhan 2a0c14b
Add where arg to `__binary_op`
neosunhan cecbb41
Remove unused import
neosunhan f8ed24a
Modify `__binary_op` to only create empty DNDarray when necessary
neosunhan c8b33ce
Merge branch 'main' into features/870-divide-kwargs
ClaudiaComito b673091
Update changelog for new `div` kwargs
neosunhan 03f288a
Add distributed test cases for `ht.div`
neosunhan bdeed00
Add check for distributed `where`
neosunhan 1ccbf7a
Remove duplicate test case
neosunhan 99316a6
Fix documentation for `where` arg
neosunhan a39dcb6
Update heat/core/_operations.py
ClaudiaComito 067c36e
Merge branch 'main' into features/870-divide-kwargs
ClaudiaComito 9d2926b
Merge branch 'main' into features/870-divide-kwargs
ClaudiaComito File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ def __binary_op( | |
t1: Union[DNDarray, int, float], | ||
t2: Union[DNDarray, int, float], | ||
out: Optional[DNDarray] = None, | ||
where: Optional[DNDarray] = None, | ||
fn_kwargs: Optional[Dict] = {}, | ||
) -> DNDarray: | ||
""" | ||
|
@@ -43,6 +44,8 @@ def __binary_op( | |
The second operand involved in the operation, | ||
out: DNDarray, optional | ||
Output buffer in which the result is placed | ||
where: DNDarray, optional | ||
Condition of interest, where true yield the result of the operation else yield original value in out (uninitialized when out=None) | ||
fn_kwargs: Dict, optional | ||
keyword arguments used for the given operation | ||
Default: {} (empty dictionary) | ||
|
@@ -101,6 +104,8 @@ def __binary_op( | |
|
||
# Make inputs have the same dimensionality | ||
output_shape = stride_tricks.broadcast_shape(t1.shape, t2.shape) | ||
if where is not None: | ||
output_shape = stride_tricks.broadcast_shape(where.shape, output_shape) | ||
# Broadcasting allows additional empty dimensions on the left side | ||
# TODO simplify this once newaxis-indexing is supported to get rid of the loops | ||
while len(t1.shape) < len(output_shape): | ||
|
@@ -163,23 +168,24 @@ def __get_out_params(target, other=None, map=None): | |
if out is not None: | ||
sanitation.sanitize_out(out, output_shape, output_split, output_device, output_comm) | ||
t1, t2 = sanitation.sanitize_distribution(t1, t2, target=out) | ||
out.larray[:] = operation( | ||
t1.larray.type(promoted_type), t2.larray.type(promoted_type), **fn_kwargs | ||
else: | ||
out_tensor = torch.empty(output_shape, dtype=promoted_type) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2 comments here:
and that will take care of only initializing slices of the global array on each process (I think this is also why the tests fail btw)
|
||
out = DNDarray( | ||
out_tensor, | ||
output_shape, | ||
types.heat_type_of(out_tensor), | ||
output_split, | ||
device=output_device, | ||
comm=output_comm, | ||
balanced=output_balanced, | ||
) | ||
return out | ||
# print(t1.lshape, t2.lshape) | ||
|
||
result = operation(t1.larray.type(promoted_type), t2.larray.type(promoted_type), **fn_kwargs) | ||
result = operation(t1.larray.to(promoted_type), t2.larray.to(promoted_type), **fn_kwargs) | ||
if where is not None: | ||
ClaudiaComito marked this conversation as resolved.
Show resolved
Hide resolved
|
||
result = torch.where(where.larray, result, out.larray) | ||
ClaudiaComito marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return DNDarray( | ||
result, | ||
output_shape, | ||
types.heat_type_of(result), | ||
output_split, | ||
device=output_device, | ||
comm=output_comm, | ||
balanced=output_balanced, | ||
) | ||
out.larray.copy_(result) | ||
return out | ||
|
||
|
||
def __cum_op( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use numpy's docs for
where
, I think they are a bit clearer. But we must expand on them a bit, e.g. iswhere
supposed/expected to be distributed, and how.