Skip to content

Commit 7595fe6

Browse files
committed
more faffing around - testing for allocations does not seem to be reliable
1 parent 91e3ff9 commit 7595fe6

File tree

4 files changed

+27
-17
lines changed

4 files changed

+27
-17
lines changed

bench/benchmark.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function benchmark(GridType::Type, n_dims::Int; n_points_per_dim::Int=15, n_rand
3333
return trial
3434
end
3535

36-
verbosity = 1
36+
verbosity = 2
3737
for ndims in 1:6
3838

3939
println("\n##################################################")

src/GridInterpolations.jl

+24-15
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,21 @@ function interpolants(grid::RectangleGrid, x::AbstractVector)
164164
weight = MVector{num_points, eltype(x)}(undef)
165165
weight2 = MVector{num_points, eltype(x)}(undef)
166166

167-
# Note: these values are set explicitly because we have not verified that the logic below is independent of the initial values. See discussion in PR #47. These can be removed if it can be proved that the logic is independent of the initial values.
168-
index .= 1
169-
index2 .= 1
170-
weight .= zero(eltype(weight))
171-
weight2 .= zero(eltype(weight2))
167+
# # Note: these values are set explicitly because we have not verified that the logic below is independent of the initial values. See discussion in PR #47. These can be removed if it can be proved that the logic is independent of the initial values.
168+
for i in 1:num_points
169+
@inbounds index[i] = 1
170+
@inbounds index2[i] = 1
171+
@inbounds weight[i] = zero(eltype(x))
172+
@inbounds weight2[i] = zero(eltype(x))
173+
end
174+
175+
# index = @MVector ones(Int, num_points)
176+
# index2 = @MVector ones(Int, num_points)
177+
# weight = @MVector zeros(eltype(x), num_points)
178+
# weight2 = @MVector zeros(eltype(x), num_points)
172179

173-
weight[1] = one(eltype(weight))
174-
weight2[1] = one(eltype(weight2))
180+
@inbounds weight[1] = one(eltype(weight))
181+
@inbounds weight2[1] = one(eltype(weight2))
175182

176183
l = 1
177184
subblock_size = 1
@@ -288,16 +295,18 @@ function interpolants(grid::SimplexGrid, x::AbstractVector)
288295
# get weight
289296
for i = 1:(length(x_p)+1)
290297
if i == 1
291-
weight[i] = 1 - x_p[i]
298+
@inbounds weight[i] = 1 - x_p[i]
292299
elseif i == length(x_p) + 1
293-
weight[i] = x_p[i-1]
300+
@inbounds weight[i] = x_p[i-1]
294301
else
295-
weight[i] = x_p[i-1] - x_p[i]
302+
@inbounds weight[i] = x_p[i-1] - x_p[i]
296303
end
297304
end
298305

299306
# get indices
300-
fill!(index, 0)
307+
for i in 1:length(index)
308+
@inbounds index[i] = 0
309+
end
301310
i_index = 0
302311
for i = 1:(length(x_p)+1)
303312
siz = 1
@@ -310,17 +319,17 @@ function interpolants(grid::SimplexGrid, x::AbstractVector)
310319
onHi = ((i_index & good_count) > 0)
311320
good_count <<= 1
312321
if onHi
313-
index[i] += (ihi[k] - 1 - ct) * siz
322+
@inbounds index[i] += (ihi[k] - 1 - ct) * siz
314323
else
315-
index[i] += (ilo[k] - 1 - ct) * siz
324+
@inbounds index[i] += (ilo[k] - 1 - ct) * siz
316325
end
317326
siz = siz * cut_counts[k]
318327
ct += cut_counts[k]
319328
end
320-
index[i] += 1
329+
@inbounds index[i] += 1
321330
end
322331

323-
weight = weight ./ sum(weight)
332+
@inbounds weight = weight ./ sum(weight)
324333

325334
return SVector(index), SVector(weight)
326335
end

test/REQUIRE

-1
This file was deleted.

test/runtests.jl

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using LinearAlgebra
44
using Random
55
using DelimitedFiles
66
using BenchmarkTools
7+
using StaticArrays
78

89
# use import otherwise Interpolations.interpolate conflicts with GridInterpolations.interpolate
910
import Interpolations: BSpline, Linear, OnGrid, Flat
@@ -262,6 +263,7 @@ function test_rect_implemented()
262263
@test x == [5, 5]
263264

264265
@test interpolants(rgrid, [1, 1]) == ([1], [1.0])
266+
@show @ballocated(interpolants($rgrid, $([1,1])))
265267
@test @ballocated(interpolants($rgrid, $([1,1]))) == 0
266268
@test interpolants(rgrid, [2, 5]) == ([3], [1.0])
267269
@test @ballocated(interpolants($rgrid, $([2, 5]))) == 0

0 commit comments

Comments
 (0)