@@ -2,36 +2,36 @@ abstract AbstractVectorOfArray{T, N} <: AbstractArray{T, N}
22
33# Based on code from M. Bauman Stackexchange answer + Gitter discussion
44type VectorOfArray{T, N, A} <: AbstractVectorOfArray{T, N}
5- data :: A # A <: AbstractVector{<: AbstractArray{T, N - 1}}
5+ u :: A # A <: AbstractVector{<: AbstractArray{T, N - 1}}
66end
77
88VectorOfArray {T, N} (vec:: AbstractVector{T} , dims:: NTuple{N} ) = VectorOfArray {eltype(T), N, typeof(vec)} (vec)
99# Assume that the first element is representative all all other elements
1010VectorOfArray (vec:: AbstractVector ) = VectorOfArray (vec, (size (vec[1 ])... , length (vec)))
1111
1212# Interface for the linear indexing. This is just a view of the underlying nested structure
13- @inline Base. endof (VA:: AbstractVectorOfArray ) = endof (VA. data )
14- @inline Base. length (VA:: AbstractVectorOfArray ) = length (VA. data )
13+ @inline Base. endof (VA:: AbstractVectorOfArray ) = endof (VA. u )
14+ @inline Base. length (VA:: AbstractVectorOfArray ) = length (VA. u )
1515# Linear indexing will be over the container elements, not the individual elements
1616# unlike an true AbstractArray
17- @inline Base. getindex {T, N} (VA:: AbstractVectorOfArray{T, N} , I:: Int ) = VA. data [I]
18- @inline Base. getindex {T, N} (VA:: AbstractVectorOfArray{T, N} , I:: Colon ) = VA. data [I]
19- @inline Base. getindex {T, N} (VA:: AbstractVectorOfArray{T, N} , I:: AbstractArray{Int} ) = VA. data [I]
17+ @inline Base. getindex {T, N} (VA:: AbstractVectorOfArray{T, N} , I:: Int ) = VA. u [I]
18+ @inline Base. getindex {T, N} (VA:: AbstractVectorOfArray{T, N} , I:: Colon ) = VA. u [I]
19+ @inline Base. getindex {T, N} (VA:: AbstractVectorOfArray{T, N} , I:: AbstractArray{Int} ) = VA. u [I]
2020
2121# Interface for the two dimensional indexing, a more standard AbstractArray interface
22- @inline Base. size (VA:: AbstractVectorOfArray ) = (size (VA. data [1 ])... , length (VA. data ))
23- @inline Base. getindex {T, N} (VA:: AbstractVectorOfArray{T, N} , I:: Vararg{Int, N} ) = VA. data [I[end ]][Base. front (I)... ]
22+ @inline Base. size (VA:: AbstractVectorOfArray ) = (size (VA. u [1 ])... , length (VA. u ))
23+ @inline Base. getindex {T, N} (VA:: AbstractVectorOfArray{T, N} , I:: Vararg{Int, N} ) = VA. u [I[end ]][Base. front (I)... ]
2424
2525# The iterator will be over the subarrays of the container, not the individual elements
2626# unlike an true AbstractArray
2727Base. start {T, N} (VA:: AbstractVectorOfArray{T, N} ) = 1
2828Base. next {T, N} (VA:: AbstractVectorOfArray{T, N} , state) = (VA[state], state + 1 )
29- Base. done {T, N} (VA:: AbstractVectorOfArray{T, N} , state) = state >= length (VA. data ) + 1
29+ Base. done {T, N} (VA:: AbstractVectorOfArray{T, N} , state) = state >= length (VA. u ) + 1
3030
3131# Growing the array simply adds to the container vector
32- Base. copy (VA:: AbstractVectorOfArray ) = typeof (VA)(copy (VA. data ))
33- Base. sizehint! {T, N} (VA:: AbstractVectorOfArray{T, N} , i) = sizehint! (VA. data , i)
34- Base. push! {T, N} (VA:: AbstractVectorOfArray{T, N} , new_item:: AbstractVector ) = push! (VA. data , new_item)
32+ Base. copy (VA:: AbstractVectorOfArray ) = typeof (VA)(copy (VA. u ))
33+ Base. sizehint! {T, N} (VA:: AbstractVectorOfArray{T, N} , i) = sizehint! (VA. u , i)
34+ Base. push! {T, N} (VA:: AbstractVectorOfArray{T, N} , new_item:: AbstractVector ) = push! (VA. u , new_item)
3535
3636function Base. append! {T, N} (VA:: AbstractVectorOfArray{T, N} , new_item:: AbstractVectorOfArray{T, N} )
3737 for item in copy (new_item)
@@ -41,4 +41,4 @@ function Base.append!{T, N}(VA::AbstractVectorOfArray{T, N}, new_item::AbstractV
4141end
4242
4343# conversion tools
44- vecarr_to_arr (VA:: AbstractVectorOfArray ) = cat (length (size (VA)), VA. data ... )
44+ vecarr_to_arr (VA:: AbstractVectorOfArray ) = cat (length (size (VA)), VA. u ... )
0 commit comments