Fix sparse_product/sparse_extra unit tests

(grafted from ed461ba9bc
)
This commit is contained in:
Gael Guennebaud 2014-02-17 09:57:47 +01:00
parent e3d34064bf
commit 2ad3dac422
2 changed files with 11 additions and 9 deletions

View File

@ -178,10 +178,10 @@ initSparse(double density,
} }
} }
template<typename Scalar> void template<typename Scalar,int Options,typename Index> void
initSparse(double density, initSparse(double density,
Matrix<Scalar,1,Dynamic>& refVec, Matrix<Scalar,1,Dynamic>& refVec,
SparseVector<Scalar,RowMajor>& sparseVec, SparseVector<Scalar,Options,Index>& sparseVec,
std::vector<int>* zeroCoords = 0, std::vector<int>* zeroCoords = 0,
std::vector<int>* nonzeroCoords = 0) std::vector<int>* nonzeroCoords = 0)
{ {

View File

@ -13,8 +13,9 @@ template<typename SparseMatrixType, typename DenseMatrix, bool IsRowMajor=Sparse
template<typename SparseMatrixType, typename DenseMatrix> struct test_outer<SparseMatrixType,DenseMatrix,false> { template<typename SparseMatrixType, typename DenseMatrix> struct test_outer<SparseMatrixType,DenseMatrix,false> {
static void run(SparseMatrixType& m2, SparseMatrixType& m4, DenseMatrix& refMat2, DenseMatrix& refMat4) { static void run(SparseMatrixType& m2, SparseMatrixType& m4, DenseMatrix& refMat2, DenseMatrix& refMat4) {
int c = internal::random(0,m2.cols()-1); typedef typename SparseMatrixType::Index Index;
int c1 = internal::random(0,m2.cols()-1); Index c = internal::random<Index>(0,m2.cols()-1);
Index c1 = internal::random<Index>(0,m2.cols()-1);
VERIFY_IS_APPROX(m4=m2.col(c)*refMat2.col(c1).transpose(), refMat4=refMat2.col(c)*refMat2.col(c1).transpose()); VERIFY_IS_APPROX(m4=m2.col(c)*refMat2.col(c1).transpose(), refMat4=refMat2.col(c)*refMat2.col(c1).transpose());
VERIFY_IS_APPROX(m4=refMat2.col(c1)*m2.col(c).transpose(), refMat4=refMat2.col(c1)*refMat2.col(c).transpose()); VERIFY_IS_APPROX(m4=refMat2.col(c1)*m2.col(c).transpose(), refMat4=refMat2.col(c1)*refMat2.col(c).transpose());
} }
@ -22,8 +23,9 @@ template<typename SparseMatrixType, typename DenseMatrix> struct test_outer<Spar
template<typename SparseMatrixType, typename DenseMatrix> struct test_outer<SparseMatrixType,DenseMatrix,true> { template<typename SparseMatrixType, typename DenseMatrix> struct test_outer<SparseMatrixType,DenseMatrix,true> {
static void run(SparseMatrixType& m2, SparseMatrixType& m4, DenseMatrix& refMat2, DenseMatrix& refMat4) { static void run(SparseMatrixType& m2, SparseMatrixType& m4, DenseMatrix& refMat2, DenseMatrix& refMat4) {
int r = internal::random(0,m2.rows()-1); typedef typename SparseMatrixType::Index Index;
int c1 = internal::random(0,m2.cols()-1); Index r = internal::random<Index>(0,m2.rows()-1);
Index c1 = internal::random<Index>(0,m2.cols()-1);
VERIFY_IS_APPROX(m4=m2.row(r).transpose()*refMat2.col(c1).transpose(), refMat4=refMat2.row(r).transpose()*refMat2.col(c1).transpose()); VERIFY_IS_APPROX(m4=m2.row(r).transpose()*refMat2.col(c1).transpose(), refMat4=refMat2.row(r).transpose()*refMat2.col(c1).transpose());
VERIFY_IS_APPROX(m4=refMat2.col(c1)*m2.row(r), refMat4=refMat2.col(c1)*refMat2.row(r)); VERIFY_IS_APPROX(m4=refMat2.col(c1)*m2.row(r), refMat4=refMat2.col(c1)*refMat2.row(r));
} }
@ -37,9 +39,9 @@ template<typename SparseMatrixType> void sparse_product()
{ {
typedef typename SparseMatrixType::Index Index; typedef typename SparseMatrixType::Index Index;
Index n = 100; Index n = 100;
const Index rows = internal::random<int>(1,n); const Index rows = internal::random<Index>(1,n);
const Index cols = internal::random<int>(1,n); const Index cols = internal::random<Index>(1,n);
const Index depth = internal::random<int>(1,n); const Index depth = internal::random<Index>(1,n);
typedef typename SparseMatrixType::Scalar Scalar; typedef typename SparseMatrixType::Scalar Scalar;
enum { Flags = SparseMatrixType::Flags }; enum { Flags = SparseMatrixType::Flags };