FillArrays.jl
FillArrays.jl copied to clipboard
Support setindex
The following should be a fast way of creating e_k (the vector of all zeros but with 1 in the k-th entry):
julia> using FillArrays
julia> Base.setindex(Zeros(5), 2, 3)
ERROR: MethodError: no method matching setindex(::Zeros{Float64, 1, Tuple{Base.OneTo{Int64}}}, ::Int64, ::Int64)
Closest candidates are:
setindex(::Tuple, ::Any, ::Integer) at tuple.jl:49
setindex(::CartesianIndex, ::Any, ::Any) at multidimensional.jl:100
setindex(::NamedTuple, ::Any, ::Symbol) at namedtuple.jl:355
Stacktrace:
[1] top-level scope
@ REPL[2]:1
What are you picturing this returning?
Zygote's OneElement is something very close to this, which could perhaps be moved upstream if it has other uses. Allows any ndims, any axes.
Flux also has a OneHotVector which is more restricted, stores just a UInt32. A vector of these can be re-interpreted as integers. There was talk of moving that out, too, but perhaps not a good fit here.
Yeah, I guess the proposal would be to move OneElement here