Commit cb8fa04c authored by Nikita Shulga's avatar Nikita Shulga Committed by Facebook GitHub Bot
Browse files

Do not use nested namespaces in torchaudio/sox (#2663)

Summary:
As it is a C++17 feature, and PyTorch and its extensions must still be C++14 compatible, as also specified in the top level CMakeLists.txt:
https://github.com/pytorch/audio/blob/8a0d7b36f7821fe55175f0d4e3ca6299b3817a6c/CMakeLists.txt#L30

Otherwise, it pollutes build logs with noisy
```
/Users/runner/work/test-infra/test-infra/pytorch/audio/torchaudio/csrc/sox/pybind/io.cpp:12:21: warning: nested namespace definition is a C++17 extension; define each namespace separately [-Wc++17-extensions]
namespace torchaudio::sox_io {
                    ^~~~~~~~
                     { namespace sox_io
```

Pull Request resolved: https://github.com/pytorch/audio/pull/2663

Reviewed By: atalman, nateanl

Differential Revision: D39362842

Pulled By: malfet

fbshipit-source-id: f9659d4420f1cc0194990d531455cf59b66c26b9
parent ec0e3a80
......@@ -24,6 +24,7 @@ cppcoreguidelines-*,
hicpp-exception-baseclass,
hicpp-avoid-goto,
modernize-*,
-modernize-concat-nested-namespaces,
-modernize-return-braced-init-list,
-modernize-use-auto,
-modernize-use-default-member-init,
......
......@@ -5,7 +5,8 @@
using namespace torchaudio::sox_utils;
namespace torchaudio::sox_effects {
namespace torchaudio {
namespace sox_effects {
namespace {
......@@ -152,4 +153,5 @@ TORCH_LIBRARY_FRAGMENT(torchaudio, m) {
&torchaudio::sox_effects::apply_effects_file);
}
} // namespace torchaudio::sox_effects
} // namespace sox_effects
} // namespace torchaudio
......@@ -4,7 +4,8 @@
#include <torch/script.h>
#include <torchaudio/csrc/sox/utils.h>
namespace torchaudio::sox_effects {
namespace torchaudio {
namespace sox_effects {
void initialize_sox_effects();
......@@ -24,6 +25,7 @@ auto apply_effects_file(
const c10::optional<std::string>& format)
-> c10::optional<std::tuple<torch::Tensor, int64_t>>;
} // namespace torchaudio::sox_effects
} // namespace sox_effects
} // namespace torchaudio
#endif
......@@ -4,7 +4,8 @@
using namespace torchaudio::sox_utils;
namespace torchaudio::sox_effects {
namespace torchaudio {
namespace sox_effects {
// Streaming decoding over file-like object is tricky because libsox operates on
// FILE pointer. The folloing is what `sox` and `play` commands do
......@@ -118,4 +119,5 @@ auto apply_effects_fileobj(
tensor, static_cast<int64_t>(chain.getOutputSampleRate()));
}
} // namespace torchaudio::sox_effects
} // namespace sox_effects
} // namespace torchaudio
......@@ -3,7 +3,8 @@
#include <torch/extension.h>
namespace torchaudio::sox_effects {
namespace torchaudio {
namespace sox_effects {
auto apply_effects_fileobj(
py::object fileobj,
......@@ -13,6 +14,7 @@ auto apply_effects_fileobj(
c10::optional<std::string> format)
-> c10::optional<std::tuple<torch::Tensor, int64_t>>;
} // namespace torchaudio::sox_effects
} // namespace sox_effects
} // namespace torchaudio
#endif
......@@ -4,7 +4,8 @@
using namespace torchaudio::sox_utils;
namespace torchaudio::sox_effects_chain {
namespace torchaudio {
namespace sox_effects_chain {
namespace {
......@@ -232,4 +233,5 @@ void SoxEffectsChainPyBind::addOutputFileObj(
}
}
} // namespace torchaudio::sox_effects_chain
} // namespace sox_effects_chain
} // namespace torchaudio
......@@ -4,7 +4,8 @@
#include <torch/extension.h>
#include <torchaudio/csrc/sox/effects_chain.h>
namespace torchaudio::sox_effects_chain {
namespace torchaudio {
namespace sox_effects_chain {
class SoxEffectsChainPyBind : public SoxEffectsChain {
using SoxEffectsChain::SoxEffectsChain;
......@@ -23,6 +24,7 @@ class SoxEffectsChainPyBind : public SoxEffectsChain {
py::object* fileobj);
};
} // namespace torchaudio::sox_effects_chain
} // namespace sox_effects_chain
} // namespace torchaudio
#endif
......@@ -9,7 +9,8 @@
using namespace torchaudio::sox_utils;
namespace torchaudio::sox_io {
namespace torchaudio {
namespace sox_io {
auto get_info_fileobj(py::object fileobj, c10::optional<std::string> format)
-> c10::optional<MetaDataTuple> {
......@@ -190,4 +191,5 @@ void save_audio_fileobj(
fileobj.attr("write")(py::bytes(buffer.ptr, buffer.size));
}
} // namespace torchaudio::sox_io
} // namespace sox_io
} // namespace torchaudio
......@@ -3,7 +3,8 @@
#include <torch/extension.h>
namespace torchaudio::sox_io {
namespace torchaudio {
namespace sox_io {
using MetaDataTuple =
std::tuple<int64_t, int64_t, int64_t, int64_t, std::string>;
......@@ -30,6 +31,7 @@ void save_audio_fileobj(
c10::optional<std::string> encoding,
c10::optional<int64_t> bits_per_sample);
} // namespace torchaudio::sox_io
} // namespace sox_io
} // namespace torchaudio
#endif
#include <torchaudio/csrc/sox/pybind/utils.h>
namespace torchaudio::sox_utils {
namespace torchaudio {
namespace sox_utils {
auto read_fileobj(py::object* fileobj, const uint64_t size, char* buffer)
-> uint64_t {
......@@ -28,4 +29,5 @@ auto read_fileobj(py::object* fileobj, const uint64_t size, char* buffer)
return num_read;
}
} // namespace torchaudio::sox_utils
} // namespace sox_utils
} // namespace torchaudio
......@@ -3,10 +3,12 @@
#include <torch/extension.h>
namespace torchaudio::sox_utils {
namespace torchaudio {
namespace sox_utils {
auto read_fileobj(py::object* fileobj, uint64_t size, char* buffer) -> uint64_t;
} // namespace torchaudio::sox_utils
} // namespace sox_utils
} // namespace torchaudio
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment