Skip to content

Commit 6c3dd68

Browse files
authored
[OpenVINO backend] Support arctan2, pass the NumpyDtypeTest::arctan2 test (keras-team#20928)
* pass NumpyDtypeTest::arctan2 and add some test cases in NumpyTwoInputOpsCorrectnessTest::arctan2 * newly add NumpyDtypeTest::test_arctan2
1 parent 4197645 commit 6c3dd68

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

keras/src/backend/openvino/excluded_concrete_tests.txt

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ NumpyDtypeTest::test_add_
77
NumpyDtypeTest::test_all
88
NumpyDtypeTest::test_any
99
NumpyDtypeTest::test_append_
10-
NumpyDtypeTest::test_arctan2_
1110
NumpyDtypeTest::test_argmax
1211
NumpyDtypeTest::test_argmin
1312
NumpyDtypeTest::test_argpartition

keras/src/backend/openvino/numpy.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,13 @@ def arctan(x):
272272
def arctan2(x1, x2):
273273
x1 = get_ov_output(x1)
274274
x2 = get_ov_output(x2)
275-
x1_type = x1.get_element_type()
276-
x2_type = x2.get_element_type()
277275

278-
if x1_type.is_integral():
279-
ov_type = OPENVINO_DTYPES[config.floatx()]
280-
x1 = ov_opset.convert(x1, ov_type)
281-
if x2_type.is_integral():
282-
ov_type = OPENVINO_DTYPES[config.floatx()]
283-
x2 = ov_opset.convert(x2, ov_type)
276+
x1_type = ov_to_keras_type(x1.get_element_type())
277+
x2_type = ov_to_keras_type(x2.get_element_type())
278+
result_type = dtypes.result_type(x1_type, x2_type, float)
279+
result_type = OPENVINO_DTYPES[result_type]
280+
x1 = ov_opset.convert(x1, result_type)
281+
x2 = ov_opset.convert(x2, result_type)
284282

285283
x = ov_opset.divide(x1, x2)
286284
y = ov_opset.atan(x)

keras/src/ops/numpy_test.py

+12
Original file line numberDiff line numberDiff line change
@@ -2449,6 +2449,18 @@ def test_arctan2(self):
24492449

24502450
self.assertAllClose(knp.Arctan2()(x, y), np.arctan2(x, y))
24512451

2452+
a = np.array([0.0, 0.0, 0.0, 1.0, 1.0, -1.0, -1.0, 1.0, -1.0])
2453+
b = np.array([0.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 0.0, 0.0])
2454+
2455+
self.assertAllClose(knp.arctan2(a, b), np.arctan2(a, b))
2456+
self.assertAllClose(knp.Arctan2()(a, b), np.arctan2(a, b))
2457+
2458+
m = np.array([[3, 4], [7, 8]], dtype=np.int8)
2459+
n = np.array([[1, 2], [3, 4]], dtype=float)
2460+
2461+
self.assertAllClose(knp.arctan2(m, n), np.arctan2(m, n))
2462+
self.assertAllClose(knp.Arctan2()(m, n), np.arctan2(m, n))
2463+
24522464
def test_bitwise_and(self):
24532465
x = np.array([2, 5, 255])
24542466
y = np.array([3, 14, 16])

0 commit comments

Comments
 (0)