|
1 |
| -using Test: @test, @test_throws |
| 1 | +using Test: @test, @test_throws, @testset |
2 | 2 |
|
3 |
| -using BlockArrays: Block, blocklength, blocklengths, blockedrange, blockisequal, blocks |
| 3 | +using BlockArrays: |
| 4 | + Block, BlockVector, blocklength, blocklengths, blockedrange, blockisequal, blocks |
4 | 5 | using TestExtras: @constinferred
|
5 | 6 |
|
6 | 7 | using TensorAlgebra: BlockedTuple, blockeachindex, tuplemortar
|
@@ -54,28 +55,70 @@ using TensorAlgebra: BlockedTuple, blockeachindex, tuplemortar
|
54 | 55 | BlockedTuple{3,blocklengths(bt)}(Tuple(bt) .+ 1)
|
55 | 56 | @test (@constinferred bt .+ tuplemortar(((1,), (1, 1), (1, 1)))) ==
|
56 | 57 | BlockedTuple{3,blocklengths(bt)}(Tuple(bt) .+ 1)
|
57 |
| - @test_throws DimensionMismatch bt .+ tuplemortar(((1, 1), (1, 1), (1,))) |
| 58 | + @test (@constinferred bt .+ tuplemortar(((1,), (1, 1, 1), (1,)))) isa |
| 59 | + BlockedTuple{4,(1, 2, 1, 1),NTuple{5,Int64}} |
| 60 | + @test bt .+ tuplemortar(((1,), (1, 1, 1), (1,))) == |
| 61 | + tuplemortar(((2,), (5, 3), (6,), (4,))) |
58 | 62 |
|
59 | 63 | bt = tuplemortar(((1:2, 1:2), (1:3,)))
|
60 | 64 | @test length.(bt) == tuplemortar(((2, 2), (3,)))
|
61 | 65 | @test length.(length.(bt)) == tuplemortar(((1, 1), (1,)))
|
62 | 66 |
|
| 67 | + bt = tuplemortar(((1,), (2,))) |
| 68 | + @test (@constinferred bt .== bt) isa BlockedTuple{2,(1, 1),Tuple{Bool,Bool}} |
| 69 | + @test (bt .== bt) == tuplemortar(((true,), (true,))) |
| 70 | + @test (@constinferred bt .== tuplemortar(((1, 2),))) isa |
| 71 | + BlockedTuple{2,(1, 1),Tuple{Bool,Bool}} |
| 72 | + @test (bt .== tuplemortar(((1, 2),))) == tuplemortar(((true,), (true,))) |
| 73 | + @test_throws DimensionMismatch bt .== tuplemortar(((1,), (2,), (3,))) |
| 74 | + @test (@constinferred bt .== (1, 2)) isa BlockedTuple{2,(1, 1),Tuple{Bool,Bool}} |
| 75 | + @test (bt .== (1, 2)) == tuplemortar(((true,), (true,))) |
| 76 | + @test_throws DimensionMismatch bt .== (1, 2, 3) |
| 77 | + @test (@constinferred bt .== 1) isa BlockedTuple{2,(1, 1),Tuple{Bool,Bool}} |
| 78 | + @test (bt .== 1) == tuplemortar(((true,), (false,))) |
| 79 | + @test (@constinferred bt .== (1,)) isa BlockedTuple{2,(1, 1),Tuple{Bool,Bool}} |
| 80 | + |
| 81 | + @test (bt .== (1,)) == tuplemortar(((true,), (false,))) |
| 82 | + # BlockedTuple .== AbstractVector is not type stable. Requires fix in BlockArrays |
| 83 | + @test (bt .== [1, 1]) isa BlockVector{Bool} |
| 84 | + @test blocks(bt .== [1, 1]) == [[true], [false]] |
| 85 | + @test_throws DimensionMismatch bt .== [1, 2, 3] |
| 86 | + |
| 87 | + @test (@constinferred (1, 2) .== bt) isa BlockedTuple{2,(1, 1),Tuple{Bool,Bool}} |
| 88 | + @test ((1, 2) .== bt) == tuplemortar(((true,), (true,))) |
| 89 | + @test_throws DimensionMismatch (1, 2, 3) .== bt |
| 90 | + @test (@constinferred 1 .== bt) isa BlockedTuple{2,(1, 1),Tuple{Bool,Bool}} |
| 91 | + @test (1 .== bt) == tuplemortar(((true,), (false,))) |
| 92 | + @test (@constinferred (1,) .== bt) isa BlockedTuple{2,(1, 1),Tuple{Bool,Bool}} |
| 93 | + @test ((1,) .== bt) == tuplemortar(((true,), (false,))) |
| 94 | + @test ([1, 1] .== bt) isa BlockVector{Bool} |
| 95 | + @test blocks([1, 1] .== bt) == [[true], [false]] |
| 96 | + |
63 | 97 | # empty blocks
|
64 | 98 | bt = tuplemortar(((1,), (), (5, 3)))
|
65 | 99 | @test bt isa BlockedTuple{3}
|
66 | 100 | @test Tuple(bt) == (1, 5, 3)
|
67 | 101 | @test blocklengths(bt) == (1, 0, 2)
|
68 | 102 | @test (@constinferred blocks(bt)) == ((1,), (), (5, 3))
|
| 103 | + @test blockisequal(only(axes(bt)), blockedrange([1, 0, 2])) |
69 | 104 |
|
70 | 105 | bt = tuplemortar(((), ()))
|
71 | 106 | @test bt isa BlockedTuple{2}
|
72 | 107 | @test Tuple(bt) == ()
|
73 | 108 | @test blocklengths(bt) == (0, 0)
|
74 | 109 | @test (@constinferred blocks(bt)) == ((), ())
|
75 |
| - |
76 |
| - bt = tuplemortar(()) |
77 |
| - @test bt isa BlockedTuple{0} |
78 |
| - @test Tuple(bt) == () |
79 |
| - @test blocklengths(bt) == () |
80 |
| - @test (@constinferred blocks(bt)) == () |
| 110 | + @test blockisequal(only(axes(bt)), blockedrange([0, 0])) |
| 111 | + @test bt == bt .+ bt |
| 112 | + |
| 113 | + bt0 = tuplemortar(()) |
| 114 | + bt1 = tuplemortar(((),)) |
| 115 | + @test bt0 isa BlockedTuple{0} |
| 116 | + @test Tuple(bt0) == () |
| 117 | + @test blocklengths(bt0) == () |
| 118 | + @test (@constinferred blocks(bt0)) == () |
| 119 | + @test blockisequal(only(axes(bt0)), blockedrange(zeros(Int, 0))) |
| 120 | + @test bt0 == bt0 |
| 121 | + @test bt != bt1 |
| 122 | + @test (@constinferred bt0 .+ bt0) == bt0 |
| 123 | + @test (@constinferred bt0 .+ bt1) == bt1 |
81 | 124 | end
|
0 commit comments