pub struct SparseMultilinearExtension<F: Field> {
pub evaluations: BTreeMap<usize, F>,
pub num_vars: usize,
/* private fields */
}
Expand description
Stores a multilinear polynomial in sparse evaluation form.
Fields§
§evaluations: BTreeMap<usize, F>
tuples of index and value
num_vars: usize
number of variables
Implementations§
Source§impl<F: Field> SparseMultilinearExtension<F>
impl<F: Field> SparseMultilinearExtension<F>
pub fn from_evaluations<'a>( num_vars: usize, evaluations: impl IntoIterator<Item = &'a (usize, F)>, ) -> Self
Sourcepub fn rand_with_config<R: Rng>(
num_vars: usize,
num_nonzero_entries: usize,
rng: &mut R,
) -> Self
pub fn rand_with_config<R: Rng>( num_vars: usize, num_nonzero_entries: usize, rng: &mut R, ) -> Self
Outputs an l
-variate multilinear extension where value of evaluations
are sampled uniformly at random. The number of nonzero entries is
num_nonzero_entries
and indices of those nonzero entries are
distributed uniformly at random.
Note that this function uses rejection sampling. As number of nonzero
entries approach 2 ^ num_vars
, sampling will be very slow due to
large number of collisions.
Sourcepub fn to_dense_multilinear_extension(&self) -> DenseMultilinearExtension<F>
pub fn to_dense_multilinear_extension(&self) -> DenseMultilinearExtension<F>
Convert the sparse multilinear polynomial to dense form.
Trait Implementations§
Source§impl<'a, 'b, F: Field> Add<&'a SparseMultilinearExtension<F>> for &'b SparseMultilinearExtension<F>
impl<'a, 'b, F: Field> Add<&'a SparseMultilinearExtension<F>> for &'b SparseMultilinearExtension<F>
Source§type Output = SparseMultilinearExtension<F>
type Output = SparseMultilinearExtension<F>
+
operator.Source§impl<F: Field> Add for SparseMultilinearExtension<F>
impl<F: Field> Add for SparseMultilinearExtension<F>
Source§type Output = SparseMultilinearExtension<F>
type Output = SparseMultilinearExtension<F>
+
operator.Source§fn add(self, other: SparseMultilinearExtension<F>) -> Self
fn add(self, other: SparseMultilinearExtension<F>) -> Self
+
operation. Read moreSource§impl<'a, F: Field> AddAssign<&'a SparseMultilinearExtension<F>> for SparseMultilinearExtension<F>
impl<'a, F: Field> AddAssign<&'a SparseMultilinearExtension<F>> for SparseMultilinearExtension<F>
Source§fn add_assign(&mut self, other: &'a SparseMultilinearExtension<F>)
fn add_assign(&mut self, other: &'a SparseMultilinearExtension<F>)
+=
operation. Read moreSource§impl<'a, F: Field> AddAssign<(F, &'a SparseMultilinearExtension<F>)> for SparseMultilinearExtension<F>
impl<'a, F: Field> AddAssign<(F, &'a SparseMultilinearExtension<F>)> for SparseMultilinearExtension<F>
Source§fn add_assign(&mut self, (f, other): (F, &'a SparseMultilinearExtension<F>))
fn add_assign(&mut self, (f, other): (F, &'a SparseMultilinearExtension<F>))
+=
operation. Read moreSource§impl<F: Field> AddAssign for SparseMultilinearExtension<F>
impl<F: Field> AddAssign for SparseMultilinearExtension<F>
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+=
operation. Read moreSource§impl<F: Field> CanonicalDeserialize for SparseMultilinearExtension<F>
impl<F: Field> CanonicalDeserialize for SparseMultilinearExtension<F>
Source§fn deserialize_with_mode<R: Read>(
reader: R,
compress: Compress,
validate: Validate,
) -> Result<Self, SerializationError>
fn deserialize_with_mode<R: Read>( reader: R, compress: Compress, validate: Validate, ) -> Result<Self, SerializationError>
fn deserialize_compressed<R>(reader: R) -> Result<Self, SerializationError>where
R: Read,
fn deserialize_compressed_unchecked<R>(
reader: R,
) -> Result<Self, SerializationError>where
R: Read,
fn deserialize_uncompressed<R>(reader: R) -> Result<Self, SerializationError>where
R: Read,
fn deserialize_uncompressed_unchecked<R>(
reader: R,
) -> Result<Self, SerializationError>where
R: Read,
Source§impl<F: Field> CanonicalSerialize for SparseMultilinearExtension<F>
impl<F: Field> CanonicalSerialize for SparseMultilinearExtension<F>
Source§fn serialize_with_mode<W: Write>(
&self,
writer: W,
compress: Compress,
) -> Result<(), SerializationError>
fn serialize_with_mode<W: Write>( &self, writer: W, compress: Compress, ) -> Result<(), SerializationError>
fn serialized_size(&self, compress: Compress) -> usize
fn serialize_compressed<W>(&self, writer: W) -> Result<(), SerializationError>where
W: Write,
fn compressed_size(&self) -> usize
fn serialize_uncompressed<W>(&self, writer: W) -> Result<(), SerializationError>where
W: Write,
fn uncompressed_size(&self) -> usize
Source§impl<F: Clone + Field> Clone for SparseMultilinearExtension<F>
impl<F: Clone + Field> Clone for SparseMultilinearExtension<F>
Source§fn clone(&self) -> SparseMultilinearExtension<F>
fn clone(&self) -> SparseMultilinearExtension<F>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<F: Field> Debug for SparseMultilinearExtension<F>
impl<F: Field> Debug for SparseMultilinearExtension<F>
Source§impl<F: Default + Field> Default for SparseMultilinearExtension<F>
impl<F: Default + Field> Default for SparseMultilinearExtension<F>
Source§fn default() -> SparseMultilinearExtension<F>
fn default() -> SparseMultilinearExtension<F>
Source§impl<F: Field> Index<usize> for SparseMultilinearExtension<F>
impl<F: Field> Index<usize> for SparseMultilinearExtension<F>
Source§fn index(&self, index: usize) -> &Self::Output
fn index(&self, index: usize) -> &Self::Output
Returns the evaluation of the polynomial at a point represented by index.
Index represents a vector in {0,1}^num_vars
in little endian form. For
example, 0b1011
represents P(1,1,0,1)
For Sparse multilinear polynomial, Lookup_evaluation takes log time to the size of polynomial.
Source§impl<F: Field> MultilinearExtension<F> for SparseMultilinearExtension<F>
impl<F: Field> MultilinearExtension<F> for SparseMultilinearExtension<F>
Source§fn rand<R: Rng>(num_vars: usize, rng: &mut R) -> Self
fn rand<R: Rng>(num_vars: usize, rng: &mut R) -> Self
Outputs an l
-variate multilinear extension where value of evaluations
are sampled uniformly at random. The number of nonzero entries is
sqrt(2^num_vars)
and indices of those nonzero entries are distributed
uniformly at random.
Source§fn relabel(&self, a: usize, b: usize, k: usize) -> Self
fn relabel(&self, a: usize, b: usize, k: usize) -> Self
k
scalars from positions a..a+k
to
positions b..b+k
, and from position b..b+k
to position a..a+k
in vector. Read moreSource§fn fix_variables(&self, partial_point: &[F]) -> Self
fn fix_variables(&self, partial_point: &[F]) -> Self
self
by fixing the
partial_point.len()
variables at partial_point
.Source§fn to_evaluations(&self) -> Vec<F>
fn to_evaluations(&self) -> Vec<F>
Source§impl<F: Field> Neg for SparseMultilinearExtension<F>
impl<F: Field> Neg for SparseMultilinearExtension<F>
Source§impl<F: PartialEq + Field> PartialEq for SparseMultilinearExtension<F>
impl<F: PartialEq + Field> PartialEq for SparseMultilinearExtension<F>
Source§fn eq(&self, other: &SparseMultilinearExtension<F>) -> bool
fn eq(&self, other: &SparseMultilinearExtension<F>) -> bool
self
and other
values to be equal, and is used by ==
.Source§impl<F: Field> Polynomial<F> for SparseMultilinearExtension<F>
impl<F: Field> Polynomial<F> for SparseMultilinearExtension<F>
Source§impl<'a, 'b, F: Field> Sub<&'a SparseMultilinearExtension<F>> for &'b SparseMultilinearExtension<F>
impl<'a, 'b, F: Field> Sub<&'a SparseMultilinearExtension<F>> for &'b SparseMultilinearExtension<F>
Source§type Output = SparseMultilinearExtension<F>
type Output = SparseMultilinearExtension<F>
-
operator.Source§impl<F: Field> Sub for SparseMultilinearExtension<F>
impl<F: Field> Sub for SparseMultilinearExtension<F>
Source§type Output = SparseMultilinearExtension<F>
type Output = SparseMultilinearExtension<F>
-
operator.Source§fn sub(self, other: SparseMultilinearExtension<F>) -> Self
fn sub(self, other: SparseMultilinearExtension<F>) -> Self
-
operation. Read moreSource§impl<'a, F: Field> SubAssign<&'a SparseMultilinearExtension<F>> for SparseMultilinearExtension<F>
impl<'a, F: Field> SubAssign<&'a SparseMultilinearExtension<F>> for SparseMultilinearExtension<F>
Source§fn sub_assign(&mut self, other: &'a SparseMultilinearExtension<F>)
fn sub_assign(&mut self, other: &'a SparseMultilinearExtension<F>)
-=
operation. Read moreSource§impl<F: Field> SubAssign for SparseMultilinearExtension<F>
impl<F: Field> SubAssign for SparseMultilinearExtension<F>
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
-=
operation. Read more