pytorch/test/cpp/api/enum.cpp
Nikita Shulga 4cb534f92e Make PyTorch code-base clang-tidy compliant (#56892)
Summary:
This is an automatic change generated by the following script:
```
#!/usr/bin/env python3
from subprocess import check_output, check_call
import os

def get_compiled_files_list():
    import json
    with open("build/compile_commands.json") as f:
        data = json.load(f)
    files = [os.path.relpath(node['file']) for node in data]
    for idx, fname in enumerate(files):
        if fname.startswith('build/') and fname.endswith('.DEFAULT.cpp'):
            files[idx] = fname[len('build/'):-len('.DEFAULT.cpp')]
    return files

def run_clang_tidy(fname):
    check_call(["python3", "tools/clang_tidy.py", "-c", "build", "-x", fname,"-s"])
    changes = check_output(["git", "ls-files", "-m"])
    if len(changes) == 0:
        return
    check_call(["git", "commit","--all", "-m", f"NOLINT stubs for {fname}"])

def main():
    git_files = check_output(["git", "ls-files"]).decode("ascii").split("\n")
    compiled_files = get_compiled_files_list()
    for idx, fname in enumerate(git_files):
        if fname not in compiled_files:
            continue
        if fname.startswith("caffe2/contrib/aten/"):
            continue
        print(f"[{idx}/{len(git_files)}] Processing {fname}")
        run_clang_tidy(fname)

if __name__ == "__main__":
    main()
```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/56892

Reviewed By: H-Huang

Differential Revision: D27991944

Pulled By: malfet

fbshipit-source-id: 5415e1eb2c1b34319a4f03024bfaa087007d7179
2021-04-28 14:10:25 -07:00

89 lines
2.8 KiB
C++

#include <gtest/gtest.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(torch::enumtype::get_enum_name(v), pretty_print_name); \
}
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
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::kNearest,
torch::enumtype::kBilinear,
torch::enumtype::kBicubic,
torch::enumtype::kTrilinear,
torch::enumtype::kArea,
torch::enumtype::kSum,
torch::enumtype::kMean,
torch::enumtype::kMax,
torch::enumtype::kNone,
torch::enumtype::kBatchMean,
torch::enumtype::kZeros,
torch::enumtype::kBorder,
torch::enumtype::kReflection,
torch::enumtype::kRNN_TANH,
torch::enumtype::kRNN_RELU,
torch::enumtype::kLSTM,
torch::enumtype::kGRU
> 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(Nearest)
TORCH_ENUM_PRETTY_PRINT_TEST(Bilinear)
TORCH_ENUM_PRETTY_PRINT_TEST(Bicubic)
TORCH_ENUM_PRETTY_PRINT_TEST(Trilinear)
TORCH_ENUM_PRETTY_PRINT_TEST(Area)
TORCH_ENUM_PRETTY_PRINT_TEST(Sum)
TORCH_ENUM_PRETTY_PRINT_TEST(Mean)
TORCH_ENUM_PRETTY_PRINT_TEST(Max)
TORCH_ENUM_PRETTY_PRINT_TEST(None)
TORCH_ENUM_PRETTY_PRINT_TEST(BatchMean)
TORCH_ENUM_PRETTY_PRINT_TEST(Zeros)
TORCH_ENUM_PRETTY_PRINT_TEST(Border)
TORCH_ENUM_PRETTY_PRINT_TEST(Reflection)
TORCH_ENUM_PRETTY_PRINT_TEST(RNN_TANH)
TORCH_ENUM_PRETTY_PRINT_TEST(RNN_RELU)
TORCH_ENUM_PRETTY_PRINT_TEST(LSTM)
TORCH_ENUM_PRETTY_PRINT_TEST(GRU)
}