Mercurial > repos > public > sbplib_julia
comparison test/LazyTensors/lazy_array_test.jl @ 2057:8a2a0d678d6f feature/lazy_tensors/pretty_printing
Merge default
| author | Jonatan Werpers <jonatan@werpers.com> |
|---|---|
| date | Tue, 10 Feb 2026 22:41:19 +0100 |
| parents | 471a948cd2b2 |
| children |
comparison
equal
deleted
inserted
replaced
| 1110:c0bff9f6e0fb | 2057:8a2a0d678d6f |
|---|---|
| 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} |
| 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 |
