Public Member Functions | Public Attributes | List of all members
cnpy::NpyArray Struct Reference

#include <cnpy.h>

Public Member Functions

 NpyArray (const std::vector< size_t > &_shape, size_t _word_size, bool _fortran_order)
 
 NpyArray ()
 
template<typename T >
T * data ()
 
template<typename T >
const T * data () const
 
template<typename T >
std::vector< T > as_vec () const
 
size_t num_bytes () const
 

Public Attributes

std::shared_ptr< std::vector< char > > data_holder
 
std::vector< size_t > shape
 
size_t word_size
 
bool fortran_order
 
size_t num_vals
 

Detailed Description

Definition at line 24 of file cnpy.h.

Constructor & Destructor Documentation

cnpy::NpyArray::NpyArray ( const std::vector< size_t > &  _shape,
size_t  _word_size,
bool  _fortran_order 
)
inline

Definition at line 25 of file cnpy.h.

25  :
26  shape(_shape), word_size(_word_size), fortran_order(_fortran_order)
27  {
28  num_vals = 1;
29  for(size_t i = 0;i < shape.size();i++) num_vals *= shape[i];
30  data_holder = std::shared_ptr<std::vector<char>>(
31  new std::vector<char>(num_vals * word_size));
32  }
size_t num_vals
Definition: cnpy.h:60
size_t word_size
Definition: cnpy.h:58
bool fortran_order
Definition: cnpy.h:59
std::vector< size_t > shape
Definition: cnpy.h:57
std::shared_ptr< std::vector< char > > data_holder
Definition: cnpy.h:56
cnpy::NpyArray::NpyArray ( )
inline

Definition at line 34 of file cnpy.h.

34 : shape(0), word_size(0), fortran_order(0), num_vals(0) { }
size_t num_vals
Definition: cnpy.h:60
size_t word_size
Definition: cnpy.h:58
bool fortran_order
Definition: cnpy.h:59
std::vector< size_t > shape
Definition: cnpy.h:57

Member Function Documentation

template<typename T >
std::vector<T> cnpy::NpyArray::as_vec ( ) const
inline

Definition at line 47 of file cnpy.h.

47  {
48  const T* p = data<T>();
49  return std::vector<T>(p, p+num_vals);
50  }
size_t num_vals
Definition: cnpy.h:60
p
Definition: test.py:223
template<typename T >
T* cnpy::NpyArray::data ( )
inline

Definition at line 37 of file cnpy.h.

37  {
38  return reinterpret_cast<T*>(&(*data_holder)[0]);
39  }
template<typename T >
const T* cnpy::NpyArray::data ( ) const
inline

Definition at line 42 of file cnpy.h.

42  {
43  return reinterpret_cast<T*>(&(*data_holder)[0]);
44  }
size_t cnpy::NpyArray::num_bytes ( ) const
inline

Definition at line 52 of file cnpy.h.

52  {
53  return data_holder->size();
54  }
std::shared_ptr< std::vector< char > > data_holder
Definition: cnpy.h:56

Member Data Documentation

std::shared_ptr<std::vector<char> > cnpy::NpyArray::data_holder

Definition at line 56 of file cnpy.h.

bool cnpy::NpyArray::fortran_order

Definition at line 59 of file cnpy.h.

size_t cnpy::NpyArray::num_vals

Definition at line 60 of file cnpy.h.

std::vector<size_t> cnpy::NpyArray::shape

Definition at line 57 of file cnpy.h.

size_t cnpy::NpyArray::word_size

Definition at line 58 of file cnpy.h.


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