42 #include "DenseLinAlgLAPack.hpp"
43 #include "DenseLinAlgPack_LAPACK_Cpp.hpp"
44 #include "DenseLinAlgPack_DMatrixAsTriSym.hpp"
45 #include "Teuchos_Assert.hpp"
50 T my_min(
const T& v1,
const T& v2 ) {
return v1 < v2 ? v1 : v2; }
53 void DenseLinAlgLAPack::potrf( DMatrixSliceTriEle* A )
55 FortranTypes::f_int info;
56 LAPACK_Cpp::potrf( A->uplo(), A->rows(), A->gms().col_ptr(1), A->gms().max_rows(), &info );
59 info < 0, std::invalid_argument
60 ,
"potrf(...): Error, Invalid argument "
61 << -info <<
" sent to LAPACK function xPOTRF(...)" );
64 true, FactorizationException
65 ,
"potrf(...): Error, Minor of order "
66 << info <<
" is not positive definite, the factorization "
67 "could not be completed" );
73 void DenseLinAlgLAPack::geqrf( DMatrixSlice* A, DVectorSlice* tau, DVectorSlice* work )
75 FortranTypes::f_int info;
76 if( tau->dim() != my_min( A->rows(), A->cols() ) ) {
78 true, std::invalid_argument,
"geqrf(...): Error, tau is not sized correctly!" );
80 LAPACK_Cpp::geqrf( A->rows(), A->cols(),A->col_ptr(1), A->max_rows()
81 , tau->raw_ptr(), work->raw_ptr(), work->dim(), &info );
84 info < 0, std::invalid_argument
85 ,
"geqrf(...): Error, Invalid argument "
86 << -info <<
" sent to LAPACK function xGEQRF(...)" );
91 void DenseLinAlgLAPack::ormrq(
93 ,
const DMatrixSlice& A,
const DVectorSlice& tau
94 ,DMatrixSlice* C, DVectorSlice* work
97 FortranTypes::f_int info;
98 LAPACK_Cpp::ormqr( side, trans, C->rows(), C->cols()
99 , tau.dim(), A.col_ptr(1), A.max_rows()
100 , tau.raw_ptr(), C->col_ptr(1), C->max_rows()
101 , work->raw_ptr(), work->dim(), &info );
104 info < 0, std::invalid_argument
105 ,
"ormrq(...): Error, Invalid argument "
106 << -info <<
" sent to LAPACK function xORMRQ(...)" );
111 void DenseLinAlgLAPack::sytrf(
112 DMatrixSliceTriEle* A, FortranTypes::f_int ipiv[]
116 FortranTypes::f_int info;
117 LAPACK_Cpp::sytrf( A->uplo(), A->rows(), A->gms().col_ptr(1)
118 , A->gms().max_rows(), ipiv, work->raw_ptr(), work->dim()
121 info < 0, std::invalid_argument
122 ,
"sytrf(...): Error, Invalid argument "
123 << -info <<
" sent to LAPACK function xSYTRF(...)" );
125 info > 0, FactorizationException
126 ,
"sytrf(...): Error, xSYTRF(...) indicates a singular matrix, "
127 <<
"D("<<info<<
","<<info<<
") is zero." );
131 void DenseLinAlgLAPack::sytrs(
132 const DMatrixSliceTriEle& A, FortranTypes::f_int ipiv[]
133 ,DMatrixSlice* B, DVectorSlice* work
137 (A.rows() != B->rows()), std::invalid_argument
138 ,
"sytrs(...) : Error, The number of rows in A and B must match."
140 FortranTypes::f_int info;
141 LAPACK_Cpp::sytrs( A.uplo(), A.rows(), B->cols(), A.gms().col_ptr(1)
142 , A.gms().max_rows(), ipiv, B->col_ptr(1), B->max_rows()
145 info < 0, std::invalid_argument
146 ,
"sytrs(...): Error, Invalid argument "
147 << -info <<
" sent to LAPACK function xSYTRS(...)"
151 void DenseLinAlgLAPack::getrf(
152 DMatrixSlice* A, FortranTypes::f_int ipiv[], FortranTypes::f_int* rank
155 FortranTypes::f_int info;
157 A->rows(), A->cols(), A->col_ptr(1), A->max_rows()
160 *rank = my_min( A->rows(), A->cols() );
162 info < 0, std::invalid_argument
163 ,
"getrf(...): Error, Invalid argument "
164 << -info <<
" sent to LAPACK function xGETRF(...)" );
169 void DenseLinAlgLAPack::getrs(
170 const DMatrixSlice& LU,
const FortranTypes::f_int ipiv[],
BLAS_Cpp::Transp transp
175 (LU.rows() != LU.cols() || LU.rows() != B->rows() ), std::invalid_argument
176 ,
"getrs(...) : Error, A must be square and the number of rows in A and B must match."
178 FortranTypes::f_int info;
180 transp, LU.rows(), B->cols(), LU.col_ptr(1), LU.max_rows(), ipiv
181 ,B->col_ptr(1), B->max_rows(), &info
184 info < 0, std::invalid_argument
185 ,
"getrs(...): Error, Invalid argument "
186 << -info <<
" sent to LAPACK function xGETRS(...)" );
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)