-
Notifications
You must be signed in to change notification settings - Fork 6
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
Output Dict/Struct of Huffman Symbol Codes #28
Comments
Thank you for reporting! Could you expand on your use case? The point of any source coding encoder is to convert a message (i.e., a sequence of symbols) to a bit string. The message can be of arbitrary length. In particular, when using a symbol code like Huffman coding, there's nothing wrong with encoding a message that consists of only a single symbol: import constriction
import numpy as np
def single_code_word(symbol, code_book):
encoder = constriction.symbol.QueueEncoder()
encoder.encode_symbol(symbol, code_book)
code_word, length = encoder.get_compressed()
return f'{code_word[0]:0{length}b}'[::-1] # works for code words of length <=32
probabilities = np.array([0.1, 0.2, 0.3, 0.4])
code_book = constriction.symbol.huffman.EncoderHuffmanTree(probabilities)
print({symbol: single_code_word(symbol, code_book) for symbol in range(4)}) Are you looking for a more convenient way to do this? If so, I'd be curious which of the following best describes your use case:
|
Closing this for now because it's not actionable without further information. As mentioned in my last comment, the specific requested feature already exists, and while it is very well possible that the existing solution may not be suitable for all use cases, further information is needed to clarify what exactly is missing. Without clarification of the intended use case, any attempt from my side to guess and address the underlying issue would likely run into the XY problem. Please feel free to reopen if you can clarify the broader picture of what you're trying to achieve. |
It would be very good for me (neuroinformatics research) if we could output the binary symbol codes from the Huffman tree.
I've been working in the python library but can write rust code. If this feature exists in the rust code I'm happy to write the python binding. If the feature isn't in rust code either, I'd be happy to write it and add the python binding also.
Let me know if this would be good, and maybe me a little direction about how you'd like it if so!
The text was updated successfully, but these errors were encountered: