LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
lbann::cnpy_utils Namespace Reference

Functions

size_t compute_cnpy_array_offset (const cnpy::NpyArray &na, std::vector< size_t > indices)
 
template<typename T >
size_t ptr_offset (const cnpy::NpyArray &na, std::vector< size_t > indices)
 
template<typename T >
T & data (const cnpy::NpyArray &na, const std::vector< size_t > indices)
 
template<typename T >
T * data_ptr (const cnpy::NpyArray &na, const std::vector< size_t > indices)
 
template<>
void * data_ptr< void > (const cnpy::NpyArray &na, const std::vector< size_t > indices)
 
void shrink_to_fit (cnpy::NpyArray &na, size_t sz)
 
std::string show_shape (const cnpy::NpyArray &na)
 Show the dimensions of loaded data. More...
 

Function Documentation

◆ compute_cnpy_array_offset()

size_t lbann::cnpy_utils::compute_cnpy_array_offset ( const cnpy::NpyArray &  na,
std::vector< size_t >  indices 
)

Return the offset to the element (in terms of the number of elements from the beginning of the array) of a loaded numpy array na specified by indices If the number of indices is less than the dimension of na array, the indices vector is appended with zeros to match the dimension.

Here is the caller graph for this function:

◆ data()

template<typename T >
T& lbann::cnpy_utils::data ( const cnpy::NpyArray &  na,
const std::vector< size_t >  indices 
)
inline

Allow the access to the data element identified by the indices and the word_size of the array na, but present it as a type T element at the address.

Definition at line 75 of file cnpy_utils.hpp.

Here is the caller graph for this function:

◆ data_ptr()

template<typename T >
T* lbann::cnpy_utils::data_ptr ( const cnpy::NpyArray &  na,
const std::vector< size_t >  indices 
)
inline

Return the address of the data element identified by the indices and the word_size of the array na, but present it as the address of a type T element

Definition at line 86 of file cnpy_utils.hpp.

◆ data_ptr< void >()

template<>
void* lbann::cnpy_utils::data_ptr< void > ( const cnpy::NpyArray &  na,
const std::vector< size_t >  indices 
)
inline

Definition at line 93 of file cnpy_utils.hpp.

Here is the call graph for this function:

◆ ptr_offset()

template<typename T >
size_t lbann::cnpy_utils::ptr_offset ( const cnpy::NpyArray &  na,
std::vector< size_t >  indices 
)
inline

If the type T of the numpy array element is something larger than 1 byte in size, the word_size of the numpy array must be the same as sizeof(T). In such a case, offset to add to a type T pointer is computed as the number of elements up to the position pointed by the indices. If sizeof(T) is 1 byte, then the array may be of char string, or the pointer may be cast to a byte-long type. In such a case, the offset is computed as the number of elements scaled by the word_size of the array. cnpy treats an array of strings as a 1D array, for which the word_size is equal to the length of the largest string.

Definition at line 59 of file cnpy_utils.hpp.

Here is the call graph for this function:

◆ show_shape()

std::string lbann::cnpy_utils::show_shape ( const cnpy::NpyArray &  na)

Show the dimensions of loaded data.

Here is the caller graph for this function:

◆ shrink_to_fit()

void lbann::cnpy_utils::shrink_to_fit ( cnpy::NpyArray &  na,
size_t  sz 
)

Shrink the first dimension of cnpy::NpyArray to the given size. This is used to choose only first sz samples in data.

Here is the caller graph for this function: