Struct LDLTMgr

Source
pub struct LDLTMgr {
    pub pos: (usize, usize),
    pub wit: Array1<f64>,
    pub ndim: usize,
    pub storage: Array2<f64>,
}
Expand description

The LDLTMgr struct is a manager for LDLTMgr factorization in Rust.

LDLTMgr is a class that performs the LDLTMgr factorization for a given symmetric matrix. The LDLTMgr factorization decomposes a symmetric matrix A into the product of a lower triangular matrix L, a diagonal matrix D, and the transpose of L. This factorization is useful for solving linear systems and eigenvalue problems. The class provides methods to perform the factorization, check if the matrix is positive definite, calculate a witness vector if it is not positive definite, and calculate the symmetric quadratic form.

  • LDL^T square-root-free version
  • Option allow semidefinite
  • A matrix A in R^{m x m} is positive definite iff v’ A v > 0 for all v in R^n.
  • O(p^2) per iteration, independent of N

Properties:

  • pos: A tuple containing two usize values. It represents the dimensions of the LDLTMgr factorization.
  • wit: The wit property is an Array1 of f64 values.
  • ndim: The ndim property represents the size of the matrix that will be factorized using LDLTMgr factorization.
  • storage: The storage property is a 2-dimensional array of type f64. It is used to store the LDLTMgr factorization of a matrix.

Fields§

§pos: (usize, usize)§wit: Array1<f64>§ndim: usize§storage: Array2<f64>

Implementations§

Source§

impl LDLTMgr

Source

pub fn new(ndim: usize) -> Self

The function new initializes a struct with default values for its fields.

Arguments:

  • ndim: The parameter ndim represents the size of the arrays and matrices being initialized in the new function. It is of type usize, which means it represents a non-negative integer.

Returns:

The new function is returning an instance of the struct that it is defined in.

§Examples
use ellalgo_rs::oracles::ldlt_mgr::LDLTMgr;
use ndarray::{array, Array1};
let ldlt_mgr = LDLTMgr::new(3);
assert_eq!(ldlt_mgr.pos, (0, 0));
assert_eq!(ldlt_mgr.wit.len(), 3);
assert_eq!(ldlt_mgr.ndim, 3);
assert_eq!(ldlt_mgr.storage.len(), 9);
Source

pub fn factorize(&mut self, mat_a: &Array2<f64>) -> bool

The factorize function takes a 2D array of f64 values and factors it using a closure.

Arguments:

  • mat_a: The parameter mat_a is a reference to a 2-dimensional array (Array2) of f64 values.

Returns:

The factorize function returns a boolean value.

§Examples
use ellalgo_rs::oracles::ldlt_mgr::LDLTMgr;
use ndarray::array;
let mut ldlt_mgr = LDLTMgr::new(3);
let mat_a = array![
    [1.0, 2.0, 3.0],
    [2.0, 4.0, 5.0],
    [3.0, 5.0, 6.0],
];
assert_eq!(ldlt_mgr.factorize(&mat_a), false);
Source

pub fn factor<F>(&mut self, get_elem: F) -> bool
where F: Fn(usize, usize) -> f64,

The factor function performs LDLTMgr factorization on a matrix and checks if it is symmetric positive definite.

Arguments:

  • get_elem: get_elem is a closure that takes two usize parameters (i and j) and returns a f64 value. It is used to retrieve elements from a matrix-like data structure.

Returns:

The factor function returns a boolean value.

§Examples
use ellalgo_rs::oracles::ldlt_mgr::LDLTMgr;
use ndarray::array;
let mut ldlt_mgr = LDLTMgr::new(3);
let mat_a = array![
    [1.0, 2.0, 3.0],
    [2.0, 4.0, 5.0],
    [3.0, 5.0, 6.0],
];
assert_eq!(ldlt_mgr.factor(&|i, j| mat_a[[i, j]]), false);
Source

pub fn factor_with_allow_semidefinite<F>(&mut self, get_elem: F) -> bool
where F: Fn(usize, usize) -> f64,

The function factor_with_allow_semidefinite checks if a given matrix is symmetric positive definite (SPD) or semidefinite.

Arguments:

  • get_elem: get_elem is a closure that takes two usize parameters i and start and returns a f64 value.

Returns:

a boolean value.

§Examples
use ellalgo_rs::oracles::ldlt_mgr::LDLTMgr;
use ndarray::array;
let mut ldlt_mgr = LDLTMgr::new(3);
let mat_a = array![
    [1.0, 2.0, 3.0],
    [2.0, 4.0, 5.0],
    [3.0, 5.0, 6.0],
];
assert_eq!(ldlt_mgr.factor_with_allow_semidefinite(&|i, j| mat_a[[i, j]]), true);
Source

pub fn is_spd(&self) -> bool

The function is_spd checks if the second element of the tuple pos is equal to 0.

Returns:

A boolean value is being returned.

§Examples
use ellalgo_rs::oracles::ldlt_mgr::LDLTMgr;
use ndarray::array;
let mut ldlt_mgr = LDLTMgr::new(3);
let mat_a = array![
    [1.0, 2.0, 3.0],
    [2.0, 4.0, 5.0],
    [3.0, 5.0, 6.0],
];
assert_eq!(ldlt_mgr.factor(&|i, j| mat_a[[i, j]]), false);
assert_eq!(ldlt_mgr.is_spd(), false);
Source

pub fn witness(&mut self) -> f64

The function calculates the witness vector of a matrix.

Returns:

The function witness returns a f64 (a 64-bit floating-point number).

§Examples
use ellalgo_rs::oracles::ldlt_mgr::LDLTMgr;
use ndarray::array;
let mut ldlt_mgr = LDLTMgr::new(3);
let mat_a = array![
    [1.0, 2.0, 3.0],
    [2.0, 4.0, 5.0],
    [3.0, 5.0, 6.0],
];
assert_eq!(ldlt_mgr.factor(&|i, j| mat_a[[i, j]]), false);
assert_eq!(ldlt_mgr.witness(), 0.0);
assert_eq!(ldlt_mgr.wit[0], -2.0);
assert_eq!(ldlt_mgr.wit[1], 1.0);
assert_eq!(ldlt_mgr.pos.1, 2);
Source

pub fn sym_quad(&self, mat_a: &Array2<f64>) -> f64

The sym_quad function calculates the quadratic form of a symmetric matrix and a vector.

Arguments:

  • mat_a: A 2-dimensional array of type f64.

Returns:

The function sym_quad returns a f64 value.

§Examples
use ellalgo_rs::oracles::ldlt_mgr::LDLTMgr;
use ndarray::array;
let mut ldlt_mgr = LDLTMgr::new(3);
let mat_a = array![
    [1.0, 2.0, 3.0],
    [2.0, 4.0, 5.0],
    [3.0, 5.0, 6.0],
];
assert_eq!(ldlt_mgr.factor(&|i, j| mat_a[[i, j]]), false);
assert_eq!(ldlt_mgr.witness(), 0.0);
let mat_b = array![
    [1.0, 2.0, 3.0],
    [2.0, 6.0, 5.0],
    [3.0, 5.0, 4.0],
];
assert_eq!(ldlt_mgr.sym_quad(&mat_b), 2.0);
Source

pub fn sqrt(&self) -> Array2<f64>

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.