comparison test/LazyTensors/lazy_tensor_operations_test.jl @ 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 b12e28a03b2e
comparison
equal deleted inserted replaced
1837:200971c71657 1838:4bd998069053
180 @test_throws DomainSizeMismatch ScalingTensor(2.0, (4,)) + SizeDoublingMapping{Float64,1,1}((2,)) 180 @test_throws DomainSizeMismatch ScalingTensor(2.0, (4,)) + SizeDoublingMapping{Float64,1,1}((2,))
181 @test_throws DomainSizeMismatch SizeDoublingMapping{Float64,1,1}((2,)) + ScalingTensor(2.0, (4,)) 181 @test_throws DomainSizeMismatch SizeDoublingMapping{Float64,1,1}((2,)) + ScalingTensor(2.0, (4,))
182 @test_throws RangeSizeMismatch ScalingTensor(2.0, (2,)) + SizeDoublingMapping{Float64,1,1}((2,)) 182 @test_throws RangeSizeMismatch ScalingTensor(2.0, (2,)) + SizeDoublingMapping{Float64,1,1}((2,))
183 @test_throws RangeSizeMismatch SizeDoublingMapping{Float64,1,1}((2,)) + ScalingTensor(2.0, (2,)) 183 @test_throws RangeSizeMismatch SizeDoublingMapping{Float64,1,1}((2,)) + ScalingTensor(2.0, (2,))
184 end 184 end
185
186 @testset "Chained operators" begin
187 A = ScalingTensor(1.0, (3,))
188 B = ScalingTensor(2.0, (3,))
189 C = ScalingTensor(3.0, (3,))
190 D = ScalingTensor(4.0, (3,))
191
192 @test A+B+C+D isa TensorSum
193 @test length((A+B+C+D).tms) == 4
194
195
196 @test A+B-C+D isa TensorSum
197 @test length((A+B-C+D).tms) == 4
198
199 v = rand(3)
200 @test (A+B-C+D)*v == 1v + 2v - 3v + 4v
201
202
203 @test -A-B-C-D isa TensorSum
204 @test length((-A-B-C-D).tms) == 4
205
206 v = rand(3)
207 @test (-A-B-C-D)*v == -1v - 2v - 3v - 4v
208 end
185 end 209 end
186 210
187 211
188 @testset "TensorComposition" begin 212 @testset "TensorComposition" begin
189 A = rand(2,3) 213 A = rand(2,3)