Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
visp::cnpy Namespace Reference

Classes

struct  NpyArray

Typedefs

using npz_t = std::map<std::string, NpyArray>

Functions

VISP_EXPORT npz_t npz_load (const std::string &fname)
VISP_EXPORT char BigEndianTest ()
VISP_EXPORT char map_type (const std::type_info &t)
template<typename T>
std::vector< char > create_npy_header (const std::vector< size_t > &shape)
VISP_EXPORT void parse_npy_header (FILE *fp, size_t &word_size, std::vector< size_t > &shape, bool &fortran_order, bool &little_endian, char &data_type)
VISP_EXPORT void parse_npy_header (unsigned char *buffer, size_t &word_size, std::vector< size_t > &shape, bool &fortran_order, bool &little_endian, char &data_type)
VISP_EXPORT void parse_zip_footer (FILE *fp, uint16_t &nrecs, size_t &global_header_size, size_t &global_header_offset)
VISP_EXPORT NpyArray npz_load (const std::string &fname, const std::string &varname)
VISP_EXPORT NpyArray npy_load (const std::string &fname)
VISP_EXPORT void npz_save (const std::string &zipname, std::string fname, const std::vector< std::string > &data_vec, const std::vector< size_t > &shape, const std::string &mode="w")
VISP_EXPORT void npz_save (const std::string &zipname, const std::string &fname, const std::string &data, const std::string &mode="w")
template<typename T>
std::vector< char > & operator+= (std::vector< char > &lhs, const T rhs)
template<>
std::vector< char > & operator+= (std::vector< char > &lhs, const std::string rhs)
template<>
std::vector< char > & operator+= (std::vector< char > &lhs, const char *rhs)
template<typename T>
void npy_save (const std::string &fname, const T *data, const std::vector< size_t > &shape, const std::string &mode="w")
template<typename T>
void npz_save (const std::string &zipname, std::string fname, const T *data, const std::vector< size_t > &shape, const std::string &mode="w")
template<typename T>
void npy_save (const std::string &fname, const std::vector< T > &data, const std::string &mode="w")
template<typename T>
void npz_save (const std::string &zipname, const std::string &fname, const std::vector< T > &data, const std::string &mode="w")
std::vector< char > create_npy_header_string (const std::vector< size_t > &shape, const std::vector< size_t > &lengths)
std::vector< char > utf8_to_utf32_vec_pad (const std::string &utf8, const std::size_t &max_size)

Detailed Description

Helpers to convert NPY/NPZ format to/from ViSP format.

Tutorials & Examples

Tutorials
If you are interested in converting NPY/NPZ format to/from ViSP format, you may have a look at:

Typedef Documentation

◆ npz_t

Function Documentation

◆ BigEndianTest()

char visp::cnpy::BigEndianTest ( )

Definition at line 145 of file vpIoTools_npy.cpp.

Referenced by create_npy_header(), and create_npy_header_string().

◆ create_npy_header()

template<typename T>
std::vector< char > visp::cnpy::create_npy_header ( const std::vector< size_t > & shape)

Definition at line 456 of file vpIoTools.h.

References BigEndianTest(), map_type(), and vpEndian::swap16bits().

Referenced by npy_save(), and npz_save().

◆ create_npy_header_string()

std::vector< char > visp::cnpy::create_npy_header_string ( const std::vector< size_t > & shape,
const std::vector< size_t > & lengths )

Definition at line 656 of file vpIoTools_npy.cpp.

References BigEndianTest(), map_type(), and vpEndian::swap16bits().

Referenced by npz_save().

◆ map_type()

char visp::cnpy::map_type ( const std::type_info & t)

Definition at line 151 of file vpIoTools_npy.cpp.

Referenced by create_npy_header(), and create_npy_header_string().

◆ npy_load()

visp::cnpy::NpyArray visp::cnpy::npy_load ( const std::string & fname)

Load the specified npy fname filepath as one array of data. This function is similar to the numpy.load function.

Parameters
[in]fname: Path to the npy file.
Returns
An array of basic data type.
Warning
This function has only been tested on little endian platform.
Note
Original library: cnpy with MIT license.
Examples
tutorial-rbt-sequence.cpp.

Definition at line 594 of file vpIoTools_npy.cpp.

References vpIoTools::checkFilename(), and vpException::ioError.

Referenced by vpDiskGrabber::acquire().

◆ npy_save() [1/2]

template<typename T>
void visp::cnpy::npy_save ( const std::string & fname,
const std::vector< T > & data,
const std::string & mode = "w" )

