Teuchos - Trilinos Tools Package Version of the Day
Public Member Functions | Protected Member Functions
Teuchos::MatrixMarket::CoordDataReader< Callback, Ordinal, Scalar, isComplex > Class Template Reference

Coordinate-format sparse matrix data reader. More...

#include <Teuchos_MatrixMarket_CoordDataReader.hpp>

Inheritance diagram for Teuchos::MatrixMarket::CoordDataReader< Callback, Ordinal, Scalar, isComplex >:
Teuchos::MatrixMarket::CoordDataReaderBase< Callback, Ordinal >

List of all members.

Public Member Functions

 CoordDataReader (const Teuchos::RCP< Callback > &adder)
 Constructor with "adder" argument.
 CoordDataReader ()
 No-argument constructor.
virtual ~CoordDataReader ()
 Virtual destructor for safety and happy compilers.

Protected Member Functions

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.

Detailed Description

template<class Callback, class Ordinal, class Scalar, bool isComplex = Teuchos::ScalarTraits<Scalar>::isComplex>
class Teuchos::MatrixMarket::CoordDataReader< Callback, Ordinal, Scalar, isComplex >

Coordinate-format sparse matrix data reader.

Use this class to read in sparse matrix data and add it to the sparse matrix using your Callback implementation (see the documentation of CoordDataReaderBase).

Template Parameters:
CallbackSame as in CoordDataReaderBase. Its operator() takes three arguments: the row index, the column index, and the matrix value. The indices are all one-based.
OrdinalSame as in CoordDataReaderBase. The type of indices in the sparse matrix.
ScalarThe type of entries of the sparse matrix. For a real Scalar type (isComplex=false), any type for which a Teuchos::ScalarTraits specialization exists is valid. If Scalar is complex (isComplex=true), then Scalar's operator= must accept an std::complex<typename Teuchos::ScalarTraits<Scalar>::magnitudeType> input.
isComplexWhether Scalar is a complex-valued type or a real-valued type. The default value here is fine for most users.

This class completes the implementation of CoordDataReaderBase for sparse matrices. We provide two partial specializations: one for real-valued data (isComplex=false), and the other for complex-valued data (isComplex=true).

If you have an existing sparse matrix implementation to which you want to add entries, you'll either have to make it implement Callback's three-argument operator(), or write your own Callback implementation that wraps the sparse matrix.

Definition at line 461 of file Teuchos_MatrixMarket_CoordDataReader.hpp.


Constructor & Destructor Documentation

template<class Callback , class Ordinal , class Scalar , bool isComplex = Teuchos::ScalarTraits<Scalar>::isComplex>
Teuchos::MatrixMarket::CoordDataReader< Callback, Ordinal, Scalar, isComplex >::CoordDataReader ( const Teuchos::RCP< Callback > &  adder)

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 matrix dimensions. This is the case if your Callback wraps Tpetra::CrsMatrix, for example.

Parameters:
adder[in/out] Closure (a.k.a. callback) whose operator() adds an entry to the sparse graph or matrix on each invocation.
template<class Callback , class Ordinal , class Scalar , bool isComplex = Teuchos::ScalarTraits<Scalar>::isComplex>
Teuchos::MatrixMarket::CoordDataReader< Callback, Ordinal, Scalar, isComplex >::CoordDataReader ( )

No-argument constructor.

We offer this option in case the adder's constructor needs the 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().

template<class Callback , class Ordinal , class Scalar , bool isComplex = Teuchos::ScalarTraits<Scalar>::isComplex>
virtual Teuchos::MatrixMarket::CoordDataReader< Callback, Ordinal, Scalar, isComplex >::~CoordDataReader ( ) [virtual]

Virtual destructor for safety and happy compilers.


Member Function Documentation

template<class Callback , class Ordinal , class Scalar , bool isComplex = Teuchos::ScalarTraits<Scalar>::isComplex>
bool Teuchos::MatrixMarket::CoordDataReader< Callback, Ordinal, Scalar, isComplex >::readLine ( const std::string &  theLine,
const size_t  lineNumber,
const bool  tolerant 
) [protected, 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.

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.

Note:
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.)

Implements Teuchos::MatrixMarket::CoordDataReaderBase< Callback, Ordinal >.


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