From 91c5b2db0cf2139a3e1cf716c6ab92a322cc588e Mon Sep 17 00:00:00 2001 From: rafaqz Date: Sun, 12 Mar 2023 13:12:04 +0000 Subject: [PATCH] dont use nothing for layerdims --- src/stack/stack.jl | 12 +++++------- test/stack.jl | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/stack/stack.jl b/src/stack/stack.jl index da1f33cb1..960efbe07 100644 --- a/src/stack/stack.jl +++ b/src/stack/stack.jl @@ -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] @@ -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) @@ -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 diff --git a/test/stack.jl b/test/stack.jl index 7f9070be8..1615a0245 100644 --- a/test/stack.jl +++ b/test/stack.jl @@ -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)