changeset 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
files src/LazyTensors/lazy_tensor_operations.jl test/testLazyTensors.jl
diffstat 2 files changed, 16 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
diff -r 8414c2334393 -r 418cfd945715 src/LazyTensors/lazy_tensor_operations.jl
--- a/src/LazyTensors/lazy_tensor_operations.jl	Wed Sep 30 21:15:42 2020 +0200
+++ b/src/LazyTensors/lazy_tensor_operations.jl	Fri Oct 02 13:43:36 2020 +0200
@@ -113,8 +113,8 @@
 end
 export LazyLinearMap
 
-range_size(llm::LazyLinearMap) = size(llm.A)[llm.range_indicies...]
-domain_size(llm::LazyLinearMap) = size(llm.A)[llm.domain_indicies...]
+range_size(llm::LazyLinearMap) = size(llm.A)[[llm.range_indicies...]]
+domain_size(llm::LazyLinearMap) = size(llm.A)[[llm.domain_indicies...]]
 
 function apply(llm::LazyLinearMap{T,R,D}, v::AbstractArray{T,D}, I::Vararg{Index,R}) where {T,R,D}
     view_index = ntuple(i->:,ndims(llm.A))
@@ -126,4 +126,3 @@
 
     return sum(A_view.*v)
 end
-
diff -r 8414c2334393 -r 418cfd945715 test/testLazyTensors.jl
--- a/test/testLazyTensors.jl	Wed Sep 30 21:15:42 2020 +0200
+++ b/test/testLazyTensors.jl	Fri Oct 02 13:43:36 2020 +0200
@@ -193,8 +193,6 @@
     @test_throws DimensionMismatch v1 + v2
 end
 
-end
-
 
 @testset "LazyFunctionArray" begin
     @test LazyFunctionArray(i->i^2, (3,)) == [1,4,9]
@@ -217,17 +215,24 @@
 
 @testset "LazyLinearMap" begin
     A = rand(3,4)
-    B = rand(3,4,2)
+	B = rand(3,4,2)
     v = rand(4)
 
-    @test LazyLinearMap(A, (1,), (2,)) isa LazyLinearMap{T,1,1} where T
-    @test LazyLinearMap(A, (1,), (2,)) isa TensorMapping{T,1,1} where T
-    @test LazyLinearMap(B, (1,2), (3,)) isa TensorMapping{T,2,1} where T
-    @test LazyLinearMap(B, (2), (3,1)) isa TensorMapping{T,1,2} where T
+	Ã = LazyLinearMap(A, (1,), (2,))
+    @test à isa LazyLinearMap{T,1,1} where T
+    @test à isa TensorMapping{T,1,1} where T
+
+	@test Ã*ones(4) ≈ A*ones(4) atol=5e-13
+	@test Ã*v ≈ A*v atol=5e-13
 
+	B̃_21 = LazyLinearMap(B, (1,2), (3,))
+	B̃_12 = LazyLinearMap(B, (2,), (3,1))
+	@test B̃_21 isa TensorMapping{T,2,1} where T
+    @test B̃_12 isa TensorMapping{T,1,2} where T
+	@test B̃_21*ones(2) ≈ B[:,:,1] + B[:,:,2] atol=5e-13
+	@test B̃_12*ones(3,2) ≈ B[1,:,1] + B[2,:,1] + B[3,:,1] +
+						   B[1,:,2] + B[2,:,2] + B[3,:,2] atol=5e-13
 
-    @test LazyLinearMap(A, (1,), (2,))*ones(4) == A*ones(4)
-    @test LazyLinearMap(A, (1,), (2,))*v == A*v
 end
 
 end