-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix binary search #3
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,19 +64,23 @@ def quantize_array_lbda(A, lbda): | |
def quantize_array_target(A, target_err): | ||
low = 1 | ||
high = 128 | ||
mid = low | ||
A_norms = np.sqrt(np.sum(A**2, axis=-1)) | ||
|
||
while high - low > 1: | ||
mid = (high + low) / 2 | ||
while low < high: | ||
mid = low + (high - low) / 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Python has arbitrary precision integers, no need to do this |
||
quant_A, dequant_A = quantize_array(A, mid) | ||
mean_err = np.mean(np.sqrt(np.sum((dequant_A - A)**2, axis=-1)) / A_norms) | ||
logging.info("Binary search: q=%d, err=%.3f", mid, mean_err) | ||
|
||
if mean_err > target_err: | ||
low = mid | ||
low = mid + 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This breaks the loop invariant that error(high) <= target_err < error(low) |
||
else: | ||
high = mid | ||
|
||
mid = low | ||
quant_A, dequant_A = quantize_array(A, mid) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is copypasta |
||
mean_err = np.mean(np.sqrt(np.sum((dequant_A - A)**2, axis=-1)) / A_norms) | ||
logging.info("Result: q=%d, err=%.3f", mid, mean_err) | ||
return mid, mean_err, quant_A, dequant_A | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need this