Mercurial > repos > public > sbplib_julia
comparison src/LazyTensors/lazy_tensor_operations.jl @ 1594:d68d02dd882f feature/boundary_conditions
Merge with default
author | Vidar Stiernström <vidar.stiernstrom@gmail.com> |
---|---|
date | Sat, 25 May 2024 16:07:10 -0700 |
parents | bdcdbd4ea9cd d7bc11053951 |
children | 1388149b54ad |
comparison
equal
deleted
inserted
replaced
1591:615eeb6e662e | 1594:d68d02dd882f |
---|---|
3 | 3 |
4 Struct for lazy application of a LazyTensor. Created using `*`. | 4 Struct for lazy application of a LazyTensor. Created using `*`. |
5 | 5 |
6 Allows the result of a `LazyTensor` applied to a vector to be treated as an `AbstractArray`. | 6 Allows the result of a `LazyTensor` applied to a vector to be treated as an `AbstractArray`. |
7 With a mapping `m` and a vector `v` the TensorApplication object can be created by `m*v`. | 7 With a mapping `m` and a vector `v` the TensorApplication object can be created by `m*v`. |
8 The actual result will be calcualted when indexing into `m*v`. | 8 The actual result will be calculated when indexing into `m*v`. |
9 """ | 9 """ |
10 struct TensorApplication{T,R,D, TM<:LazyTensor{<:Any,R,D}, AA<:AbstractArray{<:Any,D}} <: LazyArray{T,R} | 10 struct TensorApplication{T,R,D, TM<:LazyTensor{<:Any,R,D}, AA<:AbstractArray{<:Any,D}} <: LazyArray{T,R} |
11 t::TM | 11 t::TM |
12 o::AA | 12 o::AA |
13 | 13 |
100 | 100 |
101 """ | 101 """ |
102 TensorComposition(tm, tmi::IdentityTensor) | 102 TensorComposition(tm, tmi::IdentityTensor) |
103 TensorComposition(tmi::IdentityTensor, tm) | 103 TensorComposition(tmi::IdentityTensor, tm) |
104 | 104 |
105 Composes a `Tensormapping` `tm` with an `IdentityTensor` `tmi`, by returning `tm` | 105 Composes a `LazyTensor` `tm` with an `IdentityTensor` `tmi`, by returning `tm` |
106 """ | 106 """ |
107 function TensorComposition(tm::LazyTensor{T,R,D}, tmi::IdentityTensor{T,D}) where {T,R,D} | 107 function TensorComposition(tm::LazyTensor{T,R,D}, tmi::IdentityTensor{T,D}) where {T,R,D} |
108 @boundscheck check_domain_size(tm, range_size(tmi)) | 108 @boundscheck check_domain_size(tm, range_size(tmi)) |
109 return tm | 109 return tm |
110 end | 110 end |
124 Base.:-(tm::LazyTensor{T}) where T = (-one(T))*tm | 124 Base.:-(tm::LazyTensor{T}) where T = (-one(T))*tm |
125 | 125 |
126 """ | 126 """ |
127 InflatedTensor{T,R,D} <: LazyTensor{T,R,D} | 127 InflatedTensor{T,R,D} <: LazyTensor{T,R,D} |
128 | 128 |
129 An inflated `LazyTensor` with dimensions added before and afer its actual dimensions. | 129 An inflated `LazyTensor` with dimensions added before and after its actual dimensions. |
130 """ | 130 """ |
131 struct InflatedTensor{T,R,D,D_before,R_middle,D_middle,D_after, TM<:LazyTensor{T,R_middle,D_middle}} <: LazyTensor{T,R,D} | 131 struct InflatedTensor{T,R,D,D_before,R_middle,D_middle,D_after, TM<:LazyTensor{T,R_middle,D_middle}} <: LazyTensor{T,R,D} |
132 before::IdentityTensor{T,D_before} | 132 before::IdentityTensor{T,D_before} |
133 tm::TM | 133 tm::TM |
134 after::IdentityTensor{T,D_after} | 134 after::IdentityTensor{T,D_after} |
218 | 218 |
219 | 219 |
220 @doc raw""" | 220 @doc raw""" |
221 LazyOuterProduct(tms...) | 221 LazyOuterProduct(tms...) |
222 | 222 |
223 Creates a `TensorComposition` for the outerproduct of `tms...`. | 223 Creates a `TensorComposition` for the outer product of `tms...`. |
224 This is done by separating the outer product into regular products of outer products involving only identity mappings and one non-identity mapping. | 224 This is done by separating the outer product into regular products of outer products involving only identity mappings and one non-identity mapping. |
225 | 225 |
226 First let | 226 First let |
227 ```math | 227 ```math |
228 \begin{aligned} | 228 \begin{aligned} |
277 Inflate `tm` such that it gets the size `sz` in all directions except `dir`. | 277 Inflate `tm` such that it gets the size `sz` in all directions except `dir`. |
278 Here `sz[dir]` is ignored and replaced with the range and domains size of | 278 Here `sz[dir]` is ignored and replaced with the range and domains size of |
279 `tm`. | 279 `tm`. |
280 | 280 |
281 An example of when this operation is useful is when extending a one | 281 An example of when this operation is useful is when extending a one |
282 dimensional difference operator `D` to a 2D grid of a ceratin size. In that | 282 dimensional difference operator `D` to a 2D grid of a certain size. In that |
283 case we could have | 283 case we could have |
284 | 284 |
285 ```julia | 285 ```julia |
286 Dx = inflate(D, (10,10), 1) | 286 Dx = inflate(D, (10,10), 1) |
287 Dy = inflate(D, (10,10), 2) | 287 Dy = inflate(D, (10,10), 2) |