ExprStack

Struct ExprStack 

Source
pub struct ExprStack<const N: usize, E1: ExprTrait<N>, E2: ExprTrait<N>> { /* private fields */ }

Implementations§

Source§

impl<const N: usize, E1: ExprTrait<N>, E2: ExprTrait<N>> ExprStack<N, E1, E2>

Source

pub fn new(item1: E1, item2: E2, dim: usize) -> Self

Source

pub fn stack<T: IntoExpr<N>>( self, dim: usize, other: T, ) -> ExprStackRec<N, Self, T::Result>

Source

pub fn vstack<T: IntoExpr<N>>( self, other: T, ) -> ExprStackRec<N, Self, T::Result>

Source

pub fn hstack<T: IntoExpr<N>>( self, other: T, ) -> ExprStackRec<N, Self, T::Result>

Trait Implementations§

Source§

impl<const N: usize, E1: ExprTrait<N>, E2: ExprTrait<N>> ExprStackRecTrait<N> for ExprStack<N, E1, E2>

Source§

fn stack_dim(&self) -> usize

Source§

fn eval_rec( &self, rs: &mut WorkStack, ws: &mut WorkStack, xs: &mut WorkStack, ) -> Result<usize, ExprEvalError>

Source§

impl<const N: usize, E1: ExprTrait<N>, E2: ExprTrait<N>> ExprTrait<N> for ExprStack<N, E1, E2>

Source§

fn eval( &self, rs: &mut WorkStack, ws: &mut WorkStack, xs: &mut WorkStack, ) -> Result<(), ExprEvalError>

Evaluate the expression and put the result on the rs stack, using the ws to evaluate sub-expressions and xs for general storage. The job of eval is to evaluate all sub-expressions and compute the flattened expression from this (basically, coefficients and subscripts of the expression). Upon return, the rs stack must hold the result of the evaluation.
Source§

fn eval_finalize( &self, rs: &mut WorkStack, ws: &mut WorkStack, xs: &mut WorkStack, ) -> Result<(), ExprEvalError>

Evaluate the expression, then clean it up and put it on the rs stack. The result will guarantee that Read more
Source§

fn dynamic<'a>(self) -> ExprDynamic<'a, N>
where Self: Sized + 'a,

Create a dynamic expression from an expression. Expression types generally depend on the types of all the sub-expressions, so it is not possible to make e.g. an array of expressions unless they are exactly the same types. Wrapping each expression in a dynamic expression allows us to create structures like arrays that requires all elements to have the same type. The down-side is heap-allocated objects and that eval() calls are dynamic. Read more
Source§

fn axispermute(self, perm: &[usize; N]) -> ExprPermuteAxes<N, Self>
where Self: Sized,

Permute axes of the expression. Permute the index coordinates of each entry in the expression, and similarly permute the shape. This is a generalized transpose operation, so in two dimensions this is just a regular transpose. Read more
Source§

fn sum(self) -> ExprSum<N, Self>
where Self: Sized,

Sum all elements in an expression producing a scalar expression.
Source§

fn neg(self) -> ExprMulScalar<N, Self>
where Self: Sized,

Negate coefficients of all elements in the expression.
Source§

fn sum_on<const K: usize>( self, axes: &[usize; K], ) -> ExprReduceShape<N, K, ExprSumLastDims<N, ExprPermuteAxes<N, Self>>>
where Self: Sized,

Sum over a number of axes, reducing the dimensionality of the expression. Read more
Source§

fn add<RHS>(self, rhs: RHS) -> ExprAdd<N, Self, RHS::Result>
where RHS: IntoExpr<N>, Self: Sized,

Add an expression and an item that is addable to an expression, e.g. constants or other expressions. Read more
Source§

fn sub<RHS>(self, rhs: RHS) -> ExprAdd<N, Self, RHS::Result>
where RHS: IntoExpr<N>, Self: Sized,

Subtract expression and an item that is addable to an expression, e.g. constants or other expressions. Read more
Source§

fn dot<RHS>(self, rhs: RHS) -> RHS::Result
where RHS: RightDottable<N, Self>, Self: Sized,

Source§

fn mul_elem<RHS>(self, other: RHS) -> RHS::Result
where Self: Sized, RHS: ExprRightElmMultipliable<N, Self>,

Element-wise multiplication of two operands. The operand shapes must be the same. Read more
Source§

