Go to the documentation of this file.
25 #ifndef MSHADOW_EXTENSION_RANGE_H_
26 #define MSHADOW_EXTENSION_RANGE_H_
28 #include "../extension.h"
41 template<
typename DType>
43 public Exp<RangeExp<DType>, DType, type::kMapper> {
49 RangeExp(DType start, DType stop, DType step,
int repeat)
53 template<
typename DType>
54 inline RangeExp<DType>
55 range(DType start, DType stop, DType step = 1,
int repeat = 1) {
62 template<
typename DType>
72 return start_ +
static_cast<DType
>((
static_cast<int>(x) / repeat_)) * step_;
82 template<
typename DType>
83 inline Plan<RangeExp<DType>, DType>
89 template<
typename DType>
90 inline int RangeOutSize(DType start, DType stop, DType step,
int repeat) {
91 return repeat * ((stop - start - 1) / step + 1);
96 double d_start =
static_cast<double>(start);
97 double d_stop =
static_cast<double>(stop);
98 double d_step =
static_cast<double>(step);
99 return repeat *
static_cast<int>(ceil((d_stop - d_start) / d_step));
104 return repeat *
static_cast<int>(ceil((stop - start) / step));
108 template<
int dim,
typename DType>
113 <<
"RangeExp only support 1 dimension output, received " << dim;
115 <<
"RangeExp does not support step=0, received " << t.
step_;
117 <<
"RangeExp only supports repeat > 0, received " << t.
repeat_;
119 CHECK(t.
start_ < t.
stop_) <<
"RangeExp does not support (start, stop, step) = "
122 CHECK(t.
start_ > t.
stop_) <<
"RangeExp does not support (start, stop, step)= "
129 template<
typename DType>
136 #endif // MSHADOW_EXTENSION_RANGE_H_
static const int kDevMask
Definition: expr_engine-inl.h:264
int RangeOutSize< float >(float start, float stop, float step, int repeat)
Definition: range.h:95
int RangeOutSize(DType start, DType stop, DType step, int repeat)
Definition: range.h:90
MSHADOW_XINLINE DType Eval(index_t y, index_t x) const
Definition: range.h:71
#define MSHADOW_XINLINE
Definition: base.h:228
const DType start_
Definition: range.h:44
runtime shape checking template get the shape of an expression, report error if shape mismatch
Definition: expr_engine-inl.h:364
int RangeOutSize< double >(double start, double stop, double step, int repeat)
Definition: range.h:103
static type inference template, used to get the dimension of each expression, if ExpInfo<E>::kDim == ...
Definition: expr_engine-inl.h:262
static Shape< dim > Check(const RangeExp< DType > &t)
Definition: range.h:111
Plan< BinaryMapExp< OP, TA, TB, DType, etype >, DType > MakePlan(const BinaryMapExp< OP, TA, TB, DType, etype > &e)
Definition: expr_engine-inl.h:239
const DType step_
Definition: range.h:46
const int repeat_
Definition: range.h:47
const DType stop_
Definition: range.h:45
static const int kDim
Definition: expr_engine-inl.h:263
int32_t index_t
type that will be used for index
Definition: base.h:328
Definition: expr_engine-inl.h:58
defines how expression exp can be evaluated and stored into dst
Definition: expression.h:79
overloaded + operator between half_t and bf16_t
Definition: base.h:319
Generate a range vector similar to python: range(start, stop[, step][, repeat]). If step is positive,...
Definition: range.h:42
Plan(const RangeExp< DType > &e)
Definition: range.h:65
MSHADOW_XINLINE Shape< 1 > Shape1(index_t s0)
construct a one dimension shape, stride will equal s0
Definition: tensor.h:220
RangeExp(DType start, DType stop, DType step, int repeat)
constructor
Definition: range.h:49
RangeExp< DType > range(DType start, DType stop, DType step=1, int repeat=1)
Definition: range.h:55