Skip to content

Commit

Permalink
dont use nothing for layerdims
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Apr 1, 2023
1 parent ba98b75 commit 91c5b2d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions src/stack/stack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ refdims(s::AbstractDimStack) = getfield(s, :refdims)
metadata(s::AbstractDimStack) = getfield(s, :metadata)

layerdims(s::AbstractDimStack) = getfield(s, :layerdims)
function layerdims(s::AbstractDimStack, key::Symbol)
isnothing(layerdims(s)) ? dims(s) : dims(s, layerdims(s)[key])
end
layerdims(s::AbstractDimStack, key::Symbol) = dims(s, layerdims(s)[key])
layermetadata(s::AbstractDimStack) = getfield(s, :layermetadata)
layermetadata(s::AbstractDimStack, key::Symbol) = layermetadata(s)[key]

Expand Down Expand Up @@ -255,8 +253,7 @@ function DimStack(@nospecialize(das::AbstractArray{<:AbstractDimArray});
dims = DD.combinedims(collect(das))
as = map(parent, das)
data = NamedTuple{keys_tuple}(as)
same_dims_layers = all(map(a -> ndims(a) == length(dims), as))
layerdims = same_dims_layers ? nothing : NamedTuple{keys_tuple}(map(basedims, das))
layerdims = NamedTuple{keys_tuple}(map(basedims, das))
layermetadata = NamedTuple{keys_tuple}(map(DD.metadata, das))

DimStack(data, dims, refdims, layerdims, metadata, layermetadata)
Expand All @@ -269,10 +266,11 @@ function DimStack(das::NamedTuple{<:Any,<:Tuple{Vararg{AbstractDimArray}}};
end
# Same sized arrays
function DimStack(data::NamedTuple, dims::Tuple;
refdims=(), metadata=NoMetadata(), layermetadata=map(_ -> NoMetadata(), data)
refdims=(), metadata=NoMetadata(),
layermetadata=map(_ -> NoMetadata(), data),
layerdims = map(_ -> basedims(dims), data),
)
all(map(d -> axes(d) == axes(first(data)), data)) || _stack_size_mismatch()
layerdims = nothing
DimStack(data, format(dims, first(data)), refdims, layerdims, metadata, layermetadata)
end

Expand Down
2 changes: 1 addition & 1 deletion test/stack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ end
@test layers(s) === (; s...)
@test layers(s) === (; one=da1, s[(:two,)]..., (three=da3,)...)
@test layers(s) === (; (one=da1,)..., two=da2, s[(:three,)]...)
@test s === merge(s[(:one,:two)], (three=da3,))
@test typeof(s) === typeof(merge(s[(:one,:two)], (three=da3,)))
@test s === merge(s[(:one,)], (two=da2, three=da3))
@test merge(mixed) === mixed
@test keys(merge(mixed, s)) == (:one, :two, :extradim, :three)
Expand Down

0 comments on commit 91c5b2d

Please sign in to comment.