File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,23 @@ using LinearMaps
3
3
using SparseArrays
4
4
using LinearAlgebra
5
5
6
+ # adopted from: https://discourse.julialang.org/t/way-to-return-the-number-of-allocations/5167/10
7
+ macro numalloc (expr)
8
+ return quote
9
+ let
10
+ local f
11
+ function f ()
12
+ n1 = Base. gc_num ()
13
+ $ (expr)
14
+ n2 = Base. gc_num ()
15
+ diff = Base. GC_Diff (n2, n1)
16
+ Base. gc_alloc_count (diff)
17
+ end
18
+ f ()
19
+ end
20
+ end
21
+ end
22
+
6
23
import Base: *
7
24
import LinearAlgebra: issymmetric, mul!
8
25
@@ -185,10 +202,14 @@ end
185
202
end
186
203
187
204
CS! = LinearMap (cumsum!, 10 ; ismutating= true )
188
- v = rand (ComplexF64, 10 )
205
+ v = rand (10 )
189
206
u = similar (v)
190
207
mul! (u, CS!, v)
191
208
@test ((@allocated mul! (u, CS!, v)) == 0 )
209
+ n = 10
210
+ L = sum (fill (CS!, n))
211
+ @test mul! (u, L, v) ≈ n * cumsum (v)
212
+ @test ((@numalloc mul! (u, L, v)) <= 1 )
192
213
193
214
A = 2 * rand (ComplexF64, (10 , 10 )) .- 1
194
215
B = rand (size (A)... )
You can’t perform that action at this time.
0 commit comments