Skip to content

Implementation of squeeze function#790

Merged
oleksandr-pavlyk merged 2 commits intomasterfrom
squeeze
Mar 16, 2022
Merged

Implementation of squeeze function#790
oleksandr-pavlyk merged 2 commits intomasterfrom
squeeze

Conversation

@vlad-perevezentsev
Copy link
Copy Markdown
Collaborator

This PR adds squeeze functions according to Python array API standard for usm_ndarray.

)
else:
new_shape = [axis for axis in X_shape if axis != 1]
if new_shape == X.shape:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since new_shape is of type list, and X.shape is of type tuple the comparison is always going to return False:

In [1]: x = (1,2,3)

In [2]: y = list(x)

In [3]: y == x
Out[3]: False

@github-actions
Copy link
Copy Markdown

Comment thread dpctl/tensor/_manipulation_functions.py Outdated
"which has size not equal to one."
)
else:
new_shape = [axis for axis in X_shape if axis != 1]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
new_shape = [axis for axis in X_shape if axis != 1]
new_shape = tuple(axis for axis in X_shape if axis != 1)

raise ValueError(
"Cannot select an axis to squeeze out "
"which has size not equal to one."
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the conclusion of iteration, add the line new_shape = tuple(new_shape).

Comment thread dpctl/tensor/_manipulation_functions.py Outdated
if new_shape == X.shape:
return X
else:
return dpt.reshape(X, tuple(new_shape))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming the earlier changes to ensure new_shape has type of tuple, the tuple(new_shape) becomes redundant, and can be replaced with value new_shape to avoid extra copy.

@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Mar 13, 2022

Coverage Status

Coverage increased (+0.07%) to 81.766% when pulling 31a960b on squeeze into e30e7a4 on master.

@oleksandr-pavlyk oleksandr-pavlyk merged commit aa7071f into master Mar 16, 2022
@oleksandr-pavlyk oleksandr-pavlyk deleted the squeeze branch March 16, 2022 15:22
@github-actions
Copy link
Copy Markdown

Deleted rendered PR docs from intelpython.github.com/dpctl, latest should be updated shortly. 🤞

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

Successfully merging this pull request may close these issues.

3 participants