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

Breaking: Implement AbstractArray interface for AbstractDimStack #871

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix broadcast_dims
  • Loading branch information
tiemvanderdeure committed Nov 27, 2024
commit 1ba7d2b2dea4bafa8cbb0dfb9afebed37e451dd5
2 changes: 1 addition & 1 deletion src/array/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ function DimArray(A::AbstractBasicDimArray;
data=parent(A), dims=dims(A), refdims=refdims(A), name=name(A), metadata=metadata(A)
)
newdata = collect(data)
T(newdata, format(dims, newdata); refdims, name, metadata)
DimArray(newdata, format(dims, newdata); refdims, name, metadata)
end
"""
DimArray(f::Function, dim::Dimension; [name])
Expand Down
20 changes: 10 additions & 10 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,17 @@ sliced by the dimensions of `B`.
"""
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{AbstractDimStack,AbstractBasicDimArray}...)
st = _firststack(As...)
nts = _as_extended_nts(NamedTuple(st), As...)
layers = map(keys(st)) do name
broadcast_dims(f, map(nt -> nt[name], nts)...)
if any(map(A -> A isa AbstractDimStack, As))
st = _firststack(As...)
nts = _as_extended_nts(NamedTuple(st), As...)
layers = map(keys(st)) do name
broadcast_dims(f, map(nt -> nt[name], nts)...)
end
rebuild_from_arrays(st, layers)
else
T = Base.Broadcast.combine_eltypes(f, As)
broadcast_dims!(f, similar(first(As), T, dims), As...)
end
rebuild_from_arrays(st, layers)
end

"""
Expand Down
Loading