-
Notifications
You must be signed in to change notification settings - Fork 21
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
dpnp.linalg.vector_norm
raises exception for zero sized input array
#2319
Comments
NumPy raises a similar Error, what is the use case that you encountered it? >>> import numpy
>>> numpy.linalg.norm(numpy.zeros(0), ord=numpy.inf)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[2], line 1
----> 1 numpy.linalg.norm(numpy.zeros(0), ord=numpy.inf)
File /localdisk/work/vtavana/miniforge/envs/dpnp_2025/lib/python3.12/site-packages/numpy/linalg/_linalg.py:2765, in norm(x, ord, axis, keepdims)
2763 if len(axis) == 1:
2764 if ord == inf:
-> 2765 return abs(x).max(axis=axis, keepdims=keepdims)
2766 elif ord == -inf:
2767 return abs(x).min(axis=axis, keepdims=keepdims)
File /localdisk/work/vtavana/miniforge/envs/dpnp_2025/lib/python3.12/site-packages/numpy/_core/_methods.py:44, in _amax(a, axis, out, keepdims, initial, where)
42 def _amax(a, axis=None, out=None, keepdims=False,
43 initial=_NoValue, where=True):
---> 44 return umr_maximum(a, axis, None, out, keepdims, initial, where)
ValueError: zero-size array to reduction operation maximum which has no identity |
NumPy is going to resolve that in numpy#28343 |
vtavana
added a commit
that referenced
this issue
Mar 20, 2025
resolves #2319 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The example below with
dpnp.linalg.vector_norm
triggersValueError
exception:The text was updated successfully, but these errors were encountered: