Skip to content

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

Description

@vtavana

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_

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions