getindex with UnitRange
x = reshape(1:25, 5, 5)
v = view(x, 1:2:5, 1:2:5)
v[:,1]
produces
ERROR: `getindex` has no method matching getindex(::StridedView{Int64,2,0,Array{Int64,2}}, ::UnitRange{Int64}, ::Int64)
Selecting by range is very common and I believe should be supported. Is there a reason why it is not?
I can reproduce this.
I can't comment on ArrayViews, but this works if you use sub instead of view.
Unfortunately, I need to use strided_view so replacing it with sub would be tricky.
Out of curiosity, why do you need to use strided_view? I ask because I believe it's fair to say that in 0.4, sub (or slice) will be the recommended way to create views. If there's code out there that requires StridedView inputs, it might be time to start thinking about loosening that typing.
I'm trying to create a moving window view. For example, I have a function
function moving_window(arr, n)
shp = (size(arr, 1) * n, size(arr, 2) - n + 1)
strided_view(arr, shp, ArrayViews.contrank(arr), strides(arr))
end
In my case, n is ~30 and I have a ~1gb dataset. I can handle ~1gb but not as easily ~30gb.
Does sub(arr, :, size(arr, 2)-n+1:size(arr,2)) not work?
No, sub only construct subarray views as far as I know.
julia> x = reshape(1:12, 2, 6)
2x6 Array{Int64,2}:
1 3 5 7 9 11
2 4 6 8 10 12
julia> moving_window(x, 2)
4x5 StridedView{Int64,2,2,Array{Int64,2}}:
1 3 5 7 9
2 4 6 8 10
3 5 7 9 11
4 6 8 10 12
julia> sub(x, :, size(x, 2)-2+1:size(x, 2))
2x2 SubArray{Int64,2,Array{Int64,2},(UnitRange{Int64},UnitRange{Int64})}:
9 11
10 12
This does this trick for me:
getindex(av::ArrayView, I::Union(Int,UnitRange{Int})...) = sub(av,I...)
Now I understand what you're after---thanks for the demo. I agree, currently there isn't a great way to achieve that without directly messing with strides.
Hi, @samuela, can you make a PR to add your trick to the code?
I also have this problem with Julia 0.3, but not 0.4
Is this still relevant to track?