27 #ifndef MXNET_CPP_NDARRAY_H_ 28 #define MXNET_CPP_NDARRAY_H_ 138 NDArray(
const std::vector<mx_uint> &shape,
const Context &context,
139 bool delay_alloc =
true,
int dtype = 0);
148 bool delay_alloc =
true,
int dtype = 0);
163 NDArray(
const std::vector<mx_float> &data,
const Shape &shape,
165 explicit NDArray(
const std::vector<mx_float> &data);
263 void SyncCopyFromCPU(
const mx_float *data,
size_t size);
273 void SyncCopyFromCPU(
const std::vector<mx_float> &data);
284 void SyncCopyToCPU(
mx_float *data,
size_t size = 0);
295 void SyncCopyToCPU(std::vector<mx_float> *data,
size_t size = 0);
314 size_t Offset(
size_t h = 0,
size_t w = 0)
const;
322 size_t Offset(
size_t c,
size_t h,
size_t w)
const;
335 mx_float At(
size_t h,
size_t w)
const;
343 mx_float At(
size_t c,
size_t h,
size_t w)
const;
361 void WaitToRead()
const;
371 static void WaitAll();
394 static void Load(
const std::string &file_name,
395 std::vector<NDArray> *array_list =
nullptr,
396 std::map<std::string, NDArray> *array_map =
nullptr);
402 static std::map<std::string, NDArray> LoadToMap(
const std::string &file_name);
408 static std::vector<NDArray> LoadToList(
const std::string &file_name);
418 static void LoadFromBuffer(
const void *buffer,
size_t size,
419 std::vector<NDArray> *array_list =
nullptr,
420 std::map<std::string, NDArray> *array_map =
nullptr);
427 static std::map<std::string, NDArray> LoadFromBufferToMap(
const void *buffer,
size_t size);
434 static std::vector<NDArray> LoadFromBufferToList(
const void *buffer,
size_t size);
440 static void Save(
const std::string &file_name,
441 const std::map<std::string, NDArray> &array_map);
447 static void Save(
const std::string &file_name,
448 const std::vector<NDArray> &array_list);
456 std::vector<mx_uint> GetShape()
const;
460 int GetDType()
const;
478 std::shared_ptr<NDBlob> blob_ptr_;
485 #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:89
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:67
NDArrayHandle GetHandle() const
Definition: ndarray.h:475
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)
Reshapes the input array.
Definition: op.h:344
Symbol operator*(mx_float lhs, const Symbol &rhs)
Context(const DeviceType &type, int id)
Context constructor.
Definition: ndarray.h:57