Skip to content

Add a new broadcasting mode that inserts size-1 dimensions. #10033

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

Open
dcherian opened this issue Feb 6, 2025 · 3 comments
Open

Add a new broadcasting mode that inserts size-1 dimensions. #10033

dcherian opened this issue Feb 6, 2025 · 3 comments

Comments

@dcherian
Copy link
Contributor

dcherian commented Feb 6, 2025

I've found it useful to broadcast to size-1 unlabeled dimensions. This allows you to avoid useless extra work in functions that accept unlabeled arrays, and would be very convenient when paired with apply_ufunc.

For example: https://github.com/xarray-contrib/flox/blob/ca576812e78b3978421eace6e9dde5a76729ebcc/flox/xarray.py#L45-L62

This should be paired with #2171

@TomNicholas
Copy link
Member

Wouldn't it be cleaner to just stop supporting unlabeled arrays in apply_ufunc? See #8995

@TomNicholas
Copy link
Member

Or are you saying #2171 shows there is a use case for broadcasting to size-1 unlabeled dimensions outside of apply_ufunc?

@dcherian
Copy link
Contributor Author

dcherian commented Feb 6, 2025

The function being applied could benefit from receiving broadcasted arrays with size-1 dimensions instead of size-N. #2171 is relevant in that we'd need it for DataArrays broadcasted in this manner to be actually useful in Xarray ops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants