Skip to content

Implementation of squeeze function #790

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

Merged
merged 2 commits into from
Mar 16, 2022
Merged

Implementation of squeeze function #790

merged 2 commits into from
Mar 16, 2022

Conversation

vlad-perevezentsev
Copy link
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
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

"which has size not equal to one."
)
else:
new_shape = [axis for axis in X_shape if axis != 1]
Copy link
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
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).

if new_shape == X.shape:
return X
else:
return dpt.reshape(X, tuple(new_shape))
Copy link
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
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

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