Skip to content

Commit

Permalink
Use std::none_of() to replace sum() for computing isNaN
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj committed Oct 24, 2024
1 parent dccf714 commit 6f5ff1c
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions sherpa-onnx/csrc/offline-speaker-diarization-pyannote-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -485,11 +487,7 @@ class OfflineSpeakerDiarizationPyannoteImpl

std::vector<float> embedding = embedding_extractor_.Compute(stream.get());

float sum =
Eigen::Map<Eigen::RowVectorXf>(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;
Expand Down

0 comments on commit 6f5ff1c

Please sign in to comment.