Skip to content

Commit 240d841

Browse files
committed
Prefer std::size_t over plain size_t
1 parent cdde643 commit 240d841

12 files changed

+67
-66
lines changed

palace/linalg/nleps.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ void QuasiNewtonSolver::SetInitialGuess()
283283

284284
// If the number of initial guesses is greater than the number of requested modes
285285
// de-prioritize the initial guesses that have larger errors.
286-
std::vector<size_t> indices(nev_linear);
286+
std::vector<std::size_t> indices(nev_linear);
287287
std::iota(indices.begin(), indices.end(), 0);
288288
if (nev_linear > nev)
289289
{
@@ -330,8 +330,8 @@ namespace
330330
ComplexVector MatVecMult(const std::vector<ComplexVector> &X, const Eigen::VectorXcd &y)
331331
{
332332
MFEM_ASSERT(X.size() == y.size(), "Mismatch in dimension of input vectors!");
333-
const size_t k = X.size();
334-
const size_t n = X[0].Size();
333+
const std::size_t k = X.size();
334+
const std::size_t n = X[0].Size();
335335
const bool use_dev = X[0].UseDevice();
336336
ComplexVector z;
337337
z.SetSize(n);

palace/models/postoperatorcsv.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ int PrecIndexCol(const ProblemType solver_t)
292292
// Index checking when adding to a new excitation block: When adding data to data_col with
293293
// index idx, checks that idx matches what is already written in the corresponding row of
294294
// idx_col. Adds a new idx row to idx_col if needed.
295-
void CheckAppendIndex(Column &idx_col, double idx_value, size_t m_idx_row)
295+
void CheckAppendIndex(Column &idx_col, double idx_value, std::size_t m_idx_row)
296296
{
297297
if (m_idx_row == idx_col.n_rows())
298298
{
@@ -656,7 +656,7 @@ auto PostOperatorCSV<solver_t>::PrintFarFieldE(const SurfacePostOperator &surf_p
656656
}
657657
using fmt::format;
658658
int v_dim = surf_post_op.GetVDim();
659-
for (size_t i = 0; i < measurement_cache.farfield.thetaphis.size(); i++)
659+
for (std::size_t i = 0; i < measurement_cache.farfield.thetaphis.size(); i++)
660660
{
661661
farfield_E->table["idx"] << row_idx_v;
662662
if constexpr (U == ProblemType::EIGENMODE)
@@ -740,7 +740,7 @@ void PostOperatorCSV<solver_t>::PrintProbeE(const InterpolationOperator &interp_
740740

741741
CheckAppendIndex(probe_E->table["idx"], row_idx_v, row_i);
742742

743-
size_t i = 0;
743+
std::size_t i = 0;
744744
for (const auto &idx : interp_op.GetProbes())
745745
{
746746
for (int i_dim = 0; i_dim < v_dim; i_dim++)
@@ -818,7 +818,7 @@ void PostOperatorCSV<solver_t>::PrintProbeB(const InterpolationOperator &interp_
818818

819819
CheckAppendIndex(probe_B->table["idx"], row_idx_v, row_i);
820820

821-
size_t i = 0;
821+
std::size_t i = 0;
822822
for (const auto &idx : interp_op.GetProbes())
823823
{
824824
for (int i_dim = 0; i_dim < v_dim; i_dim++)

palace/models/strattonchu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void AddStrattonChuIntegrandAtElement(const GridFunction &E, const GridFunction
120120
// This is a hot loop. Manually unrolling and avoiding Vectors significantly
121121
// increases performance.
122122
PalacePragmaOmp(parallel for schedule(static))
123-
for (size_t i = 0; i < r_naughts.size(); i++)
123+
for (std::size_t i = 0; i < r_naughts.size(); i++)
124124
{
125125
const auto &r = r_naughts[i];
126126

palace/models/surfacepostoperator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,19 +400,19 @@ std::vector<std::array<std::complex<double>, 3>> SurfacePostOperator::GetFarFiel
400400

401401
double *data_r_ptr = integrals_r.data()->data();
402402
double *data_i_ptr = integrals_i.data()->data();
403-
size_t total_elements = integrals_r.size() * 3;
403+
std::size_t total_elements = integrals_r.size() * 3;
404404
Mpi::GlobalSum(total_elements, data_i_ptr, E.GetComm());
405405
Mpi::GlobalSum(total_elements, data_r_ptr, E.GetComm());
406406

407407
// Finally, we apply cross product to reduced integrals and package the result
408408
// in a neatly accessible vector of arrays of complex numbers.
409409
std::vector<std::array<std::complex<double>, 3>> result(theta_phi_pairs.size());
410410
StaticVector<3> tmp_r, tmp_i;
411-
for (size_t k = 0; k < theta_phi_pairs.size(); k++)
411+
for (std::size_t k = 0; k < theta_phi_pairs.size(); k++)
412412
{
413413
linalg::Cross3(r_naughts[k], integrals_r[k], tmp_r);
414414
linalg::Cross3(r_naughts[k], integrals_i[k], tmp_i);
415-
for (size_t d = 0; d < 3; d++)
415+
for (std::size_t d = 0; d < 3; d++)
416416
{
417417
result[k][d] = std::complex<double>{tmp_r[d], tmp_i[d]};
418418
}

palace/models/surfacepostoperator.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class SurfacePostOperator
7373
FarFieldData(const config::FarFieldPostData &data, const mfem::ParMesh &mesh,
7474
const mfem::Array<int> &bdr_attr_marker);
7575

76-
size_t size() const { return thetaphis.size(); }
76+
std::size_t size() const { return thetaphis.size(); }
7777
};
7878

7979
// Reference to material property operator (not owned).

palace/utils/tablecsv.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717
namespace palace
1818
{
1919

20-
[[nodiscard]] size_t Column::col_width(const ColumnOptions &defaults) const
20+
[[nodiscard]] std::size_t Column::col_width(const ColumnOptions &defaults) const
2121
{
2222
// Quickfix to specify full column width in integer case to match current formatting.
2323
if (print_as_int)
2424
{
2525
return std::max(min_left_padding.value_or(defaults.min_left_padding),
2626
header_text.size());
2727
}
28-
size_t pad = min_left_padding.value_or(defaults.min_left_padding);
29-
size_t prec = float_precision.value_or(defaults.float_precision);
28+
std::size_t pad = min_left_padding.value_or(defaults.min_left_padding);
29+
std::size_t prec = float_precision.value_or(defaults.float_precision);
3030

3131
// Normal float in our exponent format needs float_precision + 7 ("+" , leading digit,
3232
// ".", "e", "+", +2 exponent. Sometimes exponent maybe +3 if very small or large; see
@@ -36,14 +36,14 @@ namespace palace
3636
}
3737

3838
[[nodiscard]] auto Column::format_header(const ColumnOptions &defaults,
39-
const std::optional<size_t> &width) const
39+
const std::optional<std::size_t> &width) const
4040
{
4141
auto w = width.value_or(col_width(defaults));
4242
return fmt::format("{0:>{1}s}", header_text, w);
4343
}
4444

45-
[[nodiscard]] auto Column::format_row(size_t i, const ColumnOptions &defaults,
46-
const std::optional<size_t> &width) const
45+
[[nodiscard]] auto Column::format_row(std::size_t i, const ColumnOptions &defaults,
46+
const std::optional<std::size_t> &width) const
4747
{
4848
auto width_ = width.value_or(col_width(defaults));
4949
// If data available format double.
@@ -68,15 +68,16 @@ namespace palace
6868
}
6969

7070
Column::Column(std::string name_, std::string header_text_, long column_group_idx_,
71-
std::optional<size_t> min_left_padding_,
72-
std::optional<size_t> float_precision_, std::optional<std::string> fmt_sign_)
71+
std::optional<std::size_t> min_left_padding_,
72+
std::optional<std::size_t> float_precision_,
73+
std::optional<std::string> fmt_sign_)
7374
: name(std::move(name_)), header_text(std::move(header_text_)),
7475
column_group_idx(column_group_idx_), min_left_padding(min_left_padding_),
7576
float_precision(float_precision_), fmt_sign(std::move(fmt_sign_))
7677
{
7778
}
7879

79-
[[nodiscard]] size_t Table::n_rows() const
80+
[[nodiscard]] std::size_t Table::n_rows() const
8081
{
8182
if (n_cols() == 0)
8283
{
@@ -87,7 +88,7 @@ Column::Column(std::string name_, std::string header_text_, long column_group_id
8788
return max_col->n_rows();
8889
}
8990

90-
void Table::reserve(size_t n_rows, size_t n_cols)
91+
void Table::reserve(std::size_t n_rows, std::size_t n_cols)
9192
{
9293
reserve_n_rows = n_rows;
9394
cols.reserve(n_cols);
@@ -127,7 +128,7 @@ Column &Table::operator[](std::string_view name)
127128
template <typename T>
128129
void Table::append_header(T &buf) const
129130
{
130-
for (size_t i = 0; i < n_cols(); i++)
131+
for (std::size_t i = 0; i < n_cols(); i++)
131132
{
132133
if (i > 0)
133134
{
@@ -139,9 +140,9 @@ void Table::append_header(T &buf) const
139140
}
140141

141142
template <typename T>
142-
void Table::append_row(T &buf, size_t row_j) const
143+
void Table::append_row(T &buf, std::size_t row_j) const
143144
{
144-
for (size_t i = 0; i < n_cols(); i++)
145+
for (std::size_t i = 0; i < n_cols(); i++)
145146
{
146147
if (i > 0)
147148
{
@@ -159,7 +160,7 @@ void Table::append_row(T &buf, size_t row_j) const
159160
return {buf.data(), buf.size()};
160161
}
161162

162-
[[nodiscard]] std::string Table::format_row(size_t j) const
163+
[[nodiscard]] std::string Table::format_row(std::size_t j) const
163164
{
164165
fmt::memory_buffer buf{};
165166
append_row(buf, j);
@@ -170,7 +171,7 @@ void Table::append_row(T &buf, size_t row_j) const
170171
{
171172
fmt::memory_buffer buf{};
172173
append_header(buf);
173-
for (size_t j = 0; j < n_rows(); j++)
174+
for (std::size_t j = 0; j < n_rows(); j++)
174175
{
175176
append_row(buf, j);
176177
}
@@ -273,7 +274,7 @@ Table::Table(std::string_view table_str,
273274

274275
// explicit instantiation to avoid fmt inclusion.
275276
template void Table::append_header(fmt::memory_buffer &) const;
276-
template void Table::append_row(fmt::memory_buffer &, size_t) const;
277+
template void Table::append_row(fmt::memory_buffer &, std::size_t) const;
277278

278279
TableWithCSVFile::TableWithCSVFile(std::string csv_file_fullpath, bool load_existing_file)
279280
: csv_file_fullpath_{std::move(csv_file_fullpath)}

test/unit/test-config.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,13 @@ TEST_CASE("Config Driven Solver", "[config][Serial]")
138138
constexpr double delta_eps = 1.0e-9; // Precision in frequency comparisons (Hz)
139139
{
140140
auto sample_f = std::vector{0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1};
141-
auto save_indices = std::vector<size_t>{0, 2, 4, 6, 8, 10};
141+
auto save_indices = std::vector<std::size_t>{0, 2, 4, 6, 8, 10};
142142
{
143143
// Top level configuration
144144
config::DrivenSolverData driven_solver;
145145
REQUIRE_NOTHROW(driven_solver.SetUp(*config.find("driven_base_uniform_sample")));
146146

147-
for (size_t i = 0; i < sample_f.size(); ++i)
147+
for (std::size_t i = 0; i < sample_f.size(); ++i)
148148
{
149149
CHECK_THAT(driven_solver.sample_f[i], WithinAbs(sample_f[i], delta_eps));
150150
}
@@ -156,7 +156,7 @@ TEST_CASE("Config Driven Solver", "[config][Serial]")
156156
config::DrivenSolverData driven_solver;
157157
REQUIRE_NOTHROW(driven_solver.SetUp(*config.find("driven_uniform_freq_step")));
158158

159-
for (size_t i = 0; i < sample_f.size(); ++i)
159+
for (std::size_t i = 0; i < sample_f.size(); ++i)
160160
{
161161
CHECK_THAT(driven_solver.sample_f[i], WithinAbs(sample_f[i], delta_eps));
162162
}
@@ -170,9 +170,9 @@ TEST_CASE("Config Driven Solver", "[config][Serial]")
170170
REQUIRE_NOTHROW(driven_solver.SetUp(*config.find("driven_uniform_nsample")));
171171

172172
auto sample_f = std::vector{0.0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1.0};
173-
auto save_indices = std::vector<size_t>{0, 2, 4, 6, 8};
173+
auto save_indices = std::vector<std::size_t>{0, 2, 4, 6, 8};
174174

175-
for (size_t i = 0; i < sample_f.size(); ++i)
175+
for (std::size_t i = 0; i < sample_f.size(); ++i)
176176
{
177177
CHECK_THAT(driven_solver.sample_f[i], WithinAbs(sample_f[i], delta_eps));
178178
}
@@ -185,10 +185,10 @@ TEST_CASE("Config Driven Solver", "[config][Serial]")
185185
REQUIRE_NOTHROW(driven_solver.SetUp(*config.find("driven_paired_uniform_sample")));
186186

187187
auto sample_f = std::vector{0.0, 0.25, 0.5, 0.75, 1.0, 2.5, 5.0, 7.5, 10.0};
188-
auto save_indices =
189-
std::vector<size_t>{0, 2, 4, 5, 6, 7, 8}; // 0.0, 0.5, 1.0, 2.5, 5.0, 7.5, 10.0
188+
auto save_indices = std::vector<std::size_t>{
189+
0, 2, 4, 5, 6, 7, 8}; // 0.0, 0.5, 1.0, 2.5, 5.0, 7.5, 10.0
190190

191-
for (size_t i = 0; i < sample_f.size(); ++i)
191+
for (std::size_t i = 0; i < sample_f.size(); ++i)
192192
{
193193
CHECK_THAT(driven_solver.sample_f[i], WithinAbs(sample_f[i], delta_eps));
194194
}
@@ -202,10 +202,10 @@ TEST_CASE("Config Driven Solver", "[config][Serial]")
202202

203203
auto sample_f = std::vector{0.0, 0.125, 0.15, 0.25, 0.35, 0.375,
204204
0.5, 0.55, 0.625, 0.75, 0.875, 1.0};
205-
auto save_indices = std::vector<size_t>{0, 2, 3, 4, 6, 7, 9, 11};
206-
auto prom_indices = std::vector<size_t>{0, sample_f.size() - 1, 2, 4, 7};
205+
auto save_indices = std::vector<std::size_t>{0, 2, 3, 4, 6, 7, 9, 11};
206+
auto prom_indices = std::vector<std::size_t>{0, sample_f.size() - 1, 2, 4, 7};
207207

208-
for (size_t i = 0; i < sample_f.size(); ++i)
208+
for (std::size_t i = 0; i < sample_f.size(); ++i)
209209
{
210210
CHECK_THAT(driven_solver.sample_f[i], WithinAbs(sample_f[i], delta_eps));
211211
}
@@ -219,10 +219,10 @@ TEST_CASE("Config Driven Solver", "[config][Serial]")
219219

220220
auto sample_f = std::vector{0.1, 0.15, 0.1778279410038923, 0.31622776601683794,
221221
0.35, 0.55, 0.5623413251903491, 1.0};
222-
auto save_indices = std::vector<size_t>{0, 1, 3, 4, 5, 7};
223-
auto prom_indices = std::vector<size_t>{0, sample_f.size() - 1, 1, 4, 5};
222+
auto save_indices = std::vector<std::size_t>{0, 1, 3, 4, 5, 7};
223+
auto prom_indices = std::vector<std::size_t>{0, sample_f.size() - 1, 1, 4, 5};
224224

225-
for (size_t i = 0; i < sample_f.size(); ++i)
225+
for (std::size_t i = 0; i < sample_f.size(); ++i)
226226
{
227227
CHECK_THAT(driven_solver.sample_f[i], WithinAbs(sample_f[i], delta_eps));
228228
}

test/unit/test-lumpedportintegration.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ TEST_CASE("LumpedPort_BasicTests_3ElementPort_Cube321", "[lumped_port][Serial]")
576576

577577
std::vector<std::array<double, 2>> expected_length_width = {{1., 1.}, {2., 1.}, {3., 1.}};
578578
// Properties of single rectangular element in port.
579-
for (size_t i = 0; i < port_1.elems.size(); i++)
579+
for (std::size_t i = 0; i < port_1.elems.size(); i++)
580580
{
581581
const auto [dl, dw] = expected_length_width.at(i);
582582
const auto *el_ptr = port_1.elems.at(i).get();
@@ -609,7 +609,7 @@ TEST_CASE("LumpedPort_BasicTests_3ElementPort_Cube321", "[lumped_port][Serial]")
609609

610610
std::vector<int> perp_vec_dir_index = {0, 0, 1};
611611

612-
for (size_t i = 0; i < port_1.elems.size(); i++)
612+
for (std::size_t i = 0; i < port_1.elems.size(); i++)
613613
{
614614
const auto *el_ptr = port_1.elems.at(i).get();
615615
REQUIRE(el_ptr != nullptr);

test/unit/test-postoperatorcsv.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class PostOperatorCSVFixture
9191
CHECK(post_op_csv.row_i == 0);
9292
CHECK(post_op_csv.ex_idx_i == 0);
9393
CHECK(post_op_csv.nr_expected_measurement_rows == 6);
94-
CHECK(post_op_csv.ex_idx_v_all == std::vector<size_t>{1});
94+
CHECK(post_op_csv.ex_idx_v_all == std::vector<std::size_t>{1});
9595
CHECK(post_op_csv.HasSingleExIdx());
9696
CHECK(!post_op_csv.reload_table); // Default restart
9797
REQUIRE_NOTHROW(post_op_csv.InitializePortVI(space_op));
@@ -111,7 +111,7 @@ class PostOperatorCSVFixture
111111
CHECK(post_op_csv.row_i == 3);
112112
CHECK(post_op_csv.ex_idx_i == 0);
113113
CHECK(post_op_csv.nr_expected_measurement_rows == 6);
114-
CHECK(post_op_csv.ex_idx_v_all == std::vector<size_t>{1});
114+
CHECK(post_op_csv.ex_idx_v_all == std::vector<std::size_t>{1});
115115

116116
CHECK_THROWS_WITH(post_op_csv.InitializePortVI(space_op),
117117
Catch::Matchers::ContainsSubstring(
@@ -137,7 +137,7 @@ class PostOperatorCSVFixture
137137
CHECK(post_op_csv.row_i == 3);
138138
CHECK(post_op_csv.ex_idx_i == 0);
139139
CHECK(post_op_csv.nr_expected_measurement_rows == 6);
140-
CHECK(post_op_csv.ex_idx_v_all == std::vector<size_t>{1});
140+
CHECK(post_op_csv.ex_idx_v_all == std::vector<std::size_t>{1});
141141
CHECK(post_op_csv.HasSingleExIdx());
142142
CHECK(post_op_csv.reload_table);
143143

@@ -180,7 +180,7 @@ class PostOperatorCSVFixture
180180
CHECK(post_op_csv.row_i == 0);
181181
CHECK(post_op_csv.ex_idx_i == 0);
182182
CHECK(post_op_csv.nr_expected_measurement_rows == 6);
183-
CHECK(post_op_csv.ex_idx_v_all == std::vector<size_t>{1});
183+
CHECK(post_op_csv.ex_idx_v_all == std::vector<std::size_t>{1});
184184

185185
CHECK_NOTHROW(post_op_csv.InitializePortVI(space_op));
186186
}
@@ -195,7 +195,7 @@ class PostOperatorCSVFixture
195195
CHECK(post_op_csv.row_i == 5);
196196
CHECK(post_op_csv.ex_idx_i == 0);
197197
CHECK(post_op_csv.nr_expected_measurement_rows == 6);
198-
CHECK(post_op_csv.ex_idx_v_all == std::vector<size_t>{1});
198+
CHECK(post_op_csv.ex_idx_v_all == std::vector<std::size_t>{1});
199199

200200
CHECK_THROWS_WITH(post_op_csv.InitializePortVI(space_op),
201201
Catch::Matchers::ContainsSubstring(
@@ -220,7 +220,7 @@ class PostOperatorCSVFixture
220220
CHECK(post_op_csv.row_i == 0);
221221
CHECK(post_op_csv.ex_idx_i == 0);
222222
CHECK(post_op_csv.nr_expected_measurement_rows == 6);
223-
CHECK(post_op_csv.ex_idx_v_all == std::vector<size_t>{1});
223+
CHECK(post_op_csv.ex_idx_v_all == std::vector<std::size_t>{1});
224224
CHECK(post_op_csv.HasSingleExIdx());
225225
CHECK(!post_op_csv.reload_table); // Default restart
226226

@@ -304,7 +304,7 @@ class PostOperatorCSVFixture
304304
CHECK(post_op_csv.row_i == 3);
305305
CHECK(post_op_csv.ex_idx_i == 0);
306306
CHECK(post_op_csv.nr_expected_measurement_rows == 6);
307-
CHECK(post_op_csv.ex_idx_v_all == std::vector<size_t>{1, 2});
307+
CHECK(post_op_csv.ex_idx_v_all == std::vector<std::size_t>{1, 2});
308308
CHECK(!post_op_csv.HasSingleExIdx());
309309
CHECK(post_op_csv.reload_table);
310310

@@ -354,7 +354,7 @@ class PostOperatorCSVFixture
354354
CHECK(post_op_csv.row_i == 0);
355355
CHECK(post_op_csv.ex_idx_i == 0);
356356
CHECK(post_op_csv.nr_expected_measurement_rows == 6);
357-
CHECK(post_op_csv.ex_idx_v_all == std::vector<size_t>{1, 2});
357+
CHECK(post_op_csv.ex_idx_v_all == std::vector<std::size_t>{1, 2});
358358

359359
// No throw since 1 restart just overwrite existing table.
360360
CHECK_NOTHROW(post_op_csv.InitializePortVI(space_op));
@@ -370,7 +370,7 @@ class PostOperatorCSVFixture
370370
CHECK(post_op_csv.row_i == 1);
371371
CHECK(post_op_csv.ex_idx_i == 1);
372372
CHECK(post_op_csv.nr_expected_measurement_rows == 6);
373-
CHECK(post_op_csv.ex_idx_v_all == std::vector<size_t>{1, 2});
373+
CHECK(post_op_csv.ex_idx_v_all == std::vector<std::size_t>{1, 2});
374374

375375
CHECK_THROWS_WITH(post_op_csv.InitializePortVI(space_op),
376376
Catch::Matchers::ContainsSubstring(
@@ -396,7 +396,7 @@ class PostOperatorCSVFixture
396396
CHECK(post_op_csv.row_i == 4);
397397
CHECK(post_op_csv.ex_idx_i == 1);
398398
CHECK(post_op_csv.nr_expected_measurement_rows == 6);
399-
CHECK(post_op_csv.ex_idx_v_all == std::vector<size_t>{1, 2});
399+
CHECK(post_op_csv.ex_idx_v_all == std::vector<std::size_t>{1, 2});
400400
CHECK(!post_op_csv.HasSingleExIdx());
401401
CHECK(post_op_csv.reload_table);
402402

0 commit comments

Comments
 (0)