You definitely can, StaticArrays are super handy in kernels since they don’t allocate (which is a requirement of kernel code). The problem with your code above is just that its not valid CPU code either, your x
variable is just a type, not an instance of an SVector. Here’s a similar example that works,
using StaticArrays, Setfield
function register()
x = @SVector Float64[0, 0, 0]
@set! x[1] = 1
return nothing
end
Note also the use of @set!
from Setfield
since you can’t actually mutate the SVector. Depending on what you’re trying to do, that could be useful (though not necessarily the most performant thing).