changeset 1086:74c54996de6a

Merge feature/scalar_times_tensor
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Sun, 08 May 2022 11:35:22 +0200
parents 9abb140a4636 (current diff) d5a82a142d6a (diff)
children 2278730f9cee 95464a1af340 1e8270c18edb b4ee47f2aafb 5b3d4a8ec3ab
files
diffstat 2 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/LazyTensors/lazy_tensor_operations.jl	Fri Apr 08 19:36:22 2022 +0200
+++ b/src/LazyTensors/lazy_tensor_operations.jl	Sun May 08 11:35:22 2022 +0200
@@ -98,7 +98,6 @@
     apply_transpose(c.t2, c.t1'*v, I...)
 end
 
-
 """
     TensorComposition(tm, tmi::IdentityTensor)
     TensorComposition(tmi::IdentityTensor, tm)
@@ -120,6 +119,8 @@
     return tmi
 end
 
+Base.:*(a::T, tm::LazyTensor{T}) where T = TensorComposition(ScalingTensor{T,range_dim(tm)}(a,range_size(tm)), tm)
+Base.:*(tm::LazyTensor{T}, a::T) where T = a*tm
 
 """
     InflatedTensor{T,R,D} <: LazyTensor{T,R,D}
--- a/test/LazyTensors/lazy_tensor_operations_test.jl	Fri Apr 08 19:36:22 2022 +0200
+++ b/test/LazyTensors/lazy_tensor_operations_test.jl	Sun May 08 11:35:22 2022 +0200
@@ -181,6 +181,14 @@
 
     @test (Ã∘B̃*ComplexF64[1.,2.,3.,4.])[1] isa ComplexF64
     @test ((Ã∘B̃)'*ComplexF64[1.,2.])[1] isa ComplexF64
+
+    a = 2.
+    v = rand(3)
+    @test a*Ã isa TensorComposition
+    @test a*Ã == Ã*a
+    @test range_size(a*Ã) == range_size(Ã)
+    @test domain_size(a*Ã) == domain_size(Ã)
+    @test a*Ã*v == a.*A*v
 end