99template<
class Element>
102 Allocate(no_rows,no_cols,0,0,1);
109template<
class Element>
112 Allocate(row_upb-row_lwb+1,col_upb-col_lwb+1,row_lwb,col_lwb,1);
119template<
class Element>
128 if (row[irowmin] < row_lwb || row[irowmax] > row_upb) {
129 Error(
"TMatrixTSparse",
"Inconsistency between row index and its range");
130 if (row[irowmin] < row_lwb) {
131 Info(
"TMatrixTSparse",
"row index lower bound adjusted to %d",row[irowmin]);
132 row_lwb = row[irowmin];
134 if (row[irowmax] > row_upb) {
135 Info(
"TMatrixTSparse",
"row index upper bound adjusted to %d",row[irowmax]);
136 col_lwb = col[irowmax];
139 if (col[icolmin] < col_lwb || col[icolmax] > col_upb) {
140 Error(
"TMatrixTSparse",
"Inconsistency between column index and its range");
141 if (col[icolmin] < col_lwb) {
142 Info(
"TMatrixTSparse",
"column index lower bound adjusted to %d",col[icolmin]);
143 col_lwb = col[icolmin];
145 if (col[icolmax] > col_upb) {
146 Info(
"TMatrixTSparse",
"column index upper bound adjusted to %d",col[icolmax]);
147 col_upb = col[icolmax];
151 Allocate(row_upb-row_lwb+1,col_upb-col_lwb+1,row_lwb,col_lwb,1,nr);
153 SetMatrixArray(nr,row,col,
data);
158template<
class Element>
171template<
class Element>
176 SetSparseIndex(another);
184template<
class Element>
189 Int_t nr_nonzeros = 0;
204 for (
Int_t i = rowLwb; i <= rowLwb+nrows-1; i++)
205 for (
Int_t j = colLwb; j <= colLwb+ncols-1; j++)
206 if (i==j) nr_nonzeros++;
207 Allocate(nrows,ncols,rowLwb,colLwb,1,nr_nonzeros);
215 Transpose(prototype);
226 Error(
"TMatrixTSparse(EMatrixCreatorOp1)",
"operation %d not yet implemented", op);
234template<
class Element>
258 Error(
"TMatrixTSparse(EMatrixCreatorOp2)",
"operation %d not yet implemented",op);
266template<
class Element>
290 Error(
"TMatrixTSparse(EMatrixCreatorOp2)",
"operation %d not yet implemented",op);
298template<
class Element>
322 Error(
"TMatrixTSparse(EMatrixCreatorOp2)",
"operation %d not yet implemented",op);
331template<
class Element>
335 if ( (nr_nonzeros > 0 && (no_rows == 0 || no_cols == 0)) ||
336 (no_rows < 0 || no_cols < 0 || nr_nonzeros < 0) )
338 Error(
"Allocate",
"no_rows=%d no_cols=%d non_zeros=%d",no_rows,no_cols,nr_nonzeros);
344 this->fNrows = no_rows;
345 this->fNcols = no_cols;
346 this->fRowLwb = row_lwb;
347 this->fColLwb = col_lwb;
348 this->fNrowIndex = this->fNrows+1;
349 this->fNelems = nr_nonzeros;
350 this->fIsOwner =
kTRUE;
351 this->fTol = std::numeric_limits<Element>::epsilon();
353 fRowIndex =
new Int_t[this->fNrowIndex];
355 memset(fRowIndex,0,this->fNrowIndex*
sizeof(
Int_t));
357 if (this->fNelems > 0) {
358 fElements =
new Element[this->fNelems];
359 fColIndex =
new Int_t [this->fNelems];
361 memset(fElements,0,this->fNelems*
sizeof(Element));
362 memset(fColIndex,0,this->fNelems*
sizeof(
Int_t));
373template<
class Element>
376 const Int_t arown = rown-this->fRowLwb;
377 const Int_t acoln = coln-this->fColLwb;
378 const Int_t nr = (
n > 0) ?
n : this->fNcols;
381 if (arown >= this->fNrows || arown < 0) {
382 Error(
"InsertRow",
"row %d out of matrix range",rown);
386 if (acoln >= this->fNcols || acoln < 0) {
387 Error(
"InsertRow",
"column %d out of matrix range",coln);
391 if (acoln+nr > this->fNcols || nr < 0) {
392 Error(
"InsertRow",
"row length %d out of range",nr);
397 const Int_t sIndex = fRowIndex[arown];
398 const Int_t eIndex = fRowIndex[arown+1];
405 Int_t lIndex = sIndex-1;
406 Int_t rIndex = sIndex-1;
411 if (icol >= acoln+nr)
break;
412 if (icol >= acoln) nslots++;
416 const Int_t nelems_old = this->fNelems;
417 const Int_t *colIndex_old = fColIndex;
418 const Element *elements_old = fElements;
420 const Int_t ndiff = nr-nslots;
421 this->fNelems += ndiff;
422 fColIndex =
new Int_t[this->fNelems];
423 fElements =
new Element[this->fNelems];
425 for (
Int_t irow = arown+1; irow < this->fNrows+1; irow++)
426 fRowIndex[irow] += ndiff;
429 memmove(fColIndex,colIndex_old,(lIndex+1)*
sizeof(
Int_t));
430 memmove(fElements,elements_old,(lIndex+1)*
sizeof(Element));
433 if (nelems_old > 0 && nelems_old-rIndex > 0) {
434 memmove(fColIndex+rIndex+ndiff,colIndex_old+rIndex,(nelems_old-rIndex)*
sizeof(
Int_t));
435 memmove(fElements+rIndex+ndiff,elements_old+rIndex,(nelems_old-rIndex)*
sizeof(Element));
439 for (
Int_t i = 0; i < nr; i++) {
440 fColIndex[
index] = acoln+i;
445 if (colIndex_old)
delete [] (
Int_t*) colIndex_old;
446 if (elements_old)
delete [] (Element*) elements_old;
448 R__ASSERT(this->fNelems == fRowIndex[this->fNrowIndex-1]);
456template<
class Element>
459 const Int_t arown = rown-this->fRowLwb;
460 const Int_t acoln = coln-this->fColLwb;
461 const Int_t nr = (
n > 0) ?
n : this->fNcols;
464 if (arown >= this->fNrows || arown < 0) {
465 Error(
"ExtractRow",
"row %d out of matrix range",rown);
469 if (acoln >= this->fNcols || acoln < 0) {
470 Error(
"ExtractRow",
"column %d out of matrix range",coln);
474 if (acoln+nr > this->fNcols || nr < 0) {
475 Error(
"ExtractRow",
"row length %d out of range",nr);
480 const Int_t sIndex = fRowIndex[arown];
481 const Int_t eIndex = fRowIndex[arown+1];
483 memset(
v,0,nr*
sizeof(Element));
484 const Int_t *
const pColIndex = GetColIndexArray();
485 const Element *
const pData = GetMatrixArray();
488 if (icol < acoln || icol >= acoln+nr)
continue;
489 v[icol-acoln] = pData[
index];
497template<
class Element>
504 if (
a.GetNcols() !=
b.GetNcols() ||
a.GetColLwb() !=
b.GetColLwb()) {
505 Error(
"AMultBt",
"A and B columns incompatible");
509 if (!constr && this->GetMatrixArray() ==
a.GetMatrixArray()) {
510 Error(
"AMultB",
"this = &a");
514 if (!constr && this->GetMatrixArray() ==
b.GetMatrixArray()) {
515 Error(
"AMultB",
"this = &b");
520 const Int_t *
const pRowIndexa =
a.GetRowIndexArray();
521 const Int_t *
const pColIndexa =
a.GetColIndexArray();
522 const Int_t *
const pRowIndexb =
b.GetRowIndexArray();
523 const Int_t *
const pColIndexb =
b.GetColIndexArray();
531 Int_t nr_nonzero_rowa = 0;
533 for (
Int_t irowa = 0; irowa <
a.GetNrows(); irowa++)
534 if (pRowIndexa[irowa] < pRowIndexa[irowa+1])
537 Int_t nr_nonzero_rowb = 0;
539 for (
Int_t irowb = 0; irowb <
b.GetNrows(); irowb++)
540 if (pRowIndexb[irowb] < pRowIndexb[irowb+1])
544 const Int_t nc = nr_nonzero_rowa*nr_nonzero_rowb;
545 Allocate(
a.GetNrows(),
b.GetNrows(),
a.GetRowLwb(),
b.GetRowLwb(),1,nc);
547 pRowIndexc = this->GetRowIndexArray();
548 pColIndexc = this->GetColIndexArray();
552 for (
Int_t irowa = 0; irowa <
a.GetNrows(); irowa++) {
553 pRowIndexc[irowa+1] = pRowIndexc[irowa];
554 if (pRowIndexa[irowa] >= pRowIndexa[irowa+1])
continue;
555 for (
Int_t irowb = 0; irowb <
b.GetNrows(); irowb++) {
556 if (pRowIndexb[irowb] >= pRowIndexb[irowb+1])
continue;
557 pRowIndexc[irowa+1]++;
558 pColIndexc[ielem++] = irowb;
562 pRowIndexc = this->GetRowIndexArray();
563 pColIndexc = this->GetColIndexArray();
566 const Element *
const pDataa =
a.GetMatrixArray();
567 const Element *
const pDatab =
b.GetMatrixArray();
568 Element *
const pDatac = this->GetMatrixArray();
570 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
571 const Int_t sIndexa = pRowIndexa[irowc];
572 const Int_t eIndexa = pRowIndexa[irowc+1];
573 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
574 const Int_t sIndexb = pRowIndexb[icolc];
575 const Int_t eIndexb = pRowIndexb[icolc+1];
577 Int_t indexb = sIndexb;
578 for (
Int_t indexa = sIndexa; indexa < eIndexa && indexb < eIndexb; indexa++) {
579 const Int_t icola = pColIndexa[indexa];
580 while (indexb < eIndexb && pColIndexb[indexb] <= icola) {
581 if (icola == pColIndexb[indexb]) {
582 sum += pDataa[indexa]*pDatab[indexb];
589 pColIndexc[indexc_r] = icolc;
590 pDatac[indexc_r] =
sum;
594 pRowIndexc[irowc+1] = indexc_r;
598 SetSparseIndex(indexc_r);
605template<
class Element>
612 if (
a.GetNcols() !=
b.GetNcols() ||
a.GetColLwb() !=
b.GetColLwb()) {
613 Error(
"AMultBt",
"A and B columns incompatible");
617 if (!constr && this->GetMatrixArray() ==
a.GetMatrixArray()) {
618 Error(
"AMultB",
"this = &a");
622 if (!constr && this->GetMatrixArray() ==
b.GetMatrixArray()) {
623 Error(
"AMultB",
"this = &b");
628 const Int_t *
const pRowIndexa =
a.GetRowIndexArray();
629 const Int_t *
const pColIndexa =
a.GetColIndexArray();
637 Int_t nr_nonzero_rowa = 0;
639 for (
Int_t irowa = 0; irowa <
a.GetNrows(); irowa++)
640 if (pRowIndexa[irowa] < pRowIndexa[irowa+1])
643 Int_t nr_nonzero_rowb =
b.GetNrows();
645 const Int_t nc = nr_nonzero_rowa*nr_nonzero_rowb;
646 Allocate(
a.GetNrows(),
b.GetNrows(),
a.GetRowLwb(),
b.GetRowLwb(),1,nc);
648 pRowIndexc = this->GetRowIndexArray();
649 pColIndexc = this->GetColIndexArray();
653 for (
Int_t irowa = 0; irowa <
a.GetNrows(); irowa++) {
654 pRowIndexc[irowa+1] = pRowIndexc[irowa];
655 for (
Int_t irowb = 0; irowb <
b.GetNrows(); irowb++) {
656 pRowIndexc[irowa+1]++;
657 pColIndexc[ielem++] = irowb;
661 pRowIndexc = this->GetRowIndexArray();
662 pColIndexc = this->GetColIndexArray();
665 const Element *
const pDataa =
a.GetMatrixArray();
666 const Element *
const pDatab =
b.GetMatrixArray();
667 Element *
const pDatac = this->GetMatrixArray();
669 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
670 const Int_t sIndexa = pRowIndexa[irowc];
671 const Int_t eIndexa = pRowIndexa[irowc+1];
672 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
673 const Int_t off = icolc*
b.GetNcols();
675 for (
Int_t indexa = sIndexa; indexa < eIndexa; indexa++) {
676 const Int_t icola = pColIndexa[indexa];
677 sum += pDataa[indexa]*pDatab[off+icola];
680 pColIndexc[indexc_r] = icolc;
681 pDatac[indexc_r] =
sum;
685 pRowIndexc[irowc+1]= indexc_r;
689 SetSparseIndex(indexc_r);
696template<
class Element>
703 if (
a.GetNcols() !=
b.GetNcols() ||
a.GetColLwb() !=
b.GetColLwb()) {
704 Error(
"AMultBt",
"A and B columns incompatible");
708 if (!constr && this->GetMatrixArray() ==
a.GetMatrixArray()) {
709 Error(
"AMultB",
"this = &a");
713 if (!constr && this->GetMatrixArray() ==
b.GetMatrixArray()) {
714 Error(
"AMultB",
"this = &b");
719 const Int_t *
const pRowIndexb =
b.GetRowIndexArray();
720 const Int_t *
const pColIndexb =
b.GetColIndexArray();
728 Int_t nr_nonzero_rowa =
a.GetNrows();
729 Int_t nr_nonzero_rowb = 0;
731 for (
Int_t irowb = 0; irowb <
b.GetNrows(); irowb++)
732 if (pRowIndexb[irowb] < pRowIndexb[irowb+1])
736 const Int_t nc = nr_nonzero_rowa*nr_nonzero_rowb;
737 Allocate(
a.GetNrows(),
b.GetNrows(),
a.GetRowLwb(),
b.GetRowLwb(),1,nc);
739 pRowIndexc = this->GetRowIndexArray();
740 pColIndexc = this->GetColIndexArray();
744 for (
Int_t irowa = 0; irowa <
a.GetNrows(); irowa++) {
745 pRowIndexc[irowa+1] = pRowIndexc[irowa];
746 for (
Int_t irowb = 0; irowb <
b.GetNrows(); irowb++) {
747 if (pRowIndexb[irowb] >= pRowIndexb[irowb+1])
continue;
748 pRowIndexc[irowa+1]++;
749 pColIndexc[ielem++] = irowb;
753 pRowIndexc = this->GetRowIndexArray();
754 pColIndexc = this->GetColIndexArray();
757 const Element *
const pDataa =
a.GetMatrixArray();
758 const Element *
const pDatab =
b.GetMatrixArray();
759 Element *
const pDatac = this->GetMatrixArray();
761 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
762 const Int_t off = irowc*
a.GetNcols();
763 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
764 const Int_t sIndexb = pRowIndexb[icolc];
765 const Int_t eIndexb = pRowIndexb[icolc+1];
767 for (
Int_t indexb = sIndexb; indexb < eIndexb; indexb++) {
768 const Int_t icolb = pColIndexb[indexb];
769 sum += pDataa[off+icolb]*pDatab[indexb];
772 pColIndexc[indexc_r] = icolc;
773 pDatac[indexc_r] =
sum;
777 pRowIndexc[irowc+1] = indexc_r;
781 SetSparseIndex(indexc_r);
788template<
class Element>
795 if (
a.GetNrows() !=
b.GetNrows() ||
a.GetNcols() !=
b.GetNcols() ||
796 a.GetRowLwb() !=
b.GetRowLwb() ||
a.GetColLwb() !=
b.GetColLwb()) {
797 Error(
"APlusB(const TMatrixTSparse &,const TMatrixTSparse &",
"matrices not compatible");
801 if (!constr && this->GetMatrixArray() ==
a.GetMatrixArray()) {
802 Error(
"APlusB",
"this = &a");
806 if (!constr && this->GetMatrixArray() ==
b.GetMatrixArray()) {
807 Error(
"APlusB",
"this = &b");
812 const Int_t *
const pRowIndexa =
a.GetRowIndexArray();
813 const Int_t *
const pRowIndexb =
b.GetRowIndexArray();
814 const Int_t *
const pColIndexa =
a.GetColIndexArray();
815 const Int_t *
const pColIndexb =
b.GetColIndexArray();
818 Allocate(
a.GetNrows(),
a.GetNcols(),
a.GetRowLwb(),
a.GetColLwb());
819 SetSparseIndexAB(
a,
b);
822 Int_t *
const pRowIndexc = this->GetRowIndexArray();
823 Int_t *
const pColIndexc = this->GetColIndexArray();
825 const Element *
const pDataa =
a.GetMatrixArray();
826 const Element *
const pDatab =
b.GetMatrixArray();
827 Element *
const pDatac = this->GetMatrixArray();
829 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
830 const Int_t sIndexa = pRowIndexa[irowc];
831 const Int_t eIndexa = pRowIndexa[irowc+1];
832 const Int_t sIndexb = pRowIndexb[irowc];
833 const Int_t eIndexb = pRowIndexb[irowc+1];
834 Int_t indexa = sIndexa;
835 Int_t indexb = sIndexb;
836 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
838 while (indexa < eIndexa && pColIndexa[indexa] <= icolc) {
839 if (icolc == pColIndexa[indexa]) {
840 sum += pDataa[indexa];
845 while (indexb < eIndexb && pColIndexb[indexb] <= icolc) {
846 if (icolc == pColIndexb[indexb]) {
847 sum += pDatab[indexb];
854 pColIndexc[indexc_r] = icolc;
855 pDatac[indexc_r] =
sum;
859 pRowIndexc[irowc+1] = indexc_r;
863 SetSparseIndex(indexc_r);
870template<
class Element>
877 if (
a.GetNrows() !=
b.GetNrows() ||
a.GetNcols() !=
b.GetNcols() ||
878 a.GetRowLwb() !=
b.GetRowLwb() ||
a.GetColLwb() !=
b.GetColLwb()) {
879 Error(
"APlusB(const TMatrixTSparse &,const TMatrixT &",
"matrices not compatible");
883 if (!constr && this->GetMatrixArray() ==
a.GetMatrixArray()) {
884 Error(
"APlusB",
"this = &a");
888 if (!constr && this->GetMatrixArray() ==
b.GetMatrixArray()) {
889 Error(
"APlusB",
"this = &b");
895 Allocate(
a.GetNrows(),
a.GetNcols(),
a.GetRowLwb(),
a.GetColLwb());
896 SetSparseIndexAB(
a,
b);
899 Int_t *
const pRowIndexc = this->GetRowIndexArray();
900 Int_t *
const pColIndexc = this->GetColIndexArray();
902 const Int_t *
const pRowIndexa =
a.GetRowIndexArray();
903 const Int_t *
const pColIndexa =
a.GetColIndexArray();
905 const Element *
const pDataa =
a.GetMatrixArray();
906 const Element *
const pDatab =
b.GetMatrixArray();
907 Element *
const pDatac = this->GetMatrixArray();
909 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
910 const Int_t sIndexa = pRowIndexa[irowc];
911 const Int_t eIndexa = pRowIndexa[irowc+1];
912 const Int_t off = irowc*this->GetNcols();
913 Int_t indexa = sIndexa;
914 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
915 Element
sum = pDatab[off+icolc];
916 while (indexa < eIndexa && pColIndexa[indexa] <= icolc) {
917 if (icolc == pColIndexa[indexa]) {
918 sum += pDataa[indexa];
925 pColIndexc[indexc_r] = icolc;
926 pDatac[indexc_r] =
sum;
930 pRowIndexc[irowc+1] = indexc_r;
934 SetSparseIndex(indexc_r);
941template<
class Element>
948 if (
a.GetNrows() !=
b.GetNrows() ||
a.GetNcols() !=
b.GetNcols() ||
949 a.GetRowLwb() !=
b.GetRowLwb() ||
a.GetColLwb() !=
b.GetColLwb()) {
950 Error(
"AMinusB(const TMatrixTSparse &,const TMatrixTSparse &",
"matrices not compatible");
954 if (!constr && this->GetMatrixArray() ==
a.GetMatrixArray()) {
955 Error(
"AMinusB",
"this = &a");
959 if (!constr && this->GetMatrixArray() ==
b.GetMatrixArray()) {
960 Error(
"AMinusB",
"this = &b");
965 const Int_t *
const pRowIndexa =
a.GetRowIndexArray();
966 const Int_t *
const pRowIndexb =
b.GetRowIndexArray();
967 const Int_t *
const pColIndexa =
a.GetColIndexArray();
968 const Int_t *
const pColIndexb =
b.GetColIndexArray();
971 Allocate(
a.GetNrows(),
a.GetNcols(),
a.GetRowLwb(),
a.GetColLwb());
972 SetSparseIndexAB(
a,
b);
975 Int_t *
const pRowIndexc = this->GetRowIndexArray();
976 Int_t *
const pColIndexc = this->GetColIndexArray();
978 const Element *
const pDataa =
a.GetMatrixArray();
979 const Element *
const pDatab =
b.GetMatrixArray();
980 Element *
const pDatac = this->GetMatrixArray();
982 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
983 const Int_t sIndexa = pRowIndexa[irowc];
984 const Int_t eIndexa = pRowIndexa[irowc+1];
985 const Int_t sIndexb = pRowIndexb[irowc];
986 const Int_t eIndexb = pRowIndexb[irowc+1];
987 Int_t indexa = sIndexa;
988 Int_t indexb = sIndexb;
989 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
991 while (indexa < eIndexa && pColIndexa[indexa] <= icolc) {
992 if (icolc == pColIndexa[indexa]) {
993 sum += pDataa[indexa];
998 while (indexb < eIndexb && pColIndexb[indexb] <= icolc) {
999 if (icolc == pColIndexb[indexb]) {
1000 sum -= pDatab[indexb];
1007 pColIndexc[indexc_r] = icolc;
1008 pDatac[indexc_r] =
sum;
1012 pRowIndexc[irowc+1] = indexc_r;
1016 SetSparseIndex(indexc_r);
1023template<
class Element>
1030 if (
a.GetNrows() !=
b.GetNrows() ||
a.GetNcols() !=
b.GetNcols() ||
1031 a.GetRowLwb() !=
b.GetRowLwb() ||
a.GetColLwb() !=
b.GetColLwb()) {
1032 Error(
"AMinusB(const TMatrixTSparse &,const TMatrixT &",
"matrices not compatible");
1036 if (!constr && this->GetMatrixArray() ==
a.GetMatrixArray()) {
1037 Error(
"AMinusB",
"this = &a");
1041 if (!constr && this->GetMatrixArray() ==
b.GetMatrixArray()) {
1042 Error(
"AMinusB",
"this = &b");
1048 Allocate(
a.GetNrows(),
a.GetNcols(),
a.GetRowLwb(),
a.GetColLwb());
1049 SetSparseIndexAB(
a,
b);
1052 Int_t *
const pRowIndexc = this->GetRowIndexArray();
1053 Int_t *
const pColIndexc = this->GetColIndexArray();
1055 const Int_t *
const pRowIndexa =
a.GetRowIndexArray();
1056 const Int_t *
const pColIndexa =
a.GetColIndexArray();
1058 const Element *
const pDataa =
a.GetMatrixArray();
1059 const Element *
const pDatab =
b.GetMatrixArray();
1060 Element *
const pDatac = this->GetMatrixArray();
1062 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
1063 const Int_t sIndexa = pRowIndexa[irowc];
1064 const Int_t eIndexa = pRowIndexa[irowc+1];
1065 const Int_t off = irowc*this->GetNcols();
1066 Int_t indexa = sIndexa;
1067 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
1068 Element
sum = -pDatab[off+icolc];
1069 while (indexa < eIndexa && pColIndexa[indexa] <= icolc) {
1070 if (icolc == pColIndexa[indexa]) {
1071 sum += pDataa[indexa];
1078 pColIndexc[indexc_r] = icolc;
1079 pDatac[indexc_r] =
sum;
1083 pRowIndexc[irowc+1] = indexc_r;
1087 SetSparseIndex(indexc_r);
1094template<
class Element>
1101 if (
a.GetNrows() !=
b.GetNrows() ||
a.GetNcols() !=
b.GetNcols() ||
1102 a.GetRowLwb() !=
b.GetRowLwb() ||
a.GetColLwb() !=
b.GetColLwb()) {
1103 Error(
"AMinusB(const TMatrixT &,const TMatrixTSparse &",
"matrices not compatible");
1107 if (!constr && this->GetMatrixArray() ==
a.GetMatrixArray()) {
1108 Error(
"AMinusB",
"this = &a");
1112 if (!constr && this->GetMatrixArray() ==
b.GetMatrixArray()) {
1113 Error(
"AMinusB",
"this = &b");
1119 Allocate(
a.GetNrows(),
a.GetNcols(),
a.GetRowLwb(),
a.GetColLwb());
1120 SetSparseIndexAB(
a,
b);
1123 Int_t *
const pRowIndexc = this->GetRowIndexArray();
1124 Int_t *
const pColIndexc = this->GetColIndexArray();
1126 const Int_t *
const pRowIndexb =
b.GetRowIndexArray();
1127 const Int_t *
const pColIndexb =
b.GetColIndexArray();
1129 const Element *
const pDataa =
a.GetMatrixArray();
1130 const Element *
const pDatab =
b.GetMatrixArray();
1131 Element *
const pDatac = this->GetMatrixArray();
1133 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
1134 const Int_t sIndexb = pRowIndexb[irowc];
1135 const Int_t eIndexb = pRowIndexb[irowc+1];
1136 const Int_t off = irowc*this->GetNcols();
1137 Int_t indexb = sIndexb;
1138 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
1139 Element
sum = pDataa[off+icolc];
1140 while (indexb < eIndexb && pColIndexb[indexb] <= icolc) {
1141 if (icolc == pColIndexb[indexb]) {
1142 sum -= pDatab[indexb];
1149 pColIndexc[indexc_r] = icolc;
1150 pDatac[indexc_r] =
sum;
1154 pRowIndexc[irowc+1] = indexc_r;
1158 SetSparseIndex(indexc_r);
1164template<
class Element>
1169 const Element *
const elem = GetMatrixArray();
1170 memcpy(
data,elem,this->fNelems*
sizeof(Element));
1178template<
class Element>
1183 Error(
"SetMatrixArray(Int_t,Int_t*,Int_t*,Element*",
"nr <= 0");
1192 R__ASSERT(row[irowmin] >= this->fRowLwb && row[irowmax] <= this->fRowLwb+this->fNrows-1);
1193 R__ASSERT(col[icolmin] >= this->fColLwb && col[icolmax] <= this->fColLwb+this->fNcols-1);
1195 if (row[irowmin] < this->fRowLwb|| row[irowmax] > this->fRowLwb+this->fNrows-1) {
1196 Error(
"SetMatrixArray",
"Inconsistency between row index and its range");
1197 if (row[irowmin] < this->fRowLwb) {
1198 Info(
"SetMatrixArray",
"row index lower bound adjusted to %d",row[irowmin]);
1199 this->fRowLwb = row[irowmin];
1201 if (row[irowmax] > this->fRowLwb+this->fNrows-1) {
1202 Info(
"SetMatrixArray",
"row index upper bound adjusted to %d",row[irowmax]);
1203 this->fNrows = row[irowmax]-this->fRowLwb+1;
1206 if (col[icolmin] < this->fColLwb || col[icolmax] > this->fColLwb+this->fNcols-1) {
1207 Error(
"SetMatrixArray",
"Inconsistency between column index and its range");
1208 if (col[icolmin] < this->fColLwb) {
1209 Info(
"SetMatrixArray",
"column index lower bound adjusted to %d",col[icolmin]);
1210 this->fColLwb = col[icolmin];
1212 if (col[icolmax] > this->fColLwb+this->fNcols-1) {
1213 Info(
"SetMatrixArray",
"column index upper bound adjusted to %d",col[icolmax]);
1214 this->fNcols = col[icolmax]-this->fColLwb+1;
1220 Int_t nr_nonzeros = 0;
1221 const Element *ep =
data;
1222 const Element *
const fp =
data+nr;
1225 if (*ep++ != 0.0) nr_nonzeros++;
1227 if (nr_nonzeros != this->fNelems) {
1228 if (fColIndex) {
delete [] fColIndex; fColIndex =
nullptr; }
1229 if (fElements) {
delete [] fElements; fElements =
nullptr; }
1230 this->fNelems = nr_nonzeros;
1231 if (this->fNelems > 0) {
1232 fColIndex =
new Int_t[nr_nonzeros];
1233 fElements =
new Element[nr_nonzeros];
1235 fColIndex =
nullptr;
1236 fElements =
nullptr;
1240 if (this->fNelems <= 0)
1246 for (
Int_t irow = 1; irow < this->fNrows+1; irow++) {
1247 if (ielem < nr && row[ielem] - this->fRowLwb < irow) {
1248 while (ielem < nr) {
1249 if (
data[ielem] != 0.0) {
1250 fColIndex[nr_nonzeros] = col[ielem]-this->fColLwb;
1251 fElements[nr_nonzeros] =
data[ielem];
1255 if (ielem >= nr || row[ielem] != row[ielem-1])
1259 fRowIndex[irow] = nr_nonzeros;
1265template <
class Element>
1271 Error(
"SetMatrixArray(Int_t,Int_t*,Int_t*,Element*",
"nr <= 0");
1275 if (nrows != this->fNrows) {
1278 fRowIndex =
nullptr;
1280 this->fNrows = nrows;
1281 if (this->fNrows > 0) {
1282 fRowIndex =
new Int_t[nrows + 1];
1283 this->fNrowIndex = nrows + 1;
1285 fRowIndex =
nullptr;
1286 this->fNrowIndex = 0;
1290 if (ncols != this->fNcols) {
1291 this->fNcols = ncols;
1294 if (this->fRowLwb != this->fColLwb) {
1295 auto tmp = this->fRowLwb;
1296 this->fRowLwb = this->fColLwb;
1297 this->fColLwb = tmp;
1305 R__ASSERT(row[irowmin] >= this->fRowLwb && row[irowmax] <= this->fRowLwb + this->fNrows - 1);
1306 R__ASSERT(col[icolmin] >= this->fColLwb && col[icolmax] <= this->fColLwb + this->fNcols - 1);
1308 if (row[irowmin] < this->fRowLwb || row[irowmax] > this->fRowLwb + this->fNrows - 1) {
1309 Error(
"SetMatrixArray",
"Inconsistency between row index and its range");
1310 if (row[irowmin] < this->fRowLwb) {
1311 Info(
"SetMatrixArray",
"row index lower bound adjusted to %d", row[irowmin]);
1312 this->fRowLwb = row[irowmin];
1314 if (row[irowmax] > this->fRowLwb + this->fNrows - 1) {
1315 Info(
"SetMatrixArray",
"row index upper bound adjusted to %d", row[irowmax]);
1316 this->fNrows = row[irowmax] - this->fRowLwb + 1;
1319 if (col[icolmin] < this->fColLwb || col[icolmax] > this->fColLwb + this->fNcols - 1) {
1320 Error(
"SetMatrixArray",
"Inconsistency between column index and its range");
1321 if (col[icolmin] < this->fColLwb) {
1322 Info(
"SetMatrixArray",
"column index lower bound adjusted to %d", col[icolmin]);
1323 this->fColLwb = col[icolmin];
1325 if (col[icolmax] > this->fColLwb + this->fNcols - 1) {
1326 Info(
"SetMatrixArray",
"column index upper bound adjusted to %d", col[icolmax]);
1327 this->fNcols = col[icolmax] - this->fColLwb + 1;
1333 Int_t nr_nonzeros = 0;
1334 const Element *ep =
data;
1335 const Element *
const fp =
data + nr;
1341 if (nr_nonzeros != this->fNelems) {
1344 fColIndex =
nullptr;
1348 fElements =
nullptr;
1350 this->fNelems = nr_nonzeros;
1351 if (this->fNelems > 0) {
1352 fColIndex =
new Int_t[nr_nonzeros];
1353 fElements =
new Element[nr_nonzeros];
1355 fColIndex =
nullptr;
1356 fElements =
nullptr;
1360 if (this->fNelems <= 0)
1366 for (
Int_t irow = 1; irow < this->fNrows + 1; irow++) {
1367 if (ielem < nr && row[ielem] - this->fRowLwb < irow) {
1368 while (ielem < nr) {
1369 if (
data[ielem] != 0.0) {
1370 fColIndex[nr_nonzeros] = col[ielem] - this->fColLwb;
1371 fElements[nr_nonzeros] =
data[ielem];
1375 if (ielem >= nr || row[ielem] != row[ielem - 1])
1379 fRowIndex[irow] = nr_nonzeros;
1388template<
class Element>
1391 if (nelems_new != this->fNelems) {
1393 Int_t *oIp = fColIndex;
1394 fColIndex =
new Int_t[nelems_new];
1396 memmove(fColIndex,oIp,nr*
sizeof(
Int_t));
1399 Element *oDp = fElements;
1400 fElements =
new Element[nelems_new];
1402 memmove(fElements,oDp,nr*
sizeof(Element));
1405 this->fNelems = nelems_new;
1406 if (nelems_new > nr) {
1407 memset(fElements+nr,0,(nelems_new-nr)*
sizeof(Element));
1408 memset(fColIndex+nr,0,(nelems_new-nr)*
sizeof(
Int_t));
1410 for (
Int_t irow = 0; irow < this->fNrowIndex; irow++)
1411 if (fRowIndex[irow] > nelems_new)
1412 fRowIndex[irow] = nelems_new;
1422template<
class Element>
1427 if (this->GetNrows() != source.
GetNrows() || this->GetNcols() != source.
GetNcols() ||
1428 this->GetRowLwb() != source.
GetRowLwb() || this->GetColLwb() != source.
GetColLwb()) {
1429 Error(
"SetSparseIndex",
"matrices not compatible");
1436 if (nr_nonzeros != this->fNelems)
1437 SetSparseIndex(nr_nonzeros);
1445 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
1446 fRowIndex[irow] = nr;
1447 for (
Int_t icol = 0; icol < this->fNcols; icol++) {
1449 fColIndex[nr] = icol;
1455 fRowIndex[this->fNrows] = nr;
1465template<
class Element>
1472 if (
a.GetNrows() !=
b.GetNrows() ||
a.GetNcols() !=
b.GetNcols() ||
1473 a.GetRowLwb() !=
b.GetRowLwb() ||
a.GetColLwb() !=
b.GetColLwb()) {
1474 Error(
"SetSparseIndexAB",
"source matrices not compatible");
1478 if (this->GetNrows() !=
a.GetNrows() || this->GetNcols() !=
a.GetNcols() ||
1479 this->GetRowLwb() !=
a.GetRowLwb() || this->GetColLwb() !=
a.GetColLwb()) {
1480 Error(
"SetSparseIndexAB",
"matrix not compatible with source matrices");
1485 const Int_t *
const pRowIndexa =
a.GetRowIndexArray();
1486 const Int_t *
const pRowIndexb =
b.GetRowIndexArray();
1487 const Int_t *
const pColIndexa =
a.GetColIndexArray();
1488 const Int_t *
const pColIndexb =
b.GetColIndexArray();
1492 for (
Int_t irowc = 0; irowc <
a.GetNrows(); irowc++) {
1493 const Int_t sIndexa = pRowIndexa[irowc];
1494 const Int_t eIndexa = pRowIndexa[irowc+1];
1495 const Int_t sIndexb = pRowIndexb[irowc];
1496 const Int_t eIndexb = pRowIndexb[irowc+1];
1497 nc += eIndexa-sIndexa;
1498 Int_t indexb = sIndexb;
1499 for (
Int_t indexa = sIndexa; indexa < eIndexa; indexa++) {
1500 const Int_t icola = pColIndexa[indexa];
1501 for (; indexb < eIndexb; indexb++) {
1502 if (pColIndexb[indexb] >= icola) {
1503 if (pColIndexb[indexb] == icola)
1510 while (indexb < eIndexb) {
1511 const Int_t icola = (eIndexa > sIndexa && eIndexa > 0) ? pColIndexa[eIndexa-1] : -1;
1512 if (pColIndexb[indexb++] > icola)
1518 if (this->NonZeros() != nc)
1521 Int_t *
const pRowIndexc = this->GetRowIndexArray();
1522 Int_t *
const pColIndexc = this->GetColIndexArray();
1526 for (
Int_t irowc = 0; irowc <
a.GetNrows(); irowc++) {
1527 const Int_t sIndexa = pRowIndexa[irowc];
1528 const Int_t eIndexa = pRowIndexa[irowc+1];
1529 const Int_t sIndexb = pRowIndexb[irowc];
1530 const Int_t eIndexb = pRowIndexb[irowc+1];
1531 Int_t indexb = sIndexb;
1532 for (
Int_t indexa = sIndexa; indexa < eIndexa; indexa++) {
1533 const Int_t icola = pColIndexa[indexa];
1534 for (; indexb < eIndexb; indexb++) {
1535 if (pColIndexb[indexb] >= icola) {
1536 if (pColIndexb[indexb] == icola)
1540 pColIndexc[nc++] = pColIndexb[indexb];
1542 pColIndexc[nc++] = pColIndexa[indexa];
1544 while (indexb < eIndexb) {
1545 const Int_t icola = (eIndexa > 0) ? pColIndexa[eIndexa-1] : -1;
1546 if (pColIndexb[indexb++] > icola)
1547 pColIndexc[nc++] = pColIndexb[indexb-1];
1549 pRowIndexc[irowc+1] = nc;
1559template<
class Element>
1566 if (
a.GetNrows() !=
b.GetNrows() ||
a.GetNcols() !=
b.GetNcols() ||
1567 a.GetRowLwb() !=
b.GetRowLwb() ||
a.GetColLwb() !=
b.GetColLwb()) {
1568 Error(
"SetSparseIndexAB",
"source matrices not compatible");
1572 if (this->GetNrows() !=
a.GetNrows() || this->GetNcols() !=
a.GetNcols() ||
1573 this->GetRowLwb() !=
a.GetRowLwb() || this->GetColLwb() !=
a.GetColLwb()) {
1574 Error(
"SetSparseIndexAB",
"matrix not compatible with source matrices");
1579 const Element *
const pDataa =
a.GetMatrixArray();
1581 const Int_t *
const pRowIndexb =
b.GetRowIndexArray();
1582 const Int_t *
const pColIndexb =
b.GetColIndexArray();
1586 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
1587 const Int_t sIndexb = pRowIndexb[irowc];
1588 const Int_t eIndexb = pRowIndexb[irowc+1];
1589 const Int_t off = irowc*this->GetNcols();
1590 Int_t indexb = sIndexb;
1591 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
1592 if (pDataa[off+icolc] != 0.0 || pColIndexb[indexb] > icolc)
continue;
1593 for (; indexb < eIndexb; indexb++) {
1594 if (pColIndexb[indexb] >= icolc) {
1595 if (pColIndexb[indexb] == icolc) {
1606 if (this->NonZeros() != nc)
1609 Int_t *
const pRowIndexc = this->GetRowIndexArray();
1610 Int_t *
const pColIndexc = this->GetColIndexArray();
1614 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
1615 const Int_t sIndexb = pRowIndexb[irowc];
1616 const Int_t eIndexb = pRowIndexb[irowc+1];
1617 const Int_t off = irowc*this->GetNcols();
1618 Int_t indexb = sIndexb;
1619 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
1620 if (pDataa[off+icolc] != 0.0)
1621 pColIndexc[nc++] = icolc;
1622 else if (pColIndexb[indexb] <= icolc) {
1623 for (; indexb < eIndexb; indexb++) {
1624 if (pColIndexb[indexb] >= icolc) {
1625 if (pColIndexb[indexb] == icolc)
1626 pColIndexc[nc++] = pColIndexb[indexb++];
1632 pRowIndexc[irowc+1] = nc;
1644template<
class Element>
1648 if (!this->fIsOwner) {
1649 Error(
"ResizeTo(Int_t,Int_t,Int_t)",
"Not owner of data array,cannot resize");
1653 if (this->fNelems > 0) {
1654 if (this->fNrows == nrows && this->fNcols == ncols &&
1655 (this->fNelems == nr_nonzeros || nr_nonzeros < 0))
1657 else if (nrows == 0 || ncols == 0 || nr_nonzeros == 0) {
1658 this->fNrows = nrows; this->fNcols = ncols;
1663 const Element *elements_old = GetMatrixArray();
1664 const Int_t *rowIndex_old = GetRowIndexArray();
1665 const Int_t *colIndex_old = GetColIndexArray();
1667 Int_t nrows_old = this->fNrows;
1668 Int_t nrowIndex_old = this->fNrowIndex;
1671 if (nr_nonzeros > 0)
1672 nelems_new = nr_nonzeros;
1675 for (
Int_t irow = 0; irow < nrows_old; irow++) {
1676 if (irow >= nrows)
continue;
1677 const Int_t sIndex = rowIndex_old[irow];
1678 const Int_t eIndex = rowIndex_old[irow+1];
1687 Allocate(nrows,ncols,0,0,1,nelems_new);
1690 Element *elements_new = GetMatrixArray();
1691 Int_t *rowIndex_new = GetRowIndexArray();
1692 Int_t *colIndex_new = GetColIndexArray();
1694 Int_t nelems_copy = 0;
1695 rowIndex_new[0] = 0;
1697 for (
Int_t irow = 0; irow < nrows_old && cont; irow++) {
1698 if (irow >= nrows)
continue;
1699 const Int_t sIndex = rowIndex_old[irow];
1700 const Int_t eIndex = rowIndex_old[irow+1];
1704 rowIndex_new[irow+1] = nelems_copy+1;
1705 colIndex_new[nelems_copy] = icol;
1706 elements_new[nelems_copy] = elements_old[
index];
1709 if (nelems_copy >= nelems_new) {
1716 if (rowIndex_old)
delete [] (
Int_t*) rowIndex_old;
1717 if (colIndex_old)
delete [] (
Int_t*) colIndex_old;
1718 if (elements_old)
delete [] (Element*) elements_old;
1720 if (nrowIndex_old < this->fNrowIndex) {
1721 for (
Int_t irow = nrowIndex_old; irow < this->fNrowIndex; irow++)
1722 rowIndex_new[irow] = rowIndex_new[nrowIndex_old-1];
1725 const Int_t nelems_new = (nr_nonzeros >= 0) ? nr_nonzeros : 0;
1726 Allocate(nrows,ncols,0,0,1,nelems_new);
1738template<
class Element>
1743 if (!this->fIsOwner) {
1744 Error(
"ResizeTo(Int_t,Int_t,Int_t,Int_t,Int_t)",
"Not owner of data array,cannot resize");
1748 const Int_t new_nrows = row_upb-row_lwb+1;
1749 const Int_t new_ncols = col_upb-col_lwb+1;
1751 if (this->fNelems > 0) {
1752 if (this->fNrows == new_nrows && this->fNcols == new_ncols &&
1753 this->fRowLwb == row_lwb && this->fColLwb == col_lwb &&
1754 (this->fNelems == nr_nonzeros || nr_nonzeros < 0))
1756 else if (new_nrows == 0 || new_ncols == 0 || nr_nonzeros == 0) {
1757 this->fNrows = new_nrows; this->fNcols = new_ncols;
1758 this->fRowLwb = row_lwb; this->fColLwb = col_lwb;
1763 const Int_t *rowIndex_old = GetRowIndexArray();
1764 const Int_t *colIndex_old = GetColIndexArray();
1765 const Element *elements_old = GetMatrixArray();
1767 const Int_t nrowIndex_old = this->fNrowIndex;
1769 const Int_t nrows_old = this->fNrows;
1770 const Int_t rowLwb_old = this->fRowLwb;
1771 const Int_t colLwb_old = this->fColLwb;
1774 if (nr_nonzeros > 0)
1775 nelems_new = nr_nonzeros;
1778 for (
Int_t irow = 0; irow < nrows_old; irow++) {
1779 if (irow+rowLwb_old > row_upb || irow+rowLwb_old < row_lwb)
continue;
1780 const Int_t sIndex = rowIndex_old[irow];
1781 const Int_t eIndex = rowIndex_old[irow+1];
1784 if (icol+colLwb_old <= col_upb && icol+colLwb_old >= col_lwb)
1790 Allocate(new_nrows,new_ncols,row_lwb,col_lwb,1,nelems_new);
1793 Int_t *rowIndex_new = GetRowIndexArray();
1794 Int_t *colIndex_new = GetColIndexArray();
1795 Element *elements_new = GetMatrixArray();
1797 Int_t nelems_copy = 0;
1798 rowIndex_new[0] = 0;
1799 const Int_t row_off = rowLwb_old-row_lwb;
1800 const Int_t col_off = colLwb_old-col_lwb;
1801 for (
Int_t irow = 0; irow < nrows_old; irow++) {
1802 if (irow+rowLwb_old > row_upb || irow+rowLwb_old < row_lwb)
continue;
1803 const Int_t sIndex = rowIndex_old[irow];
1804 const Int_t eIndex = rowIndex_old[irow+1];
1807 if (icol+colLwb_old <= col_upb && icol+colLwb_old >= col_lwb) {
1808 rowIndex_new[irow+row_off+1] = nelems_copy+1;
1809 colIndex_new[nelems_copy] = icol+col_off;
1810 elements_new[nelems_copy] = elements_old[
index];
1813 if (nelems_copy >= nelems_new) {
1819 if (rowIndex_old)
delete [] (
Int_t*) rowIndex_old;
1820 if (colIndex_old)
delete [] (
Int_t*) colIndex_old;
1821 if (elements_old)
delete [] (Element*) elements_old;
1823 if (nrowIndex_old < this->fNrowIndex) {
1824 for (
Int_t irow = nrowIndex_old; irow < this->fNrowIndex; irow++)
1825 rowIndex_new[irow] = rowIndex_new[nrowIndex_old-1];
1828 const Int_t nelems_new = (nr_nonzeros >= 0) ? nr_nonzeros : 0;
1829 Allocate(new_nrows,new_ncols,row_lwb,col_lwb,1,nelems_new);
1837template<
class Element>
1842 if (row_upb < row_lwb) {
1843 Error(
"Use",
"row_upb=%d < row_lwb=%d",row_upb,row_lwb);
1846 if (col_upb < col_lwb) {
1847 Error(
"Use",
"col_upb=%d < col_lwb=%d",col_upb,col_lwb);
1854 this->fNrows = row_upb-row_lwb+1;
1855 this->fNcols = col_upb-col_lwb+1;
1856 this->fRowLwb = row_lwb;
1857 this->fColLwb = col_lwb;
1858 this->fNrowIndex = this->fNrows+1;
1859 this->fNelems = nr_nonzeros;
1861 this->fTol = std::numeric_limits<Element>::epsilon();
1864 fRowIndex = pRowIndex;
1865 fColIndex = pColIndex;
1877template<
class Element>
1883 if (row_lwb < this->fRowLwb || row_lwb > this->fRowLwb+this->fNrows-1) {
1884 Error(
"GetSub",
"row_lwb out-of-bounds");
1887 if (col_lwb < this->fColLwb || col_lwb > this->fColLwb+this->fNcols-1) {
1888 Error(
"GetSub",
"col_lwb out-of-bounds");
1891 if (row_upb < this->fRowLwb || row_upb > this->fRowLwb+this->fNrows-1) {
1892 Error(
"GetSub",
"row_upb out-of-bounds");
1895 if (col_upb < this->fColLwb || col_upb > this->fColLwb+this->fNcols-1) {
1896 Error(
"GetSub",
"col_upb out-of-bounds");
1899 if (row_upb < row_lwb || col_upb < col_lwb) {
1900 Error(
"GetSub",
"row_upb < row_lwb || col_upb < col_lwb");
1909 const Int_t row_lwb_sub = (shift) ? 0 : row_lwb;
1910 const Int_t row_upb_sub = (shift) ? row_upb-row_lwb : row_upb;
1911 const Int_t col_lwb_sub = (shift) ? 0 : col_lwb;
1912 const Int_t col_upb_sub = (shift) ? col_upb-col_lwb : col_upb;
1914 Int_t nr_nonzeros = 0;
1915 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
1916 if (irow+this->fRowLwb > row_upb || irow+this->fRowLwb < row_lwb)
continue;
1917 const Int_t sIndex = fRowIndex[irow];
1918 const Int_t eIndex = fRowIndex[irow+1];
1921 if (icol+this->fColLwb <= col_upb && icol+this->fColLwb >= col_lwb)
1926 target.ResizeTo(row_lwb_sub,row_upb_sub,col_lwb_sub,col_upb_sub,nr_nonzeros);
1928 const Element *ep = this->GetMatrixArray();
1932 Element *ep_sub =
target.GetMatrixArray();
1934 if (
target.GetRowIndexArray() &&
target.GetColIndexArray()) {
1935 Int_t nelems_copy = 0;
1936 rowIndex_sub[0] = 0;
1937 const Int_t row_off = this->fRowLwb-row_lwb;
1938 const Int_t col_off = this->fColLwb-col_lwb;
1939 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
1940 if (irow+this->fRowLwb > row_upb || irow+this->fRowLwb < row_lwb)
continue;
1941 const Int_t sIndex = fRowIndex[irow];
1942 const Int_t eIndex = fRowIndex[irow+1];
1945 if (icol+this->fColLwb <= col_upb && icol+this->fColLwb >= col_lwb) {
1946 rowIndex_sub[irow+row_off+1] = nelems_copy+1;
1947 colIndex_sub[nelems_copy] = icol+col_off;
1948 ep_sub[nelems_copy] = ep[
index];
1954 const Int_t row_off = this->fRowLwb-row_lwb;
1955 const Int_t col_off = this->fColLwb-col_lwb;
1956 const Int_t ncols_sub = col_upb_sub-col_lwb_sub+1;
1957 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
1958 if (irow+this->fRowLwb > row_upb || irow+this->fRowLwb < row_lwb)
continue;
1959 const Int_t sIndex = fRowIndex[irow];
1960 const Int_t eIndex = fRowIndex[irow+1];
1961 const Int_t off = (irow+row_off)*ncols_sub;
1964 if (icol+this->fColLwb <= col_upb && icol+this->fColLwb >= col_lwb)
1965 ep_sub[off+icol+col_off] = ep[
index];
1977template<
class Element>
1984 if (row_lwb < this->fRowLwb || row_lwb > this->fRowLwb+this->fNrows-1) {
1985 Error(
"SetSub",
"row_lwb out-of-bounds");
1988 if (col_lwb < this->fColLwb || col_lwb > this->fColLwb+this->fNcols-1) {
1989 Error(
"SetSub",
"col_lwb out-of-bounds");
1992 if (row_lwb+source.
GetNrows() > this->fRowLwb+this->fNrows || col_lwb+source.
GetNcols() > this->fColLwb+this->fNcols) {
1993 Error(
"SetSub",
"source matrix too large");
2003 Int_t nr_nonzeros = 0;
2004 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
2005 if (irow+this->fRowLwb >= row_lwb+nRows_source || irow+this->fRowLwb < row_lwb)
continue;
2006 const Int_t sIndex = fRowIndex[irow];
2007 const Int_t eIndex = fRowIndex[irow+1];
2010 if (icol+this->fColLwb < col_lwb+nCols_source && icol+this->fColLwb >= col_lwb)
2019 const Int_t nelems_old = this->fNelems;
2020 const Int_t *rowIndex_old = GetRowIndexArray();
2021 const Int_t *colIndex_old = GetColIndexArray();
2022 const Element *elements_old = GetMatrixArray();
2024 const Int_t nelems_new = nelems_old+source.
NonZeros()-nr_nonzeros;
2025 fRowIndex =
new Int_t[this->fNrowIndex];
2026 fColIndex =
new Int_t[nelems_new];
2027 fElements =
new Element[nelems_new];
2028 this->fNelems = nelems_new;
2030 Int_t *rowIndex_new = GetRowIndexArray();
2031 Int_t *colIndex_new = GetColIndexArray();
2032 Element *elements_new = GetMatrixArray();
2034 const Int_t row_off = row_lwb-this->fRowLwb;
2035 const Int_t col_off = col_lwb-this->fColLwb;
2038 rowIndex_new[0] = 0;
2039 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
2040 rowIndex_new[irow+1] = rowIndex_new[irow];
2042 if (irow+this->fRowLwb < row_lwb+nRows_source && irow+this->fRowLwb >= row_lwb)
2045 const Int_t sIndex_o = rowIndex_old[irow];
2046 const Int_t eIndex_o = rowIndex_old[irow+1];
2049 const Int_t icol_left = col_off-1;
2052 rowIndex_new[irow+1]++;
2053 colIndex_new[nr] = colIndex_old[
index];
2054 elements_new[nr] = elements_old[
index];
2058 if (rowIndex_s && colIndex_s) {
2059 const Int_t sIndex_s = rowIndex_s[irow-row_off];
2060 const Int_t eIndex_s = rowIndex_s[irow-row_off+1];
2062 rowIndex_new[irow+1]++;
2063 colIndex_new[nr] = colIndex_s[
index]+col_off;
2064 elements_new[nr] = elements_s[
index];
2068 const Int_t off = (irow-row_off)*nCols_source;
2069 for (
Int_t icol = 0; icol < nCols_source; icol++) {
2070 rowIndex_new[irow+1]++;
2071 colIndex_new[nr] = icol+col_off;
2072 elements_new[nr] = elements_s[off+icol];
2077 const Int_t icol_right = col_off+nCols_source-1;
2080 while (right < eIndex_o-1 && colIndex_old[right+1] <= icol_right)
2085 rowIndex_new[irow+1]++;
2086 colIndex_new[nr] = colIndex_old[
index];
2087 elements_new[nr] = elements_old[
index];
2093 rowIndex_new[irow+1]++;
2094 colIndex_new[nr] = colIndex_old[
index];
2095 elements_new[nr] = elements_old[
index];
2101 R__ASSERT(this->fNelems == fRowIndex[this->fNrowIndex-1]);
2103 if (rowIndex_old)
delete [] (
Int_t*) rowIndex_old;
2104 if (colIndex_old)
delete [] (
Int_t*) colIndex_old;
2105 if (elements_old)
delete [] (Element*) elements_old;
2113template<
class Element>
2132 Element *pData_t =
new Element[nr_nonzeros];
2135 for (
Int_t irow_s = 0; irow_s < source.
GetNrows(); irow_s++) {
2136 const Int_t sIndex = pRowIndex_s[irow_s];
2137 const Int_t eIndex = pRowIndex_s[irow_s+1];
2139 rownr[ielem] = pColIndex_s[
index]+this->fRowLwb;
2140 colnr[ielem] = irow_s+this->fColLwb;
2141 pData_t[ielem] = pData_s[
index];
2149 SetMatrixArray(nr_nonzeros, source.
GetNcols(), source.
GetNrows(), rownr, colnr, pData_t);
2151 SetMatrixArray(nr_nonzeros, rownr, colnr, pData_t);
2154 R__ASSERT(this->fNelems == fRowIndex[this->fNrowIndex-1]);
2156 if (pData_t)
delete [] pData_t;
2157 if (rownr)
delete [] rownr;
2158 if (colnr)
delete [] colnr;
2165template<
class Element>
2170 if (fElements) {
delete [] fElements; fElements =
nullptr; }
2171 if (fColIndex) {
delete [] fColIndex; fColIndex =
nullptr; }
2173 memset(this->GetRowIndexArray(),0,this->fNrowIndex*
sizeof(
Int_t));
2181template<
class Element>
2188 Int_t nr_nonzeros = 0;
2189 for (i = this->fRowLwb; i <= this->fRowLwb+this->fNrows-1; i++)
2190 for (
Int_t j = this->fColLwb; j <= this->fColLwb+this->fNcols-1; j++)
2191 if (i == j) nr_nonzeros++;
2193 if (nr_nonzeros != this->fNelems) {
2194 this->fNelems = nr_nonzeros;
2195 Int_t *oIp = fColIndex;
2196 fColIndex =
new Int_t[nr_nonzeros];
2197 if (oIp)
delete [] oIp;
2198 Element *oDp = fElements;
2199 fElements =
new Element[nr_nonzeros];
2200 if (oDp)
delete [] oDp;
2205 for (i = this->fRowLwb; i <= this->fRowLwb+this->fNrows-1; i++) {
2206 for (
Int_t j = this->fColLwb; j <= this->fColLwb+this->fNcols-1; j++) {
2208 const Int_t irow = i-this->fRowLwb;
2209 fRowIndex[irow+1] = ielem+1;
2210 fElements[ielem] = 1.0;
2211 fColIndex[ielem++] = j-this->fColLwb;
2223template<
class Element>
2228 const Element * ep = GetMatrixArray();
2229 const Element *
const fp = ep+this->fNelems;
2230 const Int_t *
const pR = GetRowIndexArray();
2234 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
2235 const Int_t sIndex = pR[irow];
2236 const Int_t eIndex = pR[irow+1];
2252template<
class Element>
2260 const Element *
const fp = ep+this->fNcols;
2267 for (
Int_t i = 0; i < this->fNrows; i++,ep += this->fNcols)
2269 ep -= this->fNelems-1;
2280template<
class Element>
2285 const Int_t arown = rown-this->fRowLwb;
2286 const Int_t acoln = coln-this->fColLwb;
2287 if (arown >= this->fNrows || arown < 0) {
2288 Error(
"operator()",
"Request row(%d) outside matrix range of %d - %d",rown,this->fRowLwb,this->fRowLwb+this->fNrows);
2289 return fElements[0];
2291 if (acoln >= this->fNcols || acoln < 0) {
2292 Error(
"operator()",
"Request column(%d) outside matrix range of %d - %d",coln,this->fColLwb,this->fColLwb+this->fNcols);
2293 return fElements[0];
2299 if (this->fNrowIndex > 0 && fRowIndex[this->fNrowIndex-1] != 0) {
2300 sIndex = fRowIndex[arown];
2301 eIndex = fRowIndex[arown+1];
2305 if (
index >= sIndex && fColIndex[
index] == acoln)
2306 return fElements[
index];
2309 InsertRow(rown,coln,&val,1);
2310 sIndex = fRowIndex[arown];
2311 eIndex = fRowIndex[arown+1];
2313 if (
index >= sIndex && fColIndex[
index] == acoln)
2314 return fElements[
index];
2316 Error(
"operator()(Int_t,Int_t",
"Insert row failed");
2317 return fElements[0];
2324template <
class Element>
2328 if (this->fNrowIndex > 0 && this->fRowIndex[this->fNrowIndex-1] == 0) {
2329 Error(
"operator()(Int_t,Int_t) const",
"row/col indices are not set");
2330 Info(
"operator()",
"fNrowIndex = %d fRowIndex[fNrowIndex-1] = %d\n",this->fNrowIndex,this->fRowIndex[this->fNrowIndex-1]);
2333 const Int_t arown = rown-this->fRowLwb;
2334 const Int_t acoln = coln-this->fColLwb;
2336 if (arown >= this->fNrows || arown < 0) {
2337 Error(
"operator()",
"Request row(%d) outside matrix range of %d - %d",rown,this->fRowLwb,this->fRowLwb+this->fNrows);
2340 if (acoln >= this->fNcols || acoln < 0) {
2341 Error(
"operator()",
"Request column(%d) outside matrix range of %d - %d",coln,this->fColLwb,this->fColLwb+this->fNcols);
2345 const Int_t sIndex = fRowIndex[arown];
2346 const Int_t eIndex = fRowIndex[arown+1];
2348 if (
index < sIndex || fColIndex[
index] != acoln)
return 0.0;
2349 else return fElements[
index];
2356template<
class Element>
2360 Error(
"operator=(const TMatrixTSparse &)",
"matrices not compatible");
2368 Element *
const tp = this->GetMatrixArray();
2369 memcpy(tp,sp,this->fNelems*
sizeof(Element));
2370 this->fTol = source.
GetTol();
2379template<
class Element>
2383 Error(
"operator=(const TMatrixT &)",
"matrices not compatible");
2391 Element *
const tp = this->GetMatrixArray();
2392 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
2393 const Int_t sIndex = fRowIndex[irow];
2394 const Int_t eIndex = fRowIndex[irow+1];
2395 const Int_t off = irow*this->fNcols;
2398 tp[
index] = sp[off+icol];
2401 this->fTol = source.
GetTol();
2410template<
class Element>
2415 if (fRowIndex[this->fNrowIndex-1] == 0) {
2416 Error(
"operator=(Element",
"row/col indices are not set");
2420 Element *ep = this->GetMatrixArray();
2421 const Element *
const ep_last = ep+this->fNelems;
2422 while (ep < ep_last)
2431template<
class Element>
2436 Element *ep = this->GetMatrixArray();
2437 const Element *
const ep_last = ep+this->fNelems;
2438 while (ep < ep_last)
2447template<
class Element>
2452 Element *ep = this->GetMatrixArray();
2453 const Element *
const ep_last = ep+this->fNelems;
2454 while (ep < ep_last)
2463template<
class Element>
2468 Element *ep = this->GetMatrixArray();
2469 const Element *
const ep_last = ep+this->fNelems;
2470 while (ep < ep_last)
2479template<
class Element>
2484 const Element scale = beta-alpha;
2485 const Element shift = alpha/scale;
2487 Int_t *
const pRowIndex = GetRowIndexArray();
2488 Int_t *
const pColIndex = GetColIndexArray();
2489 Element *
const ep = GetMatrixArray();
2491 const Int_t m = this->GetNrows();
2492 const Int_t n = this->GetNcols();
2495 const Int_t nn = this->GetNrows()*this->GetNcols();
2496 const Int_t length = (this->GetNoElements() <= nn) ? this->GetNoElements() : nn;
2500 for (
Int_t k = 0; k < nn; k++) {
2501 const Element
r =
Drand(seed);
2503 if ((nn-k)*
r <
length-chosen) {
2504 pColIndex[chosen] = k%
n;
2507 if (irow > icurrent) {
2508 for ( ; icurrent < irow; icurrent++)
2509 pRowIndex[icurrent+1] = chosen;
2511 ep[chosen] = scale*(
Drand(seed)+shift);
2515 for ( ; icurrent <
m; icurrent++)
2516 pRowIndex[icurrent+1] =
length;
2526template<
class Element>
2529 const Element scale = beta-alpha;
2530 const Element shift = alpha/scale;
2535 if (this->fNrows != this->fNcols || this->fRowLwb != this->fColLwb) {
2536 Error(
"RandomizePD(Element &",
"matrix should be square");
2541 const Int_t n = this->fNcols;
2543 Int_t *
const pRowIndex = this->GetRowIndexArray();
2544 Int_t *
const pColIndex = this->GetColIndexArray();
2545 Element *
const ep = GetMatrixArray();
2552 ep[0] = 1
e-8+scale*(
Drand(seed)+shift);
2572 for (
Int_t k = 0; k < nn; k++ ) {
2573 const Element
r =
Drand(seed);
2575 if( (nn-k)*
r <
length-chosen) {
2582 Int_t col = k-row*(row+1)/2;
2587 if (row > icurrent) {
2591 for ( ; icurrent < row; icurrent++) {
2594 for (
Int_t ll = pRowIndex[icurrent]; ll < nnz; ll++)
2596 ep[nnz] += 1
e-8+scale*(
Drand(seed)+shift);
2597 pColIndex[nnz] = icurrent;
2600 pRowIndex[icurrent+1] = nnz;
2603 ep[nnz] = scale*(
Drand(seed)+shift);
2604 pColIndex[nnz] = col;
2607 ep[pRowIndex[col+1]-1] +=
TMath::Abs(ep[nnz]);
2617 for ( ; icurrent <
n; icurrent++) {
2620 for(
Int_t ll = pRowIndex[icurrent]; ll < nnz; ll++)
2622 ep[nnz] += 1
e-8+scale*(
Drand(seed)+shift);
2623 pColIndex[nnz] = icurrent;
2626 pRowIndex[icurrent+1] = nnz;
2628 this->fNelems = nnz;
2636 const Int_t *
const pR = this->GetRowIndexArray();
2637 const Int_t *
const pC = this->GetColIndexArray();
2638 Element *
const pD = GetMatrixArray();
2639 for (
Int_t irow = 0; irow < this->fNrows+1; irow++) {
2640 const Int_t sIndex = pR[irow];
2641 const Int_t eIndex = pR[irow+1];
2655template<
class Element>
2664template<
class Element>
2673template<
class Element>
2682template<
class Element>
2692template<
class Element>
2702template<
class Element>
2711template<
class Element>
2720template<
class Element>
2729template<
class Element>
2739template<
class Element>
2749template<
class Element>
2758template<
class Element>
2767template<
class Element>
2776template<
class Element>
2786template<
class Element>
2797template<
class Element>
2800 target += scalar * source;
2807template<
class Element>
2811 ::Error(
"ElementMult(TMatrixTSparse &,const TMatrixTSparse &)",
"matrices not compatible");
2816 Element *tp =
target.GetMatrixArray();
2817 const Element *ftp = tp+
target.GetNoElements();
2827template<
class Element>
2831 ::Error(
"ElementDiv(TMatrixT &,const TMatrixT &)",
"matrices not compatible");
2836 Element *tp =
target.GetMatrixArray();
2837 const Element *ftp = tp+
target.GetNoElements();
2838 while ( tp < ftp ) {
2842 Error(
"ElementDiv",
"source element is zero");
2852template<
class Element>
2857 ::Error(
"AreCompatible",
"matrix 1 not valid");
2862 ::Error(
"AreCompatible",
"matrix 2 not valid");
2869 ::Error(
"AreCompatible",
"matrices 1 and 2 not compatible");
2876 if (memcmp(pR1,pR2,(nRows+1)*
sizeof(
Int_t))) {
2878 ::Error(
"AreCompatible",
"matrices 1 and 2 have different rowIndex");
2879 for (
Int_t i = 0; i < nRows+1; i++)
2880 printf(
"%d: %d %d\n",i,pR1[i],pR2[i]);
2886 if (memcmp(pD1,pD2,nData*
sizeof(
Int_t))) {
2888 ::Error(
"AreCompatible",
"matrices 1 and 2 have different colIndex");
2889 for (
Int_t i = 0; i < nData; i++)
2890 printf(
"%d: %d %d\n",i,pD1[i],pD2[i]);
2900template<
class Element>
2908 if (this->fNelems < 0)
#define templateClassImp(name)
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
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 Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
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 r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
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 length
R__EXTERN Int_t gMatrixCheck
TMatrixTSparse< Element > & ElementDiv(TMatrixTSparse< Element > &target, const TMatrixTSparse< Element > &source)
Divide target by the source, element-by-element.
template TMatrixFSparse & ElementDiv< Float_t >(TMatrixFSparse &target, const TMatrixFSparse &source)
template TMatrixDSparse & Add< Double_t >(TMatrixDSparse &target, Double_t scalar, const TMatrixDSparse &source)
template Bool_t AreCompatible< Float_t >(const TMatrixFSparse &m1, const TMatrixFSparse &m2, Int_t verbose)
Bool_t AreCompatible(const TMatrixTSparse< Element > &m1, const TMatrixTSparse< Element > &m2, Int_t verbose)
template TMatrixDSparse & ElementDiv< Double_t >(TMatrixDSparse &target, const TMatrixDSparse &source)
TMatrixTSparse< Element > operator*(const TMatrixTSparse< Element > &source1, const TMatrixTSparse< Element > &source2)
TMatrixTSparse< Element > operator-(const TMatrixTSparse< Element > &source1, const TMatrixTSparse< Element > &source2)
TMatrixTSparse< Element > & Add(TMatrixTSparse< Element > &target, Element scalar, const TMatrixTSparse< Element > &source)
Modify addition: target += scalar * source.
template TMatrixFSparse & ElementMult< Float_t >(TMatrixFSparse &target, const TMatrixFSparse &source)
TMatrixTSparse< Element > operator+(const TMatrixTSparse< Element > &source1, const TMatrixTSparse< Element > &source2)
template Bool_t AreCompatible< Double_t >(const TMatrixDSparse &m1, const TMatrixDSparse &m2, Int_t verbose)
TMatrixTSparse< Element > & ElementMult(TMatrixTSparse< Element > &target, const TMatrixTSparse< Element > &source)
Multiply target by the source, element-by-element.
template TMatrixDSparse & ElementMult< Double_t >(TMatrixDSparse &target, const TMatrixDSparse &source)
template TMatrixFSparse & Add< Float_t >(TMatrixFSparse &target, Float_t scalar, const TMatrixFSparse &source)
Double_t Drand(Double_t &ix)
Random number generator [0....1] with seed ix.
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 const Element * GetMatrixArray() const =0
virtual const Int_t * GetRowIndexArray() const =0
virtual Int_t NonZeros() const
Compute the number of elements != 0.0.
virtual const Int_t * GetColIndexArray() const =0
Int_t GetNoElements() const
static void DoubleLexSort(Int_t n, Int_t *first, Int_t *second, Element *data)
default kTRUE, when Use array kFALSE
TMatrixTBase< Element > & Randomize(Element alpha, Element beta, Double_t &seed) override
randomize matrix element values
TMatrixTBase< Element > & SetMatrixArray(const Element *data, Option_t *="") override
Copy array data to matrix .
TMatrixTBase< Element > & GetSub(Int_t row_lwb, Int_t row_upb, Int_t col_lwb, Int_t col_upb, TMatrixTBase< Element > &target, Option_t *option="S") const override
Get submatrix [row_lwb..row_upb][col_lwb..col_upb]; The indexing range of the returned matrix depends...
TMatrixTSparse< Element > & operator+=(Element val)
Add val to every element of the matrix.
TMatrixTSparse< Element > & SetSparseIndex(Int_t nelem_new)
Increase/decrease the number of non-zero elements to nelems_new.
TMatrixTSparse< Element > & Use(Int_t row_lwb, Int_t row_upb, Int_t col_lwb, Int_t col_upb, Int_t nr_nonzeros, Int_t *pRowIndex, Int_t *pColIndex, Element *pData)
TMatrixTBase< Element > & InsertRow(Int_t row, Int_t col, const Element *v, Int_t n=-1) override
Insert in row rown, n elements of array v at column coln.
Element ColNorm() const override
Column matrix norm, MAX{ SUM{ |M(i,j)|, over i}, over j}.
void Streamer(TBuffer &) override
Stream an object of class TMatrixTSparse.
const Int_t * GetRowIndexArray() const override
void AMinusB(const TMatrixTSparse< Element > &a, const TMatrixTSparse< Element > &b, Int_t constr=0)
General matrix subtraction.
TMatrixTSparse< Element > & operator*=(Element val)
Multiply every element of the matrix with val.
void AMultBt(const TMatrixTSparse< Element > &a, const TMatrixTSparse< Element > &b, Int_t constr=0)
General matrix multiplication.
void GetMatrix2Array(Element *data, Option_t *="") const override
Copy matrix data to array . It is assumed that array is of size >= fNelems.
TMatrixTSparse< Element > & Transpose(const TMatrixTSparse< Element > &source)
Transpose a matrix. Set the matrix to ncols x nrows if nrows != ncols.
TMatrixTSparse< Element > & operator-=(Element val)
Subtract val from every element of the matrix.
Int_t NonZeros() const override
Compute the number of elements != 0.0.
TMatrixTBase< Element > & SetSub(Int_t row_lwb, Int_t col_lwb, const TMatrixTBase< Element > &source) override
Insert matrix source starting at [row_lwb][col_lwb], thereby overwriting the part [row_lwb....
void Allocate(Int_t nrows, Int_t ncols, Int_t row_lwb=0, Int_t col_lwb=0, Int_t init=0, Int_t nr_nonzeros=0)
Allocate new matrix.
TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t nr_nonzeros=-1) override
Set size of the matrix to nrows x ncols with nr_nonzeros non-zero entries if nr_nonzeros > 0 .
void APlusB(const TMatrixTSparse< Element > &a, const TMatrixTSparse< Element > &b, Int_t constr=0)
General matrix addition.
virtual TMatrixTSparse< Element > & RandomizePD(Element alpha, Element beta, Double_t &seed)
randomize matrix element values but keep matrix symmetric positive definite
TMatrixTBase< Element > & Zero() override
Set matrix elements to zero.
TMatrixTSparse< Element > & operator=(const TMatrixT< Element > &source)
Notice that the sparsity of the matrix is NOT changed : its fRowIndex/fColIndex are used !
const Int_t * GetColIndexArray() const override
Element operator()(Int_t rown, Int_t coln) const override
void ExtractRow(Int_t row, Int_t col, Element *v, Int_t n=-1) const override
Store in array v, n matrix elements of row rown starting at column coln.
TMatrixTBase< Element > & UnitMatrix() override
Make a unit matrix (matrix need not be a square one).
Element RowNorm() const override
Row matrix norm, MAX{ SUM{ |M(i,j)|, over j}, over i}.
TMatrixTSparse< Element > & SetSparseIndexAB(const TMatrixTSparse< Element > &a, const TMatrixTSparse< Element > &b)
Set the row/column indices to the "sum" of matrices a and b It is checked that enough space has been ...
const Element * GetMatrixArray() const override
const Element * GetMatrixArray() const override
TObject & operator=(const TObject &rhs)
TObject assignment operator.
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.
Double_t Floor(Double_t x)
Rounds x downward, returning the largest integral value that is not greater than x.
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.
Long64_t BinarySearch(Long64_t n, const T *array, T value)
Binary search in an array of n values to locate value.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
void AMultBt(const Element *const ap, Int_t na, Int_t ncolsa, const Element *const bp, Int_t nb, Int_t ncolsb, Element *cp)
Elementary routine to calculate matrix multiplication A*B^T.
void AMultB(const Element *const ap, Int_t na, Int_t ncolsa, const Element *const bp, Int_t nb, Int_t ncolsb, Element *cp)
Elementary routine to calculate matrix multiplication A*B.
static uint64_t sum(uint64_t i)