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,17 +1,21 @@
|
||||
use crate::{
|
||||
alloc_aligned,
|
||||
layouts::{
|
||||
Data, DataMut, DataRef, DataView, DataViewMut, FillUniform, ReaderFrom, Reset, ToOwnedDeep, VecZnx, WriterTo, ZnxInfos,
|
||||
ZnxSliceSize, ZnxView, ZnxViewMut, ZnxZero,
|
||||
Data, DataMut, DataRef, DataView, DataViewMut, DigestU64, FillUniform, ReaderFrom, Reset, ToOwnedDeep, VecZnx, WriterTo,
|
||||
ZnxInfos, ZnxSliceSize, ZnxView, ZnxViewMut, ZnxZero,
|
||||
},
|
||||
source::Source,
|
||||
};
|
||||
use std::fmt;
|
||||
use std::{
|
||||
fmt,
|
||||
hash::{DefaultHasher, Hasher},
|
||||
};
|
||||
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
use rand::RngCore;
|
||||
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
#[repr(C)]
|
||||
#[derive(PartialEq, Eq, Clone, Hash)]
|
||||
pub struct MatZnx<D: Data> {
|
||||
data: D,
|
||||
n: usize,
|
||||
@@ -21,6 +25,19 @@ pub struct MatZnx<D: Data> {
|
||||
cols_out: usize,
|
||||
}
|
||||
|
||||
impl<D: DataRef> DigestU64 for MatZnx<D> {
|
||||
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.size);
|
||||
h.write_usize(self.rows);
|
||||
h.write_usize(self.cols_in);
|
||||
h.write_usize(self.cols_out);
|
||||
h.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DataRef> ToOwnedDeep for MatZnx<D> {
|
||||
type Owned = MatZnx<Vec<u8>>;
|
||||
fn to_owned_deep(&self) -> Self::Owned {
|
||||
@@ -57,6 +74,10 @@ impl<D: Data> ZnxInfos for MatZnx<D> {
|
||||
fn size(&self) -> usize {
|
||||
self.size
|
||||
}
|
||||
|
||||
fn poly_count(&self) -> usize {
|
||||
self.rows() * self.cols_in() * self.cols_out() * self.size()
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: Data> ZnxSliceSize for MatZnx<D> {
|
||||
@@ -175,8 +196,18 @@ impl<D: DataMut> MatZnx<D> {
|
||||
}
|
||||
|
||||
impl<D: DataMut> FillUniform for MatZnx<D> {
|
||||
fn fill_uniform(&mut self, source: &mut Source) {
|
||||
source.fill_bytes(self.data.as_mut());
|
||||
fn fill_uniform(&mut self, log_bound: usize, source: &mut Source) {
|
||||
match log_bound {
|
||||
64 => source.fill_bytes(self.data.as_mut()),
|
||||
0 => panic!("invalid log_bound, cannot be zero"),
|
||||
_ => {
|
||||
let mask: u64 = (1u64 << log_bound) - 1;
|
||||
for x in self.raw_mut().iter_mut() {
|
||||
let r = source.next_u64() & mask;
|
||||
*x = ((r << (64 - log_bound)) as i64) >> (64 - log_bound);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user