Skip to content

Reorganizes the broadcast functions in numpy and array_api - #4978

Merged
ajpotts merged 1 commit into
Bears-R-Us:mainfrom
drculhane:Closes-4975
Oct 15, 2025
Merged

ajpotts merged 1 commit into
Bears-R-Us:mainfrom
drculhane:Closes-4975

Conversation

@drculhane

@drculhane drculhane commented Oct 2, 2025 •

Copy link
Copy Markdown
Contributor

Closes #4975, adding some organization and numpy alignment to the broadcast functions.

The naming and use of the various broadcast functions in arkouda/numpy and arkouda/array_api have been inconsistent, and out of alignment with numpy.

How it was:

arkouda/array_api/manipulation_functions had: broadcast_arrays and broadcast_to, which did match numpy.

  • The docstrings lacked examples
  • The functions weren't typechecked.

arkouda/numpy/util.py had: broadcast_dims (which does not exist in numpy, though it was similar to broadcast_to),

  • The docstring had no examples.
  • It wasn't typechecked.

arkouda/numpy/pdarrayclass.py had: broadcast_to_shapes (same functionality as broadcast_to), and broadcast_if_needed (which also does not exist in numpy).

  • These were both typechecked.
  • broadcast_if_needed had no docstring.

How it is now:

I left broadcast_if_needed alone. It only appears to be used in binops and nextafter. This can probably be replaced by broadcast_arrays, but I haven't done that yet.

I also left broadcast_dims alone, for now, although I think nothing uses it anymore.

arkouda/numpy/util.py now has broadcast_to, broadcast_shapes, and broadcast_arrays. They match the behavior of the similarly named numpy functions.

arkouda/array_api/manipulation_functions.py has the same broadcast_arrays it had before. The array_api's broadcast_to function now passes its arguments directly to the arkouda/numpy broadcast_to (the parameters are tuples, not pdarrays, so why duplicate the code?).

  • broadcast_if_needed lacks a docstring. I didn't sweat that, since I expect it to be deprecated soon.
  • The docstrings now have examples.
  • The functions are all now typechecked.
  • The functions now all have unit tests.
  • I removed the instances of implements_numpy, but may put that back on all of the functions where it's relevant.

@drculhane
drculhane force-pushed the Closes-4975 branch 2 times, most recently from 4c3adeb to 689a22b Compare October 7, 2025 13:01
@drculhane
drculhane marked this pull request as ready for review October 7, 2025 13:02

@ajpotts ajpotts 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.

Great work! Thanks for fixing this!

1RyanK

This comment was marked as duplicate.

@1RyanK 1RyanK 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.

Looks good! Think this may be related to #4797 as well.

@jaketrookman jaketrookman 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.

Looks good

@ajpotts
ajpotts added this pull request to the merge queue Oct 15, 2025
Merged via the queue into Bears-R-Us:main with commit 775cf69 Oct 15, 2025
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.

Align naming of arkouda array broadcasting functions to numpy

4 participants