Mercurial > repos > public > sbplib_julia
comparison test/LazyTensors/lazy_array_test.jl @ 1858:4a9be96f2569 feature/documenter_logo
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sun, 12 Jan 2025 21:18:44 +0100 |
parents | 471a948cd2b2 |
children |
comparison
equal
deleted
inserted
replaced
1857:ffde7dad9da5 | 1858:4a9be96f2569 |
---|---|
1 using Test | 1 using Test |
2 using Sbplib.LazyTensors | 2 using Diffinitive.LazyTensors |
3 using Sbplib.RegionIndices | 3 using Diffinitive.RegionIndices |
4 | 4 |
5 | 5 |
6 @testset "LazyArray" begin | 6 @testset "LazyArray" begin |
7 @testset "LazyConstantArray" begin | 7 @testset "LazyConstantArray" begin |
8 @test LazyTensors.LazyConstantArray(3,(3,2)) isa LazyArray{Int,2} | 8 @test LazyTensors.LazyConstantArray(3,(3,2)) isa LazyArray{Int,2} |
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 |