Skip to content
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

improve broadcast_dims to work directly with Dimensions #775

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

haakon-e
Copy link
Contributor

Closes #748.

…on`s and `DimArray`s

The `broadcast_dims` function now supports broadcasting over `Dimension`s and references to them, in addition to `AbstractDimArray`s. This allows for more flexibility when broadcasting over combinations of `DimArray`s and `Dimension`s.
@haakon-e haakon-e changed the title chore: improve broadcast_dims function to work directly with Dimensions chore: improve broadcast_dims to work directly with Dimensions Aug 20, 2024
@haakon-e haakon-e changed the title chore: improve broadcast_dims to work directly with Dimensions improve broadcast_dims to work directly with Dimensions Aug 20, 2024
Copy link
Owner

@rafaqz rafaqz left a comment

Choose a reason for hiding this comment

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

Should it also work with DimStack?

"""
function broadcast_dims(f, As::AbstractBasicDimArray...)
dims = combinedims(As...)
T = Base.Broadcast.combine_eltypes(f, As)
broadcast_dims!(f, similar(first(As), T, dims), As...)
end

function broadcast_dims(f, As::Union{AbstractBasicDimArray, Dimensions.Dimension, Type{<:Dimension}, Symbol}...)
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
function broadcast_dims(f, As::Union{AbstractBasicDimArray, Dimensions.Dimension, Type{<:Dimension}, Symbol}...)
function broadcast_dims(f, As::Union{AbstractBasicDimArray,Dimension,Type{<:Dimension},Symbol}...)

@haakon-e
Copy link
Contributor Author

I think so yes -- I'll try to look at this again next week.

@rafaqz
Copy link
Owner

rafaqz commented Nov 12, 2024

Is it worth finishing this? Would still be nice to have consistency with @d, even though broadcast_dims less useful now.

@haakon-e
Copy link
Contributor Author

Thanks for pinging me again. Are there use cases for keeping both?
I've beens slowly exploring @d to understand how it fits my needs.

An alternative would be to deprecate broadcast_dims, if @d has all relevant functionality.

@rafaqz
Copy link
Owner

rafaqz commented Nov 12, 2024

I think there are still contexts to use a function, like we still have broadcast in Base.

Right now especially one of those is on DimStack

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.

FR: Make broadcast_dims work with DimArrays and Dimensions
2 participants