summaryrefslogtreecommitdiffhomepage
path: root/eigen/test/sparse.h
diff options
context:
space:
mode:
Diffstat (limited to 'eigen/test/sparse.h')
-rw-r--r--eigen/test/sparse.h23
1 files changed, 13 insertions, 10 deletions
diff --git a/eigen/test/sparse.h b/eigen/test/sparse.h
index e19a763..9912e1e 100644
--- a/eigen/test/sparse.h
+++ b/eigen/test/sparse.h
@@ -53,15 +53,15 @@ enum {
* \param zeroCoords and nonzeroCoords allows to get the coordinate lists of the non zero,
* and zero coefficients respectively.
*/
-template<typename Scalar,int Opt1,int Opt2,typename Index> void
+template<typename Scalar,int Opt1,int Opt2,typename StorageIndex> void
initSparse(double density,
Matrix<Scalar,Dynamic,Dynamic,Opt1>& refMat,
- SparseMatrix<Scalar,Opt2,Index>& sparseMat,
+ SparseMatrix<Scalar,Opt2,StorageIndex>& sparseMat,
int flags = 0,
- std::vector<Matrix<Index,2,1> >* zeroCoords = 0,
- std::vector<Matrix<Index,2,1> >* nonzeroCoords = 0)
+ std::vector<Matrix<StorageIndex,2,1> >* zeroCoords = 0,
+ std::vector<Matrix<StorageIndex,2,1> >* nonzeroCoords = 0)
{
- enum { IsRowMajor = SparseMatrix<Scalar,Opt2,Index>::IsRowMajor };
+ enum { IsRowMajor = SparseMatrix<Scalar,Opt2,StorageIndex>::IsRowMajor };
sparseMat.setZero();
//sparseMat.reserve(int(refMat.rows()*refMat.cols()*density));
sparseMat.reserve(VectorXi::Constant(IsRowMajor ? refMat.rows() : refMat.cols(), int((1.5*density)*(IsRowMajor?refMat.cols():refMat.rows()))));
@@ -71,14 +71,17 @@ initSparse(double density,
//sparseMat.startVec(j);
for(Index i=0; i<sparseMat.innerSize(); i++)
{
- int ai(i), aj(j);
+ Index ai(i), aj(j);
if(IsRowMajor)
std::swap(ai,aj);
Scalar v = (internal::random<double>(0,1) < density) ? internal::random<Scalar>() : Scalar(0);
if ((flags&ForceNonZeroDiag) && (i==j))
{
+ // FIXME: the following is too conservative
v = internal::random<Scalar>()*Scalar(3.);
- v = v*v + Scalar(5.);
+ v = v*v;
+ if(numext::real(v)>0) v += Scalar(5);
+ else v -= Scalar(5);
}
if ((flags & MakeLowerTriangular) && aj>ai)
v = Scalar(0);
@@ -93,11 +96,11 @@ initSparse(double density,
//sparseMat.insertBackByOuterInner(j,i) = v;
sparseMat.insertByOuterInner(j,i) = v;
if (nonzeroCoords)
- nonzeroCoords->push_back(Matrix<Index,2,1> (ai,aj));
+ nonzeroCoords->push_back(Matrix<StorageIndex,2,1> (ai,aj));
}
else if (zeroCoords)
{
- zeroCoords->push_back(Matrix<Index,2,1> (ai,aj));
+ zeroCoords->push_back(Matrix<StorageIndex,2,1> (ai,aj));
}
refMat(ai,aj) = v;
}
@@ -163,7 +166,7 @@ initSparse(double density,
{
sparseVec.reserve(int(refVec.size()*density));
sparseVec.setZero();
- for(Index i=0; i<refVec.size(); i++)
+ for(int i=0; i<refVec.size(); i++)
{
Scalar v = (internal::random<double>(0,1) < density) ? internal::random<Scalar>() : Scalar(0);
if (v!=Scalar(0))