Save the specified 1-D array of data (data) into the fname npz file. This function is similar to the numpy.save function.

Parameters
[in]fname: Path to the npy file.
[in]data: Pointer to a 1-D array of basic datatype (int, float, double, std::complex<double>, ...).
[in]mode: Writing mode, i.e. overwrite (w) or append (a) to the file.
Warning
This function should also work on big-endian platform, without guarantee since it has not been tested extensively.
Note
Original library: cnpy with MIT license.

Definition at line 430 of file vpIoTools.h.

References npy_save().

◆ npy_save() [2/2]

template<typename T>
void visp::cnpy::npy_save ( const std::string & fname,
const T * data,
const std::vector< size_t > & shape,
const std::string & mode = "w" )

Save an array of data (data) into the fname npy file. This function is similar to the numpy.save function.

Parameters
[in]fname: Path to the npy file.
[in]data: Pointer to an array of basic datatype (int, float, double, std::complex<double>, ...).
[in]shape: Shape of the array, e.g. Nz x Ny x Nx.
[in]mode: Writing mode, i.e. overwrite (w) or append (a) to the file.
Warning
This function should also work on big-endian platform, without guarantee since it has not been tested extensively.
Note
Original library: cnpy with MIT license.

Definition at line 228 of file vpIoTools.h.

References create_npy_header(), and parse_npy_header().

Referenced by npy_save().

◆ npz_load() [1/2]

visp::cnpy::npz_t visp::cnpy::npz_load ( const std::string & fname)

Load the specified fname filepath as arrays of data. This function is similar to the numpy.load function.

Parameters
[in]fname: Path to the npz file.
Returns
A map of arrays data. The key represents the variable name, the value is an array of basic data type.
Warning
This function has only been tested on little endian platform.
Note
Original library: cnpy with MIT license.
See also
To see how to use it, you may have a look at Tutorial: Read / Save arrays of data from / to NPZ file format
Examples
catchNPZ.cpp, catchRBTDataset.cpp, tutorial-mb-generic-tracker-read.cpp, tutorial-npz.cpp, and visp-read-rs-dataset.cpp.

Definition at line 420 of file vpIoTools_npy.cpp.

References vpIoTools::checkFilename(), and vpException::ioError.

◆ npz_load() [2/2]

visp::cnpy::NpyArray visp::cnpy::npz_load ( const std::string & fname,
const std::string & varname )

Load the specified varname array of data from the fname npz file. This function is similar to the numpy.load function.

Parameters
[in]fname: Path to the npz file.
[in]varname: Identifier for the requested array of data.
Returns
An array of basic data type.
Warning
This function has only been tested on little endian platform.
Note
Original library: cnpy with MIT license.
See also
To see how to use it, you may have a look at Tutorial: Read / Save arrays of data from / to NPZ file format

Definition at line 511 of file vpIoTools_npy.cpp.

References vpIoTools::checkFilename(), and vpException::ioError.

◆ npz_save() [1/4]

void visp::cnpy::npz_save ( const std::string & zipname,
const std::string & fname,
const std::string & data_str,
const std::string & mode = "w" )

Save the specified fname std::string (data_str) into the zipname npz file. This function is similar to the numpy.savez function.

Parameters
[in]zipname: Path to the npz file.
[in]fname: Identifier for the corresponding array of data.
[in]data_str: C++ std::string data.
[in]mode: Writing mode, i.e. overwrite (w) or append (a) to the file.
Warning
This function should also work on big-endian platform, without guarantee since it has not been tested extensively.
Note
Original library: cnpy with MIT license.
See also
To see how to use it, you may have a look at Tutorial: Read / Save arrays of data from / to NPZ file format

Definition at line 919 of file vpIoTools_npy.cpp.

References npz_save().

◆ npz_save() [2/4]

template<typename T>
void visp::cnpy::npz_save ( const std::string & zipname,
const std::string & fname,
const std::vector< T > & data,
const std::string & mode = "w" )

Save the specified fname 1-D array of data (data) into the zipname npz file. This function is similar to the numpy.savez function.

Parameters
[in]zipname: Path to the npz file.
[in]fname: Identifier for the corresponding array of data.
[in]data: Pointer to a 1-D array of basic datatype (int, float, double, std::complex<double>, ...).
[in]mode: Writing mode, i.e. overwrite (w) or append (a) to the file.
Warning
This function should also work on big-endian platform, without guarantee since it has not been tested extensively.
Note
Original library: cnpy with MIT license.
See also
To see how to use it, you may have a look at Tutorial: Read / Save arrays of data from / to NPZ file format

