-
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
moveaxis extension #5609
Merged
Merged
moveaxis extension #5609
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cdd53f3
moveaxis_extension
ac812b1
changes
bc2b190
added container and array methods
091bd12
changes
19f3fae
changed flatten to moveaxis
4f9789f
Update extensions.py
Ishticode b5a885a
Update extensions.py
Ishticode 5da5787
Merge branch 'master' into moveaxis_extension
nassimberrada 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# global | ||
from typing import Optional, Union, List, Dict, Tuple | ||
from typing import Optional, Union, List, Dict, Tuple, Sequence | ||
|
||
# local | ||
import ivy | ||
|
@@ -493,3 +493,109 @@ def max_pool2d( | |
map_sequences=map_sequences, | ||
out=out, | ||
) | ||
|
||
@staticmethod | ||
def static_moveaxis( | ||
a: Union[ivy.Array, ivy.NativeArray, ivy.Container], | ||
source: Union[int, Sequence[int]], | ||
destination: Union[int, Sequence[int]], | ||
/, | ||
*, | ||
key_chains: Optional[Union[List[str], Dict[str, str]]] = None, | ||
to_apply: bool = True, | ||
prune_unapplied: bool = False, | ||
map_sequences: bool = False, | ||
out: Optional[ivy.Container] = None, | ||
) -> ivy.Container: | ||
""" | ||
ivy.Container static method variant of ivy.moveaxis. This method simply wraps | ||
the function, and so the docstring for ivy.moveaxis also applies to this method | ||
with minimal changes. | ||
|
||
Parameters | ||
---------- | ||
a | ||
The container with the arrays whose axes should be reordered. | ||
source | ||
Original positions of the axes to move. These must be unique. | ||
destination | ||
Destination positions for each of the original axes. | ||
These must also be unique. | ||
out | ||
optional output container, for writing the result to. | ||
|
||
Returns | ||
------- | ||
ret | ||
Container including arrays with moved axes. | ||
|
||
Examples | ||
-------- | ||
With one :class:`ivy.Container` input: | ||
|
||
>>> x = ivy.Container(a=ivy.zeros((3, 4, 5)), b=ivy.zeros((2,7,6))) | ||
>>> ivy.static_moveaxis(x, 0, -1).shape | ||
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.
|
||
|
||
{ | ||
a: (4, 5, 3) | ||
b: (7, 6, 2) | ||
} | ||
""" | ||
return ContainerBase.multi_map_in_static_method( | ||
"moveaxis", | ||
a, | ||
source, | ||
destination, | ||
key_chains=key_chains, | ||
to_apply=to_apply, | ||
prune_unapplied=prune_unapplied, | ||
map_sequences=map_sequences, | ||
out=out, | ||
) | ||
|
||
def moveaxis( | ||
self: ivy.Container, | ||
source: Union[int, Sequence[int]], | ||
destination: Union[int, Sequence[int]], | ||
/, | ||
*, | ||
out: Optional[ivy.Container] = None, | ||
) -> ivy.Container: | ||
"""ivy.Container instance method variant of ivy.moveaxis. This method simply | ||
wraps the function, and so the docstring for ivy.flatten also applies to this | ||
method with minimal changes. | ||
|
||
Parameters | ||
---------- | ||
self | ||
The container with the arrays whose axes should be reordered. | ||
source | ||
Original positions of the axes to move. These must be unique. | ||
destination | ||
Destination positions for each of the original axes. | ||
These must also be unique. | ||
out | ||
optional output container, for writing the result to. | ||
|
||
Returns | ||
------- | ||
ret | ||
Container including arrays with moved axes. | ||
|
||
Examples | ||
-------- | ||
With one :class:`ivy.Container` input: | ||
|
||
>>> x = ivy.Container(a=ivy.zeros((3, 4, 5)), b=ivy.zeros((2,7,6))) | ||
>>> ivy.moveaxis(x, 0, -1).shape | ||
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. x.moveaxis(0,-1).shape here |
||
|
||
{ | ||
a: (4, 5, 3) | ||
b: (7, 6, 2) | ||
} | ||
""" | ||
return self.static_moveaxis( | ||
self, | ||
source, | ||
destination, | ||
out=out) |
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
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.
This is supposed to be
ivy.moveaxis