-
Notifications
You must be signed in to change notification settings - Fork 19.6k
Add support for numpy.flip in OpenVINO backend #21132
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ NumpyDtypeTest::test_digitize | |
NumpyDtypeTest::test_einsum | ||
NumpyDtypeTest::test_exp2 | ||
NumpyDtypeTest::test_eye | ||
NumpyDtypeTest::test_flip | ||
NumpyDtypeTest::test_floor | ||
NumpyDtypeTest::test_hstack | ||
NumpyDtypeTest::test_inner | ||
|
@@ -88,6 +87,7 @@ NumpyOneInputOpsCorrectnessTest::test_cumprod | |
NumpyOneInputOpsCorrectnessTest::test_diag | ||
NumpyOneInputOpsCorrectnessTest::test_diagonal | ||
NumpyOneInputOpsCorrectnessTest::test_exp2 | ||
NumpyOneInputOpsCorrectnessTest::test_expm1 | ||
NumpyOneInputOpsCorrectnessTest::test_flip | ||
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. please remove the line with |
||
NumpyOneInputOpsCorrectnessTest::test_floor_divide | ||
NumpyOneInputOpsCorrectnessTest::test_hstack | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -715,7 +715,36 @@ def expm1(x): | |
|
||
|
||
def flip(x, axis=None): | ||
raise NotImplementedError("`flip` is not supported with openvino backend") | ||
if axis == () or axis == []: | ||
return x | ||
x = get_ov_output(x) | ||
rank = x.get_partial_shape().rank.get_length() | ||
if axis is None: | ||
axis = list(range(rank)) | ||
else: | ||
if np.isscalar(axis): | ||
axis = [axis] | ||
else: | ||
axis = list(axis) | ||
axis = [ax if ax >= 0 else ax + rank for ax in axis] | ||
shape_of_x = ov_opset.shape_of(x) | ||
for ax in sorted(axis): | ||
dim_node = ov_opset.gather( | ||
shape_of_x, | ||
ov_opset.constant(ax, Type.i64).output(0), | ||
ov_opset.constant(0, Type.i64).output(0), | ||
).output(0) | ||
start = ov_opset.subtract( | ||
dim_node, ov_opset.constant(1, Type.i64).output(0) | ||
).output(0) | ||
stop = ov_opset.constant(-1, Type.i64).output(0) | ||
step = ov_opset.constant(-1, Type.i64).output(0) | ||
|
||
reversed_indices = ov_opset.range(start, stop, step, Type.i64).output(0) | ||
x = ov_opset.gather( | ||
x, reversed_indices, ov_opset.constant(ax, Type.i64).output(0) | ||
).output(0) | ||
Comment on lines
+743
to
+746
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. it looks not optimal. We have special op for reversing a tensor along required axis. Check 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. Hi @rkazants , Thank you for your patience! |
||
return OpenVINOKerasTensor(x) | ||
|
||
|
||
def floor(x): | ||
|
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.
please revert this change that is not related to PR