mxnet
|
#include <ndarray.h>
Public Member Functions | |
NDArray () | |
construct with a none handle More... | |
NDArray (const NDArrayHandle &handle) | |
construct with a NDArrayHandle More... | |
NDArray (const std::vector< mx_uint > &shape, const Context &context, bool delay_alloc=true) | |
construct a new dynamic NDArray More... | |
NDArray (const Shape &shape, const Context &context, bool delay_alloc=true) | |
construct a new dynamic NDArray More... | |
NDArray (const mx_float *data, size_t size) | |
NDArray (const mx_float *data, const Shape &shape, const Context &context) | |
construct a new dynamic NDArray More... | |
NDArray (const std::vector< mx_float > &data, const Shape &shape, const Context &context) | |
construct a new dynamic NDArray More... | |
NDArray (const std::vector< mx_float > &data) | |
NDArray | operator+ (mx_float scalar) |
NDArray | operator- (mx_float scalar) |
NDArray | operator* (mx_float scalar) |
NDArray | operator/ (mx_float scalar) |
NDArray | operator% (mx_float scalar) |
NDArray | operator+ (const NDArray &) |
NDArray | operator- (const NDArray &) |
NDArray | operator* (const NDArray &) |
NDArray | operator/ (const NDArray &) |
NDArray | operator% (const NDArray &) |
NDArray & | operator= (mx_float scalar) |
set all the elements in ndarray to be scalar More... | |
NDArray & | operator+= (mx_float scalar) |
elementwise add to current space this mutate the current NDArray More... | |
NDArray & | operator-= (mx_float scalar) |
elementwise subtract from current ndarray this mutate the current NDArray More... | |
NDArray & | operator*= (mx_float scalar) |
elementwise multiplication to current ndarray this mutate the current NDArray More... | |
NDArray & | operator/= (mx_float scalar) |
elementwise division from current ndarray this mutate the current NDArray More... | |
NDArray & | operator%= (mx_float scalar) |
elementwise modulo from current ndarray this mutate the current NDArray More... | |
NDArray & | operator+= (const NDArray &src) |
elementwise add to current space this mutate the current NDArray More... | |
NDArray & | operator-= (const NDArray &src) |
elementwise subtract from current ndarray this mutate the current NDArray More... | |
NDArray & | operator*= (const NDArray &src) |
elementwise multiplication to current ndarray this mutate the current NDArray More... | |
NDArray & | operator/= (const NDArray &src) |
elementwise division from current ndarray this mutate the current NDArray More... | |
NDArray & | operator%= (const NDArray &src) |
elementwise modulo from current ndarray this mutate the current NDArray More... | |
NDArray | ArgmaxChannel () |
void | SyncCopyFromCPU (const mx_float *data, size_t size) |
Do a synchronize copy from a continugous CPU memory region. More... | |
void | SyncCopyFromCPU (const std::vector< mx_float > &data) |
Do a synchronize copy from a continugous CPU memory region. More... | |
void | SyncCopyToCPU (mx_float *data, size_t size=0) |
Do a synchronize copy to a continugous CPU memory region. More... | |
void | SyncCopyToCPU (std::vector< mx_float > *data, size_t size=0) |
Do a synchronize copy to a continugous CPU memory region. More... | |
NDArray | CopyTo (NDArray *other) const |
Copy the content of current array to other. More... | |
NDArray | Copy (const Context &) const |
return a new copy this NDArray More... | |
size_t | Offset (size_t h=0, size_t w=0) const |
return offset of the element at (h, w) More... | |
size_t | Offset (size_t c, size_t h, size_t w) const |
return offset of three dimensions array More... | |
mx_float | At (size_t h, size_t w) const |
return value of the element at (h, w) More... | |
mx_float | At (size_t c, size_t h, size_t w) const |
return value of three dimensions array More... | |
NDArray | Slice (mx_uint begin, mx_uint end) const |
Slice a NDArray. More... | |
NDArray | Reshape (const Shape &new_shape) const |
Return a reshaped NDArray that shares memory with current one. More... | |
void | WaitToRead () const |
Block until all the pending write operations with respect to current NDArray are finished, and read can be performed. More... | |
void | WaitToWrite () |
Block until all the pending read/write operations with respect to current NDArray are finished, and write can be performed. More... | |
size_t | Size () const |
std::vector< mx_uint > | GetShape () const |
int | GetDType () const |
const mx_float * | GetData () const |
Get the pointer to data (IMPORTANT: The ndarray should not be in GPU) More... | |
Context | GetContext () const |
NDArrayHandle | GetHandle () const |
Static Public Member Functions | |
static void | WaitAll () |
Block until all the pending read/write operations with respect to current NDArray are finished, and read/write can be performed. More... | |
static void | SampleGaussian (mx_float mu, mx_float sigma, NDArray *out) |
Sample gaussian distribution for each elements of out. More... | |
static void | SampleUniform (mx_float begin, mx_float end, NDArray *out) |
Sample uniform distribution for each elements of out. More... | |
static void | Load (const std::string &file_name, std::vector< NDArray > *array_list=nullptr, std::map< std::string, NDArray > *array_map=nullptr) |
Load NDArrays from binary file. More... | |
static std::map< std::string, NDArray > | LoadToMap (const std::string &file_name) |
Load map of NDArrays from binary file. More... | |
static std::vector< NDArray > | LoadToList (const std::string &file_name) |
Load list of NDArrays from binary file. More... | |
static void | Save (const std::string &file_name, const std::map< std::string, NDArray > &array_map) |
save a map of string->NDArray to binary file. More... | |
static void | Save (const std::string &file_name, const std::vector< NDArray > &array_list) |
save a list of NDArrays to binary file. More... | |
NDArray interface.
mxnet::cpp::NDArray::NDArray | ( | ) |
construct with a none handle
|
explicit |
construct with a NDArrayHandle
mxnet::cpp::NDArray::NDArray | ( | const mx_float * | data, |
size_t | size | ||
) |
|
explicit |
NDArray mxnet::cpp::NDArray::ArgmaxChannel | ( | ) |
mx_float mxnet::cpp::NDArray::At | ( | size_t | h, |
size_t | w | ||
) | const |
return value of the element at (h, w)
h | height position |
w | width position |
mx_float mxnet::cpp::NDArray::At | ( | size_t | c, |
size_t | h, | ||
size_t | w | ||
) | const |
return value of three dimensions array
c | channel position |
h | height position |
w | width position |
Copy the content of current array to other.
other | the new context of this NDArray |
const mx_float* mxnet::cpp::NDArray::GetData | ( | ) | const |
Get the pointer to data (IMPORTANT: The ndarray should not be in GPU)
int mxnet::cpp::NDArray::GetDType | ( | ) | const |
|
inline |
std::vector<mx_uint> mxnet::cpp::NDArray::GetShape | ( | ) | const |
|
static |
Load NDArrays from binary file.
file_name | name of the binary file. |
array_list | a list of NDArrays returned, do not fill the list if nullptr is given. |
array_map | a map from names to NDArrays returned, do not fill the map if nullptr is given or no names is stored in binary file. |
|
static |
Load list of NDArrays from binary file.
file_name | name of the binary file. |
|
static |
Load map of NDArrays from binary file.
file_name | name of the binary file. |
size_t mxnet::cpp::NDArray::Offset | ( | size_t | h = 0 , |
size_t | w = 0 |
||
) | const |
return offset of the element at (h, w)
h | height position |
w | width position |
size_t mxnet::cpp::NDArray::Offset | ( | size_t | c, |
size_t | h, | ||
size_t | w | ||
) | const |
return offset of three dimensions array
c | channel position |
h | height position |
w | width position |
elementwise modulo from current ndarray this mutate the current NDArray
scalar | the data to subtract |
elementwise modulo from current ndarray this mutate the current NDArray
src | the data to subtract |
elementwise multiplication to current ndarray this mutate the current NDArray
scalar | the data to subtract |
elementwise multiplication to current ndarray this mutate the current NDArray
src | the data to subtract |
elementwise add to current space this mutate the current NDArray
scalar | the data to add |
elementwise add to current space this mutate the current NDArray
src | the data to add |
elementwise subtract from current ndarray this mutate the current NDArray
scalar | the data to subtract |
elementwise subtract from current ndarray this mutate the current NDArray
src | the data to subtract |
elementwise division from current ndarray this mutate the current NDArray
scalar | the data to subtract |
elementwise division from current ndarray this mutate the current NDArray
src | the data to subtract |
set all the elements in ndarray to be scalar
scalar | the scalar to set |
Return a reshaped NDArray that shares memory with current one.
new_shape | the new shape |
|
static |
Sample gaussian distribution for each elements of out.
mu | mean of gaussian distribution. |
sigma | standard deviation of gaussian distribution. |
out | output NDArray. |
|
static |
Sample uniform distribution for each elements of out.
begin | lower bound of distribution. |
end | upper bound of distribution. |
out | output NDArray. |
|
static |
save a map of string->NDArray to binary file.
file_name | name of the binary file. |
array_map | a map from names to NDArrays. |
|
static |
save a list of NDArrays to binary file.
file_name | name of the binary file. |
array_list | a list of NDArrays. |
size_t mxnet::cpp::NDArray::Size | ( | ) | const |
void mxnet::cpp::NDArray::SyncCopyFromCPU | ( | const mx_float * | data, |
size_t | size | ||
) |
Do a synchronize copy from a continugous CPU memory region.
This function will call WaitToWrite before the copy is performed. This is useful to copy data from existing memory region that are not wrapped by NDArray(thus dependency not being tracked).
data | the data source to copy from. |
size | the memory size we want to copy from. |
void mxnet::cpp::NDArray::SyncCopyFromCPU | ( | const std::vector< mx_float > & | data | ) |
Do a synchronize copy from a continugous CPU memory region.
This function will call WaitToWrite before the copy is performed. This is useful to copy data from existing memory region that are not wrapped by NDArray(thus dependency not being tracked).
data | the data source to copy from, int the form of mx_float vector |
void mxnet::cpp::NDArray::SyncCopyToCPU | ( | mx_float * | data, |
size_t | size = 0 |
||
) |
Do a synchronize copy to a continugous CPU memory region.
This function will call WaitToRead before the copy is performed. This is useful to copy data from existing memory region that are not wrapped by NDArray(thus dependency not being tracked).
data | the data source to copyinto. |
size | the memory size we want to copy into. Defualt value is Size() |
void mxnet::cpp::NDArray::SyncCopyToCPU | ( | std::vector< mx_float > * | data, |
size_t | size = 0 |
||
) |
Do a synchronize copy to a continugous CPU memory region.
This function will call WaitToRead before the copy is performed. This is useful to copy data from existing memory region that are not wrapped by NDArray(thus dependency not being tracked).
data | the data source to copyinto. |
size | the memory size we want to copy into. Defualt value is Size() |
|
static |
Block until all the pending read/write operations with respect to current NDArray are finished, and read/write can be performed.
void mxnet::cpp::NDArray::WaitToRead | ( | ) | const |
Block until all the pending write operations with respect to current NDArray are finished, and read can be performed.
void mxnet::cpp::NDArray::WaitToWrite | ( | ) |
Block until all the pending read/write operations with respect to current NDArray are finished, and write can be performed.