-
Notifications
You must be signed in to change notification settings - Fork 0
Add space complexity metrics #38
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
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d7c78c1
General cleanup and coherence between quantizers
frneer 269e04f
Add space complexity computation code
frneer 8b21f08
Add pyproject toml
frneer a7a7ca8
Add space complexity tests
frneer 57f33f5
Fix shebang
frneer 06320ab
Fix broken tests
frneer ca372c8
Add more tests
colorete87 ded44d5
Split metrics test
frneer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # pyproject.toml | ||
| [tool.black] | ||
| line-length = 79 | ||
|
|
||
| [tool.isort] | ||
| profile = "black" | ||
| line_length = 79 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| #!/usr/bin/python3 | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import argparse | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import heapq | ||
| from collections import Counter, namedtuple | ||
|
|
||
|
|
||
| # A simple Node for the Huffman tree | ||
| class Node(namedtuple("Node", ["freq", "value", "left", "right"])): | ||
| def __lt__(self, other): | ||
| return self.freq < other.freq | ||
|
|
||
|
|
||
| def build_huffman_tree(weights): | ||
| counter = Counter(weights) | ||
| heap = [Node(freq, value, None, None) for value, freq in counter.items()] | ||
| heapq.heapify(heap) | ||
|
|
||
| while len(heap) > 1: | ||
| left = heapq.heappop(heap) | ||
| right = heapq.heappop(heap) | ||
| new_node = Node(left.freq + right.freq, None, left, right) | ||
| heapq.heappush(heap, new_node) | ||
|
|
||
| return heap[0] | ||
|
|
||
|
|
||
| def assign_codes(node, prefix="", codebook={}): | ||
| if node.value is not None: | ||
| codebook[node.value] = prefix | ||
| else: | ||
| assign_codes(node.left, prefix + "0", codebook) | ||
| assign_codes(node.right, prefix + "1", codebook) | ||
| return codebook | ||
|
|
||
|
|
||
| # TODO(frneer): Add tests for the Huffman tree | ||
| # test_weights = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4] | ||
| # huffman_tree = build_huffman_tree(test_weights) | ||
| # # print(huffman_tree) | ||
| # huffman_codes = assign_codes(huffman_tree) | ||
| # # print("Huffman Codes:", [len(code) for idx, code in huffman_codes.items()]) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.