Skip to content

Commit 6b8fe99

Browse files
committed
Disable allocations tests on multi-threaded
1 parent ee65db0 commit 6b8fe99

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

test/fasteval.jl

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -78,30 +78,35 @@ end
7878
end
7979

8080
@testset "FastLDF: performance" begin
81-
# Evaluating these three models should not lead to any allocations.
82-
@model function f()
83-
x ~ Normal()
84-
return 1.0 ~ Normal(x)
85-
end
86-
@model function submodel_inner()
87-
m ~ Normal(0, 1)
88-
s ~ Exponential()
89-
return (m=m, s=s)
90-
end
91-
# Note that for the allocation tests to work on this one, `inner` has
92-
# to be passed as an argument to `submodel_outer`, instead of just
93-
# being called inside the model function itself
94-
@model function submodel_outer(inner)
95-
params ~ to_submodel(inner)
96-
y ~ Normal(params.m, params.s)
97-
return 1.0 ~ Normal(y)
98-
end
99-
@testset for model in (f(), submodel_inner(), submodel_outer(submodel_inner()))
100-
vi = VarInfo(model)
101-
fldf = DynamicPPL.Experimental.FastLDF(model, DynamicPPL.getlogjoint_internal, vi)
102-
x = vi[:]
103-
bench = median(@be LogDensityProblems.logdensity(fldf, x))
104-
@test iszero(bench.allocs)
81+
if Threads.nthreads() == 1
82+
# Evaluating these three models should not lead to any allocations (but only when
83+
# not using TSVI).
84+
@model function f()
85+
x ~ Normal()
86+
return 1.0 ~ Normal(x)
87+
end
88+
@model function submodel_inner()
89+
m ~ Normal(0, 1)
90+
s ~ Exponential()
91+
return (m=m, s=s)
92+
end
93+
# Note that for the allocation tests to work on this one, `inner` has
94+
# to be passed as an argument to `submodel_outer`, instead of just
95+
# being called inside the model function itself
96+
@model function submodel_outer(inner)
97+
params ~ to_submodel(inner)
98+
y ~ Normal(params.m, params.s)
99+
return 1.0 ~ Normal(y)
100+
end
101+
@testset for model in (f(), submodel_inner(), submodel_outer(submodel_inner()))
102+
vi = VarInfo(model)
103+
fldf = DynamicPPL.Experimental.FastLDF(
104+
model, DynamicPPL.getlogjoint_internal, vi
105+
)
106+
x = vi[:]
107+
bench = median(@be LogDensityProblems.logdensity(fldf, x))
108+
@test iszero(bench.allocs)
109+
end
105110
end
106111
end
107112

0 commit comments

Comments
 (0)