Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 0 additions & 1 deletion keras/src/backend/openvino/excluded_concrete_tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ NumpyOneInputOpsCorrectnessTest::test_var
NumpyOneInputOpsCorrectnessTest::test_vectorize
NumpyOneInputOpsCorrectnessTest::test_vstack
NumpyTwoInputOpsCorrectnessTest::test_append
NumpyTwoInputOpsCorrectnessTest::test_arctan2
NumpyTwoInputOpsCorrectnessTest::test_bitwise_and
NumpyTwoInputOpsCorrectnessTest::test_bitwise_left_shift
NumpyTwoInputOpsCorrectnessTest::test_bitwise_or
Expand Down
40 changes: 38 additions & 2 deletions keras/src/backend/openvino/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,46 @@ def arctan(x):


def arctan2(x1, x2):
raise NotImplementedError(
"`arctan2` is not supported with openvino backend"
x1 = get_ov_output(x1)
x2 = get_ov_output(x2)
x1_type = x1.get_element_type()
x2_type = x2.get_element_type()

if x1_type.is_integral():
ov_type = OPENVINO_DTYPES[config.floatx()]
x1 = ov_opset.convert(x1, ov_type)
if x2_type.is_integral():
ov_type = OPENVINO_DTYPES[config.floatx()]
x2 = ov_opset.convert(x2, ov_type)

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

ov_type = x1.get_element_type()
pi = ov_opset.constant(float(np.pi), ov_type)
half_pi = ov_opset.constant(float(np.pi / 2), ov_type)
neg_half_pi = ov_opset.constant(-float(np.pi / 2), ov_type)
zero_const = ov_opset.constant(0.0, ov_type)

cond_x2_gt0 = ov_opset.greater(x2, zero_const).output(0)
cond_x2_lt0 = ov_opset.less(x2, zero_const).output(0)

cond_x1_ge0 = ov_opset.greater_equal(x1, zero_const).output(0)
cond_x1_gt0 = ov_opset.greater(x1, zero_const).output(0)

out_x2_lt0 = ov_opset.select(
cond_x1_ge0,
ov_opset.add(y, pi),
ov_opset.subtract(y, pi),
)

out_x2_zero = ov_opset.select(cond_x1_gt0, half_pi, neg_half_pi)

out_not_pos = ov_opset.select(cond_x2_lt0, out_x2_lt0, out_x2_zero)

final_out = ov_opset.select(cond_x2_gt0, y, out_not_pos)
return OpenVINOKerasTensor(final_out.output(0))


def arctanh(x):
x = get_ov_output(x)
Expand Down