lazymatrix::WithIntercept
LazyMatrix for Rust · 0.8.1
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
impl<M, F> WithIntercept<M, F>as_inner
pub fn as_inner(&self) -> &MBorrow the predictor operator, including its normalization metadata.
into_inner
pub fn into_inner(self) -> MRecover the predictor operator without copying.
new
pub fn new(predictors: M) -> SelfAdd a leading intercept without reading or copying the predictors.
Inherent implementation
impl<M: MatrixShape, F: Scalar> WithIntercept<M, F>mat_transpose_vec_scaled_with_workspace
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>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
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>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
impl<M: core::clone::Clone, F: core::clone::Clone> Clone for WithIntercept<M, F>clone
fn clone(&self) -> SelfImplementation of Copy
impl<M: core::marker::Copy, F: core::marker::Copy> Copy for WithIntercept<M, F>Implementation of Debug
impl<M: core::fmt::Debug, F: core::fmt::Debug> Debug for WithIntercept<M, F>fmt
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::ResultImplementation of MatMatInto
impl<M: MatMatInto<F>, F: Scalar> MatMatInto<F> for lazymatrix::WithIntercept<M, F>matmat_into
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> + ?SizedImplementation of MatTransposeMatInto
impl<M: MatTransposeMatInto<F>, F: Scalar> MatTransposeMatInto<F> for lazymatrix::WithIntercept<M, F>mat_transpose_mat_into
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> + ?SizedImplementation of MatTransposeVec
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
fn mat_transpose_vec(
&self,
x: &V
) -> Result<V, <Self as MatrixErrorType>::Error>Implementation of MatTransposeVecInto
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
fn mat_transpose_vec_into(
&self,
x: &X,
out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error>Implementation of MatTransposeVecScaledInto
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
fn mat_transpose_vec_scaled_into(
&self,
alpha: F,
x: &X,
beta: F,
out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error>Implementation of MatVec
impl<M, F, V> MatVec<V> for WithIntercept<M, F> where F: Scalar, V: VectorOwned<F, Owned = V> + VectorViewMut<F>, M: MatVecInto<V>matvec
fn matvec(&self, x: &V) -> Result<V, <Self as MatrixErrorType>::Error>Implementation of MatVecInto
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
fn matvec_into(
&self,
x: &X,
out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error>Implementation of MatVecScaledInto
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
fn matvec_scaled_into(
&self,
alpha: F,
x: &X,
beta: F,
out: &mut Y
) -> Result<(), <Self as MatrixErrorType>::Error>Implementation of MatrixErrorType
impl<M: MatrixErrorType, F> MatrixErrorType for WithIntercept<M, F>Error
type Error = <M as MatrixErrorType>::Error;Implementation of MatrixShape
impl<M: MatrixShape, F> MatrixShape for WithIntercept<M, F>ncols
fn ncols(&self) -> usizenrows
fn nrows(&self) -> usizeImplementation of WeightedColumnSumsInto
impl<M, F> WeightedColumnSumsInto<F> for WithIntercept<M, F> where F: Scalar, M: WeightedColumnSumsInto<F>weighted_column_sums_into
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> + ?SizedImplementation of WeightedGramInto
impl<M, F> WeightedGramInto<F> for WithIntercept<M, F> where F: Scalar, M: WeightedGramInto<F> + WeightedColumnSumsInto<F>weighted_gram_into
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> + ?SizedImplementation of Freeze
impl<M, F> Freeze for WithIntercept<M, F> where M: Freeze, PhantomData<F>: FreezeImplementation of RefUnwindSafe
impl<M, F> RefUnwindSafe for WithIntercept<M, F> where M: RefUnwindSafe, PhantomData<F>: RefUnwindSafeImplementation of Send
impl<M, F> Send for WithIntercept<M, F> where M: Send, PhantomData<F>: SendImplementation of Sync
impl<M, F> Sync for WithIntercept<M, F> where M: Sync, PhantomData<F>: SyncImplementation of Unpin
impl<M, F> Unpin for WithIntercept<M, F> where M: Unpin, PhantomData<F>: UnpinImplementation of UnsafeUnpin
impl<M, F> UnsafeUnpin for WithIntercept<M, F> where M: UnsafeUnpin, PhantomData<F>: UnsafeUnpinImplementation of UnwindSafe
impl<M, F> UnwindSafe for WithIntercept<M, F> where M: UnwindSafe, PhantomData<F>: UnwindSafeImplementation of Any
impl<T> Any for T where T: 'static + ?SizedImplementation of Borrow
impl<T> Borrow<T> for T where T: ?SizedImplementation of BorrowMut
impl<T> BorrowMut<T> for T where T: ?SizedImplementation of ByRef
impl<T> ByRef<T> for TImplementation of CastableFrom
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT where ST: ?Sized, DT: ?SizedImplementation of CastableFrom
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT where ST: ?Sized, DT: ?SizedImplementation of CloneToUninit
impl<T> CloneToUninit for T where T: CloneImplementation of From
impl<T> From<T> for TImplementation of Imply
impl<T, U> Imply<T> for U where T: ?Sized, U: ?SizedImplementation of Into
impl<T, U> Into<U> for T where U: From<T>Implementation of IntoEither
impl<T> IntoEither for TImplementation of MatMat
impl<M, F> MatMat<F> for M where M: MatMatInto<F> + ?Sized, F: ScalarImplementation of MatTransposeMat
impl<M, F> MatTransposeMat<F> for M where M: MatTransposeMatInto<F> + ?Sized, F: ScalarImplementation of Pointable
impl<T> Pointable for TImplementation of Read
impl<T> Read<Exclusive, BecauseExclusive> for T where T: ?SizedImplementation of Same
impl<T> Same for TImplementation of SupersetOf
impl<SS, SP> SupersetOf<SS> for SP where SS: SubsetOf<SP>Implementation of ToOwned
impl<T> ToOwned for T where T: CloneImplementation of TryFrom
impl<T, U> TryFrom<U> for T where U: Into<T>Implementation of TryInto
impl<T, U> TryInto<U> for T where U: TryFrom<T>
