Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions include/LinearAlgebra/Matrix/coo_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class SparseMatrixCOO
int* column_indices_data() const;
T* values_data() const;

template <typename U>
friend std::ostream& operator<<(std::ostream& stream, const SparseMatrixCOO<U>& matrix);
template <typename U, class MemorySpace2>
friend std::ostream& operator<<(std::ostream& stream, const SparseMatrixCOO<U, MemorySpace2>& matrix);

void write_to_file(const std::string& filename) const;

Expand All @@ -81,18 +81,22 @@ class SparseMatrixCOO
bool is_symmetric_ = false;
};

template <typename U>
std::ostream& operator<<(std::ostream& stream, const SparseMatrixCOO<U>& matrix)
template <typename U, class MemorySpace>
std::ostream& operator<<(std::ostream& stream, const SparseMatrixCOO<U, MemorySpace>& matrix)
{
stream << "SparseMatrixCOO: " << matrix.rows_ << " x " << matrix.columns_ << "\n";
stream << "Number of non-zeros (nnz): " << matrix.nnz_ << "\n";
if (matrix.is_symmetric_) {
stream << "Matrix is symmetric.\n";
}
// Create host mirrors and deep_copy from device if necessary.
// If the View is already on host, deep_copy is a no-op.
auto h_values = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, matrix.values_);
auto h_column_indices = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, matrix.column_indices_);
auto h_row_indices = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, matrix.row_indices_);
stream << "Non-zero elements (row, column, value):\n";
for (int i = 0; i < matrix.nnz_; ++i) {
stream << "(" << matrix.row_indices_(i) << ", " << matrix.column_indices_(i) << ", " << matrix.values_(i)
<< ")\n";
stream << "(" << h_row_indices(i) << ", " << h_column_indices(i) << ", " << h_values(i) << ")\n";
}
return stream;
}
Expand Down
4 changes: 2 additions & 2 deletions include/LinearAlgebra/Matrix/csr_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class SparseMatrixCSR
KOKKOS_FUNCTION int* column_indices_data() const;
KOKKOS_FUNCTION int* row_start_indices_data() const;

template <typename U>
friend std::ostream& operator<<(std::ostream& stream, const SparseMatrixCSR<U, MemorySpace>& matrix);
template <typename U, class MemorySpace2>
friend std::ostream& operator<<(std::ostream& stream, const SparseMatrixCSR<U, MemorySpace2>& matrix);

template <class, class>
friend class SparseMatrixCSR;
Expand Down
Loading