42#ifndef __Teuchos_MatrixMarket_CoordDataReader_hpp
43#define __Teuchos_MatrixMarket_CoordDataReader_hpp
45#include "Teuchos_MatrixMarket_generic.hpp"
48#include "Teuchos_Tuple.hpp"
99 template<
class Callback,
class Ordinal>
202 virtual std::pair<bool, std::vector<size_t> >
206 const bool debug =
false)
210 "Input stream is invalid.");
223 const std::string
theLine = line.substr (start, size);
261 std::pair<Teuchos::Tuple<Ordinal, 3>,
bool>
284 if (
in.eof() ||
in.fail()) {
286 return std::make_pair (
dims,
false);
289 std::ostringstream os;
290 os <<
"Unable to get coordinate dimensions line (at all) "
291 "from (line " <<
lineNumber <<
") of input stream; the "
292 "input stream claims that it is at \"end-of-file\" or has "
293 "an otherwise \"fail\"ed state.";
294 throw std::invalid_argument(os.str());
303 return std::make_pair (
dims,
false);
306 std::ostringstream os;
307 os <<
"Failed to read coordinate dimensions line (at all) "
308 "from (line " <<
lineNumber <<
" from input stream. The "
309 "line should contain the coordinate matrix dimensions in "
310 <<
" the form \"<numRows> <numCols> <numNonzeros>\".";
311 throw std::invalid_argument (os.str());
318 size_t start = 0, size = 0;
325 std::istringstream
istr (line);
330 return std::make_pair (
dims,
false);
332 std::ostringstream os;
333 os <<
"Unable to read any data from line " <<
lineNumber
334 <<
" of input; the line should contain the coordinate matrix "
335 <<
"dimensions \"<numRows> <numCols> <numNonzeros>\".";
336 throw std::invalid_argument(os.str());
344 return std::make_pair (
dims,
false);
346 std::ostringstream os;
347 os <<
"Failed to get number of rows from line " <<
lineNumber
348 <<
" of input; the line should contain the coordinate matrix "
349 <<
" dimensions \"<numRows> <numCols> <numNonzeros>\".";
350 throw std::invalid_argument(os.str());
359 return std::make_pair (
dims,
false);
361 std::ostringstream os;
362 os <<
"No more data after number of rows on line " <<
lineNumber
363 <<
" of input; the line should contain the coordinate matrix "
364 <<
" dimensions \"<numRows> <numCols> <numNonzeros>\".";
365 throw std::invalid_argument(os.str());
373 return std::make_pair (
dims,
false);
375 std::ostringstream os;
376 os <<
"Failed to get number of columns from line " <<
lineNumber
377 <<
" of input; the line should contain the coordinate matrix "
378 <<
" dimensions \"<numRows> <numCols> <numNonzeros>\".";
379 throw std::invalid_argument(os.str());
388 return std::make_pair (
dims,
false);
390 std::ostringstream os;
391 os <<
"No more data after number of columns on line " <<
lineNumber
392 <<
" of input; the line should contain the coordinate matrix "
393 <<
" dimensions \"<numRows> <numCols> <numNonzeros>\".";
394 throw std::invalid_argument(os.str());
402 return std::make_pair (
dims,
false);
404 std::ostringstream os;
405 os <<
"Failed to get number of (structural) nonzeros from line "
407 <<
" of input; the line should contain the coordinate matrix "
408 <<
" dimensions \"<numRows> <numCols> <numNonzeros>\".";
409 throw std::invalid_argument(os.str());
419 return std::make_pair (
dims,
true);
496#ifdef HAVE_TEUCHOS_COMPLEX
498 template<
class Callback,
class Ordinal,
class Scalar>
514 readLine (
const std::string& theLine,
515 const size_t lineNumber,
519 typedef typename STS::magnitudeType Real;
525 Real realPart, imagPart;
526 const bool localSuccess =
527 readComplexLine (theLine, rowIndex, colIndex, realPart, imagPart,
528 lineNumber, tolerant);
537 value = std::complex<Real> (realPart, imagPart);
541 (*(this->
adder_)) (rowIndex, colIndex, value);
549 template<
class Callback,
class Ordinal,
class Scalar>
550 class CoordDataReader<Callback, Ordinal, Scalar, false> :
551 public CoordDataReaderBase<Callback, Ordinal> {
565 readLine (
const std::string& theLine,
566 const size_t lineNumber,
572 const bool localSuccess = readRealLine (theLine, rowIndex, colIndex,
573 value, lineNumber, tolerant);
577 (*(this->
adder_)) (rowIndex, colIndex, value);
606 template<
class Callback,
class Ordinal>
652 (*(this->
adder_)) (rowIndex, colIndex);
Reference-counted pointer class and non-member templated function implementations.
Defines basic traits for the scalar field type.
Common functionality of a coordinate-format sparse matrix or graph data reader.
virtual ~CoordDataReaderBase()
Virtual destructor for safety and happy compilers.
CoordDataReaderBase()
No-argument constructor.
virtual std::pair< bool, std::vector< size_t > > read(std::istream &in, const size_t startingLineNumber, const bool tolerant, const bool debug=false)
Read in all the data from the given input stream.
std::pair< Teuchos::Tuple< Ordinal, 3 >, bool > readDimensions(std::istream &in, size_t &lineNumber, const bool tolerant=false)
Read (numRows, numCols, numNonzeros).
Teuchos::RCP< Callback > adder_
Closure that knows how to add entries to the sparse graph or matrix.
CoordDataReaderBase(const Teuchos::RCP< Callback > &adder)
Constructor with "adder" argument.
virtual bool readLine(const std::string &theLine, const size_t lineNumber, const bool tolerant)=0
Read in the data from a single line of the input stream.
void setAdder(const Teuchos::RCP< Callback > &adder)
Set the Adder object.
Coordinate-format sparse matrix data reader.
CoordDataReader()
No-argument constructor.
virtual ~CoordDataReader()
Virtual destructor for safety and happy compilers.
CoordDataReader(const Teuchos::RCP< Callback > &adder)
Constructor with "adder" argument.
bool readLine(const std::string &theLine, const size_t lineNumber, const bool tolerant)
Read in the data from a single line of the input stream.
Coordinate-format sparse graph data reader.
CoordPatternReader(const Teuchos::RCP< Callback > &adder)
Constructor with "adder" argument.
virtual ~CoordPatternReader()
Virtual destructor for safety and happy compilers.
bool readLine(const std::string &theLine, const size_t lineNumber, const bool tolerant)
Read in the data from a single line of the input stream.
CoordPatternReader()
No-argument constructor.
Smart reference counting pointer class for automatic garbage collection.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
Matrix Market file utilities.
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.