I’m computing a matrix of values (specifically, a Wigner D matrix for a given ℓ value) via recurrence for a given input value R. The nature of this recurrence makes the memory-access patterns pretty ugly, and there’s really no chance for vectorization when computing one such matrix. However, I often have to compute that matrix for dozens to hundreds of values of R, so I’m thinking that I can make it an array, where the first dimension indexes the different R values. Then, through the magic of Julia it’s vectorized. (Please let me know if I’m wrong, or if there are tricks I need to look out for.)
Now, I already have this working for a single R value, though it is a little ugly, and requires some extra workspace, so I made special structs that are more than just the matrix. So I’m wondering if Julia has some fanciness that would make it easy to just use this code, and get vectorization. For example, StructArrays.jl is pretty fancy but doesn’t look like it would do the job, since inside it would just be a vector of matrices, which would have the wrong order for vectorization, right?
For context, here’s what a late part of this recurrence would like — compute some coefficients based on the indices, then combine values in this weird stencil pattern:
for m′ in range_m′
a = √((ℓ-m′)*(ℓ+m′+1))
b = √((ℓ-m′+1)*(ℓ+m′))
for m in range_m
c = √((ℓ-m+1)*(ℓ+m))
d = √((ℓ-m)*(ℓ+m+1))
Dˡ[m′+1, m] = (
b * Dˡ[m′-1, m]
- c * Dˡ[m′, m-1]
+ d * Dˡ[m′, m+1]
) / a
end
end