MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DenseLinAlgLAPack.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include "DenseLinAlgLAPack.hpp"
45 #include "Teuchos_Assert.hpp"
46 
47 namespace {
48 template< class T >
49 inline
50 T my_min( const T& v1, const T& v2 ) { return v1 < v2 ? v1 : v2; }
51 } // end namespace
52 
54 {
56  LAPACK_Cpp::potrf( A->uplo(), A->rows(), A->gms().col_ptr(1), A->gms().max_rows(), &info );
57  if( info != 0 ) {
59  info < 0, std::invalid_argument
60  ,"potrf(...): Error, Invalid argument "
61  << -info << " sent to LAPACK function xPOTRF(...)" );
62  // info > 0
65  ,"potrf(...): Error, Minor of order "
66  << info << " is not positive definite, the factorization "
67  "could not be completed" );
68  }
69  // If you get here all went okay and A has been factorized and now
70  // hold the cholesky factor of input A.
71 }
72 
74 {
76  if( tau->dim() != my_min( A->rows(), A->cols() ) ) {
78  true, std::invalid_argument, "geqrf(...): Error, tau is not sized correctly!" );
79  }
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 );
82  if( info != 0 ) {
84  info < 0, std::invalid_argument
85  ,"geqrf(...): Error, Invalid argument "
86  << -info << " sent to LAPACK function xGEQRF(...)" );
87  }
88  // If you get here A and tau contain the QR factors of input A.
89 }
90 
93  ,const DMatrixSlice& A, const DVectorSlice& tau
94  ,DMatrixSlice* C, DVectorSlice* work
95  )
96 {
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 );
102  if( info != 0 ) {
104  info < 0, std::invalid_argument
105  ,"ormrq(...): Error, Invalid argument "
106  << -info << " sent to LAPACK function xORMRQ(...)" );
107  }
108  // If you get here C contains the desired matrix-matrix multiplication.
109 }
110 
113  ,DVectorSlice* work
114  )
115 {
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()
119  , &info );
121  info < 0, std::invalid_argument
122  ,"sytrf(...): Error, Invalid argument "
123  << -info << " sent to LAPACK function xSYTRF(...)" );
124  TEUCHOS_TEST_FOR_EXCEPTION(
125  info > 0, FactorizationException
126  ,"sytrf(...): Error, xSYTRF(...) indicates a singular matrix, "
127  << "D("<<info<<","<<info<<") is zero." );
128  // If we get here A and ipiv contain the factorization.
129 }
130 
133  ,DMatrixSlice* B, DVectorSlice* work
134  )
135 {
137  (A.rows() != B->rows()), std::invalid_argument
138  ,"sytrs(...) : Error, The number of rows in A and B must match."
139  );
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()
143  , &info );
145  info < 0, std::invalid_argument
146  ,"sytrs(...): Error, Invalid argument "
147  << -info << " sent to LAPACK function xSYTRS(...)"
148  );
149 }
150 
153  )
154 {
155  FortranTypes::f_int info;
157  A->rows(), A->cols(), A->col_ptr(1), A->max_rows()
158  ,ipiv, &info
159  );
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(...)" );
165  if(info > 0)
166  *rank = info - 1;
167 }
168 
170  const DMatrixSlice& LU, const FortranTypes::f_int ipiv[], BLAS_Cpp::Transp transp
171  ,DMatrixSlice* B
172  )
173 {
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."
177  );
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
182  );
184  info < 0, std::invalid_argument
185  ,"getrs(...): Error, Invalid argument "
186  << -info << " sent to LAPACK function xGETRS(...)" );
187  // If we get here B is the solution to the linear system.
188 }
void getrf(const f_int &m, const f_int &n, f_dbl_prec A[], const f_int &lda, f_int ipiv[], f_int *info)
void ormqr(BLAS_Cpp::Side side, BLAS_Cpp::Transp trans, const f_int &m, const f_int &n, const f_int &k, const f_dbl_prec *A, const f_int &lda, const f_dbl_prec *tau, f_dbl_prec *C, const f_int &ldc, f_dbl_prec *work, const f_int &lwork, f_int *info)
FortranTypes::f_int f_int
void sytrf(DMatrixSliceTriEle *A, FortranTypes::f_int ipiv[], DVectorSlice *work)
Calls xSYTRF to compute the P*A*P' = L'*D*L factorization of a symmetric possibly indefinite matrix...
void getrs(const DMatrixSlice &LU, const FortranTypes::f_int ipiv[], BLAS_Cpp::Transp transp, DMatrixSlice *B)
Calls xGETRS to solve linear systems with the factors of P'*A = L*U generated by xGETRF.
void geqrf(DMatrixSlice *A, DVectorSlice *tau, DVectorSlice *work)
Calls xGEQRF to compute the QR factorization of a matrix A.
size_type cols() const
Return the number of columns.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void geqrf(const f_int &m, const f_int &n, f_dbl_prec *A, const f_int &lda, f_dbl_prec *tau, f_dbl_prec *work, const f_int &lwork, f_int *info)
void getrf(DMatrixSlice *A, FortranTypes::f_int ipiv[], FortranTypes::f_int *rank)
Calls xGETRF to compute the P'*A = L*U factorization of a general rectuangular matrix.
Transposed.
void getrs(BLAS_Cpp::Transp trans, const f_int &n, const f_int &nrhs, const f_dbl_prec A[], const f_int &lda, const f_int ipiv[], f_dbl_prec B[], const f_int &ldb, f_int *info)
size_type max_rows() const
Return the number of rows in the full matrix. Equivalent to BLAS LDA argument.
void potrf(DMatrixSliceTriEle *A)
Calls xPOTRF to compute the cholesky factorization of a symmetric positive definte matrix...
DenseLinAlgPack::VectorSliceTmpl< value_type > DVectorSlice
size_type rows() const
Return the number of rows.
void potrf(BLAS_Cpp::Uplo uplo, const f_int &n, f_dbl_prec *A, const f_int &lda, f_int *info)
void sytrs(BLAS_Cpp::Uplo uplo, const f_int &n, const f_int &nrhs, const f_dbl_prec A[], const f_int &lda, const f_int ipiv[], f_dbl_prec B[], const f_int &ldb, f_int *info)
void ormrq(BLAS_Cpp::Side side, BLAS_Cpp::Transp trans, const DMatrixSlice &A, const DVectorSlice &tau, DMatrixSlice *C, DVectorSlice *work)
Calls xORMRQ to compute a matrix matrix op(C)=op(Q)*op(C) where Q is stored in A and tau computed fro...
Transp
TRANS.
void sytrs(const DMatrixSliceTriEle &A, FortranTypes::f_int ipiv[], DMatrixSlice *B, DVectorSlice *work)
Calls xSYTRS(...) to compute the solution of the factorized system A * X = B where A was factorized b...
void sytrf(BLAS_Cpp::Uplo uplo, const f_int &n, f_dbl_prec A[], const f_int &lda, f_int ipiv[], f_dbl_prec work[], const f_int &lwork, f_int *info)