Skip to content

add support for order=None in dpnp.einsum #2411

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

Merged
merged 2 commits into from
Apr 9, 2025
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* The vector norms `ord={None, 1, 2, inf}` and the matrix norms `ord={None, 1, 2, inf, "fro", "nuc"}` now consistently return zero for empty arrays, which are arrays with at least one axis of size zero. This change affects `dpnp.linalg.norm`, `dpnp.linalg.vector_norm`, and `dpnp.linalg.matrix_norm`. Previously, dpnp would either raise errors or return zero depending on the parameters provided [#2371](https://github.com/IntelPython/dpnp/pull/2371)
* Extended `dpnp.fft.fftfreq` and `dpnp.fft.rfftfreq` functions to support `dtype` keyword per Python Array API spec 2024.12 [#2384](https://github.com/IntelPython/dpnp/pull/2384)
* Updated `dpnp.fix` to return output with the same data-type of input [#2392](https://github.com/IntelPython/dpnp/pull/2392)
* Updated `dpnp.einsum` to add support for `order=None` [#2411](https://github.com/IntelPython/dpnp/pull/2411)

### Fixed

Expand Down
5 changes: 3 additions & 2 deletions dpnp/dpnp_iface_linearalgebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,13 @@ def einsum(
If provided, forces the calculation to use the data type specified.

Default: ``None``.
order : {"C", "F", "A", "K"}, optional
order : {None, "C", "F", "A", "K"}, optional
Controls the memory layout of the output. ``"C"`` means it should be
C-contiguous. ``"F"`` means it should be F-contiguous, ``"A"`` means
it should be ``"F"`` if the inputs are all ``"F"``, ``"C"`` otherwise.
``"K"`` means it should be as close to the layout as the inputs as
is possible, including arbitrarily permuted axes.
is possible, including arbitrarily permuted axes. ``order=None`` is
equivalent to ``order="K"``.

Default: ``"K"``.
casting : {"no", "equiv", "safe", "same_kind", "unsafe"}, optional
Expand Down
2 changes: 1 addition & 1 deletion dpnp/dpnp_utils/dpnp_utils_einsum.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ def dpnp_einsum(
)
arrays.append(operands[id])
result_dtype = dpnp.result_type(*arrays) if dtype is None else dtype
if order in "aA":
if order is not None and order in "aA":
order = "F" if all(arr.flags.fnc for arr in arrays) else "C"

input_subscripts = [
Expand Down
4 changes: 4 additions & 0 deletions dpnp/tests/test_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,10 @@ def test_output_order(self):
assert tmp.flags.c_contiguous is False
assert tmp.flags.f_contiguous is False

tmp = dpnp.einsum("...ft,mf->...mt", a, b, order=None, optimize=opt)
assert tmp.flags.c_contiguous is False
assert tmp.flags.f_contiguous is False

tmp = dpnp.einsum("...ft,mf->...mt", a, b, optimize=opt)
assert tmp.flags.c_contiguous is False
assert tmp.flags.f_contiguous is False
Expand Down
Loading