conspire 0.6.0

The Rust interface to conspire.
Documentation
//! Mathematics library.

#[cfg(test)]
pub mod test;

/// Special functions.
pub mod special;

/// Integration and ODEs.
pub mod integrate;

/// Interpolation schemes.
pub mod interpolate;

/// Optimization and root finding.
pub mod optimize;

mod matrix;
mod random;
mod set;
mod tensor;

pub use matrix::{
    Matrix,
    square::{Banded, SquareMatrix},
    vector::Vector,
};
pub use random::{
    random_normal, random_normal_standard, random_u8, random_u64, random_uniform, random_x2_normal,
};
pub use set::{
    dsu::disjoint_set_union,
    sets::{InverseSets, Sets},
};
pub use tensor::{
    Hessian, Jacobian, Rank2, Scalar, ScalarList, ScalarListVec, Scalars, Solution, Tensor,
    TensorArray, TensorError, TensorVec,
    list::TensorList,
    rank_0::{TensorRank0, list::TensorRank0List, list_2d::TensorRank0List2D},
    rank_1::{
        TensorRank1, list::TensorRank1List, list_2d::TensorRank1List2D, vec::TensorRank1Vec,
        vec_2d::TensorRank1Vec2D, zero as tensor_rank_1_zero,
    },
    rank_2::{
        IDENTITY, IDENTITY_00, IDENTITY_10, IDENTITY_22, TensorRank2, ZERO, ZERO_10,
        list::{TensorRank2List, vec::TensorRank2ListVec},
        list_2d::TensorRank2List2D,
        vec::TensorRank2Vec,
        vec_2d::TensorRank2Vec2D,
    },
    rank_3::{LEVI_CIVITA, TensorRank3, levi_civita},
    rank_4::{
        ContractAllIndicesWithFirstIndicesOf, ContractFirstSecondIndicesWithSecondIndicesOf,
        ContractFirstThirdFourthIndicesWithFirstIndicesOf,
        ContractSecondFourthIndicesWithFirstIndicesOf, ContractSecondIndexWithFirstIndexOf,
        ContractThirdFourthIndicesWithFirstSecondIndicesOf, ContractThirdIndexWithFirstIndexOf,
        IDENTITY_1010, TensorRank4, list::TensorRank4List, vec::TensorRank4Vec,
    },
    test::{TestError, assert_eq, assert_eq_within, assert_eq_within_tols},
    tuple::{
        TensorTuple,
        list::{TensorTupleList, vec::TensorTupleListVec, vec_2d::TensorTupleListVec2D},
        vec::TensorTupleVec,
    },
    vec::{TensorRank1RefVec, TensorVector},
};

use std::fmt;

fn write_tensor_rank_0(f: &mut fmt::Formatter, tensor_rank_0: &TensorRank0) -> fmt::Result {
    let num = if tensor_rank_0.abs() > 1e-1 {
        (tensor_rank_0 * 1e6).round() / 1e6
    } else {
        *tensor_rank_0
    };
    let num_abs = num.abs();
    if num.is_nan() {
        write!(f, "{num:>11}, ")
    } else if num == 0.0 || num_abs == 1.0 {
        let temp_1 = format!("{num:>11.6e}, ").to_string();
        let mut temp_2 = temp_1.split("e");
        let a = temp_2.next().unwrap();
        let b = temp_2.next().unwrap();
        write!(f, "{a}e+00{b}")
    } else if num_abs <= 1e-100 {
        write!(f, "{num:>14.6e}, ")
    } else if num_abs >= 1e100 {
        let temp_1 = format!("{num:>13.6e}, ").to_string();
        let mut temp_2 = temp_1.split("e");
        let a = temp_2.next().unwrap();
        let b = temp_2.next().unwrap();
        write!(f, "{a}e+{b}")
    } else if num_abs < 1e-9 {
        let temp_1 = format!("{num:>13.6e}, ").to_string();
        let mut temp_2 = temp_1.split("e");
        let a = temp_2.next().unwrap();
        let b = temp_2.next().unwrap();
        let mut c = b.split("-");
        c.next();
        let e = c.next().unwrap();
        write!(f, "{a}e-0{e}")
    } else if num_abs >= 1e10 {
        let temp_1 = format!("{num:>12.6e}, ").to_string();
        let mut temp_2 = temp_1.split("e");
        let a = temp_2.next().unwrap();
        let b = temp_2.next().unwrap();
        write!(f, "{a}e+0{b}")
    } else if num_abs <= 1e0 {
        let temp_1 = format!("{num:>12.6e}, ").to_string();
        let mut temp_2 = temp_1.split("e");
        let a = temp_2.next().unwrap();
        let b = temp_2.next().unwrap();
        let mut c = b.split("-");
        c.next();
        let e = c.next().unwrap();
        write!(f, "{a}e-00{e}")
    } else {
        let temp_1 = format!("{num:>11.6e}, ").to_string();
        let mut temp_2 = temp_1.split("e");
        let a = temp_2.next().unwrap();
        let b = temp_2.next().unwrap();
        write!(f, "{a}e+00{b}")
    }
}