Mercurial > repos > public > sbplib_julia
comparison test/testLazyTensors.jl @ 394:7ad644d112de feature/lazy_linear_map
Expand tests for LazyLinearMap and update its documentation
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Fri, 02 Oct 2020 15:57:53 +0200 |
parents | b14eacf823b6 |
children | 3b4b1758a8ad |
comparison
equal
deleted
inserted
replaced
393:b14eacf823b6 | 394:7ad644d112de |
---|---|
215 | 215 |
216 @testset "LazyLinearMap" begin | 216 @testset "LazyLinearMap" begin |
217 # Test a standard matrix-vector product | 217 # Test a standard matrix-vector product |
218 # mapping vectors of size 4 to vectors of size 3. | 218 # mapping vectors of size 4 to vectors of size 3. |
219 A = rand(3,4) | 219 A = rand(3,4) |
220 Ã = LazyLinearMap(A, (1,), (2,)) | |
220 v = rand(4) | 221 v = rand(4) |
221 | 222 |
222 Ã = LazyLinearMap(A, (1,), (2,)) | |
223 @test à isa LazyLinearMap{T,1,1} where T | 223 @test à isa LazyLinearMap{T,1,1} where T |
224 @test à isa TensorMapping{T,1,1} where T | 224 @test à isa TensorMapping{T,1,1} where T |
225 @test range_size(Ã) == (3,) | |
226 @test domain_size(Ã) == (4,) | |
225 | 227 |
226 @test Ã*ones(4) ≈ A*ones(4) atol=5e-13 | 228 @test Ã*ones(4) ≈ A*ones(4) atol=5e-13 |
227 @test Ã*v ≈ A*v atol=5e-13 | 229 @test Ã*v ≈ A*v atol=5e-13 |
228 | 230 |
229 # Test more exotic mappings | 231 # Test more exotic mappings |
230 B = rand(3,4,2) | 232 B = rand(3,4,2) |
231 # Map vectors of size 2 to matrices of size (3,4) | 233 # Map vectors of size 2 to matrices of size (3,4) |
234 B̃ = LazyLinearMap(B, (1,2), (3,)) | |
232 v = rand(2) | 235 v = rand(2) |
233 B̃ = LazyLinearMap(B, (1,2), (3,)) | 236 |
237 @test range_size(B̃) == (3,4) | |
238 @test domain_size(B̃) == (2,) | |
234 @test B̃ isa TensorMapping{T,2,1} where T | 239 @test B̃ isa TensorMapping{T,2,1} where T |
235 @test B̃*ones(2) ≈ B[:,:,1] + B[:,:,2] atol=5e-13 | 240 @test B̃*ones(2) ≈ B[:,:,1] + B[:,:,2] atol=5e-13 |
236 @test B̃*v ≈ B[:,:,1]*v[1] + B[:,:,2]*v[2] atol=5e-13 | 241 @test B̃*v ≈ B[:,:,1]*v[1] + B[:,:,2]*v[2] atol=5e-13 |
237 | 242 |
238 # Map matrices of size (3,2) to vectors of size 4 | 243 # Map matrices of size (3,2) to vectors of size 4 |
239 B̃ = LazyLinearMap(B, (2,), (3,1)) | 244 B̃ = LazyLinearMap(B, (2,), (1,3)) |
240 v = rand(3,2) | 245 v = rand(3,2) |
246 | |
247 @test range_size(B̃) == (4,) | |
248 @test domain_size(B̃) == (3,2) | |
241 @test B̃ isa TensorMapping{T,1,2} where T | 249 @test B̃ isa TensorMapping{T,1,2} where T |
242 @test B̃*ones(3,2) ≈ B[1,:,1] + B[2,:,1] + B[3,:,1] + | 250 @test B̃*ones(3,2) ≈ B[1,:,1] + B[2,:,1] + B[3,:,1] + |
243 B[1,:,2] + B[2,:,2] + B[3,:,2] atol=5e-13 | 251 B[1,:,2] + B[2,:,2] + B[3,:,2] atol=5e-13 |
244 @test B̃*v ≈ B[1,:,1]*v[1,1] + B[2,:,1]*v[2,1] + B[3,:,1]*v[3,1] + | 252 @test B̃*v ≈ B[1,:,1]*v[1,1] + B[2,:,1]*v[2,1] + B[3,:,1]*v[3,1] + |
245 B[1,:,2]v[1,2] + B[2,:,2]*v[2,2] + B[3,:,2]*v[3,2] atol=5e-13 | 253 B[1,:,2]v[1,2] + B[2,:,2]*v[2,2] + B[3,:,2]*v[3,2] atol=5e-13 |