Skip to content

BUG: scalars don't have dlpack support #27137

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

Open
arogozhnikov opened this issue Aug 8, 2024 · 4 comments
Open

BUG: scalars don't have dlpack support #27137

arogozhnikov opened this issue Aug 8, 2024 · 4 comments
Labels
00 - Bug 40 - array API standard PRs and issues related to support for the array API standard
Milestone

Comments

@arogozhnikov
Copy link
Contributor

arogozhnikov commented Aug 8, 2024

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]
@ngoldbaum
Copy link
Member

Duplicate of #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.

@arogozhnikov
Copy link
Contributor Author

particular problem for me was missing dlpack functionality on scalars

@ngoldbaum ngoldbaum changed the title BUG: array api incompatibility in output of reductions (sum/prod/min/max/...) BUG: scalars don't have dlpack support Aug 8, 2024
@ngoldbaum ngoldbaum added the 40 - array API standard PRs and issues related to support for the array API standard label Aug 8, 2024
@ngoldbaum
Copy link
Member

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__?

@arogozhnikov
Copy link
Contributor Author

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.

@ngoldbaum ngoldbaum added this to the 2.2.0 release milestone Aug 29, 2024
@ngoldbaum ngoldbaum added triage review Issue/PR to be discussed at the next triage meeting and removed triage review Issue/PR to be discussed at the next triage meeting labels Aug 29, 2024
@charris charris modified the milestones: 2.2.0 release, 2.3.0 release Nov 22, 2024
@charris charris modified the milestones: 2.3.0 release, 2.4.0 release May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug 40 - array API standard PRs and issues related to support for the array API standard
Projects
None yet
Development

No branches or pull requests

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy