Skip to content

Deprecate dpnp.dot when a.ndim >= 2 and b.ndim > 2 - #3124

Merged
antonwolfy merged 2 commits into
masterfrom
deprecate-dot-nd-interleave
Oct 28, 2026
Merged

antonwolfy merged 2 commits into
masterfrom
deprecate-dot-nd-interleave

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

For inputs where a has 2 or more dimensions and b has more than 2 dimensions, dpnp.dot and dpnp.ndarray.dot place the leading dimensions of b in the middle of the result, unlike dpnp.matmul. NumPy 2.6 deprecates this case, and this PR mirrors that deprecation.

a = dpnp.ones((2, 3))
b = dpnp.ones((4, 3, 5))

dpnp.dot(a, b).shape                        # (2, 4, 5), now emits DeprecationWarning
dpnp.tensordot(a, b, axes=(-1, -2)).shape   # (2, 4, 5), same result
dpnp.matmul(a, b).shape                     # (4, 2, 5), batched matrix product

The result is unchanged, but the call now emits:

dpnp.dot received arrays with a.ndim >= 2 and b.ndim > 2. This places the leading dimensions of b in the middle of the result, which is deprecated and will eventually raise an error. Use dpnp.tensordot(a, b, axes=(-1, -2)) instead.

Only that case warns. 0-D, 1-D and 2-D inputs, a 1-D a with an N-D b, and an N-D a with a 1-D or 2-D b behave as before. As in NumPy, the warning comes after shape validation, so a shape mismatch raises ValueError without a warning.

The implementation moves into a private _dot, which both dpnp.dot and dpnp.ndarray.dot call directly. This way the warning points to the user's line for the method as well; otherwise it would be attributed to dpnp_array.py, and Python's default warning filters would hide it.

The dpnp.dot docstring gets a "Warnings" section, and the 4-D example is removed.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • Have you added documentation for your changes, if necessary?
  • Have you added your changes to the changelog?

`dpnp.dot` and `dpnp.ndarray.dot` place the leading dimensions of `b` in
the middle of the result for such inputs. Emit a `DeprecationWarning`
pointing to `dpnp.tensordot(a, b, axes=(-1, -2))`, aligning with NumPy 2.6.

The implementation moves into a private `_dot` shared by the function and
the method, so the warning points to the user's call for both.
@antonwolfy antonwolfy added this to the 0.22.0 release milestone Oct 25, 2026
@antonwolfy antonwolfy self-assigned this Oct 25, 2026
@github-actions

github-actions Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/index.html

@coveralls

coveralls commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 82.643% (+0.02%) from 82.627% — deprecate-dot-nd-interleave into master

@github-actions

Copy link
Copy Markdown
Contributor

Array API standard conformance tests for dpnp=0.21.0dev16=np2py314h8d9cdd5_12 ran successfully.
Passed: 1491
Failed: 0
Skipped: 6

@antonwolfy
antonwolfy merged commit 7175968 into master Oct 28, 2026
110 of 112 checks passed
@antonwolfy
antonwolfy deleted the deprecate-dot-nd-interleave branch October 28, 2026 12:57
github-actions Bot added a commit that referenced this pull request Oct 28, 2026
For inputs where `a` has 2 or more dimensions and `b` has more than 2
dimensions, `dpnp.dot` and `dpnp.ndarray.dot` place the leading
dimensions of `b` in the middle of the result, unlike `dpnp.matmul`.
NumPy 2.6 deprecates this case, and this PR mirrors that deprecation.

```python
a = dpnp.ones((2, 3))
b = dpnp.ones((4, 3, 5))

dpnp.dot(a, b).shape                        # (2, 4, 5), now emits DeprecationWarning
dpnp.tensordot(a, b, axes=(-1, -2)).shape   # (2, 4, 5), same result
dpnp.matmul(a, b).shape                     # (4, 2, 5), batched matrix product
```

The result is unchanged, but the call now emits:
```
dpnp.dot received arrays with a.ndim >= 2 and b.ndim > 2. This places the leading dimensions of b in the middle of the result, which is deprecated and will eventually raise an error. Use dpnp.tensordot(a, b, axes=(-1, -2)) instead.
```

Only that case warns. 0-D, 1-D and 2-D inputs, a 1-D `a` with an N-D
`b`, and an N-D `a` with a 1-D or 2-D `b` behave as before. As in NumPy,
the warning comes after shape validation, so a shape mismatch raises
`ValueError` without a warning.

The implementation moves into a private `_dot`, which both `dpnp.dot`
and `dpnp.ndarray.dot` call directly. This way the warning points to the
user's line for the method as well; otherwise it would be attributed to
`dpnp_array.py`, and Python's default warning filters would hide it.

The `dpnp.dot` docstring gets a "Warnings" section, and the 4-D example
is removed. 7175968
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants