Skip to content

lazymatrix::WithIntercept ​

LazyMatrix for Rust · 0.8.1

Source

rust
pub struct WithIntercept<M, F>

A design operator [1, predictors] with an implicit leading intercept.

Normalize predictors before wrapping them so centering cannot erase the intercept. Construction takes O(1) time and allocates nothing. Ownership or borrowing follows the supplied predictor operator; coefficient zero always belongs to the intercept. Fitting and penalty policies remain with callers.

Products delegate to the predictor's reusable-output capabilities. Forward products copy O(ncols) coefficients and broadcast the intercept after success. Transpose products use O(ncols) scratch and prepend the input sum. Backend normalization may allocate additional scratch. Reusing output therefore does not promise allocation-free evaluation. Borrowed vector views work wherever the corresponding predictor product accepts them. Fused products implement MatVecScaledInto and MatTransposeVecScaledInto when the predictors do. The optional workspace methods reuse the wrapper's predictor buffer; the inner operator may still allocate normalization scratch.

Weighted Gram products require both WeightedGramInto and WeightedColumnSumsInto on the predictors. They reuse the predictor Gram output block and compute stable cross terms in a separate pass. The wrapper uses O(ncols) scratch in addition to the predictor Gram and weighted-sum workspaces, which run sequentially. No column of ones or full design matrix is allocated. All errors retain the predictor's error type; output may be partial on error.

Inherent implementation ​

Source

rust
impl<M, F> WithIntercept<M, F>

as_inner ​

rust
pub fn as_inner(&self) -> &M

Source

Borrow the predictor operator, including its normalization metadata.

into_inner ​

rust
pub fn into_inner(self) -> M

Source

Recover the predictor operator without copying.

new ​

rust
pub fn new(predictors: M) -> Self

Source

Add a leading intercept without reading or copying the predictors.

Inherent implementation ​

Source

rust
impl<M: MatrixShape, F: Scalar> WithIntercept<M, F>

mat_transpose_vec_scaled_with_workspace ​

rust
pub fn mat_transpose_vec_scaled_with_workspace<X, Y>(
    &self,
    alpha: F,
    x: &X,
    beta: F,
    out: &mut Y,
    scratch: &mut <Y as VectorOwned>::Owned
) -> Result<(), <M as MatrixErrorType>::Error> where X: VectorView<F>, Y: VectorOwned<F> + VectorViewMut<F>, M: MatTransposeVecScaledInto<X, <Y as VectorOwned>::Owned, F>

Source

Apply out = alpha * [1, predictors]ᵀ * x + beta * out with reusable scratch.

Scratch stores the predictor output and has length ncols() - 1. Predictors may allocate additional normalization workspace. Exact zero alpha leaves scratch untouched and skips both predictor evaluation and the input sum. Exact zero beta ignores previous output.

Errors ​

Returns the predictor error. Scratch may be partial on error, but output is updated only after the predictors succeed.

Panics ​

Panics on incorrect input, output, or scratch lengths, even for zero alpha.

matvec_scaled_with_workspace ​

rust
pub fn matvec_scaled_with_workspace<X, Y>(
    &self,
    alpha: F,
    x: &X,
    beta: F,
    out: &mut Y,
    scratch: &mut <X as VectorOwned>::Owned
) -> Result<(), <M as MatrixErrorType>::Error> where X: VectorOwned<F>, Y: VectorViewMut<F>, M: MatVecScaledInto<<X as VectorOwned>::Owned, Y, F>

Source

Apply out = alpha * [1, predictors] * x + beta * out with reusable scratch.

Scratch stores the predictor coefficients and has length ncols() - 1. This reuses only the wrapper's buffer: predictors may allocate their own normalization workspace. Exact zero alpha leaves scratch untouched and skips predictor evaluation. Exact zero beta ignores previous output.

Errors ​

Returns the predictor error. Output and scratch may be partial on error; the intercept contribution is added only after the predictors succeed.

Panics ​

Panics on incorrect input, output, or scratch lengths, even for zero alpha.

Implementation of Clone ​

Source

rust
impl<M: core::clone::Clone, F: core::clone::Clone> Clone for WithIntercept<M, F>

clone ​

rust
fn clone(&self) -> Self

Source

Implementation of Copy ​

Source

rust
impl<M: core::marker::Copy, F: core::marker::Copy> Copy for WithIntercept<M, F>

Implementation of Debug ​

Source

rust
impl<M: core::fmt::Debug, F: core::fmt::Debug> Debug for WithIntercept<M, F>

fmt ​

rust
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result

Source

Implementation of MatMatInto ​

Source

rust
impl<M: MatMatInto<F>, F: Scalar> MatMatInto<F> for lazymatrix::WithIntercept<M, F>

matmat_into ​

rust
fn matmat_into<R, O>(
    &self,
    rhs: &R,
    out: &mut O
) -> Result<(), <Self as MatrixErrorType>::Error> where R: MatrixRead<F> + ?Sized, O: MatrixRead<F> + MatrixWrite<F> + ?Sized

Source

Implementation of MatTransposeMatInto ​

Source

rust
impl<M: MatTransposeMatInto<F>, F: Scalar> MatTransposeMatInto<F> for lazymatrix::WithIntercept<M, F>

mat_transpose_mat_into ​

rust
fn mat_transpose_mat_into<R, O>(
    &self,
    rhs: &R,
    out: &mut O
) -> Result<(), <Self as MatrixErrorType>::Error> where R: MatrixRead<F> + ?Sized, O: MatrixRead<F> + MatrixWrite<F> + ?Sized

Source

Implementation of MatTransposeVec ​

Source

rust
impl<M, F, V> MatTransposeVec<V> for WithIntercept<M, F> where F: Scalar, V: VectorOwned<F, Owned = V> + VectorViewMut<F>, M: MatTransposeVecInto<V>

mat_transpose_vec ​

rust
fn mat_transpose_vec(
    &self,
    x: &V
) -> Result<V, <Self as MatrixErrorType>::Error>

Source

Implementation of MatTransposeVecInto ​

Source

rust
impl<M, F, X, Y> MatTransposeVecInto<X, Y> for WithIntercept<M, F> where F: Scalar, X: VectorView<F>, Y: VectorOwned<F> + VectorViewMut<F>, M: MatTransposeVecInto<X, <Y as VectorOwned>::Owned>

mat_transpose_vec_into ​

