|
77 | 77 |
|
78 | 78 | @testset "Summed" begin |
79 | 79 | elt = Float64 |
| 80 | + |
80 | 81 | a1 = randn(elt, 2, 2) |
81 | 82 | a2 = randn(elt, 2, 2) |
82 | | - |
83 | 83 | s = Summed(a1) |
84 | 84 | @test arguments(s) ≡ (a1,) |
85 | 85 | @test coefficients(s) ≡ (one(elt),) |
86 | 86 |
|
| 87 | + a1 = randn(elt, 2, 2) |
| 88 | + a2 = randn(elt, 2, 2) |
87 | 89 | s = -Summed(a1) |
88 | 90 | @test arguments(s) ≡ (a1,) |
89 | 91 | @test coefficients(s) ≡ (-one(elt),) |
90 | 92 |
|
| 93 | + a1 = randn(elt, 2, 2) |
| 94 | + a2 = randn(elt, 2, 2) |
91 | 95 | s = 2 * Summed(a1) |
92 | 96 | @test arguments(s) ≡ (a1,) |
93 | 97 | @test coefficients(s) ≡ (2 * one(elt),) |
94 | 98 |
|
| 99 | + a1 = randn(elt, 2, 2) |
| 100 | + a2 = randn(elt, 2, 2) |
95 | 101 | s = Summed(a1) * 2 |
96 | 102 | @test arguments(s) ≡ (a1,) |
97 | 103 | @test coefficients(s) ≡ (2 * one(elt),) |
98 | 104 |
|
| 105 | + a1 = randn(elt, 2, 2) |
| 106 | + a2 = randn(elt, 2, 2) |
99 | 107 | s = Summed(a1) / 2 |
100 | 108 | @test arguments(s) ≡ (a1,) |
101 | 109 | @test coefficients(s) ≡ (one(elt) / 2,) |
102 | 110 |
|
| 111 | + a1 = randn(elt, 2, 2) |
| 112 | + a2 = randn(elt, 2, 2) |
103 | 113 | s = 2 * Summed(a1) + 3 * Summed(a2) |
104 | 114 | @test arguments(s) ≡ (a1, a2) |
105 | 115 | @test coefficients(s) ≡ (2 * one(elt), 3 * one(elt)) |
106 | 116 |
|
| 117 | + a1 = randn(elt, 2, 2) |
| 118 | + a2 = randn(elt, 2, 2) |
107 | 119 | s = 2 * Summed(a1) - 3 * Summed(a2) |
108 | 120 | @test arguments(s) ≡ (a1, a2) |
109 | 121 | @test coefficients(s) ≡ (2 * one(elt), -3 * one(elt)) |
110 | 122 |
|
| 123 | + a1 = randn(elt, 2, 2) |
| 124 | + a2 = randn(elt, 2, 2) |
111 | 125 | s = 4 * (2 * Summed(a1) + 3 * Summed(a2)) |
112 | 126 | @test arguments(s) ≡ (a1, a2) |
113 | 127 | @test coefficients(s) ≡ (8 * one(elt), 12 * one(elt)) |
114 | 128 |
|
| 129 | + a1 = randn(elt, 2, 2) |
| 130 | + a2 = randn(elt, 2, 2) |
115 | 131 | @test Summed(a1) + a2 ≡ Summed(a1) + Summed(a2) |
116 | 132 | @test Summed(a1) - a2 ≡ Summed(a1) - Summed(a2) |
117 | 133 | @test a1 + Summed(a2) ≡ Summed(a1) + Summed(a2) |
118 | 134 | @test a1 - Summed(a2) ≡ Summed(a1) - Summed(a2) |
119 | 135 |
|
| 136 | + # Regression test mixed types |
| 137 | + a1 = [1, 2] |
| 138 | + a2 = [1.0, 2.0] |
| 139 | + s = Summed(a1) + Summed(a2) |
| 140 | + @test arguments(s) ≡ (a1, a2) |
| 141 | + @test coefficients(s) ≡ (1, 1.0) |
| 142 | + |
| 143 | + a1 = randn(elt, 2, 2) |
| 144 | + a2 = randn(elt, 2, 2) |
120 | 145 | s = 2 * Summed(a1) + 3 * Summed(a2) |
121 | 146 | @test arguments(s) ≡ (a1, a2) |
122 | 147 | @test coefficients(s) ≡ (2 * one(elt), 3 * one(elt)) |
|
137 | 162 | @test copyto!(similar(s), s) ≈ 2 * a1 + 3 * a2 |
138 | 163 | @test s[1, 2] ≈ 2 * a1[1, 2] + 3 * a2[1, 2] |
139 | 164 |
|
| 165 | + a1 = randn(elt, 2, 2) |
| 166 | + a2 = randn(elt, 2, 2) |
| 167 | + s = 2 * Summed(a1) + 3 * Summed(a2) |
140 | 168 | @test Broadcasted(s) isa Broadcasted |
141 | 169 | @test Broadcasted(s).style ≡ BroadcastStyle(typeof(a1)) |
142 | 170 | @test Broadcasted(s).f ≡ LinearCombination(s) |
|
0 commit comments