From e3e919c11a723981adb73c150348474952327e93 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Tue, 16 Apr 2024 09:46:15 +0800 Subject: [PATCH] Fix code style issues (#774) --- sherpa-onnx/csrc/features.cc | 5 ++--- sherpa-onnx/csrc/offline-lm-config.cc | 2 +- .../csrc/offline-recognizer-transducer-impl.h | 10 ++++------ .../offline-transducer-greedy-search-decoder.h | 3 +-- sherpa-onnx/csrc/offline-websocket-server-impl.cc | 6 +++--- sherpa-onnx/csrc/online-lm-config.cc | 2 +- sherpa-onnx/csrc/online-lm-config.h | 2 +- sherpa-onnx/csrc/online-model-config.h | 3 +-- .../csrc/online-recognizer-transducer-impl.h | 8 ++++---- sherpa-onnx/csrc/online-recognizer.h | 2 +- sherpa-onnx/csrc/online-rnn-lm.cc | 7 +++---- .../online-transducer-greedy-search-decoder.cc | 15 +++++++-------- .../online-transducer-greedy-search-decoder.h | 3 +-- sherpa-onnx/csrc/online-transducer-model.h | 2 +- ...ine-transducer-modified-beam-search-decoder.cc | 2 +- sherpa-onnx/csrc/stack-test.cc | 12 ++++++------ sherpa-onnx/python/csrc/features.cc | 6 ++---- sherpa-onnx/python/csrc/offline-recognizer.cc | 3 +-- .../csrc/offline-transducer-model-config.cc | 3 +-- sherpa-onnx/python/csrc/online-model-config.cc | 6 +++--- 20 files changed, 45 insertions(+), 57 deletions(-) diff --git a/sherpa-onnx/csrc/features.cc b/sherpa-onnx/csrc/features.cc index 7e510361a8..c2d941e070 100644 --- a/sherpa-onnx/csrc/features.cc +++ b/sherpa-onnx/csrc/features.cc @@ -26,8 +26,7 @@ void FeatureExtractorConfig::Register(ParseOptions *po) { po->Register("feat-dim", &feature_dim, "Feature dimension. Must match the one expected by the model."); - po->Register("low-freq", &low_freq, - "Low cutoff frequency for mel bins"); + po->Register("low-freq", &low_freq, "Low cutoff frequency for mel bins"); po->Register("high-freq", &high_freq, "High cutoff frequency for mel bins " @@ -67,7 +66,7 @@ class FeatureExtractor::Impl { opts_.mel_opts.num_bins = config.feature_dim; opts_.mel_opts.high_freq = config.high_freq; - opts_.mel_opts.low_freq = config.low_freq; + opts_.mel_opts.low_freq = config.low_freq; opts_.mel_opts.is_librosa = config.is_librosa; diff --git a/sherpa-onnx/csrc/offline-lm-config.cc b/sherpa-onnx/csrc/offline-lm-config.cc index 262d91f01d..078e56fab7 100644 --- a/sherpa-onnx/csrc/offline-lm-config.cc +++ b/sherpa-onnx/csrc/offline-lm-config.cc @@ -15,7 +15,7 @@ void OfflineLMConfig::Register(ParseOptions *po) { po->Register("lm", &model, "Path to LM model."); po->Register("lm-scale", &scale, "LM scale."); po->Register("lm-num-threads", &lm_num_threads, - "Number of threads to run the neural network of LM model"); + "Number of threads to run the neural network of LM model"); po->Register("lm-provider", &lm_provider, "Specify a provider to LM model use: cpu, cuda, coreml"); } diff --git a/sherpa-onnx/csrc/offline-recognizer-transducer-impl.h b/sherpa-onnx/csrc/offline-recognizer-transducer-impl.h index de9f6263b0..68ec63a3ac 100644 --- a/sherpa-onnx/csrc/offline-recognizer-transducer-impl.h +++ b/sherpa-onnx/csrc/offline-recognizer-transducer-impl.h @@ -80,9 +80,8 @@ class OfflineRecognizerTransducerImpl : public OfflineRecognizerImpl { InitHotwords(); } if (config_.decoding_method == "greedy_search") { - decoder_ = - std::make_unique( - model_.get(), config_.blank_penalty); + decoder_ = std::make_unique( + model_.get(), config_.blank_penalty); } else if (config_.decoding_method == "modified_beam_search") { if (!config_.lm_config.model.empty()) { lm_ = OfflineLM::Create(config.lm_config); @@ -106,9 +105,8 @@ class OfflineRecognizerTransducerImpl : public OfflineRecognizerImpl { model_(std::make_unique(mgr, config_.model_config)) { if (config_.decoding_method == "greedy_search") { - decoder_ = - std::make_unique( - model_.get(), config_.blank_penalty); + decoder_ = std::make_unique( + model_.get(), config_.blank_penalty); } else if (config_.decoding_method == "modified_beam_search") { if (!config_.lm_config.model.empty()) { lm_ = OfflineLM::Create(mgr, config.lm_config); diff --git a/sherpa-onnx/csrc/offline-transducer-greedy-search-decoder.h b/sherpa-onnx/csrc/offline-transducer-greedy-search-decoder.h index f90ce91175..ca638c976b 100644 --- a/sherpa-onnx/csrc/offline-transducer-greedy-search-decoder.h +++ b/sherpa-onnx/csrc/offline-transducer-greedy-search-decoder.h @@ -16,8 +16,7 @@ class OfflineTransducerGreedySearchDecoder : public OfflineTransducerDecoder { public: explicit OfflineTransducerGreedySearchDecoder(OfflineTransducerModel *model, float blank_penalty) - : model_(model), - blank_penalty_(blank_penalty) {} + : model_(model), blank_penalty_(blank_penalty) {} std::vector Decode( Ort::Value encoder_out, Ort::Value encoder_out_length, diff --git a/sherpa-onnx/csrc/offline-websocket-server-impl.cc b/sherpa-onnx/csrc/offline-websocket-server-impl.cc index d3f9310af0..b34ebcaa9b 100644 --- a/sherpa-onnx/csrc/offline-websocket-server-impl.cc +++ b/sherpa-onnx/csrc/offline-websocket-server-impl.cc @@ -102,9 +102,9 @@ void OfflineWebsocketDecoder::Decode() { asio::post(server_->GetConnectionContext(), [this, hdl, result = ss[i]->GetResult()]() { websocketpp::lib::error_code ec; - server_->GetServer().send( - hdl, result.AsJsonString(), - websocketpp::frame::opcode::text, ec); + server_->GetServer().send(hdl, result.AsJsonString(), + websocketpp::frame::opcode::text, + ec); if (ec) { server_->GetServer().get_alog().write( websocketpp::log::alevel::app, ec.message()); diff --git a/sherpa-onnx/csrc/online-lm-config.cc b/sherpa-onnx/csrc/online-lm-config.cc index d5b41d2b66..af75d1667e 100644 --- a/sherpa-onnx/csrc/online-lm-config.cc +++ b/sherpa-onnx/csrc/online-lm-config.cc @@ -15,7 +15,7 @@ void OnlineLMConfig::Register(ParseOptions *po) { po->Register("lm", &model, "Path to LM model."); po->Register("lm-scale", &scale, "LM scale."); po->Register("lm-num-threads", &lm_num_threads, - "Number of threads to run the neural network of LM model"); + "Number of threads to run the neural network of LM model"); po->Register("lm-provider", &lm_provider, "Specify a provider to LM model use: cpu, cuda, coreml"); } diff --git a/sherpa-onnx/csrc/online-lm-config.h b/sherpa-onnx/csrc/online-lm-config.h index 90bc13d9e8..16d7b08870 100644 --- a/sherpa-onnx/csrc/online-lm-config.h +++ b/sherpa-onnx/csrc/online-lm-config.h @@ -22,7 +22,7 @@ struct OnlineLMConfig { OnlineLMConfig() = default; OnlineLMConfig(const std::string &model, float scale, int32_t lm_num_threads, - const std::string &lm_provider) + const std::string &lm_provider) : model(model), scale(scale), lm_num_threads(lm_num_threads), diff --git a/sherpa-onnx/csrc/online-model-config.h b/sherpa-onnx/csrc/online-model-config.h index d961686727..3857ee426f 100644 --- a/sherpa-onnx/csrc/online-model-config.h +++ b/sherpa-onnx/csrc/online-model-config.h @@ -40,8 +40,7 @@ struct OnlineModelConfig { const OnlineWenetCtcModelConfig &wenet_ctc, const OnlineZipformer2CtcModelConfig &zipformer2_ctc, const std::string &tokens, int32_t num_threads, - int32_t warm_up, bool debug, - const std::string &provider, + int32_t warm_up, bool debug, const std::string &provider, const std::string &model_type) : transducer(transducer), paraformer(paraformer), diff --git a/sherpa-onnx/csrc/online-recognizer-transducer-impl.h b/sherpa-onnx/csrc/online-recognizer-transducer-impl.h index add0b85d61..23fad3df11 100644 --- a/sherpa-onnx/csrc/online-recognizer-transducer-impl.h +++ b/sherpa-onnx/csrc/online-recognizer-transducer-impl.h @@ -30,9 +30,9 @@ #include "sherpa-onnx/csrc/online-transducer-greedy-search-decoder.h" #include "sherpa-onnx/csrc/online-transducer-model.h" #include "sherpa-onnx/csrc/online-transducer-modified-beam-search-decoder.h" +#include "sherpa-onnx/csrc/onnx-utils.h" #include "sherpa-onnx/csrc/symbol-table.h" #include "sherpa-onnx/csrc/utils.h" -#include "sherpa-onnx/csrc/onnx-utils.h" namespace sherpa_onnx { @@ -185,7 +185,7 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl { } // Warmping up engine with wp: warm_up count and max-batch-size - void WarmpUpRecognizer(int32_t warmup, int32_t mbs) const { + void WarmpUpRecognizer(int32_t warmup, int32_t mbs) const override { auto max_batch_size = mbs; if (warmup <= 0 || warmup > 100) { return; @@ -210,8 +210,8 @@ class OnlineRecognizerTransducerImpl : public OnlineRecognizerImpl { for (int32_t i = 0; i != warmup; ++i) { auto states = model_->StackStates(states_vec); Ort::Value x = Ort::Value::CreateTensor(memory_info, features_vec.data(), - features_vec.size(), x_shape.data(), - x_shape.size()); + features_vec.size(), + x_shape.data(), x_shape.size()); auto x_copy = Clone(model_->Allocator(), &x); auto pair = model_->RunEncoder(std::move(x), std::move(states), std::move(x_copy)); diff --git a/sherpa-onnx/csrc/online-recognizer.h b/sherpa-onnx/csrc/online-recognizer.h index c1d2e9a741..308cb08f7d 100644 --- a/sherpa-onnx/csrc/online-recognizer.h +++ b/sherpa-onnx/csrc/online-recognizer.h @@ -168,7 +168,7 @@ class OnlineRecognizer { * * @param warmup Number of warmups. * @param mbs : max-batch-size Max batch size for the models - */ + */ void WarmpUpRecognizer(int32_t warmup, int32_t mbs) const; /** Decode multiple streams in parallel diff --git a/sherpa-onnx/csrc/online-rnn-lm.cc b/sherpa-onnx/csrc/online-rnn-lm.cc index ff493c9301..5f938529b1 100644 --- a/sherpa-onnx/csrc/online-rnn-lm.cc +++ b/sherpa-onnx/csrc/online-rnn-lm.cc @@ -12,8 +12,8 @@ #include "onnxruntime_cxx_api.h" // NOLINT #include "sherpa-onnx/csrc/macros.h" #include "sherpa-onnx/csrc/onnx-utils.h" -#include "sherpa-onnx/csrc/text-utils.h" #include "sherpa-onnx/csrc/session.h" +#include "sherpa-onnx/csrc/text-utils.h" namespace sherpa_onnx { @@ -42,10 +42,9 @@ class OnlineRnnLM::Impl { // nn_lm_scores std::array x_shape{1, 1}; Ort::Value x = Ort::Value::CreateTensor(allocator_, x_shape.data(), - x_shape.size()); + x_shape.size()); *x.GetTensorMutableData() = hyp->ys.back(); - auto lm_out = - ScoreToken(std::move(x), Convert(hyp->nn_lm_states)); + auto lm_out = ScoreToken(std::move(x), Convert(hyp->nn_lm_states)); hyp->nn_lm_scores.value = std::move(lm_out.first); hyp->nn_lm_states = Convert(std::move(lm_out.second)); } diff --git a/sherpa-onnx/csrc/online-transducer-greedy-search-decoder.cc b/sherpa-onnx/csrc/online-transducer-greedy-search-decoder.cc index c026e28a49..05523dbb3f 100644 --- a/sherpa-onnx/csrc/online-transducer-greedy-search-decoder.cc +++ b/sherpa-onnx/csrc/online-transducer-greedy-search-decoder.cc @@ -71,11 +71,9 @@ void OnlineTransducerGreedySearchDecoder::StripLeadingBlanks( r->tokens = std::vector(start, end); } - void OnlineTransducerGreedySearchDecoder::Decode( Ort::Value encoder_out, std::vector *result) { - std::vector encoder_out_shape = encoder_out.GetTensorTypeAndShapeInfo().GetShape(); @@ -106,7 +104,8 @@ void OnlineTransducerGreedySearchDecoder::Decode( r.decoder_out.GetTensorTypeAndShapeInfo().GetShape(); decoder_out_shape[0] = batch_size; decoder_out = Ort::Value::CreateTensor(model_->Allocator(), - decoder_out_shape.data(), decoder_out_shape.size()); + decoder_out_shape.data(), + decoder_out_shape.size()); UseCachedDecoderOut(*result, &decoder_out); } else { Ort::Value decoder_input = model_->BuildDecoderInput(*result); @@ -116,8 +115,8 @@ void OnlineTransducerGreedySearchDecoder::Decode( for (int32_t t = 0; t != num_frames; ++t) { Ort::Value cur_encoder_out = GetEncoderOutFrame(model_->Allocator(), &encoder_out, t); - Ort::Value logit = model_->RunJoiner( - std::move(cur_encoder_out), View(&decoder_out)); + Ort::Value logit = + model_->RunJoiner(std::move(cur_encoder_out), View(&decoder_out)); float *p_logit = logit.GetTensorMutableData(); @@ -145,9 +144,9 @@ void OnlineTransducerGreedySearchDecoder::Decode( // export the per-token log scores if (y != 0 && y != unk_id_) { - LogSoftmax(p_logit, vocab_size); // renormalize probabilities, - // save time by doing it only for - // emitted symbols + LogSoftmax(p_logit, vocab_size); // renormalize probabilities, + // save time by doing it only for + // emitted symbols const float *p_logprob = p_logit; // rename p_logit as p_logprob, // now it contains normalized // probability diff --git a/sherpa-onnx/csrc/online-transducer-greedy-search-decoder.h b/sherpa-onnx/csrc/online-transducer-greedy-search-decoder.h index dd9faf8e8d..c68c32dcf0 100644 --- a/sherpa-onnx/csrc/online-transducer-greedy-search-decoder.h +++ b/sherpa-onnx/csrc/online-transducer-greedy-search-decoder.h @@ -15,8 +15,7 @@ namespace sherpa_onnx { class OnlineTransducerGreedySearchDecoder : public OnlineTransducerDecoder { public: OnlineTransducerGreedySearchDecoder(OnlineTransducerModel *model, - int32_t unk_id, - float blank_penalty) + int32_t unk_id, float blank_penalty) : model_(model), unk_id_(unk_id), blank_penalty_(blank_penalty) {} OnlineTransducerDecoderResult GetEmptyResult() const override; diff --git a/sherpa-onnx/csrc/online-transducer-model.h b/sherpa-onnx/csrc/online-transducer-model.h index bb763a9326..3e248ec947 100644 --- a/sherpa-onnx/csrc/online-transducer-model.h +++ b/sherpa-onnx/csrc/online-transducer-model.h @@ -69,7 +69,7 @@ class OnlineTransducerModel { * This has to be called before GetEncoderInitStates(), so the `encoder_embed` * init state has the correct `embed_dim` of its output. */ - virtual void SetFeatureDim(int32_t feature_dim) { } + virtual void SetFeatureDim(int32_t feature_dim) {} /** Run the encoder. * diff --git a/sherpa-onnx/csrc/online-transducer-modified-beam-search-decoder.cc b/sherpa-onnx/csrc/online-transducer-modified-beam-search-decoder.cc index 5357974dfd..84fb460595 100644 --- a/sherpa-onnx/csrc/online-transducer-modified-beam-search-decoder.cc +++ b/sherpa-onnx/csrc/online-transducer-modified-beam-search-decoder.cc @@ -188,7 +188,7 @@ void OnlineTransducerModifiedBeamSearchDecoder::Decode( // score of the transducer // export the per-token log scores if (new_token != 0 && new_token != unk_id_) { - const Hypothesis& prev_i = prev[hyp_index]; + const Hypothesis &prev_i = prev[hyp_index]; // subtract 'prev[i]' path scores, which were added before // getting topk tokens float y_prob = p_logprob[k] - prev_i.log_prob - prev_i.lm_log_prob; diff --git a/sherpa-onnx/csrc/stack-test.cc b/sherpa-onnx/csrc/stack-test.cc index 45a8dfaaeb..519015b5c8 100644 --- a/sherpa-onnx/csrc/stack-test.cc +++ b/sherpa-onnx/csrc/stack-test.cc @@ -16,10 +16,10 @@ TEST(Stack, Test1DTensors) { std::array b_shape{3}; Ort::Value a = Ort::Value::CreateTensor(allocator, a_shape.data(), - a_shape.size()); + a_shape.size()); Ort::Value b = Ort::Value::CreateTensor(allocator, b_shape.data(), - b_shape.size()); + b_shape.size()); float *pa = a.GetTensorMutableData(); float *pb = b.GetTensorMutableData(); for (int32_t i = 0; i != static_cast(a_shape[0]); ++i) { @@ -51,11 +51,11 @@ TEST(Stack, Test2DTensorsDim0) { std::array a_shape{2, 3}; std::array b_shape{2, 3}; - Ort::Value a = Ort::Value::CreateTensor( - allocator, a_shape.data(), a_shape.size()); + Ort::Value a = Ort::Value::CreateTensor(allocator, a_shape.data(), + a_shape.size()); - Ort::Value b = Ort::Value::CreateTensor( - allocator, b_shape.data(), b_shape.size()); + Ort::Value b = Ort::Value::CreateTensor(allocator, b_shape.data(), + b_shape.size()); float *pa = a.GetTensorMutableData(); float *pb = b.GetTensorMutableData(); diff --git a/sherpa-onnx/python/csrc/features.cc b/sherpa-onnx/python/csrc/features.cc index 333c6b6758..4f179999ac 100644 --- a/sherpa-onnx/python/csrc/features.cc +++ b/sherpa-onnx/python/csrc/features.cc @@ -12,10 +12,8 @@ static void PybindFeatureExtractorConfig(py::module *m) { using PyClass = FeatureExtractorConfig; py::class_(*m, "FeatureExtractorConfig") .def(py::init(), - py::arg("sampling_rate") = 16000, - py::arg("feature_dim") = 80, - py::arg("low_freq") = 20.0f, - py::arg("high_freq") = -400.0f, + py::arg("sampling_rate") = 16000, py::arg("feature_dim") = 80, + py::arg("low_freq") = 20.0f, py::arg("high_freq") = -400.0f, py::arg("dither") = 0.0f) .def_readwrite("sampling_rate", &PyClass::sampling_rate) .def_readwrite("feature_dim", &PyClass::feature_dim) diff --git a/sherpa-onnx/python/csrc/offline-recognizer.cc b/sherpa-onnx/python/csrc/offline-recognizer.cc index c0ebf7a82b..823e280fad 100644 --- a/sherpa-onnx/python/csrc/offline-recognizer.cc +++ b/sherpa-onnx/python/csrc/offline-recognizer.cc @@ -23,8 +23,7 @@ static void PybindOfflineRecognizerConfig(py::module *m) { py::arg("ctc_fst_decoder_config") = OfflineCtcFstDecoderConfig(), py::arg("decoding_method") = "greedy_search", py::arg("max_active_paths") = 4, py::arg("hotwords_file") = "", - py::arg("hotwords_score") = 1.5, - py::arg("blank_penalty") = 0.0) + py::arg("hotwords_score") = 1.5, py::arg("blank_penalty") = 0.0) .def_readwrite("feat_config", &PyClass::feat_config) .def_readwrite("model_config", &PyClass::model_config) .def_readwrite("lm_config", &PyClass::lm_config) diff --git a/sherpa-onnx/python/csrc/offline-transducer-model-config.cc b/sherpa-onnx/python/csrc/offline-transducer-model-config.cc index 9d5999036b..6d8f328ae8 100644 --- a/sherpa-onnx/python/csrc/offline-transducer-model-config.cc +++ b/sherpa-onnx/python/csrc/offline-transducer-model-config.cc @@ -4,7 +4,6 @@ #include "sherpa-onnx/python/csrc/offline-transducer-model-config.h" - #include #include @@ -16,7 +15,7 @@ void PybindOfflineTransducerModelConfig(py::module *m) { using PyClass = OfflineTransducerModelConfig; py::class_(*m, "OfflineTransducerModelConfig") .def(py::init(), + const std::string &>(), py::arg("encoder_filename"), py::arg("decoder_filename"), py::arg("joiner_filename")) .def_readwrite("encoder_filename", &PyClass::encoder_filename) diff --git a/sherpa-onnx/python/csrc/online-model-config.cc b/sherpa-onnx/python/csrc/online-model-config.cc index 2b4a8776b2..473be930fe 100644 --- a/sherpa-onnx/python/csrc/online-model-config.cc +++ b/sherpa-onnx/python/csrc/online-model-config.cc @@ -27,9 +27,9 @@ void PybindOnlineModelConfig(py::module *m) { .def(py::init(), + const OnlineZipformer2CtcModelConfig &, const std::string &, + int32_t, int32_t, bool, const std::string &, + const std::string &>(), py::arg("transducer") = OnlineTransducerModelConfig(), py::arg("paraformer") = OnlineParaformerModelConfig(), py::arg("wenet_ctc") = OnlineWenetCtcModelConfig(),