Struct twenty_first::shared_math::lattice::ModuleElement
source · pub struct ModuleElement<const N: usize> { /* private fields */ }
Expand description
The Module is a matrix over the cyclotomic ring (i.e., the ring of residue classes of polynomials modulo X^64+1). The matrix contains N cyclotomic ring elements in total.
Implementations§
source§impl<const N: usize> ModuleElement<N>
impl<const N: usize> ModuleElement<N>
pub fn sample_short(randomness: &[u8]) -> Self
pub fn sample_uniform(randomness: &[u8]) -> Self
pub fn ntt(&self) -> Self
pub fn intt(&self) -> Self
sourcepub fn multiply_hadamard<const LHS_H: usize, const LHS_N: usize, const RHS_W: usize, const RHS_N: usize, const INNER: usize, const OUT_N: usize>(
lhs: ModuleElement<LHS_N>,
rhs: ModuleElement<RHS_N>
) -> ModuleElement<OUT_N>
pub fn multiply_hadamard<const LHS_H: usize, const LHS_N: usize, const RHS_W: usize, const RHS_N: usize, const INNER: usize, const OUT_N: usize>( lhs: ModuleElement<LHS_N>, rhs: ModuleElement<RHS_N> ) -> ModuleElement<OUT_N>
Multiply two module elements from a pair of matrix- multiplication-compatible modules. This method uses hadamard multiplication for cyclotomic ring elements, which is useful for avoiding the repeated conversion to and from NTT domain.
N
counts the total number of elements in the matrix;H
counts the number of rows of the left hand side (and of the output) matrix;W
counts the number of columns of the right hand side (and of the output) matrix;INNER
counts the number of columns of the left hand side, as well as the number of rows of the right hand side.
sourcepub fn multiply<const LHS_H: usize, const LHS_N: usize, const RHS_W: usize, const RHS_N: usize, const INNER: usize, const OUT_N: usize>(
lhs: ModuleElement<LHS_N>,
rhs: ModuleElement<RHS_N>
) -> ModuleElement<OUT_N>
pub fn multiply<const LHS_H: usize, const LHS_N: usize, const RHS_W: usize, const RHS_N: usize, const INNER: usize, const OUT_N: usize>( lhs: ModuleElement<LHS_N>, rhs: ModuleElement<RHS_N> ) -> ModuleElement<OUT_N>
Multiply two module elements from a pair of matrix-
multiplication-compatible modules. This method uses the
multiplication defined for cyclotomic ring elements
abstractly. For a faster method that computes the entire
matrix multiplication in the NTT domain, use fast_multiply
.
N
counts the total number of elements in the matrix;H
counts the number of rows of the left hand side (and of the output) matrix;W
counts the number of columns of the right hand side (and of the output) matrix;INNER
counts the number of columns of the left hand side, as well as the number of rows of the right hand side.
sourcepub fn fast_multiply<const LHS_H: usize, const LHS_N: usize, const RHS_W: usize, const RHS_N: usize, const INNER: usize, const OUT_N: usize>(
lhs: ModuleElement<LHS_N>,
rhs: ModuleElement<RHS_N>
) -> ModuleElement<OUT_N>
pub fn fast_multiply<const LHS_H: usize, const LHS_N: usize, const RHS_W: usize, const RHS_N: usize, const INNER: usize, const OUT_N: usize>( lhs: ModuleElement<LHS_N>, rhs: ModuleElement<RHS_N> ) -> ModuleElement<OUT_N>
Multiply two module elements from a pair of matrix- multiplication-compatible modules, by converting everything into the NTT domain, performing the matrix multiplication, and converting back.
N
counts the total number of elements in the matrix;H
counts the number of rows of the left hand side (and of the output) matrix;W
counts the number of columns of the right hand side (and of the output) matrix;INNER
counts the number of columns of the left hand side, as well as the number of rows of the right hand side.
Trait Implementations§
source§impl<const N: usize> Add<ModuleElement<N>> for ModuleElement<N>
impl<const N: usize> Add<ModuleElement<N>> for ModuleElement<N>
source§impl<const N: usize> Clone for ModuleElement<N>
impl<const N: usize> Clone for ModuleElement<N>
source§fn clone(&self) -> ModuleElement<N>
fn clone(&self) -> ModuleElement<N>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<const N: usize> Debug for ModuleElement<N>
impl<const N: usize> Debug for ModuleElement<N>
source§impl<'de, const N: usize> Deserialize<'de> for ModuleElement<N>
impl<'de, const N: usize> Deserialize<'de> for ModuleElement<N>
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl<const N: usize> PartialEq<ModuleElement<N>> for ModuleElement<N>
impl<const N: usize> PartialEq<ModuleElement<N>> for ModuleElement<N>
source§fn eq(&self, other: &ModuleElement<N>) -> bool
fn eq(&self, other: &ModuleElement<N>) -> bool
self
and other
values to be equal, and is used
by ==
.