Skip to content
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

Noninteger indexes #21

Open
jtrakk opened this issue Nov 19, 2020 · 1 comment
Open

Noninteger indexes #21

jtrakk opened this issue Nov 19, 2020 · 1 comment

Comments

@jtrakk
Copy link

jtrakk commented Nov 19, 2020

I would like to look up non-integer values in my IndirectArray. LabelledArrays.jl supports noninteger indexes, but IndirectArrays currently enforces ::Int for the index type. Could IndirectArrays allow this type restriction to be loosened?

using LabelledArrays
using IndirectArrays

indexes = Symbol.(["a", "b", "b", "c", "c", "c"])
values = [10, 20, 30]
label_dict = Dict(v=>k for (k,v) in enumerate(unique(indexes)))
label_array = LVector(;label_dict...)
@assert label_array[:c] == 3
lookup = IndirectArray(label_array, values)
lookup[:c] == 30

ArgumentError: invalid index: :c of type Symbol
Stacktrace:
 [1] to_index(::Symbol) at ./indices.jl:297
 [2] to_index(::IndirectArray{Int64,1,LArray{Int64,1,Array{Int64,1},(:a, :b, :c)},Array{Int64,1}}, ::Symbol) at ./indices.jl:274
 [3] to_indices at ./indices.jl:325 [inlined]
 [4] to_indices at ./indices.jl:322 [inlined]
 [5] getindex(::IndirectArray{Int64,1,LArray{Int64,1,Array{Int64,1},(:a, :b, :c)},Array{Int64,1}}, ::Symbol) at ./abstractarray.jl:1060
@timholy
Copy link
Member

timholy commented Nov 19, 2020

As long as LabelledArrays doesn't permit the labels to be real values, I think that could be doable. Just create the necessary getindex methods in parallel to the existing ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants