pub trait PackedField:
Default
+ Debug
+ Clone
+ Copy
+ Eq
+ Sized
+ Add<Output = Self>
+ Sub<Output = Self>
+ Mul<Output = Self>
+ AddAssign
+ SubAssign
+ MulAssign
+ Add<Self::Scalar, Output = Self>
+ Sub<Self::Scalar, Output = Self>
+ Mul<Self::Scalar, Output = Self>
+ AddAssign<Self::Scalar>
+ SubAssign<Self::Scalar>
+ MulAssign<Self::Scalar>
+ Sum
+ Product
+ Send
+ Sync
+ Zeroable
+ 'static {
type Scalar: Field;
const LOG_WIDTH: usize;
const WIDTH: usize = _;
Show 18 methods
// Required methods
unsafe fn get_unchecked(&self, i: usize) -> Self::Scalar;
unsafe fn set_unchecked(&mut self, i: usize, scalar: Self::Scalar);
fn random(rng: impl RngCore) -> Self;
fn broadcast(scalar: Self::Scalar) -> Self;
fn from_fn(f: impl FnMut(usize) -> Self::Scalar) -> Self;
fn square(self) -> Self;
fn invert_or_zero(self) -> Self;
fn interleave(self, other: Self, log_block_len: usize) -> (Self, Self);
// Provided methods
fn get_checked(&self, i: usize) -> Result<Self::Scalar, Error> { ... }
fn set_checked(
&mut self,
i: usize,
scalar: Self::Scalar,
) -> Result<(), Error> { ... }
fn get(&self, i: usize) -> Self::Scalar { ... }
fn set(&mut self, i: usize, scalar: Self::Scalar) { ... }
fn into_iter(self) -> impl Iterator<Item = Self::Scalar> { ... }
fn iter(&self) -> impl Iterator<Item = Self::Scalar> { ... }
fn zero() -> Self { ... }
fn one() -> Self { ... }
fn set_single(scalar: Self::Scalar) -> Self { ... }
fn from_scalars(values: impl IntoIterator<Item = Self::Scalar>) -> Self { ... }
}
Expand description
A packed field represents a vector of underlying field elements.
Arithmetic operations on packed field elements can be accelerated with SIMD CPU instructions.
The vector width is a constant, WIDTH
. This trait requires that the width must be a power of
two.
Required Associated Constants§
Provided Associated Constants§
Required Associated Types§
Required Methods§
sourceunsafe fn get_unchecked(&self, i: usize) -> Self::Scalar
unsafe fn get_unchecked(&self, i: usize) -> Self::Scalar
Get the scalar at a given index without bounds checking.
§Safety
The caller must ensure that i
is less than WIDTH
.
sourceunsafe fn set_unchecked(&mut self, i: usize, scalar: Self::Scalar)
unsafe fn set_unchecked(&mut self, i: usize, scalar: Self::Scalar)
Set the scalar at a given index without bounds checking.
§Safety
The caller must ensure that i
is less than WIDTH
.
fn random(rng: impl RngCore) -> Self
fn broadcast(scalar: Self::Scalar) -> Self
sourcefn from_fn(f: impl FnMut(usize) -> Self::Scalar) -> Self
fn from_fn(f: impl FnMut(usize) -> Self::Scalar) -> Self
Construct a packed field element from a function that returns scalar values by index.
sourcefn invert_or_zero(self) -> Self
fn invert_or_zero(self) -> Self
Returns the packed inverse values or zeroes at indices where self
is zero.
sourcefn interleave(self, other: Self, log_block_len: usize) -> (Self, Self)
fn interleave(self, other: Self, log_block_len: usize) -> (Self, Self)
Interleaves blocks of this packed vector with another packed vector.
The operation can be seen as stacking the two vectors, dividing them into 2x2 matrices of
blocks, where each block is 2^log_block_width
elements, and transposing the matrices.
Consider this example, where LOG_WIDTH
is 3 and log_block_len
is 1:
A = [a0, a1, a2, a3, a4, a5, a6, a7]
B = [b0, b1, b2, b3, b4, b5, b6, b7]
The interleaved result is A’ = [a0, a1, b0, b1, a4, a5, b4, b5] B’ = [a2, a3, b2, b3, a6, a7, b6, b7]
§Preconditions
log_block_len
must be strictly less thanLOG_WIDTH
.
Provided Methods§
sourcefn get_checked(&self, i: usize) -> Result<Self::Scalar, Error>
fn get_checked(&self, i: usize) -> Result<Self::Scalar, Error>
Get the scalar at a given index.
sourcefn set_checked(&mut self, i: usize, scalar: Self::Scalar) -> Result<(), Error>
fn set_checked(&mut self, i: usize, scalar: Self::Scalar) -> Result<(), Error>
Set the scalar at a given index.
fn into_iter(self) -> impl Iterator<Item = Self::Scalar>
fn iter(&self) -> impl Iterator<Item = Self::Scalar>
fn zero() -> Self
fn one() -> Self
sourcefn set_single(scalar: Self::Scalar) -> Self
fn set_single(scalar: Self::Scalar) -> Self
Initialize zero position with scalar
, set other elements to zero.
sourcefn from_scalars(values: impl IntoIterator<Item = Self::Scalar>) -> Self
fn from_scalars(values: impl IntoIterator<Item = Self::Scalar>) -> Self
Construct a packed field element from a sequence of scalars.
If the number of values in the sequence is less than the packing width, the remaining elements are set to zero. If greater than the packing width, the excess elements are ignored.