mxnet
tuple.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
23 #ifndef MXNET_TUPLE_H_
24 #define MXNET_TUPLE_H_
25 
26 #include <vector>
27 #include <type_traits>
28 #include <algorithm>
29 #include <utility>
30 #include <iostream>
31 #include <string>
32 #include "nnvm/op_attr_types.h"
33 #include "nnvm/graph_attr_types.h"
34 #include "nnvm/graph.h"
35 #include "nnvm/pass.h"
36 #include "runtime/object.h"
37 #include "runtime/ffi_helper.h"
38 #include "node/container.h"
39 #include "ir/expr.h"
40 
41 namespace mxnet {
42 
56 template <typename ValueType>
57 class Tuple {
58  public:
60  Tuple() = default;
62  inline ~Tuple() {
63  delete[] data_heap_;
64  }
70  inline Tuple(const int ndim, const dim_t value) { // NOLINT(*)
71  this->SetDim(ndim);
72  if (ndim > 0) {
73  std::fill_n(begin(), ndim, value);
74  }
75  }
80  inline Tuple(const Tuple<ValueType>& s) {
81  if (s.ndim() == -1) {
82  this->SetDim(-1);
83  } else {
84  this->assign(s.begin(), s.end());
85  }
86  }
91  inline Tuple(std::initializer_list<ValueType> init) {
92  this->assign(init.begin(), init.end());
93  }
98  inline Tuple(std::vector<ValueType> init) { // NOLINT(runtime/explicit)
99  this->assign(init.begin(), init.end());
100  }
106  inline Tuple(Tuple<ValueType>&& src) { // NOLINT(runtime/explicit)
107  this->swap(src);
108  }
115  template <typename RandomAccessIterator>
116  inline Tuple(RandomAccessIterator begin, RandomAccessIterator end) {
117  this->assign(begin, end);
118  }
119 
120  inline explicit Tuple(const runtime::ObjectRef& src) {
121  using namespace runtime;
122  ADT adt = Downcast<ADT, ObjectRef>(src);
123  this->SetDim(adt.size());
124  for (int i = 0; i < ndim_; ++i) {
125  this->begin()[i] = Downcast<Integer, ObjectRef>(adt[i])->value;
126  }
127  }
128 
135  template <typename RandomAccessIterator>
136  inline void assign(RandomAccessIterator begin, RandomAccessIterator end) {
137  this->SetDim(end - begin);
138  CHECK_GE(ndim(), 0);
139  std::copy(begin, end, this->begin());
140  }
145  inline void swap(Tuple<ValueType>& other) { // NOLINT(*)
146  std::swap(ndim_, other.ndim_);
147  std::swap(num_heap_allocated_, other.num_heap_allocated_);
148  std::swap(data_stack_, other.data_stack_);
149  std::swap(data_heap_, other.data_heap_);
150  }
157  if (src.ndim() == -1) {
158  this->SetDim(-1);
159  } else {
160  this->assign(src.begin(), src.end());
161  }
162  return *this;
163  }
170  Tuple<ValueType>(std::move(src)).swap(*this);
171  return *this;
172  }
178  inline Tuple<ValueType>& operator=(std::initializer_list<ValueType> init) {
179  this->assign(init.begin(), init.end());
180  return *this;
181  }
186  inline bool operator==(const Tuple<ValueType>& s) const {
187  if (ndim_ != s.ndim_)
188  return false;
189  if (ndim() == -1)
190  return true;
191  return std::equal(begin(), end(), s.begin());
192  }
197  inline bool operator!=(const Tuple<ValueType>& s) const {
198  return !(*this == s);
199  }
201  inline const ValueType* begin() const {
202  return ndim_ <= kStackCache ? data_stack_ : data_heap_;
203  }
205  inline ValueType* begin() {
206  return ndim_ <= kStackCache ? data_stack_ : data_heap_;
207  }
209  inline const ValueType* end() const {
210  return ndim_ <= kStackCache ? (data_stack_ + ndim_) : (data_heap_ + ndim_);
211  }
213  inline ValueType* end() {
214  return ndim_ <= kStackCache ? (data_stack_ + ndim_) : (data_heap_ + ndim_);
215  }
217  inline int ndim() const {
218  return ndim_;
219  }
225  inline ValueType& operator[](int i) {
226 // it fixes the false alarm of assuming signed overflow does not occur
227 // when assuming that (X - c) > X is always false [-Werror=strict-overflow]
228 #pragma GCC diagnostic push
229 #pragma GCC diagnostic ignored "-Wstrict-overflow"
230  CHECK(i >= 0 && i < ndim()) << "index = " << i << " must be in range [0, " << ndim() << ")";
231 #pragma GCC diagnostic pop
232  return begin()[i];
233  }
239  inline const ValueType& operator[](int i) const {
240 // it fixes the false alarm of assuming signed overflow does not occur
241 // when assuming that (X - c) > X is always false [-Werror=strict-overflow]
242 #pragma GCC diagnostic push
243 #pragma GCC diagnostic ignored "-Wstrict-overflow"
244  CHECK(i >= 0 && i < ndim()) << "index = " << i << " must be in range [0, " << ndim() << ")";
245 #pragma GCC diagnostic pop
246  return begin()[i];
247  }
252  inline void Save(dmlc::JSONWriter* writer) const {
253  std::vector<ValueType> tmp(begin(), end());
254  writer->Write(tmp);
255  }
260  inline void Load(dmlc::JSONReader* reader) {
261  std::vector<ValueType> tmp;
262  reader->Read(&tmp);
263  this->assign(tmp.begin(), tmp.end());
264  }
271  friend std::ostream& operator<<(std::ostream& os, const Tuple<ValueType>& t) {
272  if (t.ndim() == -1) {
273  // If t is an unknown shape, return string "None".
274  // This is consistent with returning unknown shape in Python and generating
275  // C++ operator APIs by OpWrapperGenerator.py (defaultString) in cpp-package.
276  os << "None";
277  return os;
278  }
279  os << '[';
280  const ValueType* begin = t.begin();
281  const ValueType* end = t.end();
282  for (const ValueType* it = begin; it != end; ++it) {
283  if (it != begin)
284  os << ',';
285  os << *it;
286  }
287  os << ']';
288  return os;
289  }
296  friend std::istream& operator>>(std::istream& is, Tuple<ValueType>& t) {
297  // get (
298  while (true) {
299  char ch = is.peek();
300  if (isdigit(ch) || ch == '-') {
301  ValueType idx;
302  if (is >> idx) {
303  t.assign(&idx, &idx + 1);
304  }
305  return is;
306  }
307  is.get();
308  if (ch == '(' || ch == '[')
309  break;
310  if (!isspace(ch)) {
311  if (ch == 'N') {
312  std::string tmp_val;
313  is >> tmp_val;
314  if (tmp_val == "one") { // is stores "None"
315  t.SetDim(-1);
316  return is;
317  }
318  }
319  is.setstate(std::ios::failbit);
320  return is;
321  }
322  }
323  // Handle empty tuple. A tensor whose shape is an empty tuple
324  // represents a scalar with ndim = 0.
325  while (isspace(is.peek())) {
326  is.get();
327  }
328  if (is.peek() == ')' || is.peek() == ']') {
329  is.get();
330  t.SetDim(0);
331  return is;
332  }
333  // Handle non-empty tuple
334  ValueType idx;
335  std::vector<ValueType> tmp;
336  while (is >> idx) {
337  tmp.push_back(idx);
338  char ch;
339  do {
340  ch = is.get();
341  } while (isspace(ch));
342  if (std::is_integral<ValueType>::value && ch == 'L') {
343  ch = is.get();
344  }
345  if (ch == ',') {
346  while (true) {
347  ch = is.peek();
348  if (isspace(ch)) {
349  is.get();
350  continue;
351  }
352  if (ch == ')' || ch == ']') {
353  is.get();
354  break;
355  }
356  break;
357  }
358  if (ch == ')' || ch == ']')
359  break;
360  } else if (ch == ')' || ch == ']') {
361  break;
362  } else {
363  is.setstate(std::ios::failbit);
364  return is;
365  }
366  }
367  t.assign(tmp.begin(), tmp.end());
368  return is;
369  }
376  template <typename DType = ValueType, typename TStream>
377  inline void Save(TStream* strm) const;
385  template <typename DType = ValueType, typename TStream>
386  inline bool Load(TStream* strm);
387 
388  protected:
389  // stack cache size
390  static const int kStackCache = 8;
392  int ndim_{0};
398  ValueType* data_heap_{nullptr};
399  // internal function to change the dimension
400  inline void SetDim(int ndim) {
401  CHECK_GE(ndim, -1) << "ndim cannot be less than -1, received " << ndim;
403  delete[] data_heap_;
404  data_heap_ = new ValueType[ndim];
406  } else if (ndim <= 0 && data_heap_ != nullptr) {
407  delete[] data_heap_;
408  data_heap_ = nullptr;
410  }
411  ndim_ = ndim;
412  }
413 };
414 
416 inline bool ndim_is_known(const int ndim) {
417  CHECK_GE(ndim, -1) << "shape ndim must be >= -1, while received " << ndim;
418  return ndim != -1;
419 }
420 
422 inline bool dim_size_is_known(const dim_t dim_size) {
423  CHECK_GE(dim_size, -1) << "shape dim size must be >= -1, while received " << dim_size;
424  return dim_size != -1;
425 }
426 
440 class TShape : public Tuple<dim_t> {
441  public:
443  TShape() {
444  this->SetDim(-1);
445  }
451  inline TShape(const int ndim, const dim_t value) { // NOLINT(*)
452  this->SetDim(ndim);
453  if (ndim > 0) {
454  std::fill_n(begin(), ndim, value);
455  }
456  }
461  inline TShape(const Tuple<dim_t>& s) { // NOLINT(*)
462  if (s.ndim() == -1) {
463  this->SetDim(-1);
464  } else {
465  this->assign(s.begin(), s.end());
466  }
467  }
472  inline TShape(std::initializer_list<dim_t> init) {
473  this->assign(init.begin(), init.end());
474  }
479  inline TShape(Tuple<dim_t>&& s) { // NOLINT(*)
480  this->swap(s);
481  }
490  template <typename RandomAccessIterator,
491  typename std::enable_if<
492  std::is_same<typename std::iterator_traits<RandomAccessIterator>::iterator_category,
493  std::random_access_iterator_tag>::value,
494  int>::type = 0>
495  inline TShape(RandomAccessIterator begin, RandomAccessIterator end) {
496  this->assign(begin, end);
497  }
498 
499  inline explicit TShape(const ObjectRef& src) : Tuple(src) {}
505  inline TShape& operator=(const Tuple<dim_t>& src) {
506  if (src.ndim() == -1) {
507  this->SetDim(-1);
508  } else {
509  this->assign(src.begin(), src.end());
510  }
511  return *this;
512  }
518  inline TShape& operator=(Tuple<dim_t>&& src) { // NOLINT(*)
519  TShape(std::move(src)).swap(*this); // NOLINT(*)
520  return *this;
521  }
523  inline size_t Size() const {
524  CHECK(ndim_is_known(this->ndim())) << "Shape is unknown.";
525  dim_t size = 1;
526  const dim_t *start = begin(), *fin = end();
527  for (const dim_t* it = start; it != fin; ++it) {
528  CHECK(dim_size_is_known(*it)) << "Shape dim size cannot be a negative value " << *it;
529  size *= *it;
530  }
531  return size;
532  }
538  inline size_t ProdShape(int dimstart, int dimend) const {
539  CHECK(ndim_is_known(this->ndim())) << "Shape is unknown.";
540  CHECK_GE(dimstart, 0) << "dimstart must be >= 0, while received " << dimstart;
541  CHECK_LE(dimend, this->ndim())
542  << "dimend must be <= " << this->ndim() << ", while received " << dimend;
543  dim_t num = 1;
544  const dim_t* d = this->data();
545  for (int i = dimstart; i < dimend; ++i) {
546  CHECK(dim_size_is_known(d[i])) << "Shape dim size must be known, while received " << d[i];
547  num *= d[i];
548  }
549  return num;
550  }
552  inline const dim_t* data() const {
553  return begin();
554  }
556  inline dim_t* data() {
557  return begin();
558  }
559 #ifdef MSHADOW_XINLINE
560  template <int dim>
561  inline TShape(const mshadow::Shape<dim>& s) { // NOLINT(*)
562  this->assign(s.shape_, s.shape_ + dim);
563  }
564 
565  template <int dim>
566  inline TShape(mshadow::Shape<dim>&& s) { // NOLINT(*)
567  this->assign(s.shape_, s.shape_ + dim);
568  }
575  template <int dim>
576  inline TShape& operator=(const mshadow::Shape<dim>& shape) {
577  this->assign(shape.shape_, shape.shape_ + dim);
578  return *this;
579  }
585  template <int dim>
586  inline mshadow::Shape<dim> get() const {
587  CHECK_EQ(dim, ndim()) << "dimension do not match target dimension " << dim << " vs " << ndim();
588  const dim_t* d = this->data();
590  for (int i = 0; i < dim; ++i) {
591  s[i] = d[i];
592  }
593  return s;
594  }
599  inline mshadow::Shape<2> FlatTo2D(void) const {
601  CHECK(ndim_is_known(ndim())) << "shape must have a valid ndim";
602  if (ndim() == 0)
603  return mshadow::Shape2(1, 1);
604  const dim_t* d = this->data();
605  s.shape_[1] = d[ndim() - 1];
606  dim_t ymax = 1;
607  for (int i = 1; i < ndim(); ++i) {
608  ymax *= d[i - 1];
609  }
610  s.shape_[0] = ymax;
611  return s;
612  }
619  inline mshadow::Shape<3> FlatTo3D(int axis_begin, int axis_end) const {
620  CHECK(axis_end >= axis_begin);
622  CHECK(ndim_is_known(ndim())) << "shape must have a valid ndim";
623  if (ndim() == 0)
624  return mshadow::Shape3(1, 1, 1);
625  const dim_t* d = this->data();
626  s.shape_[0] = 1;
627  s.shape_[1] = 1;
628  s.shape_[2] = 1;
629 
630  for (int i = 0; i < axis_begin; ++i) {
631  s.shape_[0] *= d[i];
632  }
633  for (int i = axis_begin; i <= axis_end; ++i) {
634  s.shape_[1] *= d[i];
635  }
636  for (int i = axis_end + 1; i < ndim(); ++i) {
637  s.shape_[2] *= d[i];
638  }
639  return s;
640  }
646  inline mshadow::Shape<3> FlatTo3D(int axis) const {
647  return FlatTo3D(axis, axis);
648  }
649  inline bool operator==(const TShape& s) const {
650  if (ndim() != s.ndim())
651  return false;
652  return std::equal(begin(), end(), s.begin());
653  }
654  inline bool operator!=(const TShape& s) const {
655  return !(*this == s);
656  }
662  template <int dim>
663  inline bool operator==(const mshadow::Shape<dim>& s) const {
664  if (ndim_ != dim)
665  return false;
666  const dim_t* d = dim <= kStackCache ? data_stack_ : data_heap_;
667  for (size_t i = 0; i < dim; ++i) {
668  if (d[i] != s.shape_[i])
669  return false;
670  }
671  return true;
672  }
678  template <int dim>
679  inline bool operator!=(const mshadow::Shape<dim>& s) const {
680  return !(*this == s);
681  }
682 #endif
683 };
684 
686 inline bool ndim_is_known(const TShape& x) {
687  return ndim_is_known(x.ndim());
688 }
689 
691 inline bool dim_size_is_known(const TShape& x, const int idx) {
692  CHECK(idx >= 0 && idx < x.ndim())
693  << "idx = " << idx << " exceeds shape dimension range [0, " << x.ndim() << ")";
694  return dim_size_is_known(x[idx]);
695 }
696 
699 inline bool shape_is_known(const TShape& x) {
700  if (!ndim_is_known(x))
701  return false;
702  for (int i = 0; i < x.ndim(); ++i) {
703  if (!dim_size_is_known(x, i))
704  return false;
705  }
706  return true;
707 }
708 
709 inline bool shape_is_known(const std::vector<TShape>& shapes) {
710  for (const TShape& shape : shapes) {
711  if (!shape_is_known(shape))
712  return false;
713  }
714  return true;
715 }
716 
718 template <typename SrcIter, typename DstIter>
719 inline DstIter ShapeTypeCast(const SrcIter begin, const SrcIter end, DstIter dst_begin) {
720  typedef typename std::iterator_traits<SrcIter>::value_type SrcDType;
721  typedef typename std::iterator_traits<DstIter>::value_type DstDType;
722  auto cast = [](const SrcDType& dim) { return static_cast<DstDType>(dim); };
723  return std::transform(begin, end, dst_begin, cast);
724 }
725 
727 template <typename SrcIter>
728 inline TShape ShapeTypeCast(const SrcIter begin, const SrcIter end) {
729  size_t ndim = std::distance(begin, end);
730  TShape res(ndim, -1);
731  ShapeTypeCast(begin, end, res.begin());
732  return res;
733 }
734 
736 template <typename ValueType>
737 template <typename DType, typename TStream>
738 inline void Tuple<ValueType>::Save(TStream* strm) const {
739  strm->Write(&ndim_, sizeof(ndim_));
740  if (typeid(DType) == typeid(ValueType)) {
741  strm->Write(begin(), sizeof(ValueType) * ndim_);
742  } else {
743  std::vector<DType> buffer(ndim_);
744  ShapeTypeCast(begin(), end(), buffer.data());
745  strm->Write(buffer.data(), sizeof(DType) * ndim_);
746  }
747 }
748 
750 template <typename ValueType>
751 template <typename DType, typename TStream>
752 inline bool Tuple<ValueType>::Load(TStream* strm) {
753  if (strm->Read(&ndim_, sizeof(ndim_)) != sizeof(ndim_))
754  return false;
755  this->SetDim(ndim_);
756  size_t nread = sizeof(DType) * ndim_;
757  if (typeid(DType) == typeid(ValueType)) {
758  if (strm->Read(begin(), nread) != nread)
759  return false;
760  } else {
761  std::vector<DType> buffer(ndim_);
762  if (strm->Read(buffer.data(), nread) != nread)
763  return false;
764  ShapeTypeCast(buffer.begin(), buffer.end(), begin());
765  }
766  return true;
767 }
768 
769 } // namespace mxnet
770 
771 namespace std {
773 template <typename T>
774 struct hash<mxnet::Tuple<T>> {
776  size_t operator()(const mxnet::Tuple<T>& val) const {
777  std::hash<int> hash_int;
778  size_t res = hash_int(val.ndim());
779  for (int i = 0; i < val.ndim(); ++i) {
780  res = dmlc::HashCombine(res, val[i]);
781  }
782  return res;
783  }
784 };
785 
787 template <>
788 struct hash<mxnet::TShape> {
790  size_t operator()(const mxnet::TShape& val) const {
791  std::hash<int> hash_int;
792  size_t res = hash_int(val.ndim());
793  for (int i = 0; i < val.ndim(); ++i) {
794  res = dmlc::HashCombine(res, val[i]);
795  }
796  return res;
797  }
798 };
799 } // namespace std
800 
801 namespace dmlc {
803 DMLC_DECLARE_TYPE_NAME(optional<mxnet::TShape>, "Shape or None");
804 DMLC_DECLARE_TYPE_NAME(optional<mxnet::Tuple<int>>, "Shape or None");
805 // avoid low version of MSVC
806 #if !(defined(_MSC_VER) && _MSC_VER < 1900)
807 template <typename T>
808 struct type_name_helper<mxnet::Tuple<T>> {
809  static inline std::string value() {
810  return "tuple of <" + type_name<T>() + ">";
811  }
812 };
813 #endif
814 } // namespace dmlc
815 
816 namespace mxnet {
830 using ShapeVector = std::vector<mxnet::TShape>;
831 
843 
844 } // namespace mxnet
845 
846 #endif // MXNET_TUPLE_H_
mxnet::Tuple::begin
const ValueType * begin() const
Definition: tuple.h:201
mxnet
namespace of mxnet
Definition: api_registry.h:33
mxnet::ndim_is_known
bool ndim_is_known(const int ndim)
Definition: tuple.h:416
dmlc::JSONReader::Read
void Read(ValueType *out_value)
Read next ValueType.
mxnet::Tuple::kStackCache
static const int kStackCache
Definition: tuple.h:390
mxnet::TShape::operator=
TShape & operator=(const Tuple< dim_t > &src)
assignment function from tshape
Definition: tuple.h:505
dmlc::type_name_helper
helper class to construct a string that represents type name
Definition: type_traits.h:86
mxnet::Tuple::ndim_
int ndim_
number of dimension of the tuple
Definition: tuple.h:392
mxnet::Tuple::end
const ValueType * end() const
Definition: tuple.h:209
mxnet::Tuple
A dynamic sized array data structure that is optimized for storing small number of elements with same...
Definition: tuple.h:57
op_attr_types.h
Data structures that can appear in operator attributes.
mxnet::TShape::TShape
TShape(const ObjectRef &src)
Definition: tuple.h:499
mxnet::TShape::operator=
TShape & operator=(Tuple< dim_t > &&src)
move assignment function from tshape
Definition: tuple.h:518
mxnet::Tuple::Tuple
Tuple(const Tuple< ValueType > &s)
copy constructor from another tuple
Definition: tuple.h:80
dmlc::JSONWriter::Write
void Write(const ValueType &value)
Write value to json.
ffi_helper.h
dmlc::isspace
bool isspace(char c)
Inline implementation of isspace(). Tests whether the given character is a whitespace letter.
Definition: strtonum.h:26
dmlc
namespace for dmlc
Definition: array_view.h:12
mxnet::Tuple::Tuple
Tuple(Tuple< ValueType > &&src)
move constructor from Tuple
Definition: tuple.h:106
mxnet::shape_is_known
bool shape_is_known(const TShape &x)
Definition: tuple.h:699
mxnet::Tuple::operator=
Tuple< ValueType > & operator=(Tuple< ValueType > &&src)
assignment from rvalue of another tuple.
Definition: tuple.h:169
mxnet::TShape::TShape
TShape(std::initializer_list< dim_t > init)
constructor from initializer list
Definition: tuple.h:472
mxnet::Tuple::operator=
Tuple< ValueType > & operator=(const Tuple< ValueType > &src)
assignment from another tuple.
Definition: tuple.h:156
mxnet::Tuple::Load
void Load(dmlc::JSONReader *reader)
Load Tuple from JSON.
Definition: tuple.h:260
dmlc::type_name_helper< mxnet::Tuple< T > >::value
static std::string value()
Definition: tuple.h:809
DMLC_DECLARE_TYPE_NAME
#define DMLC_DECLARE_TYPE_NAME(Type, Name)
macro to quickly declare traits information
Definition: type_traits.h:133
dmlc::isdigit
bool isdigit(char c)
Inline implementation of isdigit(). Tests whether the given character is a decimal digit.
Definition: strtonum.h:46
mxnet::Tuple::Tuple
Tuple(std::initializer_list< ValueType > init)
constructor from initializer list
Definition: tuple.h:91
mxnet::TShape::TShape
TShape(RandomAccessIterator begin, RandomAccessIterator end)
construct the Tuple from content of iterator. This function is enforced with template arguments of ra...
Definition: tuple.h:495
mxnet::Tuple::ndim
int ndim() const
Definition: tuple.h:217
mxnet::TShape::TShape
TShape(Tuple< dim_t > &&s)
move constructor.
Definition: tuple.h:479
mxnet::Tuple::data_stack_
ValueType data_stack_[kStackCache]
in stack space used to store shape when it is small
Definition: tuple.h:396
mxnet::Tuple::operator==
bool operator==(const Tuple< ValueType > &s) const
Definition: tuple.h:186
expr.h
Base expr nodes in MXNet.
mxnet::Tuple::Tuple
Tuple(const runtime::ObjectRef &src)
Definition: tuple.h:120
mxnet::FInferShape
nnvm::FInferNodeEntryAttr< mxnet::TShape > FInferShape
Shape inference function. Update the shapes given the input shape information. TShape....
Definition: tuple.h:842
dmlc::HashCombine
size_t HashCombine(size_t key, const T &value)
hash an object and combines the key with previous keys
Definition: common.h:37
mxnet::Tuple::end
ValueType * end()
Definition: tuple.h:213
graph_attr_types.h
Data structures that can appear in graph attributes.
dim_t
int64_t dim_t
data type to store dim size
Definition: c_api.h:69
mshadow::Shape::shape_
index_t shape_[kDimension]
storing the dimension information
Definition: tensor.h:86
mxnet::Tuple::Tuple
Tuple(std::vector< ValueType > init)
constructor from vector
Definition: tuple.h:98
std::hash< mxnet::Tuple< T > >::operator()
size_t operator()(const mxnet::Tuple< T > &val) const
hash a Tuple into unsigned int
Definition: tuple.h:776
mxnet::TShape::TShape
TShape()
default constructor
Definition: tuple.h:443
mxnet::Tuple::num_heap_allocated_
int num_heap_allocated_
number of cells allocated in data_heap_
Definition: tuple.h:394
mxnet::TShape::TShape
TShape(const int ndim, const dim_t value)
Definition: tuple.h:451
mxnet::Tuple::operator<<
friend std::ostream & operator<<(std::ostream &os, const Tuple< ValueType > &t)
allow output string of tuple to ostream
Definition: tuple.h:271
mxnet::TShape::ProdShape
size_t ProdShape(int dimstart, int dimend) const
Definition: tuple.h:538
mxnet::TShape::data
dim_t * data()
Definition: tuple.h:556
nnvm::dim_t
int64_t dim_t
data type to store dim size
Definition: tuple.h:39
mxnet::Tuple::Tuple
Tuple()=default
default constructor
mxnet::TShape::TShape
TShape(const Tuple< dim_t > &s)
copy constructor of TShape
Definition: tuple.h:461
dmlc::JSONWriter
Lightweight json to write any STL compositions.
Definition: json.h:190
mxnet::Tuple::Tuple
Tuple(RandomAccessIterator begin, RandomAccessIterator end)
construct the Tuple from content of iterator
Definition: tuple.h:116
mxnet::Tuple::begin
ValueType * begin()
Definition: tuple.h:205
mxnet::TShape::Size
size_t Size() const
Definition: tuple.h:523
mxnet::TShape::data
const dim_t * data() const
Definition: tuple.h:552
mxnet::Tuple::operator!=
bool operator!=(const Tuple< ValueType > &s) const
Definition: tuple.h:197
graph.h
Configuation of nnvm as well as basic data structure.
mxnet::dim_size_is_known
bool dim_size_is_known(const dim_t dim_size)
Definition: tuple.h:422
mshadow::Shape2
MSHADOW_XINLINE Shape< 2 > Shape2(index_t s0, index_t s1)
construct a two dimension shape, stride will equal s0
Definition: tensor.h:230
mxnet::Tuple::operator>>
friend std::istream & operator>>(std::istream &is, Tuple< ValueType > &t)
read tuple from the istream
Definition: tuple.h:296
mxnet::runtime::ObjectRef
Base class of all object reference.
Definition: object.h:500
std
Definition: optional.h:251
mshadow::Shape< dim >
mxnet::ShapeVector
std::vector< mxnet::TShape > ShapeVector
The result holder of shape of each NodeEntry in the graph.
Definition: tuple.h:830
mxnet::Tuple::operator=
Tuple< ValueType > & operator=(std::initializer_list< ValueType > init)
assignment from initializer list
Definition: tuple.h:178
std::hash< mxnet::TShape >::operator()
size_t operator()(const mxnet::TShape &val) const
hash a TShape into unsigned int
Definition: tuple.h:790
mxnet::Tuple::Tuple
Tuple(const int ndim, const dim_t value)
Definition: tuple.h:70
mxnet::TShape
A Shape class that is used to represent shape of each tensor.
Definition: tuple.h:440
mxnet::ShapeTypeCast
DstIter ShapeTypeCast(const SrcIter begin, const SrcIter end, DstIter dst_begin)
helper function to cast type of container elements
Definition: tuple.h:719
mxnet::Tuple::Save
void Save(dmlc::JSONWriter *writer) const
Save Tuple to JSON.
Definition: tuple.h:252
mxnet::Tuple::assign
void assign(RandomAccessIterator begin, RandomAccessIterator end)
Assign content to tuple from iterator.
Definition: tuple.h:136
mxnet::Tuple::operator[]
const ValueType & operator[](int i) const
get corresponding index
Definition: tuple.h:239
mxnet::Tuple::operator[]
ValueType & operator[](int i)
get corresponding index
Definition: tuple.h:225
dmlc::JSONReader
Lightweight JSON Reader to read any STL compositions and structs. The user need to know the schema of...
Definition: json.h:44
nnvm::FInferNodeEntryAttr
std::function< bool(const NodeAttrs &attrs, std::vector< AttrType > *in_attrs, std::vector< AttrType > *out_attrs)> FInferNodeEntryAttr
Inference function of certain type.
Definition: op_attr_types.h:94
mxnet::Tuple::data_heap_
ValueType * data_heap_
space to store shape when dimension is big
Definition: tuple.h:398
mxnet::Tuple::~Tuple
~Tuple()
destructor
Definition: tuple.h:62
mxnet::Tuple::swap
void swap(Tuple< ValueType > &other)
Swap current object with other.
Definition: tuple.h:145
mshadow::Shape3
MSHADOW_XINLINE Shape< 3 > Shape3(index_t s0, index_t s1, index_t s2)
construct a three dimension shape, stride will equal s0
Definition: tensor.h:241
object.h
A managed object in MXNet runtime.
container.h
Array container.
pass.h
Pass that can be applied to a graph.
mxnet::Tuple::SetDim
void SetDim(int ndim)
Definition: tuple.h:400