mxnet
Public Member Functions | Static Public Member Functions | List of all members
mxnet::cpp::NDArray Class Reference

NDArray interface. More...

#include <ndarray.h>

Collaboration diagram for mxnet::cpp::NDArray:
Collaboration graph

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 &)
 
NDArrayoperator= (mx_float scalar)
 set all the elements in ndarray to be scalar More...
 
NDArrayoperator+= (mx_float scalar)
 elementwise add to current space this mutate the current NDArray More...
 
NDArrayoperator-= (mx_float scalar)
 elementwise subtract from current ndarray this mutate the current NDArray More...
 
NDArrayoperator*= (mx_float scalar)
 elementwise multiplication to current ndarray this mutate the current NDArray More...
 
NDArrayoperator/= (mx_float scalar)
 elementwise division from current ndarray this mutate the current NDArray More...
 
NDArrayoperator%= (mx_float scalar)
 elementwise modulo from current ndarray this mutate the current NDArray More...
 
NDArrayoperator+= (const NDArray &src)
 elementwise add to current space this mutate the current NDArray More...
 
NDArrayoperator-= (const NDArray &src)
 elementwise subtract from current ndarray this mutate the current NDArray More...
 
NDArrayoperator*= (const NDArray &src)
 elementwise multiplication to current ndarray this mutate the current NDArray More...
 
NDArrayoperator/= (const NDArray &src)
 elementwise division from current ndarray this mutate the current NDArray More...
 
