changeset 485:4b49f03bdb98 feature/compose_identity_mappings

Switch from DimensionMismatch to SizeMismatch for boundschecks on compositions
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 05 Nov 2020 10:49:27 +0100
parents b995f056ad1f
children 8082d43103c1
files src/LazyTensors/lazy_tensor_operations.jl test/testLazyTensors.jl
diffstat 2 files changed, 11 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/LazyTensors/lazy_tensor_operations.jl	Thu Nov 05 10:47:31 2020 +0100
+++ b/src/LazyTensors/lazy_tensor_operations.jl	Thu Nov 05 10:49:27 2020 +0100
@@ -86,15 +86,15 @@
     t2::TM2
 
     @inline function TensorMappingComposition(t1::TensorMapping{T,R,K}, t2::TensorMapping{T,K,D}) where {T,R,K,D}
-        @boundscheck check_matching_size(t1::TensorMapping, t2::TensorMapping)
+        @boundscheck check_domain_size(t1, range_size(t2))
         return new{T,R,K,D, typeof(t1), typeof(t2)}(t1,t2)
     end
 end
 export TensorMappingComposition
 
-function check_matching_size(t1::TensorMapping, t2::TensorMapping)
-    if domain_size(t1) != range_size(t2)
-        throw(DimensionMismatch("the first argument has domain size $(domain_size(t1)) while the second has range size $(range_size(t2)) "))
+function check_domain_size(tm::TensorMapping, sz)
+    if domain_size(tm) != sz
+        throw(SizeMismatch(tm,sz))
     end
 end
 
@@ -192,17 +192,17 @@
 Composes a `Tensormapping` `tm` with an `IdentityMapping` `tmi`, by returning `tm`
 """
 @inline function Base.:∘(tm::TensorMapping{T,R,D}, tmi::IdentityMapping{T,D}) where {T,R,D}
-    @boundscheck check_matching_size(tm::TensorMapping, tmi::TensorMapping)
+    @boundscheck check_domain_size(tm, range_size(tmi))
     return tm
 end
 
 @inline function Base.:∘(tmi::IdentityMapping{T,R}, tm::TensorMapping{T,R,D}) where {T,R,D}
-    @boundscheck check_matching_size(tmi::TensorMapping, tm::TensorMapping)
+    @boundscheck check_domain_size(tmi, range_size(tm))
     return tm
 end
 # Specialization for the case where tm is an IdentityMapping. Required to resolve ambiguity.
 @inline function Base.:∘(tm::IdentityMapping{T,D}, tmi::IdentityMapping{T,D}) where {T,D}
-    @boundscheck check_matching_size(tm::TensorMapping, tmi::TensorMapping)
+    @boundscheck check_domain_size(tm, range_size(tmi))
     return tmi
 end
 
--- a/test/testLazyTensors.jl	Thu Nov 05 10:47:31 2020 +0100
+++ b/test/testLazyTensors.jl	Thu Nov 05 10:49:27 2020 +0100
@@ -226,7 +226,7 @@
     @test Ã∘B̃ isa TensorMappingComposition
     @test range_size(Ã∘B̃) == (2,)
     @test domain_size(Ã∘B̃) == (4,)
-    @test_throws DimensionMismatch B̃∘Ã
+    @test_throws SizeMismatch B̃∘Ã
 
     # @test @inbounds B̃∘Ã # Should not error even though dimensions don't match. (Since ]test runs with forced boundschecking this is currently not testable 2020-10-16)
 
@@ -320,9 +320,9 @@
     @test A∘I1 == A
     @test I2∘A == A
     @test I1∘I1 == I1
-    @test_throws DimensionMismatch I1∘A
-    @test_throws DimensionMismatch A∘I2
-    @test_throws DimensionMismatch I1∘I2
+    @test_throws SizeMismatch I1∘A
+    @test_throws SizeMismatch A∘I2
+    @test_throws SizeMismatch I1∘I2
 end
 
 @testset "InflatedTensorMapping" begin