@@ -4,7 +4,8 @@ using LazyArrays, FillArrays, LinearAlgebra, ArrayLayouts, SparseArrays, Test
44using StaticArrays
55import LazyArrays: CachedArray, CachedMatrix, CachedVector, PaddedLayout, CachedLayout, resizedata!, zero!,
66 CachedAbstractArray, CachedAbstractVector, CachedAbstractMatrix, AbstractCachedArray, AbstractCachedMatrix,
7- PaddedColumns, cacheddata, maybe_cacheddata
7+ PaddedColumns, cacheddata, LazyArrayStyle, maybe_cacheddata, Accumulate, CachedArrayStyle, GenericCachedLayout,
8+ AccumulateAbstractVector
89
910using .. InfiniteArrays
1011using . InfiniteArrays: OneToInf
@@ -529,6 +530,18 @@ using Infinities
529530 copyto! (dest, src)
530531 @test dest == res
531532 end
533+
534+ @testset " Avoid StackOverflow for recursive CachedArrayStyles" begin
535+ @test Matrix (view ((1 : 5 )' , :, 1 : 1 ) .* view (Accumulate (* , 1 : 5 )' , :, 1 : 1 )) == [1 ;;] # used to StackOverflow
536+ end
537+
538+ @testset " DualLayout{<:AbstractCachedLayout}" begin
539+ arg1 = view ((1 : 100 )' , :, 1 : 10 )
540+ arg2 = view (AccumulateAbstractVector (* , 1 : 100 )' , :, 1 : 10 )
541+ bc = Base. Broadcast. Broadcasted (CachedArrayStyle {2} (), * , (arg1, arg2))
542+ rsz_bc = LazyArrays. resize_bcargs! (bc);
543+ @test rsz_bc. args[2 ] == view (arg2. parent. parent. data' , :, 1 : 10 )
544+ end
532545 end
533546
534547 @testset " maybe_cacheddata" begin
@@ -539,6 +552,28 @@ using Infinities
539552 C = [1 , 2 , 3 ]
540553 @test maybe_cacheddata (C) === C
541554 end
555+
556+ @testset " Missing BroadcastStyles/MemoryLayouts/cacheddata with CachedArrayStyles" begin
557+ A = view (Accumulate (* , [1 , 2 , 3 ])' , 1 : 1 , 1 : 2 )
558+ B = view (transpose (Accumulate (* , [1 , 2im , 3 ])), 1 : 1 , 1 : 2 )
559+ C = Accumulate (* , [1 , 2im , 3 ])'
560+ D = transpose (Accumulate (* , [1 , 2im , 3 ]))
561+ E = view (Accumulate (* , [1 , 2im , 3 ])' , 1 : 1 , 1 : 2 )
562+ F = view (Accumulate (* , [1 , 2 , 3 ]), 1 : 2 )'
563+ G = view (Accumulate (* , [1 , 2im , 3 ])' , 1 : 1 , 1 : 2 )'
564+ @test all (== (CachedArrayStyle {1} ()), Base. BroadcastStyle .(typeof .((A, B, C, D, E, F, G))))
565+ @test all (== (GenericCachedLayout ()), MemoryLayout .(typeof .((A, B, E, G))))
566+ @test all (== (DualLayout {GenericCachedLayout} ()), MemoryLayout .(typeof .((C, D, F))))
567+ @test MemoryLayout (typeof (C)) == DualLayout {GenericCachedLayout} ()
568+ @test MemoryLayout (typeof (D)) == DualLayout {GenericCachedLayout} ()
569+ @test cacheddata (A) === view (cacheddata (parent (parent (A)))' , 1 : 1 , 1 : 1 )
570+ @test cacheddata (B) === view (transpose (cacheddata (parent (parent (B)))), 1 : 1 , 1 : 1 )
571+ @test cacheddata (C) === cacheddata (parent (C))'
572+ @test cacheddata (D) === transpose (cacheddata (parent (D)))
573+ @test cacheddata (E) === view (cacheddata (parent (parent (E)))' , 1 : 1 , 1 : 1 )
574+ @test cacheddata (F) === view (cacheddata (parent (parent (F))), 1 : 1 )'
575+ @test cacheddata (G) === adjoint (view (cacheddata (parent (G)), 1 : 1 , 1 : 1 ))
576+ end
542577end
543578
544579end # module
0 commit comments