pengxin99 commented on a change in pull request #15400: Add a new arange_like
operator to contrib
URL: https://github.com/apache/incubator-mxnet/pull/15400#discussion_r298581025
##########
File path: src/operator/tensor/init_op.h
##########
@@ -519,6 +552,50 @@ inline bool RangeShape(const nnvm::NodeAttrs& attrs,
return true;
}
+template<typename xpu>
+void RangeLikeCompute(const nnvm::NodeAttrs& attrs,
+ const OpContext& ctx,
+ const std::vector<TBlob>& inputs,
+ const std::vector<OpReqType>& req,
+ const std::vector<TBlob>& outputs) {
+ using namespace mxnet_op;
+ Stream<xpu> *s = ctx.get_stream<xpu>();
+ const RangeLikeParam& param = nnvm::get<RangeLikeParam>(attrs.parsed);
+ MSHADOW_TYPE_SWITCH(outputs[0].type_flag_, DType, {
+ // Force unsigned params to take two's complement form on ARM to ensure
consistency with x86
+ // results. Casting negative floats to unsigned types is undefined in
the CPP standard.
+ auto step = std::is_signed<DType>() ? param.step :
static_cast<index_t>(param.step);
+ auto start = std::is_signed<DType>() ? param.start :
static_cast<index_t>(param.start);
Review comment:
Does these mean we force cast `step `and `start `to type int when the DType
is not signed, and how about float step like 0.1? think the `numpy.arange()`
has float step
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services