changeset 458:41f9cb6ee5a7 feature/inflated_tensormapping

Moar tests and moar type stableness
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 21 Oct 2020 20:57:38 +0200
parents 8fb6a5611c7a
children 11e58c49fb46 c364e2908c6e
files src/LazyTensors/lazy_tensor_operations.jl test/testLazyTensors.jl
diffstat 2 files changed, 17 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/LazyTensors/lazy_tensor_operations.jl	Wed Oct 21 20:10:27 2020 +0200
+++ b/src/LazyTensors/lazy_tensor_operations.jl	Wed Oct 21 20:57:38 2020 +0200
@@ -230,8 +230,8 @@
 ```
 """
 function split_index(itm::InflatedTensorMapping{T,R,D}, I::Vararg{Any,R}) where {T,R,D}
-    I_before = I[1:range_dim(itm.before)]
-    I_after = slice_tuple(I,Val(R-range_dim(itm.after)+1),Val(R))
+    I_before = slice_tuple(I, Val(1), Val(range_dim(itm.before)))
+    I_after = slice_tuple(I, Val(R-range_dim(itm.after)+1), Val(R))
 
     view_index = (I_before..., ntuple((i)->:,domain_dim(itm.tm))..., I_after...)
     inner_index = slice_tuple(I, Val(range_dim(itm.before)+1), Val(R-range_dim(itm.after)))
--- a/test/testLazyTensors.jl	Wed Oct 21 20:10:27 2020 +0200
+++ b/test/testLazyTensors.jl	Wed Oct 21 20:57:38 2020 +0200
@@ -349,7 +349,21 @@
 
     @inferred LazyTensors.split_index(tm,1,1,1,1)
 
-    @inferred (tm*v)[1,1,1,1]
+    struct ScalingOperator{T,D} <: TensorMapping{T,D,D}
+        λ::T
+        size::NTuple{D,Int}
+    end
+
+    LazyTensors.apply(m::ScalingOperator{T,D}, v, I::Vararg{Index,D}) where {T,D} = m.λ*v[I]
+    LazyTensors.range_size(m::ScalingOperator) = m.size
+    LazyTensors.domain_size(m::ScalingOperator) = m.size
+
+    tm = InflatedTensorMapping(I(2,3),ScalingOperator(2.0, (3,2)),I(3,4))
+    v = rand(domain_size(tm)...)
+
+    @inferred LazyTensors.split_index(tm,1,2,3,2,2,4)
+    @inferred apply(tm,v,Index{Unknown}.((1,2,3,2,2,4))...)
+    @inferred (tm*v)[1,2,3,2,2,4]
 
 end