comparison LazyTensors/src/lazy_operations.jl @ 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 9e737d19fcfe
comparison
equal deleted inserted replaced
198:b5c9be7f391c 199:a22b419bbdf0
51 """ 51 """
52 struct LazyElementwiseOperation{T,D,Op, T1<:AbstractArray{T,D}, T2 <: AbstractArray{T,D}} <: LazyArray{T,D} 52 struct LazyElementwiseOperation{T,D,Op, T1<:AbstractArray{T,D}, T2 <: AbstractArray{T,D}} <: LazyArray{T,D}
53 a::T1 53 a::T1
54 b::T2 54 b::T2
55 55
56 function LazyElementwiseOperation{T,D,Op}(a::T1,b::T2) where {T,D,Op, T1<:AbstractArray{T,D}, T2<:AbstractArray{T,D}} 56 @inline function LazyElementwiseOperation{T,D,Op}(a::T1,b::T2) where {T,D,Op, T1<:AbstractArray{T,D}, T2<:AbstractArray{T,D}}
57 # TODO: Remove boundscheck once assert can be turned off by
58 # optimization flags. Ugly fix.
59 # NOTE: Seems like adding the boundscheck introduces allocations. Can this
60 # be fixed? Since boundscheck is removed when inlined into inbounds this
61 # should not in practise effect performance.
62 @boundscheck @assert size(a)==size(b)
57 return new{T,D,Op,T1,T2}(a,b) 63 return new{T,D,Op,T1,T2}(a,b)
58 end 64 end
59 end 65 end
60 66
61 Base.size(v::LazyElementwiseOperation) = size(v.a) 67 Base.size(v::LazyElementwiseOperation) = size(v.a)
90 return leo.a[I...] / leo.b[I...] 96 return leo.a[I...] / leo.b[I...]
91 end 97 end
92 98
93 # Define lazy operations for AbstractArrays. Operations constructs a LazyElementwiseOperation which 99 # Define lazy operations for AbstractArrays. Operations constructs a LazyElementwiseOperation which
94 # can later be indexed into. Lazy operations are denoted by the usual operator followed by a tilde 100 # can later be indexed into. Lazy operations are denoted by the usual operator followed by a tilde
95 @inline +̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:+}(a,b) 101 Base.@propagate_inbounds +̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:+}(a,b)
96 @inline -̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:-}(a,b) 102 Base.@propagate_inbounds -̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:-}(a,b)
97 @inline *̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:*}(a,b) 103 Base.@propagate_inbounds *̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:*}(a,b)
98 @inline /̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:/}(a,b) 104 Base.@propagate_inbounds /̃(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D} = LazyElementwiseOperation{T,D,:/}(a,b)
99 105
100 106 Base.@propagate_inbounds Base.:+(a::LazyArray{T,D},b::AbstractArray{T,D}) where {T,D} = a +̃ b
101 Base.:+(a::LazyArray{T,D},b::AbstractArray{T,D}) where {T,D} = a +̃ b 107 Base.@propagate_inbounds Base.:+(a::AbstractArray{T,D}, b::LazyArray{T,D}) where {T,D} = b + a
102 Base.:+(a::AbstractArray{T,D}, b::LazyArray{T,D}) where {T,D} = b + a 108 Base.@propagate_inbounds Base.:-(a::LazyArray{T,D},b::AbstractArray{T,D}) where {T,D} = a -̃ b
103 Base.:-(a::LazyArray{T,D},b::AbstractArray{T,D}) where {T,D} = a -̃ b 109 Base.@propagate_inbounds Base.:-(a::AbstractArray{T,D}, b::LazyArray{T,D}) where {T,D} = a -̃ b
104 Base.:-(a::AbstractArray{T,D}, b::LazyArray{T,D}) where {T,D} = a -̃ b 110 Base.@propagate_inbounds Base.:*(a::LazyArray{T,D},b::AbstractArray{T,D}) where {T,D} = a *̃ b
105 Base.:*(a::LazyArray{T,D},b::AbstractArray{T,D}) where {T,D} = a *̃ b 111 Base.@propagate_inbounds Base.:*(a::AbstractArray{T,D},b::LazyArray{T,D}) where {T,D} = b * a
106 Base.:*(a::AbstractArray{T,D},b::LazyArray{T,D}) where {T,D} = b * a
107 # TODO: / seems to be ambiguous 112 # TODO: / seems to be ambiguous
108 # Base.:/(a::LazyArray{T,D},b::AbstractArray{T,D}) where {T,D} = a /̃ b 113 # Base.:/(a::LazyArray{T,D},b::AbstractArray{T,D}) where {T,D} = a /̃ b
109 # Base.:/(a::AbstractArray{T,D},b::LazyArray{T,D}) where {T,D} = a /̃ b 114 # Base.:/(a::AbstractArray{T,D},b::LazyArray{T,D}) where {T,D} = a /̃ b
110 115
111 export +̃, -̃, *̃, /̃ 116 export +̃, -̃, *̃, /̃