Repository navigation
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In binary circuits, the function
mpc_math.log2_fxcan return wrong values at small precisions. I found this while testing #1796, which fixedpopcntreturning a count one bit too short for some lengths, so I checkedlog2_fx, which usespopcntin binary circuits. For instance, withScripts/compile-run.py -E replicated, the following snippet prints-5.5forlog2(8):It prints
-0.5,0.5,1.5and-5.5. The first three are 0.5 below the exact values, but-5.5is far off. With this PR,log2(8)gives2.5, which is consistent with the other outputs aslog2_fxis only approximate with 2 fractional bits.Cause
log2_fxcallsfloatingpoint.Int2FL, which computes the exponent asa.popcnt_bits(b) - lam. In binary circuits,ais ansbitintvecofkbits, 7 in the snippet. Butsbitintvec.popcnt_bitsreturns the count as a 3-bit number, just wide enough for counts up to 6, so the exponent overflows.Fix
I patched
sbitintvec.popcnt_bitsso it behaves likesbitint.popcnt_bits, returning the count with as many bits as the integer it is called on.Testing
test_gc.mpcthat the count has as many bits as the integer.log2_fxwith 21 precisions, withkfrom 5 to 31, on up to six powers of two, from2**-fto the largest that fits: without the fix, 3 precisions give a value off by 1 or more, all withkof 12 or less: (k,f) = (7, 2), (11, 2) and (12, 2). With the fix, none does, and the values that were right before are unchanged.Scripts/compile-run.py -E ring test_gcand-E replicated test_gcprint the same output as master'stest_gc.