Skip to content

Commit

Permalink
unit_tests: tighten up types in comparisons
Browse files Browse the repository at this point in the history
Signed-off-by: Carl Pearson <[email protected]>
  • Loading branch information
cwpearson committed Nov 6, 2024
1 parent 9a5d7f9 commit 8d7bbed
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 45 deletions.
22 changes: 11 additions & 11 deletions common/unit_test/Test_Common_Iota.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ void test_iota_constructor() {
// empty iota
{
Iota<T, Size> i;
EXPECT_EQ(i.size(), 0);
EXPECT_EQ(i.size(), size_t(0));
}

// basic iota
{
Iota<T, Size> ten(10);
EXPECT_EQ(ten.size(), 10);
EXPECT_EQ(ten.size(), size_t(10));
for (size_t i = 0; i < ten.size(); ++i) {
EXPECT_EQ(ten(i), i);
EXPECT_EQ(ten(i), T(i));
}
}

// iota with negative offset
if constexpr (std::is_signed_v<T>) {
Iota<T, Size> three(3, -7);
EXPECT_EQ(three.size(), 3);
EXPECT_EQ(three.size(), size_t(3));
for (size_t i = 0; i < three.size(); ++i) {
EXPECT_EQ(three(i), T(i) - T(7));
}
Expand All @@ -50,21 +50,21 @@ void test_iota_constructor() {
// iota with positive offset
{
Iota<T, Size> three(3, 2);
EXPECT_EQ(three.size(), 3);
EXPECT_EQ(three.size(), size_t(3));
for (size_t i = 0; i < three.size(); ++i) {
EXPECT_EQ(three(i), i + 2);
EXPECT_EQ(three(i), T(i + 2));
}
}

// negative sizes are capped at 0
if constexpr (std::is_signed_v<Size>) {
{
Iota<T, Size> i(-7);
EXPECT_EQ(i.size(), 0);
EXPECT_EQ(i.size(), size_t(0));
}
{
Iota<T, Size> i(-1, 2);
EXPECT_EQ(i.size(), 0);
EXPECT_EQ(i.size(), size_t(0));
}
}
}
Expand All @@ -89,9 +89,9 @@ void test_iota_subview() {
Iota<T, Size> ten(10, 1); // 1..<11
Iota<T, Size> sub(ten, Kokkos::pair{7, 9}); // 8, 9

EXPECT_EQ(sub.size(), 2);
EXPECT_EQ(sub(0), 8);
EXPECT_EQ(sub(1), 9);
EXPECT_EQ(sub.size(), size_t(2));
EXPECT_EQ(sub(0), T(8));
EXPECT_EQ(sub(1), T(9));
}

template <typename T, typename Size>
Expand Down
16 changes: 8 additions & 8 deletions graph/unit_test/Test_Graph_mis2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ void test_mis2_coarsening(lno_t numVerts, size_type nnz, lno_t bandwidth, lno_t
symRowmap, symEntries, labels, numClusters, coarseRowmapNC, coarseEntriesNC, false);
KokkosGraph::Experimental::graph_explicit_coarsen<device, rowmap_t, entries_t, entries_t, rowmap_t, entries_t>(
symRowmap, symEntries, labels, numClusters, coarseRowmapC, coarseEntriesC, true);
EXPECT_EQ(coarseRowmapC.extent(0), numClusters + 1);
EXPECT_EQ(coarseRowmapNC.extent(0), numClusters + 1);
EXPECT_EQ(coarseRowmapC.extent(0), size_t(numClusters) + 1);
EXPECT_EQ(coarseRowmapNC.extent(0), size_t(numClusters) + 1);
// Check that coarse graph doesn't have more edges than fine graph
EXPECT_LE(coarseEntriesC.extent(0), symEntries.extent(0));
EXPECT_LE(coarseEntriesNC.extent(0), symEntries.extent(0));
Expand All @@ -175,7 +175,7 @@ void test_mis2_coarsening(lno_t numVerts, size_type nnz, lno_t bandwidth, lno_t
uniqueEntries.insert(hostEntriesNC(j));
}
size_type compressedRowLen = hostRowmapC(i + 1) - hostRowmapC(i);
ASSERT_EQ(uniqueEntries.size(), compressedRowLen);
ASSERT_EQ(uniqueEntries.size(), size_t(compressedRowLen));
auto it = uniqueEntries.begin();
for (size_type j = hostRowmapC(i); j < hostRowmapC(i + 1); j++) {
EXPECT_EQ(*it, hostEntriesC(j));
Expand All @@ -200,18 +200,18 @@ void test_mis2_coarsening_zero_rows() {
lno_t numClusters;
auto labels = KokkosGraph::graph_mis2_coarsen<device, rowmap_t, entries_t>(fineRowmap, fineEntries, numClusters);
EXPECT_EQ(numClusters, 0);
EXPECT_EQ(labels.extent(0), 0);
EXPECT_EQ(labels.extent(0), size_t(0));
// coarsen, should also produce a graph with 0 rows/entries
rowmap_t coarseRowmap;
entries_t coarseEntries;
KokkosGraph::Experimental::graph_explicit_coarsen<device, rowmap_t, entries_t, entries_t, rowmap_t, entries_t>(
fineRowmap, fineEntries, labels, 0, coarseRowmap, coarseEntries, false);
EXPECT_LE(coarseRowmap.extent(0), 1);
EXPECT_EQ(coarseEntries.extent(0), 0);
EXPECT_LE(coarseRowmap.extent(0), size_t(1));
EXPECT_EQ(coarseEntries.extent(0), size_t(0));
KokkosGraph::Experimental::graph_explicit_coarsen<device, rowmap_t, entries_t, entries_t, rowmap_t, entries_t>(
fineRowmap, fineEntries, labels, 0, coarseRowmap, coarseEntries, true);
EXPECT_LE(coarseRowmap.extent(0), 1);
EXPECT_EQ(coarseEntries.extent(0), 0);
EXPECT_LE(coarseRowmap.extent(0), size_t(1));
EXPECT_EQ(coarseEntries.extent(0), size_t(0));
}

#define EXECUTE_TEST(SCALAR, ORDINAL, OFFSET, DEVICE) \
Expand Down
11 changes: 11 additions & 0 deletions sparse/impl/KokkosSparse_sptrsv_solve_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,17 @@ struct SptrsvWrap {
for (size_type i = 0; i < MAX_VEC_SIZE; ++i) m_data[i] = rhs_.m_data[i];
}

// copy-assignment
KOKKOS_INLINE_FUNCTION
ArrayType& operator=(const ArrayType& rhs_) {
if (this != &rhs_) {
for (size_type i = 0; i < MAX_VEC_SIZE; ++i) {
m_data[i] = rhs_.m_data[i];
}
}
return *this;
}

KOKKOS_INLINE_FUNCTION
ArrayType(const Vector &) { init(); }

Expand Down
13 changes: 7 additions & 6 deletions sparse/unit_test/Test_Sparse_CrsMatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,15 @@ void testCrsMatrixRawConstructor() {
int nrows = 5;
// note: last 2 columns will be empty.
// This makes sure the ncols provided to constructor is preserved.
int ncols = 7;
int nnz = 9;
int ncols = 7;
size_type nnz = 9;
// NOTE: this is not a mistake, the raw ptr constructor takes rowmap as
// ordinal.
std::vector<lno_t> rowmap = {0, 0, 2, 5, 6, 9};
std::vector<lno_t> entries = {3, 4, 0, 1, 2, 2, 0, 3, 4};
std::vector<scalar_t> values;
for (int i = 0; i < nnz; i++) values.push_back(Kokkos::ArithTraits<scalar_t>::one() * (1.0 * rand() / RAND_MAX));
for (size_type i = 0; i < nnz; i++)
values.push_back(Kokkos::ArithTraits<scalar_t>::one() * (1.0 * rand() / RAND_MAX));
KokkosSparse::CrsMatrix<scalar_t, lno_t, device, void, size_type> A("A", nrows, ncols, nnz, values.data(),
rowmap.data(), entries.data());
EXPECT_EQ(A.numRows(), nrows);
Expand All @@ -158,7 +159,7 @@ void testCrsMatrixRawConstructor() {
auto checkEntries = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), A.graph.entries);
auto checkValues = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), A.values);
for (int i = 0; i < nrows + 1; i++) EXPECT_EQ(checkRowmap(i), (size_type)rowmap[i]);
for (int i = 0; i < nnz; i++) {
for (size_type i = 0; i < nnz; i++) {
EXPECT_EQ(checkEntries(i), entries[i]);
EXPECT_EQ(checkValues(i), values[i]);
}
Expand Down Expand Up @@ -192,8 +193,8 @@ void testCrsMatrixHostMirror() {
crs_matrix_host zeroHost("zero1Host", zero);
EXPECT_EQ(zeroHost.numRows(), 0);
EXPECT_EQ(zeroHost.numCols(), 0);
EXPECT_EQ(zeroHost.nnz(), 0);
EXPECT_EQ(zeroHost.graph.row_map.extent(0), 0);
EXPECT_EQ(zeroHost.nnz(), size_type(0));
EXPECT_EQ(zeroHost.graph.row_map.extent(0), size_t(0));
}

#define KOKKOSKERNELS_EXECUTE_TEST(SCALAR, ORDINAL, OFFSET, DEVICE) \
Expand Down
6 changes: 3 additions & 3 deletions sparse/unit_test/Test_Sparse_MergeMatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void view_iota_empty_empty() {

AView a("view-iota-empty-empty-a", 0);
BView b(0);
EXPECT_EQ(MMD(a, b, 0).size(), 0);
EXPECT_EQ(MMD(a, b, 0).size(), size_t(0));
}

/*! \brief merge-matrix of a full view and empty iota
Expand All @@ -385,7 +385,7 @@ void view_iota_full_empty() {
BView b(0);

for (size_t diagonal = 0; diagonal < a.size() + b.size() - 1; ++diagonal) {
EXPECT_EQ(MMD(a, b, diagonal).size(), 0);
EXPECT_EQ(MMD(a, b, diagonal).size(), size_t(0));
}
}

Expand All @@ -404,7 +404,7 @@ void view_iota_empty_full() {
BView b(4);

for (size_t diagonal = 0; diagonal < a.size() + b.size() - 1; ++diagonal) {
EXPECT_EQ(MMD(a, b, diagonal).size(), 0);
EXPECT_EQ(MMD(a, b, diagonal).size(), size_t(0));
}
}

Expand Down
2 changes: 1 addition & 1 deletion sparse/unit_test/Test_Sparse_SortCrs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ void testSortAndMerge(bool justGraph, int howExecSpecified, bool doStructInterfa
EXPECT_EQ(goldEntries.size(), outEntries.extent(0));
if (!justGraph) {
EXPECT_EQ(goldValues.size(), outValues.extent(0));
EXPECT_EQ(goldValues.size(), output.nnz());
EXPECT_EQ(goldValues.size(), size_t(output.nnz()));
}
for (size_t i = 0; i < goldRowmap.size(); i++) EXPECT_EQ(goldRowmap[i], outRowmap(i));
for (size_t i = 0; i < goldEntries.size(); i++) {
Expand Down
15 changes: 8 additions & 7 deletions sparse/unit_test/Test_Sparse_TestUtils_RandCsMat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
namespace Test {
template <class ScalarType, class LayoutType, class ExeSpaceType>
void doCsMat(size_t m, size_t n, ScalarType min_val, ScalarType max_val) {
using RandCs = RandCsMatrix<ScalarType, LayoutType, ExeSpaceType>;
using size_type = typename RandCs::size_type;
auto expected_min = ScalarType(1.0);
size_t expected_nnz = 0;
using RandCs = RandCsMatrix<ScalarType, LayoutType, ExeSpaceType>;
using ordinal_type = typename RandCs::ordinal_type;
using size_type = typename RandCs::size_type;
auto expected_min = ScalarType(1.0);
ordinal_type expected_nnz = 0;
RandCs cm(m, n, min_val, max_val);

for (size_type i = 0; i < cm.get_nnz(); ++i) ASSERT_GE(cm(i), expected_min) << cm.info;
Expand All @@ -44,13 +45,13 @@ void doCsMat(size_t m, size_t n, ScalarType min_val, ScalarType max_val) {

// No need to check data here. Kokkos unit-tests deep_copy.
auto vals = cm.get_vals();
ASSERT_EQ(vals.extent(0), cm.get_nnz() + 1) << cm.info;
ASSERT_EQ(vals.extent(0), size_t(cm.get_nnz()) + 1) << cm.info;

auto row_ids = cm.get_ids();
ASSERT_EQ(row_ids.extent(0), cm.get_nnz()) << cm.info;
ASSERT_EQ(row_ids.extent(0), size_t(cm.get_nnz())) << cm.info;

auto col_map = cm.get_map();
ASSERT_EQ(col_map.extent(0), cm.get_dim1() + 1);
ASSERT_EQ(col_map.extent(0), size_t(cm.get_dim1()) + 1);

ASSERT_EQ(map(cm.get_dim1()), expected_nnz) << cm.info;
}
Expand Down
6 changes: 3 additions & 3 deletions sparse/unit_test/Test_Sparse_crs2coo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ void check_coo_matrix(CrsType crsMatRef, RowType row, ColType col, DataType data

Kokkos::fence();

ASSERT_EQ(crsMatRef.nnz(), row.extent(0));
ASSERT_EQ(crsMatRef.nnz(), col.extent(0));
ASSERT_EQ(crsMatRef.nnz(), data.extent(0));
ASSERT_EQ(size_t(crsMatRef.nnz()), row.extent(0));
ASSERT_EQ(size_t(crsMatRef.nnz()), col.extent(0));
ASSERT_EQ(size_t(crsMatRef.nnz()), data.extent(0));

for (decltype(row.extent(0)) idx = 0; idx < row.extent(0); ++idx) {
auto row_id = row_h(idx);
Expand Down
8 changes: 4 additions & 4 deletions sparse/unit_test/Test_Sparse_par_ilut.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ void run_test_par_ilut() {
const size_type nnzL = par_ilut_handle->get_nnzL();
const size_type nnzU = par_ilut_handle->get_nnzU();

ASSERT_EQ(nnzL, 10);
ASSERT_EQ(nnzU, 8);
ASSERT_EQ(nnzL, size_type(10));
ASSERT_EQ(nnzU, size_type(8));

EntriesType L_entries("L_entries", nnzL);
ValuesType L_values("L_values", nnzL);
Expand Down Expand Up @@ -337,8 +337,8 @@ void run_test_par_ilut_zerorow_A() {
const size_type nnzL = par_ilut_handle->get_nnzL();
const size_type nnzU = par_ilut_handle->get_nnzU();

ASSERT_EQ(nnzL, 0);
ASSERT_EQ(nnzU, 0);
ASSERT_EQ(nnzL, size_type(0));
ASSERT_EQ(nnzU, size_type(0));

EntriesType L_entries("L_entries", nnzL);
ValuesType L_values("L_values", nnzL);
Expand Down
4 changes: 2 additions & 2 deletions sparse/unit_test/Test_Sparse_spiluk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ struct SpilukTest {
const size_type nnz = values.extent(0);
const lno_t fill_lev = 2;
const size_type block_size = nrows % 2 == 0 ? 2 : 3;
ASSERT_EQ(nrows % block_size, 0);
ASSERT_EQ(nrows % block_size, size_type(0));

KernelHandle kh;

Expand Down Expand Up @@ -560,7 +560,7 @@ struct SpilukTest {
const size_type nrows = Afix.size();
const size_type block_size = nrows % 2 == 0 ? 2 : 3;
const size_type block_items = block_size * block_size;
ASSERT_EQ(nrows % block_size, 0);
ASSERT_EQ(nrows % block_size, size_type(0));

// Convert to BSR
Crs crs("crs for block spiluk test", nrows, nrows, values.extent(0), values, row_map, entries);
Expand Down

0 comments on commit 8d7bbed

Please sign in to comment.