inline MKL_INT qr_solve_factored(MKL_INT m, MKL_INT n, MKL_INT bn, T r[], T b[], T tau[], T x[], T work[], MKL_INT len, void (*ormqr)(const char*, const char*, const MKL_INT*, const MKL_INT*, const MKL_INT*, const T*, const MKL_INT*, const T*, T*, const MKL_INT*, T*, const MKL_INT*, MKL_INT* info), void (*trsm)(const CBLAS_ORDER, const CBLAS_SIDE, const CBLAS_UPLO, const CBLAS_TRANSPOSE, const CBLAS_DIAG, const MKL_INT, const MKL_INT, const T, const T*, const MKL_INT, T*, const MKL_INT)) { T* clone_b = Clone(m, bn, b); char side ='L'; char tran = 'T'; MKL_INT info = 0; ormqr(&side, &tran, &m, &bn, &n, r, &m, tau, clone_b, &m, work, &len, &info); trsm(CblasColMajor, CblasLeft, CblasUpper, CblasNoTrans, CblasNonUnit, n, bn, 1.0, r, m, clone_b, m); copyBtoX(m, n, bn, clone_b, x); delete[] clone_b; return info; }
void TNqrsolve(double **aIn, double *bIn, double *xOut, int msize, double &det, int &info){ double *a; a = qr_ctof(aIn, msize, msize); double **Atemp = new double *[msize]; for(int i = 0 ; i <msize; i++){ Atemp[i] = new double[msize]; } double *b = new double[msize]; for(int i =0 ; i < msize; i++){ b[i]=bIn[i]; } double* tau = new double[msize]; int tempinfo=0; tempinfo=geqrf(msize, msize, a, msize, tau); if(tempinfo != 0)info=tempinfo; qr_ftoc(a, Atemp, msize, msize); det=0; for(int i =0; i < msize; i++){ det += log(fabs(Atemp[i][i])); } tempinfo=0; tempinfo=ormqr('L', 'T', msize, 1, msize, a, msize, tau, b, msize); if(tempinfo != 0)info=tempinfo; tempinfo=0; tempinfo=trtrs('U', 'N', 'N', msize, 1, a, msize, b, msize); if(tempinfo != 0)info=tempinfo; for(int i =0; i < msize; i++){ xOut[i] = b[i]; } //tempinfo = trrfs('U', 'N', 'N', msize, 1, a, msize, bIn, msize, xOut, msize); delete[] a; delete[] tau; delete[] b; for(int i = 0 ; i <msize; i++){ delete[] Atemp[i]; } delete[] Atemp; }
inline int ormqr (char side, char trans, const A& a, const Tau& tau, C& c, Work& work) { #ifndef BOOST_NUMERIC_BINDINGS_NO_STRUCTURE_CHECK BOOST_STATIC_ASSERT((boost::is_same< typename traits::matrix_traits<A>::matrix_structure, traits::general_t >::value)); BOOST_STATIC_ASSERT((boost::is_same< typename traits::matrix_traits<C>::matrix_structure, traits::general_t >::value)); #endif int const m = traits::matrix_size1 (c); int const n = traits::matrix_size2 (c); int const k = traits::vector_size (tau); int const lwork = traits::vector_size (work); assert ( side=='L' || side=='R' ); assert ( trans=='N' || trans=='C' || trans=='T' ); assert ( (side=='L' ? m >= k : n >= k ) ); assert ( (side=='L' ? m == traits::matrix_size1 (a) : n == traits::matrix_size1 (a) ) ); assert (traits::matrix_size2 (a)==k); assert ( (side=='L' ? lwork >= n : lwork >= m ) ); int info; ormqr (side, trans, m, n, k, traits::matrix_storage (a), traits::leading_dimension (a), traits::vector_storage (tau), traits::matrix_storage (c), traits::leading_dimension (c), traits::vector_storage (work), lwork, info); return info; }