|
194 | 194 | @inferred constructorof(typeof(lr1))(getfields(lr2)...) |
195 | 195 | end |
196 | 196 |
|
| 197 | + @testset "Cholesky" begin |
| 198 | + x = randn(3, 3) |
| 199 | + X = x * x' |
| 200 | + @testset "uplo=$uplo" for uplo in ['L', 'U'] |
| 201 | + C = Cholesky(X, uplo, 0) |
| 202 | + |
| 203 | + # Empty patch. |
| 204 | + C_new = ConstructionBase.setproperties(C, NamedTuple()) |
| 205 | + @test typeof(C_new) === typeof(C) |
| 206 | + for f in propertynames(C) |
| 207 | + @test getproperty(C_new, f) == getproperty(C, f) |
| 208 | + end |
| 209 | + |
| 210 | + # Update `L`. |
| 211 | + C_new = ConstructionBase.setproperties(C, (L=2 * C.L,)) |
| 212 | + @test typeof(C_new) === typeof(C) |
| 213 | + for f in propertynames(C) |
| 214 | + @test getproperty(C_new, f) == 2 * getproperty(C, f) |
| 215 | + end |
| 216 | + |
| 217 | + # Update `U`. |
| 218 | + C_new = ConstructionBase.setproperties(C, (U=2 * C.U,)) |
| 219 | + @test typeof(C_new) === typeof(C) |
| 220 | + for f in propertynames(C) |
| 221 | + @test getproperty(C_new, f) == 2 * getproperty(C, f) |
| 222 | + end |
| 223 | + |
| 224 | + # Update `UL` |
| 225 | + C_new = ConstructionBase.setproperties(C, (UL=2 * C.UL,)) |
| 226 | + @test typeof(C_new) === typeof(C) |
| 227 | + for f in propertynames(C) |
| 228 | + @test getproperty(C_new, f) == 2 * getproperty(C, f) |
| 229 | + end |
| 230 | + |
| 231 | + # We can only set the properties with `LowerTriangular` or `UpperTriangular` matrices. |
| 232 | + @test_throws ArgumentError ConstructionBase.setproperties(C, (L=parent(C.L),)) |
| 233 | + @test_throws ArgumentError ConstructionBase.setproperties(C, (U=parent(C.U),)) |
| 234 | + # Can only set one at the time. |
| 235 | + @test_throws ArgumentError ConstructionBase.setproperties(C, (L=C.L, U=C.U,)) |
| 236 | + @test_throws ArgumentError ConstructionBase.setproperties(C, (UL=C.UL, U=C.U,)) |
| 237 | + @test_throws ArgumentError ConstructionBase.setproperties(C, (UL=C.UL, L=C.L,)) |
| 238 | + # And make sure any other patch will fail. |
| 239 | + @test_throws ArgumentError ConstructionBase.setproperties(C, (asdf=C.UL,)) |
| 240 | + end |
| 241 | + end |
| 242 | + |
197 | 243 | @testset "Expr" begin |
198 | 244 | e = :(a + b) |
199 | 245 | @test e == @inferred constructorof(typeof(e))(getfields(e)...) |
|
0 commit comments