Mercurial > repos > public > sbplib_julia
comparison test/testLazyTensors.jl @ 377:8414c2334393 feature/lazy_linear_map
Start implementing LazyLinearMap
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 30 Sep 2020 21:15:42 +0200 |
parents | 241bd2512c20 |
children | 418cfd945715 |
comparison
equal
deleted
inserted
replaced
376:f65809a26a17 | 377:8414c2334393 |
---|---|
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 @testset "LazyFunctionArray" begin | 199 @testset "LazyFunctionArray" begin |
197 @test LazyFunctionArray(i->i^2, (3,)) == [1,4,9] | 200 @test LazyFunctionArray(i->i^2, (3,)) == [1,4,9] |
198 @test LazyFunctionArray((i,j)->i*j, (3,2)) == [ | 201 @test LazyFunctionArray((i,j)->i*j, (3,2)) == [ |
199 1 2; | 202 1 2; |
200 2 4; | 203 2 4; |
210 @test_throws BoundsError LazyFunctionArray((i,j)->i*j, (3,2))[4,2] | 213 @test_throws BoundsError LazyFunctionArray((i,j)->i*j, (3,2))[4,2] |
211 @test_throws BoundsError LazyFunctionArray((i,j)->i*j, (3,2))[2,3] | 214 @test_throws BoundsError LazyFunctionArray((i,j)->i*j, (3,2))[2,3] |
212 | 215 |
213 end | 216 end |
214 | 217 |
215 end | 218 @testset "LazyLinearMap" begin |
219 A = rand(3,4) | |
220 B = rand(3,4,2) | |
221 v = rand(4) | |
222 | |
223 @test LazyLinearMap(A, (1,), (2,)) isa LazyLinearMap{T,1,1} where T | |
224 @test LazyLinearMap(A, (1,), (2,)) isa TensorMapping{T,1,1} where T | |
225 @test LazyLinearMap(B, (1,2), (3,)) isa TensorMapping{T,2,1} where T | |
226 @test LazyLinearMap(B, (2), (3,1)) isa TensorMapping{T,1,2} where T | |
227 | |
228 | |
229 @test LazyLinearMap(A, (1,), (2,))*ones(4) == A*ones(4) | |
230 @test LazyLinearMap(A, (1,), (2,))*v == A*v | |
231 end | |
232 | |
233 end |