Matheus de Sousa ggerganov commited on
Commit
061b71e
·
unverified ·
1 Parent(s): e29a728

minor : resolves some of warnings when compiling with clang/clang++ (#294)

Browse files

* Resolves some of warnings when compiling with clang/clang++

Mostly nit stuff that clang catches when compiling with -Wall -Wextra
-pedantic.

- Fix comparison between sign/unsigned integers.
- Passes a constant reference (const&) instead of copying each time.

* minor : normalize coding style

* minor : fix warning

Co-authored-by: Georgi Gerganov <[email protected]>

Files changed (3) hide show
  1. examples/main/main.cpp +3 -3
  2. whisper.cpp +4 -4
  3. whisper.h +1 -1
examples/main/main.cpp CHANGED
@@ -550,11 +550,11 @@ int main(int argc, char ** argv) {
550
  // convert to mono, float
551
  pcmf32.resize(n);
552
  if (wav.channels == 1) {
553
- for (int i = 0; i < n; i++) {
554
  pcmf32[i] = float(pcm16[i])/32768.0f;
555
  }
556
  } else {
557
- for (int i = 0; i < n; i++) {
558
  pcmf32[i] = float(pcm16[2*i] + pcm16[2*i + 1])/65536.0f;
559
  }
560
  }
@@ -565,7 +565,7 @@ int main(int argc, char ** argv) {
565
 
566
  pcmf32s[0].resize(n);
567
  pcmf32s[1].resize(n);
568
- for (int i = 0; i < n; i++) {
569
  pcmf32s[0][i] = float(pcm16[2*i])/32768.0f;
570
  pcmf32s[1][i] = float(pcm16[2*i + 1])/32768.0f;
571
  }
 
550
  // convert to mono, float
551
  pcmf32.resize(n);
552
  if (wav.channels == 1) {
553
+ for (uint64_t i = 0; i < n; i++) {
554
  pcmf32[i] = float(pcm16[i])/32768.0f;
555
  }
556
  } else {
557
+ for (uint64_t i = 0; i < n; i++) {
558
  pcmf32[i] = float(pcm16[2*i] + pcm16[2*i + 1])/65536.0f;
559
  }
560
  }
 
565
 
566
  pcmf32s[0].resize(n);
567
  pcmf32s[1].resize(n);
568
+ for (uint64_t i = 0; i < n; i++) {
569
  pcmf32s[0][i] = float(pcm16[2*i])/32768.0f;
570
  pcmf32s[1][i] = float(pcm16[2*i + 1])/32768.0f;
571
  }
whisper.cpp CHANGED
@@ -2360,12 +2360,12 @@ struct whisper_token_data whisper_sample_timestamp(struct whisper_context * ctx,
2360
  int whisper_tokenize(struct whisper_context * ctx, const char * text, whisper_token * tokens, int n_max_tokens) {
2361
  const auto res = tokenize(ctx->vocab, text);
2362
 
2363
- if (res.size() > n_max_tokens) {
2364
  fprintf(stderr, "%s: too many resulting tokens: %d (max %d)\n", __func__, (int) res.size(), n_max_tokens);
2365
  return -1;
2366
  }
2367
 
2368
- for (int i = 0; i < res.size(); i++) {
2369
  tokens[i] = res[i];
2370
  }
2371
 
@@ -2438,7 +2438,7 @@ int whisper_lang_auto_detect(
2438
  }
2439
 
2440
  std::vector<std::pair<float, int>> probs_id;
2441
- for (const auto kv : g_lang) {
2442
  const auto token_lang = whisper_token_lang(ctx, kv.second.first);
2443
  probs_id.push_back({ ctx->probs[token_lang], kv.second.first });
2444
  }
@@ -2464,7 +2464,7 @@ int whisper_lang_auto_detect(
2464
  }
2465
 
2466
  {
2467
- for (int i = 0; i < probs_id.size(); i++) {
2468
  if (lang_probs) {
2469
  lang_probs[probs_id[i].second] = probs_id[i].first;
2470
  }
 
2360
  int whisper_tokenize(struct whisper_context * ctx, const char * text, whisper_token * tokens, int n_max_tokens) {
2361
  const auto res = tokenize(ctx->vocab, text);
2362
 
2363
+ if (n_max_tokens < (int) res.size()) {
2364
  fprintf(stderr, "%s: too many resulting tokens: %d (max %d)\n", __func__, (int) res.size(), n_max_tokens);
2365
  return -1;
2366
  }
2367
 
2368
+ for (int i = 0; i < (int) res.size(); i++) {
2369
  tokens[i] = res[i];
2370
  }
2371
 
 
2438
  }
2439
 
2440
  std::vector<std::pair<float, int>> probs_id;
2441
+ for (const auto & kv : g_lang) {
2442
  const auto token_lang = whisper_token_lang(ctx, kv.second.first);
2443
  probs_id.push_back({ ctx->probs[token_lang], kv.second.first });
2444
  }
 
2464
  }
2465
 
2466
  {
2467
+ for (int i = 0; i < (int) probs_id.size(); i++) {
2468
  if (lang_probs) {
2469
  lang_probs[probs_id[i].second] = probs_id[i].first;
2470
  }
whisper.h CHANGED
@@ -148,7 +148,7 @@ extern "C" {
148
  struct whisper_context * ctx,
149
  const char * text,
150
  whisper_token * tokens,
151
- int n_max_tokens);
152
 
153
  // Largest language id (i.e. number of available languages - 1)
154
  WHISPER_API int whisper_lang_max_id();
 
148
  struct whisper_context * ctx,
149
  const char * text,
150
  whisper_token * tokens,
151
+ int n_max_tokens);
152
 
153
  // Largest language id (i.e. number of available languages - 1)
154
  WHISPER_API int whisper_lang_max_id();