Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Add a new arange_like operator to contrib #15400

Merged
merged 6 commits into from
Jul 6, 2019

Conversation

TaoLv
Copy link
Member

@TaoLv TaoLv commented Jun 28, 2019

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 are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

@TaoLv
Copy link
Member Author

TaoLv commented Jun 28, 2019

@pengzhao-intel @pengxin99 please help to review. Thanks.

// 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);
Copy link
Contributor

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

Copy link
Member Author

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.");
Copy link
Contributor

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().

Copy link
Member

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

@anirudhacharya
Copy link
Member

@mxnet-label-bot add [pr-awaiting-review]

@marcoabreu marcoabreu added the pr-awaiting-review PR is waiting for code review label Jun 28, 2019
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.");
Copy link
Member

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

tests/python/unittest/test_operator.py Outdated Show resolved Hide resolved
src/operator/tensor/init_op.h Outdated Show resolved Hide resolved
src/operator/tensor/init_op.h Show resolved Hide resolved
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr-awaiting-review PR is waiting for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants