From 713852d9570be808e96ad9fb61b92412c07dd79a Mon Sep 17 00:00:00 2001 From: zhenghaoz Date: Sun, 8 Nov 2026 23:06:42 +0800 Subject: [PATCH] style: group local, third-party and standard headers --- .clang-format | 11 +++++++++++ src/audio.cpp | 6 +++--- src/cli.cpp | 2 +- src/embedding.cpp | 4 ++-- src/graph.cpp | 2 ++ src/graph.h | 2 ++ src/model-loader.cpp | 7 ++++--- src/model-loader.h | 3 ++- src/model.cpp | 3 ++- src/model.h | 4 +++- src/models/clamp3.cpp | 3 ++- src/models/clap.cpp | 5 +++-- src/models/clap2.cpp | 3 ++- src/models/mert.cpp | 1 + src/models/mert2.cpp | 4 ++-- src/models/models.h | 5 +++-- src/models/muq.cpp | 3 ++- src/models/muq_mulan.cpp | 1 + src/quantization-policy.h | 1 + src/quantize-output.h | 4 ++-- src/quantize.cpp | 5 +++-- src/server.cpp | 6 +++--- src/tensor-data.cpp | 1 + src/tensor-data.h | 1 + src/vocab.cpp | 4 +++- src/vocab.h | 5 +++-- tests/abi-test.cpp | 3 ++- tests/all-quantization-test.cpp | 4 +++- tests/audio-path-test.cpp | 4 ++-- tests/audio-test.cpp | 4 +++- tests/bf16-test.cpp | 4 +++- tests/c-api-helpers.h | 1 + tests/graph-pipeline-test.cpp | 2 ++ tests/models/byte-bpe-test.cpp | 1 + tests/models/clamp3-bundled-test.cpp | 3 ++- tests/models/clamp3-model-test.cpp | 4 +++- tests/models/clap2-model-test.cpp | 2 +- tests/models/feature-extract-test.cpp | 1 + tests/models/feature-input-test.cpp | 1 + tests/models/feature-test.h | 1 + tests/models/mert-model-test.cpp | 3 ++- tests/models/mert2-fft-test.cpp | 13 +++++++------ tests/models/mert2-model-test.cpp | 2 +- tests/models/model-test.cpp | 4 +++- tests/models/muq-model-test.cpp | 4 +++- tests/models/muq-mulan-model-test.cpp | 4 +++- tests/models/unigram-test.cpp | 1 + tests/q8-test.cpp | 6 ++++-- tests/quantize-output-test.cpp | 1 + tests/tensor-ops-test.cpp | 2 ++ 50 files changed, 118 insertions(+), 53 deletions(-) diff --git a/.clang-format b/.clang-format index ec632a2..8f07062 100644 --- a/.clang-format +++ b/.clang-format @@ -3,3 +3,14 @@ IndentWidth: 4 ColumnLimit: 120 PointerAlignment: Right SortIncludes: CaseSensitive +IncludeBlocks: Regroup +IncludeCategories: + # Third-party headers may use either angle brackets or quotes. + - Regex: '^[<"](CLI/|ggml[^>]*\.h[>"]|gguf\.h[>"]|gtest/|httplib\.h[>"]|miniaudio\.h[>"]|nlohmann/|unicode/)' + Priority: 1 + # Keep the main header (implicitly priority 0) with other local headers. + - Regex: '^"' + Priority: 0 + # Standard library and platform headers. + - Regex: '.*' + Priority: 2 diff --git a/src/audio.cpp b/src/audio.cpp index 96f25bb..35deb9b 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -27,11 +27,10 @@ #define MA_NO_RUNTIME_LINKING #define MA_NO_ENCODING #define MA_NO_GENERATION -#include "miniaudio.h" - #include "audio.h" -#include +#include "miniaudio.h" + #include #include #include @@ -40,6 +39,7 @@ #include #include #include +#include namespace clap { diff --git a/src/cli.cpp b/src/cli.cpp index d99e13e..f03d2ca 100644 --- a/src/cli.cpp +++ b/src/cli.cpp @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "embedding.h" #include "clap.h" +#include "embedding.h" #include "quantize.h" #include "server.h" diff --git a/src/embedding.cpp b/src/embedding.cpp index 44ab8ce..51540f2 100644 --- a/src/embedding.cpp +++ b/src/embedding.cpp @@ -1,6 +1,6 @@ -#include "embedding.h" -#include "clap.h" #include "audio.h" +#include "clap.h" +#include "embedding.h" #include diff --git a/src/graph.cpp b/src/graph.cpp index 719dd8e..e1d02e0 100644 --- a/src/graph.cpp +++ b/src/graph.cpp @@ -1,5 +1,7 @@ #include "graph.h" + #include + #include #include #include diff --git a/src/graph.h b/src/graph.h index ed14e39..bd8e7bd 100644 --- a/src/graph.h +++ b/src/graph.h @@ -2,7 +2,9 @@ #include "model-loader.h" #include "tensor-data.h" + #include + #include #include #include diff --git a/src/model-loader.cpp b/src/model-loader.cpp index b091056..d792af9 100644 --- a/src/model-loader.cpp +++ b/src/model-loader.cpp @@ -1,11 +1,12 @@ #include "model-loader.h" #include "quantization-policy.h" #include "tensor-data.h" -#include -#include -#include + #include #include +#include +#include +#include #ifndef _WIN32 #include #include diff --git a/src/model-loader.h b/src/model-loader.h index 3ec8600..b45b155 100644 --- a/src/model-loader.h +++ b/src/model-loader.h @@ -2,12 +2,13 @@ #include #include + #include #include #include -#include #include #include +#include #include namespace clap { diff --git a/src/model.cpp b/src/model.cpp index 358d344..360309e 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -1,7 +1,8 @@ -#include "model.h" #include "audio.h" +#include "model.h" #include "models/models.h" #include "vocab.h" + #include CLAP::CLAP(const std::string &path, const clap::RuntimeOptions &options) : loader(options) { diff --git a/src/model.h b/src/model.h index e5ecd29..b189bdc 100644 --- a/src/model.h +++ b/src/model.h @@ -3,12 +3,14 @@ #include "clap.h" #include "graph.h" #include "model-loader.h" + +#include + #include #include #include #include #include -#include namespace clap { // Time-major waveform encoder output; values contains frames * dimension elements. diff --git a/src/models/clamp3.cpp b/src/models/clamp3.cpp index 5d9c663..f98e0cf 100644 --- a/src/models/clamp3.cpp +++ b/src/models/clamp3.cpp @@ -1,8 +1,9 @@ #include "models.h" -#include + #include #include #include +#include namespace clap::detail { using json = nlohmann::json; diff --git a/src/models/clap.cpp b/src/models/clap.cpp index d1f08d4..00bea66 100644 --- a/src/models/clap.cpp +++ b/src/models/clap.cpp @@ -1,9 +1,10 @@ -#include "models.h" #include "audio.h" -#include +#include "models.h" + #include #include #include +#include namespace clap::detail { using json = nlohmann::json; diff --git a/src/models/clap2.cpp b/src/models/clap2.cpp index 35b08de..9ed7189 100644 --- a/src/models/clap2.cpp +++ b/src/models/clap2.cpp @@ -1,5 +1,6 @@ -#include "model.h" #include "audio.h" +#include "model.h" + #include #include #include diff --git a/src/models/mert.cpp b/src/models/mert.cpp index 19c021f..5cea0f4 100644 --- a/src/models/mert.cpp +++ b/src/models/mert.cpp @@ -1,4 +1,5 @@ #include "models.h" + #include #include #include diff --git a/src/models/mert2.cpp b/src/models/mert2.cpp index 4577d01..055c733 100644 --- a/src/models/mert2.cpp +++ b/src/models/mert2.cpp @@ -1,11 +1,11 @@ -#include "models.h" #include "audio.h" +#include "models.h" -#include #include #include #include #include +#include namespace clap::detail { using json = nlohmann::json; diff --git a/src/models/models.h b/src/models/models.h index 66ba9f5..13facf0 100644 --- a/src/models/models.h +++ b/src/models/models.h @@ -1,9 +1,10 @@ #pragma once -#include "model.h" -#include "model-loader.h" #include "graph.h" +#include "model-loader.h" #include "model-weights.h" +#include "model.h" + #include namespace clap::detail { diff --git a/src/models/muq.cpp b/src/models/muq.cpp index 32e5da8..0a5a9fd 100644 --- a/src/models/muq.cpp +++ b/src/models/muq.cpp @@ -1,5 +1,6 @@ -#include "models.h" #include "audio.h" +#include "models.h" + #include #include #include diff --git a/src/models/muq_mulan.cpp b/src/models/muq_mulan.cpp index 41bb6cf..7f425d5 100644 --- a/src/models/muq_mulan.cpp +++ b/src/models/muq_mulan.cpp @@ -1,4 +1,5 @@ #include "models.h" + #include #include #include diff --git a/src/quantization-policy.h b/src/quantization-policy.h index 1065b6f..1b8e631 100644 --- a/src/quantization-policy.h +++ b/src/quantization-policy.h @@ -1,5 +1,6 @@ #pragma once #include + #include #include diff --git a/src/quantize-output.h b/src/quantize-output.h index a211aa7..9af2c0c 100644 --- a/src/quantize-output.h +++ b/src/quantize-output.h @@ -2,13 +2,13 @@ #include #include +#include #include #include #include #include -#include -#include #include +#include #ifdef _WIN32 #include #include diff --git a/src/quantize.cpp b/src/quantize.cpp index 66e36aa..706dd64 100644 --- a/src/quantize.cpp +++ b/src/quantize.cpp @@ -1,14 +1,15 @@ #include "model-loader.h" +#include "quantization-policy.h" #include "quantize-output.h" #include "quantize.h" -#include "quantization-policy.h" -#include + #include #include #include #include #include #include +#include #include #include diff --git a/src/server.cpp b/src/server.cpp index 0ac3b6d..9afc64b 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1,6 +1,6 @@ -#include "server.h" -#include "clap.h" #include "audio.h" +#include "clap.h" +#include "server.h" #include #include @@ -9,8 +9,8 @@ #include #include #include -#include #include +#include #include #include diff --git a/src/tensor-data.cpp b/src/tensor-data.cpp index f184c47..501c53e 100644 --- a/src/tensor-data.cpp +++ b/src/tensor-data.cpp @@ -1,4 +1,5 @@ #include "tensor-data.h" + #include #include diff --git a/src/tensor-data.h b/src/tensor-data.h index d57d867..5bd4fdd 100644 --- a/src/tensor-data.h +++ b/src/tensor-data.h @@ -1,5 +1,6 @@ #pragma once #include + #include #include #include diff --git a/src/vocab.cpp b/src/vocab.cpp index 41ae1c8..98cc863 100644 --- a/src/vocab.cpp +++ b/src/vocab.cpp @@ -1,12 +1,14 @@ #include "vocab.h" -#include + #include #include + #include #include #include #include #include +#include namespace clap::detail { using json = nlohmann::json; diff --git a/src/vocab.h b/src/vocab.h index 3275bb9..15a6ec6 100644 --- a/src/vocab.h +++ b/src/vocab.h @@ -15,6 +15,9 @@ */ #pragma once +#include +#include + #include #include #include @@ -22,8 +25,6 @@ #include #include #include -#include -#include namespace clap::detail { diff --git a/tests/abi-test.cpp b/tests/abi-test.cpp index 9bd901c..77a7031 100644 --- a/tests/abi-test.cpp +++ b/tests/abi-test.cpp @@ -15,9 +15,10 @@ */ #include "clap.h" +#include + #include #include -#include #include namespace { diff --git a/tests/all-quantization-test.cpp b/tests/all-quantization-test.cpp index 69925aa..3cc986f 100644 --- a/tests/all-quantization-test.cpp +++ b/tests/all-quantization-test.cpp @@ -1,8 +1,10 @@ -#include "model-loader.h" #include "graph-test-helpers.h" +#include "model-loader.h" #include "quantize.h" + #include #include + #include #include #include diff --git a/tests/audio-path-test.cpp b/tests/audio-path-test.cpp index 6c95bc4..855ad8e 100644 --- a/tests/audio-path-test.cpp +++ b/tests/audio-path-test.cpp @@ -1,6 +1,6 @@ -#include "clap.h" -#include "c-api-helpers.h" #include "audio.h" +#include "c-api-helpers.h" +#include "clap.h" #include #include diff --git a/tests/audio-test.cpp b/tests/audio-test.cpp index 3ece4fc..a6dfd62 100644 --- a/tests/audio-test.cpp +++ b/tests/audio-test.cpp @@ -1,9 +1,11 @@ #include "audio.h" + +#include + #include #include #include #include -#include #include #include #include diff --git a/tests/bf16-test.cpp b/tests/bf16-test.cpp index bd8883b..4ba7628 100644 --- a/tests/bf16-test.cpp +++ b/tests/bf16-test.cpp @@ -1,8 +1,10 @@ -#include "model-loader.h" #include "graph-test-helpers.h" +#include "model-loader.h" #include "quantize.h" + #include #include + #include #include #include diff --git a/tests/c-api-helpers.h b/tests/c-api-helpers.h index 7944993..ace78b9 100644 --- a/tests/c-api-helpers.h +++ b/tests/c-api-helpers.h @@ -1,5 +1,6 @@ #pragma once #include "clap.h" + #include #include #include diff --git a/tests/graph-pipeline-test.cpp b/tests/graph-pipeline-test.cpp index d542ef2..76fe222 100644 --- a/tests/graph-pipeline-test.cpp +++ b/tests/graph-pipeline-test.cpp @@ -1,5 +1,7 @@ #include "graph.h" + #include + #include #include #include diff --git a/tests/models/byte-bpe-test.cpp b/tests/models/byte-bpe-test.cpp index d997ec0..db8e241 100644 --- a/tests/models/byte-bpe-test.cpp +++ b/tests/models/byte-bpe-test.cpp @@ -1,4 +1,5 @@ #include "vocab.h" + #include #include diff --git a/tests/models/clamp3-bundled-test.cpp b/tests/models/clamp3-bundled-test.cpp index 46ad3eb..3d9c2c2 100644 --- a/tests/models/clamp3-bundled-test.cpp +++ b/tests/models/clamp3-bundled-test.cpp @@ -1,7 +1,8 @@ -#include "clap.h" #include "../c-api-helpers.h" #include "audio.h" +#include "clap.h" #include "feature-test.h" + #include #include #include diff --git a/tests/models/clamp3-model-test.cpp b/tests/models/clamp3-model-test.cpp index 8aa10fa..fbf9db5 100644 --- a/tests/models/clamp3-model-test.cpp +++ b/tests/models/clamp3-model-test.cpp @@ -1,7 +1,9 @@ -#include "clap.h" #include "../c-api-helpers.h" +#include "clap.h" #include "feature-test.h" + #include + #include #include #include diff --git a/tests/models/clap2-model-test.cpp b/tests/models/clap2-model-test.cpp index f4f1f1a..ec42064 100644 --- a/tests/models/clap2-model-test.cpp +++ b/tests/models/clap2-model-test.cpp @@ -1,5 +1,5 @@ -#include "clap.h" #include "../c-api-helpers.h" +#include "clap.h" #include diff --git a/tests/models/feature-extract-test.cpp b/tests/models/feature-extract-test.cpp index c2f97c1..3d2b325 100644 --- a/tests/models/feature-extract-test.cpp +++ b/tests/models/feature-extract-test.cpp @@ -1,4 +1,5 @@ #include "feature-test.h" + #include // Test-only numerical-oracle bridge. Not part of the production CLI or install. diff --git a/tests/models/feature-input-test.cpp b/tests/models/feature-input-test.cpp index 8caff49..42aa2b1 100644 --- a/tests/models/feature-input-test.cpp +++ b/tests/models/feature-input-test.cpp @@ -1,4 +1,5 @@ #include "feature-test.h" + #include #include int main(int argc, char **argv) { diff --git a/tests/models/feature-test.h b/tests/models/feature-test.h index dbac2ec..58e8982 100644 --- a/tests/models/feature-test.h +++ b/tests/models/feature-test.h @@ -4,6 +4,7 @@ // independent of the bundled waveform pipeline. #include "../../src/models/models.h" #include "audio.h" + #include namespace clap::detail { struct FeatureTestAccess { diff --git a/tests/models/mert-model-test.cpp b/tests/models/mert-model-test.cpp index 4586ec0..20aed85 100644 --- a/tests/models/mert-model-test.cpp +++ b/tests/models/mert-model-test.cpp @@ -1,7 +1,8 @@ -#include "clap.h" #include "../c-api-helpers.h" #include "audio.h" +#include "clap.h" #include "feature-test.h" + #include #include #include diff --git a/tests/models/mert2-fft-test.cpp b/tests/models/mert2-fft-test.cpp index a7fad9c..c80e952 100644 --- a/tests/models/mert2-fft-test.cpp +++ b/tests/models/mert2-fft-test.cpp @@ -1,20 +1,20 @@ // Exercise the production FFT against a double direct DFT, not another FFT. #include "audio.h" + #include -#include -#include #include +#include #include #include #include +#include int main() { constexpr std::size_t n = 2048; std::vector> input(n); for (std::size_t i = 0; i < n; ++i) { const double t = (176.0 + i) / 24000.; - const float pcm = - static_cast(.19 * std::sin(2 * std::numbers::pi * (220 * t + 31 * t * t)) + - .03 * std::cos(2 * std::numbers::pi * 443 * t)); + const float pcm = static_cast(.19 * std::sin(2 * std::numbers::pi * (220 * t + 31 * t * t)) + + .03 * std::cos(2 * std::numbers::pi * 443 * t)); const float window = static_cast(.5 - .5 * std::cos(2 * std::numbers::pi * i / n)); input[i] = pcm * window; } @@ -25,7 +25,8 @@ int main() { for (std::size_t k = 0; k <= n / 2; ++k) { std::complex reference{}; for (std::size_t i = 0; i < n; ++i) - reference += static_cast(input[i].real()) * std::polar(1., -2 * std::numbers::pi * double(k * i) / n); + reference += + static_cast(input[i].real()) * std::polar(1., -2 * std::numbers::pi * double(k * i) / n); const std::complex expected(reference); complex_error = std::max(complex_error, double(std::abs(actual[k] - expected))); const double a = 10 * std::log10(std::max(double(std::norm(actual[k])), 1e-10)); diff --git a/tests/models/mert2-model-test.cpp b/tests/models/mert2-model-test.cpp index 7b57baa..460b270 100644 --- a/tests/models/mert2-model-test.cpp +++ b/tests/models/mert2-model-test.cpp @@ -1,5 +1,5 @@ -#include "clap.h" #include "../c-api-helpers.h" +#include "clap.h" #include diff --git a/tests/models/model-test.cpp b/tests/models/model-test.cpp index a618259..2fe4f34 100644 --- a/tests/models/model-test.cpp +++ b/tests/models/model-test.cpp @@ -1,8 +1,10 @@ -#include "clap.h" #include "../c-api-helpers.h" #include "audio.h" +#include "clap.h" #include "feature-test.h" + #include + #include #include #include diff --git a/tests/models/muq-model-test.cpp b/tests/models/muq-model-test.cpp index 8f13439..6895107 100644 --- a/tests/models/muq-model-test.cpp +++ b/tests/models/muq-model-test.cpp @@ -1,7 +1,9 @@ -#include "clap.h" #include "../c-api-helpers.h" #include "audio.h" +#include "clap.h" + #include + #include #include #include diff --git a/tests/models/muq-mulan-model-test.cpp b/tests/models/muq-mulan-model-test.cpp index 218eeae..e3baaa9 100644 --- a/tests/models/muq-mulan-model-test.cpp +++ b/tests/models/muq-mulan-model-test.cpp @@ -1,7 +1,9 @@ -#include "clap.h" #include "../c-api-helpers.h" #include "audio.h" +#include "clap.h" + #include + #include #include #include diff --git a/tests/models/unigram-test.cpp b/tests/models/unigram-test.cpp index e25918d..3b1274e 100644 --- a/tests/models/unigram-test.cpp +++ b/tests/models/unigram-test.cpp @@ -1,4 +1,5 @@ #include "vocab.h" + #include #include #include diff --git a/tests/q8-test.cpp b/tests/q8-test.cpp index 7471c76..2f0e6f2 100644 --- a/tests/q8-test.cpp +++ b/tests/q8-test.cpp @@ -1,15 +1,17 @@ -#include "model-loader.h" #include "graph-test-helpers.h" +#include "model-loader.h" + #include #include + #include #include -#include #include #include #include #include #include +#include #include using namespace clap::detail; diff --git a/tests/quantize-output-test.cpp b/tests/quantize-output-test.cpp index 735d15b..6263864 100644 --- a/tests/quantize-output-test.cpp +++ b/tests/quantize-output-test.cpp @@ -1,4 +1,5 @@ #include "quantize-output.h" + #include #include #include diff --git a/tests/tensor-ops-test.cpp b/tests/tensor-ops-test.cpp index 5d29763..7f55cdb 100644 --- a/tests/tensor-ops-test.cpp +++ b/tests/tensor-ops-test.cpp @@ -1,5 +1,7 @@ #include "graph-test-helpers.h" + #include + #include #include #include