diff LazyTensors/test/runtests.jl @ 204:9d9f7b0e514b boundary_conditions

Modify the implementation of elementwise operations to be more direct and add a few tests
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 24 Jun 2019 14:04:38 +0200
parents b5c9be7f391c
children 70e1f3401d82
line wrap: on
line diff
--- a/LazyTensors/test/runtests.jl	Thu Jun 20 23:28:02 2019 +0200
+++ b/LazyTensors/test/runtests.jl	Mon Jun 24 14:04:38 2019 +0200
@@ -56,3 +56,30 @@
     @test_broken BoundsError == (m*m*v)[0]
     @test_broken BoundsError == (m*m*v)[7]
 end
+
+
+@testset "Lazy elementwise operations" begin
+    struct DummyLazyArray{D} <: LazyArray{Int,D}
+        size::NTuple{D,Int}
+    end
+    Base.size(a::DummyLazyArray) = a.size
+    Base.getindex(a::DummyLazyArray, I...) = prod(I)
+
+
+    a = DummyLazyArray((3,))
+
+    @test (a+a)[3] == 6
+    @test (a-a)[3] == 0
+    @test (a*a)[3] == 9
+
+    a = DummyLazyArray((4,))
+    b = [3,2,1,2]
+
+    @test (a+b)[4] == 6
+    @test (a-b)[4] == 2
+    @test (a*b)[4] == 8
+
+    @test (b+a)[4] == 6
+    @test (b-a)[4] == -2
+    @test (b*a)[4] == 8
+end
\ No newline at end of file