changeset 1001:a3df203861d3 refactor/lazy_tensors

Simplify some type parameter usage
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 18 Mar 2022 22:01:25 +0100
parents 1091ac8c69ad
children 271aa6ae1055
files src/LazyTensors/LazyTensors.jl src/LazyTensors/lazy_tensor_operations.jl
diffstat 2 files changed, 7 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/LazyTensors/LazyTensors.jl	Fri Mar 18 21:54:01 2022 +0100
+++ b/src/LazyTensors/LazyTensors.jl	Fri Mar 18 22:01:25 2022 +0100
@@ -22,8 +22,8 @@
 Base.:*(a::LazyTensor, args::Union{LazyTensor, AbstractArray}...) = foldr(*,(a,args...))
 
 # Addition and subtraction of lazy tensors
-Base.:+(tm1::LazyTensor{T,R,D}, tm2::LazyTensor{T,R,D}) where {T,R,D} = LazyTensorBinaryOperation{:+,T,R,D}(tm1,tm2)
-Base.:-(tm1::LazyTensor{T,R,D}, tm2::LazyTensor{T,R,D}) where {T,R,D} = LazyTensorBinaryOperation{:-,T,R,D}(tm1,tm2)
+Base.:+(s::LazyTensor, t::LazyTensor) = LazyTensorBinaryOperation{:+}(s,t)
+Base.:-(s::LazyTensor, t::LazyTensor) = LazyTensorBinaryOperation{:-}(s,t)
 
 # Composing lazy tensors
 Base.:∘(s::LazyTensor, t::LazyTensor) = LazyTensorComposition(s,t)
--- a/src/LazyTensors/lazy_tensor_operations.jl	Fri Mar 18 21:54:01 2022 +0100
+++ b/src/LazyTensors/lazy_tensor_operations.jl	Fri Mar 18 22:01:25 2022 +0100
@@ -1,6 +1,7 @@
 # TBD: Is there a good way to split this file?
 # TODO: Split out functions for composition
 # TODO: We need to be really careful about good error messages.
+# TODO: Go over type parameters
 
 """
     LazyTensorApplication{T,R,D} <: LazyArray{T,R}
@@ -58,12 +59,14 @@
     tm1::T1
     tm2::T2
 
-    @inline function LazyTensorBinaryOperation{Op,T,R,D}(tm1::T1,tm2::T2) where {Op,T,R,D, T1<:LazyTensor{T,R,D},T2<:LazyTensor{T,R,D}}
+    function LazyTensorBinaryOperation{Op,T,R,D}(tm1::T1,tm2::T2) where {Op,T,R,D, T1<:LazyTensor{T,R,D},T2<:LazyTensor{T,R,D}}
         return new{Op,T,R,D,T1,T2}(tm1,tm2)
     end
 end
 # TODO: Boundschecking in constructor.
 
+LazyTensorBinaryOperation{Op}(s,t) where Op = LazyTensorBinaryOperation{Op,eltype(s), range_dim(s), domain_dim(s)}(s,t)
+
 apply(tmBinOp::LazyTensorBinaryOperation{:+,T,R,D}, v::AbstractArray{<:Any,D}, I::Vararg{Any,R}) where {T,R,D} = apply(tmBinOp.tm1, v, I...) + apply(tmBinOp.tm2, v, I...)
 apply(tmBinOp::LazyTensorBinaryOperation{:-,T,R,D}, v::AbstractArray{<:Any,D}, I::Vararg{Any,R}) where {T,R,D} = apply(tmBinOp.tm1, v, I...) - apply(tmBinOp.tm2, v, I...)
 
@@ -80,7 +83,7 @@
     t1::TM1
     t2::TM2
 
-    @inline function LazyTensorComposition(t1::LazyTensor{T,R,K}, t2::LazyTensor{T,K,D}) where {T,R,K,D}
+    function LazyTensorComposition(t1::LazyTensor{T,R,K}, t2::LazyTensor{T,K,D}) where {T,R,K,D}
         @boundscheck check_domain_size(t1, range_size(t2))
         return new{T,R,K,D, typeof(t1), typeof(t2)}(t1,t2)
     end