Skip to content

Commit

Permalink
[lint] autoformat test/cpp and torch/csrc
Browse files Browse the repository at this point in the history
Let's have some fun.

Pull Request resolved: pytorch#78828

Approved by: https://github.com/ezyang
  • Loading branch information
suo authored and pytorchmergebot committed Jun 11, 2022
1 parent 1ec30a6 commit 30fb2c4
Show file tree
Hide file tree
Showing 564 changed files with 42,007 additions and 27,159 deletions.
12 changes: 4 additions & 8 deletions .lintrunner.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,10 @@ include_patterns = [
'aten/src/ATen/*.h',
'c10/**/*.h',
'c10/**/*.cpp',
'torch/csrc/jit/**/*.h',
'torch/csrc/jit/**/*.cpp',
'torch/csrc/deploy/**/*.h',
'torch/csrc/deploy/**/*.cpp',
'test/cpp/jit/**/*.h',
'test/cpp/jit/**/*.cpp',
'test/cpp/tensorexpr/**/*.h',
'test/cpp/tensorexpr/**/*.cpp',
'torch/csrc/**/*.h',
'torch/csrc/**/*.cpp',
'test/cpp/**/*.h',
'test/cpp/**/*.cpp',
]
exclude_patterns = [
'c10/util/strong_type.h',
Expand Down
2 changes: 2 additions & 0 deletions aten/src/ATen/autocast_mode.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <ATen/ATen.h>

namespace at {
namespace autocast {

Expand Down
65 changes: 44 additions & 21 deletions test/cpp/api/any.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,35 @@ TEST_F(AnyModuleTest, WrongNumberOfArguments) {
#endif
ASSERT_THROWS_WITH(
any.forward(),
module_name + "'s forward() method expects 2 argument(s), but received 0. "
"If " + module_name + "'s forward() method has default arguments, "
"please make sure the forward() method is declared with a corresponding `FORWARD_HAS_DEFAULT_ARGS` macro.");
module_name +
"'s forward() method expects 2 argument(s), but received 0. "
"If " +
module_name +
"'s forward() method has default arguments, "
"please make sure the forward() method is declared with a corresponding `FORWARD_HAS_DEFAULT_ARGS` macro.");
ASSERT_THROWS_WITH(
any.forward(5),
module_name + "'s forward() method expects 2 argument(s), but received 1. "
"If " + module_name + "'s forward() method has default arguments, "
"please make sure the forward() method is declared with a corresponding `FORWARD_HAS_DEFAULT_ARGS` macro.");
module_name +
"'s forward() method expects 2 argument(s), but received 1. "
"If " +
module_name +
"'s forward() method has default arguments, "
"please make sure the forward() method is declared with a corresponding `FORWARD_HAS_DEFAULT_ARGS` macro.");
ASSERT_THROWS_WITH(
any.forward(1, 2, 3),
module_name + "'s forward() method expects 2 argument(s), but received 3.");
module_name +
"'s forward() method expects 2 argument(s), but received 3.");
}

struct M_default_arg_with_macro : torch::nn::Module {
double forward(int a, int b = 2, double c = 3.0) {
return a + b + c;
}

protected:
FORWARD_HAS_DEFAULT_ARGS({1, torch::nn::AnyValue(2)}, {2, torch::nn::AnyValue(3.0)})
FORWARD_HAS_DEFAULT_ARGS(
{1, torch::nn::AnyValue(2)},
{2, torch::nn::AnyValue(3.0)})
};

struct M_default_arg_without_macro : torch::nn::Module {
Expand All @@ -127,7 +137,9 @@ struct M_default_arg_without_macro : torch::nn::Module {
}
};

TEST_F(AnyModuleTest, PassingArgumentsToModuleWithDefaultArgumentsInForwardMethod) {
TEST_F(
AnyModuleTest,
PassingArgumentsToModuleWithDefaultArgumentsInForwardMethod) {
{
AnyModule any(M_default_arg_with_macro{});

Expand Down Expand Up @@ -155,22 +167,32 @@ TEST_F(AnyModuleTest, PassingArgumentsToModuleWithDefaultArgumentsInForwardMetho

ASSERT_THROWS_WITH(
any.forward(),
module_name + "'s forward() method expects 3 argument(s), but received 0. "
"If " + module_name + "'s forward() method has default arguments, "
"please make sure the forward() method is declared with a corresponding `FORWARD_HAS_DEFAULT_ARGS` macro.");
module_name +
"'s forward() method expects 3 argument(s), but received 0. "
"If " +
module_name +
"'s forward() method has default arguments, "
"please make sure the forward() method is declared with a corresponding `FORWARD_HAS_DEFAULT_ARGS` macro.");
ASSERT_THROWS_WITH(
any.forward<double>(1),
module_name + "'s forward() method expects 3 argument(s), but received 1. "
"If " + module_name + "'s forward() method has default arguments, "
"please make sure the forward() method is declared with a corresponding `FORWARD_HAS_DEFAULT_ARGS` macro.");
module_name +
"'s forward() method expects 3 argument(s), but received 1. "
"If " +
module_name +
"'s forward() method has default arguments, "
"please make sure the forward() method is declared with a corresponding `FORWARD_HAS_DEFAULT_ARGS` macro.");
ASSERT_THROWS_WITH(
any.forward<double>(1, 3),
module_name + "'s forward() method expects 3 argument(s), but received 2. "
"If " + module_name + "'s forward() method has default arguments, "
"please make sure the forward() method is declared with a corresponding `FORWARD_HAS_DEFAULT_ARGS` macro.");
module_name +
"'s forward() method expects 3 argument(s), but received 2. "
"If " +
module_name +
"'s forward() method has default arguments, "
"please make sure the forward() method is declared with a corresponding `FORWARD_HAS_DEFAULT_ARGS` macro.");
ASSERT_THROWS_WITH(
any.forward(1, 2, 3.0, 4),
module_name + "'s forward() method expects 3 argument(s), but received 4.");
module_name +
"'s forward() method expects 3 argument(s), but received 4.");
}
}

Expand Down Expand Up @@ -345,13 +367,14 @@ TEST_F(AnyValueTest, CorrectlyAccessesIntWhenCorrectType) {
ASSERT_NE(value.try_get<int>(), nullptr);
// const and non-const types have the same typeid(),
// but casting Holder<int> to Holder<const int> is undefined
// behavior according to UBSAN: https://github.com/pytorch/pytorch/issues/26964
// behavior according to UBSAN:
// https://github.com/pytorch/pytorch/issues/26964
// ASSERT_NE(value.try_get<const int>(), nullptr);
ASSERT_EQ(value.get<int>(), 5);
}
// This test does not work at all, because it looks like make_value
// decays const int into int.
//TEST_F(AnyValueTest, CorrectlyAccessesConstIntWhenCorrectType) {
// TEST_F(AnyValueTest, CorrectlyAccessesConstIntWhenCorrectType) {
// auto value = make_value<const int>(5);
// ASSERT_NE(value.try_get<const int>(), nullptr);
// // ASSERT_NE(value.try_get<int>(), nullptr);
Expand Down
Loading

0 comments on commit 30fb2c4

Please sign in to comment.