diff src/LazyTensors/lazy_tensor_operations.jl @ 1073:5a3281429a48 feature/variable_derivatives

Merge feature/variable_derivatives
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 24 Mar 2022 12:35:14 +0100
parents 3bb94ce74697 f857057e61e6
children fa0800591306
line wrap: on
line diff
--- a/src/LazyTensors/lazy_tensor_operations.jl	Wed Mar 23 13:32:51 2022 +0100
+++ b/src/LazyTensors/lazy_tensor_operations.jl	Thu Mar 24 12:35:14 2022 +0100
@@ -270,6 +270,20 @@
 LazyOuterProduct(tms::Vararg{LazyTensor}) = foldl(LazyOuterProduct, tms)
 
 
+
+"""
+    inflate(tm, sz, dir)
+
+Inflate `tm` with identity tensors in all directions `d` for `d != dir`.
+
+# TODO: Describe when it is useful
+"""
+function inflate(tm::LazyTensor, sz, dir)
+    Is = IdentityTensor{eltype(tm)}.(sz)
+    parts = Base.setindex(Is, tm, dir)
+    return foldl(⊗, parts)
+end
+
 function check_domain_size(tm::LazyTensor, sz)
     if domain_size(tm) != sz
         throw(DomainSizeMismatch(tm,sz))