comparison test/LazyTensors/lazy_array_test.jl @ 1207:f1c2a4fa0ee1 performance/get_region_type_inference

Merge default
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 03 Feb 2023 22:14:47 +0100
parents 805fa2ba837f
children 471a948cd2b2
comparison
equal deleted inserted replaced
919:b41180efb6c2 1207:f1c2a4fa0ee1
57 @test (s *̃ v1)[i] == r_times_s[i] 57 @test (s *̃ v1)[i] == r_times_s[i]
58 @test (s /̃ v1)[i] == 1/r_div_s[i] 58 @test (s /̃ v1)[i] == 1/r_div_s[i]
59 end 59 end
60 @test_throws BoundsError (v1 +̃ v2)[4] 60 @test_throws BoundsError (v1 +̃ v2)[4]
61 v2 = [1., 2, 3, 4] 61 v2 = [1., 2, 3, 4]
62 # Test that size of arrays is asserted when not specified inbounds
63 # TODO: Replace these errors with SizeMismatch
64 @test_throws DimensionMismatch v1 +̃ v2 62 @test_throws DimensionMismatch v1 +̃ v2
65 63
66 # Test operations on LazyArray 64 # Test operations on LazyArray
67 v1 = DummyArray([1, 2.3, 4]) 65 v1 = DummyArray([1, 2.3, 4])
68 v2 = [1., 2, 3] 66 v2 = [1., 2, 3]
69 @test isa(v1 + v2, LazyArray) 67 @test isa(v1 + v2, LazyArray)
70 @test isa(v2 + v1, LazyArray) 68 @test isa(v2 + v1, LazyArray)
71 @test isa(v1 - v2, LazyArray) 69 @test isa(v1 - v2, LazyArray)
72 @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)
73 for i ∈ eachindex(v2) 75 for i ∈ eachindex(v2)
74 @test (v1 + v2)[i] == (v2 + v1)[i] == r_add_v[i] 76 @test (v1 + v2)[i] == (v2 + v1)[i] == r_add_v[i]
75 @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]
76 end 80 end
81
77 @test_throws BoundsError (v1 + v2)[4] 82 @test_throws BoundsError (v1 + v2)[4]
78 v2 = [1., 2, 3, 4] 83 v2 = [1., 2, 3, 4]
79 # Test that size of arrays is asserted when not specified inbounds
80 # TODO: Replace these errors with SizeMismatch
81 @test_throws DimensionMismatch v1 + v2 84 @test_throws DimensionMismatch v1 + v2
82 end 85 end
83 86
84 87
85 @testset "LazyFunctionArray" begin 88 @testset "LazyFunctionArray" begin
97 100
98 @test_throws BoundsError LazyFunctionArray(i->i^2, (3,))[4] 101 @test_throws BoundsError LazyFunctionArray(i->i^2, (3,))[4]
99 @test_throws BoundsError LazyFunctionArray((i,j)->i*j, (3,2))[4,2] 102 @test_throws BoundsError LazyFunctionArray((i,j)->i*j, (3,2))[4,2]
100 @test_throws BoundsError LazyFunctionArray((i,j)->i*j, (3,2))[2,3] 103 @test_throws BoundsError LazyFunctionArray((i,j)->i*j, (3,2))[2,3]
101 104
105 # Test that the constructor works with a restrictive function
106 f(x::Vararg{Int}) = sum(x)
107 @test LazyFunctionArray(f,(3,4)) isa LazyFunctionArray
102 end 108 end