@@ -38,6 +38,7 @@ using SparseArraysBase: SparseArrayDOK, SparseMatrixDOK, SparseVectorDOK, stored
3838using TensorAlgebra: contract
3939using Test: @test , @test_broken , @test_throws , @testset , @inferred
4040using TestExtras: @constinferred
41+ using TypeParameterAccessors: TypeParameterAccessors, Position
4142include (" TestBlockSparseArraysUtils.jl" )
4243
4344arrayts = (Array, JLArray)
@@ -1084,13 +1085,53 @@ arrayts = (Array, JLArray)
10841085 @test storedlength (b) == 17
10851086 end
10861087 @testset " show" begin
1088+ vectort_elt = arrayt{elt,1 }
1089+ matrixt_elt = arrayt{elt,2 }
1090+ arrayt_elt = arrayt{elt,3 }
1091+
1092+ a = BlockSparseVector {elt,arrayt{elt,1}} ([2 , 2 ])
1093+ # Either option is possible depending on namespacing.
1094+ @test (
1095+ sprint (summary, a) ==
1096+ " 2-blocked 4-element BlockSparseVector{$(elt) , $(vectort_elt) , …}"
1097+ ) || (
1098+ sprint (summary, a) ==
1099+ " 2-blocked 4-element BlockSparseArrays.BlockSparseVector{$(elt) , $(vectort_elt) , …}"
1100+ )
1101+
1102+ a = BlockSparseMatrix {elt,arrayt{elt,2}} ([2 , 2 ], [2 , 2 ])
1103+ # Either option is possible depending on namespacing.
1104+ @test (
1105+ sprint (summary, a) == " 2×2-blocked 4×4 BlockSparseMatrix{$(elt) , $(matrixt_elt) , …}"
1106+ ) || (
1107+ sprint (summary, a) ==
1108+ " 2×2-blocked 4×4 BlockSparseArrays.BlockSparseMatrix{$(elt) , $(matrixt_elt) , …}"
1109+ )
1110+
1111+ a = BlockSparseArray {elt,3,arrayt{elt,3}} ([2 , 2 ], [2 , 2 ], [2 , 2 ])
1112+
1113+ # Either option is possible depending on namespacing.
1114+ @test (
1115+ sprint (summary, a) ==
1116+ " 2×2×2-blocked 4×4×4 BlockSparseArray{$(elt) , 3, $(arrayt_elt) , …}"
1117+ ) || (
1118+ sprint (summary, a) ==
1119+ " 2×2×2-blocked 4×4×4 BlockSparseArrays.BlockSparseArray{$(elt) , 3, $(arrayt_elt) , …}"
1120+ )
1121+
10871122 if elt === Float64
10881123 # Not testing other element types since they change the
10891124 # spacing so it isn't easy to make the test general.
1090- a = BlockSparseArray {elt} ([2 , 2 ], [2 , 2 ])
1091- a[1 , 2 ] = 12
1125+ a = BlockSparseMatrix {elt,arrayt{elt,2} } ([2 , 2 ], [2 , 2 ])
1126+ @allowscalar a[1 , 2 ] = 12
10921127 @test sprint (show, " text/plain" , a) ==
10931128 " $(summary (a)) :\n $(zero (eltype (a))) $(eltype (a)(12 )) │ . .\n $(zero (eltype (a))) $(zero (eltype (a))) │ . .\n ───────────┼──────\n . . │ . .\n . . │ . ."
10941129 end
10951130 end
1131+ @testset " TypeParameterAccessors.position" begin
1132+ @test TypeParameterAccessors. position (BlockSparseArray, eltype) == Position (1 )
1133+ @test TypeParameterAccessors. position (BlockSparseArray, ndims) == Position (2 )
1134+ @test TypeParameterAccessors. position (BlockSparseArray, blocktype) == Position (3 )
1135+ @test TypeParameterAccessors. position (BlockSparseArray, blockstype) == Position (4 )
1136+ end
10961137end
0 commit comments