BitwisexorConvolve

Struct BitwisexorConvolve 

Source
pub struct BitwisexorConvolve<M, const TRY: bool = false> {
    _marker: PhantomData<fn() -> M>,
}

Fields§

§_marker: PhantomData<fn() -> M>

Implementations§

Source§

impl<G, const TRY: bool> BitwisexorConvolve<G, TRY>
where G: Group,

Source

pub fn hadamard_transform(f: &mut [G::T])

Examples found in repository?
crates/competitive/src/math/bitwisexor_convolve.rs (line 33)
32    fn transform(mut t: Self::T, _len: usize) -> Self::F {
33        BitwisexorConvolve::<R::Additive, false>::hadamard_transform(&mut t);
34        t
35    }
36
37    fn inverse_transform(mut f: Self::F, len: usize) -> Self::T {
38        BitwisexorConvolve::<R::Additive, false>::hadamard_transform(&mut f);
39        let len = R::T::from(len);
40        for f in f.iter_mut() {
41            *f = R::div(f, &len);
42        }
43        f
44    }
45
46    fn multiply(f: &mut Self::F, g: &Self::F) {
47        for (f, g) in f.iter_mut().zip(g) {
48            *f = R::mul(f, g);
49        }
50    }
51
52    fn convolve(a: Self::T, b: Self::T) -> Self::T {
53        assert_eq!(a.len(), b.len());
54        let len = a.len();
55        let same = a == b;
56        let mut a = Self::transform(a, len);
57        if same {
58            for a in a.iter_mut() {
59                *a = R::mul(a, a);
60            }
61        } else {
62            let b = Self::transform(b, len);
63            Self::multiply(&mut a, &b);
64        }
65        Self::inverse_transform(a, len)
66    }
67}
68
69impl<R> ConvolveSteps for BitwisexorConvolve<R, true>
70where
71    R: Field<T: PartialEq + TryFrom<usize>, Additive: Invertible, Multiplicative: Invertible>,
72    <R::T as TryFrom<usize>>::Error: Debug,
73{
74    type T = Vec<R::T>;
75    type F = Vec<R::T>;
76
77    fn length(t: &Self::T) -> usize {
78        t.len()
79    }
80
81    fn transform(mut t: Self::T, _len: usize) -> Self::F {
82        BitwisexorConvolve::<R::Additive, true>::hadamard_transform(&mut t);
83        t
84    }
85
86    fn inverse_transform(mut f: Self::F, len: usize) -> Self::T {
87        BitwisexorConvolve::<R::Additive, true>::hadamard_transform(&mut f);
88        let len = R::T::try_from(len).unwrap();
89        for f in f.iter_mut() {
90            *f = R::div(f, &len);
91        }
92        f
93    }

Trait Implementations§

Source§

impl<R> ConvolveSteps for BitwisexorConvolve<R, false>
where R: Field<T: PartialEq + From<usize>, Additive: Invertible, Multiplicative: Invertible>,

Source§

type T = Vec<<R as SemiRing>::T>

Source§

type F = Vec<<R as SemiRing>::T>

Source§

fn length(t: &Self::T) -> usize

Source§

fn transform(t: Self::T, _len: usize) -> Self::F

Source§

fn inverse_transform(f: Self::F, len: usize) -> Self::T

Source§

fn multiply(f: &mut Self::F, g: &Self::F)

Source§

fn convolve(a: Self::T, b: Self::T) -> Self::T

Source§

impl<R> ConvolveSteps for BitwisexorConvolve<R, true>
where R: Field<T: PartialEq + TryFrom<usize>, Additive: Invertible, Multiplicative: Invertible>, <R::T as TryFrom<usize>>::Error: Debug,

Source§

type T = Vec<<R as SemiRing>::T>

Source§

type F = Vec<<R as SemiRing>::T>

Source§

fn length(t: &Self::T) -> usize

Source§

fn transform(t: Self::T, _len: usize) -> Self::F

Source§

fn inverse_transform(f: Self::F, len: usize) -> Self::T

Source§

fn multiply(f: &mut Self::F, g: &Self::F)

Source§

fn convolve(a: Self::T, b: Self::T) -> Self::T

Auto Trait Implementations§

§

impl<M, const TRY: bool> Freeze for BitwisexorConvolve<M, TRY>

§

impl<M, const TRY: bool> RefUnwindSafe for BitwisexorConvolve<M, TRY>

§

impl<M, const TRY: bool> Send for BitwisexorConvolve<M, TRY>

§

impl<M, const TRY: bool> Sync for BitwisexorConvolve<M, TRY>

§

impl<M, const TRY: bool> Unpin for BitwisexorConvolve<M, TRY>

§

impl<M, const TRY: bool> UnwindSafe for BitwisexorConvolve<M, TRY>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.