changeset 399:3b4b1758a8ad feature/lazy_linear_map

Add a check for permuted indecies.
author Jonatan Werpers <jonatan@werpers.com>
date Sun, 04 Oct 2020 21:37:00 +0200
parents 7ad644d112de
children c640f37d1c74
files src/LazyTensors/lazy_tensor_operations.jl test/testLazyTensors.jl
diffstat 2 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/LazyTensors/lazy_tensor_operations.jl	Fri Oct 02 15:57:53 2020 +0200
+++ b/src/LazyTensors/lazy_tensor_operations.jl	Sun Oct 04 21:37:00 2020 +0200
@@ -114,6 +114,14 @@
     A::AA
     range_indicies::NTuple{R,Int}
     domain_indicies::NTuple{D,Int}
+
+    function LazyLinearMap(A::AA, range_indicies::NTuple{R,Int}, domain_indicies::NTuple{D,Int}) where {T,R,D, RD, AA<:AbstractArray{T,RD}}
+        if !issorted(range_indicies) || !issorted(domain_indicies)
+            throw(DomainError("range_indicies and domain_indicies must be sorted in ascending order"))
+        end
+
+        return new{T,R,D,RD,AA}(A,range_indicies,domain_indicies)
+    end
 end
 export LazyLinearMap
 
--- a/test/testLazyTensors.jl	Fri Oct 02 15:57:53 2020 +0200
+++ b/test/testLazyTensors.jl	Sun Oct 04 21:37:00 2020 +0200
@@ -228,6 +228,9 @@
     @test Ã*ones(4) ≈ A*ones(4) atol=5e-13
     @test Ã*v ≈ A*v atol=5e-13
 
+    A = rand(2,3,4)
+    @test_throws DomainError LazyLinearMap(A, (3,1), (2,))
+
     # Test more exotic mappings
     B = rand(3,4,2)
     # Map vectors of size 2 to matrices of size (3,4)