Mercurial > repos > public > sbplib_julia
comparison test/testLazyTensors.jl @ 489:1a7d6da3cc45
Merge feature/compose_identity_mappings
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Thu, 05 Nov 2020 11:32:49 +0100 |
parents | 8082d43103c1 |
children | cd509e57f898 df566372bb4f |
comparison
equal
deleted
inserted
replaced
473:3041f8578bba | 489:1a7d6da3cc45 |
---|---|
175 @test (s /̃ v1)[i] == 1/r_div_s[i] | 175 @test (s /̃ v1)[i] == 1/r_div_s[i] |
176 end | 176 end |
177 @test_throws BoundsError (v1 +̃ v2)[4] | 177 @test_throws BoundsError (v1 +̃ v2)[4] |
178 v2 = [1., 2, 3, 4] | 178 v2 = [1., 2, 3, 4] |
179 # Test that size of arrays is asserted when not specified inbounds | 179 # Test that size of arrays is asserted when not specified inbounds |
180 # TODO: Replace these errors with SizeMismatch | |
180 @test_throws DimensionMismatch v1 +̃ v2 | 181 @test_throws DimensionMismatch v1 +̃ v2 |
181 | 182 |
182 # Test operations on LazyArray | 183 # Test operations on LazyArray |
183 v1 = DummyArray([1, 2.3, 4]) | 184 v1 = DummyArray([1, 2.3, 4]) |
184 v2 = [1., 2, 3] | 185 v2 = [1., 2, 3] |
191 @test (v1 - v2)[i] == -(v2 - v1)[i] == r_sub_v[i] | 192 @test (v1 - v2)[i] == -(v2 - v1)[i] == r_sub_v[i] |
192 end | 193 end |
193 @test_throws BoundsError (v1 + v2)[4] | 194 @test_throws BoundsError (v1 + v2)[4] |
194 v2 = [1., 2, 3, 4] | 195 v2 = [1., 2, 3, 4] |
195 # Test that size of arrays is asserted when not specified inbounds | 196 # Test that size of arrays is asserted when not specified inbounds |
197 # TODO: Replace these errors with SizeMismatch | |
196 @test_throws DimensionMismatch v1 + v2 | 198 @test_throws DimensionMismatch v1 + v2 |
197 end | 199 end |
198 | 200 |
199 | 201 |
200 @testset "LazyFunctionArray" begin | 202 @testset "LazyFunctionArray" begin |
224 B̃ = LazyLinearMap(B, (1,), (2,)) | 226 B̃ = LazyLinearMap(B, (1,), (2,)) |
225 | 227 |
226 @test Ã∘B̃ isa TensorMappingComposition | 228 @test Ã∘B̃ isa TensorMappingComposition |
227 @test range_size(Ã∘B̃) == (2,) | 229 @test range_size(Ã∘B̃) == (2,) |
228 @test domain_size(Ã∘B̃) == (4,) | 230 @test domain_size(Ã∘B̃) == (4,) |
229 @test_throws DimensionMismatch B̃∘Ã | 231 @test_throws SizeMismatch B̃∘Ã |
230 | 232 |
231 # @test @inbounds B̃∘Ã # Should not error even though dimensions don't match. (Since ]test runs with forced boundschecking this is currently not testable 2020-10-16) | 233 # @test @inbounds B̃∘Ã # Should not error even though dimensions don't match. (Since ]test runs with forced boundschecking this is currently not testable 2020-10-16) |
232 | 234 |
233 v = rand(4) | 235 v = rand(4) |
234 @test Ã∘B̃*v ≈ A*B*v rtol=1e-14 | 236 @test Ã∘B̃*v ≈ A*B*v rtol=1e-14 |
310 @inferred (I'*v)[3,2] | 312 @inferred (I'*v)[3,2] |
311 @inferred range_size(I) | 313 @inferred range_size(I) |
312 | 314 |
313 @inferred range_dim(I) | 315 @inferred range_dim(I) |
314 @inferred domain_dim(I) | 316 @inferred domain_dim(I) |
317 | |
318 Ã = rand(4,2) | |
319 A = LazyLinearMap(Ã,(1,),(2,)) | |
320 I1 = IdentityMapping{Float64}(2) | |
321 I2 = IdentityMapping{Float64}(4) | |
322 @test A∘I1 == A | |
323 @test I2∘A == A | |
324 @test I1∘I1 == I1 | |
325 @test_throws SizeMismatch I1∘A | |
326 @test_throws SizeMismatch A∘I2 | |
327 @test_throws SizeMismatch I1∘I2 | |
315 end | 328 end |
316 | 329 |
317 @testset "InflatedTensorMapping" begin | 330 @testset "InflatedTensorMapping" begin |
318 I(sz...) = IdentityMapping(sz...) | 331 I(sz...) = IdentityMapping(sz...) |
319 | 332 |