4#ifndef ROOT_Math_CholeskyDecomp
5#define ROOT_Math_CholeskyDecomp
35namespace CholeskyDecompHelpers {
38 template<
class F,
unsigned N,
class M>
struct _decomposer;
40 template<
class F,
unsigned N,
class M>
struct _inverter;
42 template<
class F,
unsigned N,
class V>
struct _solver;
183 template<
class M>
bool getL(M&
m)
const
185 if (!
fOk)
return false;
186 for (
unsigned i = 0; i <
N; ++i) {
188 for (
unsigned j = i + 1;
j <
N; ++
j)
191 for (
unsigned j = 0;
j <= i; ++
j)
192 m(i,
j) =
fL[i * (i + 1) / 2 +
j];
195 m(i, i) =
F(1) /
m(i, i);
208 template<
typename G>
bool getL(
G*
m)
const
210 if (!
fOk)
return false;
212 for (
unsigned i = 0; i < (
N * (
N + 1)) / 2; ++i)
216 for (
unsigned i = 0; i <
N; ++i)
217 m[(i * (i + 1)) / 2 + i] =
F(1) /
fL[(i * (i + 1)) / 2 + i];
229 if (!
fOk)
return false;
230 for (
unsigned i = 0; i <
N; ++i) {
232 for (
unsigned j = i + 1;
j <
N; ++
j)
235 for (
unsigned j = 0;
j <= i; ++
j)
236 m(
j, i) =
fL[i * (i + 1) / 2 +
j];
239 for (
unsigned i = 1; i <
N; ++i) {
240 for (
unsigned j = 0;
j < i; ++
j) {
241 typename M::value_type tmp =
F(0);
242 for (
unsigned k = i; k-- >
j;)
243 tmp -=
m(k, i) *
m(
j, k);
244 m(
j, i) = tmp *
m(i, i);
260 if (!
fOk)
return false;
262 for (
unsigned i = 0; i < (
N * (
N + 1)) / 2; ++i)
266 for (
unsigned i = 1; i <
N;
base1 += ++i) {
267 for (
unsigned j = 0;
j < i; ++
j) {
269 const G *
base2 = &
m[(i * (i - 1)) / 2];
270 for (
unsigned k = i; k-- >
j;
base2 -= k)
423 template<
class M>
bool getL(M&
m)
const
425 if (!
fOk)
return false;
426 for (
unsigned i = 0; i <
fN; ++i) {
428 for (
unsigned j = i + 1;
j <
fN; ++
j)
431 for (
unsigned j = 0;
j <= i; ++
j)
432 m(i,
j) =
fL[i * (i + 1) / 2 +
j];
435 m(i, i) =
F(1) /
m(i, i);
448 template<
typename G>
bool getL(
G*
m)
const
450 if (!
fOk)
return false;
452 for (
unsigned i = 0; i < (
fN * (
fN + 1)) / 2; ++i)
456 for (
unsigned i = 0; i <
fN; ++i)
457 m[(i * (i + 1)) / 2 + i] =
F(1) /
fL[(i * (i + 1)) / 2 + i];
469 if (!
fOk)
return false;
470 for (
unsigned i = 0; i <
fN; ++i) {
472 for (
unsigned j = i + 1;
j <
fN; ++
j)
475 for (
unsigned j = 0;
j <= i; ++
j)
476 m(
j, i) =
fL[i * (i + 1) / 2 +
j];
479 for (
unsigned i = 1; i <
fN; ++i) {
480 for (
unsigned j = 0;
j < i; ++
j) {
481 typename M::value_type tmp =
F(0);
482 for (
unsigned k = i; k-- >
j;)
483 tmp -=
m(k, i) *
m(
j, k);
484 m(
j, i) = tmp *
m(i, i);
500 if (!
fOk)
return false;
502 for (
unsigned i = 0; i < (
fN * (
fN + 1)) / 2; ++i)
506 for (
unsigned i = 1; i <
fN;
base1 += ++i) {
507 for (
unsigned j = 0;
j < i; ++
j) {
509 const G *
base2 = &
m[(i * (i - 1)) / 2];
510 for (
unsigned k = i; k-- >
j;
base2 -= k)
519namespace CholeskyDecompHelpers {
530 {
return fArr[((i * (i + 1)) / 2) +
j]; }
533 {
return fArr[((i * (i + 1)) / 2) +
j]; }
555 for (
unsigned i = 0; i <
N;
base1 += ++i) {
559 for (
unsigned j = 0;
j < i;
base2 += ++
j) {
561 for (
unsigned k =
j; k--; )
570 if (
tmpdiag <=
F(0.0))
return false;
593 F *
l =
new F[
N * (
N + 1) / 2];
594 std::copy(
src,
src + ((
N * (
N + 1)) / 2),
l);
597 for (
unsigned i = 1; i <
N;
base1 += ++i) {
598 for (
unsigned j = 0;
j < i; ++
j) {
600 const F *
base2 = &
l[(i * (i - 1)) / 2];
601 for (
unsigned k = i; k-- >
j;
base2 -= k)
608 for (
unsigned i =
N; i--; ) {
609 for (
unsigned j = i + 1;
j--; ) {
612 for (
unsigned k =
N; k-- > i;
base1 -= k)
636 for (
unsigned k = 0; k <
N; ++k) {
637 const unsigned base = (k * (k + 1)) / 2;
639 for (
unsigned i = k; i--; )
645 for (
unsigned k =
N; k--; ) {
647 for (
unsigned i =
N; --i > k; )
648 sum +=
rhs[i] *
l[(i * (i + 1)) / 2 + k];
650 rhs[k] = (
rhs[k] -
sum) *
l[(k * (k + 1)) / 2 + k];
656 template<
class F,
unsigned N,
class V>
struct _solver
669 if (
src(0,0) <=
F(0.0))
return false;
670 dst[0] = std::sqrt(
F(1.0) /
src(0,0));
673 if (
dst[2] <=
F(0.0))
return false;
674 else dst[2] = std::sqrt(
F(1.0) /
dst[2]);
678 if (
dst[5] <=
F(0.0))
return false;
679 else dst[5] = std::sqrt(
F(1.0) /
dst[5]);
684 if (
dst[9] <=
F(0.0))
return false;
685 else dst[9] = std::sqrt(
F(1.0) /
dst[9]);
691 if (
dst[14] <=
F(0.0))
return false;
692 else dst[14] = std::sqrt(
F(1.0) /
dst[14]);
699 if (
dst[20] <=
F(0.0))
return false;
700 else dst[20] = std::sqrt(
F(1.0) /
dst[20]);
710 if (
src(0,0) <=
F(0.0))
return false;
711 dst[0] = std::sqrt(
F(1.0) /
src(0,0));
714 if (
dst[2] <=
F(0.0))
return false;
715 else dst[2] = std::sqrt(
F(1.0) /
dst[2]);
719 if (
dst[5] <=
F(0.0))
return false;
720 else dst[5] = std::sqrt(
F(1.0) /
dst[5]);
725 if (
dst[9] <=
F(0.0))
return false;
726 else dst[9] = std::sqrt(
F(1.0) /
dst[9]);
732 if (
dst[14] <=
F(0.0))
return false;
733 else dst[14] = std::sqrt(
F(1.0) /
dst[14]);
743 if (
src(0,0) <=
F(0.0))
return false;
744 dst[0] = std::sqrt(
F(1.0) /
src(0,0));
747 if (
dst[2] <=
F(0.0))
return false;
748 else dst[2] = std::sqrt(
F(1.0) /
dst[2]);
752 if (
dst[5] <=
F(0.0))
return false;
753 else dst[5] = std::sqrt(
F(1.0) /
dst[5]);
758 if (
dst[9] <=
F(0.0))
return false;
759 else dst[9] = std::sqrt(
F(1.0) /
dst[9]);
769 if (
src(0,0) <=
F(0.0))
return false;
770 dst[0] = std::sqrt(
F(1.0) /
src(0,0));
773 if (
dst[2] <=
F(0.0))
return false;
774 else dst[2] = std::sqrt(
F(1.0) /
dst[2]);
778 if (
dst[5] <=
F(0.0))
return false;
779 else dst[5] = std::sqrt(
F(1.0) /
dst[5]);
789 if (
src(0,0) <=
F(0.0))
return false;
790 dst[0] = std::sqrt(
F(1.0) /
src(0,0));
793 if (
dst[2] <=
F(0.0))
return false;
794 else dst[2] = std::sqrt(
F(1.0) /
dst[2]);
804 if (
src(0,0) <=
F(0.0))
return false;
805 dst[0] = std::sqrt(
F(1.0) /
src(0,0));
988 template<
class F,
class V>
struct _solver<F,6,V>
994 const F
y0 =
rhs[0] *
l[0];
1016 const F
y0 =
rhs[0] *
l[0];
1036 const F
y0 =
rhs[0] *
l[0];
1054 const F
y0 =
rhs[0] *
l[0];
1070 const F
y0 =
rhs[0] *
l[0];
1084 rhs[0] *=
l[0] *
l[0];
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
bool getL(G *m) const
obtain the decomposed matrix L
bool getL(M &m) const
obtain the decomposed matrix L
~CholeskyDecompGenDim()
destructor
CholeskyDecompGenDim(unsigned N, G *m)
perform a Cholesky decomposition
bool Invert(G *m) const
place the inverse into m
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
F * fL
lower triangular matrix L
unsigned fN
dimensionality dimensionality of the problem
CholeskyDecompGenDim(unsigned N, const M &m)
perform a Cholesky decomposition
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, const F *src, unsigned N) 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)