Fix gh-1769 - setting shape by a scalar#1786
Merged
oleksandr-pavlyk merged 3 commits intomasterfrom Aug 6, 2024
Merged
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. |
Collaborator
ndgrigorian
reviewed
Aug 6, 2024
Collaborator
ndgrigorian
left a comment
There was a problem hiding this comment.
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,)
Contributor
Author
|
I added a docstring to document limitations of |
|
Array API standard conformance tests for dpctl=0.18.0dev0=py310ha798474_252 ran successfully. |
antonwolfy
approved these changes
Aug 6, 2024
Collaborator
antonwolfy
left a comment
There was a problem hiding this comment.
The dpnp scope of tests passed with the change. Thank you @oleksandr-pavlyk
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR resolves gh-1769
shape setter now accepts integer values.