Skip to content

Commit bb1ad31

Browse files
r-barnesfacebook-github-bot
authored andcommitted
c10::optional -> std::optional in executorch (#5871)
Summary: `c10::optional` has been just an alias for `std::optional` for some time now. We are removing the `c10::optional` alias; this change facilitates that removal. Pull Request resolved: #5871 Reviewed By: q10, tarun292, bunnypak Differential Revision: D63876538 fbshipit-source-id: c2dd1e8857f9b13eb875593184c08a5c16ef59ef
1 parent 324f021 commit bb1ad31

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

extension/aten_util/make_aten_functor_from_et_functor.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ struct type_map<torch::executor::Tensor> final {
6262
// Optional.
6363
template <class T>
6464
struct type_map<torch::executor::optional<T>> final {
65-
using type = c10::optional<typename type_map<T>::type>;
65+
using type = std::optional<typename type_map<T>::type>;
6666
};
6767

6868
template <class T>
6969
struct type_map<torch::executor::optional<T>&> final {
70-
using type = c10::optional<typename type_map<T>::type>&;
70+
using type = std::optional<typename type_map<T>::type>&;
7171
};
7272

7373
// ArrayRef.
@@ -150,11 +150,11 @@ struct type_convert<
150150

151151
// Optionals: ATen to ETen.
152152
template <class F, class T>
153-
struct type_convert<c10::optional<F>, torch::executor::optional<T>> final {
153+
struct type_convert<std::optional<F>, torch::executor::optional<T>> final {
154154
public:
155-
c10::optional<F> val;
155+
std::optional<F> val;
156156
std::unique_ptr<struct type_convert<F, T>> convert_struct;
157-
explicit type_convert(c10::optional<F> value) : val(value) {}
157+
explicit type_convert(std::optional<F> value) : val(value) {}
158158
torch::executor::optional<T> call() {
159159
if (val.has_value()) {
160160
convert_struct = std::make_unique<struct type_convert<F, T>>(
@@ -168,18 +168,18 @@ struct type_convert<c10::optional<F>, torch::executor::optional<T>> final {
168168

169169
// Optionals: ETen to ATen.
170170
template <class F, class T>
171-
struct type_convert<torch::executor::optional<F>, c10::optional<T>> final {
171+
struct type_convert<torch::executor::optional<F>, std::optional<T>> final {
172172
public:
173173
torch::executor::optional<F> val;
174174
std::unique_ptr<struct type_convert<F, T>> convert_struct;
175175
explicit type_convert(torch::executor::optional<F> value) : val(value) {}
176-
c10::optional<T> call() {
176+
std::optional<T> call() {
177177
if (val.has_value()) {
178178
convert_struct = std::make_unique<struct type_convert<F, T>>(
179179
type_convert<F, T>(val.value()));
180-
return c10::optional<T>(convert_struct->call());
180+
return std::optional<T>(convert_struct->call());
181181
} else {
182-
return c10::optional<T>();
182+
return std::optional<T>();
183183
}
184184
}
185185
};

extension/aten_util/test/make_aten_functor_from_et_functor_test.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,21 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestTypeMap_Optionals) {
138138
// Scalar.
139139
EXPECT_TRUE((std::is_same<
140140
type_map<torch::executor::optional<int64_t>>::type,
141-
c10::optional<int64_t>>::value));
141+
std::optional<int64_t>>::value));
142142
// Tensor.
143143
EXPECT_TRUE(
144144
(std::is_same<
145145
type_map<torch::executor::optional<torch::executor::Tensor>>::type,
146-
c10::optional<at::Tensor>>::value));
146+
std::optional<at::Tensor>>::value));
147147
// ArrayRef.
148148
EXPECT_TRUE((std::is_same<
149149
type_map<torch::executor::optional<
150150
torch::executor::ArrayRef<int64_t>>>::type,
151-
c10::optional<c10::ArrayRef<int64_t>>>::value));
151+
std::optional<c10::ArrayRef<int64_t>>>::value));
152152
EXPECT_TRUE((std::is_same<
153153
type_map<torch::executor::optional<
154154
torch::executor::ArrayRef<torch::executor::Tensor>>>::type,
155-
c10::optional<c10::ArrayRef<at::Tensor>>>::value));
155+
std::optional<c10::ArrayRef<at::Tensor>>>::value));
156156
}
157157

158158
TEST_F(MakeATenFunctorFromETFunctorTest, TestTypeMap_ArrayRef) {
@@ -169,11 +169,11 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestTypeMap_ArrayRef) {
169169
EXPECT_TRUE((std::is_same<
170170
type_map<torch::executor::ArrayRef<
171171
torch::executor::optional<int64_t>>>::type,
172-
c10::ArrayRef<c10::optional<int64_t>>>::value));
172+
c10::ArrayRef<std::optional<int64_t>>>::value));
173173
EXPECT_TRUE((std::is_same<
174174
type_map<torch::executor::ArrayRef<
175175
torch::executor::optional<torch::executor::Tensor>>>::type,
176-
c10::ArrayRef<c10::optional<at::Tensor>>>::value));
176+
c10::ArrayRef<std::optional<at::Tensor>>>::value));
177177
}
178178

179179
TEST_F(MakeATenFunctorFromETFunctorTest, TestConvert_Tensor) {
@@ -191,9 +191,9 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestConvert_Tensor) {
191191

192192
TEST_F(MakeATenFunctorFromETFunctorTest, TestConvert_OptionalScalar) {
193193
// Convert optional at to et.
194-
auto optional_at_in = c10::optional<int64_t>();
194+
auto optional_at_in = std::optional<int64_t>();
195195
auto optional_et =
196-
type_convert<c10::optional<int64_t>, torch::executor::optional<int64_t>>(
196+
type_convert<std::optional<int64_t>, torch::executor::optional<int64_t>>(
197197
optional_at_in)
198198
.call();
199199
EXPECT_TRUE(
@@ -203,19 +203,19 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestConvert_OptionalScalar) {
203203
// Convert optional et to at.
204204
auto optional_et_in = torch::executor::optional<int64_t>();
205205
auto optional_at_out =
206-
type_convert<torch::executor::optional<int64_t>, c10::optional<int64_t>>(
206+
type_convert<torch::executor::optional<int64_t>, std::optional<int64_t>>(
207207
optional_et_in)
208208
.call();
209209
EXPECT_TRUE(
210-
(std::is_same<decltype(optional_at_out), c10::optional<int64_t>>::value));
210+
(std::is_same<decltype(optional_at_out), std::optional<int64_t>>::value));
211211
}
212212

213213
TEST_F(MakeATenFunctorFromETFunctorTest, TestConvert_OptionalTensor) {
214214
// Convert optional at to et.
215-
auto optional_at_in = c10::optional<at::Tensor>();
215+
auto optional_at_in = std::optional<at::Tensor>();
216216
auto optional_et =
217217
type_convert<
218-
c10::optional<at::Tensor>,
218+
std::optional<at::Tensor>,
219219
torch::executor::optional<torch::executor::Tensor>>(optional_at_in)
220220
.call();
221221
EXPECT_TRUE((std::is_same<
@@ -227,10 +227,10 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestConvert_OptionalTensor) {
227227
auto et_in = torch::executor::optional<torch::executor::Tensor>(tf.ones({3}));
228228
auto optional_at_out = type_convert<
229229
torch::executor::optional<torch::executor::Tensor>,
230-
c10::optional<at::Tensor>>(optional_et)
230+
std::optional<at::Tensor>>(optional_et)
231231
.call();
232232
EXPECT_TRUE(
233-
(std::is_same<decltype(optional_at_out), c10::optional<at::Tensor>>::
233+
(std::is_same<decltype(optional_at_out), std::optional<at::Tensor>>::
234234
value));
235235
}
236236

@@ -344,8 +344,8 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestWrap_EmbeddingByte) {
344344
}
345345

346346
TEST_F(MakeATenFunctorFromETFunctorTest, TestWrap_OptionalScalarAdd) {
347-
c10::optional<int64_t> a = c10::optional<int64_t>(3);
348-
c10::optional<int64_t> b = c10::optional<int64_t>();
347+
std::optional<int64_t> a = std::optional<int64_t>(3);
348+
std::optional<int64_t> b = std::optional<int64_t>();
349349
at::Tensor out = torch::tensor({0});
350350

351351
auto op = c10::Dispatcher::singleton().findSchema(
@@ -359,8 +359,8 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestWrap_OptionalScalarAdd) {
359359
}
360360

361361
TEST_F(MakeATenFunctorFromETFunctorTest, TestWrap_OptionalTensorAdd) {
362-
c10::optional<at::Tensor> a = c10::optional<at::Tensor>(torch::tensor({8}));
363-
c10::optional<at::Tensor> b = c10::optional<at::Tensor>();
362+
std::optional<at::Tensor> a = std::optional<at::Tensor>(torch::tensor({8}));
363+
std::optional<at::Tensor> b = std::optional<at::Tensor>();
364364
at::Tensor out = torch::tensor({0});
365365

366366
auto op = c10::Dispatcher::singleton().findSchema(
@@ -405,10 +405,10 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestWrap_ArrayRefTensorAdd) {
405405
}
406406

407407
TEST_F(MakeATenFunctorFromETFunctorTest, TestWrap_ArrayRefOptional) {
408-
std::vector<c10::optional<at::Tensor>> vec{
409-
c10::optional<at::Tensor>(torch::tensor({1})),
410-
c10::optional<at::Tensor>(),
411-
c10::optional<at::Tensor>(torch::tensor({3}))};
408+
std::vector<std::optional<at::Tensor>> vec{
409+
std::optional<at::Tensor>(torch::tensor({1})),
410+
std::optional<at::Tensor>(),
411+
std::optional<at::Tensor>(torch::tensor({3}))};
412412
at::Tensor out = torch::tensor({0});
413413

414414
at::ArrayRef arrayref = at::ArrayRef(vec.data(), vec.size());

kernels/test/op_index_put_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class OpIndexPutOutTest : public OperatorTest {
3434
const bool accumulate,
3535
Tensor& out) {
3636
#ifdef USE_ATEN_LIB
37-
c10::List<c10::optional<at::Tensor>> indices_list(indices);
37+
c10::List<std::optional<at::Tensor>> indices_list(indices);
3838
return torch::executor::aten::index_put_outf(
3939
context_, input, indices_list, values, accumulate, out);
4040
#else

0 commit comments

Comments
 (0)