Mercurial > repos > public > sbplib_julia
comparison LazyTensors/src/lazy_operations.jl @ 210:2aa33d0eef90 boundary_conditions
Add ability to add and subtract TensorMappings
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 25 Jun 2019 17:26:39 +0200 |
parents | 7db145ce6e4d |
children | a20bb4fac23d |
comparison
equal
deleted
inserted
replaced
209:7db145ce6e4d | 210:2aa33d0eef90 |
---|---|
58 throw(DimensionMismatch("dimensions must match")) | 58 throw(DimensionMismatch("dimensions must match")) |
59 end | 59 end |
60 return new{T,D,Op,T1,T2}(a,b) | 60 return new{T,D,Op,T1,T2}(a,b) |
61 end | 61 end |
62 end | 62 end |
63 # TODO: Move Op to be the first parameter? Compare to Binary operations | |
63 | 64 |
64 Base.size(v::LazyElementwiseOperation) = size(v.a) | 65 Base.size(v::LazyElementwiseOperation) = size(v.a) |
65 | 66 |
66 # TODO: Make sure boundschecking is done properly and that the lenght of the vectors are equal | 67 # TODO: Make sure boundschecking is done properly and that the lenght of the vectors are equal |
67 # NOTE: Boundschecking in getindex functions now assumes that the size of the | 68 # NOTE: Boundschecking in getindex functions now assumes that the size of the |
141 range_size(tmt::LazyTensorMappingTranspose{T,R,D}, d_size::NTuple{R,Integer}) where {T,R,D} = domain_size(tmt.tm, domain_size) | 142 range_size(tmt::LazyTensorMappingTranspose{T,R,D}, d_size::NTuple{R,Integer}) where {T,R,D} = domain_size(tmt.tm, domain_size) |
142 domain_size(tmt::LazyTensorMappingTranspose{T,R,D}, r_size::NTuple{D,Integer}) where {T,R,D} = range_size(tmt.tm, range_size) | 143 domain_size(tmt::LazyTensorMappingTranspose{T,R,D}, r_size::NTuple{D,Integer}) where {T,R,D} = range_size(tmt.tm, range_size) |
143 | 144 |
144 | 145 |
145 | 146 |
147 | |
148 struct LazyTensorMappingBinaryOperation{Op,T,R,D,T1<:TensorMapping{T,R,D},T2<:TensorMapping{T,R,D}} <: TensorMapping{T,D,R} | |
149 A::T1 | |
150 B::T2 | |
151 | |
152 @inline function LazyTensorMappingBinaryOperation{Op,T,R,D}(A::T1,B::T2) where {Op,T,R,D, T1<:TensorMapping{T,R,D},T2<:TensorMapping{T,R,D}} | |
153 return new{Op,T,R,D,T1,T2}(A,B) | |
154 end | |
155 end | |
156 | |
157 apply(mb::LazyTensorMappingBinaryOperation{:+,T,R,D}, v::AbstractArray{T,D}, I::Vararg) where {T,R,D} = apply(mb.A, v, I...) + apply(mb.B,v,I...) | |
158 apply(mb::LazyTensorMappingBinaryOperation{:-,T,R,D}, v::AbstractArray{T,D}, I::Vararg) where {T,R,D} = apply(mb.A, v, I...) - apply(mb.B,v,I...) | |
159 | |
160 range_size(mp::LazyTensorMappingBinaryOperation{Op,T,R,D}, domain_size::NTuple{D,Integer}) where {Op,T,R,D} = range_size(mp.A, domain_size) | |
161 domain_size(mp::LazyTensorMappingBinaryOperation{Op,T,R,D}, range_size::NTuple{R,Integer}) where {Op,T,R,D} = domain_size(mp.A, range_size) | |
162 | |
163 Base.:+(A::TensorMapping{T,R,D}, B::TensorMapping{T,R,D}) where {T,R,D} = LazyTensorMappingBinaryOperation{:+,T,R,D}(A,B) | |
164 Base.:-(A::TensorMapping{T,R,D}, B::TensorMapping{T,R,D}) where {T,R,D} = LazyTensorMappingBinaryOperation{:-,T,R,D}(A,B) | |
165 | |
166 | |
146 # TODO: Write tests and documentation for LazyTensorMappingComposition | 167 # TODO: Write tests and documentation for LazyTensorMappingComposition |
147 # struct LazyTensorMappingComposition{T,R,K,D} <: TensorMapping{T,R,D} | 168 # struct LazyTensorMappingComposition{T,R,K,D} <: TensorMapping{T,R,D} |
148 # t1::TensorMapping{T,R,K} | 169 # t1::TensorMapping{T,R,K} |
149 # t2::TensorMapping{T,K,D} | 170 # t2::TensorMapping{T,K,D} |
150 # end | 171 # end |