42 #ifndef __Teuchos_MatrixMarket_Raw_Writer_hpp 43 #define __Teuchos_MatrixMarket_Raw_Writer_hpp 45 #include "Teuchos_MatrixMarket_SetScientific.hpp" 46 #include "Teuchos_ArrayView.hpp" 66 template<
class ScalarType,
class OrdinalType>
95 const OrdinalType numRows,
96 const OrdinalType numCols)
98 std::ofstream out (filename.c_str ());
100 "Failed to open file \"" << filename <<
"\" for writing.");
101 write (out, rowptr, colind, values, numRows, numCols);
134 const OrdinalType numRows,
135 const OrdinalType numCols)
148 std::string dataType;
149 if (STS::isComplex) {
150 dataType =
"complex";
151 }
else if (STS::isOrdinal) {
152 dataType =
"integer";
159 out <<
"%%MatrixMarket matrix coordinate " << dataType <<
" general" 173 out << numRows <<
" " << numCols <<
" " << rowptr[numRows] << endl;
175 for (size_type i = 0; i < numRows; ++i) {
176 for (OrdinalType k = rowptr[i]; k < rowptr[i+1]; ++k) {
177 const OrdinalType j = colind[k];
178 const ScalarType& A_ij = values[k];
181 out << (i+1) <<
" " << (j+1) <<
" ";
182 if (STS::isComplex) {
183 out << STS::real (A_ij) <<
" " << STS::imag (A_ij);
196 #endif // __Teuchos_MatrixMarket_Raw_Writer_hpp #define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
"Raw" input of sparse matrices from Matrix Market files.
Ordinal size_type
Type representing the number of elements in an ArrayRCP or view thereof.
Templated Parameter List class.
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.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos, as well as a number of utility routines.
Write a sparse matrix from raw CSR (compressed sparse row) storage to a Matrix Market file...
Matrix Market file utilities.
Temporarily make an output stream use scientific notation with sufficient precision.