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

ndarray interface More...

#include <ndarray.h>

Collaboration diagram for mxnet::NDArray:
Collaboration graph

Public Member Functions

 NDArray ()
 default constructor More...
 
 NDArray (const TShape &shape, Context ctx, bool delay_alloc=false, int dtype=mshadow::default_type_flag)
 constructs a new dynamic NDArray More...
 
 NDArray (const TBlob &data, int dev_id)
 constructing a static NDArray that shares data with TBlob Use with caution: allocate ONLY ONE NDArray for each TBlob, make sure the memory region is available through out the life of NDArray More...
 
const TShapeshape () const
 
const TBlobdata () const
 
NDArray grad () const
 
Context ctx () const
 
int dtype () const
 
bool is_none () const
 
bool fresh_out_grad () const
 
void set_fresh_out_grad (bool state) const
 
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 () const
 Block until all the pending read/write operations with respect to current NDArray are finished, and write can be performed. More...
 
Engine::VarHandle var () const
 
void Save (dmlc::Stream *strm) const
 save the content into binary stream More...
 
bool Load (dmlc::Stream *strm)
 load the content from binary stream More...
 
NDArrayoperator= (real_t scalar)
 set all the elements in ndarray to be scalar More...
 
NDArrayoperator+= (const NDArray &src)
 elementwise add to current space this mutate the current NDArray More...
 
NDArrayoperator+= (const real_t &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 real_t &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 real_t &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 real_t &src)
 elementwise division from current ndarray this mutate the current NDArray More...
 
NDArray T () const
 return transpose of current NDArray More...
 
NDArray Copy (Context ctx) const
 return a new copy this NDArray More...
 
void SyncCopyFromCPU (const void *data, size_t size) const
 Do a synchronize copy from a continugous CPU memory region. More...
 
void SyncCopyToCPU (void *data, size_t size) const
 Do a synchronize copy to a continugous CPU memory region. More...
 
NDArray Slice (index_t begin, index_t end) const
 Slice a NDArray. More...
 
NDArray At (index_t idx) const
 Index a NDArray. More...
 
NDArray AsArray (const TShape &shape, int dtype) const
 Create a NDArray that shares memory with current one The new array must have smaller memory size than the current array. More...
 
NDArray Reshape (const TShape &shape) const
 Get an reshaped NDArray. More...
 
NDArray Detach () const
 Return a copy of this NDArray without autograd history. More...
 
nnvm::Symbol get_autograd_symbol ()
 
void CheckAndAlloc () const
 Allocate the space if it is delayed allocated. This is an internal function used by system that normal user should not use. More...
 

Static Public Member Functions

static void Save (dmlc::Stream *fo, const std::vector< NDArray > &data, const std::vector< std::string > &names)
 Save list of ndarray into the Stream.x. More...
 
static void Load (dmlc::Stream *fi, std::vector< NDArray > *data, std::vector< std::string > *keys)
 Load list of ndarray into from the stream. More...
 

Friends

class autograd::AutogradRuntime
 

Detailed Description

ndarray interface

Constructor & Destructor Documentation

mxnet::NDArray::NDArray ( )
inline

default constructor

mxnet::NDArray::NDArray ( const TShape shape,
Context  ctx,
bool  delay_alloc = false,
int  dtype = mshadow::default_type_flag 
)
inline

constructs a new dynamic NDArray

Parameters
shapethe shape of array
ctxcontext of NDArray
delay_allocwhether delay the allocation
dtypedata type of this ndarray
mxnet::NDArray::NDArray ( const TBlob data,
int  dev_id 
)
inline

constructing a static NDArray that shares data with TBlob Use with caution: allocate ONLY ONE NDArray for each TBlob, make sure the memory region is available through out the life of NDArray

Parameters
datathe memory content of static data
dev_idthe device id this tensor sits at

Member Function Documentation

NDArray mxnet::NDArray::AsArray ( const TShape shape,
int  dtype 
) const
inline

Create a NDArray that shares memory with current one The new array must have smaller memory size than the current array.

Parameters
shapenew shape
dtypeThe data type.
Returns
NDArray in new shape and type.
NDArray mxnet::NDArray::At ( index_t  idx) const

Index a NDArray.

Parameters
idxthe index
Returns
idx-th sub array NDArray
void mxnet::NDArray::CheckAndAlloc ( ) const
inline

Allocate the space if it is delayed allocated. This is an internal function used by system that normal user should not use.

