From 6ab92ed3836b9ac9915b4a7edd3d88a993234815 Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Tue, 20 Feb 2024 11:58:46 -0600 Subject: [PATCH] add tests --- test/basic_indexing.jl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/basic_indexing.jl b/test/basic_indexing.jl index a6e0c77c..5a1e3b3d 100644 --- a/test/basic_indexing.jl +++ b/test/basic_indexing.jl @@ -232,3 +232,24 @@ mulX .= sqrt.(abs.(testva .* testvb)) a = ArrayPartition(1:5, 1:6) a[1:8] a[[1, 3, 8]] + +#################################################################### +# test when VectorOfArray is constructed from a linearly indexed +# multidimensional array of arrays +#################################################################### + +u_matrix = VectorOfArray(fill([1, 2], 2, 3)) +u_vector = VectorOfArray(vec(u_matrix.u)) + +# test broadcasting +function foo!(u) + @. u += 2 * u * abs(u) + return u +end +foo!(u_matrix) +foo!(u_vector) +@test u_matrix ≈ u_vector + +# test efficiency +num_allocs = @allocations foo!(u_matrix) +@test num_allocs == 0