diff options
author | Gael Guennebaud <g.gael@free.fr> | 2012-01-28 11:13:59 +0100 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2012-01-28 11:13:59 +0100 |
commit | 87138075dad1bcef1c496704f2cc3d6983156cbb (patch) | |
tree | 8b977e4b058c91fbbbb93691683f1af5c7554625 /Eigen/src/SparseCore/SparseUtil.h | |
parent | fc2d85d139afeab3fb36d5b2edcda5c33df95fd1 (diff) |
add the possibility to assemble a SparseMatrix object from a random list of triplets that may contain duplicated elements. It works in linear time, with O(1) re-allocations.
Diffstat (limited to 'Eigen/src/SparseCore/SparseUtil.h')
-rw-r--r-- | Eigen/src/SparseCore/SparseUtil.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Eigen/src/SparseCore/SparseUtil.h b/Eigen/src/SparseCore/SparseUtil.h index a03cdbd5b..248ae7898 100644 --- a/Eigen/src/SparseCore/SparseUtil.h +++ b/Eigen/src/SparseCore/SparseUtil.h @@ -149,4 +149,35 @@ template<typename T> struct plain_matrix_type<T,Sparse> } // end namespace internal +/** \ingroup SparseCore_Module + * + * \class Triplet + * + * \brief A small structure to hold a non zero as a triplet (i,j,value). + * + * \sa SparseMatrix::setFromTriplets() + */ +template<typename Scalar, typename Index=unsigned int> +class Triplet +{ +public: + Triplet() : m_row(0), m_col(0), m_value(0) {} + + Triplet(const Index& i, const Index& j, const Scalar& v = Scalar(0)) + : m_row(i), m_col(j), m_value(v) + {} + + /** \returns the row index of the element */ + const Index& row() const { return m_row; } + + /** \returns the column index of the element */ + const Index& col() const { return m_col; } + + /** \returns the value of the element */ + const Scalar& value() const { return m_value; } +protected: + Index m_row, m_col; + Scalar m_value; +}; + #endif // EIGEN_SPARSEUTIL_H |