10#ifndef __Teuchos_MatrixMarket_Raw_Writer_hpp
11#define __Teuchos_MatrixMarket_Raw_Writer_hpp
13#include <Teuchos_SetScientific.hpp>
14#include "Teuchos_ArrayView.hpp"
20 namespace MatrixMarket {
34 template<
class ScalarType,
class OrdinalType>
63 const OrdinalType numRows,
64 const OrdinalType numCols)
66 std::ofstream out (filename.c_str ());
68 "Failed to open file \"" << filename <<
"\" for writing.");
69 write (out, rowptr, colind, values, numRows, numCols);
102 const OrdinalType numRows,
103 const OrdinalType numCols)
116 std::string dataType;
117 if (STS::isComplex) {
118 dataType =
"complex";
119 }
else if (STS::isOrdinal) {
120 dataType =
"integer";
127 out <<
"%%MatrixMarket matrix coordinate " << dataType <<
" general"
141 out << numRows <<
" " << numCols <<
" " << rowptr[numRows] << endl;
143 for (size_type i = 0; i < numRows; ++i) {
144 for (OrdinalType k = rowptr[i]; k < rowptr[i+1]; ++k) {
145 const OrdinalType j = colind[k];
146 const ScalarType& A_ij = values[k];
149 out << (i+1) <<
" " << (j+1) <<
" ";
150 if (STS::isComplex) {
151 out << STS::real (A_ij) <<
" " << STS::imag (A_ij);
Templated Parameter List class.
Ordinal size_type
Type representing the number of elements in an ArrayRCP or view thereof.
Write a sparse matrix from raw CSR (compressed sparse row) storage to a Matrix Market file.
void write(std::ostream &out, const ArrayView< const OrdinalType > &rowptr, const ArrayView< const OrdinalType > &colind, const ArrayView< const ScalarType > &values, const OrdinalType numRows, const OrdinalType numCols)
Write the sparse matrix to the given output stream.
void writeFile(const std::string &filename, const ArrayView< const OrdinalType > &rowptr, const ArrayView< const OrdinalType > &colind, const ArrayView< const ScalarType > &values, const OrdinalType numRows, const OrdinalType numCols)
Write the sparse matrix to the given file.
Temporarily make an output stream use scientific notation with sufficient precision.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
This structure defines some basic traits for a scalar field type.