Mercurial > repos > public > sbplib_julia
comparison test/LazyTensors/lazy_array_test.jl @ 1888:eb70a0941cd6 allocation_testing
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 03 Feb 2023 23:02:46 +0100 |
parents | 805fa2ba837f |
children | 471a948cd2b2 |
comparison
equal
deleted
inserted
replaced
1887:24590890e124 | 1888:eb70a0941cd6 |
---|---|
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 |
93 | 100 |
94 @test_throws BoundsError LazyFunctionArray(i->i^2, (3,))[4] | 101 @test_throws BoundsError LazyFunctionArray(i->i^2, (3,))[4] |
95 @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] |
96 @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] |
97 | 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 | |
98 end | 108 end |