mirror of
https://github.com/arnaucube/poulpy.git
synced 2026-02-10 21:26:41 +01:00
Ref. + AVX code & generic tests + benches (#85)
This commit is contained in:
committed by
GitHub
parent
99b9e3e10e
commit
56dbd29c59
@@ -1,12 +1,19 @@
|
||||
use std::marker::PhantomData;
|
||||
use std::{
|
||||
fmt,
|
||||
hash::{DefaultHasher, Hasher},
|
||||
marker::PhantomData,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
alloc_aligned,
|
||||
layouts::{Backend, Data, DataMut, DataRef, DataView, DataViewMut, ReaderFrom, WriterTo, ZnxInfos, ZnxSliceSize, ZnxView},
|
||||
layouts::{
|
||||
Backend, Data, DataMut, DataRef, DataView, DataViewMut, DigestU64, ReaderFrom, WriterTo, ZnxInfos, ZnxSliceSize, ZnxView,
|
||||
},
|
||||
oep::SvpPPolAllocBytesImpl,
|
||||
};
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
#[repr(C)]
|
||||
#[derive(PartialEq, Eq, Hash)]
|
||||
pub struct SvpPPol<D: Data, B: Backend> {
|
||||
pub data: D,
|
||||
pub n: usize,
|
||||
@@ -14,6 +21,16 @@ pub struct SvpPPol<D: Data, B: Backend> {
|
||||
pub _phantom: PhantomData<B>,
|
||||
}
|
||||
|
||||
impl<D: DataRef, B: Backend> DigestU64 for SvpPPol<D, B> {
|
||||
fn digest_u64(&self) -> u64 {
|
||||
let mut h: DefaultHasher = DefaultHasher::new();
|
||||
h.write(self.data.as_ref());
|
||||
h.write_usize(self.n);
|
||||
h.write_usize(self.cols);
|
||||
h.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data, B: Backend> ZnxSliceSize for SvpPPol<D, B> {
|
||||
fn sl(&self) -> usize {
|
||||
B::layout_prep_word_count() * self.n()
|
||||
@@ -153,3 +170,32 @@ impl<D: DataRef, B: Backend> WriterTo for SvpPPol<D, B> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef, B: Backend> fmt::Display for SvpPPol<D, B> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
writeln!(f, "SvpPPol(n={}, cols={})", self.n, self.cols)?;
|
||||
|
||||
for col in 0..self.cols {
|
||||
writeln!(f, "Column {}:", col)?;
|
||||
let coeffs = self.at(col, 0);
|
||||
write!(f, "[")?;
|
||||
|
||||
let max_show = 100;
|
||||
let show_count = coeffs.len().min(max_show);
|
||||
|
||||
for (i, &coeff) in coeffs.iter().take(show_count).enumerate() {
|
||||
if i > 0 {
|
||||
write!(f, ", ")?;
|
||||
}
|
||||
write!(f, "{}", coeff)?;
|
||||
}
|
||||
|
||||
if coeffs.len() > max_show {
|
||||
write!(f, ", ... ({} more)", coeffs.len() - max_show)?;
|
||||
}
|
||||
|
||||
writeln!(f, "]")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user