binius_field/
packed_extension.rs1use crate::{
23 BinaryField, ExtensionField, PackedField, packed_fields::primitive::PackedPrimitiveType,
24 underlier::UnderlierView,
25};
26
27pub type PackedSubfield<P, FSub> = PackedPrimitiveType<<P as UnderlierView>::Underlier, FSub>;
32
33pub fn cast_base<FSub, P>(ext: P) -> PackedSubfield<P, FSub>
35where
36 FSub: BinaryField,
37 P: PackedField<Scalar: ExtensionField<FSub>> + UnderlierView,
38 PackedSubfield<P, FSub>: PackedField<Scalar = FSub>,
39{
40 PackedSubfield::<P, FSub>::from_underlier(ext.to_underlier())
41}
42
43pub fn cast_base_mut<FSub, P>(packed: &mut P) -> &mut PackedSubfield<P, FSub>
45where
46 FSub: BinaryField,
47 P: PackedField<Scalar: ExtensionField<FSub>> + UnderlierView,
48 PackedSubfield<P, FSub>: PackedField<Scalar = FSub>,
49{
50 PackedSubfield::<P, FSub>::from_underlier_ref_mut(packed.to_underlier_ref_mut())
51}
52
53pub fn cast_ext<FSub, P>(base: PackedSubfield<P, FSub>) -> P
55where
56 FSub: BinaryField,
57 P: PackedField<Scalar: ExtensionField<FSub>> + UnderlierView,
58 PackedSubfield<P, FSub>: PackedField<Scalar = FSub>,
59{
60 P::from_underlier(base.to_underlier())
61}
62
63pub fn cast_bases_mut<FSub, P>(packed: &mut [P]) -> &mut [PackedSubfield<P, FSub>]
65where
66 FSub: BinaryField,
67 P: PackedField<Scalar: ExtensionField<FSub>> + UnderlierView,
68 PackedSubfield<P, FSub>: PackedField<Scalar = FSub>,
69{
70 PackedSubfield::<P, FSub>::from_underliers_ref_mut(P::to_underliers_ref_mut(packed))
71}