changeset 207:f85a0b38f3ff boundary_conditions

Change error type when doing element wise operations on lazy arrays of missmatching dimension
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 24 Jun 2019 15:54:47 +0200
parents 7b0650021b36
children 992969237359
files LazyTensors/src/lazy_operations.jl LazyTensors/test/runtests.jl
diffstat 2 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/LazyTensors/src/lazy_operations.jl	Mon Jun 24 14:57:17 2019 +0200
+++ b/LazyTensors/src/lazy_operations.jl	Mon Jun 24 15:54:47 2019 +0200
@@ -54,12 +54,12 @@
     b::T2
 
     @inline function LazyElementwiseOperation{T,D,Op}(a::T1,b::T2) where {T,D,Op, T1<:AbstractArray{T,D}, T2<:AbstractArray{T,D}}
-        # TODO: Remove boundscheck once assert can be turned off by
-        # optimization flags. Ugly fix.
         # NOTE: Seems like adding the boundscheck introduces allocations. Can this
         # be fixed? Since boundscheck is removed when inlined into inbounds this
         # should not in practise effect performance.
-        @boundscheck @assert size(a)==size(b)
+        @boundscheck if size(a) != size(b)
+            throw(DimensionMismatch("dimensions must match"))
+        end
         return new{T,D,Op,T1,T2}(a,b)
     end
 end
--- a/LazyTensors/test/runtests.jl	Mon Jun 24 14:57:17 2019 +0200
+++ b/LazyTensors/test/runtests.jl	Mon Jun 24 15:54:47 2019 +0200
@@ -84,7 +84,7 @@
     @test_throws BoundsError (v1 +̃  v2)[4]
     v2 = [1., 2, 3, 4]
     # Test that size of arrays is asserted when not specified inbounds
-    @test_throws AssertionError v1 +̃ v2
+    @test_throws DimensionMismatch v1 +̃ v2
     # Test that no error checking is performed when specified inbounds
     res = (v1,v2) -> (@inbounds (v1 +̃ v2)[1] == 2)
     @test res(v1,v2)
@@ -103,7 +103,7 @@
     @test_throws BoundsError (v1 + v2)[4]
     v2 = [1., 2, 3, 4]
     # Test that size of arrays is asserted when not specified inbounds
-    @test_throws AssertionError v1 + v2
+    @test_throws DimensionMismatch v1 + v2
     # Test that no error checking is performed when specified inbounds
     res = (v1,v2) -> (@inbounds (v1 + v2)[1] == 2)
     @test res(v1,v2)