From 808d4cf21063e7fe1d0d0549b2c7ea91f3903a06 Mon Sep 17 00:00:00 2001 From: Jason Colburne Date: Mon, 6 Jan 2025 19:06:24 -0400 Subject: [PATCH] move logic --- conversion.go | 53 --------------------------------------------------- reduction.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/conversion.go b/conversion.go index b608b38..1bd06fb 100644 --- a/conversion.go +++ b/conversion.go @@ -382,56 +382,3 @@ func vectorMaxAbsCoefficient(parameters ParameterSet, v [][]int32, lowBitsOnly b return max } - -func onesInH(h [][]bool) int32 { - count := int32(0) - - for _, row := range h { - for _, value := range row { - if value { - count += 1 - } - } - } - - return count -} - -func vectorMakeHint(parameters ParameterSet, ct0Neg [][]int32, wPrime [][]int32) [][]bool { - h := make([][]bool, len(ct0Neg)) - - for i, ct0NegValues := range ct0Neg { - h[i] = make([]bool, len(ct0NegValues)) - for j, value := range ct0NegValues { - h[i][j] = makeHint(parameters, value, wPrime[i][j]) - } - } - - return h -} - -func vectorHighBits(parameters ParameterSet, v [][]int32) [][]int32 { - w1 := make([][]int32, parameters.K) - - for j, row := range v { - w1[j] = make([]int32, 256) - for i, value := range row { - w1[j][i] = highBits(parameters, value) - } - } - - return w1 -} - -func vectorUseHint(parameters ParameterSet, v [][]int32, h [][]bool) [][]int32 { - w1Prime := make([][]int32, parameters.K) - - for i, row := range v { - w1Prime[i] = make([]int32, len(row)) - for j, value := range row { - w1Prime[i][j] = useHint(parameters, h[i][j], value) - } - } - - return w1Prime -} diff --git a/reduction.go b/reduction.go index c7b4505..23754bc 100644 --- a/reduction.go +++ b/reduction.go @@ -73,6 +73,19 @@ func highBits(parameters ParameterSet, r int32) int32 { return r1 } +func vectorHighBits(parameters ParameterSet, v [][]int32) [][]int32 { + w1 := make([][]int32, parameters.K) + + for j, row := range v { + w1[j] = make([]int32, 256) + for i, value := range row { + w1[j][i] = highBits(parameters, value) + } + } + + return w1 +} + func lowBits(parameters ParameterSet, r int32) int32 { _, r0 := decompose(parameters, r) return r0 @@ -85,6 +98,19 @@ func makeHint(parameters ParameterSet, z, r int32) bool { return r1 != v1 } +func vectorMakeHint(parameters ParameterSet, ct0Neg [][]int32, wPrime [][]int32) [][]bool { + h := make([][]bool, len(ct0Neg)) + + for i, ct0NegValues := range ct0Neg { + h[i] = make([]bool, len(ct0NegValues)) + for j, value := range ct0NegValues { + h[i][j] = makeHint(parameters, value, wPrime[i][j]) + } + } + + return h +} + func useHint(parameters ParameterSet, h bool, r int32) int32 { m := (parameters.Q - 1) / (2 * parameters.Gamma2) r1, r0 := decompose(parameters, r) @@ -99,3 +125,30 @@ func useHint(parameters ParameterSet, h bool, r int32) int32 { return r1 } + +func vectorUseHint(parameters ParameterSet, v [][]int32, h [][]bool) [][]int32 { + w1Prime := make([][]int32, parameters.K) + + for i, row := range v { + w1Prime[i] = make([]int32, len(row)) + for j, value := range row { + w1Prime[i][j] = useHint(parameters, h[i][j], value) + } + } + + return w1Prime +} + +func onesInH(h [][]bool) int32 { + count := int32(0) + + for _, row := range h { + for _, value := range row { + if value { + count += 1 + } + } + } + + return count +}