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.pow() with dtype=c16 and scalar on gpu/cpu returns different result #1378

Open
vlad-perevezentsev opened this issue Aug 28, 2023 · 2 comments

Comments

@vlad-perevezentsev
Copy link
Collaborator

vlad-perevezentsev commented Aug 28, 2023

The below example works differently depending on the device:

import dpctl.tensor as dpt

a = dpt.asarray([0], dtype='c16', device='gpu')
dpt.pow(a,1)
# usm_ndarray([0.+0.j])

a = dpt.asarray([0], dtype='c16', device='cpu')
dpt.pow(a,1)
# usm_ndarray([nan+nanj])

with dtype = 'c8' returns the same result for different devices

import dpctl.tensor as dpt

a = dpt.asarray([0], dtype='c8',device='gpu')
dpt.pow(a ,1)
# usm_ndarray([0.+0.j], dtype=complex64)

a = dpt.asarray([0], dtype='c8',device='cpu')
dpt.pow(a,1)
# usm_ndarray([0.+0.j], dtype=complex64)


I also noticed that dpt.pow works correctly when the input array size is between 2 and 7 for dtype c16.

import dpctl.tensor as dpt


a = dpt.zeros((2,), dtype='c16', device='cpu')
dpt.pow(a,1)
# usm_ndarray([0.+0.j, 0.+0.j])

a = dpt.zeros((7,), dtype='c16', device='cpu')
dpt.pow(a,1)
# usm_ndarray([0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j])


a = dpt.zeros((8,), dtype='c16', device='cpu')
dpt.pow(a,1)
# usm_ndarray([ 0. +0.j,  0. +0.j,  0. +0.j,  0. +0.j, nan+nanj, nan+nanj,
             nan+nanj, nan+nanj])


Besides this there is an interesting case when x2 (scalar) is numpy dtype
Then dpt.pow with input array with data type c8 returns nans too

import dpctl.tensor as dpt
import numpy

a = dpt.zeros((8,), dtype='c8', device='cpu')
dpt.pow(a, 1)
# usm_ndarray([0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j,
             0.+0.j], dtype=complex64)

dpt.pow(a, numpy.int32(1))
# usm_ndarray([ 0. +0.j,  0. +0.j,  0. +0.j,  0. +0.j, nan+nanj, nan+nanj,
             nan+nanj, nan+nanj])

@ndgrigorian
Copy link
Collaborator

ndgrigorian commented Nov 23, 2023

@vlad-perevezentsev
These discrepancies seem to have been resolved recently.

In [1]: import dpctl.tensor as dpt, numpy as np

In [2]: a = dpt.asarray([0], dtype='c16', device='cpu')

In [3]: dpt.pow(a,1)
Out[3]: usm_ndarray([0.+0.j])

In [4]: a = dpt.zeros((2,), dtype='c16', device='cpu')

In [5]: dpt.pow(a,1)
Out[5]: usm_ndarray([0.+0.j, 0.+0.j])

In [6]: a = dpt.zeros((8,), dtype='c16', device='cpu')

In [7]: dpt.pow(a,1)
Out[7]:
usm_ndarray([0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j,
             0.+0.j])

For the Numpy dtype case:

In [1]: import dpctl.tensor as dpt, numpy as np

In [2]: a = dpt.zeros((8,), dtype='c8', device='cpu')

In [3]: dpt.pow(a, np.int32(1))
Out[3]:
usm_ndarray([0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j,
             0.+0.j])

It's hard to know if it was a result of #1411 or the change in compiler version.

Either way, if you can confirm that these issues are resolved for you as well, we can consider this issue resolved.

@oleksandr-pavlyk
Copy link
Collaborator

@vlad-perevezentsev I think this issue is ready to be resolved

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

3 participants