aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2016-12-14 17:05:26 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2016-12-14 17:05:26 +0100
commite67397bfa7cc1662774c4586f7532bbe3e69e0fd (patch)
tree18700af83e6f63ee0838c750c9cdeed343ed6da1 /test
parent98d74582751f65af99f94e9234b0817fa79f7fb9 (diff)
bug #1359: fix compilation of col_major_sparse.row() *= scalar
(used to work in 3.2.9 though the expression is not really writable)
Diffstat (limited to 'test')
-rw-r--r--test/sparse_block.cpp53
1 files changed, 44 insertions, 9 deletions
diff --git a/test/sparse_block.cpp b/test/sparse_block.cpp
index cb5213ade..2a0b3b617 100644
--- a/test/sparse_block.cpp
+++ b/test/sparse_block.cpp
@@ -9,6 +9,20 @@
#include "sparse.h"
+template<typename T>
+typename Eigen::internal::enable_if<(T::Flags&RowMajorBit)==RowMajorBit, typename T::RowXpr>::type
+innervec(T& A, Index i)
+{
+ return A.row(i);
+}
+
+template<typename T>
+typename Eigen::internal::enable_if<(T::Flags&RowMajorBit)==0, typename T::ColXpr>::type
+innervec(T& A, Index i)
+{
+ return A.col(i);
+}
+
template<typename SparseMatrixType> void sparse_block(const SparseMatrixType& ref)
{
const Index rows = ref.rows();
@@ -20,9 +34,10 @@ template<typename SparseMatrixType> void sparse_block(const SparseMatrixType& re
typedef typename SparseMatrixType::StorageIndex StorageIndex;
double density = (std::max)(8./(rows*cols), 0.01);
- typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrix;
+ typedef Matrix<Scalar,Dynamic,Dynamic,SparseMatrixType::IsRowMajor?RowMajor:ColMajor> DenseMatrix;
typedef Matrix<Scalar,Dynamic,1> DenseVector;
typedef Matrix<Scalar,1,Dynamic> RowDenseVector;
+ typedef SparseVector<Scalar> SparseVectorType;
Scalar s1 = internal::random<Scalar>();
{
@@ -110,15 +125,35 @@ template<typename SparseMatrixType> void sparse_block(const SparseMatrixType& re
initSparse<Scalar>(density, refMat2, m2);
Index j0 = internal::random<Index>(0,outer-1);
Index j1 = internal::random<Index>(0,outer-1);
- if(SparseMatrixType::IsRowMajor)
- VERIFY_IS_APPROX(m2.innerVector(j0), refMat2.row(j0));
- else
- VERIFY_IS_APPROX(m2.innerVector(j0), refMat2.col(j0));
+ Index r0 = internal::random<Index>(0,rows-1);
+ Index c0 = internal::random<Index>(0,cols-1);
- if(SparseMatrixType::IsRowMajor)
- VERIFY_IS_APPROX(m2.innerVector(j0)+m2.innerVector(j1), refMat2.row(j0)+refMat2.row(j1));
- else
- VERIFY_IS_APPROX(m2.innerVector(j0)+m2.innerVector(j1), refMat2.col(j0)+refMat2.col(j1));
+ VERIFY_IS_APPROX(m2.innerVector(j0), innervec(refMat2,j0));
+ VERIFY_IS_APPROX(m2.innerVector(j0)+m2.innerVector(j1), innervec(refMat2,j0)+innervec(refMat2,j1));
+
+ m2.innerVector(j0) *= Scalar(2);
+ innervec(refMat2,j0) *= Scalar(2);
+ VERIFY_IS_APPROX(m2, refMat2);
+
+ m2.row(r0) *= Scalar(3);
+ refMat2.row(r0) *= Scalar(3);
+ VERIFY_IS_APPROX(m2, refMat2);
+
+ m2.col(c0) *= Scalar(4);
+ refMat2.col(c0) *= Scalar(4);
+ VERIFY_IS_APPROX(m2, refMat2);
+
+ m2.row(r0) /= Scalar(3);
+ refMat2.row(r0) /= Scalar(3);
+ VERIFY_IS_APPROX(m2, refMat2);
+
+ m2.col(c0) /= Scalar(4);
+ refMat2.col(c0) /= Scalar(4);
+ VERIFY_IS_APPROX(m2, refMat2);
+
+ SparseVectorType v1;
+ VERIFY_IS_APPROX(v1 = m2.col(c0) * 4, refMat2.col(c0)*4);
+ VERIFY_IS_APPROX(v1 = m2.row(r0) * 4, refMat2.row(r0).transpose()*4);
SparseMatrixType m3(rows,cols);
m3.reserve(VectorXi::Constant(outer,int(inner/2)));