Skip to content

Commit

Permalink
fix codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyouzhi committed Dec 15, 2023
1 parent 4b5ec2e commit d66310d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
5 changes: 3 additions & 2 deletions paddle/phi/kernels/funcs/activation_functor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1803,8 +1803,9 @@ struct ThresholdedReluFunctor : public BaseActivationFunctor<T> {
template <typename Device, typename X, typename Out>
void operator()(Device d, X x, Out out) const {
auto th = static_cast<T>(threshold); // NOLINT
auto va = static_cast<T>(value); // NOLINT
out.device(d) = (x > th).template cast<T>() * x + (x <= th).template cast<T>() * va;
auto va = static_cast<T>(value); // NOLINT
out.device(d) =
(x > th).template cast<T>() * x + (x <= th).template cast<T>() * va;
}
};

Expand Down
16 changes: 12 additions & 4 deletions test/legacy_test/test_activation_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -4358,21 +4358,29 @@ def test_static_api(self):
with paddle.static.program_guard(paddle.static.Program()):
x = paddle.static.data('X', self.x_np.shape, self.x_np.dtype)
out1 = F.thresholded_relu(x, self.threshold, self.value)
thresholded_relu = paddle.nn.ThresholdedReLU(self.threshold, self.value)
thresholded_relu = paddle.nn.ThresholdedReLU(
self.threshold, self.value
)
out2 = thresholded_relu(x)
exe = paddle.static.Executor(self.place)
res = exe.run(feed={'X': self.x_np}, fetch_list=[out1, out2])
out_ref = ref_thresholded_relu(self.x_np, self.threshold, self.value)
out_ref = ref_thresholded_relu(
self.x_np, self.threshold, self.value
)
for r in res:
np.testing.assert_allclose(out_ref, r, rtol=1e-05)

def test_dygraph_api(self):
with dynamic_guad():
x = paddle.to_tensor(self.x_np)
out1 = F.thresholded_relu(x, self.threshold, self.value)
thresholded_relu = paddle.nn.ThresholdedReLU(self.threshold, self.value)
thresholded_relu = paddle.nn.ThresholdedReLU(
self.threshold, self.value
)
out2 = thresholded_relu(x)
out_ref = ref_thresholded_relu(self.x_np, self.threshold, self.value)
out_ref = ref_thresholded_relu(
self.x_np, self.threshold, self.value
)
for r in [out1, out2]:
np.testing.assert_allclose(out_ref, r.numpy(), rtol=1e-05)

Expand Down

0 comments on commit d66310d

Please sign in to comment.