comparison test/LazyTensors/lazy_array_test.jl @ 1118:6104db60b7a3 feature/lazy_arrays

Export binary operations for LazyArrays and scalars
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Fri, 15 Jul 2022 15:23:16 +0200
parents 7ef605b8f132
children 805fa2ba837f
comparison
equal deleted inserted replaced
1111:5b3d4a8ec3ab 1118:6104db60b7a3
65 v1 = DummyArray([1, 2.3, 4]) 65 v1 = DummyArray([1, 2.3, 4])
66 v2 = [1., 2, 3] 66 v2 = [1., 2, 3]
67 @test isa(v1 + v2, LazyArray) 67 @test isa(v1 + v2, LazyArray)
68 @test isa(v2 + v1, LazyArray) 68 @test isa(v2 + v1, LazyArray)
69 @test isa(v1 - v2, LazyArray) 69 @test isa(v1 - v2, LazyArray)
70 @test isa(v2 - v1, LazyArray) 70 @test isa(v2 - v1, LazyArray)
71 @test isa(v1 + s, LazyArray)
72 @test isa(s + v1, LazyArray)
73 @test isa(v1 - s, LazyArray)
74 @test isa(s - v1, LazyArray)
71 for i ∈ eachindex(v2) 75 for i ∈ eachindex(v2)
72 @test (v1 + v2)[i] == (v2 + v1)[i] == r_add_v[i] 76 @test (v1 + v2)[i] == (v2 + v1)[i] == r_add_v[i]
73 @test (v1 - v2)[i] == -(v2 - v1)[i] == r_sub_v[i] 77 @test (v1 - v2)[i] == -(v2 - v1)[i] == r_sub_v[i]
78 @test (v1 + s)[i] == (s + v1)[i] == r_add_s[i]
79 @test (v1 - s)[i] == -(s - v1)[i] == r_sub_s[i]
74 end 80 end
81
75 @test_throws BoundsError (v1 + v2)[4] 82 @test_throws BoundsError (v1 + v2)[4]
76 v2 = [1., 2, 3, 4] 83 v2 = [1., 2, 3, 4]
77 @test_throws DimensionMismatch v1 + v2 84 @test_throws DimensionMismatch v1 + v2
78 end 85 end
79 86