Skip to main content

LinearOperation

Struct LinearOperation 

Source
pub struct LinearOperation<T>
where T: Clone + Zero + Add<Output = T> + One + Mul<Output = T>,
{ _marker: PhantomData<fn() -> T>, }
Expand description

$(a, b) \circ (c, d) = \lambda x. c \times (a \times x + b) + d$

Fields§

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

Implementations§

Source§

impl<T> LinearOperation<T>
where T: Clone + Zero + Add<Output = T> + One + Mul<Output = T>,

Source

pub fn apply(f: &(T, T), x: &T) -> T

Examples found in repository?
crates/library_checker/src/tree/dynamic_tree_vertex_set_path_composite.rs (line 103)
90pub fn dynamic_tree_vertex_set_path_composite(reader: impl Read, writer: impl Write) {
91    prepare_io!(reader, writer);
92    sc!(n, q, ab: [Affine; n], edges: [(usize, usize); n - 1]);
93    let mut tree = PathLinkCutTree::<PathComposite>::from_edges(ab, &edges);
94    for _ in 0..q {
95        sc!(query: Query);
96        match query {
97            Query::Relink { u, v, w, x } => {
98                tree.cut(u, v);
99                tree.link(w, x);
100            }
101            Query::Set { p, cd } => tree.set(p, cd),
102            Query::Apply { u, v, x } => {
103                pp!(LinearOperation::apply(&tree.fold_path(u, v).0, &x));
104            }
105        }
106    }
107}
108
109#[verify::library_checker("dynamic_tree_vertex_set_path_composite")]
110pub fn dynamic_tree_vertex_set_path_composite_top_tree(reader: impl Read, writer: impl Write) {
111    prepare_io!(reader, writer);
112    sc!(n, q, ab: [Affine; n], edges: [(usize, usize); n - 1]);
113    let mut tree = TopTree::<PathComposite>::from_edges(ab, &edges);
114    for _ in 0..q {
115        sc!(query: Query);
116        match query {
117            Query::Relink { u, v, w, x } => {
118                tree.cut(u, v);
119                tree.link(w, x);
120            }
121            Query::Set { p, cd } => tree.set(p, cd),
122            Query::Apply { u, v, x } => {
123                pp!(LinearOperation::apply(&tree.fold_path(u, v).0, &x));
124            }
125        }
126    }
127}

Trait Implementations§

Source§

impl<T> Associative for LinearOperation<T>
where T: Clone + Zero + One + Add<Output = T> + Mul<Output = T>,

Source§

impl<T> Invertible for LinearOperation<T>
where T: Clone + Zero + One + Add<Output = T> + Sub<Output = T> + Neg<Output = T> + Mul<Output = T> + Div<Output = T>,

Source§

fn inverse(x: &Self::T) -> Self::T

$a$ where $a \circ x = e$
Source§

fn rinv_operate(x: &Self::T, y: &Self::T) -> Self::T

Source§

fn rinv_operate_assign(x: &mut Self::T, y: &Self::T)

Source§

impl<T> Magma for LinearOperation<T>
where T: Clone + Zero + One + Add<Output = T> + Mul<Output = T>,

Source§

type T = (T, T)

type of operands: $T$
Source§

fn operate(x: &Self::T, y: &Self::T) -> Self::T

binary operaion: $\circ$
Source§

fn reverse_operate(x: &Self::T, y: &Self::T) -> Self::T

Source§

fn operate_assign(x: &mut Self::T, y: &Self::T)

Source§

impl<T> Unital for LinearOperation<T>
where T: Clone + Zero + One + Add<Output = T> + Mul<Output = T>,

Source§

fn unit() -> Self::T

identity element: $e$
Source§

fn is_unit(x: &Self::T) -> bool
where Self::T: PartialEq,

Source§

fn set_unit(x: &mut Self::T)

Auto Trait Implementations§

§

impl<T> Freeze for LinearOperation<T>
where PhantomData<fn() -> T>: Freeze,

§

impl<T> RefUnwindSafe for LinearOperation<T>
where PhantomData<fn() -> T>: RefUnwindSafe,

§

impl<T> Send for LinearOperation<T>
where PhantomData<fn() -> T>: Send,

§

impl<T> Sync for LinearOperation<T>
where PhantomData<fn() -> T>: Sync,

§

impl<T> Unpin for LinearOperation<T>
where PhantomData<fn() -> T>: Unpin,

§

impl<T> UnsafeUnpin for LinearOperation<T>
where PhantomData<fn() -> T>: UnsafeUnpin,

§

impl<T> UnwindSafe for LinearOperation<T>
where PhantomData<fn() -> T>: UnwindSafe,

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<G> Group for G
where G: Monoid + Invertible,

Source§

fn signed_pow<E>(x: Self::T, exp: E) -> Self::T
where E: SignedExpBits,

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<M> Monoid for M
where M: SemiGroup + Unital,

Source§

fn pow<E>(x: Self::T, exp: E) -> Self::T
where E: ExpBits,

binary exponentiation: $x^n = x\circ\ddots\circ x$
Source§

fn fold<I>(iter: I) -> Self::T
where I: IntoIterator<Item = Self::T>,

Source§

impl<S> SemiGroup for S
where S: Magma + Associative,

Source§

impl<T> ToArrayVecScalar for T

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.