Mercurial > repos > public > sbplib_julia
comparison src/LazyTensors/lazy_tensor_operations.jl @ 1355:102ebdaf7c11 feature/variable_derivatives
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 08 Feb 2023 21:21:28 +0100 |
parents | fa0800591306 6f51160c7ca7 |
children | 49d03d1169ef |
comparison
equal
deleted
inserted
replaced
1210:fa0800591306 | 1355:102ebdaf7c11 |
---|---|
98 | 98 |
99 function apply_transpose(c::TensorComposition{T,R,K,D}, v::AbstractArray{<:Any,R}, I::Vararg{Any,D}) where {T,R,K,D} | 99 function apply_transpose(c::TensorComposition{T,R,K,D}, v::AbstractArray{<:Any,R}, I::Vararg{Any,D}) where {T,R,K,D} |
100 apply_transpose(c.t2, c.t1'*v, I...) | 100 apply_transpose(c.t2, c.t1'*v, I...) |
101 end | 101 end |
102 | 102 |
103 | |
104 """ | 103 """ |
105 TensorComposition(tm, tmi::IdentityTensor) | 104 TensorComposition(tm, tmi::IdentityTensor) |
106 TensorComposition(tmi::IdentityTensor, tm) | 105 TensorComposition(tmi::IdentityTensor, tm) |
107 | 106 |
108 Composes a `Tensormapping` `tm` with an `IdentityTensor` `tmi`, by returning `tm` | 107 Composes a `Tensormapping` `tm` with an `IdentityTensor` `tmi`, by returning `tm` |
120 function TensorComposition(tm::IdentityTensor{T,D}, tmi::IdentityTensor{T,D}) where {T,D} | 119 function TensorComposition(tm::IdentityTensor{T,D}, tmi::IdentityTensor{T,D}) where {T,D} |
121 @boundscheck check_domain_size(tm, range_size(tmi)) | 120 @boundscheck check_domain_size(tm, range_size(tmi)) |
122 return tmi | 121 return tmi |
123 end | 122 end |
124 | 123 |
124 Base.:*(a::T, tm::LazyTensor{T}) where T = TensorComposition(ScalingTensor{T,range_dim(tm)}(a,range_size(tm)), tm) | |
125 Base.:*(tm::LazyTensor{T}, a::T) where T = a*tm | |
125 | 126 |
126 """ | 127 """ |
127 InflatedTensor{T,R,D} <: LazyTensor{T,R,D} | 128 InflatedTensor{T,R,D} <: LazyTensor{T,R,D} |
128 | 129 |
129 An inflated `LazyTensor` with dimensions added before and afer its actual dimensions. | 130 An inflated `LazyTensor` with dimensions added before and afer its actual dimensions. |
270 LazyOuterProduct(tms::Vararg{LazyTensor}) = foldl(LazyOuterProduct, tms) | 271 LazyOuterProduct(tms::Vararg{LazyTensor}) = foldl(LazyOuterProduct, tms) |
271 | 272 |
272 | 273 |
273 | 274 |
274 """ | 275 """ |
275 inflate(tm, sz, dir) | 276 inflate(tm::LazyTensor, sz, dir) |
276 | 277 |
277 Inflate `tm` with identity tensors in all directions `d` for `d != dir`. | 278 Inflate `tm` such that it gets the size `sz` in all directions except `dir`. |
278 | 279 Here `sz[dir]` is ignored and replaced with the range and domains size of |
279 # TODO: Describe when it is useful | 280 `tm`. |
281 | |
282 An example of when this operation is useful is when extending a one | |
283 dimensional difference operator `D` to a 2D grid of a ceratin size. In that | |
284 case we could have | |
285 | |
286 ```julia | |
287 Dx = inflate(D, (10,10), 1) | |
288 Dy = inflate(D, (10,10), 2) | |
289 ``` | |
280 """ | 290 """ |
281 function inflate(tm::LazyTensor, sz, dir) | 291 function inflate(tm::LazyTensor, sz, dir) |
282 Is = IdentityTensor{eltype(tm)}.(sz) | 292 Is = IdentityTensor{eltype(tm)}.(sz) |
283 parts = Base.setindex(Is, tm, dir) | 293 parts = Base.setindex(Is, tm, dir) |
284 return foldl(⊗, parts) | 294 return foldl(⊗, parts) |