HybridArrays.jl icon indicating copy to clipboard operation
HybridArrays.jl copied to clipboard

slices along fixed dimensions

Open simonbyrne opened this issue 4 years ago • 3 comments

I often want to do something like:

julia> A = HybridArray{Tuple{2,4,StaticArrays.Dynamic()}}(fill(0.0, 2, 4, 3));

julia> v = view(A,:,StaticArrays.SUnitRange(2,3),:)
2×2×3 view(::HybridArray{Tuple{2,4,StaticArrays.Dynamic()},Float64,3,3,Array{Float64,3}}, :, [2, 3], :) with eltype Float64 with indices SOneTo(2)×SOneTo(2)×Base.OneTo(3):
[:, :, 1] =
 0.0  0.0
 0.0  0.0

[:, :, 2] =
 0.0  0.0
 0.0  0.0

[:, :, 3] =
 0.0  0.0
 0.0  0.0

Is it possible to make this return a SizedArray?

simonbyrne avatar Jan 06 '21 05:01 simonbyrne

Is it possible to make this return a SizedArray?

Or I guess it should be a HybridArray?

simonbyrne avatar Jan 06 '21 16:01 simonbyrne

That looks possible, and I think it should return HybridArray. I will try to add it.

mateuszbaran avatar Jan 06 '21 20:01 mateuszbaran

When all dynamically sized axes are set to a fixed size (by indexing using SOneTo or some SizedVector like SUnitRange), then views should return SizedArray, otherwise a HybridArray will be returned. I didn't need that case before but that turned out to be simple to add. As a bonus I noticed a small problem with handling SUnitRange so that will be fixed as well :slightly_smiling_face: .

mateuszbaran avatar Jan 06 '21 20:01 mateuszbaran