10#ifndef ROOT_Minuit2_MnMatrix
11#define ROOT_Minuit2_MnMatrix
28#ifdef MN_USE_STACK_ALLOC
29#define _MN_NO_THREAD_SAVE_
70#ifdef _MN_NO_THREAD_SAVE_
80#ifdef _MN_NO_THREAD_SAVE_
89#ifdef _MN_NO_THREAD_SAVE_
106#ifdef DEBUG_ALLOCATOR
111 void *result =
malloc(nBytes);
113 throw std::bad_alloc();
121#ifdef _MN_NO_THREAD_SAVE_
123 int delBlock =
ToInt(p);
124 int nextBlock =
ReadInt(delBlock);
125 int previousBlock =
ReadInt(nextBlock -
sizeof(
int));
131 int nextNextBlock =
ReadInt(nextBlock);
132 WriteInt(nextNextBlock -
sizeof(
int), previousBlock);
134 WriteInt(previousBlock, nextNextBlock);
138#ifdef DEBUG_ALLOCATOR
150 int *ip = (
int *)(
fStack + offset);
162 int *ip =
reinterpret_cast<int *
>(
fStack + offset);
168 unsigned char *pc =
static_cast<unsigned char *
>(p);
172 int userBlock = pc -
fStack;
173 return userBlock -
sizeof(
int);
178 const int fAlignment = 4;
179 int needed = nBytes % fAlignment == 0 ? nBytes : (nBytes / fAlignment + 1) * fAlignment;
180 return needed + 2 *
sizeof(
int);
206 int beg2 =
ReadInt(end -
sizeof(
int));
242 return gStackAllocator;
267template <
class Type,
class M,
class T =
double>
283template <
class mt,
class M,
class T>
290template <
class mt,
class M,
class T>
293 return {obj, T(1.) /
f};
297template <
class mt,
class M,
class T>
304template <
class mt,
class M,
class T>
307 return {obj.
Obj(), obj.
f() *
f};
311template <
class mt,
class M,
class T>
314 return {obj.
Obj(), obj.
f() /
f};
318template <
class mt,
class M,
class T>
321 return {obj.
Obj(), T(-1.) * obj.
f()};
324template <
class M1,
class M2>
329 const M1 &
A()
const {
return fA; }
330 const M2 &
B()
const {
return fB; }
338template <
class atype,
class A,
class B,
class T>
347template <
class atype,
class A,
class B,
class T>
348ABObj<atype, ABSum<ABObj<atype, A, T>, ABObj<atype, B, T>>, T>
355template <
class M1,
class M2>
360 const M1 &
A()
const {
return fA; }
361 const M2 &
B()
const {
return fB; }
369template <
class A,
class B,
class T>
377template <
class M,
class T>
389template <
class M,
class T>
395template <
class mtype,
class M,
class T>
408template <
class M,
class T>
415template <
class mt,
class M,
class T>
421void Mndaxpy(
unsigned int,
double,
const double *,
double *);
422void Mndscal(
unsigned int,
double,
double *);
450 std::memset(
fData, 0,
fSize *
sizeof(
double));
464 std::memcpy(
fData,
v.Data(),
fSize *
sizeof(
double));
484 }
else if (
fSize >
v.size()) {
485 throw std::runtime_error(
"Can't assign smaller LASymMatrix to larger LASymMatrix");
487 std::memcpy(
fData,
v.Data(),
fSize *
sizeof(
double));
508 std::memcpy(
fData,
v.Obj().Data(),
fSize *
sizeof(
double));
513 template <
class A,
class B,
class T>
518 (*this) =
sum.Obj().A();
519 (*this) +=
sum.Obj().B();
523 template <
class A,
class T>
531 (*this) =
sum.Obj().B();
533 (*this) +=
sum.Obj().A();
538 template <
class A,
class T>
543 (*this) = something.Obj();
544 (*this) *= something.f();
555 std::memcpy(
fData, inv.Obj().Obj().Obj().Data(),
fSize *
sizeof(
double));
561 template <
class A,
class T>
563 const ABObj<
sym,
ABSum<
ABObj<
sym,
MatrixInverse<
sym,
ABObj<sym, LASymMatrix, T>, T>, T>,
ABObj<sym, A, T>>, T>
570 (*this) =
sum.Obj().B();
571 (*this) +=
sum.Obj().A();
578 template <
class A,
class T>
580 const ABObj<
sym,
ABSum<
ABObj<
sym,
VectorOuterProduct<
ABObj<vec, LAVector, T>, T>, T>,
ABObj<sym, A, T>>, T> &
sum)
586 (*this) =
sum.Obj().B();
587 (*this) +=
sum.Obj().A();
595 assert(
fSize ==
m.size());
603 assert(
fSize ==
m.size());
612 assert(
fSize ==
m.Obj().size());
613 if (
m.Obj().Data() ==
fData) {
622 template <
class A,
class T>
649 Outer_prod(*
this,
m.Obj().Obj().Obj(),
m.f() *
m.Obj().Obj().f() *
m.Obj().Obj().f());
663 return fData[col + row * (row + 1) / 2];
665 return fData[row + col * (col + 1) / 2];
672 return fData[col + row * (row + 1) / 2];
674 return fData[row + col * (col + 1) / 2];
702 assert(
fSize ==
v.Obj().size());
705 std::memcpy(
fData,
v.Obj().Data(),
fSize *
sizeof(
double));
710 template <
class A,
class T>
716 (*this) = something.Obj();
717 (*this) *= something.f();
720 tmp *= something.f();
729 template <
class A,
class B,
class T>
736 (*this) =
sum.Obj().A();
737 (*this) +=
sum.Obj().B();
741 tmp +=
sum.Obj().B();
749 template <
class A,
class T>
757 (*this) =
sum.Obj().B();
758 (*this) +=
sum.Obj().A();
763 tmp +=
sum.Obj().A();
776 fSize = inv.Obj().Obj().Obj().size();
777 fNRow = inv.Obj().Obj().Obj().Nrow();
779 std::memcpy(
fData, inv.Obj().Obj().Obj().Data(),
fSize *
sizeof(
double));
780 (*this) *= inv.Obj().Obj().f();
796inline ABObj<sym, ABSum<ABObj<sym, LASymMatrix>, ABObj<sym, LASymMatrix>>>
802inline ABObj<sym, ABSum<ABObj<sym, LASymMatrix>, ABObj<sym, LASymMatrix>>>
815 return {obj, 1. /
f};
823void Mndaxpy(
unsigned int,
double,
const double *,
double *);
824void Mndscal(
unsigned int,
double,
double *);
825void Mndspmv(
unsigned int,
double,
const double *,
const double *,
double,
double *);
836 std::memset(
fData, 0,
size() *
sizeof(
double));
856 std::memcpy(
fData,
v.data(),
fSize *
sizeof(
double));
867 }
else if (
fSize >
v.size()) {
868 throw std::runtime_error(
"Can't assign smaller LAVector to larger LAVector");
870 std::memcpy(
fData,
v.Data(),
fSize *
sizeof(
double));
888 std::memcpy(
fData,
v.Obj().Data(),
fSize *
sizeof(T));
893 template <
class A,
class B,
class T>
898 (*this) =
sum.Obj().A();
899 (*this) +=
sum.Obj().B();
903 template <
class A,
class T>
911 (*this) =
sum.Obj().B();
913 (*this) +=
sum.Obj().A();
918 template <
class A,
class T>
922 (*this) = something.Obj();
923 (*this) *= something.f();
935 Mndspmv(
fSize, prod.f() * prod.Obj().A().f() * prod.Obj().B().f(), prod.Obj().A().Obj().Data(),
936 prod.Obj().B().Obj().Data(), 0.,
fData);
943 ABSum<
ABObj<
vec,
ABProd<
ABObj<sym, LASymMatrix, T>,
ABObj<vec, LAVector, T>>, T>,
ABObj<vec, LAVector, T>>,
946 (*this) = prod.Obj().B();
947 (*this) += prod.Obj().A();
948 (*this) *=
double(prod.f());
955 assert(
fSize ==
m.size());
963 assert(
fSize ==
m.size());
972 assert(
fSize ==
m.Obj().size());
973 if (
m.Obj().Data() ==
fData) {
982 template <
class A,
class T>
993 Mndspmv(
fSize, prod.f() * prod.Obj().A().f() * prod.Obj().B().f(), prod.Obj().A().Obj().Data(),
994 prod.Obj().B().Data(), 1.,
fData);
1047 assert(
fSize ==
v.Obj().size());
1049 std::memcpy(
fData,
v.Obj().Data(),
fSize *
sizeof(
double));
1050 (*this) *= T(
v.f());
1054 template <
class A,
class T>
1060 (*this) = something.Obj();
1066 (*this) *= something.f();
1070 template <
class A,
class B,
class T>
1074 (*this) =
sum.Obj().A();
1075 (*this) +=
sum.Obj().B();
1078 tmp +=
sum.Obj().B();
1086 template <
class A,
class T>
1090 (*this) =
sum.Obj().B();
1091 (*this) +=
sum.Obj().A();
1094 tmp +=
sum.Obj().B();
1107 fSize = prod.Obj().B().Obj().size();
1109 Mndspmv(
fSize,
double(prod.f() * prod.Obj().A().f() * prod.Obj().B().f()), prod.Obj().A().Obj().Data(),
1110 prod.Obj().B().Obj().Data(), 0.,
fData);
1114 Mndspmv(
fSize,
double(prod.f() * prod.Obj().A().f()), prod.Obj().A().Obj().Data(), tmp.
Data(), 0.,
fData);
1124 ABSum<
ABObj<
vec,
ABProd<
ABObj<sym, LASymMatrix, T>,
ABObj<vec, LAVector, T>>, T>,
ABObj<vec, LAVector, T>>,
1128 (*this) = prod.Obj().B();
1129 (*this) += prod.Obj().A();
1133 tmp += prod.Obj().A();
1137 (*this) *= prod.f();
1142inline ABObj<vec, ABSum<ABObj<vec, LAVector>, ABObj<vec, LAVector>>>
1154inline ABObj<vec, ABSum<ABObj<vec, LAVector>, ABObj<vec, LAVector>>>
1166 return {obj, 1. /
f};
1174inline ABObj<vec, ABProd<ABObj<sym, LASymMatrix>, ABObj<vec, LAVector>>>
1188int Invert(LASymMatrix &);
1200void Outer_prod(LASymMatrix &,
const LAVector &,
double f = 1.);
1202double inner_product(
const LAVector &,
const LAVector &);
1203double similarity(
const LAVector &,
const LASymMatrix &);
1204double sum_of_elements(
const LASymMatrix &);
1205LAVector eigenvalues(
const LASymMatrix &);
1207std::ostream &
operator<<(std::ostream &,
const LAVector &);
1209std::ostream &
operator<<(std::ostream &,
const LASymMatrix &);
TTime operator*(const TTime &t1, const TTime &t2)
TTime operator/(const TTime &t1, const TTime &t2)
TTime operator-(const TTime &t1, const TTime &t2)
ABObj(const M &obj, T factor=1.)
ABProd(const M1 &a, const M2 &b)
ABSum(const M1 &a, const M2 &b)
DeleteAssignment & operator=(const DeleteAssignment &)=delete
~DeleteAssignment()=default
DeleteAssignment(DeleteAssignment &&)=default
DeleteAssignment(const DeleteAssignment &)=default
DeleteAssignment & operator=(DeleteAssignment &&)=delete
DeleteAssignment()=default
Class describing a symmetric matrix of size n.
LASymMatrix(const ABObj< sym, MatrixInverse< sym, ABObj< sym, LASymMatrix, T >, T >, T > &inv)
LASymMatrix & operator=(const ABObj< sym, LASymMatrix, T > &v)
LASymMatrix & operator-=(const LASymMatrix &m)
LASymMatrix(const ABObj< sym, ABSum< ABObj< sym, LASymMatrix, T >, ABObj< sym, A, T > >, T > &sum)
double & operator()(unsigned int row, unsigned int col)
const double * Data() const
unsigned int Ncol() const
double operator()(unsigned int row, unsigned int col) const
LASymMatrix & operator=(const LASymMatrix &v)
LASymMatrix & operator+=(const ABObj< sym, LASymMatrix, T > &m)
LASymMatrix(const ABObj< sym, ABSum< ABObj< sym, MatrixInverse< sym, ABObj< sym, LASymMatrix, T >, T >, T >, ABObj< sym, A, T > >, T > &sum)
LASymMatrix(const ABObj< sym, ABSum< ABObj< sym, A, T >, ABObj< sym, B, T > >, T > &sum)
LASymMatrix(LASymMatrix &&v)
LASymMatrix & operator*=(double scal)
LASymMatrix & operator+=(const ABObj< sym, A, T > &m)
LASymMatrix & operator=(const ABObj< sym, MatrixInverse< sym, ABObj< sym, LASymMatrix, T >, T >, T > &inv)
LASymMatrix(unsigned int n)
LASymMatrix(const ABObj< sym, LASymMatrix, T > &v)
LASymMatrix & operator=(const ABObj< sym, ABSum< ABObj< sym, A, T >, ABObj< sym, B, T > >, T > &sum)
LASymMatrix & operator=(LASymMatrix &&v)
LASymMatrix(const LASymMatrix &v)
unsigned int Nrow() const
LASymMatrix(const ABObj< sym, ABObj< sym, A, T >, T > &something)
LASymMatrix & operator+=(const ABObj< sym, MatrixInverse< sym, ABObj< sym, LASymMatrix, T >, T >, T > &m)
LASymMatrix & operator=(const ABObj< sym, ABSum< ABObj< sym, LASymMatrix, T >, ABObj< sym, A, T > >, T > &sum)
LASymMatrix(const ABObj< sym, ABSum< ABObj< sym, VectorOuterProduct< ABObj< vec, LAVector, T >, T >, T >, ABObj< sym, A, T > >, T > &sum)
LASymMatrix & operator+=(const LASymMatrix &m)
LASymMatrix & operator+=(const ABObj< sym, VectorOuterProduct< ABObj< vec, LAVector, T >, T >, T > &m)
unsigned int size() const
LASymMatrix & operator=(const ABObj< sym, ABObj< sym, A, T >, T > &something)
LAVector & operator=(const ABObj< vec, ABSum< ABObj< vec, A, T >, ABObj< vec, B, T > >, T > &sum)
const double * Data() const
LAVector & operator*=(double scal)
unsigned int size() const
double operator[](unsigned int i) const
double operator()(unsigned int i) const
LAVector & operator+=(const LAVector &m)
LAVector(const ABObj< vec, ABProd< ABObj< sym, LASymMatrix, T >, ABObj< vec, LAVector, T > >, T > &prod)
LAVector(const ABObj< vec, ABObj< vec, A, T >, T > &something)
LAVector & operator=(const ABObj< vec, LAVector, T > &v)
LAVector(const ABObj< vec, ABSum< ABObj< vec, A, T >, ABObj< vec, B, T > >, T > &sum)
double & operator[](unsigned int i)
LAVector & operator=(const ABObj< vec, ABObj< vec, A, T >, T > &something)
LAVector & operator=(LAVector &&v)
LAVector & operator=(const LAVector &v)
LAVector(const ABObj< vec, ABSum< ABObj< vec, LAVector, T >, ABObj< vec, A, T > >, T > &sum)
LAVector & operator+=(const ABObj< vec, A, T > &m)
LAVector(const ABObj< vec, ABSum< ABObj< vec, ABProd< ABObj< sym, LASymMatrix, T >, ABObj< vec, LAVector, T > >, T >, ABObj< vec, LAVector, T > >, T > &prod)
LAVector(const ABObj< vec, LAVector, T > &v)
LAVector & operator-=(const LAVector &m)
LAVector(std::span< const double > v)
LAVector(const LAVector &v)
LAVector & operator=(const ABObj< vec, ABSum< ABObj< vec, ABProd< ABObj< sym, LASymMatrix, T >, ABObj< vec, LAVector, T > >, T >, ABObj< vec, LAVector, T > >, T > &prod)
double & operator()(unsigned int i)
LAVector & operator=(const ABObj< vec, ABSum< ABObj< vec, LAVector, T >, ABObj< vec, A, T > >, T > &sum)
LAVector & operator=(const ABObj< vec, ABProd< ABObj< sym, LASymMatrix, T >, ABObj< vec, LAVector, T > >, T > &prod)
LAVector & operator+=(const ABObj< vec, ABProd< ABObj< sym, LASymMatrix, T >, ABObj< vec, LAVector, T > >, T > &prod)
LAVector & operator+=(const ABObj< vec, LAVector, T > &m)
MatrixInverse(MatrixInverse &&)=delete
MatrixInverse(const MatrixInverse &)=delete
MatrixInverse(const M &obj)
static StackAllocator & Get()
StackAllocator controls the memory allocation/deallocation of Minuit.
void WriteInt(int offset, int Value)
void * Allocate(size_t nBytes)
void CheckOverflow(int n)
int AlignedSize(int nBytes)
define stack allocator symbol
VectorOuterProduct(const M &obj)
std::ostream & operator<<(std::ostream &os, const RConcurrentHashColl::HashValue &h)
ABObj< mt, M, T > operator*(T f, const M &obj)
int Invert_undef_sym(LASymMatrix &)
void Mndaxpy(unsigned int, double, const double *, double *)
int Invert(LASymMatrix &)
void Mndscal(unsigned int, double, double *)
ABObj< mt, MatrixInverse< mt, ABObj< mt, M, T >, T >, T > Inverse(const ABObj< mt, M, T > &obj)
void Mndspmv(unsigned int, double, const double *, const double *, double, double *)
ABObj< mt, M, T > operator-(const M &obj)
void Outer_prod(LASymMatrix &, const LAVector &, double f=1.)
ABObj< mt, M, T > operator/(const M &obj, T f)
ABObj< atype, ABSum< ABObj< atype, A, T >, ABObj< atype, B, T > >, T > operator+(const ABObj< atype, A, T > &a, const ABObj< atype, B, T > &b)
ABObj< sym, VectorOuterProduct< ABObj< vec, M, T >, T >, T > Outer_product(const ABObj< vec, M, T > &obj)
ELogLevel operator+(ELogLevel severity, int offset)
static uint64_t sum(uint64_t i)