diff --git a/sparse/src/KokkosSparse_BsrMatrix.hpp b/sparse/src/KokkosSparse_BsrMatrix.hpp index db9ef71753..06a9ad92cf 100644 --- a/sparse/src/KokkosSparse_BsrMatrix.hpp +++ b/sparse/src/KokkosSparse_BsrMatrix.hpp @@ -34,6 +34,7 @@ #include "Kokkos_ArithTraits.hpp" #include "KokkosSparse_CrsMatrix.hpp" #include "KokkosKernels_Error.hpp" +#include "KokkosKernels_default_types.hpp" namespace KokkosSparse { @@ -325,9 +326,7 @@ struct BsrRowViewConst { /// storage for sparse matrices, as described, for example, in Saad /// (2nd ed.). template ::size_type> + class MemoryTraits = void, class SizeType = default_size_type> class BsrMatrix { static_assert( std::is_signed::value, diff --git a/sparse/src/KokkosSparse_CrsMatrix.hpp b/sparse/src/KokkosSparse_CrsMatrix.hpp index ce9ec99e4e..2e69683441 100644 --- a/sparse/src/KokkosSparse_CrsMatrix.hpp +++ b/sparse/src/KokkosSparse_CrsMatrix.hpp @@ -339,9 +339,7 @@ struct SparseRowViewConst { /// storage for sparse matrices, as described, for example, in Saad /// (2nd ed.). template ::size_type> + class MemoryTraits = void, class SizeType = default_size_type> class CrsMatrix { static_assert( std::is_signed::value, diff --git a/sparse/src/KokkosSparse_ccs2crs.hpp b/sparse/src/KokkosSparse_ccs2crs.hpp index 9b4bae2134..fcdf45c9c8 100644 --- a/sparse/src/KokkosSparse_ccs2crs.hpp +++ b/sparse/src/KokkosSparse_ccs2crs.hpp @@ -102,6 +102,14 @@ template auto ccs2crs(OrdinalType nrows, OrdinalType ncols, SizeType nnz, ValViewType vals, ColMapViewType col_map, RowIdViewType row_ids) { + static_assert( + std::is_same_v, + "ccs2crs: SizeType (type of nnz) must match the element type of " + "ColMapViewType"); + static_assert( + std::is_same_v, + "ccs2crs: OrdinalType (type of nrows, ncols) must match the element type " + "of RowIdViewType"); using Ccs2crsType = Impl::Ccs2Crs; Ccs2crsType ccs2Crs(nrows, ncols, nnz, vals, col_map, row_ids); diff --git a/sparse/src/KokkosSparse_crs2ccs.hpp b/sparse/src/KokkosSparse_crs2ccs.hpp index c9265842cb..4b985b5b6d 100644 --- a/sparse/src/KokkosSparse_crs2ccs.hpp +++ b/sparse/src/KokkosSparse_crs2ccs.hpp @@ -100,6 +100,14 @@ template auto crs2ccs(OrdinalType nrows, OrdinalType ncols, SizeType nnz, ValViewType vals, RowMapViewType row_map, ColIdViewType col_ids) { + static_assert( + std::is_same_v, + "crs2ccs: SizeType (type of nnz) must match the element type of " + "RowMapViewType"); + static_assert( + std::is_same_v, + "crs2ccs: OrdinalType (type of nrows, ncols) must match the element type " + "of ColIdViewType"); using Crs2ccsType = Impl::Crs2Ccs; Crs2ccsType crs2Ccs(nrows, ncols, nnz, vals, row_map, col_ids); @@ -128,4 +136,4 @@ auto crs2ccs(KokkosSparse::CrsMatrix auto crs2coo(OrdinalType nrows, OrdinalType ncols, SizeType nnz, ValViewType vals, RowMapViewType row_map, ColIdViewType col_ids) { + static_assert( + std::is_same_v, + "crs2coo: SizeType (type of nnz) must match the element type of " + "RowMapViewType"); + static_assert( + std::is_same_v, + "crs2coo: OrdinalType (type of nrows, ncols) must match the element type " + "of ColIdViewType"); using Crs2cooType = Impl::Crs2Coo; Crs2cooType crs2Coo(nrows, ncols, nnz, vals, row_map, col_ids); @@ -161,4 +169,4 @@ auto crs2coo(KokkosSparse::CrsMatrix void doCsMat(size_t m, size_t n, ScalarType min_val, ScalarType max_val) { + using RandCs = RandCsMatrix; + using size_type = typename RandCs::size_type; auto expected_min = ScalarType(1.0); size_t expected_nnz = 0; - RandCsMatrix cm(m, n, min_val, max_val); + RandCs cm(m, n, min_val, max_val); - for (size_t i = 0; i < cm.get_nnz(); ++i) + for (size_type i = 0; i < cm.get_nnz(); ++i) ASSERT_GE(cm(i), expected_min) << cm.info; auto map_d = cm.get_map(); @@ -83,4 +85,4 @@ TEST_F(TestCategory, sparse_randcsmat) { doAllCsMat(dim, dim * 3); } } -} // namespace Test \ No newline at end of file +} // namespace Test diff --git a/sparse/unit_test/Test_Sparse_spmv_bsr.hpp b/sparse/unit_test/Test_Sparse_spmv_bsr.hpp index 6482d33d8a..cb42f5c2e4 100644 --- a/sparse/unit_test/Test_Sparse_spmv_bsr.hpp +++ b/sparse/unit_test/Test_Sparse_spmv_bsr.hpp @@ -134,9 +134,9 @@ Bsr bsr_random(const int blockSize, const int blockRows, const int blockCols) { rcs(blockRows, blockCols, scalar_type(0), max_a()); const auto colids = Kokkos::subview( - rcs.get_ids(), Kokkos::make_pair(size_t(0), rcs.get_nnz())); + rcs.get_ids(), Kokkos::make_pair(size_type(0), rcs.get_nnz())); const auto vals = Kokkos::subview( - rcs.get_vals(), Kokkos::make_pair(size_t(0), rcs.get_nnz())); + rcs.get_vals(), Kokkos::make_pair(size_type(0), rcs.get_nnz())); Graph graph(colids, rcs.get_map()); Crs crs("crs", blockCols, vals, graph); diff --git a/test_common/KokkosKernels_TestUtils.hpp b/test_common/KokkosKernels_TestUtils.hpp index 232b66242a..50a28cb1e8 100644 --- a/test_common/KokkosKernels_TestUtils.hpp +++ b/test_common/KokkosKernels_TestUtils.hpp @@ -643,9 +643,7 @@ class RandCooMat { /// \tparam LayoutType /// \tparam Device template ::size_type> + typename Ordinal = int64_t, typename Size = default_size_type> class RandCsMatrix { public: using value_type = ScalarType; @@ -765,7 +763,7 @@ class RandCsMatrix { // O(c), where c is a constant. ScalarType operator()(Size idx) { return __vals(idx); } - size_t get_nnz() { return size_t(__nnz); } + Size get_nnz() { return __nnz; } // dimension2: This is either columns for a Crs matrix or rows for a Ccs // matrix. Ordinal get_dim2() { return __dim2; }