// @(#)root/minuit2:$Id$ // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005 /********************************************************************** * * * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT * * * **********************************************************************/ #ifndef ROOT_Minuit2_LAVector #define ROOT_Minuit2_LAVector #include "Minuit2/ABSum.h" #include "Minuit2/ABProd.h" #include "Minuit2/LASymMatrix.h" #include #include #include "Minuit2/StackAllocator.h" namespace ROOT { namespace Minuit2 { // extern StackAllocator StackAllocatorHolder::Get(); int Mndaxpy(unsigned int, double, const double *, int, double *, int); int Mndscal(unsigned int, double, double *, int); int Mndspmv(const char *, unsigned int, double, const double *, const double *, int, double, double *, int); class LAVector { private: LAVector() : fSize(0), fData(nullptr) {} public: typedef vec Type; LAVector(unsigned int n) : fSize(n), fData( (n>0) ? (double *)StackAllocatorHolder::Get().Allocate(sizeof(double) * n) : nullptr) { // assert(fSize>0); if (fData) std::memset(fData, 0, size() * sizeof(double)); // std::cout<<"LAVector(unsigned int n), n= "< fSize) { if (fData) StackAllocatorHolder::Get().Deallocate(fData); fSize = v.size(); fData = (double *)StackAllocatorHolder::Get().Allocate(sizeof(double) * fSize); } std::memcpy(fData, v.Data(), fSize * sizeof(double)); return *this; } template LAVector(const ABObj &v) : fSize(v.Obj().size()), fData((double *)StackAllocatorHolder::Get().Allocate(sizeof(double) * v.Obj().size())) { // std::cout<<"LAVector(const ABObj& v)"< LAVector(const ABObj, ABObj>, T> &sum) : fSize(0), fData(nullptr) { // std::cout<<"template LAVector(const ABObj, ABObj > >& // sum)"< LAVector(const ABObj, ABObj>, T> &sum) : fSize(0), fData(nullptr) { // std::cout<<"template LAVector(const ABObj, ABObj >,T>& // sum)"< LAVector(const ABObj LAVector(const ABObj, T> &something) : fSize(0), fData(nullptr) { // std::cout<<"template LAVector(const ABObj, T>& something)"< LAVector(const ABObj, ABObj>, T> &prod) : fSize(prod.Obj().B().Obj().size()), fData((double *)StackAllocatorHolder::Get().Allocate(sizeof(double) * prod.Obj().B().Obj().size())) { // std::cout<<"template LAVector(const ABObj, ABObj >, T>& prod)"< LAVector(const ABObj< vec, ABSum, ABObj>, T>, ABObj>, T> &prod) : fSize(0), fData(nullptr) { (*this) = prod.Obj().B(); (*this) += prod.Obj().A(); (*this) *= double(prod.f()); } // LAVector &operator+=(const LAVector &m) { // std::cout<<"LAVector& operator+=(const LAVector& m)"< LAVector &operator+=(const ABObj &m) { // std::cout<<"template LAVector& operator+=(const ABObj& m)"< LAVector &operator+=(const ABObj &m) { // std::cout<<"template LAVector& operator+=(const ABObj& m)"< LAVector &operator+=(const ABObj, ABObj>, T> &prod) { Mndspmv("U", fSize, prod.f() * prod.Obj().A().f() * prod.Obj().B().f(), prod.Obj().A().Obj().Data(), prod.Obj().B().Data(), 1, 1., fData, 1); return *this; } LAVector &operator*=(double scal) { Mndscal(fSize, scal, fData, 1); return *this; } double operator()(unsigned int i) const { assert(i < fSize); return fData[i]; } double &operator()(unsigned int i) { assert(i < fSize); return fData[i]; } double operator[](unsigned int i) const { assert(i < fSize); return fData[i]; } double &operator[](unsigned int i) { assert(i < fSize); return fData[i]; } const double *Data() const { return fData; } double *Data() { return fData; } unsigned int size() const { return fSize; } private: unsigned int fSize; double *fData; public: template LAVector &operator=(const ABObj &v) { // std::cout<<"template LAVector& operator=(ABObj& v)"< LAVector &operator=(const ABObj, T> &something) { // std::cout<<"template LAVector& operator=(const ABObj, T>& // something)"< LAVector &operator=(const ABObj, ABObj>, T> &sum) { if (fSize == 0 && !fData) { (*this) = sum.Obj().A(); (*this) += sum.Obj().B(); } else { LAVector tmp(sum.Obj().A()); tmp += sum.Obj().B(); assert(fSize == tmp.size()); std::memcpy(fData, tmp.Data(), fSize * sizeof(double)); } (*this) *= sum.f(); return *this; } template LAVector &operator=(const ABObj, ABObj>, T> &sum) { if (fSize == 0 && !fData) { (*this) = sum.Obj().B(); (*this) += sum.Obj().A(); } else { LAVector tmp(sum.Obj().A()); tmp += sum.Obj().B(); assert(fSize == tmp.size()); std::memcpy(fData, tmp.Data(), fSize * sizeof(double)); } (*this) *= sum.f(); return *this; } // template LAVector &operator=(const ABObj, ABObj>, T> &prod) { if (fSize == 0 && !fData) { fSize = prod.Obj().B().Obj().size(); fData = (double *)StackAllocatorHolder::Get().Allocate(sizeof(double) * fSize); Mndspmv("U", fSize, double(prod.f() * prod.Obj().A().f() * prod.Obj().B().f()), prod.Obj().A().Obj().Data(), prod.Obj().B().Obj().Data(), 1, 0., fData, 1); } else { LAVector tmp(prod.Obj().B()); assert(fSize == tmp.size()); Mndspmv("U", fSize, double(prod.f() * prod.Obj().A().f()), prod.Obj().A().Obj().Data(), tmp.Data(), 1, 0., fData, 1); } return *this; } // template LAVector & operator=(const ABObj< vec, ABSum, ABObj>, T>, ABObj>, T> &prod) { if (fSize == 0 && !fData) { (*this) = prod.Obj().B(); (*this) += prod.Obj().A(); } else { // std::cout<<"creating tmp variable"<