fml
0.1-0
Fused Matrix Library
linalg_chol.hh
1
// This file is part of fml which is released under the Boost Software
2
// License, Version 1.0. See accompanying file LICENSE or copy at
3
// https://www.boost.org/LICENSE_1_0.txt
4
5
#ifndef FML_CPU_LINALG_LINALG_CHOL_H
6
#define FML_CPU_LINALG_LINALG_CHOL_H
7
#pragma once
8
9
10
#include <cmath>
11
#include <stdexcept>
12
13
#include "../../_internals/linalgutils.hh"
14
#include "../../_internals/omp.hh"
15
16
#include "../internals/cpu_utils.hh"
17
18
#include "../cpumat.hh"
19
20
#include "lapack.hh"
21
22
23
namespace
fml
24
{
25
namespace
linalg
26
{
46
template
<
typename
REAL>
47
void
chol
(
cpumat<REAL>
&x)
48
{
49
const
len_t n = x.
nrows
();
50
if
(n != x.
ncols
())
51
throw
std::runtime_error(
"'x' must be a square matrix"
);
52
53
int
info = 0;
54
fml::lapack::potrf(
'L'
, n, x.
data_ptr
(), n, &info);
55
56
if
(info < 0)
57
fml::linalgutils::check_info(info,
"potrf"
);
58
else
if
(info > 0)
59
throw
std::runtime_error(
"chol: leading minor of order "
+ std::to_string(info) +
" is not positive definite"
);
60
61
fml::cpu_utils::tri2zero(
'U'
,
false
, n, n, x.
data_ptr
(), n);
62
}
63
}
64
}
65
66
67
#endif
fml::cpumat
Matrix class for data held on a single CPU.
Definition:
cpumat.hh:36
fml::unimat::nrows
len_t nrows() const
Number of rows.
Definition:
unimat.hh:36
fml::unimat::ncols
len_t ncols() const
Number of columns.
Definition:
unimat.hh:38
fml::unimat::data_ptr
REAL * data_ptr()
Pointer to the internal array.
Definition:
unimat.hh:40
fml
Core namespace.
Definition:
dimops.hh:10
fml::linalg::chol
void chol(cpumat< REAL > &x)
Compute the Choleski factorization.
Definition:
linalg_chol.hh:47
fml
src
fml
cpu
linalg
linalg_chol.hh
Generated by
1.8.17