Mercurial > repos > public > sbplib_julia
comparison src/LazyTensors/lazy_tensor_operations.jl @ 992:bc384aaade30 refactor/lazy_tensors
Add a bunch of todos and add a ScalingTensor
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 18 Mar 2022 17:28:07 +0100 |
parents | 043d13ef8898 |
children | 55ab7801c45f |
comparison
equal
deleted
inserted
replaced
988:83046af6143a | 992:bc384aaade30 |
---|---|
1 # TBD: Is there a good way to split this file? | |
2 | |
1 """ | 3 """ |
2 LazyTensorMappingApplication{T,R,D} <: LazyArray{T,R} | 4 LazyTensorMappingApplication{T,R,D} <: LazyArray{T,R} |
3 | 5 |
4 Struct for lazy application of a TensorMapping. Created using `*`. | 6 Struct for lazy application of a TensorMapping. Created using `*`. |
5 | 7 |
184 # Specialization for the case where tm is an IdentityMapping. Required to resolve ambiguity. | 186 # Specialization for the case where tm is an IdentityMapping. Required to resolve ambiguity. |
185 @inline function Base.:∘(tm::IdentityMapping{T,D}, tmi::IdentityMapping{T,D}) where {T,D} | 187 @inline function Base.:∘(tm::IdentityMapping{T,D}, tmi::IdentityMapping{T,D}) where {T,D} |
186 @boundscheck check_domain_size(tm, range_size(tmi)) | 188 @boundscheck check_domain_size(tm, range_size(tmi)) |
187 return tmi | 189 return tmi |
188 end | 190 end |
189 | 191 # TODO: Implement the above as TensorMappingComposition instead |
192 # TODO: Move the operator definitions to one place | |
193 | |
194 """ | |
195 ScalingTensor{T,D} <: TensorMapping{T,D,D} | |
196 | |
197 A Lazy tensor operator that scales its input with `λ`. | |
198 """ | |
199 struct ScalingTensor{T,D} <: TensorMapping{T,D,D} | |
200 λ::T | |
201 size::NTuple{D,Int} | |
202 end | |
203 | |
204 LazyTensors.apply(tm::ScalingTensor{T,D}, v::AbstractArray{<:Any,D}, I::Vararg{Any,D}) where {T,D} = tm.λ*v[I...] | |
205 LazyTensors.apply_transpose(tm::ScalingTensor{T,D}, v::AbstractArray{<:Any,D}, I::Vararg{Any,D}) where {T,D} = tm.λ*v[I...] | |
206 | |
207 LazyTensors.range_size(m::ScalingTensor) = m.size | |
208 LazyTensors.domain_size(m::ScalingTensor) = m.size | |
209 | |
210 # TODO: Rename everything with mapping | |
211 # TODO: Remove ScalingOperator from tests | |
190 | 212 |
191 """ | 213 """ |
192 InflatedTensorMapping{T,R,D} <: TensorMapping{T,R,D} | 214 InflatedTensorMapping{T,R,D} <: TensorMapping{T,R,D} |
193 | 215 |
194 An inflated `TensorMapping` with dimensions added before and afer its actual dimensions. | 216 An inflated `TensorMapping` with dimensions added before and afer its actual dimensions. |