Skip to content

Commit

Permalink
Accept Int32 offsets for VectorOfArrays (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
Moelf authored Jul 25, 2021
1 parent 9e6a9d2 commit eca846a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/vector_of_arrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ VectorOfArrays{T,N}(A::AbstractVector{<:AbstractArray})
VectorOfArrays(
data::AbstractVector,
elem_ptr::AbstractVector{Int},
elem_ptr::AbstractVector{<:Integer},
kernel_size::AbstractVector{<:Dims}
checks::Function = ArraysOfArrays.full_consistency_checks
)
Expand All @@ -44,7 +44,7 @@ and `ArraysOfArrays.no_consistency_checks`.
struct VectorOfArrays{
T, N, M,
VT<:AbstractVector{T},
VI<:AbstractVector{Int},
VI<:AbstractVector{<:Integer},
VD<:AbstractVector{Dims{M}}
} <: AbstractVector{Array{T,N}}
data::VT
Expand Down Expand Up @@ -73,7 +73,7 @@ struct VectorOfArrays{
) where {
T, M,
VT<:AbstractVector{T},
VI<:AbstractVector{Int},
VI<:AbstractVector{<:Integer},
VD<:AbstractVector{Dims{M}}
}
N = length((ntuple(_ -> 0, Val{M}())..., 0))
Expand Down Expand Up @@ -429,7 +429,7 @@ VectorOfVectors(A::AbstractVector{<:AbstractVector})
VectorOfVectors{T}(A::AbstractVector{<:AbstractVector}) where {T}
VectorOfVectors(
data::AbstractVector, elem_ptr::AbstractVector{Int},
data::AbstractVector, elem_ptr::AbstractVector{<:Integer},
checks::Function = full_consistency_checks
)
Expand All @@ -439,7 +439,7 @@ See also [VectorOfArrays](@ref).
const VectorOfVectors{
T,
VT<:AbstractVector{T},
VI<:AbstractVector{Int},
VI<:AbstractVector{<:Integer},
VD<:AbstractVector{Dims{0}}
} = VectorOfArrays{T,1,0,VT,VI,VD}

Expand All @@ -452,9 +452,9 @@ VectorOfVectors(A::AbstractVector{<:AbstractVector}) = VectorOfArrays(A)

VectorOfVectors(
data::AbstractVector,
elem_ptr::AbstractVector{Int},
elem_ptr::AbstractVector{I},
checks::Function = full_consistency_checks
) = VectorOfArrays(
) where I <: Integer= VectorOfArrays(
data,
elem_ptr,
similar(elem_ptr, Dims{0}, size(elem_ptr, 1) - 1),
Expand Down
3 changes: 3 additions & 0 deletions test/vector_of_arrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,14 @@ using ArraysOfArrays: full_consistency_checks, append_elemptr!, element_ptr
A = [1, 1, 2, 3, 3, 2, 2, 2]
A_grouped_ref = [[1, 1], [2], [3, 3], [2, 2, 2]]
elem_ptr = consgrouped_ptrs(A)
elem_ptr32 = Int32.(consgrouped_ptrs(A))
@test first.(@inferred(VectorOfVectors(A, elem_ptr))) == [1, 2, 3, 2]
@test first.(@inferred(VectorOfVectors(A, elem_ptr32))) == [1, 2, 3, 2]

B = [1, 2, 3, 4, 5, 6, 7, 8]
B_grouped_ref = [[1, 2], [3], [4, 5], [6, 7, 8]]
@test @inferred(VectorOfVectors(B, elem_ptr)) == B_grouped_ref
@test @inferred(VectorOfVectors(B, elem_ptr32)) == B_grouped_ref

C = [1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8]
C_grouped_ref = [[1.1, 2.2], [3.3], [4.4, 5.5], [6.6, 7.7, 8.8]]
Expand Down

0 comments on commit eca846a

Please sign in to comment.