Skip to content

Commit

Permalink
changelog + change name partialtrace
Browse files Browse the repository at this point in the history
  • Loading branch information
lehugueni committed Dec 18, 2024
1 parent af750ef commit dda9b25
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ All notable changes to this library are documented in this file.

## [6.x.x] - 16.12.2024
- Refactoring of the InnerSum methods:
- `rlwe.Evaluator.InnerSum` has been replaced by `rlwe.Evaluator.PartialTrace`
- `rlwe.Evaluator.InnerSum` has been replaced by `rlwe.Evaluator.PartialTracesSum`, which applies the automorphisms that correspond to rotations at the scheme level (and sum the results).
- Introduction of the `bgv.Evaluator.InnerSum` and `ckks.Evaluator.InnerSum` methods, which have the same behaviour as the old `InnerSum` method for parameters `n` and `batchSize` s.t. `0 < n*batchSize <= ctIn.Slots()` divides the number of slots. Parameters not satisfying these conditions are rejected.
- Introduction of the `bgv.Evaluator.RotateAndAdd` and `ckks.Evaluator.RotateAndAdd` methods, which have the same behaviour as the old `InnerSum` method for all parameters.

Expand Down
7 changes: 4 additions & 3 deletions core/rlwe/inner_sum.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,11 @@ func GaloisElementsForTrace(params ParameterProvider, logN int) (galEls []uint64
return
}

// PartialTrace applies a partial trace on the input ciphertext with the automorphisms phi(i*offset, X), 0 <= i < n, where phi(k, X): X -> X^{5^k}
// PartialTracesSum applies a set of automorphisms on the input ciphertext and sum the results.
// The automorphisms are of the form phi(i*offset, X), 0 <= i < n, where phi(k, X): X -> X^{5^k}
// i.e. opOut = \sum_{i = 0}^{n-1} phi(i*offset, ctIn).
// At the scheme level, this function is used to perform inner sums or efficiently replicate slots.
func (eval Evaluator) PartialTrace(ctIn *Ciphertext, offset, n int, opOut *Ciphertext) (err error) {
func (eval Evaluator) PartialTracesSum(ctIn *Ciphertext, offset, n int, opOut *Ciphertext) (err error) {
if n == 0 || offset == 0 {
return fmt.Errorf("partialtrace: invalid parameter (n = 0 or batchSize = 0)")
}
Expand Down Expand Up @@ -473,7 +474,7 @@ func GaloisElementsForInnerSum(params ParameterProvider, batch, n int) (galEls [
// two consecutive sub-vectors to replicate.
// This method is faster than Replicate when the number of rotations is large and it uses log2(n) + HW(n) instead of n.
func (eval Evaluator) Replicate(ctIn *Ciphertext, batchSize, n int, opOut *Ciphertext) (err error) {
return eval.PartialTrace(ctIn, -batchSize, n, opOut)
return eval.PartialTracesSum(ctIn, -batchSize, n, opOut)
}

// GaloisElementsForReplicate returns the list of Galois elements necessary to perform the
Expand Down
2 changes: 1 addition & 1 deletion core/rlwe/rlwe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ func testSlotOperations(tc *TestContext, level, bpw2 int, t *testing.T) {
// Galois Keys
evk := NewMemEvaluationKeySet(nil, kgen.GenGaloisKeysNew(GaloisElementsForInnerSum(params, batch, n), sk)...)

require.NoError(t, eval.WithKey(evk).PartialTrace(ct, batch, n, ct))
require.NoError(t, eval.WithKey(evk).PartialTracesSum(ct, batch, n, ct))

dec.Decrypt(ct, pt)

Expand Down
6 changes: 3 additions & 3 deletions schemes/bgv/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ func (eval Evaluator) InnerSum(ctIn *rlwe.Ciphertext, batchSize, n int, opOut *r
return
}

if err = eval.Evaluator.PartialTrace(ctIn, batchSize, n/2, opOut); err != nil {
if err = eval.Evaluator.PartialTracesSum(ctIn, batchSize, n/2, opOut); err != nil {
return
}

Expand All @@ -1561,7 +1561,7 @@ func (eval Evaluator) InnerSum(ctIn *rlwe.Ciphertext, batchSize, n int, opOut *r
return
}

err = eval.Evaluator.PartialTrace(ctIn, batchSize, n, opOut)
err = eval.Evaluator.PartialTracesSum(ctIn, batchSize, n, opOut)
return
}

Expand All @@ -1581,7 +1581,7 @@ func (eval Evaluator) InnerSum(ctIn *rlwe.Ciphertext, batchSize, n int, opOut *r
//
// Calling RotateAndAdd(ctIn, 1, n, opOut) can be used to compute the inner sum of the first n slots of a plaintext.
func (eval Evaluator) RotateAndAdd(ctIn *rlwe.Ciphertext, batchSize, n int, opOut *rlwe.Ciphertext) (err error) {
err = eval.Evaluator.PartialTrace(ctIn, batchSize, n, opOut)
err = eval.Evaluator.PartialTracesSum(ctIn, batchSize, n, opOut)
return
}

Expand Down
4 changes: 2 additions & 2 deletions schemes/ckks/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ func (eval Evaluator) InnerSum(ctIn *rlwe.Ciphertext, batchSize, n int, opOut *r
if l&(l-1) != 0 {
return fmt.Errorf("innersum: invalid parameters (n*batchSize=%d does not divide #slots=%d)", l, N)
}
err = eval.Evaluator.PartialTrace(ctIn, batchSize, n, opOut)
err = eval.Evaluator.PartialTracesSum(ctIn, batchSize, n, opOut)
return
}

Expand All @@ -1312,7 +1312,7 @@ func (eval Evaluator) InnerSum(ctIn *rlwe.Ciphertext, batchSize, n int, opOut *r
//
// Calling RotateAndAdd(ctIn, 1, n, opOut) can be used to compute the inner sum of the first n slots of a plaintext.
func (eval Evaluator) RotateAndAdd(ctIn *rlwe.Ciphertext, batchSize, n int, opOut *rlwe.Ciphertext) (err error) {
err = eval.Evaluator.PartialTrace(ctIn, batchSize, n, opOut)
err = eval.Evaluator.PartialTracesSum(ctIn, batchSize, n, opOut)
return
}

Expand Down

0 comments on commit dda9b25

Please sign in to comment.