24 #ifndef MSHADOW_EXTENSION_CONCAT_H_ 25 #define MSHADOW_EXTENSION_CONCAT_H_ 27 #include "../extension.h" 39 template<
typename LhsExp,
typename RhsExp,
40 typename Device,
typename DType,
41 int srcdim,
int dimsrc_m_cat>
44 srcdim, dimsrc_m_cat>,
45 Device, srcdim, DType> {
46 static const int dimcat = srcdim - dimsrc_m_cat;
52 ConcatExp(
const LhsExp &src1,
const RhsExp &src2) : src1_(src1), src2_(src2) {
56 for (
int i = 0; i < srcdim; ++i) {
58 CHECK_EQ(sshape1[i], sshape2[i]) <<
"ConcatExp: shape mismatch";
61 this->shape_ = sshape1;
63 this->dcat_src1_ = sshape1[
dimcat];
64 this->dcat_src2_ = sshape2[
dimcat];
66 template<
typename E,
int etype>
86 template<
int cdim,
typename LhsExp,
typename RhsExp,
87 typename Device,
typename DType,
int srcdim>
88 inline ConcatExp<LhsExp, RhsExp, Device, DType, srcdim, srcdim - cdim>
92 ::Error_Expression_Does_Not_Meet_Dimension_Req();
94 ::Error_Expression_Does_Not_Meet_Dimension_Req();
95 return ConcatExp<LhsExp, RhsExp, Device, DType, srcdim, srcdim - cdim>
102 template<
typename LhsExp,
typename RhsExp,
103 typename Device,
typename DType,
104 int srcdim,
int dimsrc_m_cat>
107 Device, DType, srcdim, dimsrc_m_cat> &t) {
111 template<
typename LhsExp,
typename RhsExp,
112 typename Device,
typename DType,
113 int srcdim,
int dimsrc_m_cat>
119 if (lhs != rhs)
return NULL;
124 template<
typename LhsExp,
typename RhsExp,
125 typename Device,
typename DType,
126 int srcdim,
int dimsrc_m_cat>
131 static const int kDim = (kDimLhs >= 0 && kDimRhs >= 0) ?\
134 ((kDimRhs == 0 || kDimLhs == kDimRhs) ? kDimLhs : -1)) : -1;
140 template<
typename LhsExp,
typename RhsExp,
141 typename Device,
typename DType,
142 int srcdim,
int dimsrc_m_cat>
143 struct Plan<
ConcatExp<LhsExp, RhsExp, Device, DType, srcdim, dimsrc_m_cat>, DType> {
145 static const int dimcat = srcdim - dimsrc_m_cat;
148 height_(e.
shape_.ProdShape(dimcat + 1, srcdim - 1)),
157 return src1_.Eval((b * ch_src1_ + c) * height_ + y, x);
159 return src2_.Eval((b * ch_src2_ + c - ch_src1_) * height_ + y, x);
169 return src1_.REval((b * ch_src1_ + c) * height_ + y, x);
171 return src2_.REval((b * ch_src2_ + c - ch_src1_) * height_ + y, x);
178 const index_t height_, ch_src1_, ch_src2_, ch_;
182 template<
typename LhsExp,
typename RhsExp,
183 typename Device,
typename DType,
191 if (x < width_src1_) {
192 return src1_.Eval(y, x);
194 return src2_.Eval(y, x - width_src1_);
198 if (x < width_src1_) {
199 return src1_.REval(y, x);
201 return src2_.REval(y, x - width_src1_);
212 #endif // MSHADOW_EXTENSION_CONCAT_H_ static Stream< Device > * Get(const ConcatExp< LhsExp, RhsExp, Device, DType, srcdim, dimsrc_m_cat > &t)
Definition: concat.h:116
index_t dcat_src2_
Definition: concat.h:50
Tensor RValue, this is the super type of all kinds of possible tensors.
Definition: tensor.h:409
const Container & self(void) const
Definition: expression.h:82
Definition: expr_engine-inl.h:58
used to help static type check
Definition: expr_engine-inl.h:330
static const int dimcat
Definition: concat.h:46
ConcatExp(const LhsExp &src1, const RhsExp &src2)
Definition: concat.h:52
void operator=(const expr::Exp< E, DType, etype > &exp)
Definition: concat.h:68
const LhsExp & src1_
Definition: concat.h:47
index_t dcat_src1_
Definition: concat.h:49
static Shape< dim > Check(const E &t)
#define MSHADOW_XINLINE
Definition: base.h:230
static type inference template, used to get the dimension of each expression, if ExpInfo<E>::kDim == ...
Definition: expr_engine-inl.h:262
Definition: expr_engine-inl.h:345
int32_t index_t
type that will be used for index
Definition: base.h:343
Plan(const ConcatExp< LhsExp, RhsExp, Device, DType, srcdim, dimsrc_m_cat > &e)
Definition: concat.h:146
MSHADOW_XINLINE DType Eval(index_t i, index_t j) const
Definition: concat.h:150
Plan(const ConcatExp< LhsExp, RhsExp, Device, DType, srcdim, 1 > &e)
Definition: concat.h:187
const RhsExp & src2_
Definition: concat.h:48
index_t shape_[kDimension]
storing the dimension information
Definition: tensor.h:75
runtime shape checking template get the shape of an expression, report error if shape mismatch ...
Definition: expr_engine-inl.h:364
MSHADOW_XINLINE DType & REval(index_t i, index_t j)
Definition: concat.h:162
MSHADOW_XINLINE DType Eval(index_t y, index_t x) const
Definition: concat.h:190
static Stream< Device > * Get(const E &t)
Shape< 4 > shape_
Definition: concat.h:51
void operator=(const DType &exp)
Definition: concat.h:72
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:89
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:79
Plan< BinaryMapExp< OP, TA, TB, DType, etype >, DType > MakePlan(const BinaryMapExp< OP, TA, TB, DType, etype > &e)
Definition: expr_engine-inl.h:239
overloaded + operator between half_t and bf16_t
Definition: base.h:334
concat expression, concat two tensor's channel
Definition: concat.h:42
ConcatExp< LhsExp, RhsExp, Device, DType, srcdim, dimsrc_m_cat > & __assign(DType s)
operator overload
Definition: expression.h:178
MSHADOW_XINLINE DType & REval(index_t y, index_t x)
Definition: concat.h:197
static Shape< srcdim > Check(const ConcatExp< LhsExp, RhsExp, Device, DType, srcdim, dimsrc_m_cat > &t)
Definition: concat.h:106
computaion stream structure, used for asynchronous computations
Definition: tensor.h:383