JuliaData / JuliaData/InvertedIndices.jl
Inverting arrays of custom index types
Open
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 90
- Forks
- 9
- PR merge metrics
- No merged PRs in 30d
Description
MWE:
julia> struct NamedVector{T,A,B} <: AbstractArray{T,1}
data::A
names::B
end
function NamedVector(data, names)
@assert size(data) == size(names)
NamedVector{eltype(data), typeof(data), typeof(names)}(data, names)
end
Base.size(n::NamedVector) = size(n.data)
Base.getindex(n::NamedVector, i::Int) = n.data[i]
Base.to_index(n::NamedVector, name::Symbol) = findfirst(==(name), n.names)
Base.checkbounds(::Type{Bool}, n::NamedVector, names::AbstractArray{Symbol}) = all(name in n.names for name in names)
julia> n = NamedVector(1:4, [:a, :b, :c, :d]);
julia> using InvertedIndices
julia> n[Not([:a,:b])]
2-element Array{Int64,1}:
1
2
julia> n[[:a,:b]]
2-element Array{Int64,1}:
1
2
The issue is that arrays don't get their elements converted by to_indices, but we check each element assuming that it did.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Julia's to_indices behavior and the InvertedIndices handling exercised by the NamedVector MWE. Reproduce both n[Not([:a,:b])] and n[[:a,:b]], then trace where array elements are checked without conversion; done means custom index types produce the same selected values as direct indexing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100