Skip to content
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

dpt.sum returns incorrect result when dtype=dpt.bool is passed #1944

Open
vtavana opened this issue Dec 20, 2024 · 0 comments
Open

dpt.sum returns incorrect result when dtype=dpt.bool is passed #1944

vtavana opened this issue Dec 20, 2024 · 0 comments

Comments

@vtavana
Copy link
Collaborator

vtavana commented Dec 20, 2024

Python Array API for sum function states:

If the data type (either specified or resolved) differs from the data type of x, the input array should be cast to the specified data type before computing the sum ...

With this in mind, dpctl does not behave correct

import dpctl.tensor as dpt
a = dpt.asarray([-1, 1], dtype=dpt.int32)
dpt.sum(a)
# usm_ndarray(0)
dpt.sum(a, dtype=dpt.bool)
# usm_ndarray(False)

# However what array API is specifying is 
dpt.sum(dpt.astype(a, dpt.bool), dtype=dpt.bool)
# usm_ndarray(True)


# NumPy follows Array API
import numpy
numpy.__version__
# '2.2.0'

b = numpy.zeros(2, dtype=numpy.int32)
b.sum()
# np.int64(0)
b.sum(dtype=numpy.bool_)
# np.False_
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

No branches or pull requests

1 participant