Skip to content

Commit

Permalink
move logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncolburne committed Jan 6, 2025
1 parent 7eff77e commit 808d4cf
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 53 deletions.
53 changes: 0 additions & 53 deletions conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
53 changes: 53 additions & 0 deletions reduction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
}

0 comments on commit 808d4cf

Please sign in to comment.