diff src/LazyTensors/lazy_tensor_operations.jl @ 429:46acb2560451 feature/lazy_identity

Start implementing LazyIdentity
author Jonatan Werpers <jonatan@werpers.com>
date Sun, 18 Oct 2020 22:30:17 +0200
parents 4aa59af074ef
children 541c16a8c791 904aae1899df
line wrap: on
line diff
--- a/src/LazyTensors/lazy_tensor_operations.jl	Sun Oct 18 22:21:43 2020 +0200
+++ b/src/LazyTensors/lazy_tensor_operations.jl	Sun Oct 18 22:30:17 2020 +0200
@@ -141,3 +141,24 @@
 function apply_transpose(llm::LazyLinearMap{T,R,D}, v::AbstractArray{T,R}, I::Vararg{Index,D}) where {T,R,D}
     apply(LazyLinearMap(llm.A, llm.domain_indicies, llm.range_indicies), v, I...)
 end
+
+
+"""
+    LazyIdentity{T,D} <: TensorMapping{T,D,D}
+
+The lazy identity TensorMapping for a given size. Usefull for building up higher dimensional tensor mappings from lower
+dimensional ones through outer products. Also used in the Implementation for InflatedTensorMapping.
+"""
+struct LazyIdentity{T,D} <: TensorMapping{T,D,D}
+    size::NTuple{D,Int}
+end
+export LazyIdentity
+
+LazyIdentity{T}(size::NTuple{D,Int}) where {T,D} = LazyIdentity{T,D}(size)
+
+range_size(tmi::LazyIdentity) = tmi.size
+domain_size(tmi::LazyIdentity) = tmi.size
+
+apply(tmi::LazyIdentity{T,D}, v::AbstractArray{T,D}, I::Vararg{Index,D}) where {T,D} = v[Int.(I)...]
+apply_transpose(tmi::LazyIdentity{T,D}, v::AbstractArray{T,D}, I::Vararg{Index,D}) where {T,D} = v[Int.(I)...]
+