JuliaArrays / StructArrays.jl

Efficient implementation of struct arrays in Julia
https://juliaarrays.github.io/StructArrays.jl/
Other
322 stars 41 forks source link

how to set the i,j,k index for a multidimensional structarray ? #191

Open MKAbdElrahman opened 3 years ago

MKAbdElrahman commented 3 years ago

Currently, to set the field values for the ijk struct, I convert first to linear indexing.

lh = LazyRow(h,i + Ny*(j-1) + Nx*Ny * (k-1));

setproperty!(lh,:x,hx)
setproperty!(lh,:y,hy)                  
setproperty!(lh,:z,hz)      

I wonder if there is a direct way:

lh = LazyRow(h,(i,j,k));

setproperty!(lh,:x,hx)
setproperty!(lh,:y,hy)                  
setproperty!(lh,:z,hz)
piever commented 3 years ago

Ah, LazyRow is actually a bit too low-level, because it assumes that the passed index type is the optimal one for the array you are using.

lh = LazyRows(t)[i, j, k]

is probably what you want. Keeping the issue open because the docs should probably get updated to make this clearer.