Skip to content

Support numpy size() and array.size - #1777

Merged
certik merged 4 commits into
lcompilers:mainfrom
ubaidsk:numpy_size
May 11, 2023
Merged

Support numpy size() and array.size#1777
certik merged 4 commits into
lcompilers:mainfrom
ubaidsk:numpy_size

Conversation

@ubaidsk

Copy link
Copy Markdown
Collaborator

fixes#1773

@ubaidsk
ubaidsk marked this pull request as draft May 11, 2023 00:26
@ubaidskubaidsk changed the title Support numpy array.sizeSupport numpy size and array.sizeMay 11, 2023
@ubaidsk
ubaidsk marked this pull request as ready for review May 11, 2023 00:58
@ubaidsk
ubaidsk requested a review from certikMay 11, 2023 00:58
@ubaidskubaidsk changed the title Support numpy size and array.sizeSupport numpy size() and array.sizeMay 11, 2023
@ubaidsk

Copy link
Copy Markdown
CollaboratorAuthor

This is ready.

@certikcertik left a comment

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.

Thank you! This PR is good to merge.

Since we are doing it, in a new PR can you also please add a test like:

from numpy import size
a = empty((2, 3))
assert size(a) == 2*3
assert size(a, 0) == 2
assert size(a, 1) == 3

It will probably already work, but just in case. I usually use the size function like this, just like in Fortran.

@certik
certik merged commit ff38f75 into lcompilers:mainMay 11, 2023
@ubaidsk
ubaidsk deleted the numpy_size branch May 11, 2023 14:36
@ubaidskubaidsk mentioned this pull request May 11, 2023
@ubaidsk

Copy link
Copy Markdown
CollaboratorAuthor

Since we are doing it, in a new PR can you also please add a test like:

Sure, thank you for the guidance. It seems the backends expect dimension value to start from 1, where as the axis attribute of numpy size() starts from 0. I fixed it by adding a constant 1 to the user provided dimension and added the test case in #1780.

Sign up for freeto 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.

Implement numpy.size()

2 participants

@ubaidsk@certik