NDArrayoperator%= (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_uintGetShape () const
 
int GetDType () const
 
const mx_floatGetData () 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, NDArrayLoadToMap (const std::string &file_name)
 Load map of NDArrays from binary file. More...
 
static std::vector< NDArrayLoadToList (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...
 

Detailed Description

NDArray interface.

Constructor & Destructor Documentation

mxnet::cpp::NDArray::NDArray ( )

construct with a none handle

mxnet::cpp::NDArray::NDArray ( const NDArrayHandle handle)
explicit

construct with a NDArrayHandle

mxnet::cpp::NDArray::NDArray ( const std::vector< mx_uint > &  shape,
const Context context,
bool  delay_alloc = true 
)

construct a new dynamic NDArray

Parameters
shapethe shape of array
constextcontext of NDArray
delay_allocwhether delay the allocation
mxnet::cpp::NDArray::NDArray ( const Shape shape,
const Context context,
bool  delay_alloc = true 
)

construct a new dynamic NDArray

Parameters
shapethe shape of array
constextcontext of NDArray
delay_allocwhether delay the allocation
mxnet::cpp::NDArray::NDArray ( const mx_float data,
size_t  size 
)
mxnet::cpp::NDArray::NDArray ( const mx_float data,
const Shape shape,
const Context context 
)

construct a new dynamic NDArray

Parameters
datathe data to create NDArray from
shapethe shape of array
constextcontext of NDArray
mxnet::cpp::NDArray::NDArray ( const std::vector< mx_float > &  data,
const Shape shape,
const Context context 
)

construct a new dynamic NDArray

Parameters
datathe data to create NDArray from
shapethe shape of array
constextcontext of NDArray
mxnet::cpp::NDArray::NDArray ( const std::vector< mx_float > &  data)
explicit

Member Function Documentation

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)

Parameters
hheight position
wwidth position
Returns
value of two dimensions array
mx_float mxnet::cpp::NDArray::At ( size_t  c,
size_t  h,
size_t  w 
) const

return value of three dimensions array

Parameters
cchannel position
hheight position
wwidth position
Returns
value of three dimensions array
NDArray mxnet::cpp::NDArray::Copy ( const Context ) const

return a new copy this NDArray

Parameters
otherthe target NDArray
Returns
the copy target NDarray
NDArray mxnet::cpp::NDArray::CopyTo ( NDArray other) const

Copy the content of current array to other.

Parameters
otherthe new context of this NDArray
Returns
the new copy
Context mxnet::cpp::NDArray::GetContext ( ) const
Returns
the context of NDArray
const mx_float* mxnet::cpp::NDArray::GetData ( ) const

Get the pointer to data (IMPORTANT: The ndarray should not be in GPU)

Returns
the data pointer to the current NDArray
int mxnet::cpp::NDArray::GetDType ( ) const
Returns
the data type of current NDArray
NDArrayHandle mxnet::cpp::NDArray::GetHandle ( ) const
inline
Returns
the NDArrayHandle of the current NDArray
std::vector<mx_uint> mxnet::cpp::NDArray::GetShape ( ) const
Returns
the shape of current NDArray, in the form of mx_uint vector
static void mxnet::cpp::NDArray::Load ( const std::string &  file_name,
std::vector< NDArray > *  array_list = nullptr,
std::map< std::string, NDArray > *  array_map = nullptr 
)
static

Load NDArrays from binary file.

Parameters
file_namename of the binary file.
array_lista list of NDArrays returned, do not fill the list if nullptr is given.
array_mapa map from names to NDArrays returned, do not fill the map if nullptr is given or no names is stored in binary file.
static std::vector<NDArray> mxnet::cpp::NDArray::LoadToList ( const std::string &  file_name)
static

Load list of NDArrays from binary file.

Parameters
file_namename of the binary file.
Returns
a map from names to NDArrays.
static std::map<std::string, NDArray> mxnet::cpp::NDArray::LoadToMap ( const std::string &  file_name)
static

Load map of NDArrays from binary file.

Parameters
file_namename of the binary file.
Returns
a list of NDArrays.
size_t mxnet::cpp::NDArray::Offset ( size_t  h = 0,
size_t  w = 0 
) const

return offset of the element at (h, w)

Parameters
hheight position
wwidth position
Returns
offset of two dimensions array
size_t mxnet::cpp::NDArray::Offset ( size_t  c,
size_t  h,
size_t  w 
) const

return offset of three dimensions array

Parameters
cchannel position
hheight position
wwidth position
Returns
offset of three dimensions array
NDArray mxnet::cpp::NDArray::operator% ( mx_float  scalar)
NDArray mxnet::cpp::NDArray::operator% ( const NDArray )
NDArray& mxnet::cpp::NDArray::operator%= ( mx_float  scalar)

elementwise modulo from current ndarray this mutate the current NDArray

Parameters
scalarthe data to subtract
Returns
reference of self
NDArray& mxnet::cpp::NDArray::operator%= ( const NDArray src)

elementwise modulo from current ndarray this mutate the current NDArray

Parameters
srcthe data to subtract
Returns
reference of self
NDArray mxnet::cpp::NDArray::operator* ( mx_float  scalar)
NDArray mxnet::cpp::NDArray::operator* ( const NDArray )
NDArray& mxnet::cpp::NDArray::operator*= ( mx_float  scalar)

elementwise multiplication to current ndarray this mutate the current NDArray

Parameters
scalarthe data to subtract
Returns
reference of self
NDArray& mxnet::cpp::NDArray::operator*= ( const NDArray src)

elementwise multiplication to current ndarray this mutate the current NDArray

Parameters
srcthe data to subtract
Returns
reference of self
NDArray mxnet::cpp::NDArray::operator+ ( mx_float  scalar)
NDArray mxnet::cpp::NDArray::operator+ ( const NDArray )
NDArray& mxnet::cpp::NDArray::operator+= ( mx_float  scalar)

elementwise add to current space this mutate the current NDArray

Parameters
scalarthe data to add
Returns
reference of self
NDArray& mxnet::cpp::NDArray::operator+= ( const NDArray src)

elementwise add to current space this mutate the current NDArray

Parameters
srcthe data to add
Returns
reference of self
NDArray mxnet::cpp::NDArray::operator- ( mx_float  scalar)
NDArray mxnet::cpp::NDArray::operator- ( const NDArray )
NDArray& mxnet::cpp::NDArray::operator-= ( mx_float  scalar)

elementwise subtract from current ndarray this mutate the current NDArray

Parameters
scalarthe data to subtract
Returns
reference of self
NDArray& mxnet::cpp::NDArray::operator-= ( const NDArray src)

elementwise subtract from current ndarray this mutate the current NDArray

Parameters
srcthe data to subtract
Returns
reference of self
NDArray mxnet::cpp::NDArray::operator/ ( mx_float  scalar)
NDArray mxnet::cpp::NDArray::operator/ ( const NDArray )
NDArray& mxnet::cpp::NDArray::operator/= ( mx_float  scalar)

elementwise division from current ndarray this mutate the current NDArray

Parameters
scalarthe data to subtract
Returns
reference of self
NDArray& mxnet::cpp::NDArray::operator/= ( const NDArray src)

elementwise division from current ndarray this mutate the current NDArray

Parameters
srcthe data to subtract
Returns
reference of self
NDArray& mxnet::cpp::NDArray::operator= ( mx_float  scalar)

set all the elements in ndarray to be scalar

Parameters
scalarthe scalar to set
Returns
reference of self
NDArray mxnet::cpp::NDArray::Reshape ( const Shape new_shape) const

Return a reshaped NDArray that shares memory with current one.

Parameters
new_shapethe new shape
Returns
reshaped NDarray
static void mxnet::cpp::NDArray::SampleGaussian ( mx_float  mu,
mx_float  sigma,
NDArray out 
)
static

Sample gaussian distribution for each elements of out.

Parameters
mumean of gaussian distribution.
sigmastandard deviation of gaussian distribution.
outoutput NDArray.
static void mxnet::cpp::NDArray::SampleUniform ( mx_float  begin,
mx_float  end,
NDArray out 
)
static

Sample uniform distribution for each elements of out.

Parameters
beginlower bound of distribution.
endupper bound of distribution.
outoutput NDArray.
static void mxnet::cpp::NDArray::Save ( const std::string &  file_name,
const std::map< std::string, NDArray > &  array_map 
)
static

save a map of string->NDArray to binary file.

Parameters
file_namename of the binary file.
array_mapa map from names to NDArrays.
static void mxnet::cpp::NDArray::Save ( const std::string &  file_name,
const std::vector< NDArray > &  array_list 
)
static

save a list of NDArrays to binary file.

Parameters
file_namename of the binary file.
array_lista list of NDArrays.
size_t mxnet::cpp::NDArray::Size ( ) const
Returns
the size of current NDArray, a.k.a. the production of all shape dims
NDArray mxnet::cpp::NDArray::Slice ( mx_uint  begin,
mx_uint  end 
) const

Slice a NDArray.

Parameters
beginbegin index in first dim
endend index in first dim
Returns
sliced NDArray
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).

Parameters
datathe data source to copy from.
sizethe 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).

Parameters
datathe 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).

Parameters
datathe data source to copyinto.
sizethe 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).

Parameters
datathe data source to copyinto.
sizethe memory size we want to copy into. Defualt value is Size()
static void mxnet::cpp::NDArray::WaitAll ( )
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.


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