mxnet
plain-inl.h
Go to the documentation of this file.
1 
6 #ifndef MSHADOW_PACKET_PLAIN_INL_H_
7 #define MSHADOW_PACKET_PLAIN_INL_H_
8 
9 #include "../base.h"
10 #include "../packet-inl.h"
11 
12 namespace mshadow {
13 namespace packet {
14 template<typename DType>
15 struct Packet<DType, kPlain> {
16  public:
18  static constexpr index_t size = 1;
20  DType data_;
21  // enable default copy constructor
22  Packet(void) {}
23  // constructor from the intrinsic type
24  explicit Packet(DType data) : data_(data) {}
25  // create a fill with the target value s
27  return Packet<DType, kPlain>(s);
28  }
29  // load from address
30  MSHADOW_CINLINE static Packet<DType, kPlain> Load(const DType* src) {
31  return Packet<DType, kPlain>(*src);
32  }
33  // load from address
35  return Packet<DType, kPlain>(*src);
36  }
37  // fill it with value s
39  data_ = s;
40  return *this;
41  }
42  // store data into dst
43  MSHADOW_CINLINE void Store(DType* dst) const {
44  *dst = data_;
45  }
46  // get the sum of all contents
47  MSHADOW_CINLINE DType Sum() const {
48  return data_;
49  }
50 };
51 
52 template<typename DType>
54  const Packet<DType, kPlain>& rhs) {
55  return Packet<DType, kPlain>(lhs.data_ + rhs.data_);
56 }
57 
58 template<typename DType>
60  const Packet<DType, kPlain>& rhs) {
61  return Packet<DType, kPlain>(lhs.data_ - rhs.data_);
62 }
63 template<typename DType>
65  const Packet<DType, kPlain>& rhs) {
66  return Packet<DType, kPlain>(lhs.data_ * rhs.data_);
67 }
68 
69 template<typename DType>
71  const Packet<DType, kPlain>& rhs) {
72  return Packet<DType, kPlain>(lhs.data_ / rhs.data_);
73 }
74 } // namespace packet
75 } // namespace mshadow
76 #endif // MSHADOW_PACKET_PLAIN_INL_H_
static MSHADOW_CINLINE Packet< DType, kPlain > Fill(DType s)
Definition: plain-inl.h:26
Packet(DType data)
Definition: plain-inl.h:24
MSHADOW_CINLINE Packet< DType, kPlain > & operator=(DType s)
Definition: plain-inl.h:38
MSHADOW_CINLINE Packet< DType, kPlain > operator-(const Packet< DType, kPlain > &lhs, const Packet< DType, kPlain > &rhs)
Definition: plain-inl.h:59
static MSHADOW_CINLINE Packet< DType, kPlain > LoadUnAligned(const DType *src)
Definition: plain-inl.h:34
MSHADOW_CINLINE DType Sum() const
Definition: plain-inl.h:47
MSHADOW_CINLINE void Store(DType *dst) const
Definition: plain-inl.h:43
Definition: packet-inl.h:24
MSHADOW_CINLINE Packet< DType, kPlain > operator/(const Packet< DType, kPlain > &lhs, const Packet< DType, kPlain > &rhs)
Definition: plain-inl.h:70
int32_t index_t
type that will be used for index
Definition: base.h:291
static MSHADOW_CINLINE Packet< DType, kPlain > Load(const DType *src)
Definition: plain-inl.h:30
MSHADOW_CINLINE Packet< DType, kPlain > operator*(const Packet< DType, kPlain > &lhs, const Packet< DType, kPlain > &rhs)
Definition: plain-inl.h:64
Packet(void)
Definition: plain-inl.h:22
DType data_
The internal data.
Definition: plain-inl.h:20
MSHADOW_CINLINE Packet< DType, kPlain > operator+(const Packet< DType, kPlain > &lhs, const Packet< DType, kPlain > &rhs)
Definition: plain-inl.h:53
#define MSHADOW_CINLINE
cpu force inline
Definition: base.h:207
namespace for mshadow
Definition: base.h:282
Generic packet type.
Definition: packet-inl.h:41