Resurrect the llama npy support. (#140)

This commit is contained in:
Laurent Mazare
2023-07-11 19:32:10 +01:00
committed by GitHub
parent 760f1d7055
commit 37cad85869
6 changed files with 264 additions and 90 deletions

View File

@ -139,6 +139,9 @@ pub enum Error {
rhs_stride: Vec<usize>,
mnk: (usize, usize, usize),
},
#[error("cannot find tensor {path}")]
CannotFindTensor { path: String },
}
pub type Result<T> = std::result::Result<T, Error>;

View File

@ -1,10 +1,10 @@
//! Numpy support for literals.
//! Numpy support for tensors.
//!
//! The spec for the npy format can be found in
//! [npy-format](https://docs.scipy.org/doc/numpy-1.14.2/neps/npy-format.html).
//! The functions from this module can be used to read literals from npy/npz files
//! or write literals to these files. A npy file contains a single literal (unnamed)
//! whereas a npz file can contain multiple named literals. npz files are also compressed.
//! The functions from this module can be used to read tensors from npy/npz files
//! or write tensors to these files. A npy file contains a single tensor (unnamed)
//! whereas a npz file can contain multiple named tensors. npz files are also compressed.
//!
//! These two formats are easy to use in Python using the numpy library.
//!
@ -232,7 +232,7 @@ impl Tensor {
}
}
/// Reads a npy file and return the stored multi-dimensional array as a literal.
/// Reads a npy file and return the stored multi-dimensional array as a tensor.
pub fn read_npy<T: AsRef<Path>>(path: T) -> Result<Self> {
let mut reader = File::open(path.as_ref())?;
let header = read_header(&mut reader)?;

View File

@ -10,3 +10,10 @@ pub fn get_num_threads() -> usize {
Some(_) | None => num_cpus::get(),
}
}
pub fn has_mkl() -> bool {
#[cfg(feature = "mkl")]
return true;
#[cfg(not(feature = "mkl"))]
return false;
}