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 5, 2024
1 parent 9a5d7f9 commit aa94896
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 34 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
2 changes: 1 addition & 1 deletion sparse/unit_test/Test_Sparse_CrsMatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void testCrsMatrixHostMirror() {
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.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

0 comments on commit aa94896

Please sign in to comment.