Skip to content

This PR implements the numpy.logspace function for the OpenVINO backend as requested in issue #30114. #21266

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 10 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ examples/**/*.jpg
.python-version
.coverage
*coverage.xml
.ruff_cache
.ruff_cache
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove it

Copy link
Contributor

@rkazants rkazants May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not addressed comment

venv/
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 @@ -31,7 +31,6 @@ NumpyDtypeTest::test_isinf
NumpyDtypeTest::test_isnan
NumpyDtypeTest::test_linspace
NumpyDtypeTest::test_logaddexp
NumpyDtypeTest::test_logspace
NumpyDtypeTest::test_matmul_
NumpyDtypeTest::test_max
NumpyDtypeTest::test_mean
Expand Down Expand Up @@ -145,7 +144,6 @@ NumpyTwoInputOpsCorrectnessTest::test_divide_no_nan
NumpyTwoInputOpsCorrectnessTest::test_einsum
NumpyTwoInputOpsCorrectnessTest::test_inner
NumpyTwoInputOpsCorrectnessTest::test_linspace
NumpyTwoInputOpsCorrectnessTest::test_logspace
NumpyTwoInputOpsCorrectnessTest::test_outer
NumpyTwoInputOpsCorrectnessTest::test_quantile
NumpyTwoInputOpsCorrectnessTest::test_take_along_axis
Expand Down
58 changes: 55 additions & 3 deletions keras/src/backend/openvino/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,9 +1029,61 @@ def logical_or(x1, x2):


def logspace(start, stop, num=50, endpoint=True, base=10, dtype=None, axis=0):
raise NotImplementedError(
"`logspace` is not supported with openvino backend"
)
if dtype is not None:
ov_type = OPENVINO_DTYPES[standardize_dtype(dtype)]
else:
ov_type = OPENVINO_DTYPES[config.floatx()]

start_t = ov_opset.convert(get_ov_output(start), ov_type).output(0)
stop_t = ov_opset.convert(get_ov_output(stop), ov_type).output(0)
num_t = ov_opset.convert(get_ov_output(num), ov_type).output(0)
base_t = ov_opset.convert(get_ov_output(base), ov_type).output(0)

if isinstance(num, (int, float)):
num_value = int(num)
else:
num_value = 50

if endpoint:
one = ov_opset.constant(1, ov_type).output(0)
divisor = ov_opset.subtract(num_t, one).output(0)
else:
divisor = num_t

step_t = ov_opset.divide(
ov_opset.subtract(stop_t, start_t).output(0), divisor
).output(0)

indices_t = ov_opset.range(
ov_opset.constant(0, ov_type).output(0),
num_t,
ov_opset.constant(1, ov_type).output(0),
ov_type,
).output(0)

static_shape = start_t.get_partial_shape().to_shape()
if len(static_shape) > 0:
reshape_shape = [num_value] + [1] * len(static_shape)
indices_t = ov_opset.reshape(
indices_t,
ov_opset.constant(reshape_shape, dtype=Type.i32).output(0),
special_zero=False,
).output(0)

step_t = ov_opset.reshape(
step_t,
ov_opset.constant([1] + list(static_shape), dtype=Type.i32).output(
0
),
special_zero=False,
).output(0)

linear_t = ov_opset.add(
start_t, ov_opset.multiply(indices_t, step_t).output(0)
).output(0)
result_t = ov_opset.power(base_t, linear_t).output(0)

return OpenVINOKerasTensor(result_t)


def maximum(x1, x2):
Expand Down
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not addressed comment

env =
KERAS_BACKEND=openvino