Definition at line 449 of file vpIoTools.h.

References npz_save().

◆ npz_save() [3/4]

void visp::cnpy::npz_save ( const std::string & zipname,
std::string fname,
const std::vector< std::string > & data_vec,
const std::vector< size_t > & shape,
const std::string & mode = "w" )

Save the specified fname vector of std::string (data) into the zipname npz file. This function is similar to the numpy.savez function.

Parameters
[in]zipname: Path to the npz file.
[in]fname: Identifier for the corresponding array of data.
[in]data_vec: Vector of std::string.
[in]shape: Shape of the array, e.g. Nz x Ny x Nx.
[in]mode: Writing mode, i.e. overwrite (w) or append (a) to the file.
Warning
This function should also work on big-endian platform, without guarantee since it has not been tested extensively.
Note
Original library: cnpy with MIT license.
See also
To see how to use it, you may have a look at Tutorial: Read / Save arrays of data from / to NPZ file format
Examples
catchNPZ.cpp, tutorial-mb-generic-tracker-full.cpp, tutorial-mb-generic-tracker-save.cpp, tutorial-npz.cpp, and visp-save-rs-dataset.cpp.

Definition at line 758 of file vpIoTools_npy.cpp.

References vpException::badValue, create_npy_header_string(), vpException::dimensionError, parse_zip_footer(), vpEndian::swap16bits(), vpEndian::swap32bits(), and utf8_to_utf32_vec_pad().

Referenced by npz_save(), and npz_save().

◆ npz_save() [4/4]

template<typename T>
void visp::cnpy::npz_save ( const std::string & zipname,
std::string fname,
const T * data,
const std::vector< size_t > & shape,
const std::string & mode = "w" )

Save the specified fname array of data (data) into the zipname npz file. This function is similar to the numpy.savez function.

Parameters
[in]zipname: Path to the npz file.
[in]fname: Identifier for the corresponding array of data.
[in]data: Pointer to an array of basic datatype (int, float, double, std::complex<double>, ...).
[in]shape: Shape of the array, e.g. Nz x Ny x Nx.
[in]mode: Writing mode, i.e. overwrite (w) or append (a) to the file.
Warning
This function should also work on big-endian platform, without guarantee since it has not been tested extensively.
Note
Original library: cnpy with MIT license.
See also
To see how to use it, you may have a look at Tutorial: Read / Save arrays of data from / to NPZ file format

Definition at line 291 of file vpIoTools.h.

References create_npy_header(), parse_zip_footer(), vpEndian::swap16bits(), and vpEndian::swap32bits().

◆ operator+=() [1/3]

template<>
std::vector< char > & visp::cnpy::operator+= ( std::vector< char > & lhs,
const char * rhs )
inline

Definition at line 207 of file vpIoTools.h.

◆ operator+=() [2/3]

template<>
std::vector< char > & visp::cnpy::operator+= ( std::vector< char > & lhs,
const std::string rhs )
inline

Definition at line 201 of file vpIoTools.h.

◆ operator+=() [3/3]

template<typename T>
std::vector< char > & visp::cnpy::operator+= ( std::vector< char > & lhs,
const T rhs )

Definition at line 191 of file vpIoTools.h.

◆ parse_npy_header() [1/2]

void visp::cnpy::parse_npy_header ( FILE * fp,
size_t & word_size,
std::vector< size_t > & shape,
bool & fortran_order,
bool & little_endian,
char & data_type )

Definition at line 217 of file vpIoTools_npy.cpp.

Referenced by npy_save().

◆ parse_npy_header() [2/2]

void visp::cnpy::parse_npy_header ( unsigned char * buffer,
size_t & word_size,
std::vector< size_t > & shape,
bool & fortran_order,
bool & little_endian,
char & data_type )

Definition at line 180 of file vpIoTools_npy.cpp.

◆ parse_zip_footer()

void visp::cnpy::parse_zip_footer ( FILE * fp,
uint16_t & nrecs,
size_t & global_header_size,
size_t & global_header_offset )

Definition at line 277 of file vpIoTools_npy.cpp.

References vpEndian::swap16bits(), and vpEndian::swap32bits().

Referenced by npz_save(), and npz_save().

◆ utf8_to_utf32_vec_pad()

std::vector< char > visp::cnpy::utf8_to_utf32_vec_pad ( const std::string & utf8,
const std::size_t & max_size )

Definition at line 727 of file vpIoTools_npy.cpp.

Referenced by npz_save().