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

+3-3
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

+3-3
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

+12-12
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

+12-12
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

+2-2
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

+2-2
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

+5-5
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

+3-3
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

+1-1
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

+1-1
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

src/libtorio/ffmpeg/ffmpeg.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace torio::io {
1010
////////////////////////////////////////////////////////////////////////////////
1111
// AVDictionary
1212
////////////////////////////////////////////////////////////////////////////////
13-
AVDictionary* get_option_dict(const c10::optional<OptionDict>& option) {
13+
AVDictionary* get_option_dict(const std::optional<OptionDict>& option) {
1414
AVDictionary* opt = nullptr;
1515
if (option) {
1616
for (auto const& [key, value] : option.value()) {

src/libtorio/ffmpeg/ffmpeg.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Wrapper {
7777
// IIRC-semantic. Instead we provide helper functions.
7878

7979
// Convert standard dict to FFmpeg native type
80-
AVDictionary* get_option_dict(const c10::optional<OptionDict>& option);
80+
AVDictionary* get_option_dict(const std::optional<OptionDict>& option);
8181

8282
// Clean up the dict after use. If there is an unsed key, throw runtime error
8383
void clean_up_dict(AVDictionary* p);

src/libtorio/ffmpeg/pybind/pybind.cpp

+17-17
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ struct StreamingMediaDecoderFileObj : private FileObj,
160160
public StreamingMediaDecoderCustomIO {
161161
StreamingMediaDecoderFileObj(
162162
py::object fileobj,
163-
const c10::optional<std::string>& format,
164-
const c10::optional<std::map<std::string, std::string>>& option,
163+
const std::optional<std::string>& format,
164+
const std::optional<std::map<std::string, std::string>>& option,
165165
int buffer_size)
166166
: FileObj{fileobj, buffer_size},
167167
StreamingMediaDecoderCustomIO(
@@ -177,7 +177,7 @@ struct StreamingMediaEncoderFileObj : private FileObj,
177177
public StreamingMediaEncoderCustomIO {
178178
StreamingMediaEncoderFileObj(
179179
py::object fileobj,
180-
const c10::optional<std::string>& format,
180+
const std::optional<std::string>& format,
181181
int buffer_size)
182182
: FileObj{fileobj, buffer_size},
183183
StreamingMediaEncoderCustomIO(
@@ -231,8 +231,8 @@ struct StreamingMediaDecoderBytes : private BytesWrapper,
231231
public StreamingMediaDecoderCustomIO {
232232
StreamingMediaDecoderBytes(
233233
std::string_view src,
234-
const c10::optional<std::string>& format,
235-
const c10::optional<std::map<std::string, std::string>>& option,
234+
const std::optional<std::string>& format,
235+
const std::optional<std::map<std::string, std::string>>& option,
236236
int64_t buffer_size)
237237
: BytesWrapper{src},
238238
StreamingMediaDecoderCustomIO(
@@ -278,10 +278,10 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) {
278278
.def_readwrite("frames", &Chunk::frames)
279279
.def_readwrite("pts", &Chunk::pts);
280280
py::class_<CodecConfig>(m, "CodecConfig", py::module_local())
281-
.def(py::init<int, int, const c10::optional<int>&, int, int>());
281+
.def(py::init<int, int, const std::optional<int>&, int, int>());
282282
py::class_<StreamingMediaEncoder>(
283283
m, "StreamingMediaEncoder", py::module_local())
284-
.def(py::init<const std::string&, const c10::optional<std::string>&>())
284+
.def(py::init<const std::string&, const std::optional<std::string>&>())
285285
.def("set_metadata", &StreamingMediaEncoder::set_metadata)
286286
.def("add_audio_stream", &StreamingMediaEncoder::add_audio_stream)
287287
.def("add_video_stream", &StreamingMediaEncoder::add_video_stream)
@@ -293,7 +293,7 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) {
293293
.def("close", &StreamingMediaEncoder::close);
294294
py::class_<StreamingMediaEncoderFileObj>(
295295
m, "StreamingMediaEncoderFileObj", py::module_local())
296-
.def(py::init<py::object, const c10::optional<std::string>&, int64_t>())
296+
.def(py::init<py::object, const std::optional<std::string>&, int64_t>())
297297
.def("set_metadata", &StreamingMediaEncoderFileObj::set_metadata)
298298
.def("add_audio_stream", &StreamingMediaEncoderFileObj::add_audio_stream)
299299
.def("add_video_stream", &StreamingMediaEncoderFileObj::add_video_stream)
@@ -366,8 +366,8 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) {
366366
m, "StreamingMediaDecoder", py::module_local())
367367
.def(py::init<
368368
const std::string&,
369-
const c10::optional<std::string>&,
370-
const c10::optional<OptionDict>&>())
369+
const std::optional<std::string>&,
370+
const std::optional<OptionDict>&>())
371371
.def("num_src_streams", &StreamingMediaDecoder::num_src_streams)
372372
.def("num_out_streams", &StreamingMediaDecoder::num_out_streams)
373373
.def(
@@ -385,7 +385,7 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) {
385385
.def("remove_stream", &StreamingMediaDecoder::remove_stream)
386386
.def(
387387
"process_packet",
388-
py::overload_cast<const c10::optional<double>&, const double>(
388+
py::overload_cast<const std::optional<double>&, const double>(
389389
&StreamingMediaDecoder::process_packet))
390390
.def("process_all_packets", &StreamingMediaDecoder::process_all_packets)
391391
.def("fill_buffer", &StreamingMediaDecoder::fill_buffer)
@@ -395,8 +395,8 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) {
395395
m, "StreamingMediaDecoderFileObj", py::module_local())
396396
.def(py::init<
397397
py::object,
398-
const c10::optional<std::string>&,
399-
const c10::optional<OptionDict>&,
398+
const std::optional<std::string>&,
399+
const std::optional<OptionDict>&,
400400
int64_t>())
401401
.def("num_src_streams", &StreamingMediaDecoderFileObj::num_src_streams)
402402
.def("num_out_streams", &StreamingMediaDecoderFileObj::num_out_streams)
@@ -419,7 +419,7 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) {
419419
.def("remove_stream", &StreamingMediaDecoderFileObj::remove_stream)
420420
.def(
421421
"process_packet",
422-
py::overload_cast<const c10::optional<double>&, const double>(
422+
py::overload_cast<const std::optional<double>&, const double>(
423423
&StreamingMediaDecoder::process_packet))
424424
.def(
425425
"process_all_packets",
@@ -431,8 +431,8 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) {
431431
m, "StreamingMediaDecoderBytes", py::module_local())
432432
.def(py::init<
433433
std::string_view,
434-
const c10::optional<std::string>&,
435-
const c10::optional<OptionDict>&,
434+
const std::optional<std::string>&,
435+
const std::optional<OptionDict>&,
436436
int64_t>())
437437
.def("num_src_streams", &StreamingMediaDecoderBytes::num_src_streams)
438438
.def("num_out_streams", &StreamingMediaDecoderBytes::num_out_streams)
@@ -455,7 +455,7 @@ PYBIND11_MODULE(TORIO_FFMPEG_EXT_NAME, m) {
455455
.def("remove_stream", &StreamingMediaDecoderBytes::remove_stream)
456456
.def(
457457
"process_packet",
458-
py::overload_cast<const c10::optional<double>&, const double>(
458+
py::overload_cast<const std::optional<double>&, const double>(
459459
&StreamingMediaDecoder::process_packet))
460460
.def(
461461
"process_all_packets",

src/libtorio/ffmpeg/stream_reader/buffer/chunked_buffer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void ChunkedBuffer::push_frame(torch::Tensor frame, int64_t pts_) {
105105
}
106106
}
107107

108-
c10::optional<Chunk> ChunkedBuffer::pop_chunk() {
108+
std::optional<Chunk> ChunkedBuffer::pop_chunk() {
109109
using namespace torch::indexing;
110110
if (!num_buffered_frames) {
111111
return {};

src/libtorio/ffmpeg/stream_reader/buffer/chunked_buffer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ChunkedBuffer {
2626

2727
bool is_ready() const;
2828
void flush();
29-
c10::optional<Chunk> pop_chunk();
29+
std::optional<Chunk> pop_chunk();
3030
void push_frame(torch::Tensor frame, int64_t pts_);
3131
};
3232

src/libtorio/ffmpeg/stream_reader/buffer/unchunked_buffer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void UnchunkedBuffer::push_frame(torch::Tensor frame, int64_t pts_) {
1515
chunks.push_back(frame);
1616
}
1717

18-
c10::optional<Chunk> UnchunkedBuffer::pop_chunk() {
18+
std::optional<Chunk> UnchunkedBuffer::pop_chunk() {
1919
if (chunks.size() == 0) {
2020
return {};
2121
}

src/libtorio/ffmpeg/stream_reader/buffer/unchunked_buffer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class UnchunkedBuffer {
1616
explicit UnchunkedBuffer(AVRational time_base);
1717
bool is_ready() const;
1818
void push_frame(torch::Tensor frame, int64_t pts_);
19-
c10::optional<Chunk> pop_chunk();
19+
std::optional<Chunk> pop_chunk();
2020
void flush();
2121
};
2222

src/libtorio/ffmpeg/stream_reader/post_process.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ struct ProcessImpl : public IPostDecodeProcess {
144144
return ret;
145145
}
146146

147-
c10::optional<Chunk> pop_chunk() override {
147+
std::optional<Chunk> pop_chunk() override {
148148
return buffer.pop_chunk();
149149
}
150150
};

src/libtorio/ffmpeg/stream_reader/post_process.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct IPostDecodeProcess {
88
virtual ~IPostDecodeProcess() = default;
99

1010
virtual int process_frame(AVFrame* frame) = 0;
11-
virtual c10::optional<Chunk> pop_chunk() = 0;
11+
virtual std::optional<Chunk> pop_chunk() = 0;
1212
virtual bool is_buffer_ready() const = 0;
1313
virtual const std::string& get_filter_desc() const = 0;
1414
virtual FilterGraphOutputInfo get_filter_output_info() const = 0;

0 commit comments

Comments
 (0)