25 #ifndef MSHADOW_EXTENSION_CONCAT_H_ 26 #define MSHADOW_EXTENSION_CONCAT_H_ 28 #include "../extension.h" 40 template<
typename LhsExp,
typename RhsExp,
41 typename Device,
typename DType,
42 int srcdim,
int dimsrc_m_cat>
45 srcdim, dimsrc_m_cat>,
46 Device, srcdim, DType> {
47 static const int dimcat = srcdim - dimsrc_m_cat;
53 ConcatExp(
const LhsExp &src1,
const RhsExp &src2) : src1_(src1), src2_(src2) {
57 for (
int i = 0; i < srcdim; ++i) {
59 CHECK_EQ(sshape1[i], sshape2[i]) <<
"ConcatExp: shape mismatch";
62 this->shape_ = sshape1;
64 this->dcat_src1_ = sshape1[
dimcat];
65 this->dcat_src2_ = sshape2[
dimcat];
67 template<
typename E,
int etype>
87 template<
int cdim,
typename LhsExp,
typename RhsExp,
88 typename Device,
typename DType,
int srcdim>
89 inline ConcatExp<LhsExp, RhsExp, Device, DType, srcdim, srcdim - cdim>
93 ::Error_Expression_Does_Not_Meet_Dimension_Req();
95 ::Error_Expression_Does_Not_Meet_Dimension_Req();
96 return ConcatExp<LhsExp, RhsExp, Device, DType, srcdim, srcdim - cdim>
103 template<
typename LhsExp,
typename RhsExp,
104 typename Device,
typename DType,
105 int srcdim,
int dimsrc_m_cat>
108 Device, DType, srcdim, dimsrc_m_cat> &t) {
112 template<
typename LhsExp,
typename RhsExp,
113 typename Device,
typename DType,
114 int srcdim,
int dimsrc_m_cat>
120 if (lhs != rhs)
return NULL;
125 template<
typename LhsExp,
typename RhsExp,
126 typename Device,
typename DType,
127 int srcdim,
int dimsrc_m_cat>
132 static const int kDim = (kDimLhs >= 0 && kDimRhs >= 0) ?\
135 ((kDimRhs == 0 || kDimLhs == kDimRhs) ? kDimLhs : -1)) : -1;
141 template<
typename LhsExp,
typename RhsExp,
142 typename Device,
typename DType,
143 int srcdim,
int dimsrc_m_cat>
144 struct Plan<
ConcatExp<LhsExp, RhsExp, Device, DType, srcdim, dimsrc_m_cat>, DType> {
146 static const int dimcat = srcdim - dimsrc_m_cat;
149 height_(e.
shape_.ProdShape(dimcat + 1, srcdim - 1)),
158 return src1_.Eval((b * ch_src1_ + c) * height_ + y, x);
160 return src2_.Eval((b * ch_src2_ + c - ch_src1_) * height_ + y, x);
170 return src1_.REval((b * ch_src1_ + c) * height_ + y, x);
172 return src2_.REval((b * ch_src2_ + c - ch_src1_) * height_ + y, x);
179 const index_t height_, ch_src1_, ch_src2_, ch_;
183 template<
typename LhsExp,
typename RhsExp,
184 typename Device,
typename DType,
192 if (x < width_src1_) {
193 return src1_.Eval(y, x);
195 return src2_.Eval(y, x - width_src1_);
199 if (x < width_src1_) {
200 return src1_.REval(y, x);
202 return src2_.REval(y, x - width_src1_);
213 #endif // MSHADOW_EXTENSION_CONCAT_H_ static Stream< Device > * Get(const ConcatExp< LhsExp, RhsExp, Device, DType, srcdim, dimsrc_m_cat > &t)
Definition: concat.h:117
index_t dcat_src2_
Definition: concat.h:51
MSHADOW_XINLINE DType Eval(index_t y, index_t x) const
Definition: concat.h:191
Tensor RValue, this is the super type of all kinds of possible tensors.
Definition: tensor.h:410
Definition: expr_engine-inl.h:59
used to help static type check
Definition: expr_engine-inl.h:331
static const int dimcat
Definition: concat.h:47
ConcatExp(const LhsExp &src1, const RhsExp &src2)
Definition: concat.h:53
MSHADOW_XINLINE DType Eval(index_t i, index_t j) const
Definition: concat.h:151
void operator=(const expr::Exp< E, DType, etype > &exp)
Definition: concat.h:69
const LhsExp & src1_
Definition: concat.h:48
index_t dcat_src1_
Definition: concat.h:50
static Shape< dim > Check(const E &t)
#define MSHADOW_XINLINE
Definition: base.h:223
static type inference template, used to get the dimension of each expression, if ExpInfo<E>::kDim == ...
Definition: expr_engine-inl.h:263
Definition: expr_engine-inl.h:346
int32_t index_t
type that will be used for index
Definition: base.h:336
Plan(const ConcatExp< LhsExp, RhsExp, Device, DType, srcdim, dimsrc_m_cat > &e)
Definition: concat.h:147
Plan(const ConcatExp< LhsExp, RhsExp, Device, DType, srcdim, 1 > &e)
Definition: concat.h:188
const RhsExp & src2_
Definition: concat.h:49
index_t shape_[kDimension]
storing the dimension information
Definition: tensor.h:76
runtime shape checking template get the shape of an expression, report error if shape mismatch ...
Definition: expr_engine-inl.h:365
MSHADOW_XINLINE DType & REval(index_t i, index_t j)
Definition: concat.h:163
static Stream< Device > * Get(const E &t)
Shape< 4 > shape_
Definition: concat.h:52
void operator=(const DType &exp)
Definition: concat.h:73
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:90
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:80
const Container & self(void) const
Definition: expression.h:83
Plan< BinaryMapExp< OP, TA, TB, DType, etype >, DType > MakePlan(const BinaryMapExp< OP, TA, TB, DType, etype > &e)
Definition: expr_engine-inl.h:240
overloaded + operator between half_t and bf16_t
Definition: base.h:327
concat expression, concat two tensor's channel
Definition: concat.h:43
ConcatExp< LhsExp, RhsExp, Device, DType, srcdim, dimsrc_m_cat > & __assign(DType s)
operator overload
Definition: expression.h:179
MSHADOW_XINLINE DType & REval(index_t y, index_t x)
Definition: concat.h:198
static Shape< srcdim > Check(const ConcatExp< LhsExp, RhsExp, Device, DType, srcdim, dimsrc_m_cat > &t)
Definition: concat.h:107
computaion stream structure, used for asynchronous computations
Definition: tensor.h:384