From 709e9033355834e6d9166dd9eac975a383e55ece Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 7 Jan 2009 17:01:57 +0000 Subject: Sparse module: * extend unit tests * add support for generic sum reduction and dot product * optimize the cwise()* : this is a special case of CwiseBinaryOp where we only have to process the coeffs which are not null for *both* matrices. Perhaps there exist some other binary operations like that ? --- test/sparse_vector.cpp | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 test/sparse_vector.cpp (limited to 'test/sparse_vector.cpp') diff --git a/test/sparse_vector.cpp b/test/sparse_vector.cpp new file mode 100644 index 000000000..0a25884ca --- /dev/null +++ b/test/sparse_vector.cpp @@ -0,0 +1,92 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. Eigen itself is part of the KDE project. +// +// Copyright (C) 2008 Daniel Gomez Ferro +// +// Eigen is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// Alternatively, you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License and a copy of the GNU General Public License along with +// Eigen. If not, see . + +#include "sparse.h" + +template void sparse_vector(int rows, int cols) +{ + double densityMat = std::max(8./(rows*cols), 0.01); + double densityVec = std::max(8./float(rows), 0.1); + typedef Matrix DenseMatrix; + typedef Matrix DenseVector; + typedef SparseVector SparseVectorType; + typedef SparseMatrix SparseMatrixType; + Scalar eps = 1e-6; + + SparseMatrixType m1(rows,cols); + SparseVectorType v1(rows), v2(rows), v3(rows); + DenseMatrix refM1 = DenseMatrix::Zero(rows, cols); + DenseVector refV1 = DenseVector::Random(rows), + refV2 = DenseVector::Random(rows), + refV3 = DenseVector::Random(rows); + + std::vector zerocoords, nonzerocoords; + initSparse(densityVec, refV1, v1, &zerocoords, &nonzerocoords); + initSparse(densityMat, refM1, m1); + + initSparse(densityVec, refV2, v2); + initSparse(densityVec, refV3, v3); + + Scalar s1 = ei_random(); + + // test coeff and coeffRef + for (unsigned int i=0; i(8, 8) ); +// CALL_SUBTEST( sparse_vector >(16, 16) ); + CALL_SUBTEST( sparse_vector(299, 535) ); + } +} + -- cgit v1.2.3