Repository navigation
Deprecate dpnp.dot when a.ndim >= 2 and b.ndim > 2 - #3124
Merged
Merged
Conversation
`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
requested review from
ndgrigorian and
vlad-perevezentsev
as code owners
October 25, 2026 11:42
Contributor
|
View rendered docs @ https://intelpython.github.io/dpnp/index.html |
Collaborator
ndgrigorian
approved these changes
Oct 26, 2026
Contributor
|
Array API standard conformance tests for dpnp=0.21.0dev16=np2py314h8d9cdd5_12 ran successfully. |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For inputs where
ahas 2 or more dimensions andbhas more than 2 dimensions,dpnp.dotanddpnp.ndarray.dotplace the leading dimensions ofbin the middle of the result, unlikedpnp.matmul. NumPy 2.6 deprecates this case, and this PR mirrors that deprecation.The result is unchanged, but the call now emits:
Only that case warns. 0-D, 1-D and 2-D inputs, a 1-D
awith an N-Db, and an N-Dawith a 1-D or 2-Dbbehave as before. As in NumPy, the warning comes after shape validation, so a shape mismatch raisesValueErrorwithout a warning.The implementation moves into a private
_dot, which bothdpnp.dotanddpnp.ndarray.dotcall directly. This way the warning points to the user's line for the method as well; otherwise it would be attributed todpnp_array.py, and Python's default warning filters would hide it.The
dpnp.dotdocstring gets a "Warnings" section, and the 4-D example is removed.