From 22c7609d72c3faaebe7931a4f6759e3c4546839a Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 22 Mar 2011 11:58:22 +0100 Subject: extend sparse product unit tests --- test/sparse.h | 51 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-) (limited to 'test/sparse.h') diff --git a/test/sparse.h b/test/sparse.h index 949a597fc..530ae30bc 100644 --- a/test/sparse.h +++ b/test/sparse.h @@ -1,7 +1,7 @@ // This file is part of Eigen, a lightweight C++ template library // for linear algebra. // -// Copyright (C) 2008 Daniel Gomez Ferro +// Copyright (C) 2008-2011 Gael Guennebaud // // Eigen is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -58,30 +58,35 @@ enum { * \param zeroCoords and nonzeroCoords allows to get the coordinate lists of the non zero, * and zero coefficients respectively. */ -template void +template void initSparse(double density, - Matrix& refMat, - SparseMatrix& sparseMat, + Matrix& refMat, + SparseMatrix& sparseMat, int flags = 0, std::vector* zeroCoords = 0, std::vector* nonzeroCoords = 0) { + enum { IsRowMajor = SparseMatrix::IsRowMajor }; sparseMat.setZero(); sparseMat.reserve(int(refMat.rows()*refMat.cols()*density)); - for(int j=0; j(0,1) < density) ? internal::random() : Scalar(0); if ((flags&ForceNonZeroDiag) && (i==j)) { v = internal::random()*Scalar(3.); v = v*v + Scalar(5.); } - if ((flags & MakeLowerTriangular) && j>i) + if ((flags & MakeLowerTriangular) && aj>ai) v = Scalar(0); - else if ((flags & MakeUpperTriangular) && jpush_back(Vector2i(i,j)); + nonzeroCoords->push_back(Vector2i(ai,aj)); } else if (zeroCoords) { - zeroCoords->push_back(Vector2i(i,j)); + zeroCoords->push_back(Vector2i(ai,aj)); } - refMat(i,j) = v; + refMat(ai,aj) = v; } } sparseMat.finalize(); } -template void +template void initSparse(double density, - Matrix& refMat, - DynamicSparseMatrix& sparseMat, + Matrix& refMat, + DynamicSparseMatrix& sparseMat, int flags = 0, std::vector* zeroCoords = 0, std::vector* nonzeroCoords = 0) { + enum { IsRowMajor = DynamicSparseMatrix::IsRowMajor }; sparseMat.setZero(); sparseMat.reserve(int(refMat.rows()*refMat.cols()*density)); - for(int j=0; j(0,1) < density) ? internal::random() : Scalar(0); if ((flags&ForceNonZeroDiag) && (i==j)) { v = internal::random()*Scalar(3.); v = v*v + Scalar(5.); } - if ((flags & MakeLowerTriangular) && j>i) + if ((flags & MakeLowerTriangular) && aj>ai) v = Scalar(0); - else if ((flags & MakeUpperTriangular) && jpush_back(Vector2i(i,j)); + nonzeroCoords->push_back(Vector2i(ai,aj)); } else if (zeroCoords) { - zeroCoords->push_back(Vector2i(i,j)); + zeroCoords->push_back(Vector2i(ai,aj)); } - refMat(i,j) = v; + refMat(ai,aj) = v; } } sparseMat.finalize(); -- cgit v1.2.3