Skip to content

Conversation

@inkydragon
Copy link
Member

@inkydragon inkydragon commented Dec 13, 2024

Fix #99

  • Check overflow in multinomial. For large input, it will throw a OverflowError
  • Add new tests for large input and special case.
  • Update docs (Maybe it should be split into another pr)
julia> using Combinatorics

julia> using BenchmarkTools

julia> @benchmark multinomial(10,10,10,5) evals=2000
BenchmarkTools.Trial: 10000 samples with 2000 evaluations.
 Range (min  max):  170.350 ns  514.200 ns  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     178.400 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   182.391 ns ±  17.635 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  ▆▅▄▃▆█▇▅▄▄▄▃▃▂▁▁▁▁                                            ▂
  ███████████████████▇█▇▇▇▆▇▆▅▇▆▇▅▆▅▆▅▆▆▅▄▅▅▄▆▅▆▅▅▅▅▆▆▅▅▆▅▄▄▅▄▃ █
  170 ns        Histogram: log(frequency) by time        263 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

julia> @benchmark multinomial_pr(10,10,10,5) evals=2000
BenchmarkTools.Trial: 10000 samples with 2000 evaluations.
 Range (min  max):  170.500 ns  557.450 ns  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     178.500 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   183.319 ns ±  21.158 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  █▇▅▇█▇▆▅▅▄▄▃▂▂▂▁▁▁▁                                           ▂
  ████████████████████▇▇█▇█▆▆█▇▇▇▆▆▇▆▆▇▇▆▇▇▆▅▆▇▇▇▆▆▅▆▇▆▅▆▆▅▄▃▄▄ █
  170 ns        Histogram: log(frequency) by time        273 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

Multinomial coefficient where `n = sum(k)`.
Compute the multinomial coefficient
``\\binom{n}{k_1,k_2,...,k_i} = \\frac{n!}{k_1!k_2! \\cdots k_i!}, n = \\sum{k_i}``.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pr mainly addresses overflow issues, perhaps I should split the document and update it to another pr?

image

@codecov
Copy link

codecov bot commented Dec 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.89%. Comparing base (85c7193) to head (bc12ba1).
Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #172   +/-   ##
=======================================
  Coverage   96.88%   96.89%           
=======================================
  Files           7        7           
  Lines         803      804    +1     
=======================================
+ Hits          778      779    +1     
  Misses         25       25           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@inkydragon inkydragon merged commit c663926 into JuliaMath:master Apr 30, 2025
12 checks passed
@inkydragon inkydragon deleted the multinomial branch April 30, 2025 06:50
This was referenced Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

multinomial() may lead to hidden overflow

2 participants