27 #ifndef MXNET_CPP_NDARRAY_H_ 28 #define MXNET_CPP_NDARRAY_H_ 137 NDArray(
const std::vector<mx_uint> &shape,
const Context &context,
138 bool delay_alloc =
true);
160 NDArray(
const std::vector<mx_float> &data,
const Shape &shape,
162 explicit NDArray(
const std::vector<mx_float> &data);
260 void SyncCopyFromCPU(
const mx_float *data,
size_t size);
270 void SyncCopyFromCPU(
const std::vector<mx_float> &data);
281 void SyncCopyToCPU(
mx_float *data,
size_t size = 0);
292 void SyncCopyToCPU(std::vector<mx_float> *data,
size_t size = 0);
311 size_t Offset(
size_t h = 0,
size_t w = 0)
const;
319 size_t Offset(
size_t c,
size_t h,
size_t w)
const;
326 mx_float At(
size_t h,
size_t w)
const;
334 mx_float At(
size_t c,
size_t h,
size_t w)
const;
352 void WaitToRead()
const;
362 static void WaitAll();
385 static void Load(
const std::string &file_name,
386 std::vector<NDArray> *array_list =
nullptr,
387 std::map<std::string, NDArray> *array_map =
nullptr);
393 static std::map<std::string, NDArray> LoadToMap(
const std::string &file_name);
399 static std::vector<NDArray> LoadToList(
const std::string &file_name);
405 static void Save(
const std::string &file_name,
406 const std::map<std::string, NDArray> &array_map);
412 static void Save(
const std::string &file_name,
413 const std::vector<NDArray> &array_list);
421 std::vector<mx_uint> GetShape()
const;
425 int GetDType()
const;
443 std::shared_ptr<NDBlob> blob_ptr_;
450 #endif // MXNET_CPP_NDARRAY_H_ NDBlob()
default constructor
Definition: ndarray.h:98
Symbol operator/(mx_float lhs, const Symbol &rhs)
namespace of mxnet
Definition: base.h:127
dynamic shape class that can hold shape of arbirary dimension
Definition: shape.h:43
MXNET_DLL int MXNDArrayFree(NDArrayHandle handle)
free the narray handle
~NDBlob()
destructor, free the NDArrayHandle
Definition: ndarray.h:107
static Context cpu(int device_id=0)
Return a CPU context.
Definition: ndarray.h:81
Symbol operator%(mx_float lhs, const Symbol &rhs)
DeviceType
Definition: ndarray.h:41
NDArray interface.
Definition: ndarray.h:121
NDBlob(NDArrayHandle handle)
construct with a NDArrayHandle
Definition: ndarray.h:103
void SampleGaussian(real_t mu, real_t sigma, NDArray *out)
Sample gaussian distribution for each elements of out.
void * NDArrayHandle
handle to NDArray
Definition: c_api.h:65
NDArrayHandle GetHandle() const
Definition: ndarray.h:440
NDArrayHandle handle_
the NDArrayHandle
Definition: ndarray.h:111
Symbol operator+(mx_float lhs, const Symbol &rhs)
unsigned int mx_uint
manually define unsigned int
Definition: c_api.h:58
void SampleUniform(real_t begin, real_t end, NDArray *out)
Sample uniform distribution for each elements of out.
DeviceType GetDeviceType() const
Definition: ndarray.h:61
std::ostream & operator<<(std::ostream &out, const NDArray &ndarray)
int GetDeviceId() const
Definition: ndarray.h:65
float mx_float
manually define float
Definition: c_api.h:60
Symbol operator-(mx_float lhs, const Symbol &rhs)
struct to store NDArrayHandle
Definition: ndarray.h:93
static Context gpu(int device_id=0)
Return a GPU context.
Definition: ndarray.h:72
Context interface.
Definition: ndarray.h:50
Symbol Reshape(const std::string &symbol_name, Symbol data, Shape shape=Shape(), bool reverse=false, Shape target_shape=Shape(), bool keep_highest=false)
Definition: op.h:232
Symbol operator*(mx_float lhs, const Symbol &rhs)
Context(const DeviceType &type, int id)
Context constructor.
Definition: ndarray.h:57