Go to the documentation of this file.
24 #ifndef MXNET_NDARRAY_H_
25 #define MXNET_NDARRAY_H_
29 #include <dmlc/logging.h>
43 #if DMLC_USE_CXX11 == 0
44 #error "cxx11 was required for ndarray module"
95 bool delay_alloc =
false,
101 autograd_entry_(nullptr) {}
107 bool delay_alloc =
true,
125 autograd_entry_(nullptr) {}
134 : ptr_(
std::make_shared<Chunk>(
data, dev_id)),
136 dtype_(
data.type_flag_),
138 autograd_entry_(nullptr) {}
149 : ptr_(new Chunk(
data, dev_id),
150 [deleter](Chunk* p) {
157 autograd_entry_(
nullptr) {}
161 : ptr_(
std::make_shared<Chunk>(shared_pid, shared_id,
shape,
dtype)),
165 autograd_entry_(nullptr) {}
184 dtype_(
data.type_flag_),
185 storage_type_(stype),
186 autograd_entry_(nullptr) {}
192 ptr_->Init(
shape, this->dtype_);
193 this->shape_ =
shape;
208 bool delay_alloc =
true,
209 const std::vector<int>*
aux_types =
nullptr,
232 return byte_offset_ > 0 ||
shape() != ptr_->storage_shape;
237 return ptr_ == other.ptr_ && shape_ == other.shape_ && byte_offset_ == other.byte_offset_ &&
238 dtype_ == other.dtype_;
253 CHECK(ptr_ !=
nullptr);
255 <<
"storage_shape() is not intended for kDefaultStorage.";
256 return ptr_->storage_shape;
266 return ptr_->aux_shapes[index];
272 <<
"aux_shapes() is not intended for kDefaultStorage.";
273 return ptr_->aux_shapes;
279 return ptr_->aux_types;
291 <<
"set_aux_shape() is not intended for kDefaultStorage.";
292 ptr_->set_aux_shape(index,
shape);
318 auto dptr =
static_cast<DType*
>(ptr_->aux_handles[i].dptr);
320 <<
"Unexpected storage type: " << stype;
321 res =
TBlob(dptr,
shape, ptr_->aux_handles[i].ctx.dev_mask(), type);
330 return ptr_->shandle.ctx;
340 return ptr_->aux_types[i];
344 return storage_type_;
348 return ptr_.get() ==
nullptr;
363 <<
"storage_initialized() is not intended for kDefaultStorage.";
366 <<
"inconsistent storage shape " <<
storage_shape() <<
" vs. aux shape "
371 <<
"inconsistent storage shape " <<
storage_shape() <<
" vs. aux shape "
375 LOG(FATAL) <<
"Unknown storage type";
384 return ptr_->shandle;
387 void AssignStorageInfo(
const std::string& profiler_scope,
const std::string& name);
589 <<
"NDArray.AsArray: target memory size is bigger";
601 <<
"AsArray is intended only for kDefaultStorage.";
603 <<
"NDArray.AsArray: target memory size is bigger than what was allocated.";
640 CHECK(shape_ == arr.shape_) <<
"ndarray shape is different from the target";
641 CHECK(dtype_ == arr.dtype_) <<
"ndarray dtype is different from the target";
644 <<
"Only to be used with CSR and RSP storage types";
647 arr.ptr_->shandle = ptr_->shandle;
648 ptr_->shandle = shandle_dst;
650 ptr_->storage_shape = arr.ptr_->storage_shape;
651 ptr_->storage_type = arr.ptr_->storage_type;
652 ptr_->ctx = arr.ptr_->ctx;
656 CHECK(ptr_->aux_handles.size() == arr.ptr_->aux_handles.size())
657 <<
"ndarray number of aux_handles is different from target";
658 for (
auto& aux_handle : arr.ptr_->aux_handles) {
660 ptr_->aux_handles[aux_idx] = aux_handle;
661 aux_handle = aux_dst;
664 ptr_->aux_types = arr.ptr_->aux_types;
665 ptr_->aux_shapes = arr.ptr_->aux_shapes;
698 ptr_->CheckAndAlloc();
723 <<
"CheckAndAlloc(aux_shapes) is not intended for kDefaultStorage";
724 ptr_->CheckAndAlloc(shape_,
aux_shapes, dtype_);
728 <<
"CheckAndAllocData is not intended for kDefaultStorage";
733 <<
"CheckAndAllocAuxData is not intended for kDefaultStorage";
734 ptr_->CheckAndAllocAuxData(i,
aux_shape);
737 #if MXNET_USE_ONEDNN == 1
742 explicit NDArray(
const std::shared_ptr<dnnl::memory>& dnnl_mem);
747 explicit NDArray(
const void* md);
751 bool IsDNNLData()
const {
752 return ptr_->IsDNNL();
757 bool IsDefaultData()
const {
758 return ptr_->IsDefault();
770 const dnnl::memory* GetDNNLData()
const;
775 const dnnl::memory* GetDNNLData(
const void* md)
const;
781 const dnnl::memory* GetDNNLDataReorder(
const void* md)
const;
786 void CopyFrom(
const dnnl::memory& mem);
791 dnnl::memory* CreateDNNLData(
const void* md);
798 void Reorder2DefaultAsync()
const;
799 void DNNLDataReorderAsync(
const void* md)
const;
805 NDArray Reorder2Default()
const;
811 NDArray Reorder2DefaultFloatFormat()
const;
813 void InvalidateDNNLData();
830 void UpdateDNNLMemDesc(
const void* desc);
840 const std::vector<NDArray>&
data,
841 const std::vector<std::string>& names);
864 std::vector<Storage::Handle> aux_handles;
866 #if MXNET_USE_ONEDNN == 1
869 std::shared_ptr<DNNLMemory> dnnl_mem_;
897 std::shared_ptr<Storage> storage_ref_;
899 std::weak_ptr<Engine> engine_ref_;
905 storage_ref_(
Storage::_GetSharedRef()),
906 engine_ref_(
Engine::_GetSharedRef()) {}
910 : static_data(false),
913 storage_ref_(
Storage::_GetSharedRef()),
914 engine_ref_(
Engine::_GetSharedRef()) {
926 Chunk(
const TBlob&
data,
int dev_id)
929 storage_ref_(Storage::_GetSharedRef()),
930 engine_ref_(Engine::_GetSharedRef()) {
947 : static_data(false),
949 storage_ref_(Storage::_GetSharedRef()),
950 engine_ref_(Engine::_GetSharedRef()) {
966 const std::vector<int>& aux_types_,
968 : static_data(false),
969 delay_alloc(delay_alloc_),
975 storage_ref_(Storage::_GetSharedRef()),
976 engine_ref_(Engine::_GetSharedRef()) {
980 for (
size_t i = 0; i <
aux_shapes.size(); i++) {
984 aux_handles[i].ctx =
ctx;
998 storage_ref_(Storage::_GetSharedRef()),
999 engine_ref_(Engine::_GetSharedRef()) {
1018 Storage::Handle aux_handle;
1019 aux_handle.ctx =
ctx;
1020 aux_handle.dptr = aux.dptr_;
1021 aux_handle.size = aux.shape_.Size() *
mshadow_sizeof(aux.type_flag_);
1022 aux_handles.push_back(aux_handle);
1044 #if MXNET_USE_ONEDNN == 1
1045 dnnl_mem_ =
nullptr;
1047 delay_alloc =
false;
1055 <<
"CheckAndAlloc(dbytes) is only intended for kDefaultStorage";
1056 dbytes = std::max(dbytes,
static_cast<uint64_t
>(shandle.
size));
1058 shandle.
size = dbytes;
1060 #if MXNET_USE_ONEDNN == 1
1061 dnnl_mem_ =
nullptr;
1063 delay_alloc =
false;
1064 }
else if (shandle.
size < dbytes) {
1068 shandle.
size = dbytes;
1070 #if MXNET_USE_ONEDNN == 1
1071 dnnl_mem_ =
nullptr;
1098 LOG(FATAL) <<
"Storage type " <<
storage_type <<
" not implemented for CheckAndAlloc";
1107 #if MXNET_USE_ONEDNN == 1
1113 void Reorder2Default();
1115 void DNNLDataReorder(
const void* md);
1116 bool IsDNNL()
const;
1117 bool IsDefault()
const;
1126 CHECK_EQ(
shape.
ndim(), 1) <<
"shape must be 1D in CheckAndAllocAuxData";
1128 <<
"storage type cannot be kUndefinedStorage in CheckAndAllocAuxData";
1130 <<
"storage type cannot be kDefaultStorage in CheckAndAllocAuxData";
1131 if (aux_handles.size() <= i) {
1132 aux_handles.resize(i + 1);
1135 if (aux_handles[i].size < aux_bytes) {
1154 storage_type_ = stype;
1160 void SetTBlob()
const;
1163 std::shared_ptr<Chunk> ptr_{
nullptr};
1170 size_t byte_offset_ = 0;
1174 bool reuse_ =
false;
1188 mutable TBlob tblob_;
1352 typedef std::function<void(
NDArray** used_vars,
1397 body = [fsetvalue](
NDArray** used_vars,
1402 char** param_vals) { (*fsetvalue)(s[0], mutate_vars[0]); };
1403 num_mutate_vars = 1;
1405 this->add_argument(
"src",
"real_t",
"Source input to the function.");
1416 body = [fternary](
NDArray** used_vars,
1421 char** param_vals) {
1422 (*fternary)(*used_vars[0], *used_vars[1], *used_vars[2], mutate_vars[0]);
1425 num_mutate_vars = 1;
1427 this->add_argument(
"lhs",
"NDArray",
"Left operand to the function.");
1428 this->add_argument(
"mhs",
"NDArray",
"Middle operand to the function.");
1429 this->add_argument(
"rhs",
"NDArray",
"Right operand to the function.");
1441 body = [fbinary](
NDArray** used_vars,
1446 char** param_vals) {
1447 (*fbinary)(*used_vars[0], *used_vars[1], mutate_vars[0]);
1450 num_mutate_vars = 1;
1452 this->add_argument(
"lhs",
"NDArray",
"Left operand to the function.");
1453 this->add_argument(
"rhs",
"NDArray",
"Right operand to the function.");
1465 body = [fscalar](
NDArray** used_vars,
1470 char** param_vals) { (*fscalar)(*used_vars[0], s[0], mutate_vars[0]); };
1472 num_mutate_vars = 1;
1475 this->add_argument(
"lhs",
"NDArray",
"Left operand to the function.");
1476 this->add_argument(
"rhs",
"real_t",
"Right operand to the function.");
1486 body = [funary](
NDArray** used_vars,
1491 char** param_vals) { (*funary)(*used_vars[0], mutate_vars[0]); };
1493 num_mutate_vars = 1;
1495 this->add_argument(
"src",
"NDArray",
"Source input to the function.");
1505 void (*fgeneric)(
NDArray** used_vars,
1508 const std::map<std::string, std::string>& param)) {
1509 body = [fgeneric](
NDArray** used_vars,
1514 char** param_vals) {
1515 std::map<std::string, std::string> param;
1516 for (
int i = 0; i < num_params; ++i) {
1517 param[param_keys[i]] = param_vals[i];
1519 fgeneric(used_vars, s, mutate_vars, param);
1538 num_mutate_vars = n;
1572 #define MXNET_REGISTER_NDARRAY_FUN(name) \
1573 DMLC_REGISTRY_REGISTER(::mxnet::NDArrayFunctionReg, NDArrayFunctionReg, name)
1581 #endif // MXNET_NDARRAY_H_
void AssignStorageInfo(const std::string &profiler_scope, const std::string &name)
assign profiler scope and name to the storage handles
namespace of mxnet
Definition: api_registry.h:33
void ReshapeAndAlloc(const mxnet::TShape &shape)
Allocate the space if the allocation has been delayed or the requested size is bigger than the availa...
Definition: ndarray.h:710
NDArrayFunctionReg & set_num_use_vars(unsigned n)
set the number of mutate variables
Definition: ndarray.h:1528
NDArray Detach() const
Return a copy of this NDArray without autograd and deferred compute history.
Definition: ndarray.h:684
@ kRSPShapeErr
Definition: ndarray.h:73
NDArray At(index_t idx) const
Index a NDArray.
const int default_type_flag
type enum value for default real type
Definition: base.h:492
NDArrayFunctionReg & set_type_mask(int tmask)
set type mask
Definition: ndarray.h:1555
void SampleGaussian(real_t mu, real_t sigma, NDArray *out)
Sample gaussian distribution for each elements of out.
size_t version() const
return var version of the NDArray
Definition: ndarray.h:419
NDArray operator*(const NDArray &lhs, const NDArray &rhs)
elementwise multiplication
Common base class for function registry.
Definition: registry.h:151
void InitAsArray(const NDArray &src, const mxnet::TShape &shape, int dtype)
Definition: ndarray.h:599
void SyncCopyToCPU(void *data, size_t size) const
Do a synchronize copy to a contiguous CPU memory region.
CSRAuxType
Definition: ndarray.h:54
@ kAcceptEmptyMutateTarget
whether this function allows the handles in the target to be empty NDArray that are not yet initializ...
Definition: ndarray.h:1373
ScalarExp< DType > scalar(DType s)
create an scalar expression
Definition: expression.h:103
void ElementwiseSum(const std::vector< NDArray > &source, NDArray *out, int priority=0)
Perform elementwise sum over each data from source, store result into out.
void * dptr
Pointer to the data.
Definition: storage.h:60
void CheckAndAllocData(const mxnet::TShape &storage_shape) const
Definition: ndarray.h:726
void SamplePoisson(real_t lambda, NDArray *out)
Sample Poisson distribution for each elements of out.
void set_aux_shape(size_t index, const mxnet::TShape &shape) const
For a sparse operation on a csr matrix for example, the size of the column index array is an estimate...
Definition: ndarray.h:289
virtual VarHandle NewVariable()=0
Allocate a new variable, the variable can then be used to schedule the operation concurrently via dep...
int dtype() const
Definition: ndarray.h:335
Registry entry for NDArrayFunction.
Definition: ndarray.h:1376
void WaitToRead() const
Block until all the pending write operations with respect to current NDArray are finished,...
NDArray(int shared_pid, int shared_id, const mxnet::TShape &shape, int dtype)
create ndarray from shared memory
Definition: ndarray.h:160
NDArray(const TBlob &data, int dev_id, const std::function< void()> &deleter)
constructing a static NDArray that shares data with TBlob which is with deleter Use with caution: all...
Definition: ndarray.h:148
namespace for dmlc
Definition: array_view.h:12
NDArray & operator*=(const NDArray &src)
elementwise multiplication to current ndarray this mutate the current NDArray
@ kNormalErr
Definition: ndarray.h:69
bool shape_is_known(const TShape &x)
Definition: tuple.h:699
NDArray Slice(index_t begin, index_t end) const
Slice a NDArray.
#define DMLC_DECLARE_TRAITS(Trait, Type, Value)
macro to quickly declare traits information
Definition: type_traits.h:126
NDArray & operator=(real_t scalar)
set all the elements in ndarray to be scalar
std::function< void(NDArray **used_vars, real_t *scalars, NDArray **mutate_vars, int num_params, char **param_keys, char **param_vals)> NDArrayAPIFunction
definition of NDArray function
Definition: ndarray.h:1358
@ kDefaultStorage
Definition: ndarray.h:63
@ kCSRIndPtrErr
Definition: ndarray.h:71
void ReInit()
Definition: ndarray.h:200
NDArray(const NDArrayStorageType stype, const mxnet::TShape &shape, Context ctx, bool delay_alloc=true, int dtype=mshadow::default_type_flag, const std::vector< int > &aux_types={}, const mxnet::ShapeVector &aux_shapes={}, const mxnet::TShape &storage_shape=mxnet::TShape(mshadow::Shape1(0)))
constructor for NDArray with storage type
Definition: ndarray.h:104
@ kUndefinedStorage
Definition: ndarray.h:62
NDArray(const TBlob &data, int dev_id)
constructing a static NDArray that shares data with TBlob Use with caution: allocate ONLY ONE NDArray...
Definition: ndarray.h:133
const TBlob & data() const
Definition: ndarray.h:298
@ kNDArrayArgBeforeScalar
all the use_vars should go before scalar
Definition: ndarray.h:1362
void SelfReorder2Default()
@ kScalarArgBeforeNDArray
all the scalar should go before use_vars
Definition: ndarray.h:1364
Storage::Handle storage_handle() const
get storage handle
Definition: ndarray.h:380
NDArray & operator-=(const NDArray &src)
elementwise subtract from current ndarray this mutate the current NDArray
NDArrayFunctionReg & set_function(void(*fgeneric)(NDArray **used_vars, real_t *s, NDArray **mutate_vars, const std::map< std::string, std::string > ¶m))
set the function body to a unary NDArray function this will also auto set the parameters correctly
Definition: ndarray.h:1504
void WaitToWrite() const
Block until all the pending read/write operations with respect to current NDArray are finished,...
bool IsSame(const NDArray &other) const
Definition: ndarray.h:236
defines configuration macros
void SyncCheckFormat(const bool full_check) const
check whether the NDArray format is valid
const mxnet::TShape & storage_shape() const
Definition: ndarray.h:252
@ kIndPtr
Definition: ndarray.h:54
NDArray data_ndarray() const
Generate a deep copy of data() returned as a default storage type NDArray.
void * dptr_
pointer to the data
Definition: tensor_blob.h:70
bool IsView() const
Definition: ndarray.h:224
NDArray AsArray(const mxnet::TShape &shape, int dtype) const
Create a NDArray that shares memory with current one The new array must have smaller memory size than...
Definition: ndarray.h:586
static const int kDevMask
device flag number, identifies this device
Definition: tensor.h:43
NDArrayFunctionReg()
constructor
Definition: ndarray.h:1389
static Context GPU(int32_t dev_id=-1)
NDArray ReshapeWithRecord(const mxnet::TShape &shape)
Get an reshaped NDArray. Supports autograd recording.
int ndim() const
Definition: tuple.h:217
NDArray(const NDArrayStorageType stype, const mxnet::TShape &shape, const TBlob &data, const std::vector< TBlob > &aux_data, int dev_id)
constructing a static NDArray of non-default storage that shares data with TBlob Use with caution: al...
Definition: ndarray.h:177
NDArray aux_ndarray(size_t i) const
Generate a deep copy of aux_data(i) returned as a default storage type NDArray.
C Tensor object, manage memory of DLTensor. This data structure is intended to facilitate the borrowi...
Definition: dlpack.h:157
size_t size
Size of the storage.
Definition: storage.h:64
NDArray operator+(const NDArray &lhs, const NDArray &rhs)
elementwise add
@ kIdx
Definition: ndarray.h:54
int aux_type(size_t i) const
Definition: ndarray.h:338
void CheckAndAlloc() const
Allocate the space if it is delayed allocated. This is an internal function used by system that norma...
Definition: ndarray.h:696
void SampleExponential(real_t lambda, NDArray *out)
Sample exponential distribution for each elements of out.
NDArrayFunctionReg & set_function(void(*funary)(const NDArray &src, NDArray *out))
set the function body to a unary NDArray function this will also auto set the parameters correctly
Definition: ndarray.h:1485
TBlob aux_data(size_t i) const
Definition: ndarray.h:312
int dev_mask() const
device mask of the corresponding device
Definition: tensor_blob.h:257
Symbol is help class used to represent the operator node in Graph.
Definition: symbolic.h:50
const mxnet::TShape & aux_shape(size_t index) const
get the shape of aux_data(index)
Definition: ndarray.h:264
@ kCSRIdxErr
Definition: ndarray.h:72
NDArrayStorageType
Definition: ndarray.h:61
NDArray(const mxnet::TShape &shape, Context ctx, bool delay_alloc=false, int dtype=mshadow::default_type_flag)
constructs a new dynamic NDArray
Definition: ndarray.h:93
const std::vector< int > & aux_types() const
Definition: ndarray.h:277
NDArray(Context ctx, int dtype=mshadow::default_type_flag)
constructs a new dynamic NDArray whose shape is unknown, hence the NDArray is inherently lazily creat...
Definition: ndarray.h:120
NDArrayFunctionReg & set_function(void(*fbinary)(const NDArray &lhs, const NDArray &rhs, NDArray *out))
set the function body to a binary NDArray function this will also auto set the parameters correctly
Definition: ndarray.h:1438
@ kCSRShapeErr
Definition: ndarray.h:70
static Context CPUShared(int32_t dev_id=0)
static NDArray FromDLPack(const DLManagedTensor *tensor, bool transient_handle)
Create a NDArray backed by a dlpack tensor.
int type_flag_
type flag of the tensor blob
Definition: tensor_blob.h:74
NDArrayFunctionReg & set_function(void(*fsetvalue)(const real_t &rhs, NDArray *out))
set the function body to a NDArray setvalue function this will also auto set the parameters correctly
Definition: ndarray.h:1396
@ kRSPIdxErr
Definition: ndarray.h:74
void Save(dmlc::Stream *strm) const
save the content into binary stream
bool is_none() const
Definition: ndarray.h:347
NDArray AtWithRecord(index_t idx)
Index a NDArray.
void set_fresh_out_grad(bool state) const
void SampleGenNegBinomial(real_t mu, real_t alpha, NDArray *out)
Sample generalized negative binomial distribution for each elements of out.
size_t byte_offset() const
Definition: ndarray.h:415
void StreamSync(int stream) const
Synchronize the destination stream provided by consumer with the source stream that current NDArray l...
unsigned num_use_vars
number of variable used by this function
Definition: ndarray.h:1379
Storage handle.
Definition: storage.h:56
ndarray interface
Definition: ndarray.h:82
void SyncCopyFromCPU(const void *data, size_t size) const
Do a synchronize copy from a contiguous CPU memory region.
Context ctx() const
Definition: ndarray.h:328
tensor blob class that can be used to hold tensor of any dimension, any device and any data type,...
Definition: tensor_blob.h:65
const mxnet::TShape & shape() const
Definition: ndarray.h:244
NDArray Copy(Context ctx) const
return a new copy this NDArray
nnvm::Symbol get_autograd_symbol() const
unsigned num_scalars
number of scalars used by this function
Definition: ndarray.h:1383
Dependency engine that schedules operations.
Definition: engine.h:213
NDArray Reshape(const mxnet::TShape &shape) const
Get an reshaped NDArray.
void InitDetached(const NDArray *src)
Definition: ndarray.h:196
void CheckAndAllocAuxData(size_t i, const mxnet::TShape &aux_shape) const
Definition: ndarray.h:731
int shared_pid
Id for IPC shared memory.
Definition: storage.h:72
defines serializable interface of dmlc
size_t mshadow_sizeof(int type)
get data type size from type enum
Definition: base.h:1804
const mxnet::ShapeVector & aux_shapes() const
Definition: ndarray.h:270
NDArrayFunctionTypeMask
mask information on how functions can be exposed
Definition: ndarray.h:1360
Context information about the execution environment.
Definition: base.h:90
runtime functions for NDArray
Definition: imperative.h:61
size_t Size() const
Definition: tuple.h:523
virtual void Free(Handle handle)=0
Free storage.
void SetShapeFromChunk() const
set the correct shape of NDArray directly from the storage_shape of its own chunk.
bool Load(dmlc::Stream *strm)
load the content from binary stream
overloaded + operator between half_t and bf16_t
Definition: base.h:319
Storage manager across multiple devices.
void RandomSeed(uint32_t seed)
Seed all random number generator in mxnet.
void SparseUpdateChunk(const NDArray &arr) const
Update ndarray chunk storage handles using existing ndarray storage handles Also update the aux_handl...
Definition: ndarray.h:639
void SampleUniform(real_t begin, real_t end, NDArray *out)
Sample uniform distribution for each elements of out.
base class of engine variables.
Definition: engine.h:111
Context ctx
Context information about device and ID.
Definition: storage.h:68
Engine::VarHandle var() const
Definition: ndarray.h:411
NDArray & operator/=(const NDArray &src)
elementwise division from current ndarray this mutate the current NDArray
NDArrayFormatErr
Definition: ndarray.h:68
mshadow::index_t index_t
index type usually use unsigned
Definition: base.h:81
@ kCSRStorage
Definition: ndarray.h:65
Definition: optional.h:251
DLManagedTensor * ToDLPack() const
Create a reference view of NDArray that represents as DLManagedTensor.
type traits information header
NDArrayFunctionReg & set_function(void(*fternary)(const NDArray &lhs, const NDArray &mhs, const NDArray &rhs, NDArray *out))
set the function body to a ternary NDArray function this will also auto set the parameters correctly
Definition: ndarray.h:1414
void Init(const mxnet::TShape &shape)
initialize the NDArray, assuming it is not assigned a meaningful shape before
Definition: ndarray.h:191
NDArrayFunctionReg & set_num_mutate_vars(unsigned n)
set the number of mutate variables
Definition: ndarray.h:1537
Handle Alloc(size_t size, Context ctx, bool failsafe=false)
Allocate a new contiguous memory for a given size.
Definition: storage.h:92
NDArray operator-(const NDArray &lhs, const NDArray &rhs)
elementwise subtraction
static Context CPU(int32_t dev_id=0)
size_t num_aux_data(NDArrayStorageType stype)
std::vector< mxnet::TShape > ShapeVector
The result holder of shape of each NodeEntry in the graph.
Definition: tuple.h:830
@ kIdx
Definition: ndarray.h:58
an entry that represents output data from a node
Definition: node.h:52
MSHADOW_XINLINE Shape< 1 > Shape1(index_t s0)
construct a one dimension shape, stride will equal s0
Definition: tensor.h:220
void SampleNegBinomial(int32_t k, real_t p, NDArray *out)
Sample negative binomial distribution for each elements of out.
mxnet::TShape shape_
shape of the tensor
Definition: tensor_blob.h:72
A Shape class that is used to represent shape of each tensor.
Definition: tuple.h:440
void SampleGamma(real_t alpha, real_t beta, NDArray *out)
Sample gamma distribution for each elements of out.
Engine that schedules all the operations according to dependency.
NDArray & operator+=(const NDArray &src)
elementwise add to current space this mutate the current NDArray
NDArrayFunctionReg & set_function(void(*fscalar)(const NDArray &lhs, const real_t &rhs, NDArray *out))
set the function body to a binary NDArray function this will also auto set the parameters correctly
Definition: ndarray.h:1462
Registry utility that helps to build registry singletons.
int shared_id
Definition: storage.h:73
Graph node data structure.
bool fresh_out_grad() const
RowSparseAuxType
Definition: ndarray.h:58
static const int kDevMask
device flag number, identifies this device
Definition: tensor.h:50
NDArray operator/(const NDArray &lhs, const NDArray &rhs)
elementwise division
NDArrayStorageType storage_type() const
Definition: ndarray.h:343
virtual size_t version()
Definition: engine.h:112
interface of stream I/O for serialization
Definition: io.h:30
@ kRowSparseStorage
Definition: ndarray.h:64
Storage manager across multiple devices.
Definition: storage.h:40
NDArrayFunctionReg & set_num_scalars(unsigned n)
set the number of scalar arguments
Definition: ndarray.h:1546
bool LegacyLoad(dmlc::Stream *strm, const uint32_t magic)
load ndarrays before supporting sparse ndarrays
void CopyFromTo(const NDArray &from, const NDArray *to, int priority=0)
issue an copy operation from one NDArray to another the two ndarray can sit on different devices this...
unsigned num_mutate_vars
number of variable mutated by this function
Definition: ndarray.h:1381
bool storage_initialized() const
Returns true if a sparse ndarray's aux_data and storage are initialized Throws an exception if the in...
Definition: ndarray.h:358
NDArray()
default constructor
Definition: ndarray.h:85
void SyncCopyFromNDArray(const NDArray &src, int i=-1, int j=-1)
Copy from src.data()/aux_data(i) to this->data()/aux_data(j)
mshadow::default_real_t real_t
data type that will be used to store ndarray
Definition: base.h:85
void CheckAndAlloc(const mxnet::ShapeVector &aux_shapes) const
Definition: ndarray.h:721
NDArray SliceWithRecord(index_t begin, index_t end)
Slice a NDArray. Supports recording with autograd.
int type_mask
information on how function should be called from API
Definition: ndarray.h:1385
#define MSHADOW_TYPE_SWITCH(type, DType,...)
Definition: base.h:1163