10 #ifndef __Teuchos_MatrixMarket_Raw_Graph_Adder_hpp
11 #define __Teuchos_MatrixMarket_Raw_Graph_Adder_hpp
29 namespace MatrixMarket {
53 template<
class Ordinal>
73 return ! (*
this == rhs);
101 template<
class Ordinal>
103 operator<< (std::ostream& out, const GraphElement<Ordinal>& elt)
105 out << elt.rowIndex () <<
" " << elt.colIndex ();
128 template<
class Ordinal>
133 typedef typename std::vector<element_type>::size_type
size_type;
174 const Ordinal expectedNumCols,
175 const Ordinal expectedNumEntries,
176 const bool tolerant=
false,
177 const bool debug=
false) :
211 const bool countAgainstTotal=
true)
214 const bool indexPairOutOfRange = i < 1 || j < 1 ||
219 << expectedNumCols_ <<
", so entry A(" << i <<
"," << j
220 <<
") is out of range.");
221 if (countAgainstTotal) {
223 std::invalid_argument,
"Cannot add entry A(" << i <<
"," << j
224 <<
") to graph; already have expected number "
238 if (countAgainstTotal) {
260 print (std::ostream& out,
const bool doMerge,
const bool replace=
false)
264 (replace, std::logic_error,
"replace = true not implemented!");
271 typedef std::ostream_iterator<element_type> iter_type;
272 std::copy (
elts_.begin(),
elts_.end(), iter_type (out,
"\n"));
288 std::pair<size_type, size_type>
291 typedef typename std::vector<element_type>::iterator iter_type;
307 elts_.resize( std::distance(
elts_.begin(),it) );
308 elts_.resize (numUnique);
309 return std::make_pair (numUnique, numRemoved);
352 std::pair<size_type, size_type> mergeResult =
merge();
368 typedef typename std::vector<element_type>::const_iterator iter_type;
370 for (iter_type it =
elts_.begin(); it !=
elts_.end(); ++it) {
371 const Ordinal i = it->rowIndex ();
372 const Ordinal j = it->colIndex ();
375 "current graph entry's row index " << i <<
" is less then what "
376 "should be the current row index lower bound " << curRow <<
".");
377 for (Ordinal k = curRow+1; k <= i; ++k) {
383 static_cast<size_t> (curInd) >=
elts_.size (),
384 std::logic_error,
"The current index " << curInd <<
" into ind "
385 "is >= the number of matrix entries " <<
elts_.size ()
390 for (Ordinal k = curRow+1; k <= nrows; ++k) {
399 numUniqueElts = mergeResult.first;
400 numRemovedElts = mergeResult.second;
439 #endif // #ifndef __Teuchos_MatrixMarket_Raw_Graph_Adder_hpp
bool operator==(const GraphElement &rhs)
Compare row and column indices.
To be used with Checker for "raw" sparse matrix input.
GraphAdder()
Default constructor.
bool operator<(const GraphElement &rhs) const
Lexicographic order first by row index, then by column index.
void clear()
Clear all the added graph entries and reset metadata.
bool operator!=(const GraphElement &rhs)
Compare row and column indices.
const std::vector< element_type > & getEntries() const
A temporary const view of the entries of the graph.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
const Ordinal numRows() const
Computed number of rows.
const Ordinal numCols() const
Computed number of columns.
Teuchos header file which uses auto-configuration information to include necessary C++ headers...
GraphElement< Ordinal > element_type
GraphElement()
Default constructor: an invalid entry of the graph.
Templated Parameter List class.
Ordinal colIndex() const
Column index (zero-based) of this GraphElement.
GraphElement(const Ordinal i, const Ordinal j)
Create a sparse graph entry at (i,j).
void operator()(const Ordinal i, const Ordinal j, const bool countAgainstTotal=true)
Add an entry to the sparse graph.
This structure defines some basic traits for the ordinal field type.
void print(std::ostream &out, const bool doMerge, const bool replace=false)
Print the sparse graph data.
std::vector< element_type > elts_
The actual matrix entries, stored as an array of structs.
GraphAdder(const Ordinal expectedNumRows, const Ordinal expectedNumCols, const Ordinal expectedNumEntries, const bool tolerant=false, const bool debug=false)
Standard constructor.
Ordinal rowIndex() const
Row index (zero-based) of this GraphElement.
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.
Ordinal expectedNumEntries_
std::pair< size_type, size_type > merge()
Merge duplicate elements.
std::vector< element_type >::size_type size_type
Stores one entry of a sparse graph.
Reference-counted smart pointer for managing arrays.