Skip to content

Implementation np.moveaxis function #21269

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions keras/src/backend/openvino/excluded_concrete_tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ NumpyDtypeTest::test_mean
NumpyDtypeTest::test_median
NumpyDtypeTest::test_meshgrid
NumpyDtypeTest::test_minimum_python_types
NumpyDtypeTest::test_moveaxis
NumpyDtypeTest::test_multiply
NumpyDtypeTest::test_outer_
NumpyDtypeTest::test_power
Expand Down Expand Up @@ -96,7 +95,6 @@ NumpyOneInputOpsCorrectnessTest::test_max
NumpyOneInputOpsCorrectnessTest::test_mean
NumpyOneInputOpsCorrectnessTest::test_median
NumpyOneInputOpsCorrectnessTest::test_meshgrid
NumpyOneInputOpsCorrectnessTest::test_moveaxis
NumpyOneInputOpsCorrectnessTest::test_pad_float16_constant_2
NumpyOneInputOpsCorrectnessTest::test_pad_float32_constant_2
NumpyOneInputOpsCorrectnessTest::test_pad_float64_constant_2
Expand Down
20 changes: 17 additions & 3 deletions keras/src/backend/openvino/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,9 +1109,23 @@ def mod(x1, x2):


def moveaxis(x, source, destination):
raise NotImplementedError(
"`moveaxis` is not supported with openvino backend"
)
x = get_ov_output(x)
if isinstance(source, int):
source = [source]
if isinstance(destination, int):
destination = [destination]

ndim = x.get_partial_shape().rank.get_length()
source = [axis if axis >= 0 else axis + ndim for axis in source]
destination = [axis if axis >= 0 else axis + ndim for axis in destination]

axes = list(range(ndim))
for src, dst in zip(source, destination):
axes.remove(src)
axes.insert(dst, src)

axes_const = ov_opset.constant(axes, Type.i32).output(0)
return OpenVINOKerasTensor(ov_opset.transpose(x, axes_const).output(0))


def nan_to_num(x, nan=0.0, posinf=None, neginf=None):
Expand Down