updated handling of modulus

This commit is contained in:
Jean-Philippe Bossuat
2025-02-03 15:30:12 +01:00
parent 0b8bf98b2a
commit e6cb70dbdf
7 changed files with 156 additions and 119 deletions

View File

@@ -1,4 +1,5 @@
use base2k::{Matrix3D, Module, VecZnx, VecZnxBig, VecZnxDft, VmpPMat, FFT64};
use std::cmp::min;
fn main() {
let log_n = 5;
@@ -6,10 +7,10 @@ fn main() {
let module: Module = Module::new::<FFT64>(n);
let log_base2k: usize = 15;
let log_q: usize = 60;
let limbs: usize = (log_q + log_base2k - 1) / log_base2k;
let limbs: usize = 5;
let log_k: usize = log_base2k * limbs - 5;
let rows: usize = limbs + 1;
let rows: usize = limbs;
let cols: usize = limbs + 1;
// Maximum size of the byte scratch needed
@@ -21,23 +22,18 @@ fn main() {
let mut a_values: Vec<i64> = vec![i64::default(); n];
a_values[1] = (1 << log_base2k) + 1;
let mut a: VecZnx = module.new_vec_znx(log_base2k, log_q);
a.from_i64(&a_values, 32);
let mut a: VecZnx = module.new_vec_znx(log_base2k, limbs);
a.from_i64(&a_values, 32, log_k);
a.normalize(&mut buf);
(0..a.limbs()).for_each(|i| println!("{}: {:?}", i, a.at(i)));
let mut b_mat: Matrix3D<i64> = Matrix3D::new(rows, cols, n);
(0..rows).for_each(|i| {
(0..cols).for_each(|j| {
b_mat.at_mut(i, j)[0] = (i * cols + j) as i64;
b_mat.at_mut(i, j)[0] = (i * cols + j) as i64;
})
(0..min(rows, cols)).for_each(|i| {
b_mat.at_mut(i, i)[1] = 1 as i64;
});
//b_mat.data.iter_mut().enumerate().for_each(|(i, xi)| *xi = i as i64);
println!();
(0..rows).for_each(|i| {
(0..cols).for_each(|j| println!("{} {}: {:?}", i, j, b_mat.at(i, j)));
@@ -47,24 +43,26 @@ fn main() {
let mut vmp_pmat: VmpPMat = module.new_vmp_pmat(rows, cols);
module.vmp_prepare_contiguous(&mut vmp_pmat, &b_mat.data, &mut buf);
/*
(0..cols).for_each(|i| {
(0..rows).for_each(|j| println!("{} {}: {:?}", i, j, vmp_pmat.at(i, j)));
println!();
});
*/
println!("{:?}", vmp_pmat.as_f64());
//println!("{:?}", vmp_pmat.as_f64());
let mut c_dft: VecZnxDft = module.new_vec_znx_dft(limbs);
let mut c_dft: VecZnxDft = module.new_vec_znx_dft(cols);
module.vmp_apply_dft(&mut c_dft, &a, &vmp_pmat, &mut buf);
let mut c_big: VecZnxBig = c_dft.as_vec_znx_big();
module.vec_znx_idft_tmp_a(&mut c_big, &mut c_dft, limbs);
module.vec_znx_idft_tmp_a(&mut c_big, &mut c_dft, cols);
let mut res: VecZnx = module.new_vec_znx(log_base2k, log_q);
let mut res: VecZnx = module.new_vec_znx(log_base2k, cols);
module.vec_znx_big_normalize(&mut res, &c_big, &mut buf);
let mut values_res: Vec<i64> = vec![i64::default(); n];
res.to_i64(&mut values_res);
res.to_i64(&mut values_res, log_k);
(0..res.limbs()).for_each(|i| println!("{}: {:?}", i, res.at(i)));
@@ -72,5 +70,5 @@ fn main() {
c_dft.delete();
vmp_pmat.delete();
println!("{:?}", values_res)
//println!("{:?}", values_res)
}