pub struct RNSConvolution<I = BigIntRing, C = NTTConvolution<Zn>, A = Global, CreateC = CreateNTTConvolution>where
I: RingStore + Clone,
I::Type: IntegerRing,
C: ConvolutionAlgorithm<ZnBase>,
A: Allocator + Clone,
CreateC: Fn(Zn) -> C,{ /* private fields */ }Expand description
A ConvolutionAlgorithm that computes convolutions by computing them modulo a
suitable composite modulus q, whose factors are of a certain shape, usually such
as to allow for NTT-based convolutions.
Due to overlapping blanket impls, this type can only be used to compute convolutions
over IntegerRings. For computing convolutions over ZnRings, wrap it in a
RNSConvolutionZn.
§Availability
This API is marked as unstable and is only available when the unstable-enable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.
Implementations§
Source§impl RNSConvolution
impl RNSConvolution
Sourcepub fn new(max_log2_n: usize) -> Self
pub fn new(max_log2_n: usize) -> Self
Creates a new RNSConvolution that can compute convolutions of sequences with output
length <= 2^max_log2_n. As base convolution, the NTTConvolution is used.
§Availability
This API is marked as unstable and is only available when the unstable-enable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.
Source§impl<I, C, A, CreateC> RNSConvolution<I, C, A, CreateC>where
I: RingStore + Clone,
I::Type: IntegerRing,
C: ConvolutionAlgorithm<ZnBase>,
A: Allocator + Clone,
CreateC: Fn(Zn) -> C,
impl<I, C, A, CreateC> RNSConvolution<I, C, A, CreateC>where
I: RingStore + Clone,
I::Type: IntegerRing,
C: ConvolutionAlgorithm<ZnBase>,
A: Allocator + Clone,
CreateC: Fn(Zn) -> C,
Sourcepub fn new_with(
required_root_of_unity_log2: usize,
max_prime_size_log2: usize,
integer_ring: I,
allocator: A,
create_convolution: CreateC,
) -> Self
pub fn new_with( required_root_of_unity_log2: usize, max_prime_size_log2: usize, integer_ring: I, allocator: A, create_convolution: CreateC, ) -> Self
Creates a new RNSConvolution with all the given configuration parameters.
In particular
required_root_of_unity_log2andmax_prime_size_log2control which prime factors are used for the underlying composite modulus; Only primes<= 2^max_prime_size_log2and= 1modrequired_root_of_unity_log2are sampledinteger_ringis the ring to store intermediate lifts in; this probably has to beBigIntRing, unless inputs are pretty smallallocatoris used to allocate elements modulo the internal modulus, as elements ofzn_rns::Zncreate_convolutionis called whenever a new convolution algorithm for a new prime has to be created; the modulus of the givenZnalways satisfies the constraints defined bymax_prime_size_log2andrequired_root_of_unity_log2
§Availability
This API is marked as unstable and is only available when the unstable-enable crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time.
Trait Implementations§
Source§impl<R, I, C, A, CreateC> ConvolutionAlgorithm<R> for RNSConvolution<I, C, A, CreateC>where
I: RingStore + Clone,
I::Type: IntegerRing,
C: ConvolutionAlgorithm<ZnBase>,
A: Allocator + Clone,
CreateC: Fn(Zn) -> C,
R: ?Sized + IntegerRing,
impl<R, I, C, A, CreateC> ConvolutionAlgorithm<R> for RNSConvolution<I, C, A, CreateC>where
I: RingStore + Clone,
I::Type: IntegerRing,
C: ConvolutionAlgorithm<ZnBase>,
A: Allocator + Clone,
CreateC: Fn(Zn) -> C,
R: ?Sized + IntegerRing,
Source§fn compute_convolution<S: RingStore<Type = R> + Copy, V1: VectorView<<R as RingBase>::Element>, V2: VectorView<<R as RingBase>::Element>>(
&self,
lhs: V1,
rhs: V2,
dst: &mut [<R as RingBase>::Element],
ring: S,
)
fn compute_convolution<S: RingStore<Type = R> + Copy, V1: VectorView<<R as RingBase>::Element>, V2: VectorView<<R as RingBase>::Element>>( &self, lhs: V1, rhs: V2, dst: &mut [<R as RingBase>::Element], ring: S, )
Source§fn supports_ring<S: RingStore<Type = R> + Copy>(&self, _ring: S) -> bool
fn supports_ring<S: RingStore<Type = R> + Copy>(&self, _ring: S) -> bool
Source§fn specialize_prepared_convolution<F>(function: F) -> Result<F::Output, F>where
F: PreparedConvolutionOperation<Self, R>,
fn specialize_prepared_convolution<F>(function: F) -> Result<F::Output, F>where
F: PreparedConvolutionOperation<Self, R>,
PreparedConvolutionAlgorithm, then
the given function is called and its result is returned. Otherwise,
Err is returned.Source§impl<'a, I, C, A, CreateC> From<&'a RNSConvolution<I, C, A, CreateC>> for &'a RNSConvolutionZn<I, C, A, CreateC>where
I: RingStore + Clone,
I::Type: IntegerRing,
C: ConvolutionAlgorithm<ZnBase>,
A: Allocator + Clone,
CreateC: Fn(Zn) -> C,
impl<'a, I, C, A, CreateC> From<&'a RNSConvolution<I, C, A, CreateC>> for &'a RNSConvolutionZn<I, C, A, CreateC>where
I: RingStore + Clone,
I::Type: IntegerRing,
C: ConvolutionAlgorithm<ZnBase>,
A: Allocator + Clone,
CreateC: Fn(Zn) -> C,
Source§fn from(value: &'a RNSConvolution<I, C, A, CreateC>) -> Self
fn from(value: &'a RNSConvolution<I, C, A, CreateC>) -> Self
Source§impl<'a, I, C, A, CreateC> From<&'a RNSConvolutionZn<I, C, A, CreateC>> for &'a RNSConvolution<I, C, A, CreateC>where
I: RingStore + Clone,
I::Type: IntegerRing,
C: ConvolutionAlgorithm<ZnBase>,
A: Allocator + Clone,
CreateC: Fn(Zn) -> C,
impl<'a, I, C, A, CreateC> From<&'a RNSConvolutionZn<I, C, A, CreateC>> for &'a RNSConvolution<I, C, A, CreateC>where
I: RingStore + Clone,
I::Type: IntegerRing,
C: ConvolutionAlgorithm<ZnBase>,
A: Allocator + Clone,
CreateC: Fn(Zn) -> C,
Source§fn from(value: &'a RNSConvolutionZn<I, C, A, CreateC>) -> Self
fn from(value: &'a RNSConvolutionZn<I, C, A, CreateC>) -> Self
Source§impl<I, C, A, CreateC> From<RNSConvolution<I, C, A, CreateC>> for RNSConvolutionZn<I, C, A, CreateC>where
I: RingStore + Clone,
I::Type: IntegerRing,
C: ConvolutionAlgorithm<ZnBase>,
A: Allocator + Clone,
CreateC: Fn(Zn) -> C,
impl<I, C, A, CreateC> From<RNSConvolution<I, C, A, CreateC>> for RNSConvolutionZn<I, C, A, CreateC>where
I: RingStore + Clone,
I::Type: IntegerRing,
C: ConvolutionAlgorithm<ZnBase>,
A: Allocator + Clone,
CreateC: Fn(Zn) -> C,
Source§fn from(value: RNSConvolution<I, C, A, CreateC>) -> Self
fn from(value: RNSConvolution<I, C, A, CreateC>) -> Self
Source§impl<I, C, A, CreateC> From<RNSConvolutionZn<I, C, A, CreateC>> for RNSConvolution<I, C, A, CreateC>where
I: RingStore + Clone,
I::Type: IntegerRing,
C: ConvolutionAlgorithm<ZnBase>,
A: Allocator + Clone,
CreateC: Fn(Zn) -> C,
impl<I, C, A, CreateC> From<RNSConvolutionZn<I, C, A, CreateC>> for RNSConvolution<I, C, A, CreateC>where
I: RingStore + Clone,
I::Type: IntegerRing,
C: ConvolutionAlgorithm<ZnBase>,
A: Allocator + Clone,
CreateC: Fn(Zn) -> C,
Source§fn from(value: RNSConvolutionZn<I, C, A, CreateC>) -> Self
fn from(value: RNSConvolutionZn<I, C, A, CreateC>) -> Self
Source§impl<R, I, C, A, CreateC> PreparedConvolutionAlgorithm<R> for RNSConvolution<I, C, A, CreateC>where
I: RingStore + Clone,
I::Type: IntegerRing,
C: PreparedConvolutionAlgorithm<ZnBase>,
A: Allocator + Clone,
CreateC: Fn(Zn) -> C,
R: ?Sized + IntegerRing,
impl<R, I, C, A, CreateC> PreparedConvolutionAlgorithm<R> for RNSConvolution<I, C, A, CreateC>where
I: RingStore + Clone,
I::Type: IntegerRing,
C: PreparedConvolutionAlgorithm<ZnBase>,
A: Allocator + Clone,
CreateC: Fn(Zn) -> C,
R: ?Sized + IntegerRing,
type PreparedConvolutionOperand = PreparedConvolutionOperand<R, C>
fn prepare_convolution_operand<S, V>( &self, val: V, ring: S, ) -> Self::PreparedConvolutionOperand
fn compute_convolution_lhs_prepared<S, V>( &self, lhs: &Self::PreparedConvolutionOperand, rhs: V, dst: &mut [R::Element], ring: S, )
fn compute_convolution_prepared<S>( &self, lhs: &Self::PreparedConvolutionOperand, rhs: &Self::PreparedConvolutionOperand, dst: &mut [R::Element], ring: S, )
fn compute_convolution_inner_product_lhs_prepared<'a, S, J, V>(
&self,
values: J,
dst: &mut [R::Element],
ring: S,
)where
S: RingStore<Type = R> + Copy,
J: Iterator<Item = (&'a Self::PreparedConvolutionOperand, V)>,
V: VectorView<R::Element>,
Self: 'a,
R: 'a,
Self::PreparedConvolutionOperand: 'a,
fn compute_convolution_inner_product_prepared<'a, S, J>(
&self,
values: J,
dst: &mut [R::Element],
ring: S,
)where
S: RingStore<Type = R> + Copy,
J: Iterator<Item = (&'a Self::PreparedConvolutionOperand, &'a Self::PreparedConvolutionOperand)>,
Self::PreparedConvolutionOperand: 'a,
Self: 'a,
R: 'a,
fn compute_convolution_rhs_prepared<S, V>( &self, lhs: V, rhs: &Self::PreparedConvolutionOperand, dst: &mut [R::Element], ring: S, )
Auto Trait Implementations§
impl<I = RingValue<MPZBase>, C = NTTConvolution<RingValue<ZnBase>>, A = Global, CreateC = CreateNTTConvolution> !Freeze for RNSConvolution<I, C, A, CreateC>
impl<I = RingValue<MPZBase>, C = NTTConvolution<RingValue<ZnBase>>, A = Global, CreateC = CreateNTTConvolution> !RefUnwindSafe for RNSConvolution<I, C, A, CreateC>
impl<I, C, A, CreateC> Send for RNSConvolution<I, C, A, CreateC>
impl<I, C, A, CreateC> Sync for RNSConvolution<I, C, A, CreateC>
impl<I, C, A, CreateC> Unpin for RNSConvolution<I, C, A, CreateC>
impl<I, C, A, CreateC> UnwindSafe for RNSConvolution<I, C, A, CreateC>where
I: UnwindSafe + RefUnwindSafe,
CreateC: UnwindSafe,
A: UnwindSafe + RefUnwindSafe,
C: RefUnwindSafe + UnwindSafe,
<<I as RingStore>::Type as RingBase>::Element: RefUnwindSafe + UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more