-
Notifications
You must be signed in to change notification settings - Fork 28
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
Keys can be lost in mapreduce(..., cat, ...)
#87
Comments
This is tricky. My first thought here is that, without thinking about this package, you probably want to just reshape and call julia> using TensorCore
julia> KA1 ⊡ KA2
2×4×2 Array{Float64, 3}:
[:, :, 1] =
3.0 3.0 3.0 3.0
3.0 3.0 3.0 3.0
[:, :, 2] =
3.0 3.0 3.0 3.0
3.0 3.0 3.0 3.0 These packages are unaware of each other, but reshaping done there uses
The second thought is that, regardless of where slices come from, it would be nice to better propagate properties. Instead of julia> [KA1 * KA2(z=z) for z in KA2.z] # KA2.z === axiskeys(KA2, :z)
2-element Vector{KeyedArray{Float64, 2, NamedDimsArray{(:w, :y), Float64, 2, Matrix{Float64}}, Tuple{Vector{Char}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}}:
[3.0 3.0 3.0 3.0; 3.0 3.0 3.0 3.0]
[3.0 3.0 3.0 3.0; 3.0 3.0 3.0 3.0]
julia> comp = [KA1 * KA2[z=i] for i in axes(KA2, :z)]
2-element Vector{KeyedArray{Float64, 2, NamedDimsArray{(:w, :y), Float64, 2, Matrix{Float64}}, Tuple{Vector{Char}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}}:
[3.0 3.0 3.0 3.0; 3.0 3.0 3.0 3.0]
[3.0 3.0 3.0 3.0; 3.0 3.0 3.0 3.0]
julia> using LazyStack # a package AxisKeys knows about
julia> stack(comp) # 3rd axis still _ ∈ 2-element OneTo
3-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓ w ∈ 2-element Vector{Char}
→ y ∈ 4-element StepRangeLen{Float64,...}
◪ _ ∈ 2-element OneTo{Int}
And data, 2×4×2 stack(::Vector{KeyedArray{Float64, 2, NamedDimsArray{(:w, :y), Float64, 2, Matrix{Float64}}, Tuple{Vector{Char}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}}) with eltype Float64:
[:, :, 1] ~ (:, :, 1):
...
julia> stack(wrapdims(comp, z=KA2.z))
3-dimensional KeyedArray(NamedDimsArray(...)) with keys:
↓ w ∈ 2-element Vector{Char}
→ y ∈ 4-element StepRangeLen{Float64,...}
◪ z ∈ 2-element Vector{String}
And data, 2×4×2 stack(::Vector{KeyedArray{Float64, 2, NamedDimsArray{(:w, :y), Float64, 2, Matrix{Float64}}, Tuple{Vector{Char}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}}) with eltype Float64:
[:, :, 1] ~ (:, :, "foo"): Again thinking about #6, I think |
Thanks for the suggestions! To clarify, is there currently no support (on |
I want to slice a 3D array into matrices, multiply each matrix by another matrix, and then cat the result back into a 3D array.
The reason to do it this way is: the dimension shared by the matrices has non-overlapping keys, and I want to find the overlapping keys (that have non-missing values) for each slice.
The problem is that I can't preserve the axiskeys that I sliced over in the final concatenated array - it defaults to
OneTo
.MWE:
I tried using an
Interval
at theKA2_slice = KA2(z=z)
step, but Julia doesn't seem to support multiplying tensors with different dimensions, even if it's a trailing singleton dimension:My current workaround is to use
wrapdims
afterward to re-key the array.The text was updated successfully, but these errors were encountered: