42#ifndef __Teuchos_MatrixMarket_Raw_Reader_hpp
43#define __Teuchos_MatrixMarket_Raw_Reader_hpp
100 template<
class Scalar,
class Ordinal>
162 const bool debug =
false;
167 "syntax errors when parsing the Matrix Market file");
168 params->set (
"Debug mode",
debug,
"Whether to print debugging output "
169 "to stderr, on all participating MPI processes");
209 "Failed to open file \"" <<
filename <<
"\" for reading.");
268 std::ostringstream
err;
272 catch (std::exception&
e) {
273 err <<
"Failed to read Matrix Market input's Banner: " <<
e.what();
289 if (
banner->matrixType () !=
"coordinate") {
290 err <<
"Matrix Market input file must contain a \"coordinate\"-"
291 "format sparse matrix in order to create a sparse matrix object "
295 else if (! STS::isComplex &&
banner->dataType () ==
"complex") {
296 err <<
"The Matrix Market sparse matrix file contains complex-"
297 "valued data, but you are try to read the data into a sparse "
298 "matrix containing real values (your matrix's Scalar type is "
302 else if (
banner->dataType () !=
"real" &&
303 banner->dataType () !=
"complex") {
304 err <<
"Only real or complex data types (no pattern or integer "
305 "matrices) are currently supported.";
311 cerr <<
"Matrix Market banner is invalid: " <<
err.str () << endl;
317 "Matrix Market banner is invalid: " <<
err.str ());
321 cerr <<
"Matrix Market Banner line:" << endl << *
banner << endl;
334 std::pair<Tuple<Ordinal, 3>,
bool>
dims =
337 err <<
"Error reading Matrix Market sparse matrix file: failed to "
338 "read coordinate dimensions.";
355 numRows =
dims.first[0];
356 numCols =
dims.first[1];
357 const Ordinal numEntries =
dims.first[2];
359 cerr <<
"Reported dimensions: " << numRows <<
" x " << numCols
360 <<
", with " << numEntries <<
" entries (counting possible "
361 <<
"duplicates)." << endl;
381 std::pair<bool, std::vector<size_t> >
results =
386 err <<
"The Matrix Market input stream had syntax error(s)."
387 " Here is the error report." << endl;
407 catch (std::exception&
e) {
408 err <<
"Failed to convert sparse matrix data to CSR (compressed "
409 "sparse row) format. Reported error: " <<
e.what ();
443 cerr <<
"MatrixMarket::Raw::Reader:" << endl
444 <<
"- Tolerant mode: " <<
tolerant_ << endl
445 <<
"- Debug mode: " <<
debug_ << endl;
481 "Failed to get Matrix Market banner line from input, after reading "
494 "Failed to get Matrix Market banner line from input. This "
495 "probably means that the file is empty (contains zero lines).");
499 cerr <<
"Raw::Reader::readBanner: Here is the presumed banner line:"
500 << endl <<
line << endl;
507 }
catch (std::exception&
e) {
509 "Matrix Market file's banner line contains syntax error(s): "
521 const std::pair<
bool, std::vector<size_t> >&
results)
526 out <<
numErrors <<
" errors when reading Matrix Market sparse "
527 "matrix file." << endl;
529 out <<
"-- We do not report individual errors when there "
533 out <<
"Error on line " <<
results.second[0] << endl;
536 out <<
"Errors on lines {";
int size(const Comm< Ordinal > &comm)
Get the number of processes in the communicator.
Parse a Matrix Market banner line.
Read a sparse matrix from a Matrix Market file into raw CSR (compressed sparse row) storage.
RCP< const ParameterList > getValidParameters() const
Get a list of valid default parameters, with documentation.
RCP< const Banner > readBanner(std::istream &in, size_t &lineNumber)
Read in the Banner line from the given input stream.
bool read(ArrayRCP< Ordinal > &rowptr, ArrayRCP< Ordinal > &colind, ArrayRCP< Scalar > &values, Ordinal &numRows, Ordinal &numCols, std::istream &in)
Read the sparse matrix from the given input stream into CSR storage.
Reader(const bool tolerant, const bool debug)
Constructor that takes Boolean parameters.
void reportBadness(std::ostream &out, const std::pair< bool, std::vector< size_t > > &results)
void init()
"Initialize" the Reader.
Reader(const RCP< ParameterList > ¶ms)
Constructor that takes a ParameterList of parameters.
bool readFile(ArrayRCP< Ordinal > &rowptr, ArrayRCP< Ordinal > &colind, ArrayRCP< Scalar > &values, Ordinal &numRows, Ordinal &numCols, const std::string &filename)
Read the sparse matrix from the given file into CSR storage.
bool tolerant_
Whether to parse the Matrix Market file tolerantly.
Reader()
Constructor that sets default Boolean parameters.
void setParameters(const RCP< ParameterList > ¶ms)
Set parameters from the given ParameterList.
bool debug_
Whether to print debugging output to stderr.
Concrete serial communicator subclass.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
Matrix Market file utilities.
"Raw" input of sparse matrices from Matrix Market files.
bool checkCommentLine(const std::string &line, size_t &start, size_t &size, const size_t lineNumber, const bool tolerant, const bool maybeBannerLine)
True if the line is a comment line, false otherwise.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.