Skip to content

Commit 1980f8a

Browse files
authored
[codemod] c10::optional -> std::optional in pytorch/audio/src/libtorchaudio/sox/effects.cpp +20
Differential Revision: D57294298 Pull Request resolved: #3791
1 parent 9f10306 commit 1980f8a

20 files changed

+76
-76
lines changed

src/libtorchaudio/sox/effects.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ auto apply_effects_tensor(
8686
auto apply_effects_file(
8787
const std::string& path,
8888
const std::vector<std::vector<std::string>>& effects,
89-
c10::optional<bool> normalize,
90-
c10::optional<bool> channels_first,
91-
const c10::optional<std::string>& format)
89+
std::optional<bool> normalize,
90+
std::optional<bool> channels_first,
91+
const std::optional<std::string>& format)
9292
-> std::tuple<torch::Tensor, int64_t> {
9393
// Open input file
9494
SoxFormat sf(sox_open_read(

src/libtorchaudio/sox/effects.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ auto apply_effects_tensor(
1919
auto apply_effects_file(
2020
const std::string& path,
2121
const std::vector<std::vector<std::string>>& effects,
22-
c10::optional<bool> normalize,
23-
c10::optional<bool> channels_first,
24-
const c10::optional<std::string>& format)
22+
std::optional<bool> normalize,
23+
std::optional<bool> channels_first,
24+
const std::optional<std::string>& format)
2525
-> std::tuple<torch::Tensor, int64_t>;
2626

2727
} // namespace torchaudio::sox

src/libtorchaudio/sox/io.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace torchaudio::sox {
1010

1111
std::tuple<int64_t, int64_t, int64_t, int64_t, std::string> get_info_file(
1212
const std::string& path,
13-
const c10::optional<std::string>& format) {
13+
const std::optional<std::string>& format) {
1414
SoxFormat sf(sox_open_read(
1515
path.c_str(),
1616
/*signal=*/nullptr,
@@ -28,8 +28,8 @@ std::tuple<int64_t, int64_t, int64_t, int64_t, std::string> get_info_file(
2828
}
2929

3030
std::vector<std::vector<std::string>> get_effects(
31-
const c10::optional<int64_t>& frame_offset,
32-
const c10::optional<int64_t>& num_frames) {
31+
const std::optional<int64_t>& frame_offset,
32+
const std::optional<int64_t>& num_frames) {
3333
const auto offset = frame_offset.value_or(0);
3434
TORCH_CHECK(
3535
offset >= 0,
@@ -57,11 +57,11 @@ std::vector<std::vector<std::string>> get_effects(
5757

5858
std::tuple<torch::Tensor, int64_t> load_audio_file(
5959
const std::string& path,
60-
const c10::optional<int64_t>& frame_offset,
61-
const c10::optional<int64_t>& num_frames,
62-
c10::optional<bool> normalize,
63-
c10::optional<bool> channels_first,
64-
const c10::optional<std::string>& format) {
60+
const std::optional<int64_t>& frame_offset,
61+
const std::optional<int64_t>& num_frames,
62+
std::optional<bool> normalize,
63+
std::optional<bool> channels_first,
64+
const std::optional<std::string>& format) {
6565
auto effects = get_effects(frame_offset, num_frames);
6666
return apply_effects_file(path, effects, normalize, channels_first, format);
6767
}
@@ -71,10 +71,10 @@ void save_audio_file(
7171
torch::Tensor tensor,
7272
int64_t sample_rate,
7373
bool channels_first,
74-
c10::optional<double> compression,
75-
c10::optional<std::string> format,
76-
c10::optional<std::string> encoding,
77-
c10::optional<int64_t> bits_per_sample) {
74+
std::optional<double> compression,
75+
std::optional<std::string> format,
76+
std::optional<std::string> encoding,
77+
std::optional<int64_t> bits_per_sample) {
7878
validate_input_tensor(tensor);
7979

8080
const auto filetype = [&]() {

src/libtorchaudio/sox/io.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,31 @@
77
namespace torchaudio::sox {
88

99
auto get_effects(
10-
const c10::optional<int64_t>& frame_offset,
11-
const c10::optional<int64_t>& num_frames)
10+
const std::optional<int64_t>& frame_offset,
11+
const std::optional<int64_t>& num_frames)
1212
-> std::vector<std::vector<std::string>>;
1313

1414
std::tuple<int64_t, int64_t, int64_t, int64_t, std::string> get_info_file(
1515
const std::string& path,
16-
const c10::optional<std::string>& format);
16+
const std::optional<std::string>& format);
1717

1818
std::tuple<torch::Tensor, int64_t> load_audio_file(
1919
const std::string& path,
20-
const c10::optional<int64_t>& frame_offset,
21-
const c10::optional<int64_t>& num_frames,
22-
c10::optional<bool> normalize,
23-
c10::optional<bool> channels_first,
24-
const c10::optional<std::string>& format);
20+
const std::optional<int64_t>& frame_offset,
21+
const std::optional<int64_t>& num_frames,
22+
std::optional<bool> normalize,
23+
std::optional<bool> channels_first,
24+
const std::optional<std::string>& format);
2525

2626
void save_audio_file(
2727
const std::string& path,
2828
torch::Tensor tensor,
2929
int64_t sample_rate,
3030
bool channels_first,
31-
c10::optional<double> compression,
32-
c10::optional<std::string> format,
33-
c10::optional<std::string> encoding,
34-
c10::optional<int64_t> bits_per_sample);
31+
std::optional<double> compression,
32+
std::optional<std::string> format,
33+
std::optional<std::string> encoding,
34+
std::optional<int64_t> bits_per_sample);
3535

3636
} // namespace torchaudio::sox
3737

src/libtorchaudio/sox/types.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ std::string to_string(Encoding v) {
6767
}
6868
}
6969

70-
Encoding get_encoding_from_option(const c10::optional<std::string>& encoding) {
70+
Encoding get_encoding_from_option(const std::optional<std::string>& encoding) {
7171
if (!encoding.has_value())
7272
return Encoding::NOT_PROVIDED;
7373
std::string v = encoding.value();
@@ -84,7 +84,7 @@ Encoding get_encoding_from_option(const c10::optional<std::string>& encoding) {
8484
TORCH_CHECK(false, "Internal Error: unexpected encoding value: ", v);
8585
}
8686

87-
BitDepth get_bit_depth_from_option(const c10::optional<int64_t>& bit_depth) {
87+
BitDepth get_bit_depth_from_option(const std::optional<int64_t>& bit_depth) {
8888
if (!bit_depth.has_value())
8989
return BitDepth::NOT_PROVIDED;
9090
int64_t v = bit_depth.value();

src/libtorchaudio/sox/types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ enum class Encoding {
3838
};
3939

4040
std::string to_string(Encoding v);
41-
Encoding get_encoding_from_option(const c10::optional<std::string>& encoding);
41+
Encoding get_encoding_from_option(const std::optional<std::string>& encoding);
4242

4343
enum class BitDepth : unsigned {
4444
NOT_PROVIDED = 0,
@@ -49,7 +49,7 @@ enum class BitDepth : unsigned {
4949
B64 = 64,
5050
};
5151

52-
BitDepth get_bit_depth_from_option(const c10::optional<int64_t>& bit_depth);
52+
BitDepth get_bit_depth_from_option(const std::optional<int64_t>& bit_depth);
5353

5454
std::string get_encoding(sox_encoding_t encoding);
5555

src/libtorchaudio/sox/utils.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ std::tuple<sox_encoding_t, unsigned> get_save_encoding_for_wav(
289289
std::tuple<sox_encoding_t, unsigned> get_save_encoding(
290290
const std::string& format,
291291
const caffe2::TypeMeta& dtype,
292-
const c10::optional<std::string>& encoding,
293-
const c10::optional<int64_t>& bits_per_sample) {
292+
const std::optional<std::string>& encoding,
293+
const std::optional<int64_t>& bits_per_sample) {
294294
const Format fmt = get_format_from_string(format);
295295
const Encoding enc = get_encoding_from_option(encoding);
296296
const BitDepth bps = get_bit_depth_from_option(bits_per_sample);
@@ -492,9 +492,9 @@ sox_encodinginfo_t get_tensor_encodinginfo(caffe2::TypeMeta dtype) {
492492
sox_encodinginfo_t get_encodinginfo_for_save(
493493
const std::string& format,
494494
const caffe2::TypeMeta& dtype,
495-
const c10::optional<double>& compression,
496-
const c10::optional<std::string>& encoding,
497-
const c10::optional<int64_t>& bits_per_sample) {
495+
const std::optional<double>& compression,
496+
const std::optional<std::string>& encoding,
497+
const std::optional<int64_t>& bits_per_sample) {
498498
auto enc = get_save_encoding(format, dtype, encoding, bits_per_sample);
499499
return sox_encodinginfo_t{
500500
/*encoding=*/std::get<0>(enc),

src/libtorchaudio/sox/utils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ sox_encodinginfo_t get_tensor_encodinginfo(const caffe2::TypeMeta dtype);
104104
sox_encodinginfo_t get_encodinginfo_for_save(
105105
const std::string& format,
106106
const caffe2::TypeMeta& dtype,
107-
const c10::optional<double>& compression,
108-
const c10::optional<std::string>& encoding,
109-
const c10::optional<int64_t>& bits_per_sample);
107+
const std::optional<double>& compression,
108+
const std::optional<std::string>& encoding,
109+
const std::optional<int64_t>& bits_per_sample);
110110

111111
} // namespace torchaudio::sox
112112
#endif

src/libtorchaudio/utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ bool is_align_available() {
2323
#endif
2424
}
2525

26-
c10::optional<int64_t> cuda_version() {
26+
std::optional<int64_t> cuda_version() {
2727
#ifdef USE_CUDA
2828
return CUDA_VERSION;
2929
#else

src/libtorchaudio/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
namespace torchaudio {
55
bool is_rir_available();
66
bool is_align_available();
7-
c10::optional<int64_t> cuda_version();
7+
std::optional<int64_t> cuda_version();
88
} // namespace torchaudio

0 commit comments

Comments
 (0)