Skip to content

Commit

Permalink
update comment - add test
Browse files Browse the repository at this point in the history
  • Loading branch information
ilanschnell committed Dec 12, 2024
1 parent 76812e7 commit 49a4ac7
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion examples/sparse/compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def random_array(n, p=0.5):
Each bit has a probability p of being 1.
"""
if p < 0.05:
# XXX what happens for small N? N=0 crashes right now.
# XXX what happens for small n?
# when the probability p is small, it is faster to randomly
# set p * n elements
a = zeros(n)
Expand All @@ -128,6 +128,7 @@ def test_random_array():
n = 10_000_000
p = 1e-6
while p < 1.0:
assert random_array(0, p) == bitarray()
a = random_array(n, p)
cnt = a.count()
print("%10.7f %10.7f %10.7f" % (p, cnt / n, abs(p - cnt / n)))
Expand Down

0 comments on commit 49a4ac7

Please sign in to comment.