mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
Remove using namespace torch::autograd
from header files (#34423)
Summary: This PR prevents leaking symbols from `torch::autograd` namespace to the root namespace. Fixes https://github.com/pytorch/pytorch/issues/34371. Pull Request resolved: https://github.com/pytorch/pytorch/pull/34423 Differential Revision: D20338404 Pulled By: yf225 fbshipit-source-id: e7ff3348193667a0cee5d38f9a003ae36cc704ca
This commit is contained in:
committed by
Facebook Github Bot
parent
e3d50c4dda
commit
baeb359e7a
@ -15,6 +15,7 @@ set(TORCH_API_TEST_SOURCES
|
||||
${TORCH_API_TEST_DIR}/module.cpp
|
||||
${TORCH_API_TEST_DIR}/modulelist.cpp
|
||||
${TORCH_API_TEST_DIR}/modules.cpp
|
||||
${TORCH_API_TEST_DIR}/namespace.cpp
|
||||
${TORCH_API_TEST_DIR}/nn_utils.cpp
|
||||
${TORCH_API_TEST_DIR}/optim.cpp
|
||||
${TORCH_API_TEST_DIR}/ordered_dict.cpp
|
||||
|
19
test/cpp/api/namespace.cpp
Normal file
19
test/cpp/api/namespace.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <torch/torch.h>
|
||||
|
||||
struct Node {};
|
||||
|
||||
// If `torch::autograd::Note` is leaked into the root namespace, the following compile error would throw:
|
||||
// ```
|
||||
// void NotLeakingSymbolsFromTorchAutogradNamespace_test_func(Node *node) {}
|
||||
// ^
|
||||
// error: reference to `Node` is ambiguous
|
||||
// ```
|
||||
void NotLeakingSymbolsFromTorchAutogradNamespace_test_func(Node *node) {}
|
||||
|
||||
TEST(NamespaceTests, NotLeakingSymbolsFromTorchAutogradNamespace) {
|
||||
// Checks that we are not leaking symbols from the
|
||||
// `torch::autograd` namespace to the root namespace
|
||||
NotLeakingSymbolsFromTorchAutogradNamespace_test_func(nullptr);
|
||||
}
|
@ -5,22 +5,21 @@
|
||||
#include <torch/types.h>
|
||||
#include <torch/nn/options/normalization.h>
|
||||
|
||||
using namespace torch::autograd;
|
||||
|
||||
namespace torch {
|
||||
namespace nn {
|
||||
namespace functions {
|
||||
|
||||
class CrossMapLRN2d : public torch::autograd::Function<CrossMapLRN2d> {
|
||||
public:
|
||||
static Variable forward(
|
||||
AutogradContext *ctx,
|
||||
const Variable& input,
|
||||
static torch::autograd::Variable forward(
|
||||
torch::autograd::AutogradContext *ctx,
|
||||
const torch::autograd::Variable& input,
|
||||
const CrossMapLRN2dOptions& options);
|
||||
|
||||
static variable_list backward(AutogradContext *ctx, variable_list grad_output);
|
||||
static torch::autograd::variable_list backward(
|
||||
torch::autograd::AutogradContext *ctx, torch::autograd::variable_list grad_output);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace functions
|
||||
} // namespace nn
|
||||
} // namespace torch
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include <torch/nn/modules/_functions.h>
|
||||
|
||||
using namespace torch::autograd;
|
||||
|
||||
namespace torch {
|
||||
namespace nn {
|
||||
namespace functions {
|
||||
|
Reference in New Issue
Block a user