mirror of
https://github.com/tuneinsight/lattigo.git
synced 2025-09-13 03:27:14 +00:00
fixed sparse ternary sampler to wipe poly before sampling (#179)
This commit is contained in:
committed by
GitHub
parent
672f0656cb
commit
27fee8bebb
@@ -213,6 +213,13 @@ func (ts *TernarySampler) sampleSparse(lvl int, pol *Poly) {
|
||||
pointer = 0
|
||||
}
|
||||
}
|
||||
|
||||
for _, i := range index {
|
||||
for k := 0; k < lvl+1; k++ {
|
||||
pol.Coeffs[k][i] = 0
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// kysampling uses the binary expansion and random bytes matrix to sample a discrete Gaussian value and its sign.
|
||||
|
||||
@@ -391,17 +391,25 @@ func testTernarySampler(testContext *testParams, t *testing.T) {
|
||||
|
||||
ternarySampler := NewTernarySamplerWithHammingWeight(prng, testContext.ringQ, p, false)
|
||||
|
||||
checkPoly := func(pol *Poly) {
|
||||
for i := range testContext.ringQ.Modulus {
|
||||
hw := 0
|
||||
for _, c := range pol.Coeffs[i] {
|
||||
if c != 0 {
|
||||
hw++
|
||||
}
|
||||
}
|
||||
require.True(t, hw == p)
|
||||
}
|
||||
}
|
||||
|
||||
pol := ternarySampler.ReadNew()
|
||||
|
||||
for i := range testContext.ringQ.Modulus {
|
||||
hw := 0
|
||||
for _, c := range pol.Coeffs[i] {
|
||||
if c != 0 {
|
||||
hw++
|
||||
}
|
||||
}
|
||||
require.True(t, hw == p)
|
||||
}
|
||||
checkPoly(pol)
|
||||
|
||||
ternarySampler.Read(pol)
|
||||
|
||||
checkPoly(pol)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user