rust
fn mat_transpose_vec_into(
    &self,
    x: &X,
    out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error>

Source

Implementation of MatTransposeVecScaledInto ​

Source

rust
impl<M, F, X, Y> MatTransposeVecScaledInto<X, Y, F> for WithIntercept<M, F> where F: Scalar, X: VectorView<F>, Y: VectorOwned<F> + VectorViewMut<F>, M: MatTransposeVecScaledInto<X, <Y as VectorOwned>::Owned, F>

mat_transpose_vec_scaled_into ​

rust
fn mat_transpose_vec_scaled_into(
    &self,
    alpha: F,
    x: &X,
    beta: F,
    out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error>

Source

Implementation of MatVec ​

Source

rust
impl<M, F, V> MatVec<V> for WithIntercept<M, F> where F: Scalar, V: VectorOwned<F, Owned = V> + VectorViewMut<F>, M: MatVecInto<V>

matvec ​

rust
fn matvec(&self, x: &V) -> Result<V, <Self as MatrixErrorType>::Error>

Source

Implementation of MatVecInto ​

Source

rust
impl<M, F, X, Y> MatVecInto<X, Y> for WithIntercept<M, F> where F: Scalar, X: VectorOwned<F>, Y: VectorViewMut<F>, M: MatVecInto<<X as VectorOwned>::Owned, Y>

matvec_into ​

rust
fn matvec_into(
    &self,
    x: &X,
    out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error>

Source

Implementation of MatVecScaledInto ​

Source

rust
impl<M, F, X, Y> MatVecScaledInto<X, Y, F> for WithIntercept<M, F> where F: Scalar, X: VectorOwned<F>, Y: VectorViewMut<F>, M: MatVecScaledInto<<X as VectorOwned>::Owned, Y, F>

matvec_scaled_into ​

rust
fn matvec_scaled_into(
    &self,
    alpha: F,
    x: &X,
    beta: F,
    out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error>

Source

Implementation of MatrixErrorType ​

Source

rust
impl<M: MatrixErrorType, F> MatrixErrorType for WithIntercept<M, F>

Error ​

rust
type Error = <M as MatrixErrorType>::Error;

Source

Implementation of MatrixShape ​

Source

rust
impl<M: MatrixShape, F> MatrixShape for WithIntercept<M, F>

ncols ​

rust
fn ncols(&self) -> usize

Source

nrows ​

rust
fn nrows(&self) -> usize

Source

Implementation of WeightedColumnSumsInto ​

Source

rust
impl<M, F> WeightedColumnSumsInto<F> for WithIntercept<M, F> where F: Scalar, M: WeightedColumnSumsInto<F>

weighted_column_sums_into ​

rust
fn weighted_column_sums_into<W, O>(
    &self,
    weights: &W,
    out: &mut O
) -> Result<(), <Self as MatrixErrorType>::Error> where W: VectorView<F> + ?Sized, O: VectorViewMut<F> + ?Sized

Source

Implementation of WeightedGramInto ​

Source

rust
impl<M, F> WeightedGramInto<F> for WithIntercept<M, F> where F: Scalar, M: WeightedGramInto<F> + WeightedColumnSumsInto<F>

weighted_gram_into ​

rust
fn weighted_gram_into<W, O>(
    &self,
    weights: &W,
    out: &mut O
) -> Result<(), <Self as MatrixErrorType>::Error> where W: VectorView<F> + ?Sized, O: MatrixWrite<F> + ?Sized

Source

Implementation of Freeze ​

rust
impl<M, F> Freeze for WithIntercept<M, F> where M: Freeze, PhantomData<F>: Freeze

Implementation of RefUnwindSafe ​

rust
impl<M, F> RefUnwindSafe for WithIntercept<M, F> where M: RefUnwindSafe, PhantomData<F>: RefUnwindSafe

Implementation of Send ​

rust
impl<M, F> Send for WithIntercept<M, F> where M: Send, PhantomData<F>: Send

Implementation of Sync ​

rust
impl<M, F> Sync for WithIntercept<M, F> where M: Sync, PhantomData<F>: Sync

Implementation of Unpin ​

rust
impl<M, F> Unpin for WithIntercept<M, F> where M: Unpin, PhantomData<F>: Unpin

Implementation of UnsafeUnpin ​

rust
impl<M, F> UnsafeUnpin for WithIntercept<M, F> where M: UnsafeUnpin, PhantomData<F>: UnsafeUnpin

Implementation of UnwindSafe ​

rust
impl<M, F> UnwindSafe for WithIntercept<M, F> where M: UnwindSafe, PhantomData<F>: UnwindSafe

Implementation of Any ​

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

Implementation of Borrow ​

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

Implementation of BorrowMut ​

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

Implementation of ByRef ​

rust
impl<T> ByRef<T> for T

Implementation of CastableFrom ​

rust
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT where ST: ?Sized, DT: ?Sized

Implementation of CastableFrom ​

rust
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT where ST: ?Sized, DT: ?Sized

Implementation of CloneToUninit ​

rust
impl<T> CloneToUninit for T where T: Clone

Implementation of From ​

rust
impl<T> From<T> for T

Implementation of Imply ​

rust
impl<T, U> Imply<T> for U where T: ?Sized, U: ?Sized

Implementation of Into ​

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

Implementation of IntoEither ​

rust
impl<T> IntoEither for T

Implementation of MatMat ​

Source

rust
impl<M, F> MatMat<F> for M where M: MatMatInto<F> + ?Sized, F: Scalar

Implementation of MatTransposeMat ​

Source

rust
impl<M, F> MatTransposeMat<F> for M where M: MatTransposeMatInto<F> + ?Sized, F: Scalar

Implementation of Pointable ​

rust
impl<T> Pointable for T

Implementation of Read ​

rust
impl<T> Read<Exclusive, BecauseExclusive> for T where T: ?Sized

Implementation of Same ​

rust
impl<T> Same for T

Implementation of SupersetOf ​

rust
impl<SS, SP> SupersetOf<SS> for SP where SS: SubsetOf<SP>

Implementation of ToOwned ​

rust
impl<T> ToOwned for T where T: Clone

Implementation of TryFrom ​

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

Implementation of TryInto ​

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

Released under the MIT and Apache 2.0 licenses.