Skip to content

Commit

Permalink
Add TensorDirichlet benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterwln committed Jan 7, 2025
1 parent d8ccd98 commit c399f37
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ using ExponentialFamily.BayesBase

const SUITE = BenchmarkGroup()

include("benchmarks/bernoulli.jl")
include("benchmarks/bernoulli.jl")
include("benchmarks/tensordirichlet.jl")
36 changes: 36 additions & 0 deletions benchmark/benchmarks/tensordirichlet.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

SUITE["tensordirichlet"] = BenchmarkGroup(
["tensordirichlet", "distribution"],
"prod" => BenchmarkGroup(["prod", "multiplication"]),
"convert" => BenchmarkGroup(["convert"])
)

# `prod` BenchmarkGroup ========================
SUITE["tensordirichlet"]["prod"]["Closed"] = @benchmarkable prod(ClosedProd(), left, right) setup = begin
left, right = TensorDirichlet(rand(5, 5, 5)), TensorDirichlet(rand(5, 5, 5))
end
# ==============================================

# # `convert` BenchmarkGroup =====================
# SUITE["tensordirichlet"]["convert"]["Convert from D to EF"] = @benchmarkable convert(ExponentialFamilyDistribution, dist) setup = begin
# dist = TensorDirichlet(rand(5, 5, 5))
# end

# SUITE["tensordirichlet"]["convert"]["Convert from EF to D"] = @benchmarkable convert(Distribution, efdist) setup = begin
# efdist = convert(ExponentialFamilyDistribution, TensorDirichlet(rand(5, 5, 5)))
# end
# ==============================================

for rank in (3,)
for d in (2,)
distribution = TensorDirichlet(rand([d for _ in 1:rank]...))
sample = rand(d)
SUITE["tensordirichlet"]["mean"]["rank=$rank, d=$d"] = @benchmarkable mean($distribution)
SUITE["tensordirichlet"]["rand"]["rank=$rank, d=$d"] = @benchmarkable rand($distribution)
# SUITE["tensordirichlet"]["logpdf"]["rank=$rank, d=$d"] = @benchmarkable logpdf($distribution, $sample)
SUITE["tensordirichlet"]["var"]["rank=$rank, d=$d"] = @benchmarkable var($distribution)
SUITE["tensordirichlet"]["cov"]["rank=$rank, d=$d"] = @benchmarkable cov($distribution)
end
end

# ==============================================

0 comments on commit c399f37

Please sign in to comment.