sisi4s
Loading...
Searching...
No Matches
LapackInverse.hpp
Go to the documentation of this file.
1#ifndef LAPACK_INVERSE_DEFINED
2#define LAPACK_INVERSE_DEFINED
3
4#include <math/Complex.hpp>
6#include <util/Exception.hpp>
7#include <extern/Lapack.hpp>
8#include <util/Log.hpp>
9
10#include <vector>
11
12namespace sisi4s {
13// base template
14template <typename F = real>
16
17// specialization for complex
18template <>
20public:
22 : invA(A_) {
23 if (A_.getRows() != A_.getColumns()) {
24 throw EXCEPTION("Inverse requries a square matrix");
25 }
26 int rows(A_.getRows());
27 std::vector<Complex64> work(rows * rows);
28 int workSize(work.size());
29 std::vector<int> rowPermutation(rows);
30 int info;
31
32 zgetrf_(&rows,
33 &rows,
34 invA.getValues(),
35 &rows,
36 rowPermutation.data(),
37 &info);
38 zgetri_(&rows,
39 invA.getValues(),
40 &rows,
41 rowPermutation.data(),
42 work.data(),
43 &workSize,
44 &info);
45 if (info < 0) {
46 std::stringstream stream;
47 stream << "Argument " << -info << " of ZGETRI is illegal";
48 throw EXCEPTION(stream.str());
49 }
50 if (info > 0) { throw EXCEPTION("Singular matrix cannot be inverted"); }
51 }
52
54
55 const LapackMatrix<Complex64> &get() const { return invA; }
56
57protected:
59};
60} // namespace sisi4s
61
62#endif
#define EXCEPTION(message)
Definition Exception.hpp:8
void zgetri_(const int *n, sisi4s::Complex64 *a, const int *lda, const int *rowPermutation, sisi4s::Complex64 *work, const int *workSize, int *info)
void zgetrf_(const int *m, const int *n, sisi4s::Complex64 *a, const int *lda, const int *rowPermutation, int *info)
~LapackInverse()
Definition LapackInverse.hpp:53
LapackMatrix< Complex64 > invA
Definition LapackInverse.hpp:58
const LapackMatrix< Complex64 > & get() const
Definition LapackInverse.hpp:55
LapackInverse(const LapackMatrix< Complex64 > &A_)
Definition LapackInverse.hpp:21
Definition LapackInverse.hpp:15
Definition LapackMatrix.hpp:11
int getColumns() const
Definition LapackMatrix.hpp:64
int getRows() const
Definition LapackMatrix.hpp:63
Definition Algorithm.hpp:10
Complex< Float64 > Complex64
Definition Complex.hpp:14