Skip to content

ENH: allow single input argument in numpy.broadcast - #6905

Merged
jaimefrio merged 3 commits into
numpy:masterfrom
kohr-h:issue-6899__broadcast_with_one_arg
Jan 6, 2016
Merged

jaimefrio merged 3 commits into
numpy:masterfrom
kohr-h:issue-6899__broadcast_with_one_arg

Conversation

@kohr-h

@kohr-h kohr-h commented Dec 30, 2015

Copy link
Copy Markdown
Contributor

Fixes #6899. The documentation does not mention any restriction, so I guess there is no need to adapt it?

@jaimefrio

Copy link
Copy Markdown
Member

This change requires some tests to validate that it works.

Also, there are three functions:

  • PyArray_MultiIterFromObjects
  • PyArray_MultiIterNew
  • arraymultiter_new

doing almost the exact same thing, and this change brings them slightly apart, which is not a good thing.

Probably the right thing to do is to refactor the code so that there is a single implementation of the multi-iterator constructor that gets called by the others. But at the very least, the change should be made on all three.

@kohr-h

kohr-h commented Jan 3, 2016

Copy link
Copy Markdown
Contributor Author

This change requires some tests to validate that it works.

Where would such a test go? Would it be sufficient to just always use np.broadcast in this test, assuming there is also a single-array test case?

Also, there are three functions:

PyArray_MultiIterFromObjects
PyArray_MultiIterNew
arraymultiter_new

doing almost the exact same thing, and this change brings them slightly apart, which is not a good thing.

Probably the right thing to do is to refactor the code so that there is a single implementation of the multi-iterator constructor that gets called by the others. But at the very least, the change should be made on all three.

I can easily do the least and adapt those three functions. Tests are also relevant here, I guess.
Regarding the common code, I assume you are referring (roughly) to this portion of the constructor. Do you want me to make an attempt? How about names for small helpers then, any suggestion?

@kohr-h

kohr-h commented Jan 3, 2016

Copy link
Copy Markdown
Contributor Author

I just found the dedicated TestBroadcast case.

@kohr-h

kohr-h commented Jan 3, 2016

Copy link
Copy Markdown
Contributor Author

Single-arg broadcast has a test now. I did not find a nice way to modify the existing list and get the desired result, so I added a few extra lines.

@kohr-h

kohr-h commented Jan 3, 2016

Copy link
Copy Markdown
Contributor Author

I took the easy route and just changed numbers and error messages three times. The "proper" code refactoring goes beyond my knowledge of the C part.
broadcast does not seem to be used very much in the rest of the library, I just found one place in stride_tricks.py where a distinction had to be made between len(args) == 1 and all other cases. This check has been removed.

Question: are there dedicated tests for the PyArray_MultiIterFromObjects, PyArray_MultiIterNew, arraymultiter_new functions where a case for length 1 could be added?

Comment thread numpy/core/tests/test_numeric.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this deserves its own test method, test_broacast_single_arg or something along that line.

@homu

homu commented Jan 4, 2016

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #6900) made this pull request unmergeable. Please resolve the merge conflicts.

@kohr-h
kohr-h force-pushed the issue-6899__broadcast_with_one_arg branch from 7e6a365 to ec4d0b8 Compare January 4, 2016 10:04
@kohr-h
kohr-h force-pushed the issue-6899__broadcast_with_one_arg branch from ec4d0b8 to 361c0d5 Compare January 4, 2016 10:47
@kohr-h

kohr-h commented Jan 4, 2016

Copy link
Copy Markdown
Contributor Author

Rebased and streamlined the commits. Any further action necessary?

@jaimefrio

Copy link
Copy Markdown
Member

One last request: I think this is worthy of a mention in the release notes.

@kohr-h

kohr-h commented Jan 5, 2016

Copy link
Copy Markdown
Contributor Author

Sure, under which heading? Changes?

@kohr-h

kohr-h commented Jan 6, 2016

Copy link
Copy Markdown
Contributor Author

Looking ok?

jaimefrio added a commit that referenced this pull request Jan 6, 2016
ENH: allow single input argument in numpy.broadcast
@jaimefrio
jaimefrio merged commit 55b5972 into numpy:master Jan 6, 2016
@jaimefrio

Copy link
Copy Markdown
Member

Thanks Holger, in it goes.

@kohr-h

kohr-h commented Jan 7, 2016

Copy link
Copy Markdown
Contributor Author

My pleasure!

@kohr-h
kohr-h deleted the issue-6899__broadcast_with_one_arg branch January 7, 2016 00:00
eric-wieser added a commit to eric-wieser/numpy that referenced this pull request May 13, 2019
Follows on from numpygh-6905 which reduced the limit from 2 to 1. Let's go all the way to zero.

Just as for `broadcast(broadcast(a), b)` is interpreted as `broadcast(a, b)` , this change interprets
`broadcast(broadcast(), a)` as `broadcast(a)`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants