solvr 0.2.0

Advanced computing library for real-world problem solving - optimization, differential equations, interpolation, statistics, and more
Documentation
//! Unified client trait for stiff ODE solvers (BDF, Radau).
//!
//! This module provides a single `StiffSolverClient` trait that conditionally
//! includes `IterativeSolvers` and `SparseOps` when the sparse feature is enabled,
//! avoiding trait duplication between solvers.
use crate::DType;

use numr::ops::{LinalgOps, ScalarOps, TensorOps, UtilityOps};
use numr::runtime::{Runtime, RuntimeClient};

#[cfg(feature = "sparse")]
use numr::algorithm::iterative::IterativeSolvers;
#[cfg(feature = "sparse")]
use numr::ops::IndexingOps;
#[cfg(feature = "sparse")]
use numr::sparse::SparseOps;

/// Client trait for stiff ODE solvers requiring linear algebra operations.
///
/// When the `sparse` feature is enabled, this trait also requires `IterativeSolvers`
/// for GMRES-based sparse linear system solving, `SparseOps` for dense-to-CSR
/// conversion, and `IndexingOps` for `gather_2d` used by the direct sparse solver.
#[cfg(feature = "sparse")]
pub trait StiffSolverClient<R: Runtime<DType = DType>>:
    TensorOps<R>
    + ScalarOps<R>
    + LinalgOps<R>
    + UtilityOps<R>
    + RuntimeClient<R>
    + IterativeSolvers<R>
    + SparseOps<R>
    + IndexingOps<R>
{
}

#[cfg(feature = "sparse")]
impl<R, T> StiffSolverClient<R> for T
where
    R: Runtime<DType = DType>,
    T: TensorOps<R>
        + ScalarOps<R>
        + LinalgOps<R>
        + UtilityOps<R>
        + RuntimeClient<R>
        + IterativeSolvers<R>
        + SparseOps<R>
        + IndexingOps<R>,
{
}

/// Client trait for stiff ODE solvers requiring linear algebra operations.
///
/// Without the `sparse` feature, only dense linear algebra is available.
#[cfg(not(feature = "sparse"))]
pub trait StiffSolverClient<R: Runtime<DType = DType>>:
    TensorOps<R> + ScalarOps<R> + LinalgOps<R> + UtilityOps<R> + RuntimeClient<R>
{
}

#[cfg(not(feature = "sparse"))]
impl<R, T> StiffSolverClient<R> for T
where
    R: Runtime<DType = DType>,
    T: TensorOps<R> + ScalarOps<R> + LinalgOps<R> + UtilityOps<R> + RuntimeClient<R>,
{
}