rewrote all bindings, removed dependency on binding generation

This commit is contained in:
Jean-Philippe Bossuat
2025-01-30 17:34:57 +01:00
parent a7af4d6d1f
commit d3a8d20647
25 changed files with 1040 additions and 189 deletions

View File

@@ -1,8 +1,4 @@
use base2k::bindings::{
new_reim_fft_precomp, new_reim_ifft_precomp, reim_fft, reim_fft_precomp_get_buffer,
reim_fftvec_mul_simple, reim_from_znx64_simple, reim_ifft, reim_ifft_precomp_get_buffer,
reim_to_znx64_simple,
};
use base2k::ffi::reim::*;
use std::ffi::c_void;
use std::time::Instant;

View File

@@ -48,7 +48,7 @@ fn main() {
.for_each(|x| *x = source.next_u64n(16, 15) as i64);
// m
m.set_i64(&want, 4);
m.from_i64(&want, 4);
m.normalize(&mut carry);
// buf_big <- m - buf_big
@@ -73,7 +73,7 @@ fn main() {
// have = m * 2^{log_scale} + e
let mut have: Vec<i64> = vec![i64::default(); n];
res.get_i64(&mut have);
res.to_i64(&mut have);
let scale: f64 = (1 << log_scale) as f64;
izip!(want.iter(), have.iter())

View File

@@ -1,7 +1,7 @@
use base2k::{Matrix3D, Module, VecZnx, VecZnxBig, VecZnxDft, VmpPMat, FFT64};
fn main() {
let log_n = 4;
let log_n = 5;
let n = 1 << log_n;
let module: Module = Module::new::<FFT64>(n);
@@ -14,7 +14,7 @@ fn main() {
// Maximum size of the byte scratch needed
let tmp_bytes: usize = module.vmp_prepare_contiguous_tmp_bytes(rows, cols)
| module.vmp_apply_dft_to_dft_tmp_bytes(limbs, limbs, rows, cols);
| module.vmp_apply_dft_tmp_bytes(limbs, limbs, rows, cols);
let mut buf: Vec<u8> = vec![0; tmp_bytes];
@@ -22,7 +22,7 @@ fn main() {
a_values[1] = (1 << log_base2k) + 1;
let mut a: VecZnx = module.new_vec_znx(log_base2k, log_q);
a.set_i64(&a_values, 32);
a.from_i64(&a_values, 32);
a.normalize(&mut buf);
(0..a.limbs()).for_each(|i| println!("{}: {:?}", i, a.at(i)));
@@ -30,9 +30,14 @@ fn main() {
let mut b_mat: Matrix3D<i64> = Matrix3D::new(rows, cols, n);
(0..rows).for_each(|i| {
b_mat.at_mut(i, i)[0] = ((1 << 15) + 1) << 15;
(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;
})
});
//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)));
@@ -42,6 +47,13 @@ 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());
let mut c_dft: VecZnxDft = module.new_vec_znx_dft(limbs);
module.vmp_apply_dft(&mut c_dft, &a, &vmp_pmat, &mut buf);
@@ -52,9 +64,13 @@ fn main() {
module.vec_znx_big_normalize(&mut res, &c_big, &mut buf);
let mut values_res: Vec<i64> = vec![i64::default(); n];
res.get_i64(&mut values_res);
res.to_i64(&mut values_res);
(0..res.limbs()).for_each(|i| println!("{}: {:?}", i, res.at(i)));
module.delete();
c_dft.delete();
vmp_pmat.delete();
println!("{:?}", values_res)
}