Skip to content

Commit 380af83

Browse files
r-barnesfacebook-github-bot
authored andcommitted
c10::optional -> std::optional in pytorch/inplace_abn/src/inplace_abn_cuda.cu +20
Summary: `c10::optional` was switched to be `std::optional` after PyTorch moved to C++17. Let's eliminate `c10::optional`, if we can. Reviewed By: albanD Differential Revision: D57294273 fbshipit-source-id: 8ccf207440302ea91b4f5057224c5c57ca7f9106
1 parent 7fc8f54 commit 380af83

File tree

8 files changed

+20
-20
lines changed

8 files changed

+20
-20
lines changed

torchtext/csrc/bert_tokenizer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static void to_lower(UString& token) {
141141
BERTEncoder::BERTEncoder(
142142
const std::string& vocab_file,
143143
bool do_lower_case,
144-
c10::optional<bool> strip_accents,
144+
std::optional<bool> strip_accents,
145145
std::vector<std::string> never_split)
146146
: vocab_{_read_vocab(vocab_file)},
147147
do_lower_case_{do_lower_case},
@@ -153,7 +153,7 @@ BERTEncoder::BERTEncoder(
153153
BERTEncoder::BERTEncoder(
154154
Vocab vocab,
155155
bool do_lower_case,
156-
c10::optional<bool> strip_accents,
156+
std::optional<bool> strip_accents,
157157
std::vector<std::string> never_split)
158158
: vocab_{vocab},
159159
do_lower_case_{do_lower_case},

torchtext/csrc/bert_tokenizer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ typedef ska_ordered::order_preserving_flat_hash_map<std::string, int64_t>
1313
// vocabulary)
1414
typedef std::tuple<
1515
bool,
16-
c10::optional<bool>,
16+
std::optional<bool>,
1717
std::vector<std::string>,
1818
std::vector<std::string>>
1919
BERTEncoderStates;
@@ -22,12 +22,12 @@ struct BERTEncoder : torch::CustomClassHolder {
2222
TORCHTEXT_API BERTEncoder(
2323
const std::string& vocab_file,
2424
bool do_lower_case,
25-
c10::optional<bool> strip_accents,
25+
std::optional<bool> strip_accents,
2626
std::vector<std::string> never_split);
2727
BERTEncoder(
2828
Vocab vocab,
2929
bool do_lower_case,
30-
c10::optional<bool> strip_accents,
30+
std::optional<bool> strip_accents,
3131
std::vector<std::string> never_split);
3232
TORCHTEXT_API std::vector<std::string> Tokenize(std::string text);
3333
TORCHTEXT_API std::vector<int64_t> Encode(std::string text);
@@ -38,7 +38,7 @@ struct BERTEncoder : torch::CustomClassHolder {
3838

3939
Vocab vocab_;
4040
bool do_lower_case_;
41-
c10::optional<bool> strip_accents_ = {};
41+
std::optional<bool> strip_accents_ = {};
4242
std::vector<std::string> never_split_;
4343
std::set<std::string> never_split_set_;
4444

torchtext/csrc/register_pybindings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ PYBIND11_MODULE(_torchtext, m) {
116116
}));
117117

118118
py::class_<Vocab, c10::intrusive_ptr<Vocab>>(m, "Vocab")
119-
.def(py::init<StringList, c10::optional<int64_t>>())
119+
.def(py::init<StringList, std::optional<int64_t>>())
120120
.def_readonly("itos_", &Vocab::itos_)
121121
.def_readonly("default_index_", &Vocab::default_index_)
122122
.def(
@@ -242,7 +242,7 @@ PYBIND11_MODULE(_torchtext, m) {
242242
.def(py::init<
243243
const std::string,
244244
bool,
245-
c10::optional<bool>,
245+
std::optional<bool>,
246246
std::vector<std::string>>())
247247
.def("encode", &BERTEncoder::Encode)
248248
.def("tokenize", &BERTEncoder::Tokenize)

torchtext/csrc/register_torchbindings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ TORCH_LIBRARY_FRAGMENT(torchtext, m) {
9494
});
9595

9696
m.class_<Vocab>("Vocab")
97-
.def(torch::init<StringList, c10::optional<int64_t>>())
97+
.def(torch::init<StringList, std::optional<int64_t>>())
9898
.def(
9999
"__contains__",
100100
[](const c10::intrusive_ptr<Vocab>& self, const std::string& item)
@@ -181,7 +181,7 @@ TORCH_LIBRARY_FRAGMENT(torchtext, m) {
181181
.def(torch::init<
182182
const std::string,
183183
bool,
184-
c10::optional<bool>,
184+
std::optional<bool>,
185185
std::vector<std::string>>())
186186
.def("encode", &BERTEncoder::Encode)
187187
.def("tokenize", &BERTEncoder::Tokenize)

torchtext/csrc/vectors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ std::tuple<Vectors, std::vector<std::string>> _load_token_and_vectors_from_file(
226226
const std::string& file_path,
227227
const std::string& delimiter_str,
228228
int64_t num_cpus,
229-
c10::optional<torch::Tensor> opt_unk_tensor) {
229+
std::optional<torch::Tensor> opt_unk_tensor) {
230230
TORCH_CHECK(
231231
delimiter_str.size() == 1,
232232
"Only string delimeters of size 1 are supported.");

torchtext/csrc/vectors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ _load_token_and_vectors_from_file(
5252
const std::string& file_path,
5353
const std::string& delimiter_str,
5454
const int64_t num_cpus,
55-
c10::optional<torch::Tensor> opt_unk_tensor);
55+
std::optional<torch::Tensor> opt_unk_tensor);
5656

5757
} // namespace torchtext

torchtext/csrc/vocab.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <string>
99
namespace torchtext {
1010

11-
Vocab::Vocab(StringList tokens, const c10::optional<int64_t>& default_index)
11+
Vocab::Vocab(StringList tokens, const std::optional<int64_t>& default_index)
1212
: stoi_(MAX_VOCAB_SIZE, -1), default_index_{default_index} {
1313
for (auto& token : tokens) {
1414
// throw error if duplicate token is found
@@ -49,11 +49,11 @@ int64_t Vocab::__getitem__(const c10::string_view& token) const {
4949
return default_index_.value();
5050
}
5151

52-
void Vocab::set_default_index(c10::optional<int64_t> index) {
52+
void Vocab::set_default_index(std::optional<int64_t> index) {
5353
default_index_ = index;
5454
}
5555

56-
c10::optional<int64_t> Vocab::get_default_index() const {
56+
std::optional<int64_t> Vocab::get_default_index() const {
5757
return default_index_;
5858
}
5959

@@ -173,7 +173,7 @@ c10::intrusive_ptr<Vocab> _deserialize_vocab(VocabStates states) {
173173
version_str.compare("0.0.2") >= 0,
174174
"Found unexpected version for serialized Vocab: " + version_str);
175175

176-
c10::optional<int64_t> default_index = {};
176+
std::optional<int64_t> default_index = {};
177177
if (integers.size() > 0) {
178178
default_index = integers[0];
179179
}

torchtext/csrc/vocab.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ struct Vocab : torch::CustomClassHolder {
3636
std::vector<int32_t> stoi_;
3737
const std::string version_str_ = "0.0.2";
3838
StringList itos_;
39-
c10::optional<int64_t> default_index_ = {};
39+
std::optional<int64_t> default_index_ = {};
4040

4141
// TODO: [can we remove this?] we need to keep this constructor, otherwise
4242
// torch binding gets compilation error: no matching constructor for
4343
// initialization of 'torchtext::Vocab'
4444
TORCHTEXT_API explicit Vocab(StringList tokens);
4545
TORCHTEXT_API explicit Vocab(
4646
StringList tokens,
47-
const c10::optional<int64_t>& default_index);
47+
const std::optional<int64_t>& default_index);
4848
TORCHTEXT_API int64_t __len__() const;
4949
TORCHTEXT_API int64_t __getitem__(const c10::string_view& token) const;
5050
TORCHTEXT_API bool __contains__(const c10::string_view& token) const;
51-
TORCHTEXT_API void set_default_index(c10::optional<int64_t> index);
52-
TORCHTEXT_API c10::optional<int64_t> get_default_index() const;
51+
TORCHTEXT_API void set_default_index(std::optional<int64_t> index);
52+
TORCHTEXT_API std::optional<int64_t> get_default_index() const;
5353
TORCHTEXT_API void insert_token(std::string token, const int64_t& index);
5454
TORCHTEXT_API void append_token(std::string token);
5555
TORCHTEXT_API std::string lookup_token(const int64_t& index);

0 commit comments

Comments
 (0)