Skip to main content

PackedFieldExtension

Trait PackedFieldExtension 

Source
pub trait PackedFieldExtension<BaseField: Field, ExtField: ExtensionField<BaseField, ExtensionPacking = Self>>:
    Algebra<ExtField>
    + Algebra<BaseField::Packing>
    + BasedVectorSpace<BaseField::Packing> {
    // Required method
    fn packed_ext_powers(base: ExtField) -> Powers<Self> ;

    // Provided methods
    fn from_ext_fn(f: impl Fn(usize) -> ExtField) -> Self { ... }
    fn from_ext_slice(slice: &[ExtField]) -> Self { ... }
    fn pack_ext_columns<const N: usize>(rows: &[[ExtField; N]]) -> [Self; N] { ... }
    fn pack_ext_columns_fn<const N: usize>(
        row_fn: impl Fn(usize) -> [ExtField; N],
    ) -> [Self; N] { ... }
    fn extract(&self, lane: usize) -> ExtField { ... }
    fn to_ext_slice(&self, out: &mut [ExtField]) { ... }
    fn unpack_ext_into<const N: usize>(
        packed: &[Self; N],
        rows: &mut [[ExtField; N]],
    ) { ... }
    fn unpack_ext_iter<const N: usize>(
        packed: [Self; N],
    ) -> impl Iterator<Item = [ExtField; N]> { ... }
    fn to_ext_iter(
        iter: impl IntoIterator<Item = Self>,
    ) -> impl Iterator<Item = ExtField> { ... }
    fn packed_ext_powers_capped(
        base: ExtField,
        unpacked_len: usize,
    ) -> impl Iterator<Item = Self> { ... }
}
Expand description

Fix a field F a packing width W and an extension field EF of F.

By choosing a basis B, EF can be transformed into an array [F; D].

A type should implement PackedFieldExtension if it can be transformed into [F::Packing; D] ~ [[F; W]; D]

This is interpreted by taking a transpose to get [[F; D]; W] which can then be reinterpreted as [EF; W] by making use of the chosen basis B again.

Required Methods§

Source

fn packed_ext_powers(base: ExtField) -> Powers<Self>

Similar to packed_powers, construct an iterator which returns powers of base packed into PackedFieldExtension elements.

Provided Methods§

Source

fn from_ext_fn(f: impl Fn(usize) -> ExtField) -> Self

Construct a packed extension by applying f to each lane.

This is the extension-field analog of PackedValue::from_fn and the canonical primitive constructor for packed extensions: every other constructor in this trait (from_ext_slice, pack_ext_columns, etc.) routes through it.

f is called once per (basis_coefficient, lane) pair (D * W calls total), hence the Fn bound — closures with side effects are unsuitable.

The default impl uses only the BasedVectorSpace machinery the trait already requires. Concrete impls should override when the extension struct exposes its base packings directly, e.g. Self::new(F::Packing::pack_columns_fn(|l| f(l).value)).

Source

fn from_ext_slice(slice: &[ExtField]) -> Self

Pack a length-WIDTH slice of extension field elements into one packed extension.

§Panics

Panics if slice.len() != BaseField::Packing::WIDTH.

Source

fn pack_ext_columns<const N: usize>(rows: &[[ExtField; N]]) -> [Self; N]

Pack N columns from W rows of extension field elements into N packed extensions.

This is the extension-field analog of PackedValue::pack_columns: given W rows of N extension elements, lane lane of output column col is rows[lane][col].

§Panics

Panics if rows.len() != BaseField::Packing::WIDTH.

Source

fn pack_ext_columns_fn<const N: usize>( row_fn: impl Fn(usize) -> [ExtField; N], ) -> [Self; N]

Pack N columns using a closure that produces each row.

Analog of PackedValue::pack_columns_fn.

Source

fn extract(&self, lane: usize) -> ExtField

Extract the extension field element at the given SIMD lane.

Source

fn to_ext_slice(&self, out: &mut [ExtField])

Write all W lanes into the given slice.

This is the extension-field analog of PackedValue::as_slice, but the lanes of a packed extension are not contiguous in memory (the layout is [[F; W]; D], indexed first by basis coefficient), so the lanes must be copied rather than borrowed.

§Panics

Panics if out.len() != BaseField::Packing::WIDTH.

Source

fn unpack_ext_into<const N: usize>( packed: &[Self; N], rows: &mut [[ExtField; N]], )

Unpack N packed extensions into W rows of N extension elements.

Inverse of PackedFieldExtension::pack_ext_columns. Lane lane of input column col is written to rows[lane][col].

§Panics

Panics if rows.len() != BaseField::Packing::WIDTH.

Source

fn unpack_ext_iter<const N: usize>( packed: [Self; N], ) -> impl Iterator<Item = [ExtField; N]>

Iterator equivalent of PackedFieldExtension::unpack_ext_into.

Yields WIDTH rows of N extension elements without requiring a pre-allocated buffer. Analog of PackedValue::unpack_iter.

Source

fn to_ext_iter( iter: impl IntoIterator<Item = Self>, ) -> impl Iterator<Item = ExtField>

Convert an iterator of packed extension field elements to an iterator of extension field elements (flat — one ExtField per lane per packed value).

Source

fn packed_ext_powers_capped( base: ExtField, unpacked_len: usize, ) -> impl Iterator<Item = Self>

Similar to packed_ext_powers but only returns unpacked_len powers of base.

Note that the length of the returned iterator will be unpacked_len / WIDTH and not len as the iterator is over packed extension field elements. If unpacked_len is not divisible by WIDTH, unpacked_len will be rounded up to the next multiple of WIDTH.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§