|
libnpy 2.0.0
Lightweight C++ library for reading and writing NPY and NPZ files
|
Classes | |
| struct | file_entry |
| Struct representing a file in the NPZ archive. More... | |
| struct | header_info |
| Class representing the header info for an NPY file. More... | |
| class | npzfilereader |
| Class handling reading of an NPZ from a file on disk. More... | |
| class | npzfilewriter |
| Class which handles writing of an NPZ archive to disk. More... | |
| class | npzstringreader |
| Class handling reading of an NPZ from an in-memory string stream. More... | |
| class | npzstringwriter |
| Class which handles writing of an NPZ to an in-memory string stream. More... | |
| class | tensor |
| The default tensor class. More... | |
Enumerations | |
| enum class | endian_t : char { NATIVE , BIG , LITTLE } |
| Enumeration which represents a type of endianness. More... | |
| enum class | data_type_t : char { INT8 , UINT8 , INT16 , UINT16 , INT32 , UINT32 , INT64 , UINT64 , FLOAT32 , FLOAT64 , COMPLEX64 , COMPLEX128 , UNICODE_STRING } |
| This enum represents the different types of tensor data that can be stored. More... | |
| enum class | compression_method_t : std::uint16_t { STORED = 0 , DEFLATED = 8 } |
| Enumeration indicating the compression method to use for data in the NPZ archive. More... | |
Functions | |
| endian_t | native_endian () |
| This function will return the endianness of the current hardware. | |
| const std::string & | to_dtype (data_type_t dtype, endian_t endian=endian_t::NATIVE) |
| Convert a data type and endianness to a NPY dtype string. | |
| const std::pair< data_type_t, endian_t > & | from_dtype (const std::string &dtype) |
| std::ostream & | operator<< (std::ostream &os, const endian_t &obj) |
| std::ostream & | operator<< (std::ostream &os, const data_type_t &obj) |
| template<typename CHAR > | |
| void | write_npy_header (std::basic_ostream< CHAR > &output, const std::string &dtype, bool fortran_order, const std::vector< size_t > &shape) |
| Writes an NPY header to the provided stream. | |
| template<typename T , typename CHAR > | |
| void | write_values (std::basic_ostream< CHAR > &output, const T *data_ptr, size_t num_elements, endian_t endianness) |
| Write values to the provided stream. | |
| template<typename T , typename CHAR > | |
| void | save (std::basic_ostream< CHAR > &output, const T &tensor, endian_t endianness=npy::endian_t::NATIVE) |
| Saves a tensor to the provided stream. | |
| template<typename T , template< typename > class TENSOR, typename CHAR > | |
| void | save (std::basic_ostream< CHAR > &output, const TENSOR< T > &tensor, endian_t endianness=npy::endian_t::NATIVE) |
| Saves a tensor to the provided stream. | |
| template<typename T > | |
| void | save (const std::string &path, T &tensor, endian_t endianness=npy::endian_t::NATIVE) |
| Saves a tensor to the provided location on disk. | |
| template<typename T , template< typename > class TENSOR> | |
| void | save (const std::string &path, T &tensor, endian_t endianness=npy::endian_t::NATIVE) |
| Saves a tensor to the provided location on disk. | |
| template<typename CHAR > | |
| header_info | read_npy_header (std::basic_istream< CHAR > &input) |
| Read an NPY header from the provided stream. | |
| template<typename T , typename CHAR > | |
| void | read_values (std::basic_istream< CHAR > &input, T *data_ptr, size_t num_elements, const header_info &info) |
| Read values from the provided stream. | |
| template<typename T , typename CHAR > | |
| T | load (std::basic_istream< CHAR > &input) |
| template<typename T > | |
| T | load (const std::string &path) |
| Loads a tensor in NPY format from the specified location on the disk. The type of the tensor must match the data to be read. | |
| template<typename T , template< typename > class TENSOR> | |
| TENSOR< T > | load (const std::string &path) |
| Loads a tensor in NPY format from the specified location on the disk. The type of the tensor must match the data to be read. | |
| template<typename CHAR > | |
| header_info | peek (std::basic_istream< CHAR > &input) |
| Return the header information for an NPY file. | |
| header_info | peek (const std::string &path) |
| Return the header information for an NPY file. | |
|
strong |
|
strong |
This enum represents the different types of tensor data that can be stored.
|
strong |
Enumeration which represents a type of endianness.
| const std::pair< data_type_t, endian_t > & npy::from_dtype | ( | const std::string & | dtype | ) |
Converts from an NPY dtype string to a data type and endianness.
| dtype | the NPY dtype string |
| T npy::load | ( | const std::string & | path | ) |
Loads a tensor in NPY format from the specified location on the disk. The type of the tensor must match the data to be read.
| T | the data type |
| TENSOR | the tensor type |
| path | a valid location on the disk |
| TENSOR< T > npy::load | ( | const std::string & | path | ) |
Loads a tensor in NPY format from the specified location on the disk. The type of the tensor must match the data to be read.
| T | the data type |
| TENSOR | the tensor type |
| path | a valid location on the disk |
| T npy::load | ( | std::basic_istream< CHAR > & | input | ) |
|
inline |
This function will return the endianness of the current hardware.
| std::ostream & npy::operator<< | ( | std::ostream & | os, |
| const data_type_t & | obj | ||
| ) |
| std::ostream & npy::operator<< | ( | std::ostream & | os, |
| const endian_t & | obj | ||
| ) |
| header_info npy::peek | ( | const std::string & | path | ) |
Return the header information for an NPY file.
| path | the path to the NPY file on disk |
| header_info npy::peek | ( | std::basic_istream< CHAR > & | input | ) |
Return the header information for an NPY file.
| input | the input stream containing the NPY-encoded bytes |
| header_info npy::read_npy_header | ( | std::basic_istream< CHAR > & | input | ) |
Read an NPY header from the provided stream.
| input | the input stream |
| void npy::read_values | ( | std::basic_istream< CHAR > & | input, |
| T * | data_ptr, | ||
| size_t | num_elements, | ||
| const header_info & | info | ||
| ) |
Read values from the provided stream.
| T | the data type |
| CHAR | the character type of the input stream |
| input | the input stream |
| data_ptr | pointer to the start of the data buffer |
| num_elements | the number of elements to read |
| info | the header information |
| void npy::save | ( | const std::string & | path, |
| T & | tensor, | ||
| endian_t | endianness = npy::endian_t::NATIVE |
||
| ) |
Saves a tensor to the provided location on disk.
| T | the tensor type |
| path | a path to a valid location on disk |
| tensor | the tensor |
| endianness | the endianness to use in saving the tensor |
| void npy::save | ( | const std::string & | path, |
| T & | tensor, | ||
| endian_t | endianness = npy::endian_t::NATIVE |
||
| ) |
Saves a tensor to the provided location on disk.
| T | the data type |
| TENSOR | the tensor type |
| path | a path to a valid location on disk |
| tensor | the tensor |
| endianness | the endianness to use in saving the tensor |
| void npy::save | ( | std::basic_ostream< CHAR > & | output, |
| const T & | tensor, | ||
| endian_t | endianness = npy::endian_t::NATIVE |
||
| ) |
Saves a tensor to the provided stream.
| T | the tensor type |
| CHAR | the character type of the output stream |
| output | the output stream |
| tensor | the tensor |
| endianness | the endianness to use in saving the tensor |
| void npy::save | ( | std::basic_ostream< CHAR > & | output, |
| const TENSOR< T > & | tensor, | ||
| endian_t | endianness = npy::endian_t::NATIVE |
||
| ) |
Saves a tensor to the provided stream.
| T | the data type |
| TENSOR | the tensor type |
| CHAR | the character type of the output stream |
| output | the output stream |
| tensor | the tensor |
| endianness | the endianness to use in saving the tensor |
| const std::string & npy::to_dtype | ( | data_type_t | dtype, |
| endian_t | endian = endian_t::NATIVE |
||
| ) |
Convert a data type and endianness to a NPY dtype string.
| dtype | the data type |
| endian | the endianness. Defaults to the current endianness of the caller. |
| void npy::write_npy_header | ( | std::basic_ostream< CHAR > & | output, |
| const std::string & | dtype, | ||
| bool | fortran_order, | ||
| const std::vector< size_t > & | shape | ||
| ) |
Writes an NPY header to the provided stream.
| output | the output stream |
| dtype | the NPY-encoded dtype string (includes data type and endianness) |
| fortran_order | whether the data is encoded in FORTRAN (i.e. column major) order |
| shape | a sequence of values indicating the shape of each dimension of the tensor |
| void npy::write_values | ( | std::basic_ostream< CHAR > & | output, |
| const T * | data_ptr, | ||
| size_t | num_elements, | ||
| endian_t | endianness | ||
| ) |
Write values to the provided stream.
| T | the data type |
| CHAR | the character type of the output stream |
| output | the output stream |
| data_ptr | pointer to the start of the data buffer |
| num_elements | the number of elements to write |
| endianness | the endianness to use in writing the data |