Skip to content

Commit 5f8ff6a

Browse files
author
Roberto Di Remigio
committed
Silence some -Wsign-compare warnings
1 parent 520ad9e commit 5f8ff6a

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

src/cavity/Cavity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void Cavity::loadCavity(const std::string & fname)
111111
elementNormal_ = cnpy::custom::npy_to_eigen(raw_normals);
112112

113113
// Reconstruct the elements_ vector
114-
for (int i = 0; i < nElements_; ++i) {
114+
for (size_t i = 0; i < nElements_; ++i) {
115115
bool irr = false;
116116
// PEDRA puts the irreducible tesserae first
117117
if (i < nIrrElements_) irr = true;

src/cavity/Cavity.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ class Cavity
5757
/// The molecule to be wrapped by the cavity
5858
Molecule molecule_;
5959
/// Number of finite elements generated
60-
int nElements_;
60+
size_t nElements_;
6161
/// Number of irreducible finite elements
62-
int nIrrElements_;
62+
size_t nIrrElements_;
6363
/// Whether the cavity has been built
6464
bool built;
6565
/// Coordinates of elements centers

src/cavity/GePolCavity.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ void GePolCavity::build(const std::string & suffix, int maxts, int maxsph, int m
217217
elementNormal_.resize(Eigen::NoChange, nElements_);
218218
elementArea_.resize(nElements_);
219219
elementRadius_.resize(nElements_);
220-
for( int i = 0; i < nElements_; ++i ) {
220+
for( size_t i = 0; i < nElements_; ++i ) {
221221
elementCenter_(0,i) = xtscor[i];
222222
elementCenter_(1,i) = ytscor[i];
223223
elementCenter_(2,i) = ztscor[i];
@@ -233,9 +233,9 @@ void GePolCavity::build(const std::string & suffix, int maxts, int maxsph, int m
233233
// from zero by more than a fixed threshold.
234234
// The indices of the equal elements are gathered in a std::pair and saved into a std::vector
235235
double threshold = 1.0e-12;
236-
std::vector< std::pair<int, int> > equal_elements;
237-
for(int i = 0; i < nElements_; ++i) {
238-
for (int j = i + 1; j < nElements_; ++j) {
236+
std::vector< std::pair<size_t, size_t> > equal_elements;
237+
for(size_t i = 0; i < nElements_; ++i) {
238+
for (size_t j = i + 1; j < nElements_; ++j) {
239239
Eigen::Vector3d difference = elementCenter_.col(i) - elementCenter_.col(j);
240240
if ( difference.isZero(threshold) ) {
241241
equal_elements.push_back(std::make_pair(i, j));
@@ -256,13 +256,13 @@ void GePolCavity::build(const std::string & suffix, int maxts, int maxsph, int m
256256
}
257257
// Calculate normal vectors
258258
elementNormal_ = elementCenter_ - elementSphereCenter_;
259-
for( int i = 0; i < nElements_; ++i) {
259+
for( size_t i = 0; i < nElements_; ++i) {
260260
elementNormal_.col(i) /= elementNormal_.col(i).norm();
261261
}
262262

263263
// Fill elements_ vector
264-
for (int i = 0; i < nElements_; ++i) {
265-
int i_off = i + 1;
264+
for (size_t i = 0; i < nElements_; ++i) {
265+
size_t i_off = i + 1;
266266
bool irr = false;
267267
// PEDRA puts the irreducible tesserae first
268268
if (i < nIrrElements_) irr = true;
@@ -274,10 +274,10 @@ void GePolCavity::build(const std::string & suffix, int maxts, int maxsph, int m
274274
arcs.resize(Eigen::NoChange, nv);
275275
// Populate vertices and arcs
276276
for (int j = 0; j < nv; ++j) {
277-
int j_off = (j + 1) * nElements_ - 1;
278-
for (int k = 0; k < 3; ++k) {
279-
int k_off = (k + 1) * nElements_ * nv;
280-
int offset = i_off + j_off + k_off;
277+
size_t j_off = (j + 1) * nElements_ - 1;
278+
for (size_t k = 0; k < 3; ++k) {
279+
size_t k_off = (k + 1) * nElements_ * nv;
280+
size_t offset = i_off + j_off + k_off;
281281
vertices(k, j) = vert[offset];
282282
arcs(k, j) = centr[offset];
283283
}
@@ -319,7 +319,7 @@ void GePolCavity::writeOFF(const std::string & suffix)
319319
fout.open(off.str().c_str());
320320

321321
int numv = 0;
322-
for (int i = 0; i < nElements_; ++i) {
322+
for (size_t i = 0; i < nElements_; ++i) {
323323
numv += elements_[i].nVertices();
324324
}
325325
fout << "COFF" << std::endl;
@@ -328,7 +328,7 @@ void GePolCavity::writeOFF(const std::string & suffix)
328328
int k = 0;
329329
double c1, c2, c3;
330330
Eigen::MatrixXi ivts = Eigen::MatrixXi::Zero(nElements_, 10);
331-
for (int i = 0; i < nElements_; ++i) {
331+
for (size_t i = 0; i < nElements_; ++i) {
332332
if (i == 0) fout << boost::format("# Sphere number %i\n") % elements_[i].iSphere();
333333
c1 = 1.0;
334334
c2 = 1.0;
@@ -347,7 +347,7 @@ void GePolCavity::writeOFF(const std::string & suffix)
347347
% (i+1);
348348
}
349349
}
350-
for (int i = 0; i < nElements_; ++i) {
350+
for (size_t i = 0; i < nElements_; ++i) {
351351
fout << boost::format("%i ") % elements_[i].nVertices();
352352
for (int j = 0; j < elements_[i].nVertices(); ++j) {
353353
fout << boost::format("%i ") % ivts(i, j);

src/interface/Meddle.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,9 @@ namespace pcm {
300300
printer("\nLoading surface function " + functionName + " from .npy file");
301301
std::string fname = functionName + ".npy";
302302
Eigen::VectorXd values = cnpy::custom::npy_load(fname);
303-
if (values.size() != cavity_->size()) PCMSOLVER_ERROR("Inconsistent dimension of loaded surface function!", BOOST_CURRENT_FUNCTION);
303+
// This is to avoid a -Wsign-compare warning
304+
typedef EIGEN_DEFAULT_DENSE_INDEX_TYPE Index;
305+
if (values.size() != Index(cavity_->size())) PCMSOLVER_ERROR("Inconsistent dimension of loaded surface function!", BOOST_CURRENT_FUNCTION);
304306
// Append to global map
305307
if (functions_.count(functionName) == 1) { // Key in map already
306308
functions_[functionName] = values;

0 commit comments

Comments
 (0)