numerics
0.1.0
Loading...
Searching...
No Matches
lu.cpp
Go to the documentation of this file.
1
/// @file linalg/factorization/backends/lapack/lu.cpp
2
/// @brief LAPACK LU factorization via LAPACKE_dgetrf.
3
///
4
/// Falls back to seq::lu() with a warning when NUMERICS_HAS_LAPACK is not set;
5
/// this keeps the build working but reminds the caller that LAPACK is absent.
6
#include "../seq/impl.hpp"
7
#include "
impl.hpp
"
8
#include <stdexcept>
9
#include <string>
10
#include <vector>
11
12
#if defined(NUMERICS_HAS_LAPACK)
13
#include <lapacke.h>
14
#endif
15
16
namespace
num::backends::lapack
{
17
18
LUResult
lu
(
const
Matrix
& A) {
19
#if defined(NUMERICS_HAS_LAPACK)
20
const
idx
n = A.
rows
();
21
LUResult
f;
22
f.
LU
= A;
23
f.
piv
.resize(n);
24
f.
singular
=
false
;
25
26
std::vector<lapack_int> ipiv(n);
27
int
info = LAPACKE_dgetrf(LAPACK_ROW_MAJOR,
28
static_cast<
lapack_int
>
(n),
29
static_cast<
lapack_int
>
(n),
30
f.
LU
.
data
(),
31
static_cast<
lapack_int
>
(n),
32
ipiv.data());
33
if
(info < 0)
34
throw
std::runtime_error(
"lu (lapack): dgetrf argument error, info="
35
+ std::to_string(info));
36
if
(info > 0)
37
f.
singular
=
true
;
38
39
// Convert 1-based LAPACK IPIV to 0-based sequential swap targets
40
for
(
idx
k = 0; k < n; ++k)
41
f.
piv
[k] =
static_cast<
idx
>
(ipiv[k] - 1);
42
43
return
f;
44
#else
45
return
seq::lu
(A);
46
#endif
47
}
48
49
}
// namespace num::backends::lapack
num::BasicMatrix< real >
num::BasicMatrix::rows
constexpr idx rows() const noexcept
Definition
matrix.hpp:87
num::BasicMatrix::data
T * data()
Definition
matrix.hpp:91
num::backends::lapack
Definition
impl.hpp:7
num::backends::lapack::lu
LUResult lu(const Matrix &A)
Definition
lu.cpp:18
num::backends::seq::lu
LUResult lu(const Matrix &A)
Definition
lu.cpp:9
num::idx
std::size_t idx
Definition
types.hpp:11
impl.hpp
std::experimental::simd butterfly for FFT.
num::LUResult
Packed factorization .
Definition
lu.hpp:12
num::LUResult::LU
Matrix LU
Definition
lu.hpp:13
num::LUResult::piv
std::vector< idx > piv
Definition
lu.hpp:14
num::LUResult::singular
bool singular
Definition
lu.hpp:15
src
linalg
factorization
backends
lapack
lu.cpp
Generated by
1.9.8