slicing a multi-dimensional `mapview`
I'd like to create a mapview
of a multi-dimensional array, and then slice it with a :
in one of the dimensions, but that doesn't appear to work:
julia> using FlexiMaps: mapview
julia> struct Foo{Ta, Tb}
a::Ta
b::Tb
end
julia> foos = Foo.(reshape(1:10, 2, 5), reshape(range(0.0, 1.0; length=10), 2, 5))
2×5 Matrix{Foo{Int64, Float64}}:
Foo{Int64, Float64}(1, 0.0) Foo{Int64, Float64}(3, 0.222222) … Foo{Int64, Float64}(9, 0.888889)
Foo{Int64, Float64}(2, 0.111111) Foo{Int64, Float64}(4, 0.333333) Foo{Int64, Float64}(10, 1.0)
julia> as = mapview(:a, foos)
2×5 FlexiMaps.MappedArray{Int64, 2, Accessors.PropertyLens{:a}, Matrix{Foo{Int64, Float64}}}:
1 3 5 7 9
2 4 6 8 10
julia> as[1, 2]
3
julia> as[:, 2]
ERROR: TypeError: in MappedArray, in TX, expected TX<:(AbstractMatrix), got Type{Vector{Foo{Int64, Float64}}}
Stacktrace:
[1] (FlexiMaps.MappedArray{Int64, 2, F, TX} where {F, TX<:(AbstractMatrix)})(f::Accessors.PropertyLens{:a}, X::Vector{Foo{Int64, Float
64}})
@ FlexiMaps ~/.julia/packages/FlexiMaps/xDulV/src/mapview.jl:5
[2] set
@ ~/.julia/packages/FlexiMaps/xDulV/src/mapview.jl:60 [inlined]
[3] _getindex
@ ~/.julia/packages/FlexiMaps/xDulV/src/mapview.jl:11 [inlined]
[4] getindex(::FlexiMaps.MappedArray{Int64, 2, Accessors.PropertyLens{:a}, Matrix{Foo{Int64, Float64}}}, ::Function, ::Int64)
@ FlexiMaps ~/.julia/packages/FlexiMaps/xDulV/src/mapview.jl:9
[5] top-level scope
@ REPL[48]:1
julia>
A similar error occurs for a 3D array:
julia> foos2 = Foo.(reshape(1:2*3*4, 2, 3, 4), reshape(range(0.0, 1.0; length=2*3*4), 2, 3, 4))
2×3×4 Array{Foo{Int64, Float64}, 3}:
[:, :, 1] =
Foo{Int64, Float64}(1, 0.0) Foo{Int64, Float64}(3, 0.0869565) Foo{Int64, Float64}(5, 0.173913)
Foo{Int64, Float64}(2, 0.0434783) Foo{Int64, Float64}(4, 0.130435) Foo{Int64, Float64}(6, 0.217391)
[:, :, 2] =
Foo{Int64, Float64}(7, 0.26087) Foo{Int64, Float64}(9, 0.347826) Foo{Int64, Float64}(11, 0.434783)
Foo{Int64, Float64}(8, 0.304348) Foo{Int64, Float64}(10, 0.391304) Foo{Int64, Float64}(12, 0.478261)
[:, :, 3] =
Foo{Int64, Float64}(13, 0.521739) Foo{Int64, Float64}(15, 0.608696) Foo{Int64, Float64}(17, 0.695652)
Foo{Int64, Float64}(14, 0.565217) Foo{Int64, Float64}(16, 0.652174) Foo{Int64, Float64}(18, 0.73913)
[:, :, 4] =
Foo{Int64, Float64}(19, 0.782609) Foo{Int64, Float64}(21, 0.869565) Foo{Int64, Float64}(23, 0.956522)
Foo{Int64, Float64}(20, 0.826087) Foo{Int64, Float64}(22, 0.913043) Foo{Int64, Float64}(24, 1.0)
julia> as2 = mapview(:a, foos2)
2×3×4 FlexiMaps.MappedArray{Int64, 3, Accessors.PropertyLens{:a}, Array{Foo{Int64, Float64}, 3}}:
[:, :, 1] =
1 3 5
2 4 6
[:, :, 2] =
7 9 11
8 10 12
[:, :, 3] =
13 15 17
14 16 18
[:, :, 4] =
19 21 23
20 22 24
julia> as2[1, 2, 3]
15
julia> as2[:, 2, 3]
ERROR: TypeError: in MappedArray, in TX, expected TX<:(AbstractArray{<:Any, 3}), got Type{Vector{Foo{Int64, Float64}}}
Stacktrace:
[1] (FlexiMaps.MappedArray{Int64, 3, F, TX} where {F, TX<:(AbstractArray{<:Any, 3})})(f::Accessors.PropertyLens{:a}, X::Vector{Foo{Int
64, Float64}})
@ FlexiMaps ~/.julia/packages/FlexiMaps/xDulV/src/mapview.jl:5
[2] set
@ ~/.julia/packages/FlexiMaps/xDulV/src/mapview.jl:60 [inlined]
[3] _getindex
@ ~/.julia/packages/FlexiMaps/xDulV/src/mapview.jl:11 [inlined]
[4] getindex(::FlexiMaps.MappedArray{Int64, 3, Accessors.PropertyLens{:a}, Array{Foo{Int64, Float64}, 3}}, ::Function, ::Int64, ::Int6
4)
@ FlexiMaps ~/.julia/packages/FlexiMaps/xDulV/src/mapview.jl:9
[5] top-level scope
@ REPL[52]:1
julia> as2[2, :, 3]
ERROR: TypeError: in MappedArray, in TX, expected TX<:(AbstractArray{<:Any, 3}), got Type{Vector{Foo{Int64, Float64}}}
Stacktrace:
[1] (FlexiMaps.MappedArray{Int64, 3, F, TX} where {F, TX<:(AbstractArray{<:Any, 3})})(f::Accessors.PropertyLens{:a}, X::Vector{Foo{Int
64, Float64}})
@ FlexiMaps ~/.julia/packages/FlexiMaps/xDulV/src/mapview.jl:5
[2] set
@ ~/.julia/packages/FlexiMaps/xDulV/src/mapview.jl:60 [inlined]
[3] _getindex
@ ~/.julia/packages/FlexiMaps/xDulV/src/mapview.jl:11 [inlined]
[4] getindex(::FlexiMaps.MappedArray{Int64, 3, Accessors.PropertyLens{:a}, Array{Foo{Int64, Float64}, 3}}, ::Int64, ::Function, ::Int6
4)
@ FlexiMaps ~/.julia/packages/FlexiMaps/xDulV/src/mapview.jl:9
[5] top-level scope
@ REPL[53]:1
julia>