42#ifndef __Teuchos_MatrixMarket_Raw_Adder_hpp
43#define __Teuchos_MatrixMarket_Raw_Adder_hpp
86 template<
class Scalar,
class Ordinal>
107 return ! (*
this ==
rhs);
126 template<
class BinaryFunction>
130 std::invalid_argument,
131 "Attempt to merge elements at different locations in the sparse "
132 "matrix. The current element is at (" <<
rowIndex() <<
", "
133 <<
colIndex() <<
") and the element you asked me to merge with it "
134 "is at (" <<
rhs.rowIndex() <<
", " <<
rhs.colIndex() <<
"). This "
135 "probably indicates a bug in the sparse matrix reader.");
149 std::invalid_argument,
150 "Attempt to merge elements at different locations in the sparse "
151 "matrix. The current element is at (" <<
rowIndex() <<
", "
152 <<
colIndex() <<
") and the element you asked me to merge with it "
153 "is at (" <<
rhs.rowIndex() <<
", " <<
rhs.colIndex() <<
"). This "
154 "probably indicates a bug in the sparse matrix reader.");
188 template<
class Scalar,
class Ordinal>
193 std::ios::fmtflags
f( out.flags() );
210 if (! STS::isOrdinal) {
215 out << std::scientific;
218 out << std::setbase (10);
232 out << std::setprecision (
numDigits + 1);
234 out <<
elt.rowIndex () <<
" " <<
elt.colIndex () <<
" ";
235 if (STS::isComplex) {
236 out << STS::real (
elt.value ()) <<
" " << STS::imag (
elt.value ());
282 template<
class Scalar,
class Ordinal>
288 typedef typename std::vector<element_type>::size_type
size_type;
332 const bool debug=
false) :
376 <<
Aij <<
" is out of range.");
379 std::invalid_argument,
"Cannot add entry A(" <<
i <<
"," <<
j
380 <<
") = " <<
Aij <<
" to matrix; already have expected number "
417 typedef std::ostream_iterator<element_type>
iter_type;
443 std::pair<size_type, size_type>
446 typedef typename std::vector<element_type>::iterator
iter_type;
562 typedef typename std::vector<element_type>::const_iterator
iter_type;
565 const Ordinal
i =
it->rowIndex ();
566 const Ordinal
j =
it->colIndex ();
570 "current matrix entry's row index " <<
i <<
" is less then what "
571 "should be the current row index lower bound " <<
curRow <<
".");
579 std::logic_error,
"The current index " <<
curInd <<
" into ind "
580 "and val is >= the number of matrix entries " <<
elts_.
size ()
Teuchos header file which uses auto-configuration information to include necessary C++ headers.
Templated Parameter List class.
Reference-counted smart pointer for managing arrays.
int size(const Comm< Ordinal > &comm)
Get the number of processes in the communicator.
To be used with Checker for "raw" sparse matrix input.
void operator()(const Ordinal i, const Ordinal j, const Scalar &Aij, const bool countAgainstTotal=true)
Add an entry to the sparse matrix.
std::vector< element_type >::size_type size_type
void print(std::ostream &out, const bool doMerge, const bool replace=false)
Print the sparse matrix data.
const std::vector< element_type > & getEntries() const
A temporary const view of the entries of the matrix.
const Ordinal numEntries() const
Computed number of columns.
Adder(const Ordinal expectedNumRows, const Ordinal expectedNumCols, const Ordinal expectedNumEntries, const bool tolerant=false, const bool debug=false)
Standard constructor.
Element< Scalar, Ordinal > element_type
std::pair< size_type, size_type > merge(const bool replace=false)
Merge duplicate elements.
const Ordinal numCols() const
Computed number of columns.
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.
void clear()
Clear all the added matrix entries and reset metadata.
Adder()
Default constructor.
Ordinal expectedNumEntries_
const Ordinal numRows() const
Computed number of rows.
std::vector< element_type > elts_
The actual matrix entries, stored as an array of structs.
Stores one entry of a sparse matrix.
Scalar value() const
Value (A(rowIndex(), colIndex()) of this Element.
bool operator<(const Element &rhs) const
Lexicographic order first by row index, then by column index.
void merge(const Element &rhs, const BinaryFunction &f)
Merge rhs into this Element, using custom binary function.
Ordinal colIndex() const
Column index (zero-based) of this Element.
Ordinal rowIndex() const
Row index (zero-based) of this Element.
void merge(const Element &rhs, const bool replace=false)
Merge rhs into this Element, either by addition or replacement.
Element()
Default constructor: an invalid entry of the matrix.
bool operator==(const Element &rhs)
Ignore the matrix value for comparisons.
bool operator!=(const Element &rhs)
Ignore the matrix value for comparisons.
Element(const Ordinal i, const Ordinal j, const Scalar &Aij)
Create a sparse matrix entry at (i,j) with value Aij.
Concrete serial communicator subclass.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
Matrix Market file utilities.
"Raw" input of sparse matrices from Matrix Market files.
std::ostream & operator<<(std::ostream &out, const Element< Scalar, Ordinal > &elt)
Print out an Element to the given output stream.
This structure defines some basic traits for the ordinal field type.
This structure defines some basic traits for a scalar field type.