changeset 199:a22b419bbdf0 boundary_conditions

Attempt fix for assertion inside constructor of LazyElementWiseOperation
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Sat, 22 Jun 2019 20:56:17 +0200
parents b5c9be7f391c
children c19bfad0e836
files LazyTensors/src/lazy_operations.jl
diffstat 1 files changed, 17 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/LazyTensors/src/lazy_operations.jl	Thu Jun 20 23:28:02 2019 +0200
+++ b/LazyTensors/src/lazy_operations.jl	Sat Jun 22 20:56:17 2019 +0200
@@ -53,7 +53,13 @@
     a::T1
     b::T2
 
-    function LazyElementwiseOperation{T,D,Op}(a::T1,b::T2) where {T,D,Op, T1<:AbstractArray{T,D}, T2<:AbstractArray{T,D}}
+    @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)
         return new{T,D,Op,T1,T2}(a,b)
     end
 end
@@ -92,18 +98,17 @@
 
 # Define lazy operations for AbstractArrays. Operations constructs a LazyElementwiseOperation which
 # can later be indexed into. Lazy operations are denoted by the usual operator followed by a tilde
-@inline +̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:+}(a,b)
-@inline -̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:-}(a,b)
-@inline *̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:*}(a,b)
-@inline /̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:/}(a,b)
-
+Base.@propagate_inbounds +̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:+}(a,b)
+Base.@propagate_inbounds -̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:-}(a,b)
+Base.@propagate_inbounds *̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:*}(a,b)
+Base.@propagate_inbounds /̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:/}(a,b)
 
-Base.:+(a::LazyArray{T,D},b::AbstractArray{T,D}) where {T,D} = a +̃ b
-Base.:+(a::AbstractArray{T,D}, b::LazyArray{T,D}) where {T,D} = b + a
-Base.:-(a::LazyArray{T,D},b::AbstractArray{T,D}) where {T,D} = a -̃ b
-Base.:-(a::AbstractArray{T,D}, b::LazyArray{T,D}) where {T,D} = a -̃ b
-Base.:*(a::LazyArray{T,D},b::AbstractArray{T,D}) where {T,D} = a *̃ b
-Base.:*(a::AbstractArray{T,D},b::LazyArray{T,D}) where {T,D} = b * a
+Base.@propagate_inbounds Base.:+(a::LazyArray{T,D},b::AbstractArray{T,D}) where {T,D} = a +̃ b
+Base.@propagate_inbounds Base.:+(a::AbstractArray{T,D}, b::LazyArray{T,D}) where {T,D} = b + a
+Base.@propagate_inbounds Base.:-(a::LazyArray{T,D},b::AbstractArray{T,D}) where {T,D} = a -̃ b
+Base.@propagate_inbounds Base.:-(a::AbstractArray{T,D}, b::LazyArray{T,D}) where {T,D} = a -̃ b
+Base.@propagate_inbounds Base.:*(a::LazyArray{T,D},b::AbstractArray{T,D}) where {T,D} = a *̃ b
+Base.@propagate_inbounds Base.:*(a::AbstractArray{T,D},b::LazyArray{T,D}) where {T,D} = b * a
 # TODO: / seems to be ambiguous
 # Base.:/(a::LazyArray{T,D},b::AbstractArray{T,D}) where {T,D} = a /̃ b
 # Base.:/(a::AbstractArray{T,D},b::LazyArray{T,D}) where {T,D} = a /̃ b