Mercurial > repos > public > sbplib_julia
comparison src/LazyTensors/lazy_tensor_operations.jl @ 433:7327a3e41df0 feature/lazy_identity
Merge in default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Mon, 19 Oct 2020 09:50:16 +0200 |
parents | 541c16a8c791 2958b4ebd565 |
children | 648a36ebac99 |
comparison
equal
deleted
inserted
replaced
432:f24daf573bc6 | 433:7327a3e41df0 |
---|---|
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 @inline function TensorMappingComposition(t1::TensorMapping{T,R,K}, t2::TensorMapping{T,K,D}) where {T,R,K,D} |
87 @boundscheck if domain_size(t1) != range_size(t2) | |
88 throw(DimensionMismatch("the first argument has domain size $(domain_size(t1)) while the second has range size $(range_size(t2)) ")) | |
89 end | |
90 return new{T,R,K,D, typeof(t1), typeof(t2)}(t1,t2) | |
91 end | |
92 # Add check for matching sizes as a boundscheck | |
93 end | |
94 export TensorMappingComposition | |
85 | 95 |
86 # function range_size(tm::LazyTensorMappingComposition{T,R,K,D}, domain_size::NTuple{D,Integer}) where {T,R,K,D} | 96 range_size(tm::TensorMappingComposition) = range_size(tm.t1) |
87 # range_size(tm.t1, domain_size(tm.t2, domain_size)) | 97 domain_size(tm::TensorMappingComposition) = domain_size(tm.t2) |
88 # end | |
89 | 98 |
90 # function domain_size(tm::LazyTensorMappingComposition{T,R,K,D}, range_size::NTuple{R,Integer}) where {T,R,K,D} | 99 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)) | 100 apply(c.t1, c.t2*v, I...) |
92 # end | 101 end |
93 | 102 |
94 # function apply(c::LazyTensorMappingComposition{T,R,K,D}, v::AbstractArray{T,D}, I::NTuple{R,Int}) where {T,R,K,D} | 103 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...) | 104 apply_transpose(c.t2, c.t1'*v, I...) |
96 # end | 105 end |
97 | 106 |
98 # function apply_transpose(c::LazyTensorMappingComposition{T,R,K,D}, v::AbstractArray{T,D}, I::NTuple{D,Int}) where {T,R,K,D} | 107 Base.@propagate_inbounds Base.:∘(s::TensorMapping, t::TensorMapping) = TensorMappingComposition(s,t) |
99 # apply_transpose(c.t2, LazyTensorMappingApplication(c.t1',v), I...) | |
100 # end | |
101 | 108 |
102 # # Have i gone too crazy with the type parameters? Maybe they aren't all needed? | |
103 | |
104 # export → | |
105 """ | 109 """ |
106 LazyLinearMap{T,R,D,...}(A, range_indicies, domain_indicies) | 110 LazyLinearMap{T,R,D,...}(A, range_indicies, domain_indicies) |
107 | 111 |
108 TensorMapping defined by the AbstractArray A. `range_indicies` and `domain_indicies` define which indicies of A should | 112 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. | 113 be considerd the range and domain of the TensorMapping. Each set of indices must be ordered in ascending order. |