fn dot_rows<M>(self, other: M) -> ExprDotRows<Self>
where Self: ExprTrait<2> + Sized, M: Matrix,

An expression that produces a vector of dot-products of the rows of the operands, specifically, [r_0,r_1,...] = [dot(e_{0,*},m_{0,*},dot(e_{1,*},m_{1,*},...], where e if an expression and m is a matrix. The shapes of the operands must be identical. Read more
Source§

fn vstack<E>(self, other: E) -> ExprStack<N, Self, E::Result>
where Self: Sized, E: IntoExpr<N>,

Stack vertically, i.e. in first dimension. The two operands have the same number of dimensions, and must have the same shapes except in the first dimension. N must be at least 1. Read more
Source§

fn hstack<E>(self, other: E) -> ExprStack<N, Self, E::Result>
where Self: Sized, E: IntoExpr<N>,

Stack horizontally, i.e. stack in second dimension. The two operands have the same number of dimensions, and must have the same shapes except in the second dimension. N must be at least 2. Read more
Source§

fn stack<E>(self, dim: usize, other: E) -> ExprStack<N, Self, E::Result>
where Self: Sized, E: IntoExpr<N>,

Stack in arbitrary dimension. The two operands have the same number of dimensions, and must have the same shapes except in dimension dim. N must be larger than or equal to dim Read more
Source§

fn repeat(self, dim: usize, num: usize) -> ExprRepeat<N, Self>
where Self: Sized,

Repeat a fixed number of times in the given dimension. Read more
Source§

fn index<I>(self, idx: I) -> I::Output
where I: ModelExprIndex<Self>, Self: Sized,

Indexing or slicing an expression. This is not compatible with std::ops::Index since we need to return a new object rather than a reference to an object, so sugary syntax is not possible here. Read more
Source§

fn reshape<const M: usize>(self, shape: &[usize; M]) -> ExprReshape<N, M, Self>
where Self: Sized,

Reshape the experssion. The new shape must match the old shape, meaning that the product of the dimensions are the same. The function will panic if operand shapes do not match. Read more
Source§

fn into_symmetric(self, dim: usize) -> ExprIntoSymmetric<N, Self>
where Self: Sized,

Create an expression that is symmetric in dimension dim and dim+1. The shape must satisfy the following: Read more
Source§

fn flatten(self) -> ExprReshapeOneRow<N, 1, Self>
where Self: Sized,

Flatten the expression into a vector. Preserve sparsity. Read more
Source§

fn into_column(self) -> ExprReshapeOneRow<N, 2, Self>
where Self: Sized,

Flatten expression into a column, i.e. an expression of size [n,1] where n=shape.iter().product(). Read more
Source§

fn into_vec<const M: usize>(self, i: usize) -> ExprReshapeOneRow<N, M, Self>
where Self: Sized + ExprTrait<1>,

Reshape an expression into a vector expression, where all but (at most) one dimension are of size 1. Read more
Source§

fn gather(self) -> ExprGatherToVec<N, Self>
where Self: Sized,

Reshape a sparse expression into a dense expression vector. The length of the vector cannot be known until the expression is evaluated.
Source§

fn map<const M: usize, F>( self, shape: &[usize; M], f: F, ) -> ExprMap<N, M, F, Self>
where F: Clone + FnMut(&[usize; N]) -> Option<[usize; M]>, Self: Sized,

Map each nonzero to a new position in an expression with a new shape. Read more
Source§

fn flip(self, dims: &[bool; N]) -> ExprFlip<N, Self>
where Self: Sized,

Flip elements in a subset of dimensions. Read more
Source§

fn mul<RHS>(self, other: RHS) -> RHS::Result
where Self: Sized, RHS: ExprRightMultipliable<N, Self>,

Multiply (self * other), where other must be right-multipliable with Self. Read more
Source§

fn rev_mul<LHS>(self, lhs: LHS) -> LHS::Result
where Self: Sized, LHS: ExprLeftMultipliable<N, Self>,

Multiply (other * self), where other must be left-multipliable with Self. Read more
Source§

fn transpose(self) -> ExprPermuteAxes<2, Self>
where Self: Sized + ExprTrait<2>,

Transpose a two-dimensional expression. Read more
Source§

fn tril(self, with_diag: bool) -> ExprTriangularPart<Self>
where Self: Sized + ExprTrait<2>,

Create a new expression with only lower triangular nonzeros from the operand. Read more
Source§

fn triu(self, with_diag: bool) -> ExprTriangularPart<Self>
where Self: Sized + ExprTrait<2>,

Create a new expression with only upper triangular nonzeros from the operand. Read more
Source§

fn trilvec( self, with_diag: bool, ) -> ExprGatherToVec<2, ExprTriangularPart<Self>>
where Self: Sized + ExprTrait<2>,

create a new expression with only lower triangular nonzeros from the operand put into a vector in row-order. Read more
Source§

fn triuvec( self, with_diag: bool, ) -> ExprGatherToVec<2, ExprTriangularPart<Self>>
where Self: Sized + ExprTrait<2>,

Create a new expression with only upper triangular nonzeros from the operand. Read more
Source§

fn diag(self) -> ExprDiag<Self>
where Self: Sized + ExprTrait<2>,

Take the diagonal elements if a square matrix and return it as a new vector expression.
Source§

fn square_diag(self) -> ExprSquareDiag<Self>
where Self: Sized + ExprTrait<1>,

Create a sparse square matrix with the vector expression elements as diagonal.
Source§

fn mul_any_scalar(self, c: f64) -> ExprMulScalar<N, Self>
where Self: Sized,

Internal. Should normally not be called directly. Read more
Source§

fn mul_matrix_const_matrix<M>(self, m: &M) -> ExprMulRight<Self>
where Self: Sized + ExprTrait<2>, M: Matrix,

Internal. Should normally not be called directly. Read more
Source§

fn mul_rev_matrix_const_matrix<M>(self, m: &M) -> ExprMulLeft<Self>
where Self: Sized + ExprTrait<2>, M: Matrix,

Internal. Should normally not be called directly. Read more
Source§

fn mul_matrix_vec( self, v: Vec<f64>, ) -> ExprReshapeOneRow<2, 1, ExprMulRight<Self>>
where Self: Sized + ExprTrait<2>,

Internal. Should normally not be called directly. Read more
Source§

fn mul_rev_matrix_vec( self, v: Vec<f64>, ) -> ExprReshapeOneRow<2, 1, ExprMulLeft<Self>>
where Self: Sized + ExprTrait<2>,

Internal. Should normally not be called directly. Read more
Source§

fn mul_vec_matrix<M>( self, m: &M, ) -> ExprReshapeOneRow<2, 1, ExprMulRight<ExprReshapeOneRow<1, 2, Self>>>
where Self: Sized + ExprTrait<1>, M: Matrix,

Internal. Should normally not be called directly.
Source§

fn mul_rev_vec_matrix<M>( self, m: &M, ) -> ExprReshapeOneRow<2, 1, ExprMulRight<ExprReshapeOneRow<1, 2, Self>>>
where Self: Sized + ExprTrait<1>, M: Matrix,

Internal. Should normally not be called directly.
Source§

fn mul_scalar_matrix<M>( self, m: &M, ) -> ExprReshape<1, 2, ExprMulElm<1, ExprRepeat<1, ExprReshape<0, 1, Self>>>>
where Self: Sized + ExprTrait<0>, M: Matrix,

Internal. Should normally not be called directly.

Auto Trait Implementations§

§

impl<const N: usize, E1, E2> Freeze for ExprStack<N, E1, E2>
where E1: Freeze, E2: Freeze,

§

impl<const N: usize, E1, E2> RefUnwindSafe for ExprStack<N, E1, E2>

§

impl<const N: usize, E1, E2> Send for ExprStack<N, E1, E2>
where E1: Send, E2: Send,

§

impl<const N: usize, E1, E2> Sync for ExprStack<N, E1, E2>
where E1: Sync, E2: Sync,

§

impl<const N: usize, E1, E2> Unpin for ExprStack<N, E1, E2>
where E1: Unpin, E2: Unpin,

§

impl<const N: usize, E1, E2> UnwindSafe for ExprStack<N, E1, E2>
where E1: UnwindSafe, E2: 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<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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<const N: usize, E> IntoExpr<N> for E
where E: ExprTrait<N>,

Source§

type Result = E

Source§

fn into(self) -> <E as IntoExpr<N>>::Result

Source§

fn into_expr(self) -> Self::Result
where Self: Sized,

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.