AxisKeys.jl
AxisKeys.jl copied to clipboard
indexed assignment does not work with dimension name specification
Indexing by dimension names does not seem to work for LHS assignments:
julia> K = wrapdims(rand(2,2), x=1:2, y=1:2);
julia> K[x=1] .= 0
ERROR: MethodError: no method matching dotview(::KeyedArray{Float64,2,NamedDimsArray{(:x, :y),Float64,2,Array{Float64,2}},Tuple{UnitRange{Int64},UnitRange{Int64}}}; x=1)
Closest candidates are:
dotview(::KeyedArray, ::Any...) at /home/takbal/.julia/packages/AxisKeys/G3Okw/src/struct.jl:137 got unsupported keyword argument "x"
dotview(::Any...) at broadcast.jl:1160 got unsupported keyword argument "x"
dotview(::BitArray, ::BitArray) at broadcast.jl:1130 got unsupported keyword argument "x"
...
Stacktrace:
[1] top-level scope at REPL[182]:1
It works for NamedDims though:
julia> parent(K)[x=1] .= 0
2-element NamedDimsArray(view(::Array{Float64,2}, 1, :), (:y,)):
↓ y 0.0
0.0
Looks like the reason is that the Base.dotview() specialization does not pass keyword arguments upwards.
That looks like a bug, indeed. I think there ought to be a method Base.dotview(A::KaNda; kw...) which looks up the names.
I believe the same goes for setindex!()