Skip to content

Use a special case of the histogram. #341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apycula/bitmatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ def histogram(lst, bins):
r_lst[i] += 1
return r_lst

def byte_histogram(lst):
"""
Compute the histogram of a list of bytes.
Returns a list of 256 counters.
"""
r_lst = [0] * 256
from itertools import chain
for val in chain.from_iterable(lst):
r_lst[val] += 1
return r_lst

def any(bmp):
"""
Test whether any matrix element evaluates to True.
Expand Down
2 changes: 1 addition & 1 deletion apycula/bslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def write_bitstream(fname, bs, hdr, ftr, compress):
unused_bytes = []
if compress:
# search for smallest values not used in the bitstream
lst = bitmatrix.histogram(bs, bins=[i for i in range(257)]) # 257 so that the last basket is [255, 256] and not [254, 255]
lst = bitmatrix.byte_histogram(bs)
unused_bytes = [i for i,val in enumerate(lst) if val==0]
if unused_bytes:
# We may simply not have the bytes we need for the keys.
Expand Down
Loading