From a6b2a0a697cade73112ab66dd7fef477e44e9577 Mon Sep 17 00:00:00 2001 From: Hui Zhang Date: Mon, 24 Oct 2022 09:28:38 +0000 Subject: [PATCH] cpplint --- .pre-commit-config.yaml | 9 +++- speechx/speechx/base/basic_types.h | 42 +++++++++---------- speechx/speechx/base/macros.h | 2 +- speechx/speechx/base/thread_pool.h | 2 +- .../codelab/nnet/ds2_model_test_main.cc | 4 +- .../decoder/ctc_beam_search_decoder.cc | 6 +-- .../speechx/decoder/ctc_beam_search_decoder.h | 2 +- .../decoder/ctc_beam_search_decoder_main.cc | 4 +- speechx/speechx/decoder/ctc_beam_search_opt.h | 2 +- .../decoder/ctc_prefix_beam_search_decoder.cc | 6 +-- .../decoder/ctc_prefix_beam_search_decoder.h | 2 +- .../ctc_prefix_beam_search_decoder_main.cc | 17 ++++---- speechx/speechx/decoder/ctc_tlg_decoder.h | 2 +- speechx/speechx/frontend/audio/cmvn.cc | 2 +- .../frontend/audio/compute_fbank_main.cc | 4 +- speechx/speechx/frontend/audio/data_cache.h | 2 +- speechx/speechx/frontend/audio/db_norm.cc | 7 ++-- speechx/speechx/frontend/audio/fbank.cc | 7 ++-- .../frontend/audio/feature_pipeline.cc | 2 +- .../frontend/audio/linear_spectrogram.cc | 7 ++-- speechx/speechx/frontend/audio/mfcc.cc | 7 ++-- speechx/speechx/nnet/ds2_nnet.cc | 9 ++-- speechx/speechx/nnet/ds2_nnet.h | 4 +- speechx/speechx/nnet/ds2_nnet_main.cc | 4 +- speechx/speechx/nnet/u2_nnet.cc | 40 +++++++++--------- speechx/speechx/nnet/u2_nnet.h | 4 +- speechx/speechx/nnet/u2_nnet_main.cc | 6 +-- .../websocket/websocket_client_main.cc | 2 +- speechx/speechx/recognizer/recognizer.h | 3 +- speechx/speechx/recognizer/recognizer_main.cc | 5 ++- speechx/speechx/recognizer/u2_recognizer.cc | 2 +- speechx/speechx/recognizer/u2_recognizer.h | 2 - speechx/speechx/utils/file_utils.cc | 2 +- 33 files changed, 118 insertions(+), 103 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6e7ae1fb..0435cfbe 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -50,13 +50,20 @@ repos: entry: bash .pre-commit-hooks/clang-format.hook -i language: system files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|cuh|proto)$ - exclude: (?=speechx/speechx/kaldi|speechx/patch|speechx/tools/fstbin|speechx/tools/lmbin).*(\.cpp|\.cc|\.h|\.py)$ + exclude: (?=speechx/speechx/kaldi|speechx/patch|speechx/tools/fstbin|speechx/tools/lmbin|third_party/ctc_decoders).*(\.cpp|\.cc|\.h|\.py)$ #- id: copyright_checker # name: copyright_checker # entry: python .pre-commit-hooks/copyright-check.hook # language: system # files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx|proto|py)$ # exclude: (?=third_party|pypinyin|speechx/speechx/kaldi|speechx/patch|speechx/tools/fstbin|speechx/tools/lmbin).*(\.cpp|\.cc|\.h|\.py)$ + - id: cpplint + name: cpplint + description: Static code analysis of C/C++ files + language: python + files: \.(h\+\+|h|hh|hxx|hpp|cuh|c|cc|cpp|cu|c\+\+|cxx|tpp|txx)$ + exclude: (?=speechx/speechx/kaldi|speechx/patch|speechx/tools/fstbin|speechx/tools/lmbin|third_party/ctc_decoders).*(\.cpp|\.cc|\.h|\.py)$ + entry: cpplint --filter=-build,-whitespace,+whitespace/comma,-whitespace/indent - repo: https://github.com/asottile/reorder_python_imports rev: v2.4.0 hooks: diff --git a/speechx/speechx/base/basic_types.h b/speechx/speechx/base/basic_types.h index 3a648649..96bc0ca5 100644 --- a/speechx/speechx/base/basic_types.h +++ b/speechx/speechx/base/basic_types.h @@ -22,39 +22,39 @@ typedef float BaseFloat; typedef double double64; typedef signed char int8; -typedef short int16; -typedef int int32; +typedef short int16; // NOLINT +typedef int int32; // NOLINT #if defined(__LP64__) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) -typedef long int64; +typedef long int64; // NOLINT #else -typedef long long int64; +typedef long long int64; // NOLINT #endif -typedef unsigned char uint8; -typedef unsigned short uint16; -typedef unsigned int uint32; +typedef unsigned char uint8; // NOLINT +typedef unsigned short uint16; // NOLINT +typedef unsigned int uint32; // NOLINT #if defined(__LP64__) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) -typedef unsigned long uint64; +typedef unsigned long uint64; // NOLINT #else -typedef unsigned long long uint64; +typedef unsigned long long uint64; // NOLINT #endif typedef signed int char32; -const uint8 kuint8max = ((uint8)0xFF); -const uint16 kuint16max = ((uint16)0xFFFF); -const uint32 kuint32max = ((uint32)0xFFFFFFFF); -const uint64 kuint64max = ((uint64)(0xFFFFFFFFFFFFFFFFLL)); -const int8 kint8min = ((int8)0x80); -const int8 kint8max = ((int8)0x7F); -const int16 kint16min = ((int16)0x8000); -const int16 kint16max = ((int16)0x7FFF); -const int32 kint32min = ((int32)0x80000000); -const int32 kint32max = ((int32)0x7FFFFFFF); -const int64 kint64min = ((int64)(0x8000000000000000LL)); -const int64 kint64max = ((int64)(0x7FFFFFFFFFFFFFFFLL)); +const uint8 kuint8max = (static_cast 0xFF); +const uint16 kuint16max = (static_cast 0xFFFF); +const uint32 kuint32max = (static_cast 0xFFFFFFFF); +const uint64 kuint64max = (static_cast(0xFFFFFFFFFFFFFFFFLL)); +const int8 kint8min = (static_cast 0x80); +const int8 kint8max = (static_cast 0x7F); +const int16 kint16min = (static_cast 0x8000); +const int16 kint16max = (static_cast 0x7FFF); +const int32 kint32min = (static_cast 0x80000000); +const int32 kint32max = (static_cast 0x7FFFFFFF); +const int64 kint64min = (static_cast(0x8000000000000000LL)); +const int64 kint64max = (static_cast(0x7FFFFFFFFFFFFFFFLL)); const BaseFloat kBaseFloatMax = std::numeric_limits::max(); const BaseFloat kBaseFloatMin = std::numeric_limits::min(); diff --git a/speechx/speechx/base/macros.h b/speechx/speechx/base/macros.h index faf39373..95608f40 100644 --- a/speechx/speechx/base/macros.h +++ b/speechx/speechx/base/macros.h @@ -26,6 +26,6 @@ namespace ppspeech { #endif // kSpaceSymbol in UTF-8 is: ▁ -const std::string kSpaceSymbol = "\xe2\x96\x81"; +const char[] kSpaceSymbol = "\xe2\x96\x81"; } // namespace ppspeech diff --git a/speechx/speechx/base/thread_pool.h b/speechx/speechx/base/thread_pool.h index ba895f71..6d59dac5 100644 --- a/speechx/speechx/base/thread_pool.h +++ b/speechx/speechx/base/thread_pool.h @@ -35,7 +35,7 @@ class ThreadPool { public: - ThreadPool(size_t); + explicit ThreadPool(size_t); template auto enqueue(F&& f, Args&&... args) -> std::future::type>; diff --git a/speechx/speechx/codelab/nnet/ds2_model_test_main.cc b/speechx/speechx/codelab/nnet/ds2_model_test_main.cc index 09f9e2fb..ab7b2cb5 100644 --- a/speechx/speechx/codelab/nnet/ds2_model_test_main.cc +++ b/speechx/speechx/codelab/nnet/ds2_model_test_main.cc @@ -64,8 +64,8 @@ void model_forward_test() { ; std::string model_graph = FLAGS_model_path; std::string model_params = FLAGS_param_path; - CHECK(model_graph != ""); - CHECK(model_params != ""); + CHECK_NE(model_graph, ""); + CHECK_NE(model_params, ""); cout << "model path: " << model_graph << endl; cout << "model param path : " << model_params << endl; diff --git a/speechx/speechx/decoder/ctc_beam_search_decoder.cc b/speechx/speechx/decoder/ctc_beam_search_decoder.cc index c4b35ff0..6e3a0d13 100644 --- a/speechx/speechx/decoder/ctc_beam_search_decoder.cc +++ b/speechx/speechx/decoder/ctc_beam_search_decoder.cc @@ -39,12 +39,12 @@ CTCBeamSearch::CTCBeamSearch(const CTCBeamSearchOptions& opts) opts_.alpha, opts_.beta, opts_.lm_path, vocabulary_); } - CHECK(opts_.blank == 0); + CHECK_EQ(opts_.blank, 0); auto it = std::find(vocabulary_.begin(), vocabulary_.end(), " "); space_id_ = it - vocabulary_.begin(); // if no space in vocabulary - if ((size_t)space_id_ >= vocabulary_.size()) { + if (static_cast(space_id_) >= vocabulary_.size()) { space_id_ = -2; } } @@ -104,7 +104,7 @@ void CTCBeamSearch::ResetPrefixes() { } int CTCBeamSearch::DecodeLikelihoods(const vector>& probs, - vector& nbest_words) { + const vector& nbest_words) { kaldi::Timer timer; AdvanceDecoding(probs); LOG(INFO) << "ctc decoding elapsed time(s) " diff --git a/speechx/speechx/decoder/ctc_beam_search_decoder.h b/speechx/speechx/decoder/ctc_beam_search_decoder.h index 6347bba8..f06d88e3 100644 --- a/speechx/speechx/decoder/ctc_beam_search_decoder.h +++ b/speechx/speechx/decoder/ctc_beam_search_decoder.h @@ -48,7 +48,7 @@ class CTCBeamSearch : public DecoderBase { } int DecodeLikelihoods(const std::vector>& probs, - std::vector& nbest_words); + const std::vector& nbest_words); private: void ResetPrefixes(); diff --git a/speechx/speechx/decoder/ctc_beam_search_decoder_main.cc b/speechx/speechx/decoder/ctc_beam_search_decoder_main.cc index edf9215a..ab0376b6 100644 --- a/speechx/speechx/decoder/ctc_beam_search_decoder_main.cc +++ b/speechx/speechx/decoder/ctc_beam_search_decoder_main.cc @@ -59,8 +59,8 @@ int main(int argc, char* argv[]) { google::InstallFailureSignalHandler(); FLAGS_logtostderr = 1; - CHECK(FLAGS_result_wspecifier != ""); - CHECK(FLAGS_feature_rspecifier != ""); + CHECK_NE(FLAGS_result_wspecifier, ""); + CHECK_NE(FLAGS_feature_rspecifier, ""); kaldi::SequentialBaseFloatMatrixReader feature_reader( FLAGS_feature_rspecifier); diff --git a/speechx/speechx/decoder/ctc_beam_search_opt.h b/speechx/speechx/decoder/ctc_beam_search_opt.h index f9e5933c..f4a81b3a 100644 --- a/speechx/speechx/decoder/ctc_beam_search_opt.h +++ b/speechx/speechx/decoder/ctc_beam_search_opt.h @@ -36,7 +36,7 @@ struct CTCBeamSearchOptions { // u2 int first_beam_size; int second_beam_size; - explicit CTCBeamSearchOptions() + CTCBeamSearchOptions() : blank(0), dict_file("vocab.txt"), lm_path(""), diff --git a/speechx/speechx/decoder/ctc_prefix_beam_search_decoder.cc b/speechx/speechx/decoder/ctc_prefix_beam_search_decoder.cc index 56867c70..0a0afcd7 100644 --- a/speechx/speechx/decoder/ctc_prefix_beam_search_decoder.cc +++ b/speechx/speechx/decoder/ctc_prefix_beam_search_decoder.cc @@ -329,8 +329,8 @@ void CTCPrefixBeamSearch::UpdateFinalContext() { std::string CTCPrefixBeamSearch::GetBestPath(int index) { int n_hyps = Outputs().size(); - CHECK(n_hyps > 0); - CHECK(index < n_hyps); + CHECK_GT(n_hyps, 0); + CHECK_LT(index, n_hyps); std::vector one = Outputs()[index]; std::string sentence; for (int i = 0; i < one.size(); i++) { @@ -344,7 +344,7 @@ std::string CTCPrefixBeamSearch::GetBestPath() { return GetBestPath(0); } std::vector> CTCPrefixBeamSearch::GetNBestPath( int n) { int hyps_size = hypotheses_.size(); - CHECK(hyps_size > 0); + CHECK_GT(hyps_size, 0); int min_n = n == -1 ? hypotheses_.size() : std::min(n, hyps_size); diff --git a/speechx/speechx/decoder/ctc_prefix_beam_search_decoder.h b/speechx/speechx/decoder/ctc_prefix_beam_search_decoder.h index 91977092..5013246a 100644 --- a/speechx/speechx/decoder/ctc_prefix_beam_search_decoder.h +++ b/speechx/speechx/decoder/ctc_prefix_beam_search_decoder.h @@ -28,7 +28,7 @@ class ContextGraph; class CTCPrefixBeamSearch : public DecoderBase { public: CTCPrefixBeamSearch(const std::string& vocab_path, - const CTCBeamSearchOptions& opts); + const CTCBeamSearchOptions& opts); ~CTCPrefixBeamSearch() {} SearchType Type() const { return SearchType::kPrefixBeamSearch; } diff --git a/speechx/speechx/decoder/ctc_prefix_beam_search_decoder_main.cc b/speechx/speechx/decoder/ctc_prefix_beam_search_decoder_main.cc index 69f32686..c59b1f2e 100644 --- a/speechx/speechx/decoder/ctc_prefix_beam_search_decoder_main.cc +++ b/speechx/speechx/decoder/ctc_prefix_beam_search_decoder_main.cc @@ -50,10 +50,10 @@ int main(int argc, char* argv[]) { int32 num_done = 0, num_err = 0; - CHECK(FLAGS_result_wspecifier != ""); - CHECK(FLAGS_feature_rspecifier != ""); - CHECK(FLAGS_vocab_path != ""); - CHECK(FLAGS_model_path != ""); + CHECK_NE(FLAGS_result_wspecifier, ""); + CHECK_NE(FLAGS_feature_rspecifier, ""); + CHECK_NE(FLAGS_vocab_path, ""); + CHECK_NE(FLAGS_model_path, ""); LOG(INFO) << "model path: " << FLAGS_model_path; LOG(INFO) << "Reading vocab table " << FLAGS_vocab_path; @@ -64,11 +64,14 @@ int main(int argc, char* argv[]) { // nnet ppspeech::ModelOptions model_opts; model_opts.model_path = FLAGS_model_path; - std::shared_ptr nnet = std::make_shared(model_opts); + std::shared_ptr nnet = + std::make_shared(model_opts); // decodeable - std::shared_ptr raw_data = std::make_shared(); - std::shared_ptr decodable = std::make_shared(nnet, raw_data); + std::shared_ptr raw_data = + std::make_shared(); + std::shared_ptr decodable = + std::make_shared(nnet, raw_data); // decoder ppspeech::CTCBeamSearchOptions opts; diff --git a/speechx/speechx/decoder/ctc_tlg_decoder.h b/speechx/speechx/decoder/ctc_tlg_decoder.h index 0ff1de2a..8be69dad 100644 --- a/speechx/speechx/decoder/ctc_tlg_decoder.h +++ b/speechx/speechx/decoder/ctc_tlg_decoder.h @@ -71,7 +71,7 @@ class TLGDecoder : public DecoderBase { std::string GetPartialResult() override; int DecodeLikelihoods(const std::vector>& probs, - std::vector& nbest_words); + const std::vector& nbest_words); protected: std::string GetBestPath() override { diff --git a/speechx/speechx/frontend/audio/cmvn.cc b/speechx/speechx/frontend/audio/cmvn.cc index 7997e8a7..3d80e001 100644 --- a/speechx/speechx/frontend/audio/cmvn.cc +++ b/speechx/speechx/frontend/audio/cmvn.cc @@ -30,7 +30,7 @@ using std::vector; CMVN::CMVN(std::string cmvn_file, unique_ptr base_extractor) : var_norm_(true) { - CHECK(cmvn_file != ""); + CHECK_NE(cmvn_file, ""); base_extractor_ = std::move(base_extractor); bool binary; diff --git a/speechx/speechx/frontend/audio/compute_fbank_main.cc b/speechx/speechx/frontend/audio/compute_fbank_main.cc index bb7e449f..e2b54a8a 100644 --- a/speechx/speechx/frontend/audio/compute_fbank_main.cc +++ b/speechx/speechx/frontend/audio/compute_fbank_main.cc @@ -40,8 +40,8 @@ int main(int argc, char* argv[]) { google::InstallFailureSignalHandler(); FLAGS_logtostderr = 1; - CHECK(FLAGS_wav_rspecifier.size() > 0); - CHECK(FLAGS_feature_wspecifier.size() > 0); + CHECK_GT(FLAGS_wav_rspecifier.size(), 0); + CHECK_GT(FLAGS_feature_wspecifier.size(), 0); kaldi::SequentialTableReader wav_reader( FLAGS_wav_rspecifier); kaldi::SequentialTableReader wav_info_reader( diff --git a/speechx/speechx/frontend/audio/data_cache.h b/speechx/speechx/frontend/audio/data_cache.h index 5fafdeb2..5f5cd51b 100644 --- a/speechx/speechx/frontend/audio/data_cache.h +++ b/speechx/speechx/frontend/audio/data_cache.h @@ -27,7 +27,7 @@ namespace ppspeech { // pre-recorded audio/feature class DataCache : public FrontendInterface { public: - explicit DataCache() { finished_ = false; } + DataCache() { finished_ = false; } // accept waves/feats virtual void Accept(const kaldi::VectorBase& inputs) { diff --git a/speechx/speechx/frontend/audio/db_norm.cc b/speechx/speechx/frontend/audio/db_norm.cc index 931e932d..ad79fcc3 100644 --- a/speechx/speechx/frontend/audio/db_norm.cc +++ b/speechx/speechx/frontend/audio/db_norm.cc @@ -14,17 +14,18 @@ #include "frontend/audio/db_norm.h" + #include "kaldi/feat/cmvn.h" #include "kaldi/util/kaldi-io.h" namespace ppspeech { -using kaldi::Vector; -using kaldi::VectorBase; using kaldi::BaseFloat; -using std::vector; using kaldi::SubVector; +using kaldi::Vector; +using kaldi::VectorBase; using std::unique_ptr; +using std::vector; DecibelNormalizer::DecibelNormalizer( const DecibelNormalizerOptions& opts, diff --git a/speechx/speechx/frontend/audio/fbank.cc b/speechx/speechx/frontend/audio/fbank.cc index 059abbbd..deabe876 100644 --- a/speechx/speechx/frontend/audio/fbank.cc +++ b/speechx/speechx/frontend/audio/fbank.cc @@ -13,6 +13,7 @@ // limitations under the License. #include "frontend/audio/fbank.h" + #include "kaldi/base/kaldi-math.h" #include "kaldi/feat/feature-common.h" #include "kaldi/feat/feature-functions.h" @@ -20,12 +21,12 @@ namespace ppspeech { -using kaldi::int32; using kaldi::BaseFloat; -using kaldi::Vector; +using kaldi::int32; +using kaldi::Matrix; using kaldi::SubVector; +using kaldi::Vector; using kaldi::VectorBase; -using kaldi::Matrix; using std::vector; FbankComputer::FbankComputer(const Options& opts) diff --git a/speechx/speechx/frontend/audio/feature_pipeline.cc b/speechx/speechx/frontend/audio/feature_pipeline.cc index 65493e42..2931b96b 100644 --- a/speechx/speechx/frontend/audio/feature_pipeline.cc +++ b/speechx/speechx/frontend/audio/feature_pipeline.cc @@ -33,7 +33,7 @@ FeaturePipeline::FeaturePipeline(const FeaturePipelineOptions& opts) opts.linear_spectrogram_opts, std::move(data_source))); } - CHECK(opts.cmvn_file != ""); + CHECK_NE(opts.cmvn_file, ""); unique_ptr cmvn( new ppspeech::CMVN(opts.cmvn_file, std::move(base_feature))); diff --git a/speechx/speechx/frontend/audio/linear_spectrogram.cc b/speechx/speechx/frontend/audio/linear_spectrogram.cc index 55c03978..d4a2fcc6 100644 --- a/speechx/speechx/frontend/audio/linear_spectrogram.cc +++ b/speechx/speechx/frontend/audio/linear_spectrogram.cc @@ -13,6 +13,7 @@ // limitations under the License. #include "frontend/audio/linear_spectrogram.h" + #include "kaldi/base/kaldi-math.h" #include "kaldi/feat/feature-common.h" #include "kaldi/feat/feature-functions.h" @@ -20,12 +21,12 @@ namespace ppspeech { -using kaldi::int32; using kaldi::BaseFloat; -using kaldi::Vector; +using kaldi::int32; +using kaldi::Matrix; using kaldi::SubVector; +using kaldi::Vector; using kaldi::VectorBase; -using kaldi::Matrix; using std::vector; LinearSpectrogramComputer::LinearSpectrogramComputer(const Options& opts) diff --git a/speechx/speechx/frontend/audio/mfcc.cc b/speechx/speechx/frontend/audio/mfcc.cc index bda1f96d..15f8cb0f 100644 --- a/speechx/speechx/frontend/audio/mfcc.cc +++ b/speechx/speechx/frontend/audio/mfcc.cc @@ -14,6 +14,7 @@ #include "frontend/audio/mfcc.h" + #include "kaldi/base/kaldi-math.h" #include "kaldi/feat/feature-common.h" #include "kaldi/feat/feature-functions.h" @@ -21,12 +22,12 @@ namespace ppspeech { -using kaldi::int32; using kaldi::BaseFloat; -using kaldi::Vector; +using kaldi::int32; +using kaldi::Matrix; using kaldi::SubVector; +using kaldi::Vector; using kaldi::VectorBase; -using kaldi::Matrix; using std::vector; Mfcc::Mfcc(const MfccOptions& opts, diff --git a/speechx/speechx/nnet/ds2_nnet.cc b/speechx/speechx/nnet/ds2_nnet.cc index 8c83f832..22c7f61b 100644 --- a/speechx/speechx/nnet/ds2_nnet.cc +++ b/speechx/speechx/nnet/ds2_nnet.cc @@ -13,15 +13,16 @@ // limitations under the License. #include "nnet/ds2_nnet.h" + #include "absl/strings/str_split.h" namespace ppspeech { -using std::vector; -using std::string; -using std::shared_ptr; using kaldi::Matrix; using kaldi::Vector; +using std::shared_ptr; +using std::string; +using std::vector; void PaddleNnet::InitCacheEncouts(const ModelOptions& opts) { std::vector cache_names; @@ -207,7 +208,7 @@ void PaddleNnet::FeedForward(const Vector& features, // inferences->Resize(row * col); // *inference_dim = col; - out->logprobs.Resize(row*col); + out->logprobs.Resize(row * col); out->vocab_dim = col; output_tensor->CopyToCpu(out->logprobs.Data()); diff --git a/speechx/speechx/nnet/ds2_nnet.h b/speechx/speechx/nnet/ds2_nnet.h index d1e3ac8c..420fa177 100644 --- a/speechx/speechx/nnet/ds2_nnet.h +++ b/speechx/speechx/nnet/ds2_nnet.h @@ -26,7 +26,7 @@ template class Tensor { public: Tensor() {} - Tensor(const std::vector& shape) : _shape(shape) { + explicit Tensor(const std::vector& shape) : _shape(shape) { int neml = std::accumulate( _shape.begin(), _shape.end(), 1, std::multiplies()); LOG(INFO) << "Tensor neml: " << neml; @@ -50,7 +50,7 @@ class Tensor { class PaddleNnet : public NnetBase { public: - PaddleNnet(const ModelOptions& opts); + explicit PaddleNnet(const ModelOptions& opts); void FeedForward(const kaldi::Vector& features, const int32& feature_dim, diff --git a/speechx/speechx/nnet/ds2_nnet_main.cc b/speechx/speechx/nnet/ds2_nnet_main.cc index d8d33e98..6092b8a4 100644 --- a/speechx/speechx/nnet/ds2_nnet_main.cc +++ b/speechx/speechx/nnet/ds2_nnet_main.cc @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "nnet/ds2_nnet.h" #include "base/common.h" #include "decoder/param.h" #include "frontend/audio/assembler.h" #include "frontend/audio/data_cache.h" #include "kaldi/util/table-types.h" #include "nnet/decodable.h" +#include "nnet/ds2_nnet.h" DEFINE_string(feature_rspecifier, "", "test feature rspecifier"); DEFINE_string(nnet_prob_wspecifier, "", "nnet porb wspecifier"); @@ -44,7 +44,7 @@ int main(int argc, char* argv[]) { int32 num_done = 0, num_err = 0; - ppspeech::ModelOptions model_opts = ppspeech::ModelOptions::InitFromFlags(); + ppspeech::ModelOptions model_opts = ppspeech::ModelOptions::InitFromFlags(); std::shared_ptr nnet( new ppspeech::PaddleNnet(model_opts)); diff --git a/speechx/speechx/nnet/u2_nnet.cc b/speechx/speechx/nnet/u2_nnet.cc index 636e2ad4..19cb85fd 100644 --- a/speechx/speechx/nnet/u2_nnet.cc +++ b/speechx/speechx/nnet/u2_nnet.cc @@ -158,7 +158,7 @@ void U2Nnet::Reset() { } // Debug API -void U2Nnet::FeedEncoderOuts(paddle::Tensor& encoder_out) { +void U2Nnet::FeedEncoderOuts(const paddle::Tensor& encoder_out) { // encoder_out (T,D) encoder_outs_.clear(); encoder_outs_.push_back(encoder_out); @@ -206,7 +206,7 @@ void U2Nnet::ForwardEncoderChunkImpl( float* feats_ptr = feats.mutable_data(); // not cache feature in nnet - CHECK(cached_feats_.size() == 0); + CHECK_EQ(cached_feats_.size(), 0); // CHECK_EQ(std::is_same::value, true); std::memcpy(feats_ptr, chunk_feats.data(), @@ -247,9 +247,9 @@ void U2Nnet::ForwardEncoderChunkImpl( // call. std::vector inputs = { feats, offset, /*required_cache_size, */ att_cache_, cnn_cache_}; - CHECK(inputs.size() == 4); + CHECK_EQ(inputs.size(), 4); std::vector outputs = forward_encoder_chunk_(inputs); - CHECK(outputs.size() == 3); + CHECK_EQ(outputs.size(), 3); #ifdef USE_GPU paddle::Tensor chunk_out = outputs[0].copy_to(paddle::CPUPlace()); @@ -319,9 +319,9 @@ void U2Nnet::ForwardEncoderChunkImpl( inputs.clear(); outputs.clear(); inputs.push_back(chunk_out); - CHECK(inputs.size() == 1); + CHECK_EQ(inputs.size(), 1); outputs = ctc_activation_(inputs); - CHECK(outputs.size() == 1); + CHECK_EQ(outputs.size(), 1); paddle::Tensor ctc_log_probs = outputs[0]; #ifdef TEST_DEBUG @@ -350,9 +350,9 @@ void U2Nnet::ForwardEncoderChunkImpl( // Copy to output, (B=1,T,D) std::vector ctc_log_probs_shape = ctc_log_probs.shape(); - CHECK(ctc_log_probs_shape.size() == 3); + CHECK_EQ(ctc_log_probs_shape.size(), 3); int B = ctc_log_probs_shape[0]; - CHECK(B == 1); + CHECK_EQ(B, 1); int T = ctc_log_probs_shape[1]; int D = ctc_log_probs_shape[2]; *vocab_dim = D; @@ -393,9 +393,9 @@ float U2Nnet::ComputePathScore(const paddle::Tensor& prob, // hyp (U,) float score = 0.0f; std::vector dims = prob.shape(); - CHECK(dims.size() == 3); + CHECK_EQ(dims.size(), 3); VLOG(2) << "prob shape: " << dims[0] << ", " << dims[1] << ", " << dims[2]; - CHECK(dims[0] == 1); + CHECK_EQ(dims[0], 1); int vocab_dim = static_cast(dims[2]); const float* prob_ptr = prob.data(); @@ -520,14 +520,14 @@ void U2Nnet::AttentionRescoring(const std::vector>& hyps, std::vector inputs{ hyps_tensor, hyps_lens, encoder_out}; std::vector outputs = forward_attention_decoder_(inputs); - CHECK(outputs.size() == 2); + CHECK_EQ(outputs.size(), 2); // (B, Umax, V) paddle::Tensor probs = outputs[0]; std::vector probs_shape = probs.shape(); - CHECK(probs_shape.size() == 3); - CHECK(probs_shape[0] == num_hyps); - CHECK(probs_shape[1] == max_hyps_len); + CHECK_EQ(probs_shape.size(), 3); + CHECK_EQ(probs_shape[0], num_hyps); + CHECK_EQ(probs_shape[1], max_hyps_len); #ifdef TEST_DEBUG { @@ -582,13 +582,13 @@ void U2Nnet::AttentionRescoring(const std::vector>& hyps, paddle::Tensor r_probs = outputs[1]; std::vector r_probs_shape = r_probs.shape(); if (is_bidecoder_ && reverse_weight > 0) { - CHECK(r_probs_shape.size() == 3); - CHECK(r_probs_shape[0] == num_hyps); - CHECK(r_probs_shape[1] == max_hyps_len); + CHECK_EQ(r_probs_shape.size(), 3); + CHECK_EQ(r_probs_shape[0], num_hyps); + CHECK_EQ(r_probs_shape[1], max_hyps_len); } else { // dump r_probs - CHECK(r_probs_shape.size() == 1); - CHECK(r_probs_shape[0] == 1) << r_probs_shape[0]; + CHECK_EQ(r_probs_shape.size(), 1); + CHECK_EQ(r_probs_shape[0], 1) << r_probs_shape[0]; } // compute rescoring score @@ -644,7 +644,7 @@ void U2Nnet::EncoderOuts( for (int i = 0; i < size; i++) { const paddle::Tensor& item = encoder_outs_[i]; const std::vector shape = item.shape(); - CHECK(shape.size() == 3); + CHECK_EQ(shape.size(), 3); const int& B = shape[0]; const int& T = shape[1]; const int& D = shape[2]; diff --git a/speechx/speechx/nnet/u2_nnet.h b/speechx/speechx/nnet/u2_nnet.h index e548d4c0..23cc0ea3 100644 --- a/speechx/speechx/nnet/u2_nnet.h +++ b/speechx/speechx/nnet/u2_nnet.h @@ -73,7 +73,7 @@ class U2NnetBase : public NnetBase { class U2Nnet : public U2NnetBase { public: - U2Nnet(const ModelOptions& opts); + explicit U2Nnet(const ModelOptions& opts); U2Nnet(const U2Nnet& other); void FeedForward(const kaldi::Vector& features, @@ -108,7 +108,7 @@ class U2Nnet : public U2NnetBase { std::vector* rescoring_score) override; // debug - void FeedEncoderOuts(paddle::Tensor& encoder_out); + void FeedEncoderOuts(const paddle::Tensor& encoder_out); void EncoderOuts( std::vector>* encoder_out) const; diff --git a/speechx/speechx/nnet/u2_nnet_main.cc b/speechx/speechx/nnet/u2_nnet_main.cc index 5039a59a..53fc5554 100644 --- a/speechx/speechx/nnet/u2_nnet_main.cc +++ b/speechx/speechx/nnet/u2_nnet_main.cc @@ -39,9 +39,9 @@ int main(int argc, char* argv[]) { int32 num_done = 0, num_err = 0; - CHECK(FLAGS_feature_rspecifier.size() > 0); - CHECK(FLAGS_nnet_prob_wspecifier.size() > 0); - CHECK(FLAGS_model_path.size() > 0); + CHECK_GT(FLAGS_feature_rspecifier.size(), 0); + CHECK_GT(FLAGS_nnet_prob_wspecifier.size(), 0); + CHECK_GT(FLAGS_model_path.size(), 0); LOG(INFO) << "input rspecifier: " << FLAGS_feature_rspecifier; LOG(INFO) << "output wspecifier: " << FLAGS_nnet_prob_wspecifier; LOG(INFO) << "model path: " << FLAGS_model_path; diff --git a/speechx/speechx/protocol/websocket/websocket_client_main.cc b/speechx/speechx/protocol/websocket/websocket_client_main.cc index 7ad36e3a..7c5a4f2f 100644 --- a/speechx/speechx/protocol/websocket/websocket_client_main.cc +++ b/speechx/speechx/protocol/websocket/websocket_client_main.cc @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "websocket/websocket_client.h" #include "kaldi/feat/wave-reader.h" #include "kaldi/util/kaldi-io.h" #include "kaldi/util/table-types.h" +#include "websocket/websocket_client.h" DEFINE_string(host, "127.0.0.1", "host of websocket server"); DEFINE_int32(port, 8082, "port of websocket server"); diff --git a/speechx/speechx/recognizer/recognizer.h b/speechx/speechx/recognizer/recognizer.h index 27f1228a..57d5bb36 100644 --- a/speechx/speechx/recognizer/recognizer.h +++ b/speechx/speechx/recognizer/recognizer.h @@ -39,7 +39,8 @@ struct RecognizerResource { resource.feature_pipeline_opts = FeaturePipelineOptions::InitFromFlags(); resource.feature_pipeline_opts.assembler_opts.fill_zero = true; - LOG(INFO) << "ds2 need fill zero be true: " << resource.feature_pipeline_opts.assembler_opts.fill_zero; + LOG(INFO) << "ds2 need fill zero be true: " + << resource.feature_pipeline_opts.assembler_opts.fill_zero; resource.model_opts = ModelOptions::InitFromFlags(); resource.tlg_opts = TLGDecoderOptions::InitFromFlags(); return resource; diff --git a/speechx/speechx/recognizer/recognizer_main.cc b/speechx/speechx/recognizer/recognizer_main.cc index 7c30fe6a..cb0de2d6 100644 --- a/speechx/speechx/recognizer/recognizer_main.cc +++ b/speechx/speechx/recognizer/recognizer_main.cc @@ -13,9 +13,9 @@ // limitations under the License. #include "decoder/param.h" -#include "recognizer/recognizer.h" #include "kaldi/feat/wave-reader.h" #include "kaldi/util/table-types.h" +#include "recognizer/recognizer.h" DEFINE_string(wav_rspecifier, "", "test feature rspecifier"); DEFINE_string(result_wspecifier, "", "test result wspecifier"); @@ -30,7 +30,8 @@ int main(int argc, char* argv[]) { google::InstallFailureSignalHandler(); FLAGS_logtostderr = 1; - ppspeech::RecognizerResource resource = ppspeech::RecognizerResource::InitFromFlags(); + ppspeech::RecognizerResource resource = + ppspeech::RecognizerResource::InitFromFlags(); ppspeech::Recognizer recognizer(resource); kaldi::SequentialTableReader wav_reader( diff --git a/speechx/speechx/recognizer/u2_recognizer.cc b/speechx/speechx/recognizer/u2_recognizer.cc index 4ec64665..382f622f 100644 --- a/speechx/speechx/recognizer/u2_recognizer.cc +++ b/speechx/speechx/recognizer/u2_recognizer.cc @@ -35,7 +35,7 @@ U2Recognizer::U2Recognizer(const U2RecognizerResource& resource) BaseFloat am_scale = resource.acoustic_scale; decodable_.reset(new Decodable(nnet, feature_pipeline_, am_scale)); - CHECK(resource.vocab_path != ""); + CHECK_NE(resource.vocab_path, ""); decoder_.reset(new CTCPrefixBeamSearch( resource.vocab_path, resource.decoder_opts.ctc_prefix_search_opts)); diff --git a/speechx/speechx/recognizer/u2_recognizer.h b/speechx/speechx/recognizer/u2_recognizer.h index 9b43b08f..25850863 100644 --- a/speechx/speechx/recognizer/u2_recognizer.h +++ b/speechx/speechx/recognizer/u2_recognizer.h @@ -1,5 +1,3 @@ - - // Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/speechx/speechx/utils/file_utils.cc b/speechx/speechx/utils/file_utils.cc index e5943e31..c42a642c 100644 --- a/speechx/speechx/utils/file_utils.cc +++ b/speechx/speechx/utils/file_utils.cc @@ -40,4 +40,4 @@ std::string ReadFile2String(const std::string& path) { return std::string((std::istreambuf_iterator(input_file)), std::istreambuf_iterator()); } -} +} // namespace ppspeech -- GitLab