Mercurial > repos > public > sbplib_julia
comparison test/testLazyTensors.jl @ 392:418cfd945715 feature/lazy_linear_map
Fix bug in range_size and domain_size for LazyLinearMap and expand the test
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Fri, 02 Oct 2020 13:43:36 +0200 |
parents | 8414c2334393 |
children | b14eacf823b6 |
comparison
equal
deleted
inserted
replaced
377:8414c2334393 | 392:418cfd945715 |
---|---|
191 v2 = [1., 2, 3, 4] | 191 v2 = [1., 2, 3, 4] |
192 # Test that size of arrays is asserted when not specified inbounds | 192 # Test that size of arrays is asserted when not specified inbounds |
193 @test_throws DimensionMismatch v1 + v2 | 193 @test_throws DimensionMismatch v1 + v2 |
194 end | 194 end |
195 | 195 |
196 end | |
197 | |
198 | 196 |
199 @testset "LazyFunctionArray" begin | 197 @testset "LazyFunctionArray" begin |
200 @test LazyFunctionArray(i->i^2, (3,)) == [1,4,9] | 198 @test LazyFunctionArray(i->i^2, (3,)) == [1,4,9] |
201 @test LazyFunctionArray((i,j)->i*j, (3,2)) == [ | 199 @test LazyFunctionArray((i,j)->i*j, (3,2)) == [ |
202 1 2; | 200 1 2; |
215 | 213 |
216 end | 214 end |
217 | 215 |
218 @testset "LazyLinearMap" begin | 216 @testset "LazyLinearMap" begin |
219 A = rand(3,4) | 217 A = rand(3,4) |
220 B = rand(3,4,2) | 218 B = rand(3,4,2) |
221 v = rand(4) | 219 v = rand(4) |
222 | 220 |
223 @test LazyLinearMap(A, (1,), (2,)) isa LazyLinearMap{T,1,1} where T | 221 Ã = LazyLinearMap(A, (1,), (2,)) |
224 @test LazyLinearMap(A, (1,), (2,)) isa TensorMapping{T,1,1} where T | 222 @test à isa LazyLinearMap{T,1,1} where T |
225 @test LazyLinearMap(B, (1,2), (3,)) isa TensorMapping{T,2,1} where T | 223 @test à isa TensorMapping{T,1,1} where T |
226 @test LazyLinearMap(B, (2), (3,1)) isa TensorMapping{T,1,2} where T | 224 |
227 | 225 @test Ã*ones(4) ≈ A*ones(4) atol=5e-13 |
228 | 226 @test Ã*v ≈ A*v atol=5e-13 |
229 @test LazyLinearMap(A, (1,), (2,))*ones(4) == A*ones(4) | 227 |
230 @test LazyLinearMap(A, (1,), (2,))*v == A*v | 228 B̃_21 = LazyLinearMap(B, (1,2), (3,)) |
231 end | 229 B̃_12 = LazyLinearMap(B, (2,), (3,1)) |
232 | 230 @test B̃_21 isa TensorMapping{T,2,1} where T |
233 end | 231 @test B̃_12 isa TensorMapping{T,1,2} where T |
232 @test B̃_21*ones(2) ≈ B[:,:,1] + B[:,:,2] atol=5e-13 | |
233 @test B̃_12*ones(3,2) ≈ B[1,:,1] + B[2,:,1] + B[3,:,1] + | |
234 B[1,:,2] + B[2,:,2] + B[3,:,2] atol=5e-13 | |
235 | |
236 end | |
237 | |
238 end |