Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | List of all members
Teuchos::MatrixMarket::Raw::GraphAdder< Ordinal > Class Template Reference

To be used with Checker for "raw" sparse matrix input. More...

#include <Teuchos_MatrixMarket_Raw_Graph_Adder.hpp>

Public Member Functions

 GraphAdder ()
 Default constructor. More...
 
 GraphAdder (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 bool countAgainstTotal=true)
 Add an entry to the sparse graph. More...
 
void print (std::ostream &out, const bool doMerge, const bool replace=false)
 Print the sparse graph data. More...
 
std::pair< size_type, size_type > merge ()
 Merge duplicate elements. More...
 
void mergeAndConvertToCSR (size_type &numUniqueElts, size_type &numRemovedElts, Teuchos::ArrayRCP< Ordinal > &rowptr, Teuchos::ArrayRCP< Ordinal > &colind)
 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 graph. More...
 
void clear ()
 Clear all the added graph entries and reset metadata. More...
 
const Ordinal numRows () const
 Computed number of rows. More...
 
const Ordinal numCols () const
 Computed number of columns. More...
 

Detailed Description

template<class Ordinal>
class Teuchos::MatrixMarket::Raw::GraphAdder< Ordinal >

To be used with Checker for "raw" sparse matrix input.

Template Parameters
OrdinalThe type of indices in the sparse matrix.

This class implements the following interface, which is required by the Callback template parameter of Teuchos::MatrixMarket::CoordPatternReader:

class AdderType {
public:
typedef ... index_type; // Ellipsis represents the actual type
void operator() (const index_type, const index_type, const value_type&);
};

For GraphAdder, the Ordinal template parameter is index_type. GraphAdder provides a simple implementation of the above interface which is useful for things like printing out a sparse graph's entries, or converting between storage formats.

Definition at line 161 of file Teuchos_MatrixMarket_Raw_Graph_Adder.hpp.

Constructor & Destructor Documentation

template<class Ordinal >
Teuchos::MatrixMarket::Raw::GraphAdder< Ordinal >::GraphAdder ( )
inline

Default constructor.

If you call the default constructor, we assume that you want tolerant mode (in which the GraphAdder tries to infer the graph dimensions and number of entries from the actual graph 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 graph dimensions (m,n) wrong if the lower right entry of the graph is zero and is not supplied explicitly by calling operator().

Definition at line 177 of file Teuchos_MatrixMarket_Raw_Graph_Adder.hpp.

template<class Ordinal >
Teuchos::MatrixMarket::Raw::GraphAdder< Ordinal >::GraphAdder ( const Ordinal  expectedNumRows,
const Ordinal  expectedNumCols,
const Ordinal  expectedNumEntries,
const bool  tolerant = false,
const bool  debug = false 
)
inline

Standard constructor.

Parameters
expectedNumRows[in] Number of rows in the graph, as specified by the matrix metadata.
expectedNumCols[in] Number of columns in the graph, as specified by the matrix metadata.
expectedNumEntries[in] Number of entries in the graph, as specified by the matrix metadata.
tolerant[in] Whether the "expected" metadata is required to match what the read-in graph entries tell us.
debug[in] If true, we may print copious status output for debugging purposes.

Definition at line 205 of file Teuchos_MatrixMarket_Raw_Graph_Adder.hpp.

Member Function Documentation

template<class Ordinal >
void Teuchos::MatrixMarket::Raw::GraphAdder< Ordinal >::operator() ( const Ordinal  i,
const Ordinal  j,
const bool  countAgainstTotal = true 
)
inline

Add an entry to the sparse graph.

If tolerant==false, this method will perform error checking to ensure that the graph 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 graph entries. Regardless, this method will update the "actual" metadata.

Parameters
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 241 of file Teuchos_MatrixMarket_Raw_Graph_Adder.hpp.

template<class Ordinal >
void Teuchos::MatrixMarket::Raw::GraphAdder< Ordinal >::print ( std::ostream &  out,
const bool  doMerge,
const bool  replace = false 
)
inline

Print the sparse graph data.

We always print the data sorted. You may also merge duplicate entries if you prefer.

Parameters
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.
Warning
It never makes sense for replace to be true. Perhaps we should get rid of this argument at some point.

Definition at line 292 of file Teuchos_MatrixMarket_Raw_Graph_Adder.hpp.

template<class Ordinal >
std::pair<size_type, size_type> Teuchos::MatrixMarket::Raw::GraphAdder< Ordinal >::merge ( )
inline

Merge duplicate elements.

Merge elements of the sparse graph that have the same row and column indices ("duplicates"). Resize the array of elements to fit just the "unique" (not duplicate) elements.

Returns
(# unique elements, # removed elements)
Note
This method does not change the "expected" or "seen" numbers of entries, since both of those count entries with the same row and column indices as separate entries.

Definition at line 321 of file Teuchos_MatrixMarket_Raw_Graph_Adder.hpp.

template<class Ordinal >
void Teuchos::MatrixMarket::Raw::GraphAdder< Ordinal >::mergeAndConvertToCSR ( size_type &  numUniqueElts,
size_type &  numRemovedElts,
Teuchos::ArrayRCP< Ordinal > &  rowptr,
Teuchos::ArrayRCP< Ordinal > &  colind 
)
inline

Merge duplicate elements and convert to zero-based CSR.

Merge elements of the sparse graph 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.

Parameters
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 graph. 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 graph. Same number of entries as values. colind[k] is the column index of values[k].
Note
This method does not change the "expected" or "seen" numbers of entries, since both of those count entries with the same row and column indices as separate entries.

Definition at line 376 of file Teuchos_MatrixMarket_Raw_Graph_Adder.hpp.

template<class Ordinal >
const std::vector<element_type>& Teuchos::MatrixMarket::Raw::GraphAdder< Ordinal >::getEntries ( ) const
inline

A temporary const view of the entries of the graph.

Definition at line 436 of file Teuchos_MatrixMarket_Raw_Graph_Adder.hpp.

template<class Ordinal >
void Teuchos::MatrixMarket::Raw::GraphAdder< Ordinal >::clear ( )
inline

Clear all the added graph entries and reset metadata.

Definition at line 441 of file Teuchos_MatrixMarket_Raw_Graph_Adder.hpp.

template<class Ordinal >
const Ordinal Teuchos::MatrixMarket::Raw::GraphAdder< Ordinal >::numRows ( ) const
inline

Computed number of rows.

"Computed" means "as seen from the matrix data."

Definition at line 451 of file Teuchos_MatrixMarket_Raw_Graph_Adder.hpp.

template<class Ordinal >
const Ordinal Teuchos::MatrixMarket::Raw::GraphAdder< Ordinal >::numCols ( ) const
inline

Computed number of columns.

"Computed" means "as seen from the matrix data."

Definition at line 456 of file Teuchos_MatrixMarket_Raw_Graph_Adder.hpp.


The documentation for this class was generated from the following file: