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 19 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> + Send { ... } fn zero() -> Self { ... } fn one() -> Self { ... } fn set_single(scalar: Self::Scalar) -> Self { ... } fn from_scalars(values: impl IntoIterator<Item = Self::Scalar>) -> Self { ... } fn spread(self, log_block_len: usize, block_idx: usize) -> 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> + Send

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.

source

fn spread(self, log_block_len: usize, block_idx: usize) -> Self

Spread takes a block of elements within a packed field and repeats them to the full packing width.

Spread can be seen as an extension of the functionality of Self::broadcast.

§Examples
use binius_field::{BinaryField16b, PackedField, PackedBinaryField8x16b};

let input =
    PackedBinaryField8x16b::from_scalars([0, 1, 2, 3, 4, 5, 6, 7].map(BinaryField16b::new));
assert_eq!(
    input.spread(0, 5),
    PackedBinaryField8x16b::from_scalars([5, 5, 5, 5, 5, 5, 5, 5].map(BinaryField16b::new))
);
assert_eq!(
    input.spread(1, 2),
    PackedBinaryField8x16b::from_scalars([4, 4, 4, 4, 5, 5, 5, 5].map(BinaryField16b::new))
);
assert_eq!(
    input.spread(2, 1),
    PackedBinaryField8x16b::from_scalars([4, 4, 5, 5, 6, 6, 7, 7].map(BinaryField16b::new))
);
assert_eq!(input.spread(3, 0), input);
§Preconditions
  • log_block_len must be less than or equal to LOG_WIDTH.
  • block_idx must be less than 2^(Self::LOG_WIDTH - log_block_len).

Object Safety§

This trait is not object safe.

Implementors§