changeset 1838:4bd998069053 refactor/lazy_tensors/elementwise_ops

Add tests for adding and subtracting several tensors at once
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 09 Jan 2025 21:54:45 +0100
parents 200971c71657
children e1077273eda5
files test/LazyTensors/lazy_tensor_operations_test.jl
diffstat 1 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/test/LazyTensors/lazy_tensor_operations_test.jl	Thu Jan 09 21:46:01 2025 +0100
+++ b/test/LazyTensors/lazy_tensor_operations_test.jl	Thu Jan 09 21:54:45 2025 +0100
@@ -182,6 +182,30 @@
         @test_throws RangeSizeMismatch ScalingTensor(2.0, (2,)) + SizeDoublingMapping{Float64,1,1}((2,))
         @test_throws RangeSizeMismatch SizeDoublingMapping{Float64,1,1}((2,)) + ScalingTensor(2.0, (2,))
     end
+
+    @testset "Chained operators" begin
+        A = ScalingTensor(1.0, (3,))
+        B = ScalingTensor(2.0, (3,))
+        C = ScalingTensor(3.0, (3,))
+        D = ScalingTensor(4.0, (3,))
+
+        @test A+B+C+D isa TensorSum
+        @test length((A+B+C+D).tms) == 4
+
+
+        @test A+B-C+D isa TensorSum
+        @test length((A+B-C+D).tms) == 4
+
+        v = rand(3)
+        @test (A+B-C+D)*v == 1v + 2v - 3v + 4v
+
+
+        @test -A-B-C-D isa TensorSum
+        @test length((-A-B-C-D).tms) == 4
+
+        v = rand(3)
+        @test (-A-B-C-D)*v == -1v - 2v - 3v - 4v
+    end
 end