Skip to content
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

Simplify nonzero edge decoding / encoding #75

Merged
merged 9 commits into from
May 15, 2024
Merged

Conversation

mcroomp
Copy link
Collaborator

@mcroomp mcroomp commented May 8, 2024

Remove ProbabilityTablesCoefficientContext and calculate the values when actually needed. This means that we can range check the values at the same place that does the array lookup, which means no range check effectively. It also means that we can recycle the absolute value calculation on the best_prior.

Overall this speeds up execution about 1.5% and simplifies the code as well.

@mcroomp mcroomp requested a review from Melirius May 8, 2024 14:09
@mcroomp mcroomp requested review from davidol33 and gbrovman May 9, 2024 13:09
Comment on lines +128 to +136
// No need to go to 32 bits since max exponent is 11, ie 2047, so
// (2047 + 2047) * 13 + 2047 * 6 = 65504 which still fits in 16 bits.
// In addition, if we ever returned anything higher that 2047, it would
// assert in the array lookup in the model.
best_prior[i] = ((left.get_coefficient(i).unsigned_abs()
+ above.get_coefficient(i).unsigned_abs())
* 13
+ 6 * above_left.get_coefficient(i).abs() as u32)
>> 5) as i16;
+ 6 * above_left.get_coefficient(i).unsigned_abs())
>> 5;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

@Melirius Melirius mentioned this pull request May 15, 2024
@mcroomp mcroomp merged commit 2e452f2 into main May 15, 2024
3 checks passed
@mcroomp mcroomp deleted the simplify_nonzero_edge branch May 15, 2024 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants