libnpy 2.0.0
Lightweight C++ library for reading and writing NPY and NPZ files
Loading...
Searching...
No Matches
Public Member Functions | List of all members
npy::npzfilereader Class Reference

Class handling reading of an NPZ from a file on disk. More...

#include <npy.h>

Public Member Functions

 npzfilereader (const std::string &path)
 Constructor.
 
 npzfilereader (const char *path)
 Constructor.
 
 npzfilereader (const std::filesystem::path &path)
 Constructor.
 
bool is_open () const
 Whether the NPZ file is open.
 
void close ()
 Closes the NPZ file.
 
const std::vector< std::string > & keys () const
 The keys of the tensors in the NPZ.
 
bool contains (const std::string &filename)
 Returns whether this NPZ contains the specified tensor.
 
header_info peek (const std::string &filename)
 Returns the header for a specified tensor.
 
template<typename T >
read (const std::string &filename)
 Read a tensor from the archive.
 
template<typename T , template< typename > class TENSOR>
TENSOR< T > read (const std::string &filename)
 Read a tensor from the archive.
 

Detailed Description

Class handling reading of an NPZ from a file on disk.

Constructor & Destructor Documentation

◆ npzfilereader() [1/3]

npy::npzfilereader::npzfilereader ( const std::string &  path)

Constructor.

Parameters
pathpath to the input NPZ file

◆ npzfilereader() [2/3]

npy::npzfilereader::npzfilereader ( const char *  path)

Constructor.

Parameters
pathpath to the input NPZ file

◆ npzfilereader() [3/3]

npy::npzfilereader::npzfilereader ( const std::filesystem::path &  path)

Constructor.

Parameters
pathpath to the input NPZ file

Member Function Documentation

◆ close()

void npy::npzfilereader::close ( )

Closes the NPZ file.

◆ contains()

bool npy::npzfilereader::contains ( const std::string &  filename)

Returns whether this NPZ contains the specified tensor.

Parameters
filenamethe name of the tensor in the archive
Returns
whether the tensor is in the archive

◆ is_open()

bool npy::npzfilereader::is_open ( ) const

Whether the NPZ file is open.

◆ keys()

const std::vector< std::string > & npy::npzfilereader::keys ( ) const

The keys of the tensors in the NPZ.

◆ peek()

header_info npy::npzfilereader::peek ( const std::string &  filename)

Returns the header for a specified tensor.

Parameters
filenamethe name of the tensor in the archive
Returns
the header for the tensor

◆ read() [1/2]

template<typename T >
T npy::npzfilereader::read ( const std::string &  filename)
inline

Read a tensor from the archive.

This method will throw an exception if the tensor does not exist, or if the data type of the tensor does not match the template type.

Template Parameters
Tthe tensor type
Parameters
filenamethe name of the tensor in the archive
Returns
an instance of T read from the archive

◆ read() [2/2]

template<typename T , template< typename > class TENSOR>
TENSOR< T > npy::npzfilereader::read ( const std::string &  filename)
inline

Read a tensor from the archive.

This method will throw an exception if the tensor does not exist, or if the data type of the tensor does not match the template type.

Template Parameters
Tthe data type
TENSORthe tensor type
Parameters
filenamethe name of the tensor in the archive
Returns
an instance of TENSOR<T> read from the archive

The documentation for this class was generated from the following file: