Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
MahmoudAshraf97 authored May 14, 2024
2 parents c023405 + 1980f8a commit 0129429
Show file tree
Hide file tree
Showing 35 changed files with 250 additions and 250 deletions.
2 changes: 1 addition & 1 deletion docs/source/libtorio.stream_reader.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ StreamingMediaDecoder

.. doxygenclass:: torio::io::StreamingMediaDecoder

.. doxygenfunction:: torio::io::StreamingMediaDecoder::StreamingMediaDecoder(const std::string &src, const c10::optional<std::string> &format = {}, const c10::optional<OptionDict> &option = {})
.. doxygenfunction:: torio::io::StreamingMediaDecoder::StreamingMediaDecoder(const std::string &src, const std::optional<std::string> &format = {}, const c10::optional<OptionDict> &option = {})

StreamingMediaDecoderCustomIO
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion docs/source/libtorio.stream_writer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ StreamingMediaEncoder

.. doxygenclass:: torio::io::StreamingMediaEncoder

.. doxygenfunction:: torio::io::StreamingMediaEncoder::StreamingMediaEncoder(const std::string &dst, const c10::optional<std::string> &format = {})
.. doxygenfunction:: torio::io::StreamingMediaEncoder::StreamingMediaEncoder(const std::string &dst, const std::optional<std::string> &format = {})

StreamingMediaEncoderCustomIO
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion src/libtorchaudio/rnnt/autograd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class RNNTLossFunction : public torch::autograd::Function<RNNTLossFunction> {
}
};

