Visual Servoing Platform  version 3.6.1 under development (2024-11-21)
visp::cnpy Namespace Reference

Classes

struct  NpyArray
 

Typedefs

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

Functions

VISP_EXPORT npz_t npz_load (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)
 
VISP_EXPORT void parse_npy_header (unsigned char *buffer, size_t &word_size, std::vector< size_t > &shape, bool &fortran_order)
 
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 (std::string fname, std::string varname)
 
VISP_EXPORT NpyArray npy_load (std::string fname)
 
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 (std::string fname, const T *data, const std::vector< size_t > shape, std::string mode="w")
 
template<typename T >
void npz_save (std::string zipname, std::string fname, const T *data, const std::vector< size_t > &shape, std::string mode="w")
 
template<typename T >
void npy_save (std::string fname, const std::vector< T > data, std::string mode="w")
 
template<typename T >
void npz_save (std::string zipname, std::string fname, const std::vector< T > data, std::string mode="w")
 

Typedef Documentation

◆ npz_t

using visp::cnpy::npz_t = typedef std::map<std::string, NpyArray>

Definition at line 130 of file vpIoTools.h.

Function Documentation

◆ BigEndianTest()

char visp::cnpy::BigEndianTest ( )

Definition at line 57 of file vpIoTools_npy.cpp.

Referenced by create_npy_header().

◆ create_npy_header()

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

Definition at line 360 of file vpIoTools.h.

References BigEndianTest(), and map_type().

◆ map_type()

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

Definition at line 63 of file vpIoTools_npy.cpp.

Referenced by create_npy_header().

◆ npy_load()

visp::cnpy::NpyArray visp::cnpy::npy_load ( 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.

Definition at line 420 of file vpIoTools_npy.cpp.

◆ npy_save() [1/2]

template<typename T >
void visp::cnpy::npy_save ( std::string  fname,
const std::vector< T >  data,
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 has only been tested on little endian platform.
Note
Original library: cnpy with MIT license.

Definition at line 336 of file vpIoTools.h.

References npy_save().

◆ npy_save() [2/2]

template<typename T >
void visp::cnpy::npy_save ( std::string  fname,
const T *  data,
const std::vector< size_t >  shape,
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 has only been tested on little endian platform.
Note
Original library: cnpy with MIT license.

Definition at line 178 of file vpIoTools.h.

References parse_npy_header().

Referenced by npy_save().

◆ npz_load() [1/2]

visp::cnpy::npz_t visp::cnpy::npz_load ( 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.
Examples
catchNPZ.cpp, readRealSenseData.cpp, tutorial-mb-generic-tracker-read.cpp, and tutorial-npz.cpp.

Definition at line 270 of file vpIoTools_npy.cpp.

◆ npz_load() [2/2]

visp::cnpy::NpyArray visp::cnpy::npz_load ( std::string  fname,
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.

Definition at line 347 of file vpIoTools_npy.cpp.

◆ npz_save() [1/2]

template<typename T >
void visp::cnpy::npz_save ( std::string  zipname,
std::string  fname,
const std::vector< T >  data,
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 has only been tested on little endian platform.
Note
Original library: cnpy with MIT license.

Definition at line 353 of file vpIoTools.h.

References npz_save().

◆ npz_save() [2/2]

template<typename T >
void visp::cnpy::npz_save ( std::string  zipname,
std::string  fname,
const T *  data,
const std::vector< size_t > &  shape,
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 has only been tested on little endian platform.
Note
Original library: cnpy with MIT license.
Examples
catchNPZ.cpp, saveRealSenseData.cpp, tutorial-mb-generic-tracker-full.cpp, tutorial-mb-generic-tracker-save.cpp, and tutorial-npz.cpp.

Definition at line 235 of file vpIoTools.h.

References parse_zip_footer().

Referenced by npz_save().

◆ operator+=() [1/3]

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

Definition at line 157 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 151 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 141 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 
)

Definition at line 125 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 
)

Definition at line 90 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 181 of file vpIoTools_npy.cpp.

Referenced by npz_save().