changeset 196:b3c252280a19 boundary_conditions

Move LazyArray and make LazyTensorMappingApplication and LazyElementwiseOperation subtypes of it
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 20 Jun 2019 23:25:38 +0200
parents 5413067d2c4a
children a340fa91b1fc
files LazyTensors/src/lazy_operations.jl
diffstat 1 files changed, 13 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/LazyTensors/src/lazy_operations.jl	Thu Jun 20 23:14:46 2019 +0200
+++ b/LazyTensors/src/lazy_operations.jl	Thu Jun 20 23:25:38 2019 +0200
@@ -25,7 +25,17 @@
 
 
 """
-    LazyTensorMappingApplication{T,R,D} <: AbstractArray{T,R}
+    LazyArray{T,D} <: AbstractArray{T,D}
+
+Array which is calcualted lazily when indexing.
+
+A subtype of `LazyArray` will use lazy version of `+`, `-`, `*`, `/`.
+"""
+abstract type LazyArray{T,D} <: AbstractArray{T,D} end
+export LazyArray
+
+"""
+    LazyTensorMappingApplication{T,R,D} <: LazyArray{T,R}
 
 Struct for lazy application of a TensorMapping. Created using `*`.
 
@@ -33,7 +43,7 @@
 With a mapping `m` and a vector `v` the LazyTensorMappingApplication object can be created by `m*v`.
 The actual result will be calcualted when indexing into `m*v`.
 """
-struct LazyTensorMappingApplication{T,R,D} <: AbstractArray{T,R}
+struct LazyTensorMappingApplication{T,R,D} <: LazyArray{T,R}
     t::TensorMapping{T,R,D}
     o::AbstractArray{T,D}
 end
@@ -64,7 +74,7 @@
 together with an operation. The operations are carried out when the
 LazyElementwiseOperation is indexed.
 """
-struct LazyElementwiseOperation{T,D,Op, T1<:AbstractArray{T,D}, T2 <: AbstractArray{T,D}} <: AbstractArray{T,D}
+struct LazyElementwiseOperation{T,D,Op, T1<:AbstractArray{T,D}, T2 <: AbstractArray{T,D}} <: LazyArray{T,D}
     a::T1
     b::T2
 
@@ -112,9 +122,6 @@
 @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)
 
-# Abstract type for which the normal operations are defined by their
-# lazy counterparts
-abstract type LazyArray{T,D} <: AbstractArray{T,D} end
 
 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