aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2015-06-24 18:11:06 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2015-06-24 18:11:06 +0200
commit4c8cd13b35e4f6ff095ea34b91379e897e63ae2d (patch)
tree57fb4a3b7e95852033587654f9944a39520d6086
parentc38c1953218bdf8aebdeedd43c75407670bb0973 (diff)
Add explicit ctor for diagonal to sparse conversion
-rw-r--r--Eigen/src/SparseCore/SparseMatrix.h9
-rw-r--r--test/sparse_basic.cpp2
2 files changed, 11 insertions, 0 deletions
diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h
index 01fcaace8..f18829866 100644
--- a/Eigen/src/SparseCore/SparseMatrix.h
+++ b/Eigen/src/SparseCore/SparseMatrix.h
@@ -695,6 +695,15 @@ class SparseMatrix
initAssignment(other);
other.evalTo(*this);
}
+
+ /** \brief Copy constructor with in-place evaluation */
+ template<typename OtherDerived>
+ explicit SparseMatrix(const DiagonalBase<OtherDerived>& other)
+ : Base(), m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0)
+ {
+ check_template_parameters();
+ *this = other.derived();
+ }
/** Swaps the content of two sparse matrices of the same type.
* This is a fast operation that simply swaps the underlying pointers and parameters. */
diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp
index 2ebf4d420..492b3a4f2 100644
--- a/test/sparse_basic.cpp
+++ b/test/sparse_basic.cpp
@@ -372,6 +372,8 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
SparseMatrixType m2(rows, rows);
m2 = d.asDiagonal();
VERIFY_IS_APPROX(m2, refMat2);
+ SparseMatrixType m3(d.asDiagonal());
+ VERIFY_IS_APPROX(m3, refMat2);
refMat2 += d.asDiagonal();
m2 += d.asDiagonal();
VERIFY_IS_APPROX(m2, refMat2);