6 #ifndef MSHADOW_EXTENSION_CONCAT_H_ 7 #define MSHADOW_EXTENSION_CONCAT_H_ 9 #include "../extension.h" 21 template<
typename LhsExp,
typename RhsExp,
22 typename Device,
typename DType,
23 int srcdim,
int dimsrc_m_cat>
26 srcdim, dimsrc_m_cat>,
27 Device, srcdim, DType> {
28 static const int dimcat = srcdim - dimsrc_m_cat;
34 ConcatExp(
const LhsExp &src1,
const RhsExp &src2) : src1_(src1), src2_(src2) {
38 for (
int i = 0; i < srcdim; ++i) {
40 CHECK_EQ(sshape1[i], sshape2[i]) <<
"ConcatExp: shape mismatch";
43 this->shape_ = sshape1;
45 this->dcat_src1_ = sshape1[
dimcat];
46 this->dcat_src2_ = sshape2[
dimcat];
48 template<
typename E,
int etype>
68 template<
int cdim,
typename LhsExp,
typename RhsExp,
69 typename Device,
typename DType,
int srcdim>
70 inline ConcatExp<LhsExp, RhsExp, Device, DType, srcdim, srcdim - cdim>
74 ::Error_Expression_Does_Not_Meet_Dimension_Req();
76 ::Error_Expression_Does_Not_Meet_Dimension_Req();
77 return ConcatExp<LhsExp, RhsExp, Device, DType, srcdim, srcdim - cdim>
84 template<
typename LhsExp,
typename RhsExp,
85 typename Device,
typename DType,
86 int srcdim,
int dimsrc_m_cat>
89 Device, DType, srcdim, dimsrc_m_cat> &t) {
93 template<
typename LhsExp,
typename RhsExp,
94 typename Device,
typename DType,
95 int srcdim,
int dimsrc_m_cat>
101 if (lhs != rhs)
return NULL;
106 template<
typename LhsExp,
typename RhsExp,
107 typename Device,
typename DType,
108 int srcdim,
int dimsrc_m_cat>
113 static const int kDim = (kDimLhs >= 0 && kDimRhs >= 0) ?\
116 ((kDimRhs == 0 || kDimLhs == kDimRhs) ? kDimLhs : -1)) : -1;
122 template<
typename LhsExp,
typename RhsExp,
123 typename Device,
typename DType,
124 int srcdim,
int dimsrc_m_cat>
125 struct Plan<
ConcatExp<LhsExp, RhsExp, Device, DType, srcdim, dimsrc_m_cat>, DType> {
127 static const int dimcat = srcdim - dimsrc_m_cat;
130 height_(e.
shape_.ProdShape(dimcat + 1, srcdim - 1)),
139 return src1_.Eval((b * ch_src1_ + c) * height_ + y, x);
141 return src2_.Eval((b * ch_src2_ + c - ch_src1_) * height_ + y, x);
151 return src1_.REval((b * ch_src1_ + c) * height_ + y, x);
153 return src2_.REval((b * ch_src2_ + c - ch_src1_) * height_ + y, x);
160 const index_t height_, ch_src1_, ch_src2_, ch_;
164 template<
typename LhsExp,
typename RhsExp,
165 typename Device,
typename DType,
173 if (x < width_src1_) {
174 return src1_.Eval(y, x);
176 return src2_.Eval(y, x - width_src1_);
180 if (x < width_src1_) {
181 return src1_.REval(y, x);
183 return src2_.REval(y, x - width_src1_);
194 #endif // MSHADOW_EXTENSION_CONCAT_H_ static Stream< Device > * Get(const ConcatExp< LhsExp, RhsExp, Device, DType, srcdim, dimsrc_m_cat > &t)
Definition: concat.h:98
index_t dcat_src2_
Definition: concat.h:32
MSHADOW_XINLINE DType Eval(index_t y, index_t x) const
Definition: concat.h:172
Tensor RValue, this is the super type of all kinds of possible tensors.
Definition: tensor.h:391
Definition: expr_engine-inl.h:40
used to help static type check
Definition: expr_engine-inl.h:312
static const int dimcat
Definition: concat.h:28
ConcatExp(const LhsExp &src1, const RhsExp &src2)
Definition: concat.h:34
MSHADOW_XINLINE DType Eval(index_t i, index_t j) const
Definition: concat.h:132
void operator=(const expr::Exp< E, DType, etype > &exp)
Definition: concat.h:50
const LhsExp & src1_
Definition: concat.h:29
index_t dcat_src1_
Definition: concat.h:31
static Shape< dim > Check(const E &t)
#define MSHADOW_XINLINE
Definition: base.h:204
static type inference template, used to get the dimension of each expression, if ExpInfo<E>::kDim == ...
Definition: expr_engine-inl.h:244
Definition: expr_engine-inl.h:327
int32_t index_t
type that will be used for index
Definition: base.h:291
Plan(const ConcatExp< LhsExp, RhsExp, Device, DType, srcdim, dimsrc_m_cat > &e)
Definition: concat.h:128
Plan(const ConcatExp< LhsExp, RhsExp, Device, DType, srcdim, 1 > &e)
Definition: concat.h:169
const RhsExp & src2_
Definition: concat.h:30
index_t shape_[kDimension]
storing the dimension information
Definition: tensor.h:57
runtime shape checking template get the shape of an expression, report error if shape mismatch ...
Definition: expr_engine-inl.h:346
MSHADOW_XINLINE DType & REval(index_t i, index_t j)
Definition: concat.h:144
static Stream< Device > * Get(const E &t)
Shape< 4 > shape_
Definition: concat.h:33
void operator=(const DType &exp)
Definition: concat.h:54
ConcatExp< LhsExp, RhsExp, Device, DType, srcdim, srcdim-cdim > concat(const TRValue< LhsExp, Device, srcdim, DType > &src1, const TRValue< RhsExp, Device, srcdim, DType > &src2)
concat two 4D tensor
Definition: concat.h:71
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:61
const Container & self(void) const
Definition: expression.h:64
Plan< BinaryMapExp< OP, TA, TB, DType, etype >, DType > MakePlan(const BinaryMapExp< OP, TA, TB, DType, etype > &e)
Definition: expr_engine-inl.h:221
namespace for mshadow
Definition: base.h:282
concat expression, concat two tensor's channel
Definition: concat.h:24
ConcatExp< LhsExp, RhsExp, Device, DType, srcdim, dimsrc_m_cat > & __assign(DType s)
operator overload
Definition: expression.h:160
MSHADOW_XINLINE DType & REval(index_t y, index_t x)
Definition: concat.h:179
static Shape< srcdim > Check(const ConcatExp< LhsExp, RhsExp, Device, DType, srcdim, dimsrc_m_cat > &t)
Definition: concat.h:88
computaion stream structure, used for asynchronous computations
Definition: tensor.h:365