binius_field::packed

Trait PackedField

source
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§

source

const LOG_WIDTH: usize

Base-2 logarithm of the number of field elements packed into one packed element.

Provided Associated Constants§

source

const WIDTH: usize = _

The number of field elements packed into one packed element.

WIDTH is guaranteed to equal 2^LOG_WIDTH.

Required Associated Types§

Required Methods§

source

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.

source

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.

source

fn random(rng: impl RngCore) -> Self

source

fn broadcast(scalar: Self::Scalar) -> Self

source

fn from_fn(f: impl FnMut(usize) -> Self::Scalar) -> Self

Construct a packed field element from a function that returns scalar values by index.

source

fn square(self) -> Self

Returns the value multiplied by itself

source

fn invert_or_zero(self) -> Self

Returns the packed inverse values or zeroes at indices where self is zero.

source

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 than LOG_WIDTH.

Provided Methods§

source

fn get_checked(&self, i: usize) -> Result<Self::Scalar, Error>

Get the scalar at a given index.

source

fn set_checked(&mut self, i: usize, scalar: Self::Scalar) -> Result<(), Error>

Set the scalar at a given index.

source

fn get(&self, i: usize) -> Self::Scalar

Get the scalar at a given index.

source

fn set(&mut self, i: usize, scalar: Self::Scalar)

Set the scalar at a given index.

source

fn into_iter(self) -> impl Iterator<Item = Self::Scalar>

source

fn iter(&self) -> impl Iterator<Item = Self::Scalar>

source

fn zero() -> Self

source

fn one() -> Self

source

fn set_single(scalar: Self::Scalar) -> Self

Initialize zero position with scalar, set other elements to zero.

source

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.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<F: Field> PackedField for F

source§

const LOG_WIDTH: usize = 0usize

source§

type Scalar = F