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

Incorrect behavior of dpctl.tensor.all and dpctl.tensor.any with axis=0 parameter #1327

Closed
vlad-perevezentsev opened this issue Aug 7, 2023 · 0 comments · Fixed by #1329
Closed
Assignees
Labels
bug Something isn't working

Comments

@vlad-perevezentsev
Copy link
Collaborator

The dpctl.tensor.all function returns an incorrect result with the parameter axis=0 and dimension >=3 of the input ndarray.

Running on GPU

import dpctl.tensor as dpt
import numpy

a = numpy.arange(24).reshape(2, 3, 4) - 10

a.dtype
>dtype('int64')

dpt_a = dpt.asarray(a)

numpy.all(a,axis=0)
>array([[ True,  True,  True,  True],
        [ True,  True,  True,  True],
        [ True,  True, False,  True]])

dpt.all(dpt_a,axis=0)
>usm_ndarray([[ True, False, False, False],
              [False, False, False, False],
              [False, False, False, False]])

# at the same for dtype=int32

# floating types and boolean work correctly 

a = a.astype('float32')
dpt_a = dpt.asarray(a)

numpy.all(a,axis=0)
>array([[ True,  True,  True,  True],
        [ True,  True,  True,  True],
        [ True,  True, False,  True]])

dpt.all(dpt_a,axis=0)
>usm_ndarray([[ True,  True,  True,  True],
              [ True,  True,  True,  True],
              [ True,  True,  True,  True]])

Running on CPU for integer and floating types throws Segmentation fault
for boolean type incorrect result

import dpctl.tensor as dpt
import numpy

a = numpy.arange(24).reshape(2, 3, 4) - 10
dpt_a = dpt.asarray(a)
dpt.all(dpt_a,axis=0)
> Segmentation fault

dpt_a = dpt.astype(dpt_a, 'float32')
dpt.all(dpt_a,axis=0)
> Segmentation fault

dpt_a = dpt.astype(dpt_a, 'bool')
> usm_ndarray([[ True,  True,  True,  True],
              [ True,  True,  True,  True],
              [False, False,  True, False]])


# for ndim<3 works

a = numpy.arange(6).reshape(2, 3) - 4
dpt_a = dpt.asarray(a)
dpt.all(dpt_a,axis=0)
> usm_ndarray([ True, False,  True])

The dpctl.tensor.any function does not work on CPU (Segmentation fault) with the parameter axis=0 and dimension >=3 of the input ndarray for all dtypes.

import dpctl.tensor as dpt

dpt_a = dpt.ones((2, 3, 4))
dpt.any(dpt_a,axis=0)
Segmentation fault (core dumped)

@vlad-perevezentsev vlad-perevezentsev added the bug Something isn't working label Aug 7, 2023
ndgrigorian added a commit that referenced this issue Aug 8, 2023
ndgrigorian added a commit that referenced this issue Aug 8, 2023
* Resolves #1327 by fixing a typo in the boolean reduction Python binding

* Adds a test for #1327
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants