-
Notifications
You must be signed in to change notification settings - Fork 30
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
Fix gh-1769 - setting shape by a scalar #1786
Conversation
Modify shape.setter to handle integers. ``` In [1]: import dpctl.tensor as dpt In [2]: x = dpt.ones((2, 3)) In [3]: x.shape = 6 In [4]: x Out[4]: usm_ndarray([1., 1., 1., 1., 1., 1.], dtype=float32) In [5]: x = dpt.ones((2, 3)) In [6]: class Six: ...: def __init__(self, dim=1): ...: self.v = (1,) * (dim - 1) + (6,) ...: def __len__(self): ...: return len(self.v) ...: def __iter__(self): ...: return iter(self.v) ...: In [7]: x.shape = Six(3) In [8]: x.shape Out[8]: (1, 1, 6) ```
Replaced uses of np.prod with math.prod.
Deleted rendered PR docs from intelpython.github.com/dpctl, latest should be updated shortly. 🤞 |
Array API standard conformance tests for dpctl=0.18.0dev0=py310ha798474_240 ran successfully. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not work for -1, where NumPy does
In [2]: x = dpt.arange(100, dtype="i4")
In [3]: x.shape = -1
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[3], line 1
----> 1 x.shape = -1
File ~/repos/dpctl/dpctl/tensor/_usmarray.pyx:592, in dpctl.tensor._usmarray.usm_ndarray.shape.__set__()
590 size = shape_to_elem_count(self.nd_, self.shape_)
591 if not np.prod(new_shape) == size:
--> 592 raise TypeError(
593 f"Can not reshape array of size {self.size} into {new_shape}"
594 )
TypeError: Can not reshape array of size 100 into (-1,)
I added a docstring to document limitations of |
Array API standard conformance tests for dpctl=0.18.0dev0=py310ha798474_252 ran successfully. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dpnp scope of tests passed with the change. Thank you @oleksandr-pavlyk
This PR resolves gh-1769
shape setter now accepts integer values.