Skip to content

dpt.astype returns wrong result on boolean view of numpy.ndarray #2121

@antonwolfy

Description

@antonwolfy

Here is example with unexpected behavior:

import dpctl, dpctl.tensor as dpt, numpy

dpctl.__version__
# Out: '0.21.0dev0+49.g5be8ef909c'

a = numpy.array([0, 3, 1, 2, 0, 1], dtype='u1')
a_view = a.view('?')

# create a view from numpy.ndarray
b = numpy.array(a_view)
b
# Out: array([False,  True,  True,  True, False,  True])

dpt_b = dpt.asarray(a_view)
dpt_b  # the same as b
# Out: usm_ndarray([False,  True,  True,  True, False,  True])

# cast to integer dtype
numpy.astype(b, int)
# Out: array([0, 1, 1, 1, 0, 1])

# the result is unexpected, since True and False have to casted to 0 and 1 only
dpt.astype(dpt_b, int)
# Out: usm_ndarray([0, 3, 1, 2, 0, 1])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions