Teuchos - Trilinos Tools Package
Version of the Day
|
To be used with Checker for "raw" sparse matrix input. More...
#include <Teuchos_MatrixMarket_Raw_Adder.hpp>
Public Member Functions | |
Adder () | |
Default constructor. More... | |
Adder (const Ordinal expectedNumRows, const Ordinal expectedNumCols, const Ordinal expectedNumEntries, const bool tolerant=false, const bool debug=false) | |
Standard constructor. More... | |
void | operator() (const Ordinal i, const Ordinal j, const Scalar &Aij, const bool countAgainstTotal=true) |
Add an entry to the sparse matrix. More... | |
void | print (std::ostream &out, const bool doMerge, const bool replace=false) |
Print the sparse matrix data. More... | |
std::pair< size_type, size_type > | merge (const bool replace=false) |
Merge duplicate elements. More... | |
void | mergeAndConvertToCSR (size_type &numUniqueElts, size_type &numRemovedElts, Teuchos::ArrayRCP< Ordinal > &rowptr, Teuchos::ArrayRCP< Ordinal > &colind, Teuchos::ArrayRCP< Scalar > &values, const bool replace=false) |
Merge duplicate elements and convert to zero-based CSR. More... | |
const std::vector< element_type > & | getEntries () const |
A temporary const view of the entries of the matrix. More... | |
void | clear () |
Clear all the added matrix entries and reset metadata. More... | |
const Ordinal | numRows () const |
Computed number of rows. More... | |
const Ordinal | numCols () const |
Computed number of columns. More... | |
const Ordinal | numEntries () const |
Computed number of columns. More... | |
To be used with Checker for "raw" sparse matrix input.
Scalar | The type of entries in the sparse matrix. |
Ordinal | The type of indices in the sparse matrix. |
This class implements the following interface, which is required by the Callback template parameter of Teuchos::MatrixMarket::CoordDataReader:
For Adder, the Scalar template parameter is value_type, and the Ordinal template parameter is index_type. Adder provides a simple implementation of the above interface which is useful for things like printing out a sparse matrix's entries, or converting between storage formats.
It is possible to nest classes that implement the above interface, in order to modify the definition of inserting values into a sparse matrix. (If you are familiar with Emacs Lisp, this is called "advising" (the insertion function, in this case). See the Emacs Lisp Manual for details.) If you are building a chain of classes, each of which implements the above interface by calling the next lower class' operator() beneath it, this class is a good start, since it implements insertion of values directly. SymmetrizingAdder is an example; it "advises" Adder by inserting an entry at (j,i) whenever Adder inserts an entry at (i,j) with i != j.
Definition at line 251 of file Teuchos_MatrixMarket_Raw_Adder.hpp.
|
inline |
Default constructor.
If you call the default constructor, we assume that you want tolerant mode (in which the Adder tries to infer the matrix dimensions and number of entries from the actual matrix data, not from any metadata). Tolerant mode is similar to what Matlab does if you give it an ASCII file of (i,j,Aij) triples. It may get the matrix dimensions (m,n) wrong if the lower right entry of the matrix is zero and is not supplied explicitly by calling operator().
Definition at line 268 of file Teuchos_MatrixMarket_Raw_Adder.hpp.
|
inline |
Standard constructor.
expectedNumRows | [in] Number of rows in the matrix, as specified by the matrix metadata. |
expectedNumCols | [in] Number of columns in the matrix, as specified by the matrix metadata. |
expectedNumEntries | [in] Number of entries in the matrix, as specified by the matrix metadata. |
tolerant | [in] Whether the "expected" metadata is required to match what the read-in matrix entries tell us. |
debug | [in] If true, we may print copious status output for debugging purposes. |
Definition at line 296 of file Teuchos_MatrixMarket_Raw_Adder.hpp.
|
inline |
Add an entry to the sparse matrix.
If tolerant==false, this method will perform error checking to ensure that the matrix data matches the metadata. For example, it will check that i and j are in bounds. If countAgainstTotal is true, it will also check to make sure you haven't added more than the expected number of matrix entries. Regardless, this method will update the "actual" metadata.
i | [in] (1-based) row index |
j | [in] (1-based) column index |
Aij | [in] Value of the entry A(i,j) |
countAgainstTotal | [in] Whether to count the entry to insert against the total expected number of entries. The default is true. Make this false if you are inserting an entry that wasn't stored in the original Matrix Market file, which you're adding in order to preserve symmetry or some other related structural property of the matrix. |
Definition at line 332 of file Teuchos_MatrixMarket_Raw_Adder.hpp.
|
inline |
Print the sparse matrix data.
We always print the data sorted. You may also merge duplicate entries if you prefer.
out | [out] Output stream to which to print |
doMerge | [in] Whether to merge entries before printing |
replace | [in] If merging, whether to replace duplicate entries; otherwise their values are added together. |
Definition at line 377 of file Teuchos_MatrixMarket_Raw_Adder.hpp.
|
inline |
Merge duplicate elements.
Merge elements of the sparse matrix that have the same row and column indices ("duplicates"). Resize the array of elements to fit just the "unique" (not duplicate) elements.
replace | [in] If true, replace each duplicate element with the next element sharing the same row and column index. This means that results will depend on the order in which the duplicate elements were added. Otherwise, duplicate elements have their values added together; in that case, the result is independent (in exact arithmetic, not in finite-precision arithmetic) of their order. |
Definition at line 412 of file Teuchos_MatrixMarket_Raw_Adder.hpp.
|
inline |
Merge duplicate elements and convert to zero-based CSR.
Merge elements of the sparse matrix that have the same row and column indices ("duplicates"). Resize the array of elements to fit just the "unique" (not duplicate) elements. Return a CSR (compressed sparse row) version of the data, with zero-based indices.
We combine merge and conversion to CSR because the latter requires the former.
numUniqueElts | [out] Same as the first return value of merge(). |
numRemovedElts | [out] Same as the second return value of merge(). |
rowptr | [out] Array of numRows+1 offsets, where numRows is the number of rows in the sparse matrix. For row i (zero-based indexing), the entries of that row are in indices rowptr[i] .. rowptr[i+1]-1 of colind and values. |
colind | [out] Column indices of the matrix. Same number of entries as values. colind[k] is the column index of values[k]. |
values | [out] Values stored in the matrix. |
replace | [in] If true, replace each duplicate element with the next element sharing the same row and column index. This means that results will depend on the order in which the duplicate elements were added. Otherwise, duplicate elements have their values added together; in that case, the result is independent (in exact arithmetic, not in finite-precision arithmetic) of their order. |
Definition at line 503 of file Teuchos_MatrixMarket_Raw_Adder.hpp.
|
inline |
A temporary const view of the entries of the matrix.
Definition at line 569 of file Teuchos_MatrixMarket_Raw_Adder.hpp.
|
inline |
Clear all the added matrix entries and reset metadata.
Definition at line 574 of file Teuchos_MatrixMarket_Raw_Adder.hpp.
|
inline |
Computed number of rows.
"Computed" means "as seen from the matrix data."
Definition at line 584 of file Teuchos_MatrixMarket_Raw_Adder.hpp.
|
inline |
Computed number of columns.
"Computed" means "as seen from the matrix data."
Definition at line 589 of file Teuchos_MatrixMarket_Raw_Adder.hpp.
|
inline |
Computed number of columns.
"Computed" means "as seen from the matrix data."
Definition at line 594 of file Teuchos_MatrixMarket_Raw_Adder.hpp.