BUG: scalars don't have dlpack support
Describe the issue:
reduction (e.g. xp.sum) are expected to produce arrays, but in numpy they produce scalars, that don't follow array api specifications (e.g. I can't use dlpack on those).
In numpy v1, np.array_api correctly returned arrays in this case
Reproduce the code example:
import numpy as np
x = np.zeros([3, 4])
type(x.__array_namespace__().sum(x))
# outputs: numpy.float64 expected: numpy.ndarray
Python and NumPy Versions:
2.0.1
3.11.9 (main, Apr 6 2024, 17:59:24) [GCC 11.4.0]
Duplicate of https://github.com/numpy/numpy/issues/26850. Is there any particular you're problem with getting a scalar here? If it's a duck typing issue we should fix the issue in the scalars like in that issue.
particular problem for me was missing dlpack functionality on scalars
Maybe we could add a __dlpack__ implementation (in C) to the scalars that converts to a 0-D array and delegates to the ndarray __dlpack__?
That's maintainers' decision.
From my user perspective I was quite happy that array api removes different corner cases in favor of uniformity (e.g. returning arrays), but I have no insight about potential performance issues.