chombo-discharge
Loading...
Searching...
No Matches
CD_LaPackUtils.H
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021-2026 SINTEF Energy Research
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
13
14#ifndef CD_LAPACKUTILS_H
15#define CD_LAPACKUTILS_H
16
17// Std includes
18#include <vector>
19
20// Our includes
21#include <CD_NamespaceHeader.H>
22
24extern "C" void
25dgelss_(int* a_M,
26 int* a_N,
27 int* a_nRHS,
28 double* a_A,
29 int* a_LDA,
30 double* a_B,
31 int* a_LDB,
32 double* a_S,
33 double* a_rcond,
34 int* a_RANK,
35 double* a_WORK,
36 int* a_LWORK,
37 int* a_INFO);
38
39extern "C" void
40dgesdd_(char* a_JOBZ,
41 int* a_M,
42 int* a_N,
43 double* a_A,
44 int* a_LDA,
45 double* a_S,
46 double* a_U,
47 int* a_LDU,
48 double* a_VT,
49 int* a_LDVT,
50 double* a_WORK,
51 int* a_LWORK,
52 int* a_IWORK,
53 int* a_INFO);
54
55extern "C" void
56sgesdd_(char* a_JOBZ,
57 int* a_M,
58 int* a_N,
59 float* a_A,
60 int* a_LDA,
61 float* a_S,
62 float* a_U,
63 int* a_LDU,
64 float* a_VT,
65 int* a_LDVT,
66 float* a_WORK,
67 int* a_LWORK,
68 int* a_IWORK,
69 int* a_INFO);
70
71extern "C" void
72dgemm_(char* a_TRANSA,
73 char* a_TRANSB,
74 int* a_M,
75 int* a_N,
76 int* a_K,
77 double* a_ALPHA,
78 double* a_A,
79 int* a_LDA,
80 double* a_B,
81 int* a_LDB,
82 double* a_BETA,
83 double* a_C,
84 int* a_LDC);
85
86extern "C" void
87sgemm_(char* a_TRANSA,
88 char* a_TRANSB,
89 int* a_M,
90 int* a_N,
91 int* a_K,
92 float* a_ALPHA,
93 float* a_A,
94 int* a_LDA,
95 float* a_B,
96 int* a_LDB,
97 float* a_BETA,
98 float* a_C,
99 int* a_LDC);
100
101extern "C" void
102dgesv_(int* N, int* NRHS, double* A, int* LDA, int* IPIV, double* B, int* LDB, int* INFO);
104
108namespace LaPackUtils {
109
118int
119linearIndex(const int irow, const int jcol, const int M, const int N);
120
136bool
137computeSVD(std::vector<double>& a_linU,
138 std::vector<double>& a_linSigma,
139 std::vector<double>& a_linVtran,
140 const std::vector<double>& a_linA,
141 const int& a_M,
142 const int& a_N);
143
159bool
160computeSVD(std::vector<float>& a_linU,
161 std::vector<float>& a_linSigma,
162 std::vector<float>& a_linVtran,
163 const std::vector<float>& a_linA,
164 const int& a_M,
165 const int& a_N);
166
178bool
179computePseudoInverse(std::vector<double>& a_linAplus,
180 int& a_rank,
181 const std::vector<double>& a_linA,
182 const int& a_M,
183 const int& a_N);
184
196bool
197computePseudoInverse(std::vector<float>& a_linAplus,
198 int& a_rank,
199 const std::vector<float>& a_linA,
200 const int& a_M,
201 const int& a_N);
202
212void
213linearizeMatrix(std::vector<double>& a_linA,
214 int& a_M,
215 int& a_N,
216 const std::vector<std::vector<double>>& a_A,
217 const char& a_format);
218
226void
227linearizeColumnMajorMatrix(std::vector<double>& a_linA,
228 int& a_M,
229 int& a_N,
230 const std::vector<std::vector<double>>& a_A);
231
239void
240linearizeRowMajorMatrix(std::vector<double>& a_linA, int& a_M, int& a_N, const std::vector<std::vector<double>>& a_A);
241
251void
252deLinearizeMatrix(std::vector<std::vector<double>>& a_A,
253 const int& a_M,
254 const int& a_N,
255 const std::vector<double>& a_linA,
256 const char& a_format);
257
265void
266deLinearizeColumnMajorMatrix(std::vector<std::vector<double>>& a_A,
267 const int& a_M,
268 const int& a_N,
269 const std::vector<double>& a_linA);
270
278void
279deLinearizeRowMajorMatrix(std::vector<std::vector<double>>& a_A,
280 const int& a_M,
281 const int& a_N,
282 const std::vector<double>& a_linA);
283} // namespace LaPackUtils
284
285#include <CD_NamespaceFooter.H>
286
287#endif
Namespace containing various useful linear algebra routines using LaPACK.
Definition CD_LaPackUtils.H:108
void deLinearizeMatrix(std::vector< std::vector< double > > &a_A, const int &a_M, const int &a_N, const std::vector< double > &a_linA, const char &a_format)
Delinearize a linearized matrix from column major Fortran to row or major column matrix format.
Definition CD_LaPackUtils.cpp:470
void deLinearizeRowMajorMatrix(std::vector< std::vector< double > > &a_A, const int &a_M, const int &a_N, const std::vector< double > &a_linA)
Delinearize a linearized matrix from column major Fortran to row major form.
Definition CD_LaPackUtils.cpp:449
void linearizeMatrix(std::vector< double > &a_linA, int &a_M, int &a_N, const std::vector< std::vector< double > > &a_A, const char &a_format)
Linearize a matrix to column major Fortran form by assuming row or major column format of the input m...
Definition CD_LaPackUtils.cpp:410
void linearizeRowMajorMatrix(std::vector< double > &a_linA, int &a_M, int &a_N, const std::vector< std::vector< double > > &a_A)
Linearize a matrix to column major Fortran form by row major format of the input matrix.
Definition CD_LaPackUtils.cpp:390
bool computeSVD(std::vector< double > &a_linU, std::vector< double > &a_linSigma, std::vector< double > &a_linVtran, const std::vector< double > &a_linA, const int &a_M, const int &a_N)
Compute the singular value decomposition of a matrix.
Definition CD_LaPackUtils.cpp:30
void linearizeColumnMajorMatrix(std::vector< double > &a_linA, int &a_M, int &a_N, const std::vector< std::vector< double > > &a_A)
Linearize a matrix to column major Fortran form by column major format of the input matrix.
Definition CD_LaPackUtils.cpp:370
int linearIndex(const int irow, const int jcol, const int M, const int N)
Get the index in the linearized matrix of size MxN.
Definition CD_LaPackUtils.cpp:24
bool computePseudoInverse(std::vector< double > &a_linAplus, int &a_rank, const std::vector< double > &a_linA, const int &a_M, const int &a_N)
Compute the pseudoinverse of matrix through singular value decomposition.
Definition CD_LaPackUtils.cpp:164
void deLinearizeColumnMajorMatrix(std::vector< std::vector< double > > &a_A, const int &a_M, const int &a_N, const std::vector< double > &a_linA)
Delinearize a linearized matrix from column major Fortran to column major form.
Definition CD_LaPackUtils.cpp:428