Teuchos - Trilinos Tools Package
Version of the Day
|
Common functionality of a coordinate-format sparse matrix or graph data reader. More...
#include <Teuchos_MatrixMarket_CoordDataReader.hpp>
Public Member Functions | |
CoordDataReaderBase (const Teuchos::RCP< Callback > &adder) | |
Constructor with "adder" argument. More... | |
CoordDataReaderBase () | |
No-argument constructor. More... | |
virtual | ~CoordDataReaderBase () |
Virtual destructor for safety and happy compilers. More... | |
void | setAdder (const Teuchos::RCP< Callback > &adder) |
Set the Adder object. More... | |
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. More... | |
std::pair< Teuchos::Tuple < Ordinal, 3 >, bool > | readDimensions (std::istream &in, size_t &lineNumber, const bool tolerant=false) |
Read (numRows, numCols, numNonzeros). More... | |
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. More... | |
Protected Attributes | |
Teuchos::RCP< Callback > | adder_ |
Closure that knows how to add entries to the sparse graph or matrix. More... | |
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 type of matrix entries. If you are writing a function to read a sparse matrix, use CoordDataReader. If you are writing a function to read a sparse graph (a "pattern matrix" in Matrix Market terms), use CoordPatternReader. If you just want to read a sparse matrix into raw compressed sparse row (CSR) arrays, use Raw::Reader. This class is mainly for Teuchos developers.
Callback | The type of a callback (a.k.a. closure) that knows how to add entries to the sparse graph or matrix. |
Ordinal | The type of indices of the sparse graph or matrix. |
Instances of Callback must implement an operator() that adds a single entry to the sparse matrix. If the matrix contains values (i.e., is not a "pattern" matrix), the Callback's operator() takes three arguments: the row index, the column index, and the value to add. If the matrix is a "pattern" matrix, then the operator() takes two arguments: the row index, and the column index. In either case, the Callback expects one-based row and column indices, as specified by the Matrix Market standard. The Raw::Adder class provides a model for Callback with the three-argument version of operator().
The Callback object defines for itself what happens if one attempts to insert two entries at the same location. They must be "merged" in some way. Usually the right thing to do is to add the values of the two entries, but you may want to define different behavior. Your Callback implementation may defer merging entries at the same location for performance reasons. (Raw::Adder does this. Its merge() method merges the entries.)
Note that this class does not have the notion of the type of entries of the matrix, only the type of the indices in the matrix (Ordinal). The CoordDataReader subclass defines the type of matrix entries as its Scalar template parameter. The CoordPatternReader subclass does not define the type of matrix entries, because it stores a graph (a "pattern matrix" in Matrix Market terms).
Definition at line 68 of file Teuchos_MatrixMarket_CoordDataReader.hpp.
|
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 in order to create the Callback instance, you need the graph or matrix dimensions.
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 84 of file Teuchos_MatrixMarket_CoordDataReader.hpp.
|
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 94 of file Teuchos_MatrixMarket_CoordDataReader.hpp.
|
inlinevirtual |
Virtual destructor for safety and happy compilers.
Definition at line 97 of file Teuchos_MatrixMarket_CoordDataReader.hpp.
|
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 105 of file Teuchos_MatrixMarket_CoordDataReader.hpp.
|
protectedpure virtual |
Read in the data from a single line of the input stream.
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. |
Subclasses must implement this method in order to read one entry of the sparse graph or matrix. Implementations should use the callback (adder_
) to add the entry.
Implemented in Teuchos::MatrixMarket::CoordPatternReader< Callback, Ordinal >, and Teuchos::MatrixMarket::CoordDataReader< Callback, Ordinal, Scalar, isComplex >.
|
inlinevirtual |
Read in all the data from the given input stream.
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. |
Definition at line 171 of file Teuchos_MatrixMarket_CoordDataReader.hpp.
|
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.
in | [in/out] The input stream from which to attempt to read one line. |
lineNumber | The 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). |
Definition at line 226 of file Teuchos_MatrixMarket_CoordDataReader.hpp.
|
protected |
Closure that knows how to add entries to the sparse graph or matrix.
Definition at line 71 of file Teuchos_MatrixMarket_CoordDataReader.hpp.