10#ifndef __Teuchos_MatrixMarket_CoordDataReader_hpp
11#define __Teuchos_MatrixMarket_CoordDataReader_hpp
13#include "Teuchos_MatrixMarket_generic.hpp"
16#include "Teuchos_Tuple.hpp"
67 template<
class Callback,
class Ordinal>
170 virtual std::pair<bool, std::vector<size_t> >
174 const bool debug =
false)
178 "Input stream is invalid.");
190 const std::string
theLine = line.substr (start, size);
225 std::pair<Teuchos::Tuple<Ordinal, 3>,
bool>
248 if (
in.eof() ||
in.fail()) {
250 return std::make_pair (
dims,
false);
253 std::ostringstream os;
254 os <<
"Unable to get coordinate dimensions line (at all) "
255 "from (line " <<
lineNumber <<
") of input stream; the "
256 "input stream claims that it is at \"end-of-file\" or has "
257 "an otherwise \"fail\"ed state.";
258 throw std::invalid_argument(os.str());
267 return std::make_pair (
dims,
false);
270 std::ostringstream os;
271 os <<
"Failed to read coordinate dimensions line (at all) "
272 "from (line " <<
lineNumber <<
" from input stream. The "
273 "line should contain the coordinate matrix dimensions in "
274 <<
" the form \"<numRows> <numCols> <numNonzeros>\".";
275 throw std::invalid_argument (os.str());
282 size_t start = 0, size = 0;
289 std::istringstream
istr (line);
294 return std::make_pair (
dims,
false);
296 std::ostringstream os;
297 os <<
"Unable to read any data from line " <<
lineNumber
298 <<
" of input; the line should contain the coordinate matrix "
299 <<
"dimensions \"<numRows> <numCols> <numNonzeros>\".";
300 throw std::invalid_argument(os.str());
308 return std::make_pair (
dims,
false);
310 std::ostringstream os;
311 os <<
"Failed to get number of rows from line " <<
lineNumber
312 <<
" of input; the line should contain the coordinate matrix "
313 <<
" dimensions \"<numRows> <numCols> <numNonzeros>\".";
314 throw std::invalid_argument(os.str());
323 return std::make_pair (
dims,
false);
325 std::ostringstream os;
326 os <<
"No more data after number of rows on line " <<
lineNumber
327 <<
" of input; the line should contain the coordinate matrix "
328 <<
" dimensions \"<numRows> <numCols> <numNonzeros>\".";
329 throw std::invalid_argument(os.str());
337 return std::make_pair (
dims,
false);
339 std::ostringstream os;
340 os <<
"Failed to get number of columns from line " <<
lineNumber
341 <<
" of input; the line should contain the coordinate matrix "
342 <<
" dimensions \"<numRows> <numCols> <numNonzeros>\".";
343 throw std::invalid_argument(os.str());
352 return std::make_pair (
dims,
false);
354 std::ostringstream os;
355 os <<
"No more data after number of columns on line " <<
lineNumber
356 <<
" of input; the line should contain the coordinate matrix "
357 <<
" dimensions \"<numRows> <numCols> <numNonzeros>\".";
358 throw std::invalid_argument(os.str());
366 return std::make_pair (
dims,
false);
368 std::ostringstream os;
369 os <<
"Failed to get number of (structural) nonzeros from line "
371 <<
" of input; the line should contain the coordinate matrix "
372 <<
" dimensions \"<numRows> <numCols> <numNonzeros>\".";
373 throw std::invalid_argument(os.str());
383 return std::make_pair (
dims,
true);
460#ifdef HAVE_TEUCHOS_COMPLEX
462 template<
class Callback,
class Ordinal,
class Scalar>
478 readLine (
const std::string& theLine,
479 const size_t lineNumber,
483 typedef typename STS::magnitudeType Real;
489 Real realPart, imagPart;
490 const bool localSuccess =
491 readComplexLine (theLine, rowIndex, colIndex, realPart, imagPart,
492 lineNumber, tolerant);
501 value = std::complex<Real> (realPart, imagPart);
505 (*(this->
adder_)) (rowIndex, colIndex, value);
513 template<
class Callback,
class Ordinal,
class Scalar>
514 class CoordDataReader<Callback, Ordinal, Scalar, false> :
515 public CoordDataReaderBase<Callback, Ordinal> {
529 readLine (
const std::string& theLine,
530 const size_t lineNumber,
536 const bool localSuccess = readRealLine (theLine, rowIndex, colIndex,
537 value, lineNumber, tolerant);
541 (*(this->
adder_)) (rowIndex, colIndex, value);
570 template<
class Callback,
class Ordinal>
616 (*(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.