Skip to content

Commit 4a5fab4

Browse files
authored
Fix warnings in LUSOL solver and unit test. (#207)
1 parent 0d9baf8 commit 4a5fab4

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

resolve/LinSolverDirectLUSOL.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ namespace ReSolve
263263
// NOTE: this is not one-indexed like the original is
264264
std::unique_ptr<index_type[]> pt = std::unique_ptr<index_type[]>(new index_type[m_]);
265265
for (index_type i = 0; i < m_; i++) {
266-
pt[p_[i] - 1] = i;
266+
size_t j = static_cast<size_t>(p_[i] - 1);
267+
pt[j] = i;
267268
}
268269

269270
// preprocessing since columns are stored unordered within lusol's workspace
@@ -274,7 +275,8 @@ namespace ReSolve
274275
for (index_type i = 0; i < initial_m; i++) {
275276
index_type column_nnz = lenc_[i];
276277
index_type column_nnz_end = offset - column_nnz;
277-
index_type corresponding_column = pt[indr_[column_nnz_end + 1] - 1];
278+
size_t j = static_cast<size_t>(indr_[column_nnz_end + 1] - 1);
279+
index_type corresponding_column = pt[j];
278280

279281
columns[corresponding_column + 1] = column_nnz;
280282
offset = column_nnz_end;
@@ -297,12 +299,14 @@ namespace ReSolve
297299

298300
offset = lena_ - 1;
299301
for (index_type i = 0; i < initial_m; i++) {
300-
index_type corresponding_column = pt[indr_[offset - lenc_[i] + 1] - 1];
302+
size_t j = static_cast<size_t>(indr_[offset - lenc_[i] + 1] - 1);
303+
index_type corresponding_column = pt[j];
301304

302305
for (index_type destination_offset = columns[corresponding_column];
303306
destination_offset < columns[corresponding_column + 1] - 1;
304307
destination_offset++) {
305-
index_type row = pt[indc_[offset] - 1];
308+
size_t k = static_cast<size_t>(indc_[offset] - 1);
309+
index_type row = pt[k];
306310

307311
// closest position to the target row
308312
index_type* closest_position =
@@ -365,7 +369,8 @@ namespace ReSolve
365369
// NOTE: this is not one-indexed like the original is
366370
std::unique_ptr<index_type[]> qt = std::unique_ptr<index_type[]>(new index_type[n_]);
367371
for (index_type i = 0; i < n_; i++) {
368-
qt[q_[i] - 1] = i;
372+
size_t j = static_cast<size_t>(q_[i] - 1);
373+
qt[j] = i;
369374
}
370375

371376
// preprocessing since rows technically aren't ordered either
@@ -386,7 +391,8 @@ namespace ReSolve
386391
index_type offset = locr_[p_[row] - 1] - 1;
387392

388393
for (index_type destination_offset = rows[row]; destination_offset < rows[row + 1]; destination_offset++) {
389-
index_type column = qt[indr_[offset] - 1];
394+
size_t j = static_cast<size_t>(indr_[offset] - 1);
395+
index_type column = qt[j];
390396

391397
// closest position to the target column
392398
index_type* closest_position =

tests/unit/matrix/LUSOLTests.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,16 @@ namespace ReSolve
8080

8181
index_type* p_ordering = solver.getPOrdering();
8282

83-
for (index_type i = 0; i < A->getNumRows(); i++) {
84-
status *= p_ordering[i] == reference_p_ordering_[i];
83+
size_t n = static_cast<size_t>(A->getNumRows());
84+
for (size_t i = 0; i < n; i++) {
85+
status *= (p_ordering[i] == reference_p_ordering_[i]);
8586
}
8687

8788
index_type* q_ordering = solver.getQOrdering();
8889

89-
for (index_type i = 0; i < A->getNumColumns(); i++) {
90-
status *= q_ordering[i] == reference_q_ordering_[i];
90+
size_t m = static_cast<size_t>(A->getNumColumns());
91+
for (size_t i = 0; i < m; i++) {
92+
status *= (q_ordering[i] == reference_q_ordering_[i]);
9193
}
9294

9395
if (solver.solve(&rhs, &x) < 0) {
@@ -202,7 +204,7 @@ namespace ReSolve
202204
const std::vector<real_type>& coo_answer_values)
203205
{
204206
bool status = true;
205-
index_type i = 0;
207+
size_t i = 0;
206208

207209
index_type* rows = A.getRowData(memory::HOST);
208210
index_type* columns = A.getColData(memory::HOST);
@@ -266,7 +268,7 @@ namespace ReSolve
266268
const std::vector<real_type>& coo_answer_values)
267269
{
268270
bool status = true;
269-
index_type i = 0;
271+
size_t i = 0;
270272

271273
index_type* columns = A.getColData(memory::HOST);
272274
index_type* rows = A.getRowData(memory::HOST);

0 commit comments

Comments
 (0)