25 #ifndef MSHADOW_EXTENSION_SLICE_H_ 26 #define MSHADOW_EXTENSION_SLICE_H_ 28 #include "../extension.h" 39 template<
typename SrcExp,
40 typename Device,
typename DType,
41 int srcdim,
int dimsrc_m_slice>
44 srcdim, dimsrc_m_slice>,
45 Device, srcdim, DType> {
46 static const int dimslice = srcdim - dimsrc_m_slice;
52 : src_(src), ch_begin_(begin) {
55 CHECK(begin <= shape_[dimslice] && end <= shape_[dimslice])
56 <<
"The slice went out of range. ";
59 template<
typename E,
int etype>
81 template<
int sdim,
typename SrcExp,
82 typename Device,
typename DType,
int srcdim>
83 inline SliceExp<SrcExp, Device, DType, srcdim, srcdim - sdim>
86 ::Error_Expression_Does_Not_Meet_Dimension_Req();
87 return SliceExp<SrcExp, Device, DType, srcdim, srcdim - sdim>(src.
self(), begin, end);
93 template<
typename SrcExp,
94 typename Device,
typename DType,
95 int srcdim,
int dimsrc_m_slice>
98 Device, DType, srcdim, dimsrc_m_slice> &t) {
102 template<
typename SrcExp,
103 typename Device,
typename DType,
104 int srcdim,
int dimsrc_m_slice>
112 template<
typename SrcExp,
113 typename Device,
typename DType,
114 int srcdim,
int dimsrc_m_slice>
122 template<
typename SrcExp,
123 typename Device,
typename DType,
124 int srcdim,
int dimsrc_m_slice>
125 struct Plan<
SliceExp<SrcExp, Device, DType, srcdim, dimsrc_m_slice>, DType> {
127 static const int dimslice = srcdim - dimsrc_m_slice;
130 height_(e.
shape_.ProdShape(dimslice + 1, srcdim - 1)),
138 return src_.Eval((b *
ch_old_ + c) * height_ + y, x);
146 return src_.REval((b *
ch_old_ + c) * height_ + y, x);
154 template<
typename SrcExp,
155 typename Device,
typename DType,
175 #endif // MSHADOW_EXTENSION_SLICE_H_ 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 dimslice
Definition: slice.h:46
void operator=(const expr::Exp< E, DType, etype > &exp)
Definition: slice.h:61
Plan(const SliceExp< SrcExp, Device, DType, srcdim, dimsrc_m_slice > &e)
Definition: slice.h:128
MSHADOW_XINLINE DType Eval(index_t i, index_t j) const
Definition: slice.h:132
static Shape< dim > Check(const E &t)
index_t ch_old_
Definition: slice.h:49
MSHADOW_XINLINE DType & REval(index_t y, index_t x)
Definition: slice.h:165
#define MSHADOW_XINLINE
Definition: base.h:223
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:84
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
static Shape< srcdim > Check(const SliceExp< SrcExp, Device, DType, srcdim, dimsrc_m_slice > &t)
Definition: slice.h:97
int32_t index_t
type that will be used for index
Definition: base.h:336
void operator=(const DType &exp)
Definition: slice.h:65
const SrcExp & src_
Definition: slice.h:47
Plan(const SliceExp< SrcExp, Device, DType, srcdim, 1 > &e)
Definition: slice.h:159
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
Shape< srcdim > shape_
Definition: slice.h:50
static Stream< Device > * Get(const E &t)
MSHADOW_XINLINE DType & REval(index_t i, index_t j)
Definition: slice.h:140
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:80
MSHADOW_XINLINE DType Eval(index_t y, index_t x) const
Definition: slice.h:162
SliceExp(const SrcExp &src, index_t begin, index_t end)
Definition: slice.h:51
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
index_t ch_begin_
Definition: slice.h:48
slice expression, slice a tensor's channel
Definition: slice.h:42
SliceExp< SrcExp, Device, DType, srcdim, dimsrc_m_slice > & __assign(DType s)
operator overload
Definition: expression.h:179
static Stream< Device > * Get(const SliceExp< SrcExp, Device, DType, srcdim, dimsrc_m_slice > &t)
Definition: slice.h:107
computaion stream structure, used for asynchronous computations
Definition: tensor.h:384