Mercurial > repos > public > sbplib_julia
comparison src/LazyTensors/lazy_tensor_operations.jl @ 412:d94891b8dfca feature/tensor_composition
Start implementing TensorComposition
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 15 Oct 2020 22:05:22 +0200 |
parents | 1936e38fe51e |
children | 814865d40f48 |
comparison
equal
deleted
inserted
replaced
410:26e186b565b3 | 412:d94891b8dfca |
---|---|
72 domain_size(tmBinOp::LazyTensorMappingBinaryOperation{Op,T,R,D}) where {Op,T,R,D} = domain_size(tmBinOp.tm1) | 72 domain_size(tmBinOp::LazyTensorMappingBinaryOperation{Op,T,R,D}) where {Op,T,R,D} = domain_size(tmBinOp.tm1) |
73 | 73 |
74 Base.:+(tm1::TensorMapping{T,R,D}, tm2::TensorMapping{T,R,D}) where {T,R,D} = LazyTensorMappingBinaryOperation{:+,T,R,D}(tm1,tm2) | 74 Base.:+(tm1::TensorMapping{T,R,D}, tm2::TensorMapping{T,R,D}) where {T,R,D} = LazyTensorMappingBinaryOperation{:+,T,R,D}(tm1,tm2) |
75 Base.:-(tm1::TensorMapping{T,R,D}, tm2::TensorMapping{T,R,D}) where {T,R,D} = LazyTensorMappingBinaryOperation{:-,T,R,D}(tm1,tm2) | 75 Base.:-(tm1::TensorMapping{T,R,D}, tm2::TensorMapping{T,R,D}) where {T,R,D} = LazyTensorMappingBinaryOperation{:-,T,R,D}(tm1,tm2) |
76 | 76 |
77 """ | |
78 TensorMappingComposition{T,R,K,D} | |
77 | 79 |
78 # TODO: Write tests and documentation for LazyTensorMappingComposition | 80 Lazily compose two TensorMappings, so that they can be handled as a single TensorMapping. |
79 # struct LazyTensorMappingComposition{T,R,K,D} <: TensorMapping{T,R,D} | 81 """ |
80 # t1::TensorMapping{T,R,K} | 82 struct TensorMappingComposition{T,R,K,D, TM1<:TensorMapping{T,R,K}, TM2<:TensorMapping{T,K,D}} <: TensorMapping{T,R,D} |
81 # t2::TensorMapping{T,K,D} | 83 t1::TM1 |
82 # end | 84 t2::TM2 |
83 | 85 |
84 # Base.:∘(s::TensorMapping{T,R,K}, t::TensorMapping{T,K,D}) where {T,R,K,D} = LazyTensorMappingComposition(s,t) | 86 # Add check for matching sizes as a boundscheck |
87 end | |
88 export TensorMappingComposition | |
85 | 89 |
86 # function range_size(tm::LazyTensorMappingComposition{T,R,K,D}, domain_size::NTuple{D,Integer}) where {T,R,K,D} | 90 range_size(tm::TensorMappingComposition) = range_size(tm.t1) |
87 # range_size(tm.t1, domain_size(tm.t2, domain_size)) | 91 domain_size(tm::TensorMappingComposition) = domain_size(tm.t2) |
88 # end | |
89 | 92 |
90 # function domain_size(tm::LazyTensorMappingComposition{T,R,K,D}, range_size::NTuple{R,Integer}) where {T,R,K,D} | 93 function apply(c::TensorMappingComposition{T,R,K,D}, v::AbstractArray{T,D}, I::Vararg{S,R} where S) where {T,R,K,D} |
91 # domain_size(tm.t1, domain_size(tm.t2, range_size)) | 94 apply(c.t1, LazyTensorMappingApplication(c.t2,v), I...) |
92 # end | 95 end |
93 | 96 |
94 # function apply(c::LazyTensorMappingComposition{T,R,K,D}, v::AbstractArray{T,D}, I::NTuple{R,Int}) where {T,R,K,D} | 97 function apply_transpose(c::TensorMappingComposition{T,R,K,D}, v::AbstractArray{T,R}, I::Vararg{S,D} where S) where {T,R,K,D} |
95 # apply(c.t1, LazyTensorMappingApplication(c.t2,v), I...) | 98 apply_transpose(c.t2, LazyTensorMappingApplication(c.t1',v), I...) |
96 # end | 99 end |
97 | 100 |
98 # function apply_transpose(c::LazyTensorMappingComposition{T,R,K,D}, v::AbstractArray{T,D}, I::NTuple{D,Int}) where {T,R,K,D} | 101 Base.:∘(s::TensorMapping, t::TensorMapping) = TensorMappingComposition(s,t) |
99 # apply_transpose(c.t2, LazyTensorMappingApplication(c.t1',v), I...) | |
100 # end | |
101 | 102 |
102 # # Have i gone too crazy with the type parameters? Maybe they aren't all needed? | |
103 | |
104 # export → | |
105 """ | 103 """ |
106 LazyLinearMap{T,R,D,...}(A, range_indicies, domain_indicies) | 104 LazyLinearMap{T,R,D,...}(A, range_indicies, domain_indicies) |
107 | 105 |
108 TensorMapping defined by the AbstractArray A. `range_indicies` and `domain_indicies` define which indicies of A should | 106 TensorMapping defined by the AbstractArray A. `range_indicies` and `domain_indicies` define which indicies of A should |
109 be considerd the range and domain of the TensorMapping. Each set of indices must be ordered in ascending order. | 107 be considerd the range and domain of the TensorMapping. Each set of indices must be ordered in ascending order. |