106template<
class Element>
109 Allocate(no_rows,no_cols,0,0,1);
116template <
class Element>
119 Allocate(row_upb - row_lwb + 1, col_upb - col_lwb + 1, row_lwb, col_lwb, 1, nr_nonzeros);
129template<
class Element>
138 if (row[irowmin] < row_lwb || row[irowmax] > row_upb) {
139 Error(
"TMatrixTSparse",
"Inconsistency between row index and its range");
140 if (row[irowmin] < row_lwb) {
141 Info(
"TMatrixTSparse",
"row index lower bound adjusted to %d",row[irowmin]);
142 row_lwb = row[irowmin];
144 if (row[irowmax] > row_upb) {
145 Info(
"TMatrixTSparse",
"row index upper bound adjusted to %d",row[irowmax]);
146 col_lwb = col[irowmax];
149 if (col[icolmin] < col_lwb || col[icolmax] > col_upb) {
150 Error(
"TMatrixTSparse",
"Inconsistency between column index and its range");
151 if (col[icolmin] < col_lwb) {
152 Info(
"TMatrixTSparse",
"column index lower bound adjusted to %d",col[icolmin]);
153 col_lwb = col[icolmin];
155 if (col[icolmax] > col_upb) {
156 Info(
"TMatrixTSparse",
"column index upper bound adjusted to %d",col[icolmax]);
157 col_upb = col[icolmax];
161 Allocate(row_upb-row_lwb+1,col_upb-col_lwb+1,row_lwb,col_lwb,1,nr);
163 SetMatrixArray(nr,row,col,
data);
173template <
class Element>
179 if (
n <= 0 || nr < 0) {
180 Error(
"TMatrixTSparse",
"Inconsistency in row indices");
183 Allocate(row_upb - row_lwb + 1, col_upb - col_lwb + 1, row_lwb, col_lwb, 1, nr);
189 if (col[icolmin] < col_lwb || col[icolmax] > col_upb) {
190 Error(
"TMatrixTSparse",
"Inconsistency between column index and its range");
191 if (col[icolmin] < col_lwb) {
192 Info(
"TMatrixTSparse",
"column index lower bound adjusted to %d", col[icolmin]);
193 col_lwb = col[icolmin];
195 if (col[icolmax] > col_upb) {
196 Info(
"TMatrixTSparse",
"column index upper bound adjusted to %d", col[icolmax]);
197 col_upb = col[icolmax];
201 Allocate(row_upb - row_lwb + 1, col_upb - col_lwb + 1, row_lwb, col_lwb, 1, nr);
202 memcpy(fElements,
data, this->fNelems *
sizeof(Element));
203 memcpy(fRowIndex, rowptr, this->fNrowIndex *
sizeof(
Int_t));
204 memcpy(fColIndex, col, this->fNelems *
sizeof(
Int_t));
210template<
class Element>
223template<
class Element>
236template<
class Element>
241 Int_t nr_nonzeros = 0;
256 for (
Int_t i = rowLwb; i <= rowLwb+nrows-1; i++)
257 for (
Int_t j = colLwb; j <= colLwb+ncols-1; j++)
258 if (i==j) nr_nonzeros++;
259 Allocate(nrows,ncols,rowLwb,colLwb,1,nr_nonzeros);
267 Transpose(prototype);
278 Error(
"TMatrixTSparse(EMatrixCreatorOp1)",
"operation %d not yet implemented", op);
286template<
class Element>
310 Error(
"TMatrixTSparse(EMatrixCreatorOp2)",
"operation %d not yet implemented",op);
318template<
class Element>
342 Error(
"TMatrixTSparse(EMatrixCreatorOp2)",
"operation %d not yet implemented",op);
350template<
class Element>
374 Error(
"TMatrixTSparse(EMatrixCreatorOp2)",
"operation %d not yet implemented",op);
383template<
class Element>
387 if ( (nr_nonzeros > 0 && (no_rows == 0 || no_cols == 0)) ||
388 (no_rows < 0 || no_cols < 0 || nr_nonzeros < 0) )
390 Error(
"Allocate",
"no_rows=%d no_cols=%d non_zeros=%d",no_rows,no_cols,nr_nonzeros);
396 this->fNrows = no_rows;
397 this->fNcols = no_cols;
398 this->fRowLwb = row_lwb;
399 this->fColLwb = col_lwb;
400 this->fNrowIndex = this->fNrows+1;
401 this->fNelems = nr_nonzeros;
402 this->fIsOwner =
kTRUE;
403 this->fTol = std::numeric_limits<Element>::epsilon();
405 fRowIndex =
new Int_t[this->fNrowIndex];
407 memset(fRowIndex,0,this->fNrowIndex*
sizeof(
Int_t));
409 if (this->fNelems > 0) {
410 fElements =
new Element[this->fNelems];
411 fColIndex =
new Int_t [this->fNelems];
413 memset(fElements,0,this->fNelems*
sizeof(Element));
414 memset(fColIndex,0,this->fNelems*
sizeof(
Int_t));
425template<
class Element>
428 const Int_t arown = rown-this->fRowLwb;
429 const Int_t acoln = coln-this->fColLwb;
430 const Int_t nr = (
n > 0) ?
n : this->fNcols;
433 if (arown >= this->fNrows || arown < 0) {
434 Error(
"InsertRow",
"row %d out of matrix range",rown);
438 if (acoln >= this->fNcols || acoln < 0) {
439 Error(
"InsertRow",
"column %d out of matrix range",coln);
443 if (acoln+nr > this->fNcols || nr < 0) {
444 Error(
"InsertRow",
"row length %d out of range",nr);
449 const Int_t sIndex = fRowIndex[arown];
450 const Int_t eIndex = fRowIndex[arown+1];
457 Int_t lIndex = sIndex-1;
458 Int_t rIndex = sIndex-1;
463 if (icol >= acoln+nr)
break;
464 if (icol >= acoln) nslots++;
468 const Int_t nelems_old = this->fNelems;
469 const Int_t *colIndex_old = fColIndex;
470 const Element *elements_old = fElements;
472 const Int_t ndiff = nr-nslots;
473 this->fNelems += ndiff;
474 fColIndex =
new Int_t[this->fNelems];
475 fElements =
new Element[this->fNelems];
477 for (
Int_t irow = arown+1; irow < this->fNrows+1; irow++)
478 fRowIndex[irow] += ndiff;
481 memmove(fColIndex,colIndex_old,(lIndex+1)*
sizeof(
Int_t));
482 memmove(fElements,elements_old,(lIndex+1)*
sizeof(Element));
485 if (nelems_old > 0 && nelems_old-rIndex > 0) {
486 memmove(fColIndex+rIndex+ndiff,colIndex_old+rIndex,(nelems_old-rIndex)*
sizeof(
Int_t));
487 memmove(fElements+rIndex+ndiff,elements_old+rIndex,(nelems_old-rIndex)*
sizeof(Element));
491 for (
Int_t i = 0; i < nr; i++) {
492 fColIndex[
index] = acoln+i;
497 if (colIndex_old)
delete [] (
Int_t*) colIndex_old;
498 if (elements_old)
delete [] (Element*) elements_old;
500 R__ASSERT(this->fNelems == fRowIndex[this->fNrowIndex-1]);
508template<
class Element>
511 const Int_t arown = rown-this->fRowLwb;
512 const Int_t acoln = coln-this->fColLwb;
513 const Int_t nr = (
n > 0) ?
n : this->fNcols;
516 if (arown >= this->fNrows || arown < 0) {
517 Error(
"ExtractRow",
"row %d out of matrix range",rown);
521 if (acoln >= this->fNcols || acoln < 0) {
522 Error(
"ExtractRow",
"column %d out of matrix range",coln);
526 if (acoln+nr > this->fNcols || nr < 0) {
527 Error(
"ExtractRow",
"row length %d out of range",nr);
532 const Int_t sIndex = fRowIndex[arown];
533 const Int_t eIndex = fRowIndex[arown+1];
535 memset(
v,0,nr*
sizeof(Element));
536 const Int_t *
const pColIndex = GetColIndexArray();
537 const Element *
const pData = GetMatrixArray();
540 if (icol < acoln || icol >= acoln+nr)
continue;
541 v[icol-acoln] = pData[
index];
551template <
class Element>
560 Error(
"conservative_sparse_sparse_product_impl",
"lhs and rhs columns incompatible");
571 auto mask = std::unique_ptr<bool[]>(
new bool[rows]);
572 auto values = std::unique_ptr<Element[]>(
new Element[rows]);
573 auto indices = std::unique_ptr<Int_t[]>(
new Int_t[rows]);
575 std::memset(
mask.get(),
false,
sizeof(
bool) * rows);
576 std::memset(values.get(), 0,
sizeof(Element) * rows);
577 std::memset(indices.get(), 0,
sizeof(
Int_t) * rows);
588 Int_t estimated_nnz_prod = 0;
589 for (
Int_t j = 0; j < cols; ++j) {
591 for (
Int_t l = pRowIndexrhs[j];
l < pRowIndexrhs[j + 1]; ++
l) {
593 for (
Int_t m = pRowIndexlhs[k];
m < pRowIndexlhs[k + 1]; ++
m) {
601 estimated_nnz_prod += nnz;
602 std::memset(
mask.get(),
false,
sizeof(
bool) * rows);
605 const Int_t nc = estimated_nnz_prod;
607 Allocate(cols, rows, colsLwb, rowsLwb, 1, nc);
613 Int_t *pRowIndex = this->GetRowIndexArray();
614 Int_t *pColIndex = this->GetColIndexArray();
615 Element *pData = this->GetMatrixArray();
618 for (
Int_t j = 0; j < cols; ++j) {
620 for (
Int_t l = pRowIndexrhs[j];
l < pRowIndexrhs[j + 1]; ++
l) {
621 double y = *(rhsVal +
l);
623 for (
Int_t m = pRowIndexlhs[k];
m < pRowIndexlhs[k + 1]; ++
m) {
625 double x = *(lhsVal +
m);
635 pRowIndex[j + 1] = pRowIndex[j];
636 for (
Int_t i = 0; i < rows; ++i) {
639 Int_t p = pRowIndex[j + 1];
642 pData[
p] = values[i];
648 if (this->fNelems != pRowIndex[cols]) {
649 Error(
"conservative_sparse_sparse_product_impl",
"non zeros numbers do not match");
661template<
class Element>
668 if (
a.GetNcols() !=
b.GetNcols() ||
a.GetColLwb() !=
b.GetColLwb()) {
669 Error(
"AMultBt",
"A and B columns incompatible");
673 if (!constr && this->GetMatrixArray() ==
a.GetMatrixArray()) {
674 Error(
"AMultB",
"this = &a");
678 if (!constr && this->GetMatrixArray() ==
b.GetMatrixArray()) {
679 Error(
"AMultB",
"this = &b");
684 const Int_t *
const pRowIndexa =
a.GetRowIndexArray();
685 const Int_t *
const pColIndexa =
a.GetColIndexArray();
693 Int_t nr_nonzero_rowa = 0;
695 for (
Int_t irowa = 0; irowa <
a.GetNrows(); irowa++)
696 if (pRowIndexa[irowa] < pRowIndexa[irowa+1])
699 Int_t nr_nonzero_rowb =
b.GetNrows();
701 const Int_t nc = nr_nonzero_rowa*nr_nonzero_rowb;
702 Allocate(
a.GetNrows(),
b.GetNrows(),
a.GetRowLwb(),
b.GetRowLwb(),1,nc);
704 pRowIndexc = this->GetRowIndexArray();
705 pColIndexc = this->GetColIndexArray();
709 for (
Int_t irowa = 0; irowa <
a.GetNrows(); irowa++) {
710 pRowIndexc[irowa+1] = pRowIndexc[irowa];
711 for (
Int_t irowb = 0; irowb <
b.GetNrows(); irowb++) {
712 pRowIndexc[irowa+1]++;
713 pColIndexc[ielem++] = irowb;
717 pRowIndexc = this->GetRowIndexArray();
718 pColIndexc = this->GetColIndexArray();
721 const Element *
const pDataa =
a.GetMatrixArray();
722 const Element *
const pDatab =
b.GetMatrixArray();
723 Element *
const pDatac = this->GetMatrixArray();
725 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
726 const Int_t sIndexa = pRowIndexa[irowc];
727 const Int_t eIndexa = pRowIndexa[irowc+1];
728 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
729 const Int_t off = icolc*
b.GetNcols();
731 for (
Int_t indexa = sIndexa; indexa < eIndexa; indexa++) {
732 const Int_t icola = pColIndexa[indexa];
733 sum += pDataa[indexa]*pDatab[off+icola];
736 pColIndexc[indexc_r] = icolc;
737 pDatac[indexc_r] =
sum;
741 pRowIndexc[irowc+1]= indexc_r;
745 SetSparseIndex(indexc_r);
752template<
class Element>
759 if (
a.GetNcols() !=
b.GetNcols() ||
a.GetColLwb() !=
b.GetColLwb()) {
760 Error(
"AMultBt",
"A and B columns incompatible");
764 if (!constr && this->GetMatrixArray() ==
a.GetMatrixArray()) {
765 Error(
"AMultB",
"this = &a");
769 if (!constr && this->GetMatrixArray() ==
b.GetMatrixArray()) {
770 Error(
"AMultB",
"this = &b");
775 const Int_t *
const pRowIndexb =
b.GetRowIndexArray();
776 const Int_t *
const pColIndexb =
b.GetColIndexArray();
784 Int_t nr_nonzero_rowa =
a.GetNrows();
785 Int_t nr_nonzero_rowb = 0;
787 for (
Int_t irowb = 0; irowb <
b.GetNrows(); irowb++)
788 if (pRowIndexb[irowb] < pRowIndexb[irowb+1])
792 const Int_t nc = nr_nonzero_rowa*nr_nonzero_rowb;
793 Allocate(
a.GetNrows(),
b.GetNrows(),
a.GetRowLwb(),
b.GetRowLwb(),1,nc);
795 pRowIndexc = this->GetRowIndexArray();
796 pColIndexc = this->GetColIndexArray();
800 for (
Int_t irowa = 0; irowa <
a.GetNrows(); irowa++) {
801 pRowIndexc[irowa+1] = pRowIndexc[irowa];
802 for (
Int_t irowb = 0; irowb <
b.GetNrows(); irowb++) {
803 if (pRowIndexb[irowb] >= pRowIndexb[irowb+1])
continue;
804 pRowIndexc[irowa+1]++;
805 pColIndexc[ielem++] = irowb;
809 pRowIndexc = this->GetRowIndexArray();
810 pColIndexc = this->GetColIndexArray();
813 const Element *
const pDataa =
a.GetMatrixArray();
814 const Element *
const pDatab =
b.GetMatrixArray();
815 Element *
const pDatac = this->GetMatrixArray();
817 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
818 const Int_t off = irowc*
a.GetNcols();
819 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
820 const Int_t sIndexb = pRowIndexb[icolc];
821 const Int_t eIndexb = pRowIndexb[icolc+1];
823 for (
Int_t indexb = sIndexb; indexb < eIndexb; indexb++) {
824 const Int_t icolb = pColIndexb[indexb];
825 sum += pDataa[off+icolb]*pDatab[indexb];
828 pColIndexc[indexc_r] = icolc;
829 pDatac[indexc_r] =
sum;
833 pRowIndexc[irowc+1] = indexc_r;
837 SetSparseIndex(indexc_r);
844template<
class Element>
851 if (
a.GetNrows() !=
b.GetNrows() ||
a.GetNcols() !=
b.GetNcols() ||
852 a.GetRowLwb() !=
b.GetRowLwb() ||
a.GetColLwb() !=
b.GetColLwb()) {
853 Error(
"APlusB(const TMatrixTSparse &,const TMatrixTSparse &",
"matrices not compatible");
857 if (!constr && this->GetMatrixArray() ==
a.GetMatrixArray()) {
858 Error(
"APlusB",
"this = &a");
862 if (!constr && this->GetMatrixArray() ==
b.GetMatrixArray()) {
863 Error(
"APlusB",
"this = &b");
868 const Int_t *
const pRowIndexa =
a.GetRowIndexArray();
869 const Int_t *
const pRowIndexb =
b.GetRowIndexArray();
870 const Int_t *
const pColIndexa =
a.GetColIndexArray();
871 const Int_t *
const pColIndexb =
b.GetColIndexArray();
874 Allocate(
a.GetNrows(),
a.GetNcols(),
a.GetRowLwb(),
a.GetColLwb());
875 SetSparseIndexAB(
a,
b);
878 Int_t *
const pRowIndexc = this->GetRowIndexArray();
879 Int_t *
const pColIndexc = this->GetColIndexArray();
881 const Element *
const pDataa =
a.GetMatrixArray();
882 const Element *
const pDatab =
b.GetMatrixArray();
883 Element *
const pDatac = this->GetMatrixArray();
885 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
886 const Int_t sIndexa = pRowIndexa[irowc];
887 const Int_t eIndexa = pRowIndexa[irowc+1];
888 const Int_t sIndexb = pRowIndexb[irowc];
889 const Int_t eIndexb = pRowIndexb[irowc+1];
890 Int_t indexa = sIndexa;
891 Int_t indexb = sIndexb;
892 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
894 while (indexa < eIndexa && pColIndexa[indexa] <= icolc) {
895 if (icolc == pColIndexa[indexa]) {
896 sum += pDataa[indexa];
901 while (indexb < eIndexb && pColIndexb[indexb] <= icolc) {
902 if (icolc == pColIndexb[indexb]) {
903 sum += pDatab[indexb];
910 pColIndexc[indexc_r] = icolc;
911 pDatac[indexc_r] =
sum;
915 pRowIndexc[irowc+1] = indexc_r;
919 SetSparseIndex(indexc_r);
926template<
class Element>
933 if (
a.GetNrows() !=
b.GetNrows() ||
a.GetNcols() !=
b.GetNcols() ||
934 a.GetRowLwb() !=
b.GetRowLwb() ||
a.GetColLwb() !=
b.GetColLwb()) {
935 Error(
"APlusB(const TMatrixTSparse &,const TMatrixT &",
"matrices not compatible");
939 if (!constr && this->GetMatrixArray() ==
a.GetMatrixArray()) {
940 Error(
"APlusB",
"this = &a");
944 if (!constr && this->GetMatrixArray() ==
b.GetMatrixArray()) {
945 Error(
"APlusB",
"this = &b");
951 Allocate(
a.GetNrows(),
a.GetNcols(),
a.GetRowLwb(),
a.GetColLwb());
952 SetSparseIndexAB(
a,
b);
955 Int_t *
const pRowIndexc = this->GetRowIndexArray();
956 Int_t *
const pColIndexc = this->GetColIndexArray();
958 const Int_t *
const pRowIndexa =
a.GetRowIndexArray();
959 const Int_t *
const pColIndexa =
a.GetColIndexArray();
961 const Element *
const pDataa =
a.GetMatrixArray();
962 const Element *
const pDatab =
b.GetMatrixArray();
963 Element *
const pDatac = this->GetMatrixArray();
965 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
966 const Int_t sIndexa = pRowIndexa[irowc];
967 const Int_t eIndexa = pRowIndexa[irowc+1];
968 const Int_t off = irowc*this->GetNcols();
969 Int_t indexa = sIndexa;
970 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
971 Element
sum = pDatab[off+icolc];
972 while (indexa < eIndexa && pColIndexa[indexa] <= icolc) {
973 if (icolc == pColIndexa[indexa]) {
974 sum += pDataa[indexa];
981 pColIndexc[indexc_r] = icolc;
982 pDatac[indexc_r] =
sum;
986 pRowIndexc[irowc+1] = indexc_r;
990 SetSparseIndex(indexc_r);
997template<
class Element>
1004 if (
a.GetNrows() !=
b.GetNrows() ||
a.GetNcols() !=
b.GetNcols() ||
1005 a.GetRowLwb() !=
b.GetRowLwb() ||
a.GetColLwb() !=
b.GetColLwb()) {
1006 Error(
"AMinusB(const TMatrixTSparse &,const TMatrixTSparse &",
"matrices not compatible");
1010 if (!constr && this->GetMatrixArray() ==
a.GetMatrixArray()) {
1011 Error(
"AMinusB",
"this = &a");
1015 if (!constr && this->GetMatrixArray() ==
b.GetMatrixArray()) {
1016 Error(
"AMinusB",
"this = &b");
1021 const Int_t *
const pRowIndexa =
a.GetRowIndexArray();
1022 const Int_t *
const pRowIndexb =
b.GetRowIndexArray();
1023 const Int_t *
const pColIndexa =
a.GetColIndexArray();
1024 const Int_t *
const pColIndexb =
b.GetColIndexArray();
1027 Allocate(
a.GetNrows(),
a.GetNcols(),
a.GetRowLwb(),
a.GetColLwb());
1028 SetSparseIndexAB(
a,
b);
1031 Int_t *
const pRowIndexc = this->GetRowIndexArray();
1032 Int_t *
const pColIndexc = this->GetColIndexArray();
1034 const Element *
const pDataa =
a.GetMatrixArray();
1035 const Element *
const pDatab =
b.GetMatrixArray();
1036 Element *
const pDatac = this->GetMatrixArray();
1038 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
1039 const Int_t sIndexa = pRowIndexa[irowc];
1040 const Int_t eIndexa = pRowIndexa[irowc+1];
1041 const Int_t sIndexb = pRowIndexb[irowc];
1042 const Int_t eIndexb = pRowIndexb[irowc+1];
1043 Int_t indexa = sIndexa;
1044 Int_t indexb = sIndexb;
1045 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
1047 while (indexa < eIndexa && pColIndexa[indexa] <= icolc) {
1048 if (icolc == pColIndexa[indexa]) {
1049 sum += pDataa[indexa];
1054 while (indexb < eIndexb && pColIndexb[indexb] <= icolc) {
1055 if (icolc == pColIndexb[indexb]) {
1056 sum -= pDatab[indexb];
1063 pColIndexc[indexc_r] = icolc;
1064 pDatac[indexc_r] =
sum;
1068 pRowIndexc[irowc+1] = indexc_r;
1072 SetSparseIndex(indexc_r);
1079template<
class Element>
1086 if (
a.GetNrows() !=
b.GetNrows() ||
a.GetNcols() !=
b.GetNcols() ||
1087 a.GetRowLwb() !=
b.GetRowLwb() ||
a.GetColLwb() !=
b.GetColLwb()) {
1088 Error(
"AMinusB(const TMatrixTSparse &,const TMatrixT &",
"matrices not compatible");
1092 if (!constr && this->GetMatrixArray() ==
a.GetMatrixArray()) {
1093 Error(
"AMinusB",
"this = &a");
1097 if (!constr && this->GetMatrixArray() ==
b.GetMatrixArray()) {
1098 Error(
"AMinusB",
"this = &b");
1104 Allocate(
a.GetNrows(),
a.GetNcols(),
a.GetRowLwb(),
a.GetColLwb());
1105 SetSparseIndexAB(
a,
b);
1108 Int_t *
const pRowIndexc = this->GetRowIndexArray();
1109 Int_t *
const pColIndexc = this->GetColIndexArray();
1111 const Int_t *
const pRowIndexa =
a.GetRowIndexArray();
1112 const Int_t *
const pColIndexa =
a.GetColIndexArray();
1114 const Element *
const pDataa =
a.GetMatrixArray();
1115 const Element *
const pDatab =
b.GetMatrixArray();
1116 Element *
const pDatac = this->GetMatrixArray();
1118 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
1119 const Int_t sIndexa = pRowIndexa[irowc];
1120 const Int_t eIndexa = pRowIndexa[irowc+1];
1121 const Int_t off = irowc*this->GetNcols();
1122 Int_t indexa = sIndexa;
1123 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
1124 Element
sum = -pDatab[off+icolc];
1125 while (indexa < eIndexa && pColIndexa[indexa] <= icolc) {
1126 if (icolc == pColIndexa[indexa]) {
1127 sum += pDataa[indexa];
1134 pColIndexc[indexc_r] = icolc;
1135 pDatac[indexc_r] =
sum;
1139 pRowIndexc[irowc+1] = indexc_r;
1143 SetSparseIndex(indexc_r);
1150template<
class Element>
1157 if (
a.GetNrows() !=
b.GetNrows() ||
a.GetNcols() !=
b.GetNcols() ||
1158 a.GetRowLwb() !=
b.GetRowLwb() ||
a.GetColLwb() !=
b.GetColLwb()) {
1159 Error(
"AMinusB(const TMatrixT &,const TMatrixTSparse &",
"matrices not compatible");
1163 if (!constr && this->GetMatrixArray() ==
a.GetMatrixArray()) {
1164 Error(
"AMinusB",
"this = &a");
1168 if (!constr && this->GetMatrixArray() ==
b.GetMatrixArray()) {
1169 Error(
"AMinusB",
"this = &b");
1175 Allocate(
a.GetNrows(),
a.GetNcols(),
a.GetRowLwb(),
a.GetColLwb());
1176 SetSparseIndexAB(
a,
b);
1179 Int_t *
const pRowIndexc = this->GetRowIndexArray();
1180 Int_t *
const pColIndexc = this->GetColIndexArray();
1182 const Int_t *
const pRowIndexb =
b.GetRowIndexArray();
1183 const Int_t *
const pColIndexb =
b.GetColIndexArray();
1185 const Element *
const pDataa =
a.GetMatrixArray();
1186 const Element *
const pDatab =
b.GetMatrixArray();
1187 Element *
const pDatac = this->GetMatrixArray();
1189 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
1190 const Int_t sIndexb = pRowIndexb[irowc];
1191 const Int_t eIndexb = pRowIndexb[irowc+1];
1192 const Int_t off = irowc*this->GetNcols();
1193 Int_t indexb = sIndexb;
1194 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
1195 Element
sum = pDataa[off+icolc];
1196 while (indexb < eIndexb && pColIndexb[indexb] <= icolc) {
1197 if (icolc == pColIndexb[indexb]) {
1198 sum -= pDatab[indexb];
1205 pColIndexc[indexc_r] = icolc;
1206 pDatac[indexc_r] =
sum;
1210 pRowIndexc[irowc+1] = indexc_r;
1214 SetSparseIndex(indexc_r);
1220template<
class Element>
1225 const Element *
const elem = GetMatrixArray();
1226 memcpy(
data,elem,this->fNelems*
sizeof(Element));
1234template<
class Element>
1239 Error(
"SetMatrixArray(Int_t,Int_t*,Int_t*,Element*",
"nr <= 0");
1248 R__ASSERT(row[irowmin] >= this->fRowLwb && row[irowmax] <= this->fRowLwb+this->fNrows-1);
1249 R__ASSERT(col[icolmin] >= this->fColLwb && col[icolmax] <= this->fColLwb+this->fNcols-1);
1251 if (row[irowmin] < this->fRowLwb|| row[irowmax] > this->fRowLwb+this->fNrows-1) {
1252 Error(
"SetMatrixArray",
"Inconsistency between row index and its range");
1253 if (row[irowmin] < this->fRowLwb) {
1254 Info(
"SetMatrixArray",
"row index lower bound adjusted to %d",row[irowmin]);
1255 this->fRowLwb = row[irowmin];
1257 if (row[irowmax] > this->fRowLwb+this->fNrows-1) {
1258 Info(
"SetMatrixArray",
"row index upper bound adjusted to %d",row[irowmax]);
1259 this->fNrows = row[irowmax]-this->fRowLwb+1;
1262 if (col[icolmin] < this->fColLwb || col[icolmax] > this->fColLwb+this->fNcols-1) {
1263 Error(
"SetMatrixArray",
"Inconsistency between column index and its range");
1264 if (col[icolmin] < this->fColLwb) {
1265 Info(
"SetMatrixArray",
"column index lower bound adjusted to %d",col[icolmin]);
1266 this->fColLwb = col[icolmin];
1268 if (col[icolmax] > this->fColLwb+this->fNcols-1) {
1269 Info(
"SetMatrixArray",
"column index upper bound adjusted to %d",col[icolmax]);
1270 this->fNcols = col[icolmax]-this->fColLwb+1;
1275 nr = ReduceSparseMatrix(nr, row, col,
data);
1277 Int_t nr_nonzeros = 0;
1278 const Element *ep =
data;
1279 const Element *
const fp =
data+nr;
1282 if (*ep++ != 0.0) nr_nonzeros++;
1284 if (nr_nonzeros != this->fNelems) {
1285 if (fColIndex) {
delete [] fColIndex; fColIndex =
nullptr; }
1286 if (fElements) {
delete [] fElements; fElements =
nullptr; }
1287 this->fNelems = nr_nonzeros;
1288 if (this->fNelems > 0) {
1289 fColIndex =
new Int_t[nr_nonzeros];
1290 fElements =
new Element[nr_nonzeros];
1292 fColIndex =
nullptr;
1293 fElements =
nullptr;
1297 if (this->fNelems <= 0)
1303 for (
Int_t irow = 1; irow < this->fNrows+1; irow++) {
1304 if (ielem < nr && row[ielem] - this->fRowLwb < irow) {
1305 while (ielem < nr) {
1306 if (
data[ielem] != 0.0) {
1307 fColIndex[nr_nonzeros] = col[ielem]-this->fColLwb;
1308 fElements[nr_nonzeros] =
data[ielem];
1312 if (ielem >= nr || row[ielem] != row[ielem-1])
1316 fRowIndex[irow] = nr_nonzeros;
1327template <
class Element>
1334 while (i < nz - 1) {
1335 if ((row[i] == row[i + 1]) && (col[i] == col[i + 1])) {
1340 for (
Int_t j = i + 1; j < nz; j++) {
1342 row[j] = row[j + 1];
1343 col[j] = col[j + 1];
1352template <
class Element>
1358 Error(
"SetMatrixArray(Int_t,Int_t*,Int_t*,Element*",
"nr <= 0");
1362 if (nrows != this->fNrows) {
1365 fRowIndex =
nullptr;
1367 this->fNrows = nrows;
1368 if (this->fNrows > 0) {
1369 fRowIndex =
new Int_t[nrows + 1];
1370 this->fNrowIndex = nrows + 1;
1372 fRowIndex =
nullptr;
1373 this->fNrowIndex = 0;
1377 if (ncols != this->fNcols) {
1378 this->fNcols = ncols;
1381 if (this->fRowLwb != this->fColLwb) {
1382 auto tmp = this->fRowLwb;
1383 this->fRowLwb = this->fColLwb;
1384 this->fColLwb = tmp;
1392 R__ASSERT(row[irowmin] >= this->fRowLwb && row[irowmax] <= this->fRowLwb + this->fNrows - 1);
1393 R__ASSERT(col[icolmin] >= this->fColLwb && col[icolmax] <= this->fColLwb + this->fNcols - 1);
1395 if (row[irowmin] < this->fRowLwb || row[irowmax] > this->fRowLwb + this->fNrows - 1) {
1396 Error(
"SetMatrixArray",
"Inconsistency between row index and its range");
1397 if (row[irowmin] < this->fRowLwb) {
1398 Info(
"SetMatrixArray",
"row index lower bound adjusted to %d", row[irowmin]);
1399 this->fRowLwb = row[irowmin];
1401 if (row[irowmax] > this->fRowLwb + this->fNrows - 1) {
1402 Info(
"SetMatrixArray",
"row index upper bound adjusted to %d", row[irowmax]);
1403 this->fNrows = row[irowmax] - this->fRowLwb + 1;
1406 if (col[icolmin] < this->fColLwb || col[icolmax] > this->fColLwb + this->fNcols - 1) {
1407 Error(
"SetMatrixArray",
"Inconsistency between column index and its range");
1408 if (col[icolmin] < this->fColLwb) {
1409 Info(
"SetMatrixArray",
"column index lower bound adjusted to %d", col[icolmin]);
1410 this->fColLwb = col[icolmin];
1412 if (col[icolmax] > this->fColLwb + this->fNcols - 1) {
1413 Info(
"SetMatrixArray",
"column index upper bound adjusted to %d", col[icolmax]);
1414 this->fNcols = col[icolmax] - this->fColLwb + 1;
1419 nr = ReduceSparseMatrix(nr, row, col,
data);
1421 Int_t nr_nonzeros = 0;
1422 const Element *ep =
data;
1423 const Element *
const fp =
data + nr;
1429 if (nr_nonzeros != this->fNelems) {
1432 fColIndex =
nullptr;
1436 fElements =
nullptr;
1438 this->fNelems = nr_nonzeros;
1439 if (this->fNelems > 0) {
1440 fColIndex =
new Int_t[nr_nonzeros];
1441 fElements =
new Element[nr_nonzeros];
1443 fColIndex =
nullptr;
1444 fElements =
nullptr;
1448 if (this->fNelems <= 0)
1454 for (
Int_t irow = 1; irow < this->fNrows + 1; irow++) {
1455 if (ielem < nr && row[ielem] - this->fRowLwb < irow) {
1456 while (ielem < nr) {
1457 if (
data[ielem] != 0.0) {
1458 fColIndex[nr_nonzeros] = col[ielem] - this->fColLwb;
1459 fElements[nr_nonzeros] =
data[ielem];
1463 if (ielem >= nr || row[ielem] != row[ielem - 1])
1467 fRowIndex[irow] = nr_nonzeros;
1476template<
class Element>
1479 if (nelems_new != this->fNelems) {
1481 Int_t *oIp = fColIndex;
1482 fColIndex =
new Int_t[nelems_new];
1484 memmove(fColIndex,oIp,nr*
sizeof(
Int_t));
1487 Element *oDp = fElements;
1488 fElements =
new Element[nelems_new];
1490 memmove(fElements,oDp,nr*
sizeof(Element));
1493 this->fNelems = nelems_new;
1494 if (nelems_new > nr) {
1495 memset(fElements+nr,0,(nelems_new-nr)*
sizeof(Element));
1496 memset(fColIndex+nr,0,(nelems_new-nr)*
sizeof(
Int_t));
1498 for (
Int_t irow = 0; irow < this->fNrowIndex; irow++)
1499 if (fRowIndex[irow] > nelems_new)
1500 fRowIndex[irow] = nelems_new;
1510template<
class Element>
1515 if (this->GetNrows() != source.
GetNrows() || this->GetNcols() != source.
GetNcols() ||
1516 this->GetRowLwb() != source.
GetRowLwb() || this->GetColLwb() != source.
GetColLwb()) {
1517 Error(
"SetSparseIndex",
"matrices not compatible");
1524 if (nr_nonzeros != this->fNelems)
1525 SetSparseIndex(nr_nonzeros);
1533 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
1534 fRowIndex[irow] = nr;
1535 for (
Int_t icol = 0; icol < this->fNcols; icol++) {
1537 fColIndex[nr] = icol;
1543 fRowIndex[this->fNrows] = nr;
1553template<
class Element>
1560 if (
a.GetNrows() !=
b.GetNrows() ||
a.GetNcols() !=
b.GetNcols() ||
1561 a.GetRowLwb() !=
b.GetRowLwb() ||
a.GetColLwb() !=
b.GetColLwb()) {
1562 Error(
"SetSparseIndexAB",
"source matrices not compatible");
1566 if (this->GetNrows() !=
a.GetNrows() || this->GetNcols() !=
a.GetNcols() ||
1567 this->GetRowLwb() !=
a.GetRowLwb() || this->GetColLwb() !=
a.GetColLwb()) {
1568 Error(
"SetSparseIndexAB",
"matrix not compatible with source matrices");
1573 const Int_t *
const pRowIndexa =
a.GetRowIndexArray();
1574 const Int_t *
const pRowIndexb =
b.GetRowIndexArray();
1575 const Int_t *
const pColIndexa =
a.GetColIndexArray();
1576 const Int_t *
const pColIndexb =
b.GetColIndexArray();
1580 for (
Int_t irowc = 0; irowc <
a.GetNrows(); irowc++) {
1581 const Int_t sIndexa = pRowIndexa[irowc];
1582 const Int_t eIndexa = pRowIndexa[irowc+1];
1583 const Int_t sIndexb = pRowIndexb[irowc];
1584 const Int_t eIndexb = pRowIndexb[irowc+1];
1585 nc += eIndexa-sIndexa;
1586 Int_t indexb = sIndexb;
1587 for (
Int_t indexa = sIndexa; indexa < eIndexa; indexa++) {
1588 const Int_t icola = pColIndexa[indexa];
1589 for (; indexb < eIndexb; indexb++) {
1590 if (pColIndexb[indexb] >= icola) {
1591 if (pColIndexb[indexb] == icola)
1598 while (indexb < eIndexb) {
1599 const Int_t icola = (eIndexa > sIndexa && eIndexa > 0) ? pColIndexa[eIndexa-1] : -1;
1600 if (pColIndexb[indexb++] > icola)
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 <
a.GetNrows(); irowc++) {
1615 const Int_t sIndexa = pRowIndexa[irowc];
1616 const Int_t eIndexa = pRowIndexa[irowc+1];
1617 const Int_t sIndexb = pRowIndexb[irowc];
1618 const Int_t eIndexb = pRowIndexb[irowc+1];
1619 Int_t indexb = sIndexb;
1620 for (
Int_t indexa = sIndexa; indexa < eIndexa; indexa++) {
1621 const Int_t icola = pColIndexa[indexa];
1622 for (; indexb < eIndexb; indexb++) {
1623 if (pColIndexb[indexb] >= icola) {
1624 if (pColIndexb[indexb] == icola)
1628 pColIndexc[nc++] = pColIndexb[indexb];
1630 pColIndexc[nc++] = pColIndexa[indexa];
1632 while (indexb < eIndexb) {
1633 const Int_t icola = (eIndexa > 0) ? pColIndexa[eIndexa-1] : -1;
1634 if (pColIndexb[indexb++] > icola)
1635 pColIndexc[nc++] = pColIndexb[indexb-1];
1637 pRowIndexc[irowc+1] = nc;
1647template<
class Element>
1654 if (
a.GetNrows() !=
b.GetNrows() ||
a.GetNcols() !=
b.GetNcols() ||
1655 a.GetRowLwb() !=
b.GetRowLwb() ||
a.GetColLwb() !=
b.GetColLwb()) {
1656 Error(
"SetSparseIndexAB",
"source matrices not compatible");
1660 if (this->GetNrows() !=
a.GetNrows() || this->GetNcols() !=
a.GetNcols() ||
1661 this->GetRowLwb() !=
a.GetRowLwb() || this->GetColLwb() !=
a.GetColLwb()) {
1662 Error(
"SetSparseIndexAB",
"matrix not compatible with source matrices");
1667 const Element *
const pDataa =
a.GetMatrixArray();
1669 const Int_t *
const pRowIndexb =
b.GetRowIndexArray();
1670 const Int_t *
const pColIndexb =
b.GetColIndexArray();
1674 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
1675 const Int_t sIndexb = pRowIndexb[irowc];
1676 const Int_t eIndexb = pRowIndexb[irowc+1];
1677 const Int_t off = irowc*this->GetNcols();
1678 Int_t indexb = sIndexb;
1679 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
1680 if (pDataa[off+icolc] != 0.0 || pColIndexb[indexb] > icolc)
continue;
1681 for (; indexb < eIndexb; indexb++) {
1682 if (pColIndexb[indexb] >= icolc) {
1683 if (pColIndexb[indexb] == icolc) {
1694 if (this->NonZeros() != nc)
1697 Int_t *
const pRowIndexc = this->GetRowIndexArray();
1698 Int_t *
const pColIndexc = this->GetColIndexArray();
1702 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
1703 const Int_t sIndexb = pRowIndexb[irowc];
1704 const Int_t eIndexb = pRowIndexb[irowc+1];
1705 const Int_t off = irowc*this->GetNcols();
1706 Int_t indexb = sIndexb;
1707 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
1708 if (pDataa[off+icolc] != 0.0)
1709 pColIndexc[nc++] = icolc;
1710 else if (pColIndexb[indexb] <= icolc) {
1711 for (; indexb < eIndexb; indexb++) {
1712 if (pColIndexb[indexb] >= icolc) {
1713 if (pColIndexb[indexb] == icolc)
1714 pColIndexc[nc++] = pColIndexb[indexb++];
1720 pRowIndexc[irowc+1] = nc;
1732template<
class Element>
1736 if (!this->fIsOwner) {
1737 Error(
"ResizeTo(Int_t,Int_t,Int_t)",
"Not owner of data array,cannot resize");
1741 if (this->fNelems > 0) {
1742 if (this->fNrows == nrows && this->fNcols == ncols &&
1743 (this->fNelems == nr_nonzeros || nr_nonzeros < 0))
1745 else if (nrows == 0 || ncols == 0 || nr_nonzeros == 0) {
1746 this->fNrows = nrows; this->fNcols = ncols;
1751 const Element *elements_old = GetMatrixArray();
1752 const Int_t *rowIndex_old = GetRowIndexArray();
1753 const Int_t *colIndex_old = GetColIndexArray();
1755 Int_t nrows_old = this->fNrows;
1756 Int_t nrowIndex_old = this->fNrowIndex;
1759 if (nr_nonzeros > 0)
1760 nelems_new = nr_nonzeros;
1763 for (
Int_t irow = 0; irow < nrows_old; irow++) {
1764 if (irow >= nrows)
continue;
1765 const Int_t sIndex = rowIndex_old[irow];
1766 const Int_t eIndex = rowIndex_old[irow+1];
1775 Allocate(nrows,ncols,0,0,1,nelems_new);
1778 Element *elements_new = GetMatrixArray();
1779 Int_t *rowIndex_new = GetRowIndexArray();
1780 Int_t *colIndex_new = GetColIndexArray();
1782 Int_t nelems_copy = 0;
1783 rowIndex_new[0] = 0;
1785 for (
Int_t irow = 0; irow < nrows_old && cont; irow++) {
1786 if (irow >= nrows)
continue;
1787 const Int_t sIndex = rowIndex_old[irow];
1788 const Int_t eIndex = rowIndex_old[irow+1];
1792 rowIndex_new[irow+1] = nelems_copy+1;
1793 colIndex_new[nelems_copy] = icol;
1794 elements_new[nelems_copy] = elements_old[
index];
1797 if (nelems_copy >= nelems_new) {
1804 if (rowIndex_old)
delete [] (
Int_t*) rowIndex_old;
1805 if (colIndex_old)
delete [] (
Int_t*) colIndex_old;
1806 if (elements_old)
delete [] (Element*) elements_old;
1808 if (nrowIndex_old < this->fNrowIndex) {
1809 for (
Int_t irow = nrowIndex_old; irow < this->fNrowIndex; irow++)
1810 rowIndex_new[irow] = rowIndex_new[nrowIndex_old-1];
1813 const Int_t nelems_new = (nr_nonzeros >= 0) ? nr_nonzeros : 0;
1814 Allocate(nrows,ncols,0,0,1,nelems_new);
1826template<
class Element>
1831 if (!this->fIsOwner) {
1832 Error(
"ResizeTo(Int_t,Int_t,Int_t,Int_t,Int_t)",
"Not owner of data array,cannot resize");
1836 const Int_t new_nrows = row_upb-row_lwb+1;
1837 const Int_t new_ncols = col_upb-col_lwb+1;
1839 if (this->fNelems > 0) {
1840 if (this->fNrows == new_nrows && this->fNcols == new_ncols &&
1841 this->fRowLwb == row_lwb && this->fColLwb == col_lwb &&
1842 (this->fNelems == nr_nonzeros || nr_nonzeros < 0))
1844 else if (new_nrows == 0 || new_ncols == 0 || nr_nonzeros == 0) {
1845 this->fNrows = new_nrows; this->fNcols = new_ncols;
1846 this->fRowLwb = row_lwb; this->fColLwb = col_lwb;
1851 const Int_t *rowIndex_old = GetRowIndexArray();
1852 const Int_t *colIndex_old = GetColIndexArray();
1853 const Element *elements_old = GetMatrixArray();
1855 const Int_t nrowIndex_old = this->fNrowIndex;
1857 const Int_t nrows_old = this->fNrows;
1858 const Int_t rowLwb_old = this->fRowLwb;
1859 const Int_t colLwb_old = this->fColLwb;
1862 if (nr_nonzeros > 0)
1863 nelems_new = nr_nonzeros;
1866 for (
Int_t irow = 0; irow < nrows_old; irow++) {
1867 if (irow+rowLwb_old > row_upb || irow+rowLwb_old < row_lwb)
continue;
1868 const Int_t sIndex = rowIndex_old[irow];
1869 const Int_t eIndex = rowIndex_old[irow+1];
1872 if (icol+colLwb_old <= col_upb && icol+colLwb_old >= col_lwb)
1878 Allocate(new_nrows,new_ncols,row_lwb,col_lwb,1,nelems_new);
1881 Int_t *rowIndex_new = GetRowIndexArray();
1882 Int_t *colIndex_new = GetColIndexArray();
1883 Element *elements_new = GetMatrixArray();
1885 Int_t nelems_copy = 0;
1886 rowIndex_new[0] = 0;
1887 const Int_t row_off = rowLwb_old-row_lwb;
1888 const Int_t col_off = colLwb_old-col_lwb;
1889 for (
Int_t irow = 0; irow < nrows_old; irow++) {
1890 if (irow+rowLwb_old > row_upb || irow+rowLwb_old < row_lwb)
continue;
1891 const Int_t sIndex = rowIndex_old[irow];
1892 const Int_t eIndex = rowIndex_old[irow+1];
1895 if (icol+colLwb_old <= col_upb && icol+colLwb_old >= col_lwb) {
1896 rowIndex_new[irow+row_off+1] = nelems_copy+1;
1897 colIndex_new[nelems_copy] = icol+col_off;
1898 elements_new[nelems_copy] = elements_old[
index];
1901 if (nelems_copy >= nelems_new) {
1907 if (rowIndex_old)
delete [] (
Int_t*) rowIndex_old;
1908 if (colIndex_old)
delete [] (
Int_t*) colIndex_old;
1909 if (elements_old)
delete [] (Element*) elements_old;
1911 if (nrowIndex_old < this->fNrowIndex) {
1912 for (
Int_t irow = nrowIndex_old; irow < this->fNrowIndex; irow++)
1913 rowIndex_new[irow] = rowIndex_new[nrowIndex_old-1];
1916 const Int_t nelems_new = (nr_nonzeros >= 0) ? nr_nonzeros : 0;
1917 Allocate(new_nrows,new_ncols,row_lwb,col_lwb,1,nelems_new);
1925template<
class Element>
1930 if (row_upb < row_lwb) {
1931 Error(
"Use",
"row_upb=%d < row_lwb=%d",row_upb,row_lwb);
1934 if (col_upb < col_lwb) {
1935 Error(
"Use",
"col_upb=%d < col_lwb=%d",col_upb,col_lwb);
1942 this->fNrows = row_upb-row_lwb+1;
1943 this->fNcols = col_upb-col_lwb+1;
1944 this->fRowLwb = row_lwb;
1945 this->fColLwb = col_lwb;
1946 this->fNrowIndex = this->fNrows+1;
1947 this->fNelems = nr_nonzeros;
1949 this->fTol = std::numeric_limits<Element>::epsilon();
1952 fRowIndex = pRowIndex;
1953 fColIndex = pColIndex;
1965template<
class Element>
1971 if (row_lwb < this->fRowLwb || row_lwb > this->fRowLwb+this->fNrows-1) {
1972 Error(
"GetSub",
"row_lwb out-of-bounds");
1975 if (col_lwb < this->fColLwb || col_lwb > this->fColLwb+this->fNcols-1) {
1976 Error(
"GetSub",
"col_lwb out-of-bounds");
1979 if (row_upb < this->fRowLwb || row_upb > this->fRowLwb+this->fNrows-1) {
1980 Error(
"GetSub",
"row_upb out-of-bounds");
1983 if (col_upb < this->fColLwb || col_upb > this->fColLwb+this->fNcols-1) {
1984 Error(
"GetSub",
"col_upb out-of-bounds");
1987 if (row_upb < row_lwb || col_upb < col_lwb) {
1988 Error(
"GetSub",
"row_upb < row_lwb || col_upb < col_lwb");
1997 const Int_t row_lwb_sub = (shift) ? 0 : row_lwb;
1998 const Int_t row_upb_sub = (shift) ? row_upb-row_lwb : row_upb;
1999 const Int_t col_lwb_sub = (shift) ? 0 : col_lwb;
2000 const Int_t col_upb_sub = (shift) ? col_upb-col_lwb : col_upb;
2002 Int_t nr_nonzeros = 0;
2003 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
2004 if (irow+this->fRowLwb > row_upb || irow+this->fRowLwb < row_lwb)
continue;
2005 const Int_t sIndex = fRowIndex[irow];
2006 const Int_t eIndex = fRowIndex[irow+1];
2009 if (icol+this->fColLwb <= col_upb && icol+this->fColLwb >= col_lwb)
2014 target.ResizeTo(row_lwb_sub,row_upb_sub,col_lwb_sub,col_upb_sub,nr_nonzeros);
2016 const Element *ep = this->GetMatrixArray();
2020 Element *ep_sub =
target.GetMatrixArray();
2022 if (
target.GetRowIndexArray() &&
target.GetColIndexArray()) {
2023 Int_t nelems_copy = 0;
2024 rowIndex_sub[0] = 0;
2025 const Int_t row_off = this->fRowLwb-row_lwb;
2026 const Int_t col_off = this->fColLwb-col_lwb;
2027 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
2028 if (irow+this->fRowLwb > row_upb || irow+this->fRowLwb < row_lwb)
continue;
2029 const Int_t sIndex = fRowIndex[irow];
2030 const Int_t eIndex = fRowIndex[irow+1];
2033 if (icol+this->fColLwb <= col_upb && icol+this->fColLwb >= col_lwb) {
2034 rowIndex_sub[irow+row_off+1] = nelems_copy+1;
2035 colIndex_sub[nelems_copy] = icol+col_off;
2036 ep_sub[nelems_copy] = ep[
index];
2042 const Int_t row_off = this->fRowLwb-row_lwb;
2043 const Int_t col_off = this->fColLwb-col_lwb;
2044 const Int_t ncols_sub = col_upb_sub-col_lwb_sub+1;
2045 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
2046 if (irow+this->fRowLwb > row_upb || irow+this->fRowLwb < row_lwb)
continue;
2047 const Int_t sIndex = fRowIndex[irow];
2048 const Int_t eIndex = fRowIndex[irow+1];
2049 const Int_t off = (irow+row_off)*ncols_sub;
2052 if (icol+this->fColLwb <= col_upb && icol+this->fColLwb >= col_lwb)
2053 ep_sub[off+icol+col_off] = ep[
index];
2065template<
class Element>
2072 if (row_lwb < this->fRowLwb || row_lwb > this->fRowLwb+this->fNrows-1) {
2073 Error(
"SetSub",
"row_lwb out-of-bounds");
2076 if (col_lwb < this->fColLwb || col_lwb > this->fColLwb+this->fNcols-1) {
2077 Error(
"SetSub",
"col_lwb out-of-bounds");
2080 if (row_lwb+source.
GetNrows() > this->fRowLwb+this->fNrows || col_lwb+source.
GetNcols() > this->fColLwb+this->fNcols) {
2081 Error(
"SetSub",
"source matrix too large");
2091 Int_t nr_nonzeros = 0;
2092 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
2093 if (irow+this->fRowLwb >= row_lwb+nRows_source || irow+this->fRowLwb < row_lwb)
continue;
2094 const Int_t sIndex = fRowIndex[irow];
2095 const Int_t eIndex = fRowIndex[irow+1];
2098 if (icol+this->fColLwb < col_lwb+nCols_source && icol+this->fColLwb >= col_lwb)
2107 const Int_t nelems_old = this->fNelems;
2108 const Int_t *rowIndex_old = GetRowIndexArray();
2109 const Int_t *colIndex_old = GetColIndexArray();
2110 const Element *elements_old = GetMatrixArray();
2112 const Int_t nelems_new = nelems_old+source.
NonZeros()-nr_nonzeros;
2113 fRowIndex =
new Int_t[this->fNrowIndex];
2114 fColIndex =
new Int_t[nelems_new];
2115 fElements =
new Element[nelems_new];
2116 this->fNelems = nelems_new;
2118 Int_t *rowIndex_new = GetRowIndexArray();
2119 Int_t *colIndex_new = GetColIndexArray();
2120 Element *elements_new = GetMatrixArray();
2122 const Int_t row_off = row_lwb-this->fRowLwb;
2123 const Int_t col_off = col_lwb-this->fColLwb;
2126 rowIndex_new[0] = 0;
2127 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
2128 rowIndex_new[irow+1] = rowIndex_new[irow];
2130 if (irow+this->fRowLwb < row_lwb+nRows_source && irow+this->fRowLwb >= row_lwb)
2133 const Int_t sIndex_o = rowIndex_old[irow];
2134 const Int_t eIndex_o = rowIndex_old[irow+1];
2137 const Int_t icol_left = col_off-1;
2140 rowIndex_new[irow+1]++;
2141 colIndex_new[nr] = colIndex_old[
index];
2142 elements_new[nr] = elements_old[
index];
2146 if (rowIndex_s && colIndex_s) {
2147 const Int_t sIndex_s = rowIndex_s[irow-row_off];
2148 const Int_t eIndex_s = rowIndex_s[irow-row_off+1];
2150 rowIndex_new[irow+1]++;
2151 colIndex_new[nr] = colIndex_s[
index]+col_off;
2152 elements_new[nr] = elements_s[
index];
2156 const Int_t off = (irow-row_off)*nCols_source;
2157 for (
Int_t icol = 0; icol < nCols_source; icol++) {
2158 rowIndex_new[irow+1]++;
2159 colIndex_new[nr] = icol+col_off;
2160 elements_new[nr] = elements_s[off+icol];
2165 const Int_t icol_right = col_off+nCols_source-1;
2168 while (right < eIndex_o-1 && colIndex_old[right+1] <= icol_right)
2173 rowIndex_new[irow+1]++;
2174 colIndex_new[nr] = colIndex_old[
index];
2175 elements_new[nr] = elements_old[
index];
2181 rowIndex_new[irow+1]++;
2182 colIndex_new[nr] = colIndex_old[
index];
2183 elements_new[nr] = elements_old[
index];
2189 R__ASSERT(this->fNelems == fRowIndex[this->fNrowIndex-1]);
2191 if (rowIndex_old)
delete [] (
Int_t*) rowIndex_old;
2192 if (colIndex_old)
delete [] (
Int_t*) colIndex_old;
2193 if (elements_old)
delete [] (Element*) elements_old;
2201template<
class Element>
2220 Element *pData_t =
new Element[nr_nonzeros];
2223 for (
Int_t irow_s = 0; irow_s < source.
GetNrows(); irow_s++) {
2224 const Int_t sIndex = pRowIndex_s[irow_s];
2225 const Int_t eIndex = pRowIndex_s[irow_s+1];
2227 rownr[ielem] = pColIndex_s[
index]+this->fRowLwb;
2228 colnr[ielem] = irow_s+this->fColLwb;
2229 pData_t[ielem] = pData_s[
index];
2237 SetMatrixArray(nr_nonzeros, source.
GetNcols(), source.
GetNrows(), rownr, colnr, pData_t);
2239 SetMatrixArray(nr_nonzeros, rownr, colnr, pData_t);
2242 R__ASSERT(this->fNelems == fRowIndex[this->fNrowIndex-1]);
2244 if (pData_t)
delete [] pData_t;
2245 if (rownr)
delete [] rownr;
2246 if (colnr)
delete [] colnr;
2253template<
class Element>
2258 if (fElements) {
delete [] fElements; fElements =
nullptr; }
2259 if (fColIndex) {
delete [] fColIndex; fColIndex =
nullptr; }
2261 memset(this->GetRowIndexArray(),0,this->fNrowIndex*
sizeof(
Int_t));
2269template<
class Element>
2276 Int_t nr_nonzeros = 0;
2277 for (i = this->fRowLwb; i <= this->fRowLwb+this->fNrows-1; i++)
2278 for (
Int_t j = this->fColLwb; j <= this->fColLwb+this->fNcols-1; j++)
2279 if (i == j) nr_nonzeros++;
2281 if (nr_nonzeros != this->fNelems) {
2282 this->fNelems = nr_nonzeros;
2283 Int_t *oIp = fColIndex;
2284 fColIndex =
new Int_t[nr_nonzeros];
2285 if (oIp)
delete [] oIp;
2286 Element *oDp = fElements;
2287 fElements =
new Element[nr_nonzeros];
2288 if (oDp)
delete [] oDp;
2293 for (i = this->fRowLwb; i <= this->fRowLwb+this->fNrows-1; i++) {
2294 for (
Int_t j = this->fColLwb; j <= this->fColLwb+this->fNcols-1; j++) {
2296 const Int_t irow = i-this->fRowLwb;
2297 fRowIndex[irow+1] = ielem+1;
2298 fElements[ielem] = 1.0;
2299 fColIndex[ielem++] = j-this->fColLwb;
2311template<
class Element>
2316 const Element * ep = GetMatrixArray();
2317 const Element *
const fp = ep+this->fNelems;
2318 const Int_t *
const pR = GetRowIndexArray();
2322 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
2323 const Int_t sIndex = pR[irow];
2324 const Int_t eIndex = pR[irow+1];
2340template<
class Element>
2348 const Element *
const fp = ep+this->fNcols;
2355 for (
Int_t i = 0; i < this->fNrows; i++,ep += this->fNcols)
2357 ep -= this->fNelems-1;
2368template<
class Element>
2373 const Int_t arown = rown-this->fRowLwb;
2374 const Int_t acoln = coln-this->fColLwb;
2375 if (arown >= this->fNrows || arown < 0) {
2376 Error(
"operator()",
"Request row(%d) outside matrix range of %d - %d",rown,this->fRowLwb,this->fRowLwb+this->fNrows);
2377 return fElements[0];
2379 if (acoln >= this->fNcols || acoln < 0) {
2380 Error(
"operator()",
"Request column(%d) outside matrix range of %d - %d",coln,this->fColLwb,this->fColLwb+this->fNcols);
2381 return fElements[0];
2387 if (this->fNrowIndex > 0 && fRowIndex[this->fNrowIndex-1] != 0) {
2388 sIndex = fRowIndex[arown];
2389 eIndex = fRowIndex[arown+1];
2393 if (
index >= sIndex && fColIndex[
index] == acoln)
2394 return fElements[
index];
2397 InsertRow(rown,coln,&val,1);
2398 sIndex = fRowIndex[arown];
2399 eIndex = fRowIndex[arown+1];
2401 if (
index >= sIndex && fColIndex[
index] == acoln)
2402 return fElements[
index];
2404 Error(
"operator()(Int_t,Int_t",
"Insert row failed");
2405 return fElements[0];
2412template <
class Element>
2416 if (this->fNrowIndex > 0 && this->fRowIndex[this->fNrowIndex-1] == 0) {
2417 Error(
"operator()(Int_t,Int_t) const",
"row/col indices are not set");
2418 Info(
"operator()",
"fNrowIndex = %d fRowIndex[fNrowIndex-1] = %d\n",this->fNrowIndex,this->fRowIndex[this->fNrowIndex-1]);
2421 const Int_t arown = rown-this->fRowLwb;
2422 const Int_t acoln = coln-this->fColLwb;
2424 if (arown >= this->fNrows || arown < 0) {
2425 Error(
"operator()",
"Request row(%d) outside matrix range of %d - %d",rown,this->fRowLwb,this->fRowLwb+this->fNrows);
2428 if (acoln >= this->fNcols || acoln < 0) {
2429 Error(
"operator()",
"Request column(%d) outside matrix range of %d - %d",coln,this->fColLwb,this->fColLwb+this->fNcols);
2433 const Int_t sIndex = fRowIndex[arown];
2434 const Int_t eIndex = fRowIndex[arown+1];
2436 if (
index < sIndex || fColIndex[
index] != acoln)
return 0.0;
2437 else return fElements[
index];
2444template<
class Element>
2448 Error(
"operator=(const TMatrixTSparse &)",
"matrices not compatible");
2456 Element *
const tp = this->GetMatrixArray();
2457 memcpy(tp,sp,this->fNelems*
sizeof(Element));
2458 this->fTol = source.
GetTol();
2467template<
class Element>
2471 Error(
"operator=(const TMatrixT &)",
"matrices not compatible");
2479 Element *
const tp = this->GetMatrixArray();
2480 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
2481 const Int_t sIndex = fRowIndex[irow];
2482 const Int_t eIndex = fRowIndex[irow+1];
2483 const Int_t off = irow*this->fNcols;
2486 tp[
index] = sp[off+icol];
2489 this->fTol = source.
GetTol();
2498template<
class Element>
2503 if (fRowIndex[this->fNrowIndex-1] == 0) {
2504 Error(
"operator=(Element",
"row/col indices are not set");
2508 Element *ep = this->GetMatrixArray();
2509 const Element *
const ep_last = ep+this->fNelems;
2510 while (ep < ep_last)
2519template<
class Element>
2524 Element *ep = this->GetMatrixArray();
2525 const Element *
const ep_last = ep+this->fNelems;
2526 while (ep < ep_last)
2535template<
class Element>
2540 Element *ep = this->GetMatrixArray();
2541 const Element *
const ep_last = ep+this->fNelems;
2542 while (ep < ep_last)
2551template<
class Element>
2556 Element *ep = this->GetMatrixArray();
2557 const Element *
const ep_last = ep+this->fNelems;
2558 while (ep < ep_last)
2567template<
class Element>
2572 const Element scale = beta-alpha;
2573 const Element shift = alpha/scale;
2575 Int_t *
const pRowIndex = GetRowIndexArray();
2576 Int_t *
const pColIndex = GetColIndexArray();
2577 Element *
const ep = GetMatrixArray();
2579 const Int_t m = this->GetNrows();
2580 const Int_t n = this->GetNcols();
2583 const Int_t nn = this->GetNrows()*this->GetNcols();
2584 const Int_t length = (this->GetNoElements() <= nn) ? this->GetNoElements() : nn;
2588 for (
Int_t k = 0; k < nn; k++) {
2589 const Element
r =
Drand(seed);
2591 if ((nn-k)*
r <
length-chosen) {
2592 pColIndex[chosen] = k%
n;
2595 if (irow > icurrent) {
2596 for ( ; icurrent < irow; icurrent++)
2597 pRowIndex[icurrent+1] = chosen;
2599 ep[chosen] = scale*(
Drand(seed)+shift);
2603 for ( ; icurrent <
m; icurrent++)
2604 pRowIndex[icurrent+1] =
length;
2614template<
class Element>
2617 const Element scale = beta-alpha;
2618 const Element shift = alpha/scale;
2623 if (this->fNrows != this->fNcols || this->fRowLwb != this->fColLwb) {
2624 Error(
"RandomizePD(Element &",
"matrix should be square");
2629 const Int_t n = this->fNcols;
2631 Int_t *
const pRowIndex = this->GetRowIndexArray();
2632 Int_t *
const pColIndex = this->GetColIndexArray();
2633 Element *
const ep = GetMatrixArray();
2640 ep[0] = 1
e-8+scale*(
Drand(seed)+shift);
2660 for (
Int_t k = 0; k < nn; k++ ) {
2661 const Element
r =
Drand(seed);
2663 if( (nn-k)*
r <
length-chosen) {
2670 Int_t col = k-row*(row+1)/2;
2675 if (row > icurrent) {
2679 for ( ; icurrent < row; icurrent++) {
2682 for (
Int_t ll = pRowIndex[icurrent]; ll < nnz; ll++)
2684 ep[nnz] += 1
e-8+scale*(
Drand(seed)+shift);
2685 pColIndex[nnz] = icurrent;
2688 pRowIndex[icurrent+1] = nnz;
2691 ep[nnz] = scale*(
Drand(seed)+shift);
2692 pColIndex[nnz] = col;
2695 ep[pRowIndex[col+1]-1] +=
TMath::Abs(ep[nnz]);
2705 for ( ; icurrent <
n; icurrent++) {
2708 for(
Int_t ll = pRowIndex[icurrent]; ll < nnz; ll++)
2710 ep[nnz] += 1
e-8+scale*(
Drand(seed)+shift);
2711 pColIndex[nnz] = icurrent;
2714 pRowIndex[icurrent+1] = nnz;
2716 this->fNelems = nnz;
2724 const Int_t *
const pR = this->GetRowIndexArray();
2725 const Int_t *
const pC = this->GetColIndexArray();
2726 Element *
const pD = GetMatrixArray();
2727 for (
Int_t irow = 0; irow < this->fNrows+1; irow++) {
2728 const Int_t sIndex = pR[irow];
2729 const Int_t eIndex = pR[irow+1];
2743template<
class Element>
2752template<
class Element>
2761template<
class Element>
2770template<
class Element>
2780template<
class Element>
2790template<
class Element>
2799template<
class Element>
2808template<
class Element>
2817template<
class Element>
2827template<
class Element>
2837template<
class Element>
2846template<
class Element>
2855template<
class Element>
2864template<
class Element>
2874template<
class Element>
2885template<
class Element>
2888 target += scalar * source;
2895template<
class Element>
2899 ::Error(
"ElementMult(TMatrixTSparse &,const TMatrixTSparse &)",
"matrices not compatible");
2904 Element *tp =
target.GetMatrixArray();
2905 const Element *ftp = tp+
target.GetNoElements();
2915template<
class Element>
2919 ::Error(
"ElementDiv(TMatrixT &,const TMatrixT &)",
"matrices not compatible");
2924 Element *tp =
target.GetMatrixArray();
2925 const Element *ftp = tp+
target.GetNoElements();
2926 while ( tp < ftp ) {
2930 Error(
"ElementDiv",
"source element is zero");
2940template<
class Element>
2945 ::Error(
"AreCompatible",
"matrix 1 not valid");
2950 ::Error(
"AreCompatible",
"matrix 2 not valid");
2957 ::Error(
"AreCompatible",
"matrices 1 and 2 not compatible");
2964 if (memcmp(pR1,pR2,(nRows+1)*
sizeof(
Int_t))) {
2966 ::Error(
"AreCompatible",
"matrices 1 and 2 have different rowIndex");
2967 for (
Int_t i = 0; i < nRows+1; i++)
2968 printf(
"%d: %d %d\n",i,pR1[i],pR2[i]);
2974 if (memcmp(pD1,pD2,nData*
sizeof(
Int_t))) {
2976 ::Error(
"AreCompatible",
"matrices 1 and 2 have different colIndex");
2977 for (
Int_t i = 0; i < nData; i++)
2978 printf(
"%d: %d %d\n",i,pD1[i],pD2[i]);
2988template<
class Element>
2996 if (this->fNelems < 0)
#define templateClassImp(name)
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
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.
winID h TVirtualViewer3D TVirtualGLPainter p
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 Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t mask
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 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 .
Int_t ReduceSparseMatrix(Int_t nr, Int_t *row, Int_t *col, Element *data)
Sum matrix entries corresponding to the same matrix element (i,j).
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)
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).
void conservative_sparse_sparse_product_impl(const TMatrixTSparse< Element > &lhs, const TMatrixTSparse< Element > &rhs, Int_t constr=0)
General Sparse Matrix Multiplication (SpMM).
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
RPY_EXPORTED TCppObject_t Allocate(TCppType_t type)
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)