-
Notifications
You must be signed in to change notification settings - Fork 19.6k
Support numpy.moveaxis operation #21189
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
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #21189 +/- ##
=======================================
Coverage 82.59% 82.59%
=======================================
Files 564 564
Lines 54407 54428 +21
Branches 8449 8454 +5
=======================================
+ Hits 44936 44957 +21
Misses 7396 7396
Partials 2075 2075
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
for axis in sorted(source, reverse=True): | ||
axes.pop(axis) | ||
|
||
for dest, src in sorted(zip(destination, source)): | ||
axes.insert(dest, src) |
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 think it is more clear to code this as:
for dest, src in sorted(zip(destination, source)):
axes[dest] = src
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 dont think we can do this because this results in broken permuation
as this assumes axes already has the correct length
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.
Can you share a concrete example that shows it will not work?
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 happening because the following code assumes that the index is of equal length
but after popping the elements the length is not the same hence it results in index error if dest >= len(axes)
def moveaxis(x, source, destination):
if isinstance(source, int):
source = [source]
if isinstance(destination, int):
destination = [destination]
x = get_ov_output(x)
x_shape = x.get_partial_shape()
rank = x_shape.rank.get_length()
source = [s + rank if s < 0 else s for s in source]
destination = [d + rank if d < 0 else d for d in destination]
axes = list(range(rank))
for axis in sorted(source, reverse=True):
axes.pop(axis)
for dest, src in sorted(zip(destination, source)):
axes[dest] = src
perm = ov_opset.constant(axes, dtype=Type.i32).output(0)
x_type = x.get_element_type()
if x_type == Type.bf16:
x = ov_opset.convert(x, Type.f32).output(0)
result = ov_opset.transpose(x, perm).output(0)
return OpenVINOKerasTensor(
ov_opset.convert(result, Type.bf16).output(0)
)
return OpenVINOKerasTensor(ov_opset.transpose(x, perm).output(0))
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.
@Prabha14039, once again. Share with me a concrete example with concrete values source and destination for which my code willn't work.
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.
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.
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.
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.
Here I don't see source and destination values. Please create standlalone code that proves my code does not work.
Details
cc , @rkazants plz review