This repository was archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[MXNET-381] Enhancement of take operator #11326
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -367,36 +367,46 @@ NNVM_REGISTER_OP(take) | |
|
||
This function slices the input array along a particular axis with the provided indices. | ||
|
||
Given an input array with shape ``(d0, d1, d2)`` and indices with shape ``(i0, i1)``, the output | ||
will have shape ``(i0, i1, d1, d2)``, computed by:: | ||
|
||
output[i,j,:,:] = input[indices[i,j],:,:] | ||
|
||
.. note:: | ||
- `axis`- Only slicing along axis 0 is supported for now. | ||
- `mode`- Only `clip` mode is supported for now. | ||
Given data tensor of rank r >= 1, and indices tensor of rank q, gather entries of the axis | ||
dimension of data (by default outer-most one as axis=0) indexed by indices, and concatenates them | ||
in an output tensor of rank q + (r - 1). | ||
|
||
Examples:: | ||
x = [4. 5. 6.] | ||
|
||
// Trivial case, take the second element along the first axis. | ||
|
||
take(x, [1]) = [ 5. ] | ||
|
||
// The other trivial case, axis=-1, take the third element along the first axis | ||
|
||
take(x, [3], axis=-1, mode='clip') = [ 6. ] | ||
|
||
x = [[ 1., 2.], | ||
[ 3., 4.], | ||
[ 5., 6.]] | ||
|
||
// In this case we will get rows 0 and 1, then 1 and 2. Along axis 0 | ||
|
||
take(x, [[0,1],[1,2]]) = [[[ 1., 2.], | ||
[ 3., 4.]], | ||
|
||
[[ 3., 4.], | ||
[ 5., 6.]]] | ||
|
||
// In this case we will get rows 0 and 1, then 1 and 2 (calculated by wrapping around). | ||
// Along axis 1 | ||
|
||
take(x, [[0, 3], [-1, -2]], axis=1, mode='wrap') = [[[ 1., 2.], | ||
[ 3., 4.]], | ||
|
||
[[ 3., 4.], | ||
[ 5., 6.]]] | ||
|
||
)code" ADD_FILELINE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will update that doc. |
||
.set_num_inputs(2) | ||
.set_num_outputs(1) | ||
.set_attr_parser(TakeParamParser<TakeParam>) | ||
.set_attr_parser(ParamParser<TakeParam>) | ||
.set_attr<nnvm::FListInputNames>("FListInputNames", | ||
[](const NodeAttrs& attrs) { | ||
return std::vector<std::string>{"a", "indices"}; | ||
|
@@ -420,6 +430,7 @@ Examples:: | |
NNVM_REGISTER_OP(_backward_take) | ||
.set_num_inputs(2) | ||
.set_num_outputs(2) | ||
.set_attr_parser(ParamParser<TakeParam>) | ||
.set_attr<FResourceRequest>("FResourceRequest", | ||
[](const NodeAttrs& attrs) { | ||
return std::vector<ResourceRequest>{ResourceRequest::kTempSpace}; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit:
NULL
->nullptr
.NULL
has more semantic meanings thannullptr
and should be deprecated in C++11.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.
will change.