NDArray mxnet::NDArray::Copy ( Context  ctx) const

return a new copy this NDArray

Parameters
ctxthe new context of this NDArray
Returns
the new copy
Context mxnet::NDArray::ctx ( ) const
inline
Returns
the context of NDArray, this function is only valid when the NDArray is not empty
const TBlob& mxnet::NDArray::data ( ) const
inline
Returns
the data TBlob
NDArray mxnet::NDArray::Detach ( ) const
inline

Return a copy of this NDArray without autograd history.

int mxnet::NDArray::dtype ( ) const
inline
Returns
the data type of NDArray, this function is only valid when the NDArray is not empty
bool mxnet::NDArray::fresh_out_grad ( ) const
Returns
updated grad state in entry_
nnvm::Symbol mxnet::NDArray::get_autograd_symbol ( )
inline
NDArray mxnet::NDArray::grad ( ) const
Returns
the gradient ndarray.
bool mxnet::NDArray::is_none ( ) const
inline
Returns
whether this ndarray is not initialized
bool mxnet::NDArray::Load ( dmlc::Stream *  strm)

load the content from binary stream

Parameters
strmthe output stream
Returns
whether the load is successful
static void mxnet::NDArray::Load ( dmlc::Stream *  fi,
std::vector< NDArray > *  data,
std::vector< std::string > *  keys 
)
static

Load list of ndarray into from the stream.

Parameters
fiThe stream of the input file.
datathe NDArrays to be loaded
keysthe name of the NDArray, if saved in the file.
NDArray& mxnet::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::NDArray::operator*= ( const real_t src)

elementwise multiplication to current ndarray this mutate the current NDArray

Parameters
srcthe data to subtract
Returns
reference of self
NDArray& mxnet::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::NDArray::operator+= ( const real_t src)

elementwise add to current space this mutate the current NDArray

Parameters
srcthe data to add
Returns
reference of self
NDArray& mxnet::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::NDArray::operator-= ( const real_t src)

elementwise subtract from current ndarray this mutate the current NDArray

Parameters
srcthe data to subtract
Returns
reference of self
NDArray& mxnet::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::NDArray::operator/= ( const real_t src)

elementwise division from current ndarray this mutate the current NDArray

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

set all the elements in ndarray to be scalar

Parameters
scalarthe scalar to set
Returns
reference of self
NDArray mxnet::NDArray::Reshape ( const TShape shape) const

Get an reshaped NDArray.

Parameters
shapenew shape
Returns
NDArray in new shape
void mxnet::NDArray::Save ( dmlc::Stream *  strm) const

save the content into binary stream

Parameters
strmthe output stream
static void mxnet::NDArray::Save ( dmlc::Stream *  fo,
const std::vector< NDArray > &  data,
const std::vector< std::string > &  names 
)
static

Save list of ndarray into the Stream.x.

Parameters
foThe stream of output.
datathe NDArrays to be saved.
namesthe name of the NDArray, optional, can be zero length.
void mxnet::NDArray::set_fresh_out_grad ( bool  state) const
Returns
updated grad state in entry_
const TShape& mxnet::NDArray::shape ( ) const
inline
Returns
the shape of current NDArray
NDArray mxnet::NDArray::Slice ( index_t  begin,
index_t  end 
) const

Slice a NDArray.

Parameters
beginbegin index in first dim
endend index in first dim
Returns
sliced NDArray
void mxnet::NDArray::SyncCopyFromCPU ( const void *  data,
size_t  size 
) const

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 size of the source array, in sizeof(DType) not raw btyes.
void mxnet::NDArray::SyncCopyToCPU ( void *  data,
size_t  size 
) const

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, in sizeof(DType) not raw btyes.
NDArray mxnet::NDArray::T ( ) const

return transpose of current NDArray

Returns
a new transposed NDArray
Engine::VarHandle mxnet::NDArray::var ( ) const
inline
Returns
the associated variable of the ndarray.
void mxnet::NDArray::WaitToRead ( ) const
inline

Block until all the pending write operations with respect to current NDArray are finished, and read can be performed.

void mxnet::NDArray::WaitToWrite ( ) const
inline

Block until all the pending read/write operations with respect to current NDArray are finished, and write can be performed.

Push an empty mutable function to flush all preceding reads to the variable.

Friends And Related Function Documentation

friend class autograd::AutogradRuntime
friend

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