// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2012 Desire Nuentsa Wakam // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed #define EIGEN_NO_DEBUG_SMALL_PRODUCT_BLOCKS #include "sparse.h" #include template int generate_sparse_rectangular_problem(MatrixType& A, DenseMat& dA, int maxRows = 300, int maxCols = 300) { eigen_assert(maxRows >= maxCols); typedef typename MatrixType::Scalar Scalar; int rows = internal::random(1,maxRows); int cols = internal::random(1,rows); double density = (std::max)(8./(rows*cols), 0.01); A.resize(rows,cols); dA.resize(rows,cols); initSparse(density, dA, A,ForceNonZeroDiag); A.makeCompressed(); return rows; } template void test_spqr_scalar() { typedef SparseMatrix MatrixType; MatrixType A; Matrix dA; typedef Matrix DenseVector; DenseVector refX,x,b; SPQR solver; generate_sparse_rectangular_problem(A,dA); Index m = A.rows(); b = DenseVector::Random(m); solver.compute(A); if (solver.info() != Success) { std::cerr << "sparse QR factorization failed\n"; exit(0); return; } x = solver.solve(b); if (solver.info() != Success) { std::cerr << "sparse QR factorization failed\n"; exit(0); return; } //Compare with a dense solver refX = dA.colPivHouseholderQr().solve(b); VERIFY(x.isApprox(refX,test_precision())); } EIGEN_DECLARE_TEST(spqr_support) { CALL_SUBTEST_1(test_spqr_scalar()); CALL_SUBTEST_2(test_spqr_scalar >()); }