@@ -2,36 +2,36 @@ abstract AbstractVectorOfArray{T, N} <: AbstractArray{T, N}
2
2
3
3
# Based on code from M. Bauman Stackexchange answer + Gitter discussion
4
4
type 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}}
6
6
end
7
7
8
8
VectorOfArray {T, N} (vec:: AbstractVector{T} , dims:: NTuple{N} ) = VectorOfArray {eltype(T), N, typeof(vec)} (vec)
9
9
# Assume that the first element is representative all all other elements
10
10
VectorOfArray (vec:: AbstractVector ) = VectorOfArray (vec, (size (vec[1 ])... , length (vec)))
11
11
12
12
# 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 )
15
15
# Linear indexing will be over the container elements, not the individual elements
16
16
# 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]
20
20
21
21
# 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)... ]
24
24
25
25
# The iterator will be over the subarrays of the container, not the individual elements
26
26
# unlike an true AbstractArray
27
27
Base. start {T, N} (VA:: AbstractVectorOfArray{T, N} ) = 1
28
28
Base. 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
30
30
31
31
# 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)
35
35
36
36
function Base. append! {T, N} (VA:: AbstractVectorOfArray{T, N} , new_item:: AbstractVectorOfArray{T, N} )
37
37
for item in copy (new_item)
@@ -41,4 +41,4 @@ function Base.append!{T, N}(VA::AbstractVectorOfArray{T, N}, new_item::AbstractV
41
41
end
42
42
43
43
# 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