Skip to content

Commit

Permalink
Additional documentation (#158)
Browse files Browse the repository at this point in the history
Additional documentation
  • Loading branch information
goulart-paul authored Feb 2, 2025
2 parents 841594f + d7ca8b4 commit 4403df9
Show file tree
Hide file tree
Showing 30 changed files with 219 additions and 77 deletions.
4 changes: 2 additions & 2 deletions src/algebra/csc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub struct CscMatrix<T = f64> {
pub n: usize,
/// CSC format column pointer.
///
/// Ths field should have length `n+1`. The last entry corresponds
/// This field should have length `n+1`. The last entry corresponds
/// to the the number of nonzeros and should agree with the lengths
/// of the `rowval` and `nzval` fields.
pub colptr: Vec<usize>,
Expand Down Expand Up @@ -419,7 +419,7 @@ where
self.size() == other.size() && self.colptr == other.colptr && self.rowval == other.rowval
}

/// Same as is_equal_sparsity, but returns an error indicating the reason
/// Same as `is_equal_sparsity`, but returns an error indicating the reason
/// for failure if the matrices do not have equivalent sparsity patterns.
pub fn check_equal_sparsity(&self, other: &Self) -> Result<(), SparseFormatError> {
if self.size() != other.size() {
Expand Down
2 changes: 1 addition & 1 deletion src/algebra/dense/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ where
{
/// dimensions
pub size: (usize, usize),
/// vector of data in column major formmat
/// vector of data in column major format
pub data: S,
pub(crate) phantom: std::marker::PhantomData<T>,
}
Expand Down
6 changes: 6 additions & 0 deletions src/algebra/error_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@ use thiserror::Error;
#[derive(Error, Debug)]
pub enum MatrixConcatenationError {
#[error("Incompatible dimensions")]
/// Indicates inputs have incompatible dimension
IncompatibleDimension,
}

#[derive(Error, Debug)]
/// Error type returned by sparse matrix assembly operations.
pub enum SparseFormatError {
/// Matrix dimension fields and/or array lengths are incompatible
#[error("Matrix dimension fields and/or array lengths are incompatible")]
IncompatibleDimension,
/// Data is not sorted by row index within each column
#[error("Data is not sorted by row index within each column")]
BadRowOrdering,
#[error("Row value exceeds the matrix row dimension")]
/// Row value exceeds the matrix row dimension
BadRowval,
#[error("Bad column pointer values")]
/// Matrix column pointer values are defective
BadColptr,
#[error("sparsity pattern mismatch")]
/// Operation on matrices that have mismatching sparsity patterns
SparsityMismatch,
}

Expand Down
18 changes: 14 additions & 4 deletions src/algebra/floats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ use crate::algebra::dense::BlasFloatT;
/// Core traits for internal floating point values.
///
/// This trait defines a subset of bounds for `FloatT`, which is preferred
/// throughout for use in the solver. When the "sdp" feature is enabled,
/// throughout for use in the solver. When the `sdp` feature is enabled,
/// `FloatT` is additionally restricted to f32/f64 types supported by BLAS.
/// When the `faer-sparse` feature is enabled, `FloatT` is additionally
/// restricted to types implementing `RealField` from the `faer` crate.
pub trait CoreFloatT:
'static
+ Send
Expand Down Expand Up @@ -51,24 +53,32 @@ impl<T> CoreFloatT for T where

cfg_if::cfg_if! {
if #[cfg(feature="sdp")] {
/// A marker trait implemented on types supported by BLAS (i.e. f32 and f64)
/// when the package is compiled with the "sdp" feature using a BLAS/LAPACK library
#[doc(hidden)]
pub trait MaybeBlasFloatT : BlasFloatT {}
impl<T> MaybeBlasFloatT for T where T: BlasFloatT {}
}
else {
#[doc(hidden)]
pub trait MaybeBlasFloatT {}
impl<T> MaybeBlasFloatT for T {}
}
}

// if "faer" is enabled, we must add an additional bound
// to restrict compilation to Reals implementing SimpleEntity
// to restrict compilation to types implementing RealField

cfg_if::cfg_if! {
if #[cfg(feature="faer-sparse")] {
#[doc(hidden)]
/// A marker trait implemented on types supported by faer-rs
/// when the package is compiled with the "faer-sparse" feature
pub trait MaybeFaerFloatT : faer_traits::RealField {}
impl<T> MaybeFaerFloatT for T where T: faer_traits::RealField {}
}
else {
#[doc(hidden)]
pub trait MaybeFaerFloatT {}
impl<T> MaybeFaerFloatT for T {}
}
Expand All @@ -86,7 +96,7 @@ cfg_if::cfg_if! {
pub trait FloatT: CoreFloatT + MaybeBlasFloatT + MaybeFaerFloatT {}
impl<T> FloatT for T where T: CoreFloatT + MaybeBlasFloatT + MaybeFaerFloatT {}

/// Trait for convering Rust primitives to [`FloatT`](crate::algebra::FloatT)
/// Trait for converting Rust primitives to [`FloatT`](crate::algebra::FloatT)
///
/// This convenience trait is implemented on f32/64 and u32/64. This trait
/// is required internally by the solver for converting constant primitives
Expand All @@ -97,7 +107,7 @@ impl<T> FloatT for T where T: CoreFloatT + MaybeBlasFloatT + MaybeFaerFloatT {}
// NB: `AsFloatT` is a convenience trait for f32/64 and u32/64
// so that we can do things like (2.0).as_T() everywhere on
// constants, rather than the awful T::from_f32(2.0).unwrap()
pub trait AsFloatT<T>: 'static {
pub(crate) trait AsFloatT<T>: 'static {
fn as_T(&self) -> T;
}

Expand Down
6 changes: 3 additions & 3 deletions src/algebra/math_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub trait VectorMath<T> {
/// Dot product
fn dot(&self, y: &Self) -> T;

// computes dot(z + αdz,s + αds) without intermediate allocation
/// computes dot(z + αdz,s + αds) without intermediate allocation
fn dot_shifted(z: &[T], s: &[T], dz: &[T], ds: &[T], α: T) -> T;

/// Standard Euclidian or 2-norm distance from `self` to `y`
Expand Down Expand Up @@ -93,7 +93,7 @@ pub trait VectorMath<T> {
/// Inf-norm of an elementwise scaling of `self` by `v`
fn norm_one_scaled(&self, v: &Self) -> T;

// Inf-norm of vector difference
/// Inf-norm of vector difference
fn norm_inf_diff(&self, b: &Self) -> T;

/// Minimum value in vector
Expand Down Expand Up @@ -152,7 +152,7 @@ pub trait MatrixMath<T> {
fn col_norms_no_reset(&self, norms: &mut [T]);

/// Compute columnwise infinity norm operations on
/// a symmstric matrix
/// a symmetric matrix
fn col_norms_sym(&self, norms: &mut [T]);

/// Compute columnwise infinity norm operations on
Expand Down
2 changes: 1 addition & 1 deletion src/algebra/matrix_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub trait BlockConcatenate: Sized {
/// Errors if column dimensions are incompatible
fn vcat(A: &Self, B: &Self) -> Result<Self, MatrixConcatenationError>;

/// general block concatentation
/// general block concatenation
fn hvcat(mats: &[&[&Self]]) -> Result<Self, MatrixConcatenationError>;

/// block diagonal concatenation
Expand Down
2 changes: 1 addition & 1 deletion src/algebra/sparsevector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub(crate) struct SparseVector<T = f64> {
pub nzval: Vec<T>,
}

/// Creates a SparseVector from a dense slice.
/// Creates a `SparseVector` from a dense slice.
impl<T> SparseVector<T>
where
T: Num + Copy,
Expand Down
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
//Rust hates greek characters
#![allow(confusable_idents)]
#![warn(missing_docs)]

const VERSION: &str = env!("CARGO_PKG_VERSION");

Expand All @@ -64,6 +65,9 @@ pub mod solver;
pub(crate) mod stdio;
pub mod timers;

pub(crate) mod utils;
pub use crate::utils::infbounds::*;

#[cfg(feature = "python")]
pub mod python;

Expand All @@ -79,7 +83,7 @@ macro_rules! printbuildenv {
};
}

// print detailed build info to stdout
/// print detailed build configuration info to stdout
#[allow(clippy::explicit_write)]
pub fn buildinfo() {
use std::io::Write;
Expand Down Expand Up @@ -109,6 +113,8 @@ pub fn buildinfo() {
writeln!(crate::stdio::stdout(), "no build info available").unwrap();
}

pub(crate) const _INFINITY_DEFAULT: f64 = 1e20;

#[test]
fn test_buildinfo() {
buildinfo();
Expand Down
2 changes: 1 addition & 1 deletion src/python/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Clarabel Python interface.
//!
//! This module implements a wrapper for the Rust version of Python using
//! [PYO3](https://pyo3.rs/). To build these wrappers from `cargo`, compile the crate with
//! [PyO3](https://pyo3.rs/). To build these wrappers from `cargo`, compile the crate with
//! `--features python`. This module has no public API.
//!
//! It should not normally be necessary to compile the Python wrapper from
Expand Down
6 changes: 3 additions & 3 deletions src/python/module_py.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ fn force_load_blas_lapack_py() {
// get/set for the solver's internal infinity limit
#[pyfunction(name = "get_infinity")]
fn get_infinity_py() -> f64 {
crate::solver::get_infinity()
crate::get_infinity()
}
#[pyfunction(name = "set_infinity")]
fn set_infinity_py(v: f64) {
crate::solver::set_infinity(v);
crate::set_infinity(v);
}
#[pyfunction(name = "default_infinity")]
fn default_infinity_py() {
crate::solver::default_infinity();
crate::default_infinity();
}
#[pyfunction(name = "buildinfo")]
fn buildinfo_py() {
Expand Down
Loading

0 comments on commit 4403df9

Please sign in to comment.