-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getindex with ColVecs #417
Comments
I think it wasn't me (actually I thought you implemented ColVecs and RowVecs initially @willtebbutt 😄 ) but in my opinion it is correct to return views here. I view |
Ah, interesting. How would you propose that |
I think julia> A = rand(5, 4);
julia> x = [view(A, :, i) for i in axes(A, 2)];
julia> getindex(x, 1)
5-element view(::Matrix{Float64}, :, 1) with eltype Float64:
0.832858822923345
0.1486458121118549
0.20187209965755426
0.17211775415001118
0.8813222986233952
julia> getindex(x, 2:3)
2-element Vector{SubArray{Float64, 1, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, true}}:
[0.75958434210484, 0.28127270898481205, 0.11477999962460317, 0.6093522955819292, 0.30000872694236713]
[0.0028572719840013194, 0.6307387952125958, 0.25339090743930304, 0.2795101302467987, 0.5211441981223575] Mainly, it should satisfy julia> getindex(x, 1) isa eltype(x)
true
julia> getindex(x, 1:2) isa typeof(x)
true While the first property is satisfied for KernelFunctions.jl/src/utils.jl Lines 74 to 75 in 992b665
KernelFunctions.jl/src/utils.jl Lines 144 to 145 in 992b665
KernelFunctions.jl/src/utils.jl Line 76 in 992b665
KernelFunctions.jl/src/utils.jl Line 146 in 992b665
On the other hand, julia> view(x, 1)
0-dimensional view(::Vector{SubArray{Float64, 1, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, true}}, 1) with eltype SubArray{Float64, 1, Matrix{Float64}, Tuple{Base.Slice{
Base.OneTo{Int64}}, Int64}, true}:
[0.832858822923345, 0.1486458121118549, 0.20187209965755426, 0.17211775415001118, 0.8813222986233952]
julia> view(x, 2:3)
2-element view(::Vector{SubArray{Float64, 1, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, true}}, 2:3) with eltype SubArray{Float64, 1, Matrix{Float64}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, true}:
[0.75958434210484, 0.28127270898481205, 0.11477999962460317, 0.6093522955819292, 0.30000872694236713]
[0.0028572719840013194, 0.6307387952125958, 0.25339090743930304, 0.2795101302467987, 0.5211441981223575] I think it would be reasonable to expect julia> all(y isa typeof(getindex(x, 1)) for y in view(x, 2:3))
true However, the exact return type of Base.view(x::ColVecs, i) = ColVecs(view(x.X, :, i))
Base.view(x::RowVecs, i) = RowVecs(view(x.X, :, i)) I'm not completely sure what to expect from |
We currently return a view to the underlying data when
getindex
is called on aColVecs
. SeeKernelFunctions.jl/src/utils.jl
Line 76 in 2d17212
@theogf was the last person to touch this bit of code, but I'm not sure who wrote it initially (I don't think it was me). Perhaps @devmotion ?
My concern is that if you do
getindex
, rather thanview
, my intuition is that I wouldn't get a view of the underlying data back, but a copy in a new location in memory. Any thoughts on whether my intuition is off, or should we change this?The text was updated successfully, but these errors were encountered: