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

added ravel/unravel operators #11025

Merged
merged 1 commit into from
May 30, 2018
Merged

added ravel/unravel operators #11025

merged 1 commit into from
May 30, 2018

Conversation

asmushetzel
Copy link
Contributor

Description

This resolves #10203 by implementing ravel_multi_index and unravel_index operators. The operators perform the same functionality as the corresponding operators in numpy.
This enables writing fully symbolic operations that involve ravel/unravel of indices.

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)
  • [ X] Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • [ X] To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

@piiswrong
Copy link
Contributor

Could you make sure the behavior is exactly the same with numpy for the same configuration?

@asmushetzel
Copy link
Contributor Author

Changed the behavior to match numpy: A single multi index is given by a column of the matrix (not by a row). @piiswrong is that what you recommended in your comments?

DType *unravelled, DType *ravelled) {
index_t idx(ravelled[i]);
#pragma unroll
for (int j = ndim; j--; ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this style a little confusing and would prefer for(int j = ndim; j >= 0; j--) . What is the motivation ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a style issue. I have seen people using either variant.

@asmushetzel asmushetzel force-pushed the ravel2 branch 2 times, most recently from 08485cf to 749d8e8 Compare May 25, 2018 08:22
@fhieber
Copy link
Contributor

fhieber commented May 28, 2018

Is this ready to merge? We have an important use case for these ops and would like to test them soon.

@asmushetzel
Copy link
Contributor Author

Ready from my point of view.

Copy link
Contributor

@piiswrong piiswrong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise LGTM

.set_attr<FResourceRequest>("FResourceRequest", [](const NodeAttrs& attrs)
{ return std::vector<ResourceRequest>{ResourceRequest::kTempSpace}; })
.set_attr<nnvm::FListInputNames>("FListInputNames", [](const NodeAttrs& attrs)
{ return std::vector<std::string>{"A"}; } )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data

.set_attr<FResourceRequest>("FResourceRequest", [](const NodeAttrs& attrs)
{ return std::vector<ResourceRequest>{ResourceRequest::kTempSpace}; })
.set_attr<nnvm::FListInputNames>("FListInputNames", [](const NodeAttrs& attrs)
{ return std::vector<std::string>{"A"}; } )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data

.set_attr<nnvm::FInferType>("FInferType", ElemwiseType<1, 1>)
.set_attr<FCompute>("FCompute<cpu>", RavelForward<cpu>)
.set_attr<nnvm::FGradient>("FGradient", MakeZeroGradNodes)
.add_argument("A", "NDArray-or-Symbol", "Batch of multi-indices")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data

.set_attr<nnvm::FInferType>("FInferType", ElemwiseType<1, 1>)
.set_attr<FCompute>("FCompute<cpu>", UnravelForward<cpu>)
.set_attr<nnvm::FGradient>("FGradient", MakeZeroGradNodes)
.add_argument("A", "NDArray-or-Symbol", "Array of flat indices")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data

@asmushetzel asmushetzel force-pushed the ravel2 branch 3 times, most recently from fe3a77c to f9b9b13 Compare May 30, 2018 10:31
@asmushetzel
Copy link
Contributor Author

Changed input names from "A" to "data" as requested.

@piiswrong piiswrong merged commit 5109b00 into apache:master May 30, 2018
@asmushetzel asmushetzel deleted the ravel2 branch May 31, 2018 10:05
rahul003 pushed a commit to rahul003/mxnet that referenced this pull request Jun 4, 2018
zheng-da pushed a commit to zheng-da/incubator-mxnet that referenced this pull request Jun 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Operator] unravel_index and ravel_multi_index
4 participants