Skip to content

Commit 0734048

Browse files
committed
Use std::optinal
1 parent 9d2d188 commit 0734048

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+323
-324
lines changed

backends/cadence/hifi/operators/op_mean.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ using executorch::aten::ScalarType;
1818
using executorch::aten::Tensor;
1919
using executorch::runtime::ArrayRef;
2020
using torch::executor::Error;
21-
using torch::executor::optional;
21+
using std::optional;
2222

2323
namespace cadence {
2424
namespace impl {

codegen/api/types/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class OptionalCType(CType):
5959

6060
def cpp_type(self, *, strip_ref: bool = False) -> str:
6161
# Do not pass `strip_ref` recursively.
62-
return f"torch::executor::optional<{self.elem.cpp_type()}>"
62+
return f"std::optional<{self.elem.cpp_type()}>"
6363

6464
def remove_const_ref(self) -> CType:
6565
return OptionalCType(self.elem.remove_const_ref())

extension/aten_util/make_aten_functor_from_et_functor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ struct type_map<torch::executor::Tensor> final {
6767

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

7474
template <class T>
75-
struct type_map<torch::executor::optional<T>&> final {
75+
struct type_map<std::optional<T>&> final {
7676
using type = std::optional<typename type_map<T>::type>&;
7777
};
7878

@@ -166,7 +166,7 @@ struct type_convert<
166166
typename remove_const_ref<AOptional>::type::value_type>> &&
167167
std::is_same_v<
168168
typename remove_const_ref<EOptional>::type,
169-
torch::executor::optional<
169+
std::optional<
170170
typename remove_const_ref<EOptional>::type::value_type>>>>
171171
final {
172172
public:

extension/aten_util/test/make_aten_functor_from_et_functor_test.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ Tensor& add_1_out(const Tensor& a, Tensor& out) {
3232
}
3333

3434
Tensor& add_optional_scalar_out(
35-
torch::executor::optional<int64_t> s1,
36-
torch::executor::optional<int64_t> s2,
35+
std::optional<int64_t> s1,
36+
std::optional<int64_t> s2,
3737
Tensor& out) {
3838
if (s1.has_value()) {
3939
out.mutable_data_ptr<int64_t>()[0] += s1.value();
@@ -45,8 +45,8 @@ Tensor& add_optional_scalar_out(
4545
}
4646

4747
Tensor& add_optional_tensor_out(
48-
torch::executor::optional<torch::executor::Tensor> s1,
49-
torch::executor::optional<torch::executor::Tensor> s2,
48+
std::optional<torch::executor::Tensor> s1,
49+
std::optional<torch::executor::Tensor> s2,
5050
Tensor& out) {
5151
if (s1.has_value()) {
5252
out.mutable_data_ptr<int64_t>()[0] +=
@@ -79,7 +79,7 @@ Tensor& sum_arrayref_tensor_out(
7979

8080
Tensor& sum_arrayref_optional_tensor_out(
8181
torch::executor::ArrayRef<
82-
torch::executor::optional<torch::executor::Tensor>> a,
82+
std::optional<torch::executor::Tensor>> a,
8383
Tensor& out) {
8484
for (int i = 0; i < a.size(); i++) {
8585
if (a[i].has_value()) {
@@ -137,20 +137,20 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestTypeMap_Tensor) {
137137
TEST_F(MakeATenFunctorFromETFunctorTest, TestTypeMap_Optionals) {
138138
// Scalar.
139139
EXPECT_TRUE((std::is_same<
140-
type_map<torch::executor::optional<int64_t>>::type,
140+
type_map<std::optional<int64_t>>::type,
141141
std::optional<int64_t>>::value));
142142
// Tensor.
143143
EXPECT_TRUE(
144144
(std::is_same<
145-
type_map<torch::executor::optional<torch::executor::Tensor>>::type,
145+
type_map<std::optional<torch::executor::Tensor>>::type,
146146
std::optional<at::Tensor>>::value));
147147
// ArrayRef.
148148
EXPECT_TRUE((std::is_same<
149-
type_map<torch::executor::optional<
149+
type_map<std::optional<
150150
torch::executor::ArrayRef<int64_t>>>::type,
151151
std::optional<c10::ArrayRef<int64_t>>>::value));
152152
EXPECT_TRUE((std::is_same<
153-
type_map<torch::executor::optional<
153+
type_map<std::optional<
154154
torch::executor::ArrayRef<torch::executor::Tensor>>>::type,
155155
std::optional<c10::ArrayRef<at::Tensor>>>::value));
156156
}
@@ -168,11 +168,11 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestTypeMap_ArrayRef) {
168168
// Optionals.
169169
EXPECT_TRUE((std::is_same<
170170
type_map<torch::executor::ArrayRef<
171-
torch::executor::optional<int64_t>>>::type,
171+
std::optional<int64_t>>>::type,
172172
c10::ArrayRef<std::optional<int64_t>>>::value));
173173
EXPECT_TRUE((std::is_same<
174174
type_map<torch::executor::ArrayRef<
175-
torch::executor::optional<torch::executor::Tensor>>>::type,
175+
std::optional<torch::executor::Tensor>>>::type,
176176
c10::ArrayRef<std::optional<at::Tensor>>>::value));
177177
}
178178

@@ -193,17 +193,17 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestConvert_OptionalScalar) {
193193
// Convert optional at to et.
194194
auto optional_at_in = std::optional<int64_t>();
195195
auto optional_et =
196-
type_convert<std::optional<int64_t>, torch::executor::optional<int64_t>>(
196+
type_convert<std::optional<int64_t>, std::optional<int64_t>>(
197197
optional_at_in)
198198
.call();
199199
EXPECT_TRUE(
200-
(std::is_same<decltype(optional_et), torch::executor::optional<int64_t>>::
200+
(std::is_same<decltype(optional_et), std::optional<int64_t>>::
201201
value));
202202

203203
// Convert optional et to at.
204-
auto optional_et_in = torch::executor::optional<int64_t>();
204+
auto optional_et_in = std::optional<int64_t>();
205205
auto optional_at_out =
206-
type_convert<torch::executor::optional<int64_t>, std::optional<int64_t>>(
206+
type_convert<std::optional<int64_t>, std::optional<int64_t>>(
207207
optional_et_in)
208208
.call();
209209
EXPECT_TRUE(
@@ -216,17 +216,17 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestConvert_OptionalTensor) {
216216
auto optional_et =
217217
type_convert<
218218
std::optional<at::Tensor>,
219-
torch::executor::optional<torch::executor::Tensor>>(optional_at_in)
219+
std::optional<torch::executor::Tensor>>(optional_at_in)
220220
.call();
221221
EXPECT_TRUE((std::is_same<
222222
decltype(optional_et),
223-
torch::executor::optional<torch::executor::Tensor>>::value));
223+
std::optional<torch::executor::Tensor>>::value));
224224

225225
// Convert optional et to at.
226226
torch::executor::testing::TensorFactory<ScalarType::Int> tf;
227-
auto et_in = torch::executor::optional<torch::executor::Tensor>(tf.ones({3}));
227+
auto et_in = std::optional<torch::executor::Tensor>(tf.ones({3}));
228228
auto optional_at_out = type_convert<
229-
torch::executor::optional<torch::executor::Tensor>,
229+
std::optional<torch::executor::Tensor>,
230230
std::optional<at::Tensor>>(optional_et)
231231
.call();
232232
EXPECT_TRUE(
@@ -429,15 +429,15 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestConvert_ConstRefOptionals) {
429429
auto const_optional_et =
430430
type_convert<
431431
const std::optional<int64_t>,
432-
torch::executor::optional<int64_t>>(const_optional_at_in)
432+
std::optional<int64_t>>(const_optional_at_in)
433433
.call();
434434
EXPECT_TRUE(const_optional_et.has_value());
435435
EXPECT_EQ(const_optional_et.value(), 42);
436436

437437
// Test optional scalar reference conversion
438438
std::optional<int64_t> optional_at_ref_in = std::optional<int64_t>(24);
439439
auto optional_et_from_ref =
440-
type_convert<std::optional<int64_t>&, torch::executor::optional<int64_t>>(
440+
type_convert<std::optional<int64_t>&, std::optional<int64_t>>(
441441
optional_at_ref_in)
442442
.call();
443443
EXPECT_TRUE(optional_et_from_ref.has_value());
@@ -449,7 +449,7 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestConvert_ConstRefOptionals) {
449449
auto const_optional_et_from_ref =
450450
type_convert<
451451
const std::optional<int64_t>&,
452-
torch::executor::optional<int64_t>>(const_optional_at_ref_in)
452+
std::optional<int64_t>>(const_optional_at_ref_in)
453453
.call();
454454
EXPECT_TRUE(const_optional_et_from_ref.has_value());
455455
EXPECT_EQ(const_optional_et_from_ref.value(), 84);
@@ -459,7 +459,7 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestConvert_ConstRefOptionals) {
459459
std::optional<at::Tensor>(torch::tensor({5}));
460460
auto const_optional_tensor_converter = type_convert<
461461
const std::optional<at::Tensor>,
462-
torch::executor::optional<torch::executor::Tensor>>(
462+
std::optional<torch::executor::Tensor>>(
463463
const_optional_tensor_at_in);
464464
auto const_optional_tensor_et = const_optional_tensor_converter.call();
465465
EXPECT_TRUE(const_optional_tensor_et.has_value());
@@ -470,7 +470,7 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestConvert_ConstRefOptionals) {
470470
std::optional<at::Tensor>(torch::tensor({7}));
471471
auto optional_tensor_converter_from_ref = type_convert<
472472
std::optional<at::Tensor>&,
473-
torch::executor::optional<torch::executor::Tensor>>(
473+
std::optional<torch::executor::Tensor>>(
474474
optional_tensor_at_ref_in);
475475
auto optional_tensor_et_from_ref = optional_tensor_converter_from_ref.call();
476476
EXPECT_TRUE(optional_tensor_et_from_ref.has_value());
@@ -482,7 +482,7 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestConvert_ConstRefOptionals) {
482482
std::optional<at::Tensor>(torch::tensor({9}));
483483
auto const_optional_tensor_converter_from_ref = type_convert<
484484
const std::optional<at::Tensor>&,
485-
torch::executor::optional<torch::executor::Tensor>>(
485+
std::optional<torch::executor::Tensor>>(
486486
const_optional_tensor_at_ref_in);
487487
auto const_optional_tensor_et_from_ref =
488488
const_optional_tensor_converter_from_ref.call();
@@ -496,7 +496,7 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestConvert_ConstRefOptionals) {
496496
auto empty_const_optional_et =
497497
type_convert<
498498
const std::optional<int64_t>,
499-
torch::executor::optional<int64_t>>(empty_const_optional_at_in)
499+
std::optional<int64_t>>(empty_const_optional_at_in)
500500
.call();
501501
EXPECT_FALSE(empty_const_optional_et.has_value());
502502

@@ -505,7 +505,7 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestConvert_ConstRefOptionals) {
505505
auto empty_const_optional_tensor_et =
506506
type_convert<
507507
const std::optional<at::Tensor>,
508-
torch::executor::optional<torch::executor::Tensor>>(
508+
std::optional<torch::executor::Tensor>>(
509509
empty_const_optional_tensor_at_in)
510510
.call();
511511
EXPECT_FALSE(empty_const_optional_tensor_et.has_value());

kernels/optimized/cpu/op_linear.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Tensor& opt_linear_out(
7474
RuntimeContext& ctx,
7575
const Tensor& in,
7676
const Tensor& mat2,
77-
const optional<Tensor>& bias,
77+
const std::optional<Tensor>& bias,
7878
Tensor& out) {
7979
ET_KERNEL_CHECK(ctx, check_linear_args(in, mat2, out), InvalidArgument, out);
8080

kernels/optimized/cpu/op_native_layer_norm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ template <typename CTYPE>
2727
void layer_norm(
2828
const Tensor& input,
2929
IntArrayRef normalized_shape,
30-
const optional<Tensor>& weight,
31-
const optional<Tensor>& bias,
30+
const std::optional<Tensor>& weight,
31+
const std::optional<Tensor>& bias,
3232
CTYPE eps,
3333
Tensor& out,
3434
Tensor& mean,

kernels/portable/cpu/op_any.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Tensor& any_all_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) {
5454
Tensor& any_dims_out(
5555
KernelRuntimeContext& ctx,
5656
const Tensor& in,
57-
optional<ArrayRef<int64_t>> dim_list,
57+
std::optional<ArrayRef<int64_t>> dim_list,
5858
bool keepdim,
5959
Tensor& out) {
6060
(void)ctx;

kernels/portable/cpu/op_argmax.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using std::optional;
2525
Tensor& argmax_out(
2626
KernelRuntimeContext& ctx,
2727
const Tensor& in,
28-
optional<int64_t> dim,
28+
std::optional<int64_t> dim,
2929
bool keepdim,
3030
Tensor& out) {
3131
(void)ctx;

kernels/portable/cpu/op_argmin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using std::optional;
2525
Tensor& argmin_out(
2626
KernelRuntimeContext& ctx,
2727
const Tensor& in,
28-
optional<int64_t> dim,
28+
std::optional<int64_t> dim,
2929
bool keepdim,
3030
Tensor& out) {
3131
(void)ctx;

kernels/portable/cpu/op_as_strided_copy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Tensor& as_strided_copy_out(
2121
const Tensor& in,
2222
ArrayRef<int64_t> size,
2323
ArrayRef<int64_t> stride,
24-
optional<int64_t> storage_offset,
24+
std::optional<int64_t> storage_offset,
2525
Tensor& out) {
2626
(void)ctx;
2727

0 commit comments

Comments
 (0)