fml
0.1-0
Fused Matrix Library
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
15
#include "../internals/cpu_utils.hh"
16
17
#include "../cpumat.hh"
18
19
#include "internals/lapack.hh"
20
21
22
namespace
fml
23
{
24
namespace
linalg
25
{
45
template
<
typename
REAL>
46
void
chol
(
cpumat<REAL>
&x)
47
{
48
const
len_t n = x.
nrows
();
49
if
(n != x.
ncols
())
50
throw
std::runtime_error(
"'x' must be a square matrix"
);
51
52
int
info = 0;
53
fml::lapack::potrf(
'L'
, n, x.
data_ptr
(), n, &info);
54
55
if
(info < 0)
56
fml::linalgutils::check_info(info,
"potrf"
);
57
else
if
(info > 0)
58
throw
std::runtime_error(
"chol: leading minor of order "
+ std::to_string(info) +
" is not positive definite"
);
59
60
fml::cpu_utils::tri2zero(
'U'
,
false
, n, n, x.
data_ptr
(), n);
61
}
62
}
63
}
64
65
66
#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:
chol.hh:46
fml
src
fml
cpu
linalg
chol.hh
Generated by
1.8.17