24 #ifndef MSHADOW_EXTENSION_SLICE_H_ 25 #define MSHADOW_EXTENSION_SLICE_H_ 27 #include "../extension.h" 38 template<
typename SrcExp,
39 typename Device,
typename DType,
40 int srcdim,
int dimsrc_m_slice>
43 srcdim, dimsrc_m_slice>,
44 Device, srcdim, DType> {
45 static const int dimslice = srcdim - dimsrc_m_slice;
51 : src_(src), ch_begin_(begin) {
54 CHECK(begin <= shape_[dimslice] && end <= shape_[dimslice])
55 <<
"The slice went out of range. ";
58 template<
typename E,
int etype>
80 template<
int sdim,
typename SrcExp,
81 typename Device,
typename DType,
int srcdim>
82 inline SliceExp<SrcExp, Device, DType, srcdim, srcdim - sdim>
85 ::Error_Expression_Does_Not_Meet_Dimension_Req();
86 return SliceExp<SrcExp, Device, DType, srcdim, srcdim - sdim>(src.
self(), begin, end);
92 template<
typename SrcExp,
93 typename Device,
typename DType,
94 int srcdim,
int dimsrc_m_slice>
97 Device, DType, srcdim, dimsrc_m_slice> &t) {
101 template<
typename SrcExp,
102 typename Device,
typename DType,
103 int srcdim,
int dimsrc_m_slice>
111 template<
typename SrcExp,
112 typename Device,
typename DType,
113 int srcdim,
int dimsrc_m_slice>
121 template<
typename SrcExp,
122 typename Device,
typename DType,
123 int srcdim,
int dimsrc_m_slice>
124 struct Plan<
SliceExp<SrcExp, Device, DType, srcdim, dimsrc_m_slice>, DType> {
126 static const int dimslice = srcdim - dimsrc_m_slice;
129 height_(e.
shape_.ProdShape(dimslice + 1, srcdim - 1)),
137 return src_.Eval((b *
ch_old_ + c) * height_ + y, x);
145 return src_.REval((b *
ch_old_ + c) * height_ + y, x);
153 template<
typename SrcExp,
154 typename Device,
typename DType,
174 #endif // MSHADOW_EXTENSION_SLICE_H_ MSHADOW_XINLINE DType Eval(index_t i, index_t j) const
Definition: slice.h:131
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 dimslice
Definition: slice.h:45
void operator=(const expr::Exp< E, DType, etype > &exp)
Definition: slice.h:60
Plan(const SliceExp< SrcExp, Device, DType, srcdim, dimsrc_m_slice > &e)
Definition: slice.h:127
static Shape< dim > Check(const E &t)
index_t ch_old_
Definition: slice.h:48
MSHADOW_XINLINE DType & REval(index_t y, index_t x)
Definition: slice.h:164
#define MSHADOW_XINLINE
Definition: base.h:230
SliceExp< SrcExp, Device, DType, srcdim, srcdim - sdim > slice(const TRValue< SrcExp, Device, srcdim, DType > &src, index_t begin, index_t end)
Slice a Tensor.
Definition: slice.h:83
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
static Shape< srcdim > Check(const SliceExp< SrcExp, Device, DType, srcdim, dimsrc_m_slice > &t)
Definition: slice.h:96
int32_t index_t
type that will be used for index
Definition: base.h:343
void operator=(const DType &exp)
Definition: slice.h:64
const SrcExp & src_
Definition: slice.h:46
Plan(const SliceExp< SrcExp, Device, DType, srcdim, 1 > &e)
Definition: slice.h:158
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
Shape< srcdim > shape_
Definition: slice.h:49
static Stream< Device > * Get(const E &t)
MSHADOW_XINLINE DType & REval(index_t i, index_t j)
Definition: slice.h:139
MSHADOW_XINLINE DType Eval(index_t y, index_t x) const
Definition: slice.h:161
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:79
SliceExp(const SrcExp &src, index_t begin, index_t end)
Definition: slice.h:50
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
index_t ch_begin_
Definition: slice.h:47
slice expression, slice a tensor's channel
Definition: slice.h:41
SliceExp< SrcExp, Device, DType, srcdim, dimsrc_m_slice > & __assign(DType s)
operator overload
Definition: expression.h:178
static Stream< Device > * Get(const SliceExp< SrcExp, Device, DType, srcdim, dimsrc_m_slice > &t)
Definition: slice.h:106
computaion stream structure, used for asynchronous computations
Definition: tensor.h:383