Mercurial > repos > public > sbplib_julia
comparison src/LazyTensors/lazy_tensor_operations.jl @ 436:cffdac9c612d bugfix/tensor_application_multiplication
Close branch before merge
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 19 Oct 2020 20:54:23 +0200 |
parents | 2808c41f5efa 2958b4ebd565 |
children | 907b0510699f |
comparison
equal
deleted
inserted
replaced
422:f0d6906d8937 | 436:cffdac9c612d |
---|---|
74 domain_size(tmBinOp::LazyTensorMappingBinaryOperation{Op,T,R,D}) where {Op,T,R,D} = domain_size(tmBinOp.tm1) | 74 domain_size(tmBinOp::LazyTensorMappingBinaryOperation{Op,T,R,D}) where {Op,T,R,D} = domain_size(tmBinOp.tm1) |
75 | 75 |
76 Base.:+(tm1::TensorMapping{T,R,D}, tm2::TensorMapping{T,R,D}) where {T,R,D} = LazyTensorMappingBinaryOperation{:+,T,R,D}(tm1,tm2) | 76 Base.:+(tm1::TensorMapping{T,R,D}, tm2::TensorMapping{T,R,D}) where {T,R,D} = LazyTensorMappingBinaryOperation{:+,T,R,D}(tm1,tm2) |
77 Base.:-(tm1::TensorMapping{T,R,D}, tm2::TensorMapping{T,R,D}) where {T,R,D} = LazyTensorMappingBinaryOperation{:-,T,R,D}(tm1,tm2) | 77 Base.:-(tm1::TensorMapping{T,R,D}, tm2::TensorMapping{T,R,D}) where {T,R,D} = LazyTensorMappingBinaryOperation{:-,T,R,D}(tm1,tm2) |
78 | 78 |
79 """ | |
80 TensorMappingComposition{T,R,K,D} | |
79 | 81 |
80 # TODO: Write tests and documentation for LazyTensorMappingComposition | 82 Lazily compose two TensorMappings, so that they can be handled as a single TensorMapping. |
81 # struct LazyTensorMappingComposition{T,R,K,D} <: TensorMapping{T,R,D} | 83 """ |
82 # t1::TensorMapping{T,R,K} | 84 struct TensorMappingComposition{T,R,K,D, TM1<:TensorMapping{T,R,K}, TM2<:TensorMapping{T,K,D}} <: TensorMapping{T,R,D} |
83 # t2::TensorMapping{T,K,D} | 85 t1::TM1 |
84 # end | 86 t2::TM2 |
85 | 87 |
86 # Base.:∘(s::TensorMapping{T,R,K}, t::TensorMapping{T,K,D}) where {T,R,K,D} = LazyTensorMappingComposition(s,t) | 88 @inline function TensorMappingComposition(t1::TensorMapping{T,R,K}, t2::TensorMapping{T,K,D}) where {T,R,K,D} |
89 @boundscheck if domain_size(t1) != range_size(t2) | |
90 throw(DimensionMismatch("the first argument has domain size $(domain_size(t1)) while the second has range size $(range_size(t2)) ")) | |
91 end | |
92 return new{T,R,K,D, typeof(t1), typeof(t2)}(t1,t2) | |
93 end | |
94 # Add check for matching sizes as a boundscheck | |
95 end | |
96 export TensorMappingComposition | |
87 | 97 |
88 # function range_size(tm::LazyTensorMappingComposition{T,R,K,D}, domain_size::NTuple{D,Integer}) where {T,R,K,D} | 98 range_size(tm::TensorMappingComposition) = range_size(tm.t1) |
89 # range_size(tm.t1, domain_size(tm.t2, domain_size)) | 99 domain_size(tm::TensorMappingComposition) = domain_size(tm.t2) |
90 # end | |
91 | 100 |
92 # function domain_size(tm::LazyTensorMappingComposition{T,R,K,D}, range_size::NTuple{R,Integer}) where {T,R,K,D} | 101 function apply(c::TensorMappingComposition{T,R,K,D}, v::AbstractArray{T,D}, I::Vararg{S,R} where S) where {T,R,K,D} |
93 # domain_size(tm.t1, domain_size(tm.t2, range_size)) | 102 apply(c.t1, c.t2*v, I...) |
94 # end | 103 end |
95 | 104 |
96 # function apply(c::LazyTensorMappingComposition{T,R,K,D}, v::AbstractArray{T,D}, I::NTuple{R,Int}) where {T,R,K,D} | 105 function apply_transpose(c::TensorMappingComposition{T,R,K,D}, v::AbstractArray{T,R}, I::Vararg{S,D} where S) where {T,R,K,D} |
97 # apply(c.t1, LazyTensorMappingApplication(c.t2,v), I...) | 106 apply_transpose(c.t2, c.t1'*v, I...) |
98 # end | 107 end |
99 | 108 |
100 # function apply_transpose(c::LazyTensorMappingComposition{T,R,K,D}, v::AbstractArray{T,D}, I::NTuple{D,Int}) where {T,R,K,D} | 109 Base.@propagate_inbounds Base.:∘(s::TensorMapping, t::TensorMapping) = TensorMappingComposition(s,t) |
101 # apply_transpose(c.t2, LazyTensorMappingApplication(c.t1',v), I...) | |
102 # end | |
103 | 110 |
104 # # Have i gone too crazy with the type parameters? Maybe they aren't all needed? | |
105 | |
106 # export → | |
107 """ | 111 """ |
108 LazyLinearMap{T,R,D,...}(A, range_indicies, domain_indicies) | 112 LazyLinearMap{T,R,D,...}(A, range_indicies, domain_indicies) |
109 | 113 |
110 TensorMapping defined by the AbstractArray A. `range_indicies` and `domain_indicies` define which indicies of A should | 114 TensorMapping defined by the AbstractArray A. `range_indicies` and `domain_indicies` define which indicies of A should |
111 be considerd the range and domain of the TensorMapping. Each set of indices must be ordered in ascending order. | 115 be considerd the range and domain of the TensorMapping. Each set of indices must be ordered in ascending order. |