Skip to content

Conversation

jlmelville
Copy link
Contributor

GCC is complaining about different signedness in the loop which populates the return value in getDataByLabel:

warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare]
     795 |         for (int i = 0; i < dim; i++) {

The simplest fix, given here, is to change the type of the loop index i to size_t. A more idiomatic C++ approach would be to avoid introducing the loop in the first place, e.g.

std::copy(data_ptr, data_ptr + dim, std::back_inserter(data));

I checked that this worked (at least via the R bindings) but admittedly made no effort to do a proper performance check, so simpler is probably better.

@yurymalkov
Copy link
Member

Thank you for the fix, @jlmelville!
I guess simpler is better due to readability (it looks more language agnostic). Though I am not sure why it is not just:

 for (size_t i = 0; i < dim; i++) {
      data.push_back(data_ptr[i]);
  }

Probably will change it to this.

@yurymalkov yurymalkov merged commit 898bf5d into nmslib:develop Oct 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants