mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 00:21:07 +01:00
Summary: This PR is BC-breaking in the following way: Previous, we require the use of `std::string` to specify the mode for `EmbeddingBag`. After this PR, we use variant-based enums such as `torch::kSum` / `torch::kMean` / `torch::kMax` to specify the mode for `EmbeddingBag`. Pull Request resolved: https://github.com/pytorch/pytorch/pull/28330 Differential Revision: D18127116 Pulled By: yf225 fbshipit-source-id: 15cd86c764777f4d399587be92cda15b6ce8524b
61 lines
1.8 KiB
C++
61 lines
1.8 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include <c10/util/variant.h>
|
|
#include <torch/torch.h>
|
|
|
|
#include <test/cpp/api/support.h>
|
|
|
|
#define TORCH_ENUM_PRETTY_PRINT_TEST(name) \
|
|
{ \
|
|
v = torch::k##name; \
|
|
std::string pretty_print_name("k"); \
|
|
pretty_print_name.append(#name); \
|
|
ASSERT_EQ(c10::visit(torch::enumtype::enum_name{}, v), pretty_print_name); \
|
|
}
|
|
|
|
TEST(EnumTest, AllEnums) {
|
|
c10::variant<
|
|
torch::enumtype::kLinear,
|
|
torch::enumtype::kConv1D,
|
|
torch::enumtype::kConv2D,
|
|
torch::enumtype::kConv3D,
|
|
torch::enumtype::kConvTranspose1D,
|
|
torch::enumtype::kConvTranspose2D,
|
|
torch::enumtype::kConvTranspose3D,
|
|
torch::enumtype::kSigmoid,
|
|
torch::enumtype::kTanh,
|
|
torch::enumtype::kReLU,
|
|
torch::enumtype::kLeakyReLU,
|
|
torch::enumtype::kFanIn,
|
|
torch::enumtype::kFanOut,
|
|
torch::enumtype::kConstant,
|
|
torch::enumtype::kReflect,
|
|
torch::enumtype::kReplicate,
|
|
torch::enumtype::kCircular,
|
|
torch::enumtype::kSum,
|
|
torch::enumtype::kMean,
|
|
torch::enumtype::kMax
|
|
> v;
|
|
|
|
TORCH_ENUM_PRETTY_PRINT_TEST(Linear)
|
|
TORCH_ENUM_PRETTY_PRINT_TEST(Conv1D)
|
|
TORCH_ENUM_PRETTY_PRINT_TEST(Conv2D)
|
|
TORCH_ENUM_PRETTY_PRINT_TEST(Conv3D)
|
|
TORCH_ENUM_PRETTY_PRINT_TEST(ConvTranspose1D)
|
|
TORCH_ENUM_PRETTY_PRINT_TEST(ConvTranspose2D)
|
|
TORCH_ENUM_PRETTY_PRINT_TEST(ConvTranspose3D)
|
|
TORCH_ENUM_PRETTY_PRINT_TEST(Sigmoid)
|
|
TORCH_ENUM_PRETTY_PRINT_TEST(Tanh)
|
|
TORCH_ENUM_PRETTY_PRINT_TEST(ReLU)
|
|
TORCH_ENUM_PRETTY_PRINT_TEST(LeakyReLU)
|
|
TORCH_ENUM_PRETTY_PRINT_TEST(FanIn)
|
|
TORCH_ENUM_PRETTY_PRINT_TEST(FanOut)
|
|
TORCH_ENUM_PRETTY_PRINT_TEST(Constant)
|
|
TORCH_ENUM_PRETTY_PRINT_TEST(Reflect)
|
|
TORCH_ENUM_PRETTY_PRINT_TEST(Replicate)
|
|
TORCH_ENUM_PRETTY_PRINT_TEST(Circular)
|
|
TORCH_ENUM_PRETTY_PRINT_TEST(Sum)
|
|
TORCH_ENUM_PRETTY_PRINT_TEST(Mean)
|
|
TORCH_ENUM_PRETTY_PRINT_TEST(Max)
|
|
}
|