-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Add a new arange_like operator to contrib #15400
Conversation
…to arange-like Conflicts: src/operator/tensor/init_op.cc src/operator/tensor/init_op.h
@pengzhao-intel @pengxin99 please help to review. Thanks. |
src/operator/tensor/init_op.h
Outdated
// 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just follow the convention in mx.nd.range operator. We can address the inconsistency in numpy api.
DMLC_DECLARE_FIELD(repeat) | ||
.set_default(1) | ||
.describe("The repeating time of all elements." | ||
" E.g repeat=3, the element a will be repeated three times --> a, a, a."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
want to know how the repeat
parameter work with:
https://github.com/apache/incubator-mxnet/blob/35db8e5a4719335a8974f2a8198a44e814fedaa0/src/operator/tensor/init_op.h#L494-L499
and there is not repeat parameter on the numpy.arange()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately nd.arange
has a different interface compard to numpy.arange. I think it's reasonable to let contrib.arange_like
have an interface similar to nd.arange
.
If we want to remove the repeat argument, it's best when we add the arange op to the mx.np
namespace in the numpy project.
@haojin2 @reminisce FYI the nd.arange operator interface is inconsistent with numpy
@mxnet-label-bot add [pr-awaiting-review] |
DMLC_DECLARE_FIELD(repeat) | ||
.set_default(1) | ||
.describe("The repeating time of all elements." | ||
" E.g repeat=3, the element a will be repeated three times --> a, a, a."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately nd.arange
has a different interface compard to numpy.arange. I think it's reasonable to let contrib.arange_like
have an interface similar to nd.arange
.
If we want to remove the repeat argument, it's best when we add the arange op to the mx.np
namespace in the numpy project.
@haojin2 @reminisce FYI the nd.arange operator interface is inconsistent with numpy
Description
The new operator helps to remove
.shape
calls in Gluon and will make blocks hybridizable. More description here: dmlc/gluon-nlp#789@eric-haibin-lin
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.
Changes
Comments