Tpetra Matrix/Vector Services Version of the Day
Public Member Functions | Protected Member Functions | Protected Attributes
Tpetra::MatrixMarket::CoordDataReaderBase< Callback, Ordinal > Class Template Reference

Common functionality of a coordinate-format sparse matrix or graph data reader. More...

#include <MatrixMarket_CoordDataReader.hpp>

Inheritance diagram for Tpetra::MatrixMarket::CoordDataReaderBase< Callback, Ordinal >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 CoordDataReaderBase (const RCP< Callback > &adder)
 Constructor with "adder" argument.
 CoordDataReaderBase ()
 No-argument constructor.
virtual ~CoordDataReaderBase ()
 Virtual destructor for safety and happy compilers.
void setAdder (const RCP< Callback > &adder)
 Set the Adder object.
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< Tuple< Ordinal, 3 >
, bool > 
readDimensions (std::istream &in, size_t &lineNumber, const bool tolerant=false)
 Read (numRows, numCols, numNonzeros).

Protected Member Functions

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.

Protected Attributes

RCP< Callback > adder_
 Closure that knows how to add entries to the sparse graph or matrix.

Detailed Description

template<class Callback, class Ordinal>
class Tpetra::MatrixMarket::CoordDataReaderBase< Callback, Ordinal >

Common functionality of a coordinate-format sparse matrix or graph data reader.

This class provides common functionality for reading coordinate-format sparse matrix or graph data from a Matrix Market file. In particular, this class does not depend on the Scalar type, so it works for both graph and matrix data.

Template Parameters:
CallbackThe type of a callback (a.k.a. closure) that knows how to add entries to the sparse graph or matrix.
Parameters:
OrdinalThe type of indices of the sparse graph or matrix.

Definition at line 63 of file MatrixMarket_CoordDataReader.hpp.


Constructor & Destructor Documentation

template<class Callback , class Ordinal >
Tpetra::MatrixMarket::CoordDataReaderBase< Callback, Ordinal >::CoordDataReaderBase ( const RCP< Callback > &  adder) [inline]

Constructor with "adder" argument.

This is the favored way to construct an instance of this type. Only use the no-argument constructor if you have a "chicken-and-egg" problem (where the adder needs the graph or matrix dimensions).

Parameters:
adder[in/out] Closure (a.k.a. callback) whose operator() adds an entry to the sparse graph or matrix on each invocation.

Definition at line 79 of file MatrixMarket_CoordDataReader.hpp.

template<class Callback , class Ordinal >
Tpetra::MatrixMarket::CoordDataReaderBase< Callback, Ordinal >::CoordDataReaderBase ( ) [inline]

No-argument constructor.

We offer this option in case the adder's constructor needs the graph or matrix dimensions, so that it's necessary to call readDimensions() first before constructing the adder. You should call setAdder() with a non-null argument before calling read() or readLine().

Definition at line 89 of file MatrixMarket_CoordDataReader.hpp.

template<class Callback , class Ordinal >
virtual Tpetra::MatrixMarket::CoordDataReaderBase< Callback, Ordinal >::~CoordDataReaderBase ( ) [inline, virtual]

Virtual destructor for safety and happy compilers.

Definition at line 92 of file MatrixMarket_CoordDataReader.hpp.


Member Function Documentation

template<class Callback , class Ordinal >
void Tpetra::MatrixMarket::CoordDataReaderBase< Callback, Ordinal >::setAdder ( const RCP< Callback > &  adder) [inline]

Set the Adder object.

Please don't call this after calling read() or readLine(). The right time to call this is right after calling the no-argument constructor, if it's not possible to supply an Adder object before calling readDimensions().

Definition at line 100 of file MatrixMarket_CoordDataReader.hpp.

template<class Callback , class Ordinal >
virtual bool Tpetra::MatrixMarket::CoordDataReaderBase< Callback, Ordinal >::readLine ( const std::string &  theLine,
const size_t  lineNumber,
const bool  tolerant 
) [protected, pure virtual]

Read in the data from a single line of the input stream.

Parameters:
theLine[in] The line read in from the input stream.
adder[in/out] The callback to invoke for adding an entry to the sparse matrix.
lineNumber[in] Current line number of the file. We use this for generating informative exception messages.
tolerant[in] Whether to parse tolerantly.
Returns:
In tolerant parsing mode (tolerant==true), then this method returns true if parsing the current line succeeded, else false. Otherwise, this method throws an exception (and does not invoke the adder) if parsing the current line did not succeed.
Note:
To implementers: Use the callback (adder_) in your implementations of this method to add entries to the sparse graph or matrix.
To implementers: We defer implementation of this method to subclasses, because the callback for a graph will take different arguments than the callback for a matrix. Abstracting around that using templates isn't worth the trouble. (Remember you're reading from a file and parsing strings. Virtual method call overhead isn't significant by comparison.)

Implemented in Tpetra::MatrixMarket::CoordDataReader< Callback, Ordinal, Scalar, isComplex >, and Tpetra::MatrixMarket::CoordPatternReader< Callback, Ordinal >.

template<class Callback , class Ordinal >
virtual std::pair<bool, std::vector<size_t> > Tpetra::MatrixMarket::CoordDataReaderBase< Callback, Ordinal >::read ( std::istream &  in,
const size_t  startingLineNumber,
const bool  tolerant,
const bool  debug = false 
) [inline, virtual]

Read in all the data from the given input stream.

Parameters:
in[in/out] The input stream from which to read
startingLineNumber[in] The line number of the file from which we begin reading. (This is used for informative error output, if an error is detected in the file.)
tolerant[in] If true, parse tolerantly. The resulting read-in data may be incorrect, but the parser won't throw an exception if it can just let bad data through and continue.
debug[in] If true, print verbose debugging output.
Returns:
If tolerant==false, the returned pair is always true and the empty vector. If tolerant==true, the first entry of the pair is whether all lines of data were read successfully, and the second entry is the list of line numbers containing bad data. The first entry of the pair is false if and only if the vector has nonzero size.
Note:
This method is virtual in case derived classes want to override the default behavior. The specific example we have in mind is a "pattern matrix" (i.e., a sparse graph), which we would represent with Scalar=void.

Definition at line 167 of file MatrixMarket_CoordDataReader.hpp.

template<class Callback , class Ordinal >
std::pair<Tuple<Ordinal, 3>, bool> Tpetra::MatrixMarket::CoordDataReaderBase< Callback, Ordinal >::readDimensions ( std::istream &  in,
size_t &  lineNumber,
const bool  tolerant = false 
) [inline]

Read (numRows, numCols, numNonzeros).

Read one line from the given input stream, and parse it into the number of rows, the number of columns, and the number of nonzeros in the sparse matrix. We assume that those data are in whitespace-delimited format and are read from a Matrix Market - format file.

Parameters:
in[in/out] The input stream from which to attempt to read one line.
lineNumberThe starting line number from which we begin reading from the input stream. Used for diagnostic error output.
tolerant[in] Whether to read "tolerantly" (setting defaults and returning whether we were successful) or "intolerantly" (throwing an exception on any deviation from the expected format).
Returns:
((numRows, numCols, numNonzeros), success). In tolerant mode, success may be false, meaning that the read-in triple may not be valid.

Definition at line 227 of file MatrixMarket_CoordDataReader.hpp.


Member Data Documentation

template<class Callback , class Ordinal >
RCP<Callback> Tpetra::MatrixMarket::CoordDataReaderBase< Callback, Ordinal >::adder_ [protected]

Closure that knows how to add entries to the sparse graph or matrix.

Definition at line 66 of file MatrixMarket_CoordDataReader.hpp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines