#![deny(missing_docs)]
mod array;
mod broadcast;
mod creation;
mod display;
mod element;
mod extra;
mod kernels_mem;
mod layout;
mod manip;
pub mod memory;
mod misc;
mod npz;
mod ops;
mod pool;
mod reduce;
mod simd_math;
mod slicing;
mod ufunc;
pub mod fft;
pub mod io;
pub mod linalg;
pub mod poly;
pub mod random;
pub use array::Array;
pub use broadcast::{IntoArray, broadcast_arrays, broadcast_shapes};
pub use creation::*;
pub use element::{Element, Float, Num};
pub use extra::api::{
Bins, ConvolveMode, Spacing, average, average_axis, bincount, convolve, corrcoef, correlate,
cov, cross, diff, digitize, einsum, gradient, gradient_axis, histogram, histogram_bin_edges,
interp, intersect1d, isin, kron, nanquantile, nanquantile_axis, quantile, quantile_axis,
setdiff1d, setxor1d, trapezoid, union1d,
};
pub use manip::*;
pub use misc::{
Complex, angle, angle_deg, bartlett, blackman, copysign, divmod, ediff1d, ediff1d_with,
float_power, floor_divide, fmod, gcd, hamming, hanning, heaviside, kaiser, lcm, ldexp,
logaddexp, logaddexp2, nextafter, remainder,
};
pub use ops::*;
pub use slicing::{NEW_AXIS, SliceArg};
pub use ufunc::*;
#[derive(Debug)]
pub enum Error {
Shape(String),
DType {
expected: String,
found: String,
},
Singular,
NotPositiveDefinite,
Io(std::io::Error),
Parse(String),
Format(String),
NoConvergence(String),
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Shape(s) | Self::Parse(s) | Self::Format(s) | Self::NoConvergence(s) => {
write!(f, "{s}")
}
Self::DType { expected, found } => {
write!(f, "expected dtype {expected}, found {found}")
}
Self::Singular => write!(f, "Singular matrix"),
Self::NotPositiveDefinite => write!(f, "Matrix is not positive definite"),
Self::Io(e) => e.fmt(f),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
if let Self::Io(e) = self {
Some(e)
} else {
None
}
}
}
impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Self::Io(e)
}
}
pub type Result<T> = std::result::Result<T, Error>;
#[cfg(test)]
mod tests {
#[test]
fn io_error_source() {
use std::error::Error;
let e = super::Error::from(std::io::Error::other("broken"));
assert_eq!(e.source().unwrap().to_string(), "broken");
}
}