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

fix doc for the op sort() and argsort() #15317

Merged
merged 1 commit into from
Jul 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/operator/tensor/ordering_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Examples::
[ 1., 3.]]

// flattens and then sorts
sort(x) = [ 1., 1., 3., 4.]
sort(x, axis=None) = [ 1., 1., 3., 4.]
Copy link
Contributor

Choose a reason for hiding this comment

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

This sort makes sense.
But I'm thrown off by the other example. Sorting along the last axis would be 3 then 4 unless it is descending rather than ascending. Does this need to be specified for clarity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi,
Thanks for your reply!

Do you mean this example?
// sorts along the last axis
sort(x) = [[ 1., 4.], [ 1., 3.]]

Since x = [[ 1, 4],[ 3, 1]], the pairs in the last axis are [1,4] and [3,1]. Sorting only along the last axis in a descend way would be [1,4] and [1,3]. So, in my opinion, it is correct? or maybe I'm wrong?

Copy link
Contributor

Choose a reason for hiding this comment

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

I tested it in numpy and it matches fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry that I didn't get your point. What I did wrong in this PR?

If the argument axis=None is not given, this function will sort the array alone the last axis. However, in the second example, we want the array to be flattened and then sorted.

Copy link
Contributor

Choose a reason for hiding this comment

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

Everything is fine. I might have needed more examples to see the patterns, but I understand that if you're conversant with NumPy then this all works as expected.


// sorts along the first axis
sort(x, axis=0) = [[ 1., 1.],
Expand Down Expand Up @@ -173,7 +173,7 @@ Examples::
[ 0., 1., 0.]]

// flatten and then sort
argsort(x) = [ 3., 1., 5., 0., 4., 2.]
argsort(x, axis=None) = [ 3., 1., 5., 0., 4., 2.]
)code" ADD_FILELINE)
.set_num_inputs(1)
.set_num_outputs(1)
Expand Down