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
113 throw std::bad_alloc();
121#ifdef _MN_NO_THREAD_SAVE_
138#ifdef DEBUG_ALLOCATOR
168 unsigned char *pc =
static_cast<unsigned char *
>(
p);
178 const int fAlignment = 4;
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>
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>
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();
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];
705 std::memcpy(
fData,
v.Obj().Data(),
fSize *
sizeof(
double));
710 template <
class A,
class T>
722 std::memcpy(
fData, tmp.Data(),
fSize *
sizeof(
double));
729 template <
class A,
class B,
class T>
736 (*this) =
sum.Obj().A();
737 (*this) +=
sum.Obj().B();
741 tmp +=
sum.Obj().B();
744 std::memcpy(
fData, tmp.Data(),
fSize *
sizeof(
double));
749 template <
class A,
class T>
757 (*this) =
sum.Obj().B();
758 (*this) +=
sum.Obj().A();
763 tmp +=
sum.Obj().A();
766 std::memcpy(
fData, tmp.Data(),
fSize *
sizeof(
double));
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();
788 std::memcpy(
fData, tmp.Data(),
fSize *
sizeof(
double));
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>
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());
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);
1028 const double *
Data()
const {
return fData; }
1036 double *fData =
nullptr;
1043 if (
fSize == 0 && !fData) {
1049 std::memcpy(fData,
v.Obj().Data(),
fSize *
sizeof(
double));
1050 (*this) *= T(
v.f());
1054 template <
class A,
class T>
1059 if (
fSize == 0 && !fData) {
1064 std::memcpy(fData, tmp.Data(),
fSize *
sizeof(
double));
1070 template <
class A,
class B,
class T>
1073 if (
fSize == 0 && !fData) {
1074 (*this) =
sum.Obj().A();
1075 (*this) +=
sum.Obj().B();
1078 tmp +=
sum.Obj().B();
1080 std::memcpy(fData, tmp.Data(),
fSize *
sizeof(
double));
1086 template <
class A,
class T>
1089 if (
fSize == 0 && !fData) {
1090 (*this) =
sum.Obj().B();
1091 (*this) +=
sum.Obj().A();
1094 tmp +=
sum.Obj().B();
1096 std::memcpy(fData, tmp.Data(),
fSize *
sizeof(
double));
1106 if (
fSize == 0 && !fData) {
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>>,
1127 if (
fSize == 0 && !fData) {
1128 (*this) = prod.Obj().B();
1129 (*this) += prod.Obj().A();
1133 tmp += prod.Obj().A();
1135 std::memcpy(fData, tmp.Data(),
fSize *
sizeof(
double));
1137 (*this) *= prod.f();
1166 return {obj, 1. /
f};
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 &);
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
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)
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
ELogLevel operator+(ELogLevel severity, int offset)
void inv(rsa_NUMBER *, rsa_NUMBER *, rsa_NUMBER *)
static uint64_t sum(uint64_t i)