Mercurial > repos > public > sbplib_julia
changeset 376:f65809a26a17
Merge performance/lazy_elementwise_operation
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 30 Sep 2020 21:09:35 +0200 |
parents | 99296cbb7bcd (current diff) b5444ae443a0 (diff) |
children | 8414c2334393 946516954c85 |
files | src/LazyTensors/lazy_array.jl |
diffstat | 1 files changed, 7 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/LazyTensors/lazy_array.jl Wed Sep 30 21:08:03 2020 +0200 +++ b/src/LazyTensors/lazy_array.jl Wed Sep 30 21:09:35 2020 +0200 @@ -47,20 +47,20 @@ A LazyElementwiseOperation contains two arrays together with an operation. The operations are carried out when the LazyElementwiseOperation is indexed. """ -struct LazyElementwiseOperation{T,D,Op} <: LazyArray{T,D} - a::AbstractArray{T,D} - b::AbstractArray{T,D} +struct LazyElementwiseOperation{T,D,Op,T1<:AbstractArray{T,D},T2<:AbstractArray{T,D}} <: LazyArray{T,D} + a::T1 + b::T2 - function LazyElementwiseOperation{T,D,Op}(a::AbstractArray{T,D},b::AbstractArray{T,D}) where {T,D,Op} + function LazyElementwiseOperation{T,D,Op}(a::T1,b::T2) where {T,D,Op,T1<:AbstractArray{T,D},T2<:AbstractArray{T,D}} @boundscheck if size(a) != size(b) throw(DimensionMismatch("dimensions must match")) end - return new{T,D,Op}(a,b) + return new{T,D,Op,T1,T2}(a,b) end - LazyElementwiseOperation{T,D,Op}(a::AbstractArray{T,D},b::T) where {T,D,Op} = new{T,D,Op}(a, LazyConstantArray(b, size(a))) - LazyElementwiseOperation{T,D,Op}(a::T,b::AbstractArray{T,D}) where {T,D,Op} = new{T,D,Op}(LazyConstantArray(a, size(b)), b) end +LazyElementwiseOperation{T,D,Op}(a::AbstractArray{T,D},b::T) where {T,D,Op} = LazyElementwiseOperation{T,D,Op}(a, LazyConstantArray(b, size(a))) +LazyElementwiseOperation{T,D,Op}(a::T,b::AbstractArray{T,D}) where {T,D,Op} = LazyElementwiseOperation{T,D,Op}(LazyConstantArray(a, size(b)), b) # TODO: Move Op to be the first parameter? Compare to Binary operations Base.size(v::LazyElementwiseOperation) = size(v.a)