42#ifndef __Teuchos_MatrixMarket_generic_hpp
43#define __Teuchos_MatrixMarket_generic_hpp
46#ifdef HAVE_TEUCHOS_COMPLEX
97 const size_t lineNumber,
99 const bool maybeBannerLine =
false);
134 template<
class Ordinal>
150 std::ostringstream
os;
151 os <<
"Unable to read any data from line " <<
lineNumber <<
" of input";
152 throw std::invalid_argument(
os.str());
162 std::ostringstream
os;
163 os <<
"Failed to get row index from line " <<
lineNumber <<
" of input";
164 throw std::invalid_argument(
os.str());
173 std::ostringstream
os;
174 os <<
"No more data after row index on line " <<
lineNumber <<
" of input";
175 throw std::invalid_argument(
os.str());
185 std::ostringstream
os;
186 os <<
"Failed to get column index from line " <<
lineNumber <<
" of input";
187 throw std::invalid_argument(
os.str());
233 template<
class Ordinal,
class Real>
249 std::ostringstream
os;
250 os <<
"Failed to read pattern data from line " <<
lineNumber <<
" of input";
251 throw std::invalid_argument(
os.str());
260 std::ostringstream
os;
261 os <<
"No more data after pattern data on line " <<
lineNumber <<
" of input";
262 throw std::invalid_argument(
os.str());
266 if (std::is_same<Real, float>::value) {
281 std::ostringstream
os;
282 os <<
"Failed to get real value from line " <<
lineNumber <<
" of input";
283 throw std::invalid_argument(
os.str());
290#ifdef HAVE_TEUCHOS_COMPLEX
333 template<
class Ordinal,
class Real>
350 std::ostringstream
os;
351 os <<
"Failed to read pattern data and/or real value from line "
353 throw std::invalid_argument(
os.str());
362 std::ostringstream os;
363 os <<
"No more data after real value on line "
364 << lineNumber <<
" of input";
365 throw std::invalid_argument(os.str());
368 istr >> the_imagPart;
375 std::ostringstream os;
376 os <<
"Failed to get imaginary value from line "
377 << lineNumber <<
" of input";
378 throw std::invalid_argument(os.str());
381 realPart = the_realPart;
382 imagPart = the_imagPart;
387 template<
class Ordinal>
400 template<
class Ordinal,
class Real>
418 throw std::logic_error(
"Should never get here! checkCommentLine() "
419 "is supposed to catch empty lines.");
426 std::istringstream
istr (
line.substr (start, size));
430#ifdef HAVE_TEUCHOS_COMPLEX
431 template<
class Ordinal,
class Real>
450 throw std::logic_error(
"Should never get here! checkCommentLine() "
451 "is supposed to catch empty lines.");
456 std::istringstream istr (line.substr (start, end));
458 Real the_realPart, the_imagPart;
460 readComplexData (istr, rowIndex, colIndex, the_realPart, the_imagPart,
461 lineNumber, tolerant);
464 realPart = the_realPart;
465 imagPart = the_imagPart;
471 template<
class Ordinal,
class PatternCallback>
472 std::pair<bool, std::vector<size_t> >
489 const std::string
theLine =
line.substr (start, size);
491 Ordinal rowIndex, colIndex;
502 add (rowIndex, colIndex);
514 template<
class Ordinal>
537 if (
in.eof () ||
in.fail ()) {
542 std::ostringstream
os;
543 os <<
"Unable to get coordinate dimensions line (at all) "
544 "from (line " <<
lineNumber <<
") of input stream; the "
545 "input stream claims that it is at \"end-of-file\" or has "
546 "an otherwise \"fail\"ed state.";
547 throw std::invalid_argument(
os.str());
556 std::ostringstream
os;
557 os <<
"Failed to read coordinate dimensions line (at all) "
558 "from (line " <<
lineNumber <<
" from input stream. The "
559 "line should contain the coordinate matrix dimensions in "
560 <<
" the form \"<numRows> <numCols> <numNonzeros>\".";
561 throw std::invalid_argument(
os.str());
568 size_t start = 0, size = 0;
586 std::ostringstream
os;
587 os <<
"Unable to read any coordinate dimensions data from line "
588 <<
lineNumber <<
" of input stream. Offending line:" << endl
590 throw std::invalid_argument(
os.str());
599 std::ostringstream
os;
600 os <<
"Failed to get number of rows from the coordinate "
601 "dimensions line (line " <<
lineNumber <<
" of input stream)."
602 " Offending line:" << endl <<
line;
603 throw std::invalid_argument(
os.str());
606 else if (
istr.eof ()) {
611 std::ostringstream
os;
612 os <<
"No more data after number of rows, in the coordinate "
613 "dimensions line (line " <<
lineNumber <<
" of input stream)."
614 " Offending line:" << endl <<
line;
615 throw std::invalid_argument(
os.str());
624 std::ostringstream
os;
625 os <<
"Failed to get number of columns from the coordinate "
626 "dimensions line (line " <<
lineNumber <<
" of input stream)."
627 " Offending line:" << endl <<
line;
628 throw std::invalid_argument(
os.str());
631 else if (
istr.eof ()) {
636 std::ostringstream
os;
637 os <<
"No more data after number of columns, in the coordinate "
638 "dimensions line (line " <<
lineNumber <<
" of input stream)."
639 " Offending line:" << endl <<
line;
640 throw std::invalid_argument (
os.str ());
649 std::ostringstream
os;
650 os <<
"Failed to get number of nonzeros from the coordinate "
651 "dimensions line (line " <<
lineNumber <<
" of input stream)."
652 " Offending line:" << endl <<
line;
653 throw std::invalid_argument (
os.str ());
Teuchos header file which uses auto-configuration information to include necessary C++ headers.
#define TEUCHOSNUMERICS_LIB_DLL_EXPORT
Concrete serial communicator subclass.
Matrix Market file utilities.
bool readCoordinateDimensions(std::istream &in, Ordinal &numRows, Ordinal &numCols, Ordinal &numNonzeros, size_t &lineNumber, const bool tolerant)
bool readPatternData(std::istream &istr, Ordinal &rowIndex, Ordinal &colIndex, const size_t lineNumber, const bool tolerant)
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.
std::pair< bool, std::vector< size_t > > readPatternCoordinateData(std::istream &in, PatternCallback add, const size_t startingLineNumber, const bool tolerant)
int maxLineLength()
Maximum line length for a Matrix Market file.
bool readRealLine(const std::string &line, Ordinal &rowIndex, Ordinal &colIndex, Real &realValue, const size_t lineNumber, const bool tolerant)
bool readPatternLine(const std::string &line, Ordinal &rowIndex, Ordinal &colIndex, const size_t lineNumber, const bool tolerant)
bool readRealData(std::istream &istr, Ordinal &rowIndex, Ordinal &colIndex, Real &realValue, const size_t lineNumber, const bool tolerant)