Skip to content

Commit bedc95c

Browse files
committed
use static_cast to avoid the warnings
Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
1 parent e6a089e commit bedc95c

8 files changed

+30
-29
lines changed

src/math/lp/dioph_eq.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -2014,7 +2014,10 @@ namespace lp {
20142014
}
20152015

20162016
unsigned get_markovich_number(unsigned k, unsigned h) {
2017-
return (m_e_matrix.m_columns[k].size() - 1) * (m_e_matrix.m_rows[h].size() - 1);
2017+
size_t col_size = m_e_matrix.m_columns[k].size();
2018+
size_t row_size = m_e_matrix.m_rows[h].size();
2019+
// Subtract 1 from sizes once and multiply
2020+
return static_cast<unsigned>((col_size - 1) * (row_size - 1));
20182021
}
20192022

20202023
std::tuple<mpq, unsigned, int, unsigned> find_minimal_abs_coeff(unsigned ei) {

src/math/lp/lar_solver.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,7 @@ namespace lp {
13711371
lp_assert(A_r().row_count() == i + 1 && A_r().column_count() == j + 1);
13721372
auto& last_column = A_r().m_columns[j];
13731373
int non_zero_column_cell_index = -1;
1374-
for (unsigned k = last_column.size(); k-- > 0;) {
1374+
for (unsigned k = static_cast<unsigned>(last_column.size()); k-- > 0;) {
13751375
auto& cc = last_column[k];
13761376
if (cc.var() == i)
13771377
return;
@@ -1395,7 +1395,7 @@ namespace lp {
13951395
auto& last_row = A_r().m_rows[i];
13961396
mpq& cost_j = m_mpq_lar_core_solver.m_r_solver.m_costs[j];
13971397
bool cost_is_nz = !is_zero(cost_j);
1398-
for (unsigned k = last_row.size(); k-- > 0;) {
1398+
for (unsigned k = static_cast<unsigned>(last_row.size()); k-- > 0;) {
13991399
auto& rc = last_row[k];
14001400
if (cost_is_nz) {
14011401
m_mpq_lar_core_solver.m_r_solver.m_d[rc.var()] += cost_j * rc.coeff();

src/math/lp/lp_core_solver_base.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ class lp_core_solver_base {
347347

348348
void init_non_basic_part_of_basis_heading() {
349349
this->m_nbasis.clear();
350-
for (int j = m_basis_heading.size(); j--;){
350+
for (unsigned j = static_cast<unsigned>(m_basis_heading.size()); j--;){
351351
if (m_basis_heading[j] < 0) {
352352
m_nbasis.push_back(j);
353353
// the index of column j in m_nbasis is (- basis_heading[j] - 1)

src/math/lp/lp_core_solver_base_def.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ template <typename T, typename X> bool lp_core_solver_base<T, X>::
225225
divide_row_by_pivot(unsigned pivot_row, unsigned pivot_col) {
226226
int pivot_index = -1;
227227
auto & row = m_A.m_rows[pivot_row];
228-
unsigned size = row.size();
228+
unsigned size = static_cast<unsigned>(row.size());
229229
for (unsigned j = 0; j < size; j++) {
230230
auto & c = row[j];
231231
if (c.var() == pivot_col) {

src/math/lp/lp_primal_core_solver.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,10 @@ namespace lp {
208208
continue;
209209
}
210210
unsigned not_free = get_num_of_not_free_basic_dependent_vars(j, min_non_free_so_far, bj);
211-
unsigned col_sz = this->m_A.m_columns[j].size();
211+
unsigned col_sz = static_cast<unsigned>(this->m_A.m_columns[j].size());
212212
if (not_free < min_non_free_so_far || (not_free == min_non_free_so_far && col_sz < best_col_sz)) {
213213
min_non_free_so_far = not_free;
214-
best_col_sz = this->m_A.m_columns[j].size();
214+
best_col_sz = static_cast<unsigned>(this->m_A.m_columns[j].size());
215215
choice = k;
216216
nchoices = 1;
217217
}

src/math/lp/lp_primal_core_solver_tableau_def.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ template <typename T, typename X> int lp_primal_core_solver<T, X>::find_leaving_
201201
unsigned row_min_nz = this->m_n() + 1;
202202
m_leaving_candidates.clear();
203203
auto & col = this->m_A.m_columns[entering];
204-
unsigned col_size = col.size();
204+
unsigned col_size = static_cast<unsigned>(col.size());
205205
for (;k < col_size && unlimited; k++) {
206206
const column_cell & c = col[k];
207207
unsigned i = c.var();
@@ -211,7 +211,7 @@ template <typename T, typename X> int lp_primal_core_solver<T, X>::find_leaving_
211211
limit_theta_on_basis_column(j, - ed * m_sign_of_entering_delta, t, unlimited);
212212
if (!unlimited) {
213213
m_leaving_candidates.push_back(j);
214-
row_min_nz = this->m_A.m_rows[i].size();
214+
row_min_nz = static_cast<unsigned>(this->m_A.m_rows[i].size());
215215
}
216216
}
217217
if (unlimited) {
@@ -230,7 +230,7 @@ template <typename T, typename X> int lp_primal_core_solver<T, X>::find_leaving_
230230
unlimited = true;
231231
limit_theta_on_basis_column(j, -ed * m_sign_of_entering_delta, ratio, unlimited);
232232
if (unlimited) continue;
233-
unsigned i_nz = this->m_A.m_rows[i].size();
233+
unsigned i_nz = static_cast<unsigned>(this->m_A.m_rows[i].size());
234234
if (ratio < t) {
235235
t = ratio;
236236
m_leaving_candidates.clear();
@@ -239,7 +239,7 @@ template <typename T, typename X> int lp_primal_core_solver<T, X>::find_leaving_
239239
} else if (ratio == t && i_nz < row_min_nz) {
240240
m_leaving_candidates.clear();
241241
m_leaving_candidates.push_back(j);
242-
row_min_nz = this->m_A.m_rows[i].size();
242+
row_min_nz = static_cast<unsigned>(this->m_A.m_rows[i].size());
243243
} else if (ratio == t && i_nz == row_min_nz) {
244244
m_leaving_candidates.push_back(j);
245245
}

src/math/lp/static_matrix.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
Copyright (c) 2017 Microsoft Corporation
33
44
Author:
5-
65
Lev Nachmanson (levnach)
7-
86
--*/
97

108
#pragma once
@@ -204,7 +202,7 @@ class static_matrix
204202
T get_elem(unsigned i, unsigned j) const;
205203

206204

207-
unsigned number_of_non_zeroes_in_column(unsigned j) const { return m_columns[j].size(); }
205+
unsigned number_of_non_zeroes_in_column(unsigned j) const { return static_cast<unsigned>(m_columns[j].size()); }
208206

209207
unsigned number_of_non_zeroes_in_row(unsigned i) const { return m_rows[i].size(); }
210208

@@ -257,7 +255,7 @@ class static_matrix
257255
if (m_stack.empty()) break;
258256
unsigned m = m_stack.top().m_m;
259257
while (m < row_count()) {
260-
unsigned i = m_rows.size() -1 ;
258+
unsigned i = static_cast<unsigned>(m_rows.size() -1);
261259
auto & row = m_rows[i];
262260
pop_row_columns(row);
263261
m_rows.pop_back(); // delete the last row

src/math/lp/static_matrix_def.h

+14-14
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace lp {
5757
auto & rowii = m_rows[ii];
5858
remove_element(rowii, rowii[c.offset()]);
5959
scan_row_strip_to_work_vector(rowii);
60-
unsigned prev_size_ii = rowii.size();
60+
unsigned prev_size_ii = static_cast<unsigned>(rowii.size());
6161
// run over the pivot row and update row ii
6262
for (const auto & iv : m_rows[i]) {
6363
unsigned j = iv.var();
@@ -78,7 +78,7 @@ namespace lp {
7878
}
7979

8080
// remove zeroes
81-
for (unsigned k = rowii.size(); k-- > 0; ) {
81+
for (unsigned k = static_cast<unsigned>(rowii.size()); k-- > 0; ) {
8282
if (is_zero(rowii[k].coeff()))
8383
remove_element(rowii, rowii[k]);
8484
}
@@ -90,7 +90,7 @@ namespace lp {
9090
lp_assert(i < row_count() && k < row_count() && i != k);
9191
auto & rowk = m_rows[k];
9292
scan_row_strip_to_work_vector(rowk);
93-
unsigned prev_size_k = rowk.size();
93+
unsigned prev_size_k = static_cast<unsigned>(rowk.size());
9494
// run over the pivot row and update row k
9595
for (const auto & iv : m_rows[i]) {
9696
unsigned j = iv.var();
@@ -109,7 +109,7 @@ namespace lp {
109109
}
110110

111111
// remove zeroes
112-
for (unsigned k = rowk.size(); k-- > 0; ) {
112+
for (unsigned k = static_cast<unsigned>(rowk.size()); k-- > 0; ) {
113113
if (is_zero(rowk[k].coeff()))
114114
remove_element(rowk, rowk[k]);
115115
}
@@ -126,7 +126,7 @@ namespace lp {
126126
auto & rowii = m_rows[ii];
127127
remove_element(rowii, rowii[c.offset()]);
128128
scan_row_strip_to_work_vector(rowii);
129-
unsigned prev_size_ii = rowii.size();
129+
unsigned prev_size_ii = static_cast<unsigned>(rowii.size());
130130
// run over the pivot row and update row ii
131131
for (const auto & iv : m_rows[piv_row_index]) {
132132
unsigned j = iv.var();
@@ -147,7 +147,7 @@ namespace lp {
147147
}
148148

149149
// remove zeroes
150-
for (unsigned k = rowii.size(); k-- > 0; ) {
150+
for (unsigned k = static_cast<unsigned>(rowii.size()); k-- > 0; ) {
151151
if (is_zero(rowii[k].coeff()))
152152
remove_element(rowii, rowii[k]);
153153
}
@@ -159,7 +159,7 @@ namespace lp {
159159
void static_matrix<T, X>::add_term_to_row(const mpq& alpha, TTerm const & term, unsigned ii) {
160160
auto & rowii = m_rows[ii];
161161
scan_row_strip_to_work_vector(rowii);
162-
unsigned prev_size_ii = rowii.size();
162+
unsigned prev_size_ii = static_cast<unsigned>(rowii.size());
163163
// run over the term and update row ii
164164
for (const auto & iv : term) {
165165
unsigned j = iv.var();
@@ -180,7 +180,7 @@ namespace lp {
180180
}
181181

182182
// remove zeroes
183-
for (unsigned k = rowii.size(); k-- > 0; ) {
183+
for (unsigned k = static_cast<unsigned>(rowii.size()); k-- > 0; ) {
184184
if (is_zero(rowii[k].coeff()))
185185
remove_element(rowii, rowii[k]);
186186
}
@@ -195,7 +195,7 @@ namespace lp {
195195
auto & rowii = m_rows[ii];
196196
remove_element(rowii, rowii[c.offset()]);
197197
scan_row_strip_to_work_vector(rowii);
198-
unsigned prev_size_ii = rowii.size();
198+
unsigned prev_size_ii = static_cast<unsigned>(rowii.size());
199199
// run over the pivot row and update row ii
200200
for (const auto & iv : term) {
201201
unsigned j = iv.var();
@@ -216,7 +216,7 @@ namespace lp {
216216
}
217217

218218
// remove zeroes
219-
for (unsigned k = rowii.size(); k-- > 0; ) {
219+
for (unsigned k = static_cast<unsigned>(rowii.size()); k-- > 0; ) {
220220
if (is_zero(rowii[k].coeff()))
221221
remove_element(rowii, rowii[k]);
222222
}
@@ -257,8 +257,8 @@ namespace lp {
257257
if (numeric_traits<T>::is_zero(val)) return;
258258
SASSERT(row < row_count() && col < column_count());
259259
auto & r = m_rows[row];
260-
unsigned offs_in_cols = m_columns[col].size();
261-
m_columns[col].push_back(make_column_cell(row, r.size()));
260+
unsigned offs_in_cols = static_cast<unsigned>(m_columns[col].size());
261+
m_columns[col].push_back(make_column_cell(row, static_cast<unsigned>(r.size())));
262262
r.push_back(make_row_cell(col, offs_in_cols, val));
263263
}
264264

@@ -479,8 +479,8 @@ namespace lp {
479479
void static_matrix<T, X>::add_new_element(unsigned row, unsigned col, const T& val) {
480480
auto & row_vals = m_rows[row];
481481
auto & col_vals = m_columns[col];
482-
unsigned row_el_offs = row_vals.size();
483-
unsigned col_el_offs = col_vals.size();
482+
unsigned row_el_offs = static_cast<unsigned>(row_vals.size());
483+
unsigned col_el_offs = static_cast<unsigned>(col_vals.size());
484484
row_vals.push_back(row_cell<T>(col, col_el_offs, val));
485485
col_vals.push_back(column_cell(row, row_el_offs));
486486
}

0 commit comments

Comments
 (0)