Skip to content

Commit c949e75

Browse files
authored
Implementation np.outer function (#21270)
* Implementation np.outer function in path: keras\src\backend\openvino\numpy.py * fix np.outer error: Accessing out-of-range dimension * fix np.outer error: Accessing out-of-range dimension * fix format errors * fix not request changes * fix Suggested changes in outer method * delete comment
1 parent cf08b92 commit c949e75

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

keras/src/backend/openvino/excluded_concrete_tests.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ NumpyDtypeTest::test_median
3939
NumpyDtypeTest::test_meshgrid
4040
NumpyDtypeTest::test_minimum_python_types
4141
NumpyDtypeTest::test_multiply
42-
NumpyDtypeTest::test_outer_
4342
NumpyDtypeTest::test_power
4443
NumpyDtypeTest::test_prod
4544
NumpyDtypeTest::test_quantile
@@ -143,7 +142,6 @@ NumpyTwoInputOpsCorrectnessTest::test_einsum
143142
NumpyTwoInputOpsCorrectnessTest::test_inner
144143
NumpyTwoInputOpsCorrectnessTest::test_linspace
145144
NumpyTwoInputOpsCorrectnessTest::test_logspace
146-
NumpyTwoInputOpsCorrectnessTest::test_outer
147145
NumpyTwoInputOpsCorrectnessTest::test_quantile
148146
NumpyTwoInputOpsCorrectnessTest::test_take_along_axis
149147
NumpyTwoInputOpsCorrectnessTest::test_tensordot

keras/src/backend/openvino/numpy.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,21 @@ def ones_like(x, dtype=None):
12111211

12121212

12131213
def outer(x1, x2):
1214-
raise NotImplementedError("`outer` is not supported with openvino backend")
1214+
x1 = get_ov_output(x1)
1215+
x2 = get_ov_output(x2)
1216+
1217+
x1, x2 = _align_operand_types(x1, x2, "outer()")
1218+
1219+
new_shape_x1 = ov_opset.constant([-1, 1], Type.i32).output(0)
1220+
new_shape_x2 = ov_opset.constant([1, -1], Type.i32).output(0)
1221+
1222+
# Reshape directly from original tensors
1223+
x1_reshaped = ov_opset.reshape(x1, new_shape_x1, False).output(0)
1224+
x2_reshaped = ov_opset.reshape(x2, new_shape_x2, False).output(0)
1225+
1226+
result = ov_opset.multiply(x1_reshaped, x2_reshaped).output(0)
1227+
1228+
return OpenVINOKerasTensor(result)
12151229

12161230

12171231
def pad(x, pad_width, mode="constant", constant_values=None):

0 commit comments

Comments
 (0)