MADNESS 0.10.1
linalg_wrappers.h
Go to the documentation of this file.
3
4/*!
5 \file linalg_wrappers.h
6 \brief Template wrappers for LAPACK routines
7 \ingroup linalg
8@{
9*/
10
11namespace madness {
12namespace detail {
13
14 template <typename T>
15 struct real_type {
16 using type = T;
17 };
18
19 template <typename T>
20 struct real_type< std::complex<T> > {
21 using type = T;
22 };
23
24}
25
26
27 /// Compute the SVD via LAPACK
28 template <typename T>
29 void svd( char jobu, char jobvt, integer m, integer n, T* A, integer lda,
30 typename detail::real_type<T>::type* S, T* U, integer ldu,
31 T* VT, integer ldvt );
32
33 /// Solve the EVP via LAPACK
34 template <typename T>
35 void hereig( char jobz, char uplo, integer n, T* A, integer lda,
36 typename detail::real_type<T>::type* W );
37
38 /// Solve the Generalized EVP via LAPACK
39 template <typename T>
40 void hereig_gen( integer itype, char jobz, char uplo, integer n, T* A,
41 integer lda, T* B, integer ldb,
42 typename detail::real_type<T>::type* W );
43
44 /// Compute the Cholesky Factorization via LAPACK
45 template <typename T>
46 void cholesky( char uplo, integer n, T* A, integer lda );
47
48
49
50
51
52 /// Linear algebra Exception
53 class LinAlgException : public std::exception {
54 const char* msg;
55 const char* assertion;
56 int value;
57 int line;
58 const char *function;
59 const char *filename;
60
61public:
62 LinAlgException(const char* s, const char *a, int err,
63 int lin, const char *func, const char *file)
64 : msg(s)
65 , assertion(a)
66 , value(err)
67 , line(lin)
68 , function(func)
69 , filename(file) { }
70
71 virtual const char* what() const throw() {
72 return msg;
73 }
74
75 virtual ~LinAlgException() throw() {}
76
77 friend std::ostream& operator <<(std::ostream& out, const LinAlgException& e) {
78 out << "LinAlgException: msg='";
79 if (e.msg) out << e.msg;
80 out << "'\n";
81 if (e.assertion) out << " failed assertion='" <<
82 e.assertion << "'\n";
83 out << " value=" << e.value << "\n";
84 if (e.line) out << " line=" << e.line << "\n";
85 if (e.function) out << " function='" <<
86 e.function << "'\n";
87 if (e.filename) out << " filename='" <<
88 e.filename << "'\n";
89
90 return out;
91 }
92
93 };
94
95
96
97#define LINALG_STRINGIZE(X) #X
98#define LINALG_EXCEPTION_AT(F, L) LINALG_STRINGIZE(F) "(" LINALG_STRINGIZE(L) ")"
99
100#define LINALG_EXCEPTION(msg,value) \
101 throw ::madness::LinAlgException("LINALG EXCEPTION: " LINALG_EXCEPTION_AT( __FILE__, __LINE__ ) ": " msg , \
102 0,value,__LINE__,__FUNCTION__,__FILE__)
103
104#define LINALG_ASSERT(condition,msg,value) \
105do {if (!(condition)) \
106 throw ::madness::LinAlgException("LINALG ASSERTION FAILED: " LINALG_EXCEPTION_AT( __FILE__, __LINE__ ) ": " msg , \
107 #condition,value,__LINE__,__FUNCTION__,__FILE__); \
108 } while (0)
109}
110
111/* @} */
C++ interface to LAPACK, either directly via Fortran API (see clapack_fortran.h) or via LAPACKE (see ...
Definition test_ar.cc:118
Definition test_ar.cc:141
Linear algebra Exception.
Definition linalg_wrappers.h:53
virtual ~LinAlgException()
Definition linalg_wrappers.h:75
friend std::ostream & operator<<(std::ostream &out, const LinAlgException &e)
Definition linalg_wrappers.h:77
const char * filename
Definition linalg_wrappers.h:59
const char * msg
Definition linalg_wrappers.h:54
LinAlgException(const char *s, const char *a, int err, int lin, const char *func, const char *file)
Definition linalg_wrappers.h:62
const char * assertion
Definition linalg_wrappers.h:55
virtual const char * what() const
Definition linalg_wrappers.h:71
const char * function
Definition linalg_wrappers.h:58
int line
Definition linalg_wrappers.h:57
int value
Definition linalg_wrappers.h:56
int integer
Definition crayio.c:25
Correspondence between C++ and Fortran types.
auto T(World &world, response_space &f) -> response_space
Definition global_functions.cc:34
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
void cholesky(Tensor< T > &A)
Compute the Cholesky factorization.
Definition lapack.cc:1174
void hereig(char jobz, char uplo, integer n, real4 *A, integer lda, real4 *W)
Definition linalg_wrappers.cc:171
std::shared_ptr< FunctionFunctorInterface< double, 3 > > func(new opT(g))
void svd(const Tensor< T > &a, Tensor< T > &U, Tensor< typename Tensor< T >::scalar_type > &s, Tensor< T > &VT)
Compute the singluar value decomposition of an n-by-m matrix using *gesvd.
Definition lapack.cc:739
void hereig_gen(integer itype, char jobz, char uplo, integer n, real4 *A, integer lda, real4 *B, integer ldb, real4 *W)
Definition linalg_wrappers.cc:312
Definition mraimpl.h:50
static const double a
Definition nonlinschro.cc:118
static const double m
Definition relops.cc:9
T type
Definition linalg_wrappers.h:21
Definition linalg_wrappers.h:15
T type
Definition linalg_wrappers.h:16
void e()
Definition test_sig.cc:75