-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Description
What I think is a missing feature in Julia is the ability to work with unit-stride slices of Arrays, like Matrix columns or sections of Vectors, as Vectors with perfect compatibility and equal performance as Vectors. SubArrays and ArrayViews are more general and don't quite have the compatibility or performance yet.
I could make a PR if there is interest. Sample code:
# return aliased vector slice A[i:i-1+n]
function vectorslice(A::Array, i::Int, n::Int)
@assert 0 < i <= length(A)
@assert 0 <= n
@assert i-1+n <= length(A)
return pointer_to_array(pointer(A, i), n, true)::Vector
endjulia> x = randn(3,4)
3x4 Array{Float64,2}:
-1.0475 1.44511 -0.103864 -0.395006
-1.20736 0.935344 0.0891084 1.18014
0.725243 0.0379082 0.986568 -0.204709
julia> y = vectorslice(x,4,3)
3-element Array{Float64,1}:
1.44511
0.935344
0.0379082
julia> scale!(2,y)
3-element Array{Float64,1}:
2.89022
1.87069
0.0758164
julia> x
3x4 Array{Float64,2}:
-1.0475 2.89022 -0.103864 -0.395006
-1.20736 1.87069 0.0891084 1.18014
0.725243 0.0758164 0.986568 -0.204709Metadata
Metadata
Assignees
Labels
No labels