mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 21:26:41 +01:00
fmt
This commit is contained in:
197
math/src/lib.rs
197
math/src/lib.rs
@@ -1,22 +1,20 @@
|
||||
#![feature(bigint_helper_methods)]
|
||||
#![feature(test)]
|
||||
|
||||
pub mod modulus;
|
||||
pub mod dft;
|
||||
pub mod ring;
|
||||
pub mod modulus;
|
||||
pub mod poly;
|
||||
pub mod ring;
|
||||
pub mod scalar;
|
||||
|
||||
pub const CHUNK: usize= 8;
|
||||
pub const CHUNK: usize = 8;
|
||||
|
||||
pub mod macros {
|
||||
|
||||
pub mod macros{
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! apply_v {
|
||||
|
||||
($self:expr, $f:expr, $a:expr, $CHUNK:expr) => {
|
||||
|
||||
match CHUNK{
|
||||
match CHUNK {
|
||||
8 => {
|
||||
$a.chunks_exact_mut(8).for_each(|a| {
|
||||
$f(&$self, &mut a[0]);
|
||||
@@ -30,12 +28,12 @@ pub mod macros{
|
||||
});
|
||||
|
||||
let n: usize = $a.len();
|
||||
let m = n - (n&(CHUNK-1));
|
||||
let m = n - (n & (CHUNK - 1));
|
||||
$a[m..].iter_mut().for_each(|a| {
|
||||
$f(&$self, a);
|
||||
});
|
||||
},
|
||||
_=>{
|
||||
}
|
||||
_ => {
|
||||
$a.iter_mut().for_each(|a| {
|
||||
$f(&$self, a);
|
||||
});
|
||||
@@ -46,16 +44,21 @@ pub mod macros{
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! apply_vv {
|
||||
|
||||
($self:expr, $f:expr, $a:expr, $b:expr, $CHUNK:expr) => {
|
||||
|
||||
let n: usize = $a.len();
|
||||
debug_assert!($b.len() == n, "invalid argument b: b.len() = {} != a.len() = {}", $b.len(), n);
|
||||
debug_assert!(CHUNK&(CHUNK-1) == 0, "invalid CHUNK const: not a power of two");
|
||||
debug_assert!(
|
||||
$b.len() == n,
|
||||
"invalid argument b: b.len() = {} != a.len() = {}",
|
||||
$b.len(),
|
||||
n
|
||||
);
|
||||
debug_assert!(
|
||||
CHUNK & (CHUNK - 1) == 0,
|
||||
"invalid CHUNK const: not a power of two"
|
||||
);
|
||||
|
||||
match CHUNK{
|
||||
match CHUNK {
|
||||
8 => {
|
||||
|
||||
izip!($a.chunks_exact(8), $b.chunks_exact_mut(8)).for_each(|(a, b)| {
|
||||
$f(&$self, &a[0], &mut b[0]);
|
||||
$f(&$self, &a[1], &mut b[1]);
|
||||
@@ -67,12 +70,12 @@ pub mod macros{
|
||||
$f(&$self, &a[7], &mut b[7]);
|
||||
});
|
||||
|
||||
let m = n - (n&(CHUNK-1));
|
||||
let m = n - (n & (CHUNK - 1));
|
||||
izip!($a[m..].iter(), $b[m..].iter_mut()).for_each(|(a, b)| {
|
||||
$f(&$self, a, b);
|
||||
});
|
||||
},
|
||||
_=>{
|
||||
}
|
||||
_ => {
|
||||
izip!($a.iter(), $b.iter_mut()).for_each(|(a, b)| {
|
||||
$f(&$self, a, b);
|
||||
});
|
||||
@@ -83,18 +86,33 @@ pub mod macros{
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! apply_vvv {
|
||||
|
||||
($self:expr, $f:expr, $a:expr, $b:expr, $c:expr, $CHUNK:expr) => {
|
||||
|
||||
let n: usize = $a.len();
|
||||
debug_assert!($b.len() == n, "invalid argument b: b.len() = {} != a.len() = {}", $b.len(), n);
|
||||
debug_assert!($c.len() == n, "invalid argument c: b.len() = {} != a.len() = {}", $c.len(), n);
|
||||
debug_assert!(CHUNK&(CHUNK-1) == 0, "invalid CHUNK const: not a power of two");
|
||||
debug_assert!(
|
||||
$b.len() == n,
|
||||
"invalid argument b: b.len() = {} != a.len() = {}",
|
||||
$b.len(),
|
||||
n
|
||||
);
|
||||
debug_assert!(
|
||||
$c.len() == n,
|
||||
"invalid argument c: b.len() = {} != a.len() = {}",
|
||||
$c.len(),
|
||||
n
|
||||
);
|
||||
debug_assert!(
|
||||
CHUNK & (CHUNK - 1) == 0,
|
||||
"invalid CHUNK const: not a power of two"
|
||||
);
|
||||
|
||||
match CHUNK{
|
||||
match CHUNK {
|
||||
8 => {
|
||||
|
||||
izip!($a.chunks_exact(8), $b.chunks_exact(8), $c.chunks_exact_mut(8)).for_each(|(a, b, c)| {
|
||||
izip!(
|
||||
$a.chunks_exact(8),
|
||||
$b.chunks_exact(8),
|
||||
$c.chunks_exact_mut(8)
|
||||
)
|
||||
.for_each(|(a, b, c)| {
|
||||
$f(&$self, &a[0], &b[0], &mut c[0]);
|
||||
$f(&$self, &a[1], &b[1], &mut c[1]);
|
||||
$f(&$self, &a[2], &b[2], &mut c[2]);
|
||||
@@ -105,12 +123,14 @@ pub mod macros{
|
||||
$f(&$self, &a[7], &b[7], &mut c[7]);
|
||||
});
|
||||
|
||||
let m = n - (n&7);
|
||||
izip!($a[m..].iter(), $b[m..].iter(), $c[m..].iter_mut()).for_each(|(a, b, c)| {
|
||||
$f(&$self, a, b, c);
|
||||
});
|
||||
},
|
||||
_=>{
|
||||
let m = n - (n & 7);
|
||||
izip!($a[m..].iter(), $b[m..].iter(), $c[m..].iter_mut()).for_each(
|
||||
|(a, b, c)| {
|
||||
$f(&$self, a, b, c);
|
||||
},
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
izip!($a.iter(), $b.iter(), $c.iter_mut()).for_each(|(a, b, c)| {
|
||||
$f(&$self, a, b, c);
|
||||
});
|
||||
@@ -121,16 +141,16 @@ pub mod macros{
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! apply_sv {
|
||||
|
||||
($self:expr, $f:expr, $a:expr, $b:expr, $CHUNK:expr) => {
|
||||
|
||||
let n: usize = $b.len();
|
||||
|
||||
debug_assert!(CHUNK&(CHUNK-1) == 0, "invalid CHUNK const: not a power of two");
|
||||
debug_assert!(
|
||||
CHUNK & (CHUNK - 1) == 0,
|
||||
"invalid CHUNK const: not a power of two"
|
||||
);
|
||||
|
||||
match CHUNK{
|
||||
match CHUNK {
|
||||
8 => {
|
||||
|
||||
izip!($b.chunks_exact_mut(8)).for_each(|b| {
|
||||
$f(&$self, $a, &mut b[0]);
|
||||
$f(&$self, $a, &mut b[1]);
|
||||
@@ -142,12 +162,12 @@ pub mod macros{
|
||||
$f(&$self, $a, &mut b[7]);
|
||||
});
|
||||
|
||||
let m = n - (n&7);
|
||||
let m = n - (n & 7);
|
||||
izip!($b[m..].iter_mut()).for_each(|b| {
|
||||
$f(&$self, $a, b);
|
||||
});
|
||||
},
|
||||
_=>{
|
||||
}
|
||||
_ => {
|
||||
izip!($b.iter_mut()).for_each(|b| {
|
||||
$f(&$self, $a, b);
|
||||
});
|
||||
@@ -158,16 +178,21 @@ pub mod macros{
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! apply_svv {
|
||||
|
||||
($self:expr, $f:expr, $a:expr, $b:expr, $c:expr, $CHUNK:expr) => {
|
||||
|
||||
let n: usize = $b.len();
|
||||
debug_assert!($c.len() == n, "invalid argument c: c.len() = {} != b.len() = {}", $c.len(), n);
|
||||
debug_assert!(CHUNK&(CHUNK-1) == 0, "invalid CHUNK const: not a power of two");
|
||||
debug_assert!(
|
||||
$c.len() == n,
|
||||
"invalid argument c: c.len() = {} != b.len() = {}",
|
||||
$c.len(),
|
||||
n
|
||||
);
|
||||
debug_assert!(
|
||||
CHUNK & (CHUNK - 1) == 0,
|
||||
"invalid CHUNK const: not a power of two"
|
||||
);
|
||||
|
||||
match CHUNK{
|
||||
match CHUNK {
|
||||
8 => {
|
||||
|
||||
izip!($b.chunks_exact(8), $c.chunks_exact_mut(8)).for_each(|(b, c)| {
|
||||
$f(&$self, $a, &b[0], &mut c[0]);
|
||||
$f(&$self, $a, &b[1], &mut c[1]);
|
||||
@@ -179,12 +204,12 @@ pub mod macros{
|
||||
$f(&$self, $a, &b[7], &mut c[7]);
|
||||
});
|
||||
|
||||
let m = n - (n&7);
|
||||
let m = n - (n & 7);
|
||||
izip!($b[m..].iter(), $c[m..].iter_mut()).for_each(|(b, c)| {
|
||||
$f(&$self, $a, b, c);
|
||||
});
|
||||
},
|
||||
_=>{
|
||||
}
|
||||
_ => {
|
||||
izip!($b.iter(), $c.iter_mut()).for_each(|(b, c)| {
|
||||
$f(&$self, $a, b, c);
|
||||
});
|
||||
@@ -195,18 +220,33 @@ pub mod macros{
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! apply_vvsv {
|
||||
|
||||
($self:expr, $f:expr, $a:expr, $b:expr, $c:expr, $d:expr, $CHUNK:expr) => {
|
||||
|
||||
let n: usize = $a.len();
|
||||
debug_assert!($b.len() == n, "invalid argument b: b.len() = {} != a.len() = {}", $b.len(), n);
|
||||
debug_assert!($d.len() == n, "invalid argument d: d.len() = {} != a.len() = {}", $d.len(), n);
|
||||
debug_assert!(CHUNK&(CHUNK-1) == 0, "invalid CHUNK const: not a power of two");
|
||||
debug_assert!(
|
||||
$b.len() == n,
|
||||
"invalid argument b: b.len() = {} != a.len() = {}",
|
||||
$b.len(),
|
||||
n
|
||||
);
|
||||
debug_assert!(
|
||||
$d.len() == n,
|
||||
"invalid argument d: d.len() = {} != a.len() = {}",
|
||||
$d.len(),
|
||||
n
|
||||
);
|
||||
debug_assert!(
|
||||
CHUNK & (CHUNK - 1) == 0,
|
||||
"invalid CHUNK const: not a power of two"
|
||||
);
|
||||
|
||||
match CHUNK{
|
||||
match CHUNK {
|
||||
8 => {
|
||||
|
||||
izip!($a.chunks_exact(8), $b.chunks_exact(8), $d.chunks_exact_mut(8)).for_each(|(a, b, d)| {
|
||||
izip!(
|
||||
$a.chunks_exact(8),
|
||||
$b.chunks_exact(8),
|
||||
$d.chunks_exact_mut(8)
|
||||
)
|
||||
.for_each(|(a, b, d)| {
|
||||
$f(&$self, &a[0], &b[0], $c, &mut d[0]);
|
||||
$f(&$self, &a[1], &b[1], $c, &mut d[1]);
|
||||
$f(&$self, &a[2], &b[2], $c, &mut d[2]);
|
||||
@@ -217,12 +257,14 @@ pub mod macros{
|
||||
$f(&$self, &a[7], &b[7], $c, &mut d[7]);
|
||||
});
|
||||
|
||||
let m = n - (n&7);
|
||||
izip!($a[m..].iter(), $b[m..].iter(), $d[m..].iter_mut()).for_each(|(a, b, d)| {
|
||||
$f(&$self, a, b, $c, d);
|
||||
});
|
||||
},
|
||||
_=>{
|
||||
let m = n - (n & 7);
|
||||
izip!($a[m..].iter(), $b[m..].iter(), $d[m..].iter_mut()).for_each(
|
||||
|(a, b, d)| {
|
||||
$f(&$self, a, b, $c, d);
|
||||
},
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
izip!($a.iter(), $b.iter(), $d.iter_mut()).for_each(|(a, b, d)| {
|
||||
$f(&$self, a, b, $c, d);
|
||||
});
|
||||
@@ -233,16 +275,21 @@ pub mod macros{
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! apply_vsv {
|
||||
|
||||
($self:expr, $f:expr, $a:expr, $c:expr, $b:expr, $CHUNK:expr) => {
|
||||
|
||||
let n: usize = $a.len();
|
||||
debug_assert!($b.len() == n, "invalid argument b: b.len() = {} != a.len() = {}", $b.len(), n);
|
||||
debug_assert!(CHUNK&(CHUNK-1) == 0, "invalid CHUNK const: not a power of two");
|
||||
debug_assert!(
|
||||
$b.len() == n,
|
||||
"invalid argument b: b.len() = {} != a.len() = {}",
|
||||
$b.len(),
|
||||
n
|
||||
);
|
||||
debug_assert!(
|
||||
CHUNK & (CHUNK - 1) == 0,
|
||||
"invalid CHUNK const: not a power of two"
|
||||
);
|
||||
|
||||
match CHUNK{
|
||||
match CHUNK {
|
||||
8 => {
|
||||
|
||||
izip!($a.chunks_exact(8), $b.chunks_exact_mut(8)).for_each(|(a, b)| {
|
||||
$f(&$self, &a[0], $c, &mut b[0]);
|
||||
$f(&$self, &a[1], $c, &mut b[1]);
|
||||
@@ -254,12 +301,12 @@ pub mod macros{
|
||||
$f(&$self, &a[7], $c, &mut b[7]);
|
||||
});
|
||||
|
||||
let m = n - (n&7);
|
||||
let m = n - (n & 7);
|
||||
izip!($a[m..].iter(), $b[m..].iter_mut()).for_each(|(a, b)| {
|
||||
$f(&$self, a, $c, b);
|
||||
});
|
||||
},
|
||||
_=>{
|
||||
}
|
||||
_ => {
|
||||
izip!($a.iter(), $b.iter_mut()).for_each(|(a, b)| {
|
||||
$f(&$self, a, $c, b);
|
||||
});
|
||||
@@ -267,4 +314,4 @@ pub mod macros{
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user