-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Added nanprod to ivy experimental API #21198
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7eea4f5
Added nanprod to all backends, ivy array and container and also added…
BebehCodes 1f7a5b1
Merge remote-tracking branch 'upstream/master' into feature/nanprod
BebehCodes 627402c
Merge remote-tracking branch 'upstream/main' into feature/nanprod
BebehCodes cf5f14a
Fixed typos in container docstrings
BebehCodes 5dc99bc
Added more examples of usage in docstrings
BebehCodes 848cb3c
Fix for corner cases in testing bfloat16 type
BebehCodes ca0fe3b
Fix for torch's half precision on cpu
BebehCodes 7122c01
Fix for result inaccuracies in paddle and torch
BebehCodes 480a1d3
Removed changes in paddle to_numpy and handled case in function testing
BebehCodes 637be02
Merge remote-tracking branch 'upstream/main' into feature/nanprod
BebehCodes 271c0b1
Added supported dtypes decorator for paddle. Also fixed some type che…
BebehCodes 946c5ce
Merge remote-tracking branch 'upstream/main' into feature/nanprod
BebehCodes b0aef6f
Added initial argument and strategy
BebehCodes 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
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 |
---|---|---|
|
@@ -443,6 +443,140 @@ def nanmean( | |
self, axis=axis, keepdims=keepdims, dtype=dtype, out=out | ||
) | ||
|
||
@staticmethod | ||
def static_nanprod( | ||
input: ivy.Container, | ||
/, | ||
*, | ||
axis: Optional[Union[Tuple[int], int, ivy.Container]] = None, | ||
dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype, ivy.Container]] = None, | ||
keepdims: Optional[Union[bool, ivy.Container]] = False, | ||
key_chains: Optional[Union[List[str], Dict[str, str], ivy.Container]] = None, | ||
to_apply: Union[bool, ivy.Container] = True, | ||
prune_unapplied: Union[bool, ivy.Container] = False, | ||
map_sequences: Union[bool, ivy.Container] = False, | ||
out: Optional[Union[ivy.Array, ivy.Container]] = None, | ||
initial: Optional[Union[int, float, complex, ivy.Container]] = 1, | ||
where: Optional[Union[ivy.Array, ivy.Container]] = None, | ||
) -> ivy.Container: | ||
""" | ||
ivy.Container static method variant of ivy.nanprod. This method simply wraps the | ||
function, and so the docstring for ivy.nanprod also applies to this method with | ||
minimal changes. | ||
|
||
Parameters | ||
---------- | ||
input | ||
Input container including arrays. | ||
axis | ||
Axis or axes along which the product is computed. | ||
The default is to compute the product of the flattened array. | ||
dtype | ||
The desired data type of returned array. Default is None. | ||
out | ||
optional output array, for writing the result to. | ||
keepdims | ||
If this is set to True, the axes which are reduced are left in the result | ||
as dimensions with size one. With this option, the result will broadcast | ||
correctly against the original a. | ||
initial | ||
The starting value for this product. | ||
where | ||
Elements to include in the product | ||
|
||
Returns | ||
------- | ||
ret | ||
The product of array elements over a given axis treating | ||
Not a Numbers (NaNs) as ones | ||
|
||
Examples | ||
-------- | ||
>>> a = ivy.Container(x=ivy.array([[1, 2], [3, ivy.nan]]),\ | ||
y=ivy.array([[ivy.nan, 1, 2], [1, 2, 3]]) | ||
>>> ivy.Container.static_moveaxis(a) | ||
{ | ||
x: 12.0 | ||
y: 12.0 | ||
} | ||
""" | ||
return ContainerBase.cont_multi_map_in_function( | ||
"nanprod", | ||
input, | ||
axis=axis, | ||
keepdims=keepdims, | ||
dtype=dtype, | ||
key_chains=key_chains, | ||
to_apply=to_apply, | ||
prune_unapplied=prune_unapplied, | ||
map_sequences=map_sequences, | ||
out=out, | ||
initial=initial, | ||
where=where, | ||
) | ||
|
||
def nanprod( | ||
self: ivy.Container, | ||
/, | ||
*, | ||
axis: Optional[Union[Tuple[int], int, ivy.Container]] = None, | ||
dtype: Optional[Union[ivy.Dtype, ivy.NativeDtype, ivy.Container]] = None, | ||
keepdims: Optional[Union[bool, ivy.Container]] = False, | ||
out: Optional[ivy.Container] = None, | ||
initial: Optional[Union[int, float, complex, ivy.Container]] = None, | ||
where: Optional[Union[ivy.Array, ivy.Container]] = None, | ||
) -> ivy.Container: | ||
""" | ||
ivy.Container instance method variant of ivy.nanprod. This method simply wraps | ||
the function, and so the docstring for ivy.nanprod also applies to this method | ||
with minimal changes. | ||
|
||
Parameters | ||
---------- | ||
self | ||
Input container including arrays. | ||
axis | ||
Axis or axes along which the product is computed. | ||
The default is to compute the product of the flattened array. | ||
dtype | ||
The desired data type of returned array. Default is None. | ||
out | ||
optional output array, for writing the result to. | ||
keepdims | ||
If this is set to True, the axes which are reduced are left in the result | ||
as dimensions with size one. With this option, the result will broadcast | ||
correctly against the original a. | ||
initial | ||
The starting value for this product. | ||
where | ||
Elements to include in the product | ||
|
||
Returns | ||
------- | ||
ret | ||
The product of array elements over a given axis treating | ||
Not a Numbers (NaNs) as ones | ||
|
||
Examples | ||
-------- | ||
>>> a = ivy.Container(x=ivy.array([[1, 2], [3, ivy.nan]]),\ | ||
y=ivy.array([[ivy.nan, 1, 2], [1, 2, 3]]) | ||
>>> ivy.Container.static_moveaxis(a) | ||
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. Likewise. Also this should be |
||
{ | ||
x: 12.0 | ||
y: 12.0 | ||
} | ||
""" | ||
return self.static_nanprod( | ||
self, | ||
axis=axis, | ||
keepdims=keepdims, | ||
dtype=dtype, | ||
out=out, | ||
initial=initial, | ||
where=where, | ||
) | ||
|
||
@staticmethod | ||
def static_quantile( | ||
a: Union[ivy.Container, ivy.Array, ivy.NativeArray], | ||
|
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
I assume you mean
static_nanprod
, careful when copying examples from other functions