I find DimStacks preferable for many use cases as an alternative to structures.
However, in structures I can store scalar fields.
Can DimStack be updated to do so as well?
Can't instantiate a 0-dimensional DimArray for storing in a DimStack:
julia> DimArray(fill(12.34))
ERROR: MethodError: no method matching DimArray(::Array{Float64, 0})
The type `DimArray` exists, but no method is defined for this combination of argument types when trying to construct it.
Closest candidates are:
DimArray(::AbstractArray, ::Union{Tuple, NamedTuple}; refdims, name, metadata)
@ DimensionalData C:\Users\T0185914\.julia\packages\DimensionalData\0QEaa\src\array\array.jl:428
DimArray(::AbstractArray, ::Any; kw...)
@ DimensionalData C:\Users\T0185914\.julia\packages\DimensionalData\0QEaa\src\array\array.jl:427
DimArray(::A, ::D, ::R, ::Na, ::Me) where {T, N, D<:Tuple, R<:Tuple, A<:AbstractArray{T, N}, Na, Me}
@ DimensionalData C:\Users\T0185914\.julia\packages\DimensionalData\0QEaa\src\array\array.jl:419
...
Stacktrace:
[1] top-level scope
@ REPL[54]:1
But somehow this constructs a 0-dimensional DimArray:
julia> x = X(1:10)
X 1:10
julia> y = Y(2:0.1:4)
Y 2.0:0.1:4.0
julia> st1 = DimStack((; A = rand(x, y), B = rand(x, Z([1]))))
┌ 10×21×1 DimStack ┐
├──────────────────┴──────────────────────────────────────── dims ┐
↓ X Sampled{Int64} 1:10 ForwardOrdered Regular Points,
→ Y Sampled{Float64} 2.0:0.1:4.0 ForwardOrdered Regular Points,
↗ Z Sampled{Int64} [1] ForwardOrdered Irregular Points
├───────────────────────────────────────────────────────── layers ┤
:A eltype: Float64 dims: X, Y size: 10×21
:B eltype: Float64 dims: X, Z size: 10×1
└─────────────────────────────────────────────────────────────────┘
julia> st1[X = At(1), Y = At(2)].A
┌ 0-dimensional DimArray{Float64, 0} A ┐
└──────────────────────────────────────┘
0.885065
(I understand I am demonstrating the complaint that "users do weird things." 😅)
I find
DimStacks preferable for many use cases as an alternative tostructures.However, in
structures I can store scalar fields.Can
DimStackbe updated to do so as well?Can't instantiate a 0-dimensional
DimArrayfor storing in aDimStack:But somehow this constructs a 0-dimensional
DimArray:(I understand I am demonstrating the complaint that "users do weird things." 😅)