You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Base.@purefunctionsymbol_to_index(names::SArray, s::Symbol)
findfirst((t)->s==t,names)
end
or
Base.@purefunctionsymbol_to_index(names, s::Symbol)
i =0for n in names
i +=1
n == s &&return i
endreturnerror("Label not valid")
end
would make
@inlinefunction Base.getindex(A::LMArray{S,T,N,L}, s::Symbol) where {L,N,T,S<:Tuple}
A.values[symbol_to_index(A.names, s)]
end
the symbol_to_index call be essentially free after the first time it compiles and basically makes a map between symbols and indices, but that doesn't seem to be the case. Do I need to Val{s}? That would be fine, especially after JuliaLang/julia#1974 .
@mbauman@timholy can I call on your expertise for some advice here on pure functions? There must be some way to get Julia to know that the names are constant in some form and optimize on that for literals.
The text was updated successfully, but these errors were encountered:
Did you figure this one out? I don't think a @pure function is allowed to throw errors, since you're telling the compiler it's safe to execute at any time, including in inference and compilation.
I'm going to wait until v0.7 to see if any of the inference changes help. I think the correct interface for this is via getfield overloading, in which case that should be fast I think if it optimizes on the constant correctly. That or IPO should do the trick.
I was hoping
or
would make
the
symbol_to_index
call be essentially free after the first time it compiles and basically makes a map between symbols and indices, but that doesn't seem to be the case. Do I need toVal{s}
? That would be fine, especially after JuliaLang/julia#1974 .@mbauman @timholy can I call on your expertise for some advice here on pure functions? There must be some way to get Julia to know that the names are constant in some form and optimize on that for literals.
The text was updated successfully, but these errors were encountered: