|
libnpy 2.0.0
Lightweight C++ library for reading and writing NPY and NPZ files
|
The default tensor class. More...
#include <npy.h>
Public Types | |
| typedef T | value_type |
| The value type of the tensor. | |
| typedef value_type & | reference |
| The reference type of the tensor. | |
| typedef const value_type & | const_reference |
| The const reference type of the tensor. | |
| typedef value_type * | pointer |
| The pointer type of the tensor. | |
| typedef const value_type * | const_pointer |
| The const pointer type of the tensor. | |
Public Member Functions | |
| tensor (const std::vector< size_t > &shape) | |
| Constructor. | |
| tensor (const std::vector< size_t > &shape, bool fortran_order) | |
| Constructor. | |
| tensor (const tensor< T > &other) | |
| Copy constructor. | |
| tensor (tensor< T > &&other) | |
| Move constructor. | |
| void | save (std::basic_ostream< char > &output, endian_t endianness) const |
| Save the tensor to the provided stream. | |
| template<typename... Indices> | |
| const T & | operator() (Indices... index) const |
| Variable parameter index function. | |
| const T & | operator() (const std::vector< std::size_t > &multi_index) const |
| Index function. | |
| template<typename... Indices> | |
| T & | operator() (Indices... index) |
| Variable parameter index function. | |
| T & | operator() (const std::vector< std::size_t > &multi_index) |
| Index function. | |
| std::vector< T >::iterator | begin () |
| Iterator pointing at the beginning of the tensor in memory. | |
| std::vector< T >::const_iterator | begin () const |
| Iterator pointing at the beginning of the tensor in memory. | |
| std::vector< T >::iterator | end () |
| Iterator pointing at the end of the tensor in memory. | |
| std::vector< T >::const_iterator | end () const |
| Iterator pointing at the end of the tensor in memory. | |
| void | set (const std::vector< std::int32_t > &multi_index, const T &value) |
| Sets the value at the provided index. | |
| const T & | get (const std::vector< std::int32_t > &multi_index) const |
| Gets the value at the provided index. | |
| std::string | dtype (endian_t endianness) const |
| The data type of the tensor. | |
| data_type_t | dtype () const |
| The data type of the tensor. | |
| const std::vector< T > & | values () const |
| The underlying values buffer. | |
| void | copy_from (const T *source, size_t nitems) |
| Copy values from the source to this tensor. | |
| void | copy_from (const std::vector< T > &source) |
| Copy values from the provided vector. | |
| void | move_from (std::vector< T > &&source) |
| Move values from the provided vector. | |
| T * | data () |
| A pointer to the start of the underlying values buffer. | |
| const T * | data () const |
| A pointer to the start of the underlying values buffer. | |
| size_t | size () const |
| The number of elements in the tensor. | |
| const std::vector< size_t > & | shape () const |
| The shape of the vector. Each element is the size of the corresponding dimension. | |
| size_t | shape (int index) const |
| Returns the dimensionality of the tensor at the specified index. | |
| size_t | ndim () const |
| The number of dimensions of the tensor. | |
| bool | fortran_order () const |
| Whether the tensor data is stored in FORTRAN, or column-major, order. | |
| tensor< T > & | operator= (const tensor< T > &other) |
| Copy assignment operator. | |
| tensor< T > & | operator= (tensor< T > &&other) |
| Move assignment operator. | |
| void | save (const std::string &path, endian_t endianness=npy::endian_t::NATIVE) |
| Save this tensor to the provided location on disk. | |
| template<class INDEX_IT , class SHAPE_IT > | |
| size_t | ravel (INDEX_IT index, SHAPE_IT shape) const |
| Ravels a multi-index into a single value indexing the buffer. | |
| size_t | ravel (const std::vector< std::int32_t > &multi_index) const |
| Ravels a multi-index into a single value indexing the buffer. | |
| size_t | ravel (const std::vector< std::size_t > &abs_multi_index) const |
| Ravels a multi-index into a single value indexing the buffer. | |
| std::string | dtype (endian_t endianness) const |
| Specialization of dtype for std::wstring tensors. | |
Static Public Member Functions | |
| static tensor< T > | from_file (const std::string &path) |
| Load a tensor from the specified location on disk. | |
| static tensor< T > | load (std::basic_istream< char > &input, const header_info &info) |
| Load a tensor from the provided stream. | |
The default tensor class.
This class can be used as a data exchange format for the library, but the methods and classes will also work with your own tensor implementation. The library methods require the following methods to be present in a tensor type:
As long as these are present and have the same semantics, the library should handle them in the same was as this implementation. Only certain type of tensor objects are natively supported (see npy::data_type_t).
| typedef const value_type* npy::tensor< T >::const_pointer |
The const pointer type of the tensor.
| typedef const value_type& npy::tensor< T >::const_reference |
The const reference type of the tensor.
| typedef value_type* npy::tensor< T >::pointer |
The pointer type of the tensor.
| typedef value_type& npy::tensor< T >::reference |
The reference type of the tensor.
| typedef T npy::tensor< T >::value_type |
The value type of the tensor.
|
inline |
Constructor.
This will allocate a data buffer of the appropriate size in row-major order.
| shape | the shape of the tensor |
|
inline |
Constructor.
This will allocate a data buffer of the appropriate size.
| shape | the shape of the tensor |
| fortran_order | whether the data is stored in FORTRAN, or column major, order |
|
inline |
Copy constructor.
|
inline |
Move constructor.
|
inline |
Iterator pointing at the beginning of the tensor in memory.
|
inline |
Iterator pointing at the beginning of the tensor in memory.
|
inline |
Copy values from the provided vector.
| source | the source vector. Should have the same size as values. |
|
inline |
Copy values from the source to this tensor.
| source | pointer to the start of the source buffer |
| nitems | the number of items to copy. Should be equal to size. |
|
inline |
A pointer to the start of the underlying values buffer.
|
inline |
A pointer to the start of the underlying values buffer.
|
inline |
The data type of the tensor.
This is one of the methods required by the library to read and write NPY files.
|
inline |
The data type of the tensor.
|
inline |
Specialization of dtype for std::wstring tensors.
|
inline |
Iterator pointing at the end of the tensor in memory.
|
inline |
Iterator pointing at the end of the tensor in memory.
|
inline |
Whether the tensor data is stored in FORTRAN, or column-major, order.
This is one of the methods required by the library to read and write NPY files.
|
inlinestatic |
Load a tensor from the specified location on disk.
|
inline |
Gets the value at the provided index.
| multi_index | the index into the tensor |
|
inlinestatic |
Load a tensor from the provided stream.
This is one of the methods required by the library to read NPY files. If you implement this in a custom tensor, you will need to populate your internal data structure using the provided stream and header information. The npy::read_values method can be used to read raw data from the stream.
| input | the input stream |
| info | the header information |
|
inline |
Move values from the provided vector.
| source | the source vector. Should have the same size as values. |
|
inline |
The number of dimensions of the tensor.
This is one of the methods required by the library to read and write NPY files.
|
inline |
Index function.
| multi_index | the index into the tensor |
|
inline |
Index function.
| multi_index | the index into the tensor |
|
inline |
Variable parameter index function.
| index | an index into the tensor. Can be negative (in which case it will work as in numpy) |
|
inline |
Variable parameter index function.
| index | an index into the tensor. Can be negative (in which case it will work as in numpy) |
|
inline |
Copy assignment operator.
|
inline |
Move assignment operator.
|
inline |
Ravels a multi-index into a single value indexing the buffer.
| multi_index | the multi-index value |
|
inline |
Ravels a multi-index into a single value indexing the buffer.
| abs_multi_index | the multi-index value |
|
inline |
Ravels a multi-index into a single value indexing the buffer.
| INDEX_IT | the index iterator class |
| SHAPE_IT | the shape iterator class |
| index | the multi-index iterator |
| shape | the shape iterator |
|
inline |
Save this tensor to the provided location on disk.
| path | a valid location on disk |
| endianness | the endianness to use in writing the tensor |
|
inline |
Save the tensor to the provided stream.
This is one of the methods required by the library to write NPY files. If you implement this in a custom tensor, you will need to write your internal data structure to the provided stream. The npy::write_values method can be used to write raw data to the stream.
| output | the output stream |
| endianness | the endianness to use in writing the data |
|
inline |
Sets the value at the provided index.
| multi_index | an index into the tensor |
| value | the value to set |
|
inline |
The shape of the vector. Each element is the size of the corresponding dimension.
|
inline |
Returns the dimensionality of the tensor at the specified index.
This is one of the methods required by the library to read and write NPY files.
| index | index into the shape |
|
inline |
The number of elements in the tensor.
|
inline |
The underlying values buffer.