Skip to content

Conversation

@Yanxing-Shi
Copy link
Contributor

PR types

New features

PR changes

OPs

Describe

Add paddle.searchsorted op

@CLAassistant
Copy link

CLAassistant commented Aug 25, 2021

CLA assistant check
All committers have signed the CLA.

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

Copy link
Collaborator

@sneaxiy sneaxiy left a comment

Choose a reason for hiding this comment

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

Excellent job with tiny comments.

- ``sorted_sequence[m][n]...[l][i-1] <= values[m][n]...[l][x] < sorted_sequence[m][n]...[l][i]``
Args:
sorted_sequence(Tensor): N-D or 1-D tensor, containing monotonically increasing sequence on the innermost dimension. The data type can be int32, int64, float32, float64.
Copy link
Collaborator

@sneaxiy sneaxiy Aug 26, 2021

Choose a reason for hiding this comment

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

Add indent here. Same below.
加个缩进,下同。

refer to :ref:`api_guide_Name`.
Returns:
output (Tensor):return the indices from the innermost dimension of sorted_sequence. The output tensor is the same size as values.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add indent here.

import paddle.nn.functional as F
import paddle.fluid as fluid
import paddle.fluid.core as core
from paddle.fluid import compiler, Program, program_guard
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not all imports are necessary. Please remove useless import expressions.

fetch_list=out)
out_ref = np.searchsorted(self.sorted_sequence, self.values)
for r in res:
self.assertEqual(np.allclose(out_ref, r), True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The res is a list with only one element. Please remove the for loop.

Use self.assertTrue(a) instead of self.assertEqual(a, True).


paddle.disable_static(place)
SortedSequence = paddle.to_tensor(self.sorted_sequence)
Values = paddle.to_tensor(self.values)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Try to use sorted_sequence/values instead of SearchSequence/Values. The snake case naming rule is more Pythonic.

'round_',
'rsqrt',
'rsqrt_',
'searchsorted',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why add this? Remove it.

"dimensions of sorted_sequence tensor "
"and input values tensor must "
"match, but we got sorted_sequence "
"tensor ( %s ), and input value "
Copy link
Collaborator

Choose a reason for hiding this comment

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

input value -> input values

#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I do not think that you should include these headers. Useless below.


template <typename T>
HOSTDEVICE inline int64_t BinarySearch(const T *x, int64_t num, const T &val) {
HOSTDEVICE inline int64_t BinarySearch(const T *x, size_t num, const T &val) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to change. Keep int64_t.

auto values_dims = ctx->GetInputDim("Values");
auto out_int32 = ctx->Attrs().Get<bool>("out_int32");

if (sequences_dims.size() != 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add brackets after if (...). It would be more readable.

@Yanxing-Shi Yanxing-Shi requested a review from sneaxiy August 27, 2021 11:36
@Yanxing-Shi Yanxing-Shi marked this pull request as draft August 27, 2021 11:41
@Yanxing-Shi Yanxing-Shi marked this pull request as ready for review September 7, 2021 12:17
Copy link
Collaborator

@sneaxiy sneaxiy left a comment

Choose a reason for hiding this comment

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

LGTM for codes. Reviewing docs ...

Copy link
Collaborator

@sneaxiy sneaxiy left a comment

Choose a reason for hiding this comment

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

LGTM for codes but some docs need to be updated.

Args:
sorted_sequence(Tensor): An input N-D or 1-D tensor with type int32, int64, float32, float64. The value of the tensor monotonically increases in the innermost dimension.
values(Tensor or Scalar): An input N-D tensor or a Scalar value with type int32, int64, float32, float64.
Copy link
Collaborator

Choose a reason for hiding this comment

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

No Scalar. Paddle does not support Scalar.

sorted_sequence(Tensor): An input N-D or 1-D tensor with type int32, int64, float32, float64. The value of the tensor monotonically increases in the innermost dimension.
values(Tensor or Scalar): An input N-D tensor or a Scalar value with type int32, int64, float32, float64.
out_int32(bool, optional): Data type of the output tensor which can be int32, int64. The default value is False, and it indicates that the output data type is int64.
right(bool, optional): Find the upper and lower bounds of the sorted_sequence range in the innermost dimension based on the given `values`. If the sorted_sequence value is nan or inf, return the size of the innermost dimension
Copy link
Collaborator

Choose a reason for hiding this comment

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

upper and lower bounds -> upper or lower bounds.

return the size of the innermost dimension -> return the size of the innermost dimension.

right(bool, optional): Find the upper and lower bounds of the sorted_sequence range in the innermost dimension based on the given `values`. If the sorted_sequence value is nan or inf, return the size of the innermost dimension
The default value is False and it shows the lower bounds.
name(str, optional): The default value is None. Normally there is no need for user to set this property. For more information, please
refer to :ref:`api_guide_Name`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Put this line to the previous line.

sneaxiy
sneaxiy previously approved these changes Sep 8, 2021
Copy link
Collaborator

@sneaxiy sneaxiy left a comment

Choose a reason for hiding this comment

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

LGTM now.

Copy link
Contributor

@qingqing01 qingqing01 left a comment

Choose a reason for hiding this comment

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

LGTM for API

qingqing01
qingqing01 previously approved these changes Sep 8, 2021
Copy link
Contributor

@qingqing01 qingqing01 left a comment

Choose a reason for hiding this comment

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

LGTM for API

Copy link
Contributor

@qingqing01 qingqing01 left a comment

Choose a reason for hiding this comment

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

LGTM for API.

Copy link
Contributor

@TCChenlong TCChenlong left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

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

LG API

Copy link
Contributor

@jzhang533 jzhang533 left a comment

Choose a reason for hiding this comment

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

LGTM

@sneaxiy sneaxiy merged commit 6622304 into PaddlePaddle:develop Sep 13, 2021
AnnaTrainingG pushed a commit to AnnaTrainingG/Paddle that referenced this pull request Sep 29, 2021
* fix github name

* fix CI error

* fix review and CI error

* fix inf,nan error and modify unittest samples

* add unittest samples

* add unittest samples

* fix unittest error

* test=document_fix

* test=document_fix

* modify doc and add unittest samples

* fix error newline in constant

* modify doc after mentor review

* modify __all__ and doc

* modify doc
@Yanxing-Shi Yanxing-Shi deleted the add_searchsorted_op branch November 9, 2021 02:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants