void SimpleMatrix::SolveByLeastSquares(SiconosVector &B) { if (B.isBlock()) SiconosMatrixException::selfThrow("SimpleMatrix::SolveByLeastSquares(SiconosVector &B) failed. Not yet implemented for V being a BlockVector."); DenseMat tmpB(B.size(), 1); ublas::column(tmpB, 0) = *(B.dense()); // Conversion of vector to matrix. Temporary solution. int info = 0; #ifdef USE_OPTIMAL_WORKSPACE info += lapack::gels(*mat.Dense, tmpB, lapack::optimal_workspace()); #endif #ifdef USE_MINIMAL_WORKSPACE info += lapack::gels(*mat.Dense, tmpB, lapack::minimal_workspace()); #endif if (info != 0) { std::cout << "info = " << info << std::endl; SiconosMatrixException::selfThrow("SimpleMatrix::SolveByLeastSquares failed."); } else { noalias(*(B.dense())) = ublas::column(tmpB, 0); } }
void SimpleMatrix::PLUForwardBackwardInPlace(SiconosVector &B) { if (B.isBlock()) SiconosMatrixException::selfThrow("SimpleMatrix PLUForwardBackwardInPlace(V) failed. Not yet implemented for V being a BlockVector."); DenseMat tmpB(B.size(), 1); ublas::column(tmpB, 0) = *(B.dense()); // Conversion of vector to matrix. Temporary solution. int info; if (_num == 1) { if (!_isPLUFactorized) // call gesv => LU-factorize+solve { // solve system: if (!_ipiv) _ipiv.reset(new VInt(size(0))); else _ipiv->resize(size(0)); info = lapack::gesv(*mat.Dense, *_ipiv, tmpB); _isPLUFactorized = true; /* ublas::matrix<double> COPY(*mat.Dense); ublas::vector<double> S(std::max(size(0),size(1))); ublas::matrix<double, ublas::column_major> U(size(0),size(1)); ublas::matrix<double, ublas::column_major> VT(size(0),size(1)); int ierr = lapack::gesdd(COPY, S, U, VT); printf("info = %d, ierr = %d, emax = %f, emin = %f , cond = %f\n",info,ierr,S(0),S(2),S(0)/S(2)); */ // B now contains solution: } else // call getrs: only solve using previous lu-factorization info = lapack::getrs(*mat.Dense, *_ipiv, tmpB); } else { if (!_isPLUFactorized) // call first PLUFactorizationInPlace { PLUFactorizationInPlace(); } // and then solve inplace_solve(*sparse(), tmpB, ublas::lower_tag()); inplace_solve(ublas::trans(*sparse()), tmpB, ublas::upper_tag()); info = 0; } if (info != 0) SiconosMatrixException::selfThrow("SimpleMatrix::PLUForwardBackwardInPlace failed."); else { noalias(*(B.dense())) = ublas::column(tmpB, 0); } }