4#ifndef ROOT_Math_CholeskyDecomp
5#define ROOT_Math_CholeskyDecomp
46namespace CholeskyDecompHelpers {
48template <
class F,
class M>
50template <
class F,
unsigned N,
class M>
52template <
class F,
class M>
54template <
class F,
unsigned N,
class M>
56template <
class F,
class V>
58template <
class F,
unsigned N,
class V>
94template <
class F,
unsigned N>
131 template <
typename G>
188 template <
typename G>
211 for (
unsigned i = 0; i <
N; ++i) {
213 for (
unsigned j = i + 1;
j <
N; ++
j)
216 for (
unsigned j = 0;
j <= i; ++
j)
217 m(i,
j) =
fL[i * (i + 1) / 2 +
j];
220 m(i, i) =
F(1) /
m(i, i);
233 template <
typename G>
239 for (
unsigned i = 0; i < (
N * (
N + 1)) / 2; ++i)
243 for (
unsigned i = 0; i <
N; ++i)
244 m[(i * (i + 1)) / 2 + i] =
F(1) /
fL[(i * (i + 1)) / 2 + i];
259 for (
unsigned i = 0; i <
N; ++i) {
261 for (
unsigned j = i + 1;
j <
N; ++
j)
264 for (
unsigned j = 0;
j <= i; ++
j)
265 m(
j, i) =
fL[i * (i + 1) / 2 +
j];
268 for (
unsigned i = 1; i <
N; ++i) {
269 for (
unsigned j = 0;
j < i; ++
j) {
270 typename M::value_type tmp =
F(0);
271 for (
unsigned k = i; k-- >
j;)
272 tmp -=
m(k, i) *
m(
j, k);
273 m(
j, i) = tmp *
m(i, i);
287 template <
typename G>
293 for (
unsigned i = 0; i < (
N * (
N + 1)) / 2; ++i)
297 for (
unsigned i = 1; i <
N;
base1 += ++i) {
298 for (
unsigned j = 0;
j < i; ++
j) {
300 const G *
base2 = &
m[(i * (i - 1)) / 2];
301 for (
unsigned k = i; k-- >
j;
base2 -= k)
372 if (
fL.size() <
fN * (
fN + 1) / 2)
373 fL.resize(
fN * (
fN + 1) / 2);
393 template <
typename G>
398 if (
fL.size() <
fN * (
fN + 1) / 2)
399 fL.resize(
fN * (
fN + 1) / 2);
440 return std::move(
fL);
494 template <
typename G>
518 const F *L =
fL.data();
519 for (
unsigned i = 0; i <
fN; ++i) {
521 for (
unsigned j = i + 1;
j <
fN; ++
j)
524 for (
unsigned j = 0;
j <= i; ++
j)
525 m(i,
j) = L[i * (i + 1) / 2 +
j];
528 m(i, i) =
F(1) /
m(i, i);
541 template <
typename G>
546 const F *L =
fL.data();
548 for (
unsigned i = 0; i < (
fN * (
fN + 1)) / 2; ++i)
552 for (
unsigned i = 0; i <
fN; ++i)
553 m[(i * (i + 1)) / 2 + i] =
F(1) / L[(i * (i + 1)) / 2 + i];
568 const F *L =
fL.data();
569 for (
unsigned i = 0; i <
fN; ++i) {
571 for (
unsigned j = i + 1;
j <
fN; ++
j)
574 for (
unsigned j = 0;
j <= i; ++
j)
575 m(
j, i) = L[i * (i + 1) / 2 +
j];
578 for (
unsigned i = 1; i <
fN; ++i) {
579 for (
unsigned j = 0;
j < i; ++
j) {
580 typename M::value_type tmp =
F(0);
581 for (
unsigned k = i; k-- >
j;)
582 tmp -=
m(k, i) *
m(
j, k);
583 m(
j, i) = tmp *
m(i, i);
597 template <
typename G>
602 const F *L =
fL.data();
604 for (
unsigned i = 0; i < (
fN * (
fN + 1)) / 2; ++i)
608 for (
unsigned i = 1; i <
fN;
base1 += ++i) {
609 for (
unsigned j = 0;
j < i; ++
j) {
611 const G *
base2 = &
m[(i * (i - 1)) / 2];
612 for (
unsigned k = i; k-- >
j;
base2 -= k)
621namespace CholeskyDecompHelpers {
636template <
class F,
class M>
655 for (
unsigned i = 0; i <
N;
base1 += ++i) {
659 for (
unsigned j = 0;
j < i;
base2 += ++
j) {
661 for (
unsigned k =
j; k--;)
680template <
class F,
unsigned N,
class M>
688template <
class F,
class M>
695 for (
unsigned i = 1; i <
N;
base1 += ++i) {
696 for (
unsigned j = 0;
j < i; ++
j) {
698 const F *
base2 = &
wksp[(i * (i - 1)) / 2];
699 for (
unsigned k = i; k-- >
j;
base2 -= k)
706 for (
unsigned i =
N; i--;) {
707 for (
unsigned j = i + 1;
j--;) {
710 for (
unsigned k =
N; k-- > i;
base1 -= k)
719template <
class F,
unsigned N,
class M>
732template <
class F,
class V>
738 for (
unsigned k = 0; k <
N; ++k) {
739 const unsigned base = (k * (k + 1)) / 2;
741 for (
unsigned i = k; i--;)
747 for (
unsigned k =
N; k--;) {
749 for (
unsigned i =
N; --i > k;)
750 sum +=
rhs[i] *
l[(i * (i + 1)) / 2 + k];
752 rhs[k] = (
rhs[k] -
sum) *
l[(k * (k + 1)) / 2 + k];
758template <
class F,
unsigned N,
class V>
765template <
class F,
class M>
770 if (
src(0, 0) <=
F(0.0))
772 dst[0] = std::sqrt(
F(1.0) /
src(0, 0));
775 if (
dst[2] <=
F(0.0))
778 dst[2] = std::sqrt(
F(1.0) /
dst[2]);
782 if (
dst[5] <=
F(0.0))
785 dst[5] = std::sqrt(
F(1.0) /
dst[5]);
790 if (
dst[9] <=
F(0.0))
793 dst[9] = std::sqrt(
F(1.0) /
dst[9]);
799 if (
dst[14] <=
F(0.0))
802 dst[14] = std::sqrt(
F(1.0) /
dst[14]);
810 if (
dst[20] <=
F(0.0))
813 dst[20] = std::sqrt(
F(1.0) /
dst[20]);
818template <
class F,
class M>
823 if (
src(0, 0) <=
F(0.0))
825 dst[0] = std::sqrt(
F(1.0) /
src(0, 0));
828 if (
dst[2] <=
F(0.0))
831 dst[2] = std::sqrt(
F(1.0) /
dst[2]);
835 if (
dst[5] <=
F(0.0))
838 dst[5] = std::sqrt(
F(1.0) /
dst[5]);
843 if (
dst[9] <=
F(0.0))
846 dst[9] = std::sqrt(
F(1.0) /
dst[9]);
852 if (
dst[14] <=
F(0.0))
855 dst[14] = std::sqrt(
F(1.0) /
dst[14]);
860template <
class F,
class M>
865 if (
src(0, 0) <=
F(0.0))
867 dst[0] = std::sqrt(
F(1.0) /
src(0, 0));
870 if (
dst[2] <=
F(0.0))
873 dst[2] = std::sqrt(
F(1.0) /
dst[2]);
877 if (
dst[5] <=
F(0.0))
880 dst[5] = std::sqrt(
F(1.0) /
dst[5]);
885 if (
dst[9] <=
F(0.0))
888 dst[9] = std::sqrt(
F(1.0) /
dst[9]);
893template <
class F,
class M>
898 if (
src(0, 0) <=
F(0.0))
900 dst[0] = std::sqrt(
F(1.0) /
src(0, 0));
903 if (
dst[2] <=
F(0.0))
906 dst[2] = std::sqrt(
F(1.0) /
dst[2]);
910 if (
dst[5] <=
F(0.0))
913 dst[5] = std::sqrt(
F(1.0) /
dst[5]);
918template <
class F,
class M>
923 if (
src(0, 0) <=
F(0.0))
925 dst[0] = std::sqrt(
F(1.0) /
src(0, 0));
928 if (
dst[2] <=
F(0.0))
931 dst[2] = std::sqrt(
F(1.0) /
dst[2]);
936template <
class F,
class M>
941 if (
src(0, 0) <=
F(0.0))
943 dst[0] = std::sqrt(
F(1.0) /
src(0, 0));
948template <
class F,
class M>
956template <
class F,
class M>
1025template <
class F,
class M>
1067template <
class F,
class M>
1094template <
class F,
class M>
1112template <
class F,
class M>
1125template <
class F,
class M>
1131template <
class F,
class M>
1139template <
class F,
class V>
1145 const F
y0 =
rhs[0] *
l[0];
1146 const F
y1 = (
rhs[1] -
l[1] *
y0) *
l[2];
1147 const F
y2 = (
rhs[2] - (
l[3] *
y0 +
l[4] *
y1)) *
l[5];
1161template <
class F,
class V>
1167 const F
y0 =
rhs[0] *
l[0];
1168 const F
y1 = (
rhs[1] -
l[1] *
y0) *
l[2];
1169 const F
y2 = (
rhs[2] - (
l[3] *
y0 +
l[4] *
y1)) *
l[5];
1181template <
class F,
class V>
1187 const F
y0 =
rhs[0] *
l[0];
1188 const F
y1 = (
rhs[1] -
l[1] *
y0) *
l[2];
1189 const F
y2 = (
rhs[2] - (
l[3] *
y0 +
l[4] *
y1)) *
l[5];
1199template <
class F,
class V>
1205 const F
y0 =
rhs[0] *
l[0];
1206 const F
y1 = (
rhs[1] -
l[1] *
y0) *
l[2];
1207 const F
y2 = (
rhs[2] - (
l[3] *
y0 +
l[4] *
y1)) *
l[5];
1215template <
class F,
class V>
1221 const F
y0 =
rhs[0] *
l[0];
1222 const F
y1 = (
rhs[1] -
l[1] *
y0) *
l[2];
1229template <
class F,
class V>
1235 rhs[0] *=
l[0] *
l[0];
1239template <
class F,
class V>
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char y2
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
Option_t Option_t TPoint TPoint const char y1
class to compute the Cholesky decomposition of a matrix
bool fOk
flag indicating a successful decomposition
CholeskyDecompGenDim(unsigned N, G *m, std::vector< F > wksp={})
perform a Cholesky decomposition
bool getL(G *m) const
obtain the decomposed matrix L
bool getL(M &m) const
obtain the decomposed matrix L
std::vector< F > fL
lower triangular matrix L
bool Invert(G *m) const
place the inverse into m
std::vector< F > releaseWorkspace()
release the workspace of the decomposition for reuse
bool Invert(M &m) const
place the inverse into m
bool Solve(V &rhs) const
solves a linear system for the given right hand side
bool getLi(M &m) const
obtain the inverse of the decomposed matrix L
CholeskyDecompGenDim(unsigned N, const M &m, std::vector< F > wksp={})
perform a Cholesky decomposition
unsigned fN
dimensionality dimensionality of the problem
bool getLi(G *m) const
obtain the inverse of the decomposed matrix L
bool ok() const
returns true if decomposition was successful
adapter for packed arrays (to SMatrix indexing conventions)
G * fArr
pointer to first array element
G & operator()(unsigned i, unsigned j)
write access to elements (make sure that j <= i)
const G operator()(unsigned i, unsigned j) const
read access to elements (make sure that j <= i)
PackedArrayAdapter(G *arr)
constructor
class to compute the Cholesky decomposition of a matrix
bool fOk
flag indicating a successful decomposition
bool ok() const
returns true if decomposition was successful
bool getL(G *m) const
obtain the decomposed matrix L
bool Invert(G *m) const
place the inverse into m
CholeskyDecomp(const M &m)
perform a Cholesky decomposition
bool getLi(G *m) const
obtain the inverse of the decomposed matrix L
bool getL(M &m) const
obtain the decomposed matrix L
bool Solve(V &rhs) const
solves a linear system for the given right hand side
F fL[N *(N+1)/2]
lower triangular matrix L
CholeskyDecomp(G *m)
perform a Cholesky decomposition
bool getLi(M &m) const
obtain the inverse of the decomposed matrix L
bool Invert(M &m) const
place the inverse into m
Namespace for new Math classes and functions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
struct to do a Cholesky decomposition (general dimensionality)
bool operator()(F *dst, const M &src, unsigned N) const
method to do the decomposition
bool operator()(F *dst, const M &src) const
bool operator()(F *dst, const M &src) const
method to do the decomposition
bool operator()(F *dst, const M &src) const
method to do the decomposition
bool operator()(F *dst, const M &src) const
method to do the decomposition
bool operator()(F *dst, const M &src) const
method to do the decomposition
bool operator()(F *dst, const M &src) const
method to do the decomposition
bool operator()(F *dst, const M &src) const
method to do the decomposition
struct to do a Cholesky decomposition
bool operator()(F *dst, const M &src) const
method to do the decomposition
struct to obtain the inverse from a Cholesky decomposition (general dimensionality)
void operator()(M &dst, unsigned N, F *wksp) const
method to do the inversion
void operator()(M &dst, const F *src) const
void operator()(M &dst, const F *src) const
method to do the inversion
void operator()(M &dst, const F *src) const
method to do the inversion
void operator()(M &dst, const F *src) const
method to do the inversion
void operator()(M &dst, const F *src) const
method to do the inversion
void operator()(M &dst, const F *src) const
method to do the inversion
void operator()(M &dst, const F *src) const
method to do the inversion
struct to obtain the inverse from a Cholesky decomposition
void operator()(M &dst, const F *src) const
method to do the inversion
struct to solve a linear system using its Cholesky decomposition (generalised dimensionality)
void operator()(V &rhs, const F *l, unsigned N) const
method to solve the linear system
void operator()(V &rhs, const F *l) const
void operator()(V &rhs, const F *l) const
method to solve the linear system
void operator()(V &rhs, const F *l) const
method to solve the linear system
void operator()(V &rhs, const F *l) const
method to solve the linear system
void operator()(V &rhs, const F *l) const
method to solve the linear system
void operator()(V &rhs, const F *l) const
method to solve the linear system
void operator()(V &rhs, const F *l) const
method to solve the linear system
struct to solve a linear system using its Cholesky decomposition
void operator()(V &rhs, const F *l) const
method to solve the linear system
static uint64_t sum(uint64_t i)