40template<
class Element>
43 const int incs[] = {1,5,19,41,109,209,505,929,2161,3905,8929,16001,INT_MAX};
46 while (incs[kinc] <=
n/2)
53 for( ; kinc >= 0; kinc--) {
54 const Int_t inc = incs[kinc];
56 for (
Int_t k = inc; k <
n; k++) {
57 const Element tmp = data[k];
58 const Int_t fi = first [k];
59 const Int_t se = second[k];
61 for (j = k; j >= inc; j -= inc) {
62 if ( fi < first[j-inc] || (fi == first[j-inc] && se < second[j-inc]) ) {
63 data [j] = data [j-inc];
64 first [j] = first [j-inc];
65 second[j] = second[j-inc];
79template<
class Element>
83 const int incs[] = {1,5,19,41,109,209,505,929,2161,3905,8929,16001,INT_MAX};
86 while (incs[kinc] <=
n/2)
93 for( ; kinc >= 0; kinc--) {
94 const Int_t inc = incs[kinc];
96 if ( !swapFirst && !swapSecond ) {
97 for (
Int_t k = inc; k <
n; k++) {
99 const Int_t ktemp = index[k];
100 const Int_t fi = first [ktemp];
101 const Int_t se = second[ktemp];
104 for (j = k; j >= inc; j -= inc) {
106 if (fi < first[index[j-inc]] || (fi == first[index[j-inc]] && se < second[index[j-inc]])) {
110 index[j] = index[j-inc];
121 }
else if ( swapSecond && !swapFirst ) {
122 for (
Int_t k = inc; k <
n; k++) {
123 const Int_t ktemp = index[k];
124 const Int_t fi = first [ktemp];
125 const Int_t se = second[k];
127 for (j = k; j >= inc; j -= inc) {
128 if (fi < first[index[j-inc]] || (fi == first[index[j-inc]] && se < second[j-inc])) {
129 index [j] = index[j-inc];
130 second[j] = second[j-inc];
138 }
else if (swapFirst && !swapSecond) {
140 const Int_t ktemp = index[k];
141 const Int_t fi = first[k];
142 const Int_t se = second[ktemp];
144 for (j = k; j >= inc; j -= inc) {
145 if ( fi < first[j-inc] || (fi == first[j-inc] && se < second[ index[j-inc]])) {
146 index[j] = index[j-inc];
147 first[j] = first[j-inc];
157 const Int_t ktemp = index[k];
159 const Int_t se = second[k];
161 for (j = k; j >= inc; j -= inc) {
162 if ( fi < first[j-inc] || (fi == first[j-inc] && se < second[j-inc])) {
163 index [j] = index [j-inc];
164 first [j] = first [j-inc];
165 second[j] = second[j-inc];
186template<
class Element>
200 elem[off1+icol] = data[off2+irow];
206 memcpy(elem,data,fNelems*
sizeof(Element));
214template<
class Element>
226 for (
Int_t icol = 0; icol < irow; icol++) {
227 if (elem[rowOff+icol] != elem[colOff+irow])
243template<
class Element>
257 data[off2+irow] = elem[off1+icol];
263 memcpy(data,elem,
fNelems*
sizeof(Element));
269template<
class Element>
277 if (arown >=
fNrows || arown < 0) {
278 Error(
"InsertRow",
"row %d out of matrix range",rown);
282 if (acoln >=
fNcols || acoln < 0) {
283 Error(
"InsertRow",
"column %d out of matrix range",coln);
287 if (acoln+nr >
fNcols || nr < 0) {
288 Error(
"InsertRow",
"row length %d out of range",nr);
295 memcpy(elem,
v,nr*
sizeof(Element));
303template<
class Element>
311 if (arown >=
fNrows || arown < 0) {
312 Error(
"ExtractRow",
"row %d out of matrix range",rown);
316 if (acoln >=
fNcols || acoln < 0) {
317 Error(
"ExtractRow",
"column %d out of matrix range",coln);
321 if (acoln+
n >=
fNcols || nr < 0) {
322 Error(
"ExtractRow",
"row length %d out of range",nr);
329 memcpy(
v,elem,nr*
sizeof(Element));
337template<
class Element>
349template<
class Element>
361template<
class Element>
367 const Element *
const fp = ep+
fNelems;
379template<
class Element>
385 const Element *
const fp = ep+
fNelems;
397template<
class Element>
403 const Element *
const fp = ep+
fNelems;
415template<
class Element>
421 memset(ep,0,
fNelems*
sizeof(Element));
424 *ep++ = (i==j ? 1.0 : 0.0);
434template<
class Element>
442 if (
v.GetNoElements() < nMax) {
443 Error(
"NormByDiag",
"vector shorter than matrix diagonal");
452 const Element *pV =
v.GetMatrixArray();
457 if (pV[irow] != 0.0) {
459 if (pV[icol] != 0.0) {
463 Error(
"NormbyDiag",
"vector element %d is zero",icol);
468 Error(
"NormbyDiag",
"vector element %d is zero",irow);
488template<
class Element>
494 const Element *
const fp = ep+
fNelems;
515template<
class Element>
521 const Element *
const fp = ep+
fNcols;
542template<
class Element>
548 const Element *
const fp = ep+
fNelems;
551 for ( ; ep < fp; ep++)
552 sum += (*ep) * (*ep);
560template<
class Element>
565 Int_t nr_nonzeros = 0;
567 const Element *
const fp = ep+
fNelems;
569 if (*ep++ != 0.0) nr_nonzeros++;
577template<
class Element>
584 const Element *
const fp = ep+
fNelems;
594template<
class Element>
607template<
class Element>
621template<
class Element>
624 gROOT->ProcessLine(
Form(
"THistPainter::PaintSpecialObjects((TObject*)0x%zx,\"%s\");",
625 (
size_t)
this, option));
634template<
class Element>
638 Error(
"Print",
"Matrix is invalid");
643 const char *format =
"%11.4g ";
645 const char *
f = strstr(option,
"f=");
649 snprintf(topbar,100,format,123.456789);
650 Int_t nch = strlen(topbar)+1;
651 if (nch > 18) nch = 18;
653 for (
Int_t i = 0; i < nch; i++) ftopbar[i] =
' ';
655 snprintf(ftopbar+nch/2,20-nch/2,
"%s%dd",
"%",nk);
656 Int_t nch2 = strlen(ftopbar);
657 for (
Int_t i = nch2; i < nch; i++) ftopbar[i] =
' ';
663 Int_t cols_per_sheet = 5;
664 if (nch <= 8) cols_per_sheet =10;
670 for (
Int_t i = 0; i < nk; i++) topbar[i] =
'-';
672 for (
Int_t sheet_counter = 1; sheet_counter <= ncols; sheet_counter += cols_per_sheet) {
674 for (
Int_t j = sheet_counter; j < sheet_counter+cols_per_sheet && j <= ncols; j++)
675 printf(ftopbar,j+collwb-1);
676 printf(
"\n%s\n",topbar);
678 for (
Int_t i = 1; i <= nrows; i++) {
679 printf(
"%4d |",i+rowlwb-1);
680 for (
Int_t j = sheet_counter; j < sheet_counter+cols_per_sheet && j <= ncols; j++)
681 printf(format,(*
this)(i+rowlwb-1,j+collwb-1));
691template<
class Element>
700 const Element *
const fp = ep+
fNelems;
701 for (; ep < fp; ep++)
711template<
class Element>
720 const Element *
const fp = ep+
fNelems;
721 for (; ep < fp; ep++)
731template<
class Element>
737 const Element *
const fp = ep+
fNelems;
738 for (; ep < fp; ep++)
748template<
class Element>
754 const Element *
const fp = ep+
fNelems;
755 for (; ep < fp; ep++)
765template<
class Element>
771 const Element *
const fp = ep+
fNelems;
772 for (; ep < fp; ep++)
782template<
class Element>
788 const Element *
const fp = ep+
fNelems;
789 for (; ep < fp; ep++)
799template<
class Element>
805 const Element *
const ep_last = ep+
fNelems;
816template<
class Element>
834template<
class Element>
839 const Element scale = beta-alpha;
840 const Element shift = alpha/scale;
843 const Element *
const fp = ep+
fNelems;
845 *ep++ = scale*(
Drand(seed)+shift);
853template<
class Element>
864template<
class Element>
868 ::Error(
"E2Norm",
"matrices not compatible");
877 for (; mp1 < fmp1; mp1++, mp2++)
878 sum += (*mp1 - *mp2)*(*mp1 - *mp2);
886template<
class Element1,
class Element2>
891 ::Error(
"AreCompatible",
"matrix 1 not valid");
896 ::Error(
"AreCompatible",
"matrix 2 not valid");
903 ::Error(
"AreCompatible",
"matrices 1 and 2 not compatible");
913template<
class Element>
917 Error(
"Compare(const TMatrixTBase<Element> &,const TMatrixTBase<Element> &)",
"matrices are incompatible");
921 printf(
"\n\nComparison of two TMatrices:\n");
932 const Element mv1 = m1(i,j);
933 const Element mv2 = m2(i,j);
947 printf(
"\nMaximal discrepancy \t\t%g", difmax);
948 printf(
"\n occurred at the point\t\t(%d,%d)",imax,jmax);
949 const Element mv1 = m1(imax,jmax);
950 const Element mv2 = m2(imax,jmax);
951 printf(
"\n Matrix 1 element is \t\t%g", mv1);
952 printf(
"\n Matrix 2 element is \t\t%g", mv2);
953 printf(
"\n Absolute error v2[i]-v1[i]\t\t%g", mv2-mv1);
954 printf(
"\n Relative error\t\t\t\t%g\n",
957 printf(
"\n||Matrix 1|| \t\t\t%g", norm1);
958 printf(
"\n||Matrix 2|| \t\t\t%g", norm2);
959 printf(
"\n||Matrix1-Matrix2||\t\t\t\t%g", ndiff);
960 printf(
"\n||Matrix1-Matrix2||/sqrt(||Matrix1|| ||Matrix2||)\t%g\n\n",
967template<
class Element>
977 Element maxDevObs = 0;
980 maxDevAllow = std::numeric_limits<Element>::epsilon();
982 for (
Int_t i =
m.GetRowLwb(); i <=
m.GetRowUpb(); i++) {
983 for (
Int_t j =
m.GetColLwb(); j <=
m.GetColUpb(); j++) {
985 if (dev > maxDevObs) {
997 printf(
"Largest dev for (%d,%d); dev = |%g - %g| = %g\n",imax,jmax,
m(imax,jmax),val,maxDevObs);
998 if(maxDevObs > maxDevAllow)
999 Error(
"VerifyElementValue",
"Deviation > %g\n",maxDevAllow);
1002 if(maxDevObs > maxDevAllow)
1010template<
class Element>
1012 Element maxDevAllow)
1017 if (m1 == 0 && m2 == 0)
1022 Element maxDevObs = 0;
1025 maxDevAllow = std::numeric_limits<Element>::epsilon();
1029 const Element dev =
TMath::Abs(m1(i,j)-m2(i,j));
1030 if (dev > maxDevObs) {
1042 printf(
"Largest dev for (%d,%d); dev = |%g - %g| = %g\n",
1043 imax,jmax,m1(imax,jmax),m2(imax,jmax),maxDevObs);
1044 if (maxDevObs > maxDevAllow)
1045 Error(
"VerifyMatrixValue",
"Deviation > %g\n",maxDevAllow);
1048 if (maxDevObs > maxDevAllow)
1056template<
class Element>
1065 Error(
"TMatrixTBase<Element>::Streamer",
"Unknown version number: %d",R__v);
1075template<
class Element>
1084template<
class Element>
int Int_t
Signed integer 4 bytes (int).
short Version_t
Class version identifier (short).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
float Float_t
Float 4 bytes (float).
const char Option_t
Option string (const char).
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
TMatrixTBase< Double_t > TMatrixDBase
TMatrixTBase< Float_t > TMatrixFBase
Double_t Drand(Double_t &ix)
Random number generator [0....1] with seed ix.
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Buffer base class used for serializing objects.
virtual Version_t ReadVersion(UInt_t *start=nullptr, UInt_t *bcnt=nullptr, const TClass *cl=nullptr)=0
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=nullptr)=0
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual void Operation(Element &element) const =0
virtual void Operation(Element &element) const =0
virtual Element Sum() const
Compute sum of elements.
virtual Element RowNorm() const
Row matrix norm, MAX{ SUM{ |M(i,j)|, over j}, over i}.
virtual Element ColNorm() const
Column matrix norm, MAX{ SUM{ |M(i,j)|, over i}, over j}.
virtual TMatrixTBase< Element > & Randomize(Element alpha, Element beta, Double_t &seed)
Randomize matrix element values.
virtual TMatrixTBase< Element > & Sqr()
Square each element of the matrix.
virtual const Element * GetMatrixArray() const =0
virtual TMatrixTBase< Element > & UnitMatrix()
Make a unit matrix (matrix need not be a square one).
Bool_t operator!=(Element val) const
Are all matrix elements not equal to val?
virtual TMatrixTBase< Element > & Zero()
Set matrix elements to zero.
void Print(Option_t *name="") const override
Print the matrix as a table of elements.
virtual Int_t NonZeros() const
Compute the number of elements != 0.0.
virtual Element E2Norm() const
Square of the Euclidean norm, SUM{ m(i,j)^2 }.
virtual TMatrixTBase< Element > & Apply(const TElementActionT< Element > &action)
Apply action to each matrix element.
virtual Element Min() const
return minimum matrix element value
virtual Element Max() const
return maximum vector element value
virtual void GetMatrix2Array(Element *data, Option_t *option="") const
Copy matrix data to array .
Int_t GetNoElements() const
Bool_t operator<(Element val) const
Are all matrix elements < val?
void Draw(Option_t *option="") override
Draw this matrix The histogram is named "TMatrixT" by default and no title.
virtual TMatrixTBase< Element > & InsertRow(Int_t row, Int_t col, const Element *v, Int_t n=-1)
Copy n elements from array v to row rown starting at column coln.
static Element & NaNValue()
static void DoubleLexSort(Int_t n, Int_t *first, Int_t *second, Element *data)
Lexical sort on array data using indices first and second.
Bool_t operator>(Element val) const
Are all matrix elements > val?
virtual TMatrixTBase< Element > & Sqrt()
Take square root of all elements.
Bool_t operator==(Element val) const
Are all matrix elements equal to val?
virtual TMatrixTBase< Element > & Abs()
Take an absolute value of a matrix, i.e. apply Abs() to each element.
virtual TMatrixTBase< Element > & Shift(Int_t row_shift, Int_t col_shift)
Shift the row index by adding row_shift and the column index by adding col_shift, respectively.
static void IndexedLexSort(Int_t n, Int_t *first, Int_t swapFirst, Int_t *second, Int_t swapSecond, Int_t *index)
Lexical sort on array data using indices first and second.
Bool_t operator<=(Element val) const
Are all matrix elements <= val?
void Streamer(TBuffer &) override
Stream an object of class TMatrixTBase<Element>.
virtual Bool_t IsSymmetric() const
Check whether matrix is symmetric.
virtual TMatrixTBase< Element > & SetMatrixArray(const Element *data, Option_t *option="")
Copy array data to matrix .
Bool_t operator>=(Element val) const
Are all matrix elements >= val?
virtual void ExtractRow(Int_t row, Int_t col, Element *v, Int_t n=-1) const
Store in array v, n matrix elements of row rown starting at column coln.
virtual TMatrixTBase< Element > & NormByDiag(const TVectorT< Element > &v, Option_t *option="D")
option:
const Float_t * GetMatrixArray() const override
void ToUpper()
Change string to upper case.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Long64_t LocMin(Long64_t n, const T *a)
Returns index of array with the minimum element.
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Long64_t LocMax(Long64_t n, const T *a)
Returns index of array with the maximum element.
Double_t Sqrt(Double_t x)
Returns the square root of x.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Double_t Log10(Double_t x)
Returns the common (base-10) logarithm of x.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Bool_t VerifyMatrixIdentity(const TMatrixTBase< Element > &m1, const TMatrixTBase< Element > &m2, Int_t verbose, Element maxDevAllow)
Verify that elements of the two matrices are equal within MaxDevAllow .
void Compare(const TMatrixTBase< Element > &m1, const TMatrixTBase< Element > &m2)
Compare two matrices and print out the result of the comparison.
Bool_t VerifyMatrixValue(const TMatrixTBase< Element > &m, Element val, Int_t verbose, Element maxDevAllow)
Validate that all elements of matrix have value val within maxDevAllow.
Bool_t operator==(const TMatrixTBase< Element > &m1, const TMatrixTBase< Element > &m2)
Check to see if two matrices are identical.
Element E2Norm(const TMatrixTBase< Element > &m1, const TMatrixTBase< Element > &m2)
Square of the Euclidean norm of the difference between two matrices.
Bool_t AreCompatible(const TMatrixTBase< Element1 > &m1, const TMatrixTBase< Element2 > &m2, Int_t verbose=0)
Check that matrice sm1 and m2 areboth valid and have identical shapes .
static uint64_t sum(uint64_t i)