heltonmc / SIMDMath.jl

Lightweight SIMD routines for special function evaluation
MIT License
10 stars 1 forks source link

Support for accessing specific index of a Vec or ComplexVec #5

Closed heltonmc closed 1 year ago

heltonmc commented 1 year ago

After we do the SIMD evaluations it is often times necessary to unpack or get certain elements from a simd Vec or ComplexVec.

For instance it would be nice if...

ulia>  a= Vec{4, Float64}((1.2, 1.3, 1.4, 1.5))
Vec{4, Float64}((VecElement{Float64}(1.2), VecElement{Float64}(1.3), VecElement{Float64}(1.4), VecElement{Float64}(1.5)))

julia> a[1]
ERROR: MethodError: no method matching getindex(::Vec{4, Float64}, ::Int64)
Stacktrace:
 [1] top-level scope
   @ REPL[6]:1

Would work and return either a Float64 or VecElement{Float64}. Likewise for complex it would be nice if

julia> b = ComplexVec{4, Float64}((1.2, 1.3, 1.4, 1.5), (1.1, 1.2, 1.1, 1.0))
ComplexVec{4, Float64}((VecElement{Float64}(1.2), VecElement{Float64}(1.3), VecElement{Float64}(1.4), VecElement{Float64}(1.5)), (VecElement{Float64}(1.1), VecElement{Float64}(1.2), VecElement{Float64}(1.1), VecElement{Float64}(1.0)))

julia> b[1]
ERROR: MethodError: no method matching getindex(::ComplexVec{4, Float64}, ::Int64)
Stacktrace:
 [1] top-level scope
   @ REPL[10]:1

Would return probably complex(1.2, 1.1). I think that would make the most sense in this case. Of course this is slow and should only happen once at the end of the routine but this would greatly improve the code clarity (in Bessels at least) when using SIMDMath in regular functions.