mod load;
mod save;
pub use load::*;
pub use save::*;
const MAGIC_NUMBER: &[u8] = b"\x93NUMPY";
const VERSION: &[u8] = &[1, 0];
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum Endian {
Big,
Little,
Native,
}
fn to_shape_str(shape: Vec<usize>) -> String {
shape
.iter()
.map(|v| v.to_string())
.collect::<Vec<String>>()
.join(", ")
+ if shape.len() == 1 { "," } else { "" }
}
pub trait NumpyDtype {
const DTYPE: &'static str;
}
impl NumpyDtype for f32 {
const DTYPE: &'static str = "f4";
}
impl NumpyDtype for f64 {
const DTYPE: &'static str = "f8";
}
impl<T: NumpyDtype, const M: usize> NumpyDtype for [T; M] {
const DTYPE: &'static str = T::DTYPE;
}
pub trait NumpyShape {
fn shape() -> Vec<usize> {
Vec::new()
}
}
impl NumpyShape for f32 {}
impl NumpyShape for f64 {}
impl<T: NumpyShape, const M: usize> NumpyShape for [T; M] {
fn shape() -> Vec<usize> {
let mut s = T::shape();
s.insert(0, M);
s
}
}