mirror of
https://github.com/pytorch/pytorch.git
synced 2026-11-20 09:04:25 +08:00
C++ API parity: CELU
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27487 Test Plan: Imported from OSS Differential Revision: D17835406 Pulled By: pbelevich fbshipit-source-id: a8282ae65d8996efcc8b8d846cfa637c3f89eda6
This commit is contained in:
committed by
Facebook Github Bot
parent
cddc147267
commit
795c913636
@@ -656,3 +656,37 @@ TEST_F(FunctionalTest, RReLUDefaultOptions) {
|
||||
ASSERT_EQ(y.sizes(), torch::IntArrayRef({size, size, size}));
|
||||
ASSERT_TRUE(torch::allclose(z, torch::ones_like(z)));
|
||||
}
|
||||
|
||||
TEST_F(FunctionalTest, CELU) {
|
||||
const auto size = 3;
|
||||
for (const auto inplace : {false, true}) {
|
||||
for (const auto alpha : {0.42, 1.0, 4.2, 42.42}) {
|
||||
auto x = torch::linspace(-10.0, 10.0, size * size * size);
|
||||
x.resize_({size, size, size});
|
||||
auto y_exp = torch::max(torch::zeros_like(x), x) +
|
||||
torch::min(torch::zeros_like(x), alpha * (torch::exp(x / alpha) - 1.0));
|
||||
auto y = F::celu(x, CELUOptions().alpha(alpha).inplace(inplace));
|
||||
|
||||
ASSERT_EQ(y.ndimension(), 3);
|
||||
ASSERT_EQ(y.sizes(), torch::IntArrayRef({size, size, size}));
|
||||
ASSERT_TRUE(torch::allclose(y, y_exp));
|
||||
if (inplace) {
|
||||
ASSERT_TRUE(torch::allclose(x, y_exp));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(FunctionalTest, CELUDefaultOptions) {
|
||||
const auto size = 3;
|
||||
const auto alpha = 1.0;
|
||||
auto x = torch::linspace(-10.0, 10.0, size * size * size);
|
||||
x.resize_({size, size, size});
|
||||
auto y_exp = torch::max(torch::zeros_like(x), x) +
|
||||
torch::min(torch::zeros_like(x), alpha * (torch::exp(x / alpha) - 1.0));
|
||||
auto y = F::celu(x);
|
||||
|
||||
ASSERT_EQ(y.ndimension(), 3);
|
||||
ASSERT_EQ(y.sizes(), torch::IntArrayRef({size, size, size}));
|
||||
ASSERT_TRUE(torch::allclose(y, y_exp));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user