@@ -4,7 +4,7 @@ using LazyArrays, FillArrays, LinearAlgebra, ArrayLayouts, Test, Base64
44using StaticArrays
55import LazyArrays: MemoryLayout, DenseColumnMajor, materialize!, call, paddeddata,
66 MulAdd, Applied, ApplyLayout, DefaultApplyStyle, sub_materialize, resizedata!,
7- CachedVector, ApplyLayout, arguments, BroadcastVector, LazyLayout
7+ CachedVector, ApplyLayout, arguments, BroadcastVector, LazyLayout, cacheddata
88
99@testset " concat" begin
1010 @testset " Vcat" begin
@@ -199,11 +199,38 @@ import LazyArrays: MemoryLayout, DenseColumnMajor, materialize!, call, paddeddat
199199 @test A ≠ [1 ,2 ,4 ]
200200 end
201201
202- @testset " resizedata!" begin
203- # allow emulating a cached Vector
204- a = Vcat ([1 ,2 ], Zeros (8 ))
205- @test resizedata! (a, 2 ) ≡ a
206- @test_throws BoundsError resizedata! (a,3 )
202+ @testset " cached vcat" begin
203+ @testset " resizedata!" begin
204+ v = Vcat (1 , cache (1 : 10 ));
205+ resizedata! (v, 3 );
206+ @test v. args[2 ]. datasize == (2 ,)
207+ v = Vcat (1 , [2 , 4 , 6 ], cache (7 : 10 ), cache (1 : 5 ), 50 );
208+ resizedata! (v, 1 )
209+ @test v. args[3 ]. datasize == v. args[4 ]. datasize == (0 ,)
210+ resizedata! (v, 5 )
211+ @test v. args[3 ]. datasize == (1 ,)
212+ @test v. args[4 ]. datasize == (0 ,)
213+ resizedata! (v, 10 )
214+ @test v. args[3 ]. datasize == (4 ,)
215+ @test v. args[4 ]. datasize == (2 ,)
216+ resizedata! (v, 14 )
217+ @test v. args[3 ]. datasize == (4 ,)
218+ @test v. args[4 ]. datasize == (5 ,)
219+ resizedata! (v, 50 ) # test it doesn't break for excess resize
220+ @test v. args[3 ]. datasize == (4 ,)
221+ @test v. args[4 ]. datasize == (5 ,)
222+ end
223+
224+ @testset " cacheddata" begin
225+ v = Vcat (1 , cache (1 : 2 ))
226+ @test @inferred (cacheddata (v)) == [1 ]
227+ resizedata! (v, 2 )
228+ @test @inferred (cacheddata (v)) == [1 , 1 ]
229+ @test cacheddata (v) isa Vcat
230+ end
231+
232+ p = Vcat ([1 ,2 ], Zeros (4 ));
233+ # TODO : special behaviour?
207234 end
208235
209236 @testset " Axpy" begin
0 commit comments