comparison test/inference_trouble_test.jl @ 1208:e679d4fab8ee performance/get_region_type_inference

Add some tests for allocations
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 03 Feb 2023 22:34:38 +0100
parents
children
comparison
equal deleted inserted replaced
1207:f1c2a4fa0ee1 1208:e679d4fab8ee
1 using Test
2 using Sbplib
3 using Sbplib.Grids
4 using Sbplib.SbpOperators
5 using Sbplib.RegionIndices
6 using BenchmarkTools
7
8 import Sbplib.SbpOperators: Stencil
9
10
11 @testset "First" begin
12 g = EquidistantGrid((10,10),(0.,0.), (1.,1.))
13 v = evalOn(g, (x,y)->x^2+y^2+1)
14 H = inner_product(g, 1., [1/2])
15
16 @test @ballocated(LazyTensors.apply($H.t1, $H.t2*$v, 1,2)) == 0
17 @test @ballocated(LazyTensors.apply($H.t1.tm, $(view(H.t2*v,:,1)), 2)) == 0
18
19 # Nedan är halvdåliga
20 @test @ballocated(LazyTensors.apply($H.t1.tm, $(view(H.t2*v,1,:)), 2)) == 0
21 @test @ballocated(LazyTensors.apply($H.t1.tm, $(view(v,1,:)), 2)) == 0
22 @test @ballocated(LazyTensors.apply($H.t1.tm, $(view(v,:,1)), 2)) == 0
23 @test @ballocated(LazyTensors.apply($H.t1.tm, $(v[:,1]), 2)) == 0
24 end
25
26 @testset "Second" begin
27 g = EquidistantGrid(10,0., 1.)
28 v = evalOn(g, (x)->x^2+1)
29 H = inner_product(g, 1., [1/2])
30 V = SbpOperators.VolumeOperator(g, Stencil(1.,center=1), (Stencil(1/2,center=1),), SbpOperators.even)
31 b = SbpOperators.BoundaryOperator(g, Stencil(1/2,center=1), Lower())
32
33 @test @ballocated(LazyTensors.apply($H, $H*$v, 2)) == 0
34 @test @ballocated(LazyTensors.apply($V, $V*$v, 2)) == 0
35 end
36