comparison src/LazyTensors/lazy_tensor_operations.jl @ 1221:b3b4d29b46c3 refactor/grids

Merge default
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 10 Feb 2023 08:36:56 +0100
parents 6f51160c7ca7
children 6567e38b05ca 102ebdaf7c11
comparison
equal deleted inserted replaced
1220:93bba649aea2 1221:b3b4d29b46c3
267 LazyOuterProduct(t1::IdentityTensor, t2::LazyTensor) = InflatedTensor(t1, t2) 267 LazyOuterProduct(t1::IdentityTensor, t2::LazyTensor) = InflatedTensor(t1, t2)
268 268
269 LazyOuterProduct(tms::Vararg{LazyTensor}) = foldl(LazyOuterProduct, tms) 269 LazyOuterProduct(tms::Vararg{LazyTensor}) = foldl(LazyOuterProduct, tms)
270 270
271 271
272
273 """
274 inflate(tm::LazyTensor, sz, dir)
275
276 Inflate `tm` such that it gets the size `sz` in all directions except `dir`.
277 Here `sz[dir]` is ignored and replaced with the range and domains size of
278 `tm`.
279
280 An example of when this operation is useful is when extending a one
281 dimensional difference operator `D` to a 2D grid of a ceratin size. In that
282 case we could have
283
284 ```julia
285 Dx = inflate(D, (10,10), 1)
286 Dy = inflate(D, (10,10), 2)
287 ```
288 """
289 function inflate(tm::LazyTensor, sz, dir)
290 Is = IdentityTensor{eltype(tm)}.(sz)
291 parts = Base.setindex(Is, tm, dir)
292 return foldl(⊗, parts)
293 end
294
272 function check_domain_size(tm::LazyTensor, sz) 295 function check_domain_size(tm::LazyTensor, sz)
273 if domain_size(tm) != sz 296 if domain_size(tm) != sz
274 throw(DomainSizeMismatch(tm,sz)) 297 throw(DomainSizeMismatch(tm,sz))
275 end 298 end
276 end 299 end