26 #ifndef MXNET_CPP_NDARRAY_H_ 27 #define MXNET_CPP_NDARRAY_H_ 137 NDArray(
const std::vector<mx_uint> &shape,
const Context &context,
138 bool delay_alloc =
true,
int dtype = 0);
147 bool delay_alloc =
true,
int dtype = 0);
162 NDArray(
const std::vector<mx_float> &data,
const Shape &shape,
164 explicit NDArray(
const std::vector<mx_float> &data);
262 void SyncCopyFromCPU(
const mx_float *data,
size_t size);
272 void SyncCopyFromCPU(
const std::vector<mx_float> &data);
283 void SyncCopyToCPU(
mx_float *data,
size_t size = 0);
294 void SyncCopyToCPU(std::vector<mx_float> *data,
size_t size = 0);
313 size_t Offset(
size_t h = 0,
size_t w = 0)
const;
321 size_t Offset(
size_t c,
size_t h,
size_t w)
const;
334 mx_float At(
size_t h,
size_t w)
const;
342 mx_float At(
size_t c,
size_t h,
size_t w)
const;
360 void WaitToRead()
const;
370 static void WaitAll();
393 static void Load(
const std::string &file_name,
394 std::vector<NDArray> *array_list =
nullptr,
395 std::map<std::string, NDArray> *array_map =
nullptr);
401 static std::map<std::string, NDArray> LoadToMap(
const std::string &file_name);
407 static std::vector<NDArray> LoadToList(
const std::string &file_name);
417 static void LoadFromBuffer(
const void *buffer,
size_t size,
418 std::vector<NDArray> *array_list =
nullptr,
419 std::map<std::string, NDArray> *array_map =
nullptr);
426 static std::map<std::string, NDArray> LoadFromBufferToMap(
const void *buffer,
size_t size);
433 static std::vector<NDArray> LoadFromBufferToList(
const void *buffer,
size_t size);
439 static void Save(
const std::string &file_name,
440 const std::map<std::string, NDArray> &array_map);
446 static void Save(
const std::string &file_name,
447 const std::vector<NDArray> &array_list);
455 std::vector<mx_uint>
GetShape()
const;
459 int GetDType()
const;
477 std::shared_ptr<NDBlob> blob_ptr_;
484 #endif // MXNET_CPP_NDARRAY_H_ NDBlob()
default constructor
Definition: ndarray.h:97
Symbol operator/(mx_float lhs, const Symbol &rhs)
ScalarExp< DType > scalar(DType s)
create an scalar expression
Definition: expression.h:103
float mx_float
manually define float
Definition: c_api.h:59
Shape< 2 > GetShape(const Shape< 2 > &shape, bool transpose)
Definition: dot_engine-inl.h:852
namespace of mxnet
Definition: api_registry.h:33
void Copy(Tensor< cpu, dim, DType > dst, const Tensor< cpu, dim, DType > &src, Stream< cpu > *stream=NULL)
copy data from one tensor to another, with same shape
Definition: tensor_cpu-inl.h:145
dynamic shape class that can hold shape of arbirary dimension
Definition: shape.h:42
~NDBlob()
destructor, free the NDArrayHandle
Definition: ndarray.h:106
static Context cpu(int device_id=0)
Return a CPU context.
Definition: ndarray.h:80
MXNET_DLL int MXNDArrayFree(NDArrayHandle handle)
free the narray handle
Symbol operator%(mx_float lhs, const Symbol &rhs)
int GetDeviceId() const
Definition: ndarray.h:64
DeviceType
Definition: ndarray.h:40
NDArray interface.
Definition: ndarray.h:120
NDBlob(NDArrayHandle handle)
construct with a NDArrayHandle
Definition: ndarray.h:102
void SampleGaussian(real_t mu, real_t sigma, NDArray *out)
Sample gaussian distribution for each elements of out.
NDArrayHandle handle_
the NDArrayHandle
Definition: ndarray.h:110
Symbol operator+(mx_float lhs, const Symbol &rhs)
NDArrayHandle GetHandle() const
Definition: ndarray.h:474
void SampleUniform(real_t begin, real_t end, NDArray *out)
Sample uniform distribution for each elements of out.
void * NDArrayHandle
handle to NDArray
Definition: c_api.h:66
std::ostream & operator<<(std::ostream &out, const NDArray &ndarray)
Symbol operator-(mx_float lhs, const Symbol &rhs)
struct to store NDArrayHandle
Definition: ndarray.h:92
static Context gpu(int device_id=0)
Return a GPU context.
Definition: ndarray.h:71
DeviceType GetDeviceType() const
Definition: ndarray.h:60
Context interface.
Definition: ndarray.h:49
Symbol operator*(mx_float lhs, const Symbol &rhs)
Context(const DeviceType &type, int id)
Context constructor.
Definition: ndarray.h:56
uint32_t mx_uint
manually define unsigned int
Definition: c_api.h:57