From 6f5ff1ce8ad738f446c39ee5766d8f028a4fabe6 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Thu, 24 Oct 2024 13:44:49 +0800 Subject: [PATCH] Use std::none_of() to replace sum() for computing isNaN --- .../csrc/offline-speaker-diarization-pyannote-impl.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/sherpa-onnx/csrc/offline-speaker-diarization-pyannote-impl.h b/sherpa-onnx/csrc/offline-speaker-diarization-pyannote-impl.h index 35cbadab0..51d712eb8 100644 --- a/sherpa-onnx/csrc/offline-speaker-diarization-pyannote-impl.h +++ b/sherpa-onnx/csrc/offline-speaker-diarization-pyannote-impl.h @@ -462,6 +462,8 @@ class OfflineSpeakerDiarizationPyannoteImpl int32_t sample_rate = meta_data.sample_rate; Matrix2D ans(sample_indexes.size(), embedding_extractor_.Dim()); + auto IsNaNWrapper = [](float f) -> bool { return std::isnan(f); }; + int32_t k = 0; int32_t cur_row_index = 0; for (const auto &v : sample_indexes) { @@ -485,11 +487,7 @@ class OfflineSpeakerDiarizationPyannoteImpl std::vector embedding = embedding_extractor_.Compute(stream.get()); - float sum = - Eigen::Map(embedding.data(), embedding.size()) - .sum(); - - if (!isnan(sum)) { + if (std::none_of(embedding.begin(), embedding.end(), IsNaNWrapper)) { // a valid embedding std::copy(embedding.begin(), embedding.end(), &ans(cur_row_index, 0)); cur_row_index += 1;