std::tuple<torch::Tensor, c10::optional<torch::Tensor>> rnnt_loss_autograd(
std::tuple<torch::Tensor, std::optional<torch::Tensor>> rnnt_loss_autograd(
torch::Tensor& logits,
const torch::Tensor& targets,
const torch::Tensor& logit_lengths,
Expand Down
2 changes: 1 addition & 1 deletion src/libtorchaudio/rnnt/compute.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <libtorchaudio/rnnt/compute.h>
#include <torch/script.h>

std::tuple<torch::Tensor, c10::optional<torch::Tensor>> rnnt_loss(
std::tuple<torch::Tensor, std::optional<torch::Tensor>> rnnt_loss(
torch::Tensor& logits,
const torch::Tensor& targets,
const torch::Tensor& logit_lengths,
Expand Down
2 changes: 1 addition & 1 deletion src/libtorchaudio/rnnt/compute.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <torch/script.h>

std::tuple<torch::Tensor, c10::optional<torch::Tensor>> rnnt_loss(
std::tuple<torch::Tensor, std::optional<torch::Tensor>> rnnt_loss(
torch::Tensor& logits,
const torch::Tensor& targets,
const torch::Tensor& logit_lengths,
Expand Down
4 changes: 2 additions & 2 deletions src/libtorchaudio/rnnt/cpu/compute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace rnnt {
namespace cpu {

// Entry point into RNNT Loss
std::tuple<torch::Tensor, c10::optional<torch::Tensor>> compute(
std::tuple<torch::Tensor, std::optional<torch::Tensor>> compute(
torch::Tensor& logits,
const torch::Tensor& targets,
const torch::Tensor& logit_lengths,
Expand Down Expand Up @@ -89,7 +89,7 @@ std::tuple<torch::Tensor, c10::optional<torch::Tensor>> compute(
torch::Tensor costs = torch::empty(
options.batchSize_ * options.nHypos_,
torch::TensorOptions().device(logits.device()).dtype(logits.dtype()));
c10::optional<torch::Tensor> gradients = torch::zeros_like(logits);
std::optional<torch::Tensor> gradients = torch::zeros_like(logits);

torch::Tensor int_workspace = torch::empty(
IntWorkspace::ComputeSizeFromOptions(options),
Expand Down
4 changes: 2 additions & 2 deletions src/libtorchaudio/rnnt/gpu/compute.cu
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace rnnt {
namespace gpu {

// Entry point into RNNT Loss
std::tuple<torch::Tensor, c10::optional<torch::Tensor>> compute(
std::tuple<torch::Tensor, std::optional<torch::Tensor>> compute(
torch::Tensor& logits,
const torch::Tensor& targets,
const torch::Tensor& logit_lengths,
Expand Down Expand Up @@ -92,7 +92,7 @@ std::tuple<torch::Tensor, c10::optional<torch::Tensor>> compute(
torch::Tensor costs = torch::empty(
options.batchSize_ * options.nHypos_,
torch::TensorOptions().device(logits.device()).dtype(logits.dtype()));
c10::optional<torch::Tensor> gradients = torch::zeros_like(logits);
std::optional<torch::Tensor> gradients = torch::zeros_like(logits);

torch::Tensor int_workspace = torch::empty(
IntWorkspace::ComputeSizeFromOptions(options),
Expand Down
6 changes: 3 additions & 3 deletions src/libtorchaudio/sox/effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ auto apply_effects_tensor(
auto apply_effects_file(
const std::string& path,
const std::vector<std::vector<std::string>>& effects,
c10::optional<bool> normalize,
c10::optional<bool> channels_first,
const c10::optional<std::string>& format)
std::optional<bool> normalize,
std::optional<bool> channels_first,
const std::optional<std::string>& format)
-> std::tuple<torch::Tensor, int64_t> {
// Open input file
SoxFormat sf(sox_open_read(
Expand Down
6 changes: 3 additions & 3 deletions src/libtorchaudio/sox/effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ auto apply_effects_tensor(
auto apply_effects_file(
const std::string& path,
const std::vector<std::vector<std::string>>& effects,
c10::optional<bool> normalize,
c10::optional<bool> channels_first,
const c10::optional<std::string>& format)
std::optional<bool> normalize,
std::optional<bool> channels_first,
const std::optional<std::string>& format)
-> std::tuple<torch::Tensor, int64_t>;

} // namespace torchaudio::sox
Expand Down
24 changes: 12 additions & 12 deletions src/libtorchaudio/sox/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace torchaudio::sox {

std::tuple<int64_t, int64_t, int64_t, int64_t, std::string> get_info_file(
const std::string& path,
const c10::optional<std::string>& format) {
const std::optional<std::string>& format) {
SoxFormat sf(sox_open_read(
path.c_str(),
/*signal=*/nullptr,
Expand All @@ -28,8 +28,8 @@ std::tuple<int64_t, int64_t, int64_t, int64_t, std::string> get_info_file(
}

std::vector<std::vector<std::string>> get_effects(
const c10::optional<int64_t>& frame_offset,
const c10::optional<int64_t>& num_frames) {
const std::optional<int64_t>& frame_offset,
const std::optional<int64_t>& num_frames) {
const auto offset = frame_offset.value_or(0);
TORCH_CHECK(
offset >= 0,
Expand Down Expand Up @@ -57,11 +57,11 @@ std::vector<std::vector<std::string>> get_effects(

std::tuple<torch::Tensor, int64_t> load_audio_file(
const std::string& path,
const c10::optional<int64_t>& frame_offset,
const c10::optional<int64_t>& num_frames,
c10::optional<bool> normalize,
c10::optional<bool> channels_first,
const c10::optional<std::string>& format) {
const std::optional<int64_t>& frame_offset,
const std::optional<int64_t>& num_frames,
std::optional<bool> normalize,
std::optional<bool> channels_first,
const std::optional<std::string>& format) {
auto effects = get_effects(frame_offset, num_frames);
return apply_effects_file(path, effects, normalize, channels_first, format);
}
Expand All @@ -71,10 +71,10 @@ void save_audio_file(
torch::Tensor tensor,
int64_t sample_rate,
bool channels_first,
c10::optional<double> compression,
c10::optional<std::string> format,
c10::optional<std::string> encoding,
c10::optional<int64_t> bits_per_sample) {
std::optional<double> compression,
std::optional<std::string> format,
std::optional<std::string> encoding,
std::optional<int64_t> bits_per_sample) {
validate_input_tensor(tensor);

const auto filetype = [&]() {
Expand Down
24 changes: 12 additions & 12 deletions src/libtorchaudio/sox/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@
namespace torchaudio::sox {

auto get_effects(
const c10::optional<int64_t>& frame_offset,
const c10::optional<int64_t>& num_frames)
const std::optional<int64_t>& frame_offset,
const std::optional<int64_t>& num_frames)
-> std::vector<std::vector<std::string>>;

std::tuple<int64_t, int64_t, int64_t, int64_t, std::string> get_info_file(
const std::string& path,
const c10::optional<std::string>& format);
const std::optional<std::string>& format);

std::tuple<torch::Tensor, int64_t> load_audio_file(
const std::string& path,
const c10::optional<int64_t>& frame_offset,
const c10::optional<int64_t>& num_frames,
c10::optional<bool> normalize,
c10::optional<bool> channels_first,
const c10::optional<std::string>& format);
const std::optional<int64_t>& frame_offset,
const std::optional<int64_t>& num_frames,
std::optional<bool> normalize,
std::optional<bool> channels_first,
const std::optional<std::string>& format);

void save_audio_file(
const std::string& path,
torch::Tensor tensor,
int64_t sample_rate,
bool channels_first,
c10::optional<double> compression,
c10::optional<std::string> format,
c10::optional<std::string> encoding,
c10::optional<int64_t> bits_per_sample);
std::optional<double> compression,
std::optional<std::string> format,
std::optional<std::string> encoding,
std::optional<int64_t> bits_per_sample);

} // namespace torchaudio::sox

Expand Down
4 changes: 2 additions & 2 deletions src/libtorchaudio/sox/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ std::string to_string(Encoding v) {
}
}

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

BitDepth get_bit_depth_from_option(const c10::optional<int64_t>& bit_depth) {
BitDepth get_bit_depth_from_option(const std::optional<int64_t>& bit_depth) {
if (!bit_depth.has_value())
return BitDepth::NOT_PROVIDED;
int64_t v = bit_depth.value();
Expand Down
4 changes: 2 additions & 2 deletions src/libtorchaudio/sox/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ enum class Encoding {
};

std::string to_string(Encoding v);
Encoding get_encoding_from_option(const c10::optional<std::string>& encoding);
Encoding get_encoding_from_option(const std::optional<std::string>& encoding);

enum class BitDepth : unsigned {
NOT_PROVIDED = 0,
Expand All @@ -49,7 +49,7 @@ enum class BitDepth : unsigned {
B64 = 64,
};

BitDepth get_bit_depth_from_option(const c10::optional<int64_t>& bit_depth);
BitDepth get_bit_depth_from_option(const std::optional<int64_t>& bit_depth);

std::string get_encoding(sox_encoding_t encoding);

Expand Down
10 changes: 5 additions & 5 deletions src/libtorchaudio/sox/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ std::tuple<sox_encoding_t, unsigned> get_save_encoding_for_wav(
std::tuple<sox_encoding_t, unsigned> get_save_encoding(
const std::string& format,
const caffe2::TypeMeta& dtype,
const c10::optional<std::string>& encoding,
const c10::optional<int64_t>& bits_per_sample) {
const std::optional<std::string>& encoding,
const std::optional<int64_t>& bits_per_sample) {
const Format fmt = get_format_from_string(format);
const Encoding enc = get_encoding_from_option(encoding);
const BitDepth bps = get_bit_depth_from_option(bits_per_sample);
Expand Down Expand Up @@ -492,9 +492,9 @@ sox_encodinginfo_t get_tensor_encodinginfo(caffe2::TypeMeta dtype) {
sox_encodinginfo_t get_encodinginfo_for_save(
const std::string& format,
const caffe2::TypeMeta& dtype,
const c10::optional<double>& compression,
const c10::optional<std::string>& encoding,
const c10::optional<int64_t>& bits_per_sample) {
const std::optional<double>& compression,
const std::optional<std::string>& encoding,
const std::optional<int64_t>& bits_per_sample) {
auto enc = get_save_encoding(format, dtype, encoding, bits_per_sample);
return sox_encodinginfo_t{
/*encoding=*/std::get<0>(enc),
Expand Down
6 changes: 3 additions & 3 deletions src/libtorchaudio/sox/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ sox_encodinginfo_t get_tensor_encodinginfo(const caffe2::TypeMeta dtype);
sox_encodinginfo_t get_encodinginfo_for_save(
const std::string& format,
const caffe2::TypeMeta& dtype,
const c10::optional<double>& compression,
const c10::optional<std::string>& encoding,
const c10::optional<int64_t>& bits_per_sample);
const std::optional<double>& compression,
const std::optional<std::string>& encoding,
const std::optional<int64_t>& bits_per_sample);

} // namespace torchaudio::sox
#endif
2 changes: 1 addition & 1 deletion src/libtorchaudio/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ bool is_align_available() {
#endif
}

c10::optional<int64_t> cuda_version() {
std::optional<int64_t> cuda_version() {
#ifdef USE_CUDA
return CUDA_VERSION;
#else
Expand Down
2 changes: 1 addition & 1 deletion src/libtorchaudio/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
namespace torchaudio {
bool is_rir_available();
bool is_align_available();
c10::optional<int64_t> cuda_version();
std::optional<int64_t> cuda_version();
} // namespace torchaudio
2 changes: 1 addition & 1 deletion src/libtorio/ffmpeg/ffmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace torio::io {
////////////////////////////////////////////////////////////////////////////////
// AVDictionary
////////////////////////////////////////////////////////////////////////////////
AVDictionary* get_option_dict(const c10::optional<OptionDict>& option) {
AVDictionary* get_option_dict(const std::optional<OptionDict>& option) {
AVDictionary* opt = nullptr;
if (option) {
for (auto const& [key, value] : option.value()) {
Expand Down
2 changes: 1 addition & 1 deletion src/libtorio/ffmpeg/ffmpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Wrapper {
// IIRC-semantic. Instead we provide helper functions.

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

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

0 comments on commit 0129429

Please sign in to comment.