comparison test/testLazyTensors.jl @ 371:241bd2512c20 feature/lazy_function

Add a LazyFunctionArray that evaluates a function for each index.
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 30 Sep 2020 19:48:17 +0200
parents 7fe43d902a27
children 8414c2334393 895ec483d741
comparison
equal deleted inserted replaced
370:8e55dee6a1a1 371:241bd2512c20
191 v2 = [1., 2, 3, 4] 191 v2 = [1., 2, 3, 4]
192 # Test that size of arrays is asserted when not specified inbounds 192 # Test that size of arrays is asserted when not specified inbounds
193 @test_throws DimensionMismatch v1 + v2 193 @test_throws DimensionMismatch v1 + v2
194 end 194 end
195 195
196 end 196 @testset "LazyFunctionArray" begin
197 @test LazyFunctionArray(i->i^2, (3,)) == [1,4,9]
198 @test LazyFunctionArray((i,j)->i*j, (3,2)) == [
199 1 2;
200 2 4;
201 3 6;
202 ]
203
204 @test size(LazyFunctionArray(i->i^2, (3,))) == (3,)
205 @test size(LazyFunctionArray((i,j)->i*j, (3,2))) == (3,2)
206
207 @inferred LazyFunctionArray(i->i^2, (3,))[2]
208
209 @test_throws BoundsError LazyFunctionArray(i->i^2, (3,))[4]
210 @test_throws BoundsError LazyFunctionArray((i,j)->i*j, (3,2))[4,2]
211 @test_throws BoundsError LazyFunctionArray((i,j)->i*j, (3,2))[2,3]
212
213 end
214
215 end