Skip to main content

HessianOperator

Trait HessianOperator 

Source
pub trait HessianOperator: Send + Sync {
    // Required methods
    fn dim(&self) -> usize;
    fn apply_into(
        &self,
        v: &ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>,
        out: &mut ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>,
    ) -> Result<(), ObjectiveEvalError>;

    // Provided methods
    fn apply(
        &self,
        v: &ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>,
    ) -> Result<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ObjectiveEvalError> { ... }
    fn apply_mat(
        &self,
        x: ArrayBase<ViewRepr<&f64>, Dim<[usize; 2]>>,
    ) -> Result<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ObjectiveEvalError> { ... }
    fn materialization(&self) -> HessianMaterialization { ... }
    fn materialize_dense(
        &self,
    ) -> Result<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ObjectiveEvalError> { ... }
}
Expand description

An exact analytic Hessian-vector product (and optional materialization).

Implementors expose apply_into(v, out) for matrix-free iteration and may additionally support materialize_dense() when an explicit dense Hessian is desired (e.g. for direct factorization). The materialization capability is reported up front via HessianMaterialization so solvers can pick a route without trial calls.

Send + Sync so a single operator can be shared across worker threads (e.g. parallel CG or batched Hv probes).

Required Methods§

Source

fn dim(&self) -> usize

Dimension of the operator (the Hessian is dim() × dim()).

Source

fn apply_into( &self, v: &ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, out: &mut ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ) -> Result<(), ObjectiveEvalError>

Compute out <- H * v. Implementors should write into out rather than returning an Array1 to avoid per-call allocation when the same operator is applied many times in a CG loop.

Both v and out must have length dim(). Returning a recoverable error from an Hv product asks the solver to retreat (e.g. shrink the trust radius); returning a fatal error stops the run.

Provided Methods§

Source

fn apply( &self, v: &ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ) -> Result<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, ObjectiveEvalError>

Compute H * v into a newly allocated vector.

Iterative solvers should use Self::apply_into with reusable storage; this convenience method is for one-off probes and diagnostics.

Source

fn apply_mat( &self, x: ArrayBase<ViewRepr<&f64>, Dim<[usize; 2]>>, ) -> Result<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ObjectiveEvalError>

Apply the operator to a stack of column vectors H * X. The default implementation is a column-by-column loop using apply_into; backends with an efficient batched path (e.g. tangent propagation) should override this.

x has shape (dim(), k). The returned matrix has the same shape.

Source

fn materialization(&self) -> HessianMaterialization

Reports whether a solver should materialize automatically and how expensive that route is. Default: Unavailable keeps solver policy matrix-free; explicit callers can still request basis probing through Self::materialize_dense.

Source

fn materialize_dense( &self, ) -> Result<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ObjectiveEvalError>

Produce an explicit dense Hessian on explicit request. The default implementation uses apply_mat against the identity, costing dim() Hv products, regardless of the automatic work-model declaration. Operators that already hold a dense matrix should override to return it directly.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§