mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[codemod] c10:optional
-> std::optional
(#126135)
Generated by running the following from PyTorch root: ``` find . -regex ".*\.\(cpp\|h\|cu\|hpp\|cc\|cxx\)$" | grep -v "build/" | xargs -n 50 -P 4 perl -pi -e 's/c10::optional/std::optional/' ``` `c10::optional` is just an alias for `std::optional`. This removes usages of that alias in preparation for eliminating it entirely. Pull Request resolved: https://github.com/pytorch/pytorch/pull/126135 Approved by: https://github.com/Skylion007, https://github.com/malfet, https://github.com/albanD, https://github.com/aaronenyeshi
This commit is contained in:
committed by
PyTorch MergeBot
parent
b55f57b7af
commit
ed327876f5
@ -34,8 +34,8 @@ namespace {
|
||||
|
||||
std::string stringSlice(
|
||||
std::string string,
|
||||
c10::optional<int64_t> start,
|
||||
c10::optional<int64_t> end,
|
||||
std::optional<int64_t> start,
|
||||
std::optional<int64_t> end,
|
||||
int64_t step) {
|
||||
int64_t start_val = start.has_value() ? start.value() : INT64_MAX;
|
||||
int64_t end_val = end.has_value() ? end.value() : INT64_MAX;
|
||||
@ -1167,7 +1167,7 @@ static const std::vector<OperatorGeneratorArgs> opGenArgs{
|
||||
"aten::index.Tensor_hacked_twin(Tensor self, Tensor[] indices) -> Tensor"),
|
||||
[](Stack& stack) {
|
||||
auto indices = pop(stack).to<c10::List<at::Tensor>>();
|
||||
c10::List<c10::optional<at::Tensor>> opt_list_indices;
|
||||
c10::List<std::optional<at::Tensor>> opt_list_indices;
|
||||
opt_list_indices.reserve(indices.size());
|
||||
for (const auto& ten : indices) {
|
||||
opt_list_indices.push_back(ten);
|
||||
@ -1182,7 +1182,7 @@ static const std::vector<OperatorGeneratorArgs> opGenArgs{
|
||||
"aten::_unsafe_index.Tensor_hacked_twin(Tensor self, Tensor[] indices) -> Tensor"),
|
||||
[](Stack& stack) {
|
||||
auto indices = pop(stack).to<c10::List<at::Tensor>>();
|
||||
c10::List<c10::optional<at::Tensor>> opt_list_indices;
|
||||
c10::List<std::optional<at::Tensor>> opt_list_indices;
|
||||
opt_list_indices.reserve(indices.size());
|
||||
for (const auto& ten : indices) {
|
||||
opt_list_indices.push_back(ten);
|
||||
@ -1200,7 +1200,7 @@ static const std::vector<OperatorGeneratorArgs> opGenArgs{
|
||||
auto accumulate = pop(stack).toBool();
|
||||
auto values = pop(stack).toTensor();
|
||||
auto indices = pop(stack).to<c10::List<at::Tensor>>();
|
||||
c10::List<c10::optional<at::Tensor>> opt_list_indices;
|
||||
c10::List<std::optional<at::Tensor>> opt_list_indices;
|
||||
opt_list_indices.reserve(indices.size());
|
||||
for (const auto& ten : indices) {
|
||||
opt_list_indices.push_back(ten);
|
||||
@ -1218,7 +1218,7 @@ static const std::vector<OperatorGeneratorArgs> opGenArgs{
|
||||
auto accumulate = pop(stack).toBool();
|
||||
auto values = pop(stack).toTensor();
|
||||
auto indices = pop(stack).to<c10::List<at::Tensor>>();
|
||||
c10::List<c10::optional<at::Tensor>> opt_list_indices;
|
||||
c10::List<std::optional<at::Tensor>> opt_list_indices;
|
||||
opt_list_indices.reserve(indices.size());
|
||||
for (const auto& ten : indices) {
|
||||
opt_list_indices.push_back(ten);
|
||||
@ -1236,7 +1236,7 @@ static const std::vector<OperatorGeneratorArgs> opGenArgs{
|
||||
auto accumulate = pop(stack).toBool();
|
||||
auto values = pop(stack).toTensor();
|
||||
auto indices = pop(stack).to<c10::List<at::Tensor>>();
|
||||
c10::List<c10::optional<at::Tensor>> opt_list_indices;
|
||||
c10::List<std::optional<at::Tensor>> opt_list_indices;
|
||||
opt_list_indices.reserve(indices.size());
|
||||
for (const auto& ten : indices) {
|
||||
opt_list_indices.push_back(ten);
|
||||
@ -1254,7 +1254,7 @@ static const std::vector<OperatorGeneratorArgs> opGenArgs{
|
||||
auto accumulate = pop(stack).toBool();
|
||||
auto values = pop(stack).toTensor();
|
||||
auto indices = pop(stack).to<c10::List<at::Tensor>>();
|
||||
c10::List<c10::optional<at::Tensor>> opt_list_indices;
|
||||
c10::List<std::optional<at::Tensor>> opt_list_indices;
|
||||
opt_list_indices.reserve(indices.size());
|
||||
for (const auto& ten : indices) {
|
||||
opt_list_indices.push_back(ten);
|
||||
@ -1275,9 +1275,9 @@ static const std::vector<OperatorGeneratorArgs> opGenArgs{
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-init-variables)
|
||||
bool copy;
|
||||
pop(stack, non_blocking, copy);
|
||||
c10::optional<at::ScalarType> scalarType =
|
||||
std::optional<at::ScalarType> scalarType =
|
||||
pop(stack).toOptional<at::ScalarType>();
|
||||
c10::optional<c10::Device> device =
|
||||
std::optional<c10::Device> device =
|
||||
pop(stack).toOptional<c10::Device>();
|
||||
at::Tensor self = pop(stack).toTensor();
|
||||
push(
|
||||
@ -1404,9 +1404,9 @@ static const std::vector<OperatorGeneratorArgs> opGenArgs{
|
||||
}
|
||||
}))};
|
||||
|
||||
static std::vector<c10::optional<Operator>> createOperators(
|
||||
static std::vector<std::optional<Operator>> createOperators(
|
||||
const std::vector<OperatorGeneratorArgs>& args) {
|
||||
std::vector<c10::optional<Operator>> result;
|
||||
std::vector<std::optional<Operator>> result;
|
||||
result.reserve(args.size());
|
||||
for (const auto& arg : args) {
|
||||
if (arg.schema_str) {
|
||||
@ -1769,8 +1769,8 @@ static const std::vector<OperatorGeneratorArgs> stringOpGenArgs{
|
||||
"aten::slice.str(str string, int? start=None, int? end=None, int step=1) -> str"),
|
||||
[](Stack& stack) {
|
||||
int64_t step = pop(stack).toInt();
|
||||
c10::optional<int64_t> end = pop(stack).toOptional<int64_t>();
|
||||
c10::optional<int64_t> start = pop(stack).toOptional<int64_t>();
|
||||
std::optional<int64_t> end = pop(stack).toOptional<int64_t>();
|
||||
std::optional<int64_t> start = pop(stack).toOptional<int64_t>();
|
||||
std::string string = pop(stack).toStringRef();
|
||||
push(stack, stringSlice(string, start, end, step));
|
||||
},
|
||||
@ -2397,7 +2397,7 @@ static const std::vector<OperatorGeneratorArgs> stringOpGenArgs{
|
||||
for (const auto& v : ivalues) {
|
||||
values.emplace_back(v.toStringRef());
|
||||
}
|
||||
c10::optional<std::string> opt_string =
|
||||
std::optional<std::string> opt_string =
|
||||
pop(stack).toOptional<std::string>();
|
||||
const std::string& string = opt_string.value_or("");
|
||||
std::stringstream ss;
|
||||
@ -2463,8 +2463,8 @@ static const std::vector<OperatorGeneratorArgs> opGenArgs1{
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-init-variables)
|
||||
bool copy;
|
||||
pop(stack, self, non_blocking, copy);
|
||||
c10::optional<c10::Device> device = c10::nullopt;
|
||||
c10::optional<at::ScalarType> scalarType = c10::nullopt;
|
||||
std::optional<c10::Device> device = c10::nullopt;
|
||||
std::optional<at::ScalarType> scalarType = c10::nullopt;
|
||||
push(
|
||||
stack, to_dispatch(self, device, scalarType, non_blocking, copy));
|
||||
},
|
||||
|
Reference in New Issue
Block a user