108template<
class Element>
111 Allocate(no_rows,no_cols,0,0,1);
118template <
class Element>
121 Allocate(row_upb - row_lwb + 1, col_upb - col_lwb + 1, row_lwb, col_lwb, 1, nr_nonzeros);
131template<
class Element>
140 if (row[irowmin] < row_lwb || row[irowmax] > row_upb) {
141 Error(
"TMatrixTSparse",
"Inconsistency between row index and its range");
142 if (row[irowmin] < row_lwb) {
143 Info(
"TMatrixTSparse",
"row index lower bound adjusted to %d",row[irowmin]);
144 row_lwb = row[irowmin];
146 if (row[irowmax] > row_upb) {
147 Info(
"TMatrixTSparse",
"row index upper bound adjusted to %d",row[irowmax]);
148 col_lwb = col[irowmax];
151 if (col[icolmin] < col_lwb || col[icolmax] > col_upb) {
152 Error(
"TMatrixTSparse",
"Inconsistency between column index and its range");
153 if (col[icolmin] < col_lwb) {
154 Info(
"TMatrixTSparse",
"column index lower bound adjusted to %d",col[icolmin]);
155 col_lwb = col[icolmin];
157 if (col[icolmax] > col_upb) {
158 Info(
"TMatrixTSparse",
"column index upper bound adjusted to %d",col[icolmax]);
159 col_upb = col[icolmax];
163 Allocate(row_upb-row_lwb+1,col_upb-col_lwb+1,row_lwb,col_lwb,1,nr);
165 SetMatrixArray(nr,row,col,
data);
175template <
class Element>
181 if (
n <= 0 || nr < 0) {
182 Error(
"TMatrixTSparse",
"Inconsistency in row indices");
185 Allocate(row_upb - row_lwb + 1, col_upb - col_lwb + 1, row_lwb, col_lwb, 1, nr);
191 if (col[icolmin] < col_lwb || col[icolmax] > col_upb) {
192 Error(
"TMatrixTSparse",
"Inconsistency between column index and its range");
193 if (col[icolmin] < col_lwb) {
194 Info(
"TMatrixTSparse",
"column index lower bound adjusted to %d", col[icolmin]);
195 col_lwb = col[icolmin];
197 if (col[icolmax] > col_upb) {
198 Info(
"TMatrixTSparse",
"column index upper bound adjusted to %d", col[icolmax]);
199 col_upb = col[icolmax];
203 Allocate(row_upb - row_lwb + 1, col_upb - col_lwb + 1, row_lwb, col_lwb, 1, nr);
204 memcpy(fElements,
data, this->fNelems *
sizeof(Element));
205 memcpy(fRowIndex, rowptr, this->fNrowIndex *
sizeof(
Int_t));
206 memcpy(fColIndex, col, this->fNelems *
sizeof(
Int_t));
212template<
class Element>
225template<
class Element>
238template<
class Element>
243 Int_t nr_nonzeros = 0;
258 for (
Int_t i = rowLwb; i <= rowLwb+nrows-1; i++)
259 for (
Int_t j = colLwb; j <= colLwb+ncols-1; j++)
260 if (i==j) nr_nonzeros++;
261 Allocate(nrows,ncols,rowLwb,colLwb,1,nr_nonzeros);
269 Transpose(prototype);
280 Error(
"TMatrixTSparse(EMatrixCreatorOp1)",
"operation %d not yet implemented", op);
288template<
class Element>
312 Error(
"TMatrixTSparse(EMatrixCreatorOp2)",
"operation %d not yet implemented",op);
320template<
class Element>
344 Error(
"TMatrixTSparse(EMatrixCreatorOp2)",
"operation %d not yet implemented",op);
352template<
class Element>
376 Error(
"TMatrixTSparse(EMatrixCreatorOp2)",
"operation %d not yet implemented",op);
385template<
class Element>
389 if ( (nr_nonzeros > 0 && (no_rows == 0 || no_cols == 0)) ||
390 (no_rows < 0 || no_cols < 0 || nr_nonzeros < 0) )
392 Error(
"Allocate",
"no_rows=%d no_cols=%d non_zeros=%d",no_rows,no_cols,nr_nonzeros);
398 this->fNrows = no_rows;
399 this->fNcols = no_cols;
400 this->fRowLwb = row_lwb;
401 this->fColLwb = col_lwb;
402 this->fNrowIndex = this->fNrows+1;
403 this->fNelems = nr_nonzeros;
404 this->fIsOwner =
kTRUE;
405 this->fTol = std::numeric_limits<Element>::epsilon();
407 fRowIndex =
new Int_t[this->fNrowIndex];
409 memset(fRowIndex,0,this->fNrowIndex*
sizeof(
Int_t));
411 if (this->fNelems > 0) {
412 fElements =
new Element[this->fNelems];
413 fColIndex =
new Int_t [this->fNelems];
415 memset(fElements,0,this->fNelems*
sizeof(Element));
416 memset(fColIndex,0,this->fNelems*
sizeof(
Int_t));
427template<
class Element>
430 const Int_t arown = rown-this->fRowLwb;
431 const Int_t acoln = coln-this->fColLwb;
432 const Int_t nr = (
n > 0) ?
n : this->fNcols;
435 if (arown >= this->fNrows || arown < 0) {
436 Error(
"InsertRow",
"row %d out of matrix range",rown);
440 if (acoln >= this->fNcols || acoln < 0) {
441 Error(
"InsertRow",
"column %d out of matrix range",coln);
445 if (acoln+nr > this->fNcols || nr < 0) {
446 Error(
"InsertRow",
"row length %d out of range",nr);
451 const Int_t sIndex = fRowIndex[arown];
452 const Int_t eIndex = fRowIndex[arown+1];
459 Int_t lIndex = sIndex-1;
460 Int_t rIndex = sIndex-1;
465 if (icol >= acoln+nr)
break;
466 if (icol >= acoln) nslots++;
470 const Int_t nelems_old = this->fNelems;
471 const Int_t *colIndex_old = fColIndex;
472 const Element *elements_old = fElements;
474 const Int_t ndiff = nr-nslots;
475 this->fNelems += ndiff;
476 fColIndex =
new Int_t[this->fNelems];
477 fElements =
new Element[this->fNelems];
479 for (
Int_t irow = arown+1; irow < this->fNrows+1; irow++)
480 fRowIndex[irow] += ndiff;
483 memmove(fColIndex,colIndex_old,(lIndex+1)*
sizeof(
Int_t));
484 memmove(fElements,elements_old,(lIndex+1)*
sizeof(Element));
487 if (nelems_old > 0 && nelems_old-rIndex > 0) {
488 memmove(fColIndex+rIndex+ndiff,colIndex_old+rIndex,(nelems_old-rIndex)*
sizeof(
Int_t));
489 memmove(fElements+rIndex+ndiff,elements_old+rIndex,(nelems_old-rIndex)*
sizeof(Element));
493 for (
Int_t i = 0; i < nr; i++) {
494 fColIndex[
index] = acoln+i;
499 if (colIndex_old)
delete [] (
Int_t*) colIndex_old;
500 if (elements_old)
delete [] (Element*) elements_old;
502 R__ASSERT(this->fNelems == fRowIndex[this->fNrowIndex-1]);
510template<
class Element>
513 const Int_t arown = rown-this->fRowLwb;
514 const Int_t acoln = coln-this->fColLwb;
515 const Int_t nr = (
n > 0) ?
n : this->fNcols;
518 if (arown >= this->fNrows || arown < 0) {
519 Error(
"ExtractRow",
"row %d out of matrix range",rown);
523 if (acoln >= this->fNcols || acoln < 0) {
524 Error(
"ExtractRow",
"column %d out of matrix range",coln);
528 if (acoln+nr > this->fNcols || nr < 0) {
529 Error(
"ExtractRow",
"row length %d out of range",nr);
534 const Int_t sIndex = fRowIndex[arown];
535 const Int_t eIndex = fRowIndex[arown+1];
537 memset(
v,0,nr*
sizeof(Element));
538 const Int_t *
const pColIndex = GetColIndexArray();
539 const Element *
const pData = GetMatrixArray();
542 if (icol < acoln || icol >= acoln+nr)
continue;
543 v[icol-acoln] = pData[
index];
553template <
class Element>
562 Error(
"conservative_sparse_sparse_product_impl",
"lhs and rhs columns incompatible");
573 auto mask = std::unique_ptr<bool[]>(
new bool[rows]);
574 auto values = std::unique_ptr<Element[]>(
new Element[rows]);
575 auto indices = std::unique_ptr<Int_t[]>(
new Int_t[rows]);
577 std::memset(
mask.get(),
false,
sizeof(
bool) * rows);
578 std::memset(values.get(), 0,
sizeof(Element) * rows);
579 std::memset(indices.get(), 0,
sizeof(
Int_t) * rows);
590 Int_t estimated_nnz_prod = 0;
591 for (
Int_t j = 0; j < cols; ++j) {
593 for (
Int_t l = pRowIndexrhs[j];
l < pRowIndexrhs[j + 1]; ++
l) {
595 for (
Int_t m = pRowIndexlhs[k];
m < pRowIndexlhs[k + 1]; ++
m) {
603 estimated_nnz_prod += nnz;
604 std::memset(
mask.get(),
false,
sizeof(
bool) * rows);
607 const Int_t nc = estimated_nnz_prod;
609 Allocate(cols, rows, colsLwb, rowsLwb, 1, nc);
615 Int_t *pRowIndex = this->GetRowIndexArray();
616 Int_t *pColIndex = this->GetColIndexArray();
617 Element *pData = this->GetMatrixArray();
620 for (
Int_t j = 0; j < cols; ++j) {
622 for (
Int_t l = pRowIndexrhs[j];
l < pRowIndexrhs[j + 1]; ++
l) {
623 double y = *(rhsVal +
l);
625 for (
Int_t m = pRowIndexlhs[k];
m < pRowIndexlhs[k + 1]; ++
m) {
627 double x = *(lhsVal +
m);
637 pRowIndex[j + 1] = pRowIndex[j];
638 for (
Int_t i = 0; i < rows; ++i) {
641 Int_t p = pRowIndex[j + 1];
644 pData[
p] = values[i];
650 if (this->fNelems != pRowIndex[cols]) {
651 Error(
"conservative_sparse_sparse_product_impl",
"non zeros numbers do not match");
663template<
class Element>
670 if (
a.GetNcols() !=
b.GetNcols() ||
a.GetColLwb() !=
b.GetColLwb()) {
671 Error(
"AMultBt",
"A and B columns incompatible");
675 if (!constr && this->GetMatrixArray() ==
a.GetMatrixArray()) {
676 Error(
"AMultB",
"this = &a");
680 if (!constr && this->GetMatrixArray() ==
b.GetMatrixArray()) {
681 Error(
"AMultB",
"this = &b");
686 const Int_t *
const pRowIndexa =
a.GetRowIndexArray();
687 const Int_t *
const pColIndexa =
a.GetColIndexArray();
695 Int_t nr_nonzero_rowa = 0;
697 for (
Int_t irowa = 0; irowa <
a.GetNrows(); irowa++)
698 if (pRowIndexa[irowa] < pRowIndexa[irowa+1])
701 Int_t nr_nonzero_rowb =
b.GetNrows();
703 const Int_t nc = nr_nonzero_rowa*nr_nonzero_rowb;
704 Allocate(
a.GetNrows(),
b.GetNrows(),
a.GetRowLwb(),
b.GetRowLwb(),1,nc);
706 pRowIndexc = this->GetRowIndexArray();
707 pColIndexc = this->GetColIndexArray();
711 for (
Int_t irowa = 0; irowa <
a.GetNrows(); irowa++) {
712 pRowIndexc[irowa+1] = pRowIndexc[irowa];
713 for (
Int_t irowb = 0; irowb <
b.GetNrows(); irowb++) {
714 pRowIndexc[irowa+1]++;
715 pColIndexc[ielem++] = irowb;
719 pRowIndexc = this->GetRowIndexArray();
720 pColIndexc = this->GetColIndexArray();
723 const Element *
const pDataa =
a.GetMatrixArray();
724 const Element *
const pDatab =
b.GetMatrixArray();
725 Element *
const pDatac = this->GetMatrixArray();
727 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
728 const Int_t sIndexa = pRowIndexa[irowc];
729 const Int_t eIndexa = pRowIndexa[irowc+1];
730 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
731 const Int_t off = icolc*
b.GetNcols();
733 for (
Int_t indexa = sIndexa; indexa < eIndexa; indexa++) {
734 const Int_t icola = pColIndexa[indexa];
735 sum += pDataa[indexa]*pDatab[off+icola];
738 pColIndexc[indexc_r] = icolc;
739 pDatac[indexc_r] =
sum;
743 pRowIndexc[irowc+1]= indexc_r;
747 SetSparseIndex(indexc_r);
754template<
class Element>
761 if (
a.GetNcols() !=
b.GetNcols() ||
a.GetColLwb() !=
b.GetColLwb()) {
762 Error(
"AMultBt",
"A and B columns incompatible");
766 if (!constr && this->GetMatrixArray() ==
a.GetMatrixArray()) {
767 Error(
"AMultB",
"this = &a");
771 if (!constr && this->GetMatrixArray() ==
b.GetMatrixArray()) {
772 Error(
"AMultB",
"this = &b");
777 const Int_t *
const pRowIndexb =
b.GetRowIndexArray();
778 const Int_t *
const pColIndexb =
b.GetColIndexArray();
786 Int_t nr_nonzero_rowa =
a.GetNrows();
787 Int_t nr_nonzero_rowb = 0;
789 for (
Int_t irowb = 0; irowb <
b.GetNrows(); irowb++)
790 if (pRowIndexb[irowb] < pRowIndexb[irowb+1])
794 const Int_t nc = nr_nonzero_rowa*nr_nonzero_rowb;
795 Allocate(
a.GetNrows(),
b.GetNrows(),
a.GetRowLwb(),
b.GetRowLwb(),1,nc);
797 pRowIndexc = this->GetRowIndexArray();
798 pColIndexc = this->GetColIndexArray();
802 for (
Int_t irowa = 0; irowa <
a.GetNrows(); irowa++) {
803 pRowIndexc[irowa+1] = pRowIndexc[irowa];
804 for (
Int_t irowb = 0; irowb <
b.GetNrows(); irowb++) {
805 if (pRowIndexb[irowb] >= pRowIndexb[irowb+1])
continue;
806 pRowIndexc[irowa+1]++;
807 pColIndexc[ielem++] = irowb;
811 pRowIndexc = this->GetRowIndexArray();
812 pColIndexc = this->GetColIndexArray();
815 const Element *
const pDataa =
a.GetMatrixArray();
816 const Element *
const pDatab =
b.GetMatrixArray();
817 Element *
const pDatac = this->GetMatrixArray();
819 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
820 const Int_t off = irowc*
a.GetNcols();
821 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
822 const Int_t sIndexb = pRowIndexb[icolc];
823 const Int_t eIndexb = pRowIndexb[icolc+1];
825 for (
Int_t indexb = sIndexb; indexb < eIndexb; indexb++) {
826 const Int_t icolb = pColIndexb[indexb];
827 sum += pDataa[off+icolb]*pDatab[indexb];
830 pColIndexc[indexc_r] = icolc;
831 pDatac[indexc_r] =
sum;
835 pRowIndexc[irowc+1] = indexc_r;
839 SetSparseIndex(indexc_r);
846template<
class Element>
853 if (
a.GetNrows() !=
b.GetNrows() ||
a.GetNcols() !=
b.GetNcols() ||
854 a.GetRowLwb() !=
b.GetRowLwb() ||
a.GetColLwb() !=
b.GetColLwb()) {
855 Error(
"APlusB(const TMatrixTSparse &,const TMatrixTSparse &",
"matrices not compatible");
859 if (!constr && this->GetMatrixArray() ==
a.GetMatrixArray()) {
860 Error(
"APlusB",
"this = &a");
864 if (!constr && this->GetMatrixArray() ==
b.GetMatrixArray()) {
865 Error(
"APlusB",
"this = &b");
870 const Int_t *
const pRowIndexa =
a.GetRowIndexArray();
871 const Int_t *
const pRowIndexb =
b.GetRowIndexArray();
872 const Int_t *
const pColIndexa =
a.GetColIndexArray();
873 const Int_t *
const pColIndexb =
b.GetColIndexArray();
876 Allocate(
a.GetNrows(),
a.GetNcols(),
a.GetRowLwb(),
a.GetColLwb());
877 SetSparseIndexAB(
a,
b);
880 Int_t *
const pRowIndexc = this->GetRowIndexArray();
881 Int_t *
const pColIndexc = this->GetColIndexArray();
883 const Element *
const pDataa =
a.GetMatrixArray();
884 const Element *
const pDatab =
b.GetMatrixArray();
885 Element *
const pDatac = this->GetMatrixArray();
887 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
888 const Int_t sIndexa = pRowIndexa[irowc];
889 const Int_t eIndexa = pRowIndexa[irowc+1];
890 const Int_t sIndexb = pRowIndexb[irowc];
891 const Int_t eIndexb = pRowIndexb[irowc+1];
892 Int_t indexa = sIndexa;
893 Int_t indexb = sIndexb;
894 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
896 while (indexa < eIndexa && pColIndexa[indexa] <= icolc) {
897 if (icolc == pColIndexa[indexa]) {
898 sum += pDataa[indexa];
903 while (indexb < eIndexb && pColIndexb[indexb] <= icolc) {
904 if (icolc == pColIndexb[indexb]) {
905 sum += pDatab[indexb];
912 pColIndexc[indexc_r] = icolc;
913 pDatac[indexc_r] =
sum;
917 pRowIndexc[irowc+1] = indexc_r;
921 SetSparseIndex(indexc_r);
928template<
class Element>
935 if (
a.GetNrows() !=
b.GetNrows() ||
a.GetNcols() !=
b.GetNcols() ||
936 a.GetRowLwb() !=
b.GetRowLwb() ||
a.GetColLwb() !=
b.GetColLwb()) {
937 Error(
"APlusB(const TMatrixTSparse &,const TMatrixT &",
"matrices not compatible");
941 if (!constr && this->GetMatrixArray() ==
a.GetMatrixArray()) {
942 Error(
"APlusB",
"this = &a");
946 if (!constr && this->GetMatrixArray() ==
b.GetMatrixArray()) {
947 Error(
"APlusB",
"this = &b");
953 Allocate(
a.GetNrows(),
a.GetNcols(),
a.GetRowLwb(),
a.GetColLwb());
954 SetSparseIndexAB(
a,
b);
957 Int_t *
const pRowIndexc = this->GetRowIndexArray();
958 Int_t *
const pColIndexc = this->GetColIndexArray();
960 const Int_t *
const pRowIndexa =
a.GetRowIndexArray();
961 const Int_t *
const pColIndexa =
a.GetColIndexArray();
963 const Element *
const pDataa =
a.GetMatrixArray();
964 const Element *
const pDatab =
b.GetMatrixArray();
965 Element *
const pDatac = this->GetMatrixArray();
967 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
968 const Int_t sIndexa = pRowIndexa[irowc];
969 const Int_t eIndexa = pRowIndexa[irowc+1];
970 const Int_t off = irowc*this->GetNcols();
971 Int_t indexa = sIndexa;
972 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
973 Element
sum = pDatab[off+icolc];
974 while (indexa < eIndexa && pColIndexa[indexa] <= icolc) {
975 if (icolc == pColIndexa[indexa]) {
976 sum += pDataa[indexa];
983 pColIndexc[indexc_r] = icolc;
984 pDatac[indexc_r] =
sum;
988 pRowIndexc[irowc+1] = indexc_r;
992 SetSparseIndex(indexc_r);
999template<
class Element>
1006 if (
a.GetNrows() !=
b.GetNrows() ||
a.GetNcols() !=
b.GetNcols() ||
1007 a.GetRowLwb() !=
b.GetRowLwb() ||
a.GetColLwb() !=
b.GetColLwb()) {
1008 Error(
"AMinusB(const TMatrixTSparse &,const TMatrixTSparse &",
"matrices not compatible");
1012 if (!constr && this->GetMatrixArray() ==
a.GetMatrixArray()) {
1013 Error(
"AMinusB",
"this = &a");
1017 if (!constr && this->GetMatrixArray() ==
b.GetMatrixArray()) {
1018 Error(
"AMinusB",
"this = &b");
1023 const Int_t *
const pRowIndexa =
a.GetRowIndexArray();
1024 const Int_t *
const pRowIndexb =
b.GetRowIndexArray();
1025 const Int_t *
const pColIndexa =
a.GetColIndexArray();
1026 const Int_t *
const pColIndexb =
b.GetColIndexArray();
1029 Allocate(
a.GetNrows(),
a.GetNcols(),
a.GetRowLwb(),
a.GetColLwb());
1030 SetSparseIndexAB(
a,
b);
1033 Int_t *
const pRowIndexc = this->GetRowIndexArray();
1034 Int_t *
const pColIndexc = this->GetColIndexArray();
1036 const Element *
const pDataa =
a.GetMatrixArray();
1037 const Element *
const pDatab =
b.GetMatrixArray();
1038 Element *
const pDatac = this->GetMatrixArray();
1040 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
1041 const Int_t sIndexa = pRowIndexa[irowc];
1042 const Int_t eIndexa = pRowIndexa[irowc+1];
1043 const Int_t sIndexb = pRowIndexb[irowc];
1044 const Int_t eIndexb = pRowIndexb[irowc+1];
1045 Int_t indexa = sIndexa;
1046 Int_t indexb = sIndexb;
1047 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
1049 while (indexa < eIndexa && pColIndexa[indexa] <= icolc) {
1050 if (icolc == pColIndexa[indexa]) {
1051 sum += pDataa[indexa];
1056 while (indexb < eIndexb && pColIndexb[indexb] <= icolc) {
1057 if (icolc == pColIndexb[indexb]) {
1058 sum -= pDatab[indexb];
1065 pColIndexc[indexc_r] = icolc;
1066 pDatac[indexc_r] =
sum;
1070 pRowIndexc[irowc+1] = indexc_r;
1074 SetSparseIndex(indexc_r);
1081template<
class Element>
1088 if (
a.GetNrows() !=
b.GetNrows() ||
a.GetNcols() !=
b.GetNcols() ||
1089 a.GetRowLwb() !=
b.GetRowLwb() ||
a.GetColLwb() !=
b.GetColLwb()) {
1090 Error(
"AMinusB(const TMatrixTSparse &,const TMatrixT &",
"matrices not compatible");
1094 if (!constr && this->GetMatrixArray() ==
a.GetMatrixArray()) {
1095 Error(
"AMinusB",
"this = &a");
1099 if (!constr && this->GetMatrixArray() ==
b.GetMatrixArray()) {
1100 Error(
"AMinusB",
"this = &b");
1106 Allocate(
a.GetNrows(),
a.GetNcols(),
a.GetRowLwb(),
a.GetColLwb());
1107 SetSparseIndexAB(
a,
b);
1110 Int_t *
const pRowIndexc = this->GetRowIndexArray();
1111 Int_t *
const pColIndexc = this->GetColIndexArray();
1113 const Int_t *
const pRowIndexa =
a.GetRowIndexArray();
1114 const Int_t *
const pColIndexa =
a.GetColIndexArray();
1116 const Element *
const pDataa =
a.GetMatrixArray();
1117 const Element *
const pDatab =
b.GetMatrixArray();
1118 Element *
const pDatac = this->GetMatrixArray();
1120 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
1121 const Int_t sIndexa = pRowIndexa[irowc];
1122 const Int_t eIndexa = pRowIndexa[irowc+1];
1123 const Int_t off = irowc*this->GetNcols();
1124 Int_t indexa = sIndexa;
1125 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
1126 Element
sum = -pDatab[off+icolc];
1127 while (indexa < eIndexa && pColIndexa[indexa] <= icolc) {
1128 if (icolc == pColIndexa[indexa]) {
1129 sum += pDataa[indexa];
1136 pColIndexc[indexc_r] = icolc;
1137 pDatac[indexc_r] =
sum;
1141 pRowIndexc[irowc+1] = indexc_r;
1145 SetSparseIndex(indexc_r);
1152template<
class Element>
1159 if (
a.GetNrows() !=
b.GetNrows() ||
a.GetNcols() !=
b.GetNcols() ||
1160 a.GetRowLwb() !=
b.GetRowLwb() ||
a.GetColLwb() !=
b.GetColLwb()) {
1161 Error(
"AMinusB(const TMatrixT &,const TMatrixTSparse &",
"matrices not compatible");
1165 if (!constr && this->GetMatrixArray() ==
a.GetMatrixArray()) {
1166 Error(
"AMinusB",
"this = &a");
1170 if (!constr && this->GetMatrixArray() ==
b.GetMatrixArray()) {
1171 Error(
"AMinusB",
"this = &b");
1177 Allocate(
a.GetNrows(),
a.GetNcols(),
a.GetRowLwb(),
a.GetColLwb());
1178 SetSparseIndexAB(
a,
b);
1181 Int_t *
const pRowIndexc = this->GetRowIndexArray();
1182 Int_t *
const pColIndexc = this->GetColIndexArray();
1184 const Int_t *
const pRowIndexb =
b.GetRowIndexArray();
1185 const Int_t *
const pColIndexb =
b.GetColIndexArray();
1187 const Element *
const pDataa =
a.GetMatrixArray();
1188 const Element *
const pDatab =
b.GetMatrixArray();
1189 Element *
const pDatac = this->GetMatrixArray();
1191 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
1192 const Int_t sIndexb = pRowIndexb[irowc];
1193 const Int_t eIndexb = pRowIndexb[irowc+1];
1194 const Int_t off = irowc*this->GetNcols();
1195 Int_t indexb = sIndexb;
1196 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
1197 Element
sum = pDataa[off+icolc];
1198 while (indexb < eIndexb && pColIndexb[indexb] <= icolc) {
1199 if (icolc == pColIndexb[indexb]) {
1200 sum -= pDatab[indexb];
1207 pColIndexc[indexc_r] = icolc;
1208 pDatac[indexc_r] =
sum;
1212 pRowIndexc[irowc+1] = indexc_r;
1216 SetSparseIndex(indexc_r);
1222template<
class Element>
1227 const Element *
const elem = GetMatrixArray();
1228 memcpy(
data,elem,this->fNelems*
sizeof(Element));
1236template<
class Element>
1241 Error(
"SetMatrixArray(Int_t,Int_t*,Int_t*,Element*",
"nr <= 0");
1250 R__ASSERT(row[irowmin] >= this->fRowLwb && row[irowmax] <= this->fRowLwb+this->fNrows-1);
1251 R__ASSERT(col[icolmin] >= this->fColLwb && col[icolmax] <= this->fColLwb+this->fNcols-1);
1253 if (row[irowmin] < this->fRowLwb|| row[irowmax] > this->fRowLwb+this->fNrows-1) {
1254 Error(
"SetMatrixArray",
"Inconsistency between row index and its range");
1255 if (row[irowmin] < this->fRowLwb) {
1256 Info(
"SetMatrixArray",
"row index lower bound adjusted to %d",row[irowmin]);
1257 this->fRowLwb = row[irowmin];
1259 if (row[irowmax] > this->fRowLwb+this->fNrows-1) {
1260 Info(
"SetMatrixArray",
"row index upper bound adjusted to %d",row[irowmax]);
1261 this->fNrows = row[irowmax]-this->fRowLwb+1;
1264 if (col[icolmin] < this->fColLwb || col[icolmax] > this->fColLwb+this->fNcols-1) {
1265 Error(
"SetMatrixArray",
"Inconsistency between column index and its range");
1266 if (col[icolmin] < this->fColLwb) {
1267 Info(
"SetMatrixArray",
"column index lower bound adjusted to %d",col[icolmin]);
1268 this->fColLwb = col[icolmin];
1270 if (col[icolmax] > this->fColLwb+this->fNcols-1) {
1271 Info(
"SetMatrixArray",
"column index upper bound adjusted to %d",col[icolmax]);
1272 this->fNcols = col[icolmax]-this->fColLwb+1;
1277 nr = ReduceSparseMatrix(nr, row, col,
data);
1279 Int_t nr_nonzeros = 0;
1280 const Element *ep =
data;
1281 const Element *
const fp =
data+nr;
1284 if (*ep++ != 0.0) nr_nonzeros++;
1286 if (nr_nonzeros != this->fNelems) {
1287 if (fColIndex) {
delete [] fColIndex; fColIndex =
nullptr; }
1288 if (fElements) {
delete [] fElements; fElements =
nullptr; }
1289 this->fNelems = nr_nonzeros;
1290 if (this->fNelems > 0) {
1291 fColIndex =
new Int_t[nr_nonzeros];
1292 fElements =
new Element[nr_nonzeros];
1294 fColIndex =
nullptr;
1295 fElements =
nullptr;
1299 if (this->fNelems <= 0)
1305 for (
Int_t irow = 1; irow < this->fNrows+1; irow++) {
1306 if (ielem < nr && row[ielem] - this->fRowLwb < irow) {
1307 while (ielem < nr) {
1308 if (
data[ielem] != 0.0) {
1309 fColIndex[nr_nonzeros] = col[ielem]-this->fColLwb;
1310 fElements[nr_nonzeros] =
data[ielem];
1314 if (ielem >= nr || row[ielem] != row[ielem-1])
1318 fRowIndex[irow] = nr_nonzeros;
1329template <
class Element>
1336 while (i < nz - 1) {
1337 if ((row[i] == row[i + 1]) && (col[i] == col[i + 1])) {
1342 for (
Int_t j = i + 1; j < nz; j++) {
1344 row[j] = row[j + 1];
1345 col[j] = col[j + 1];
1354template <
class Element>
1360 Error(
"SetMatrixArray(Int_t,Int_t*,Int_t*,Element*",
"nr <= 0");
1364 if (nrows != this->fNrows) {
1367 fRowIndex =
nullptr;
1369 this->fNrows = nrows;
1370 if (this->fNrows > 0) {
1371 fRowIndex =
new Int_t[nrows + 1];
1372 this->fNrowIndex = nrows + 1;
1374 fRowIndex =
nullptr;
1375 this->fNrowIndex = 0;
1379 if (ncols != this->fNcols) {
1380 this->fNcols = ncols;
1383 if (this->fRowLwb != this->fColLwb) {
1384 auto tmp = this->fRowLwb;
1385 this->fRowLwb = this->fColLwb;
1386 this->fColLwb = tmp;
1394 R__ASSERT(row[irowmin] >= this->fRowLwb && row[irowmax] <= this->fRowLwb + this->fNrows - 1);
1395 R__ASSERT(col[icolmin] >= this->fColLwb && col[icolmax] <= this->fColLwb + this->fNcols - 1);
1397 if (row[irowmin] < this->fRowLwb || row[irowmax] > this->fRowLwb + this->fNrows - 1) {
1398 Error(
"SetMatrixArray",
"Inconsistency between row index and its range");
1399 if (row[irowmin] < this->fRowLwb) {
1400 Info(
"SetMatrixArray",
"row index lower bound adjusted to %d", row[irowmin]);
1401 this->fRowLwb = row[irowmin];
1403 if (row[irowmax] > this->fRowLwb + this->fNrows - 1) {
1404 Info(
"SetMatrixArray",
"row index upper bound adjusted to %d", row[irowmax]);
1405 this->fNrows = row[irowmax] - this->fRowLwb + 1;
1408 if (col[icolmin] < this->fColLwb || col[icolmax] > this->fColLwb + this->fNcols - 1) {
1409 Error(
"SetMatrixArray",
"Inconsistency between column index and its range");
1410 if (col[icolmin] < this->fColLwb) {
1411 Info(
"SetMatrixArray",
"column index lower bound adjusted to %d", col[icolmin]);
1412 this->fColLwb = col[icolmin];
1414 if (col[icolmax] > this->fColLwb + this->fNcols - 1) {
1415 Info(
"SetMatrixArray",
"column index upper bound adjusted to %d", col[icolmax]);
1416 this->fNcols = col[icolmax] - this->fColLwb + 1;
1421 nr = ReduceSparseMatrix(nr, row, col,
data);
1423 Int_t nr_nonzeros = 0;
1424 const Element *ep =
data;
1425 const Element *
const fp =
data + nr;
1431 if (nr_nonzeros != this->fNelems) {
1434 fColIndex =
nullptr;
1438 fElements =
nullptr;
1440 this->fNelems = nr_nonzeros;
1441 if (this->fNelems > 0) {
1442 fColIndex =
new Int_t[nr_nonzeros];
1443 fElements =
new Element[nr_nonzeros];
1445 fColIndex =
nullptr;
1446 fElements =
nullptr;
1450 if (this->fNelems <= 0)
1456 for (
Int_t irow = 1; irow < this->fNrows + 1; irow++) {
1457 if (ielem < nr && row[ielem] - this->fRowLwb < irow) {
1458 while (ielem < nr) {
1459 if (
data[ielem] != 0.0) {
1460 fColIndex[nr_nonzeros] = col[ielem] - this->fColLwb;
1461 fElements[nr_nonzeros] =
data[ielem];
1465 if (ielem >= nr || row[ielem] != row[ielem - 1])
1469 fRowIndex[irow] = nr_nonzeros;
1478template<
class Element>
1481 if (nelems_new != this->fNelems) {
1483 Int_t *oIp = fColIndex;
1484 fColIndex =
new Int_t[nelems_new];
1486 memmove(fColIndex,oIp,nr*
sizeof(
Int_t));
1489 Element *oDp = fElements;
1490 fElements =
new Element[nelems_new];
1492 memmove(fElements,oDp,nr*
sizeof(Element));
1495 this->fNelems = nelems_new;
1496 if (nelems_new > nr) {
1497 memset(fElements+nr,0,(nelems_new-nr)*
sizeof(Element));
1498 memset(fColIndex+nr,0,(nelems_new-nr)*
sizeof(
Int_t));
1500 for (
Int_t irow = 0; irow < this->fNrowIndex; irow++)
1501 if (fRowIndex[irow] > nelems_new)
1502 fRowIndex[irow] = nelems_new;
1512template<
class Element>
1517 if (this->GetNrows() != source.
GetNrows() || this->GetNcols() != source.
GetNcols() ||
1518 this->GetRowLwb() != source.
GetRowLwb() || this->GetColLwb() != source.
GetColLwb()) {
1519 Error(
"SetSparseIndex",
"matrices not compatible");
1526 if (nr_nonzeros != this->fNelems)
1527 SetSparseIndex(nr_nonzeros);
1535 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
1536 fRowIndex[irow] = nr;
1537 for (
Int_t icol = 0; icol < this->fNcols; icol++) {
1539 fColIndex[nr] = icol;
1545 fRowIndex[this->fNrows] = nr;
1555template<
class Element>
1562 if (
a.GetNrows() !=
b.GetNrows() ||
a.GetNcols() !=
b.GetNcols() ||
1563 a.GetRowLwb() !=
b.GetRowLwb() ||
a.GetColLwb() !=
b.GetColLwb()) {
1564 Error(
"SetSparseIndexAB",
"source matrices not compatible");
1568 if (this->GetNrows() !=
a.GetNrows() || this->GetNcols() !=
a.GetNcols() ||
1569 this->GetRowLwb() !=
a.GetRowLwb() || this->GetColLwb() !=
a.GetColLwb()) {
1570 Error(
"SetSparseIndexAB",
"matrix not compatible with source matrices");
1575 const Int_t *
const pRowIndexa =
a.GetRowIndexArray();
1576 const Int_t *
const pRowIndexb =
b.GetRowIndexArray();
1577 const Int_t *
const pColIndexa =
a.GetColIndexArray();
1578 const Int_t *
const pColIndexb =
b.GetColIndexArray();
1582 for (
Int_t irowc = 0; irowc <
a.GetNrows(); irowc++) {
1583 const Int_t sIndexa = pRowIndexa[irowc];
1584 const Int_t eIndexa = pRowIndexa[irowc+1];
1585 const Int_t sIndexb = pRowIndexb[irowc];
1586 const Int_t eIndexb = pRowIndexb[irowc+1];
1587 nc += eIndexa-sIndexa;
1588 Int_t indexb = sIndexb;
1589 for (
Int_t indexa = sIndexa; indexa < eIndexa; indexa++) {
1590 const Int_t icola = pColIndexa[indexa];
1591 for (; indexb < eIndexb; indexb++) {
1592 if (pColIndexb[indexb] >= icola) {
1593 if (pColIndexb[indexb] == icola)
1600 while (indexb < eIndexb) {
1601 const Int_t icola = (eIndexa > sIndexa && eIndexa > 0) ? pColIndexa[eIndexa-1] : -1;
1602 if (pColIndexb[indexb++] > icola)
1608 if (this->NonZeros() != nc)
1611 Int_t *
const pRowIndexc = this->GetRowIndexArray();
1612 Int_t *
const pColIndexc = this->GetColIndexArray();
1616 for (
Int_t irowc = 0; irowc <
a.GetNrows(); irowc++) {
1617 const Int_t sIndexa = pRowIndexa[irowc];
1618 const Int_t eIndexa = pRowIndexa[irowc+1];
1619 const Int_t sIndexb = pRowIndexb[irowc];
1620 const Int_t eIndexb = pRowIndexb[irowc+1];
1621 Int_t indexb = sIndexb;
1622 for (
Int_t indexa = sIndexa; indexa < eIndexa; indexa++) {
1623 const Int_t icola = pColIndexa[indexa];
1624 for (; indexb < eIndexb; indexb++) {
1625 if (pColIndexb[indexb] >= icola) {
1626 if (pColIndexb[indexb] == icola)
1630 pColIndexc[nc++] = pColIndexb[indexb];
1632 pColIndexc[nc++] = pColIndexa[indexa];
1634 while (indexb < eIndexb) {
1635 const Int_t icola = (eIndexa > 0) ? pColIndexa[eIndexa-1] : -1;
1636 if (pColIndexb[indexb++] > icola)
1637 pColIndexc[nc++] = pColIndexb[indexb-1];
1639 pRowIndexc[irowc+1] = nc;
1649template<
class Element>
1656 if (
a.GetNrows() !=
b.GetNrows() ||
a.GetNcols() !=
b.GetNcols() ||
1657 a.GetRowLwb() !=
b.GetRowLwb() ||
a.GetColLwb() !=
b.GetColLwb()) {
1658 Error(
"SetSparseIndexAB",
"source matrices not compatible");
1662 if (this->GetNrows() !=
a.GetNrows() || this->GetNcols() !=
a.GetNcols() ||
1663 this->GetRowLwb() !=
a.GetRowLwb() || this->GetColLwb() !=
a.GetColLwb()) {
1664 Error(
"SetSparseIndexAB",
"matrix not compatible with source matrices");
1669 const Element *
const pDataa =
a.GetMatrixArray();
1671 const Int_t *
const pRowIndexb =
b.GetRowIndexArray();
1672 const Int_t *
const pColIndexb =
b.GetColIndexArray();
1676 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
1677 const Int_t sIndexb = pRowIndexb[irowc];
1678 const Int_t eIndexb = pRowIndexb[irowc+1];
1679 const Int_t off = irowc*this->GetNcols();
1680 Int_t indexb = sIndexb;
1681 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
1682 if (pDataa[off+icolc] != 0.0 || pColIndexb[indexb] > icolc)
continue;
1683 for (; indexb < eIndexb; indexb++) {
1684 if (pColIndexb[indexb] >= icolc) {
1685 if (pColIndexb[indexb] == icolc) {
1696 if (this->NonZeros() != nc)
1699 Int_t *
const pRowIndexc = this->GetRowIndexArray();
1700 Int_t *
const pColIndexc = this->GetColIndexArray();
1704 for (
Int_t irowc = 0; irowc < this->GetNrows(); irowc++) {
1705 const Int_t sIndexb = pRowIndexb[irowc];
1706 const Int_t eIndexb = pRowIndexb[irowc+1];
1707 const Int_t off = irowc*this->GetNcols();
1708 Int_t indexb = sIndexb;
1709 for (
Int_t icolc = 0; icolc < this->GetNcols(); icolc++) {
1710 if (pDataa[off+icolc] != 0.0)
1711 pColIndexc[nc++] = icolc;
1712 else if (pColIndexb[indexb] <= icolc) {
1713 for (; indexb < eIndexb; indexb++) {
1714 if (pColIndexb[indexb] >= icolc) {
1715 if (pColIndexb[indexb] == icolc)
1716 pColIndexc[nc++] = pColIndexb[indexb++];
1722 pRowIndexc[irowc+1] = nc;
1734template<
class Element>
1738 if (!this->fIsOwner) {
1739 Error(
"ResizeTo(Int_t,Int_t,Int_t)",
"Not owner of data array,cannot resize");
1743 if (this->fNelems > 0) {
1744 if (this->fNrows == nrows && this->fNcols == ncols &&
1745 (this->fNelems == nr_nonzeros || nr_nonzeros < 0))
1747 else if (nrows == 0 || ncols == 0 || nr_nonzeros == 0) {
1748 this->fNrows = nrows; this->fNcols = ncols;
1753 const Element *elements_old = GetMatrixArray();
1754 const Int_t *rowIndex_old = GetRowIndexArray();
1755 const Int_t *colIndex_old = GetColIndexArray();
1757 Int_t nrows_old = this->fNrows;
1758 Int_t nrowIndex_old = this->fNrowIndex;
1761 if (nr_nonzeros > 0)
1762 nelems_new = nr_nonzeros;
1765 for (
Int_t irow = 0; irow < nrows_old; irow++) {
1766 if (irow >= nrows)
continue;
1767 const Int_t sIndex = rowIndex_old[irow];
1768 const Int_t eIndex = rowIndex_old[irow+1];
1777 Allocate(nrows,ncols,0,0,1,nelems_new);
1780 Element *elements_new = GetMatrixArray();
1781 Int_t *rowIndex_new = GetRowIndexArray();
1782 Int_t *colIndex_new = GetColIndexArray();
1784 Int_t nelems_copy = 0;
1785 rowIndex_new[0] = 0;
1787 for (
Int_t irow = 0; irow < nrows_old && cont; irow++) {
1788 if (irow >= nrows)
continue;
1789 const Int_t sIndex = rowIndex_old[irow];
1790 const Int_t eIndex = rowIndex_old[irow+1];
1794 rowIndex_new[irow+1] = nelems_copy+1;
1795 colIndex_new[nelems_copy] = icol;
1796 elements_new[nelems_copy] = elements_old[
index];
1799 if (nelems_copy >= nelems_new) {
1806 if (rowIndex_old)
delete [] (
Int_t*) rowIndex_old;
1807 if (colIndex_old)
delete [] (
Int_t*) colIndex_old;
1808 if (elements_old)
delete [] (Element*) elements_old;
1810 if (nrowIndex_old < this->fNrowIndex) {
1811 for (
Int_t irow = nrowIndex_old; irow < this->fNrowIndex; irow++)
1812 rowIndex_new[irow] = rowIndex_new[nrowIndex_old-1];
1815 const Int_t nelems_new = (nr_nonzeros >= 0) ? nr_nonzeros : 0;
1816 Allocate(nrows,ncols,0,0,1,nelems_new);
1828template<
class Element>
1833 if (!this->fIsOwner) {
1834 Error(
"ResizeTo(Int_t,Int_t,Int_t,Int_t,Int_t)",
"Not owner of data array,cannot resize");
1838 const Int_t new_nrows = row_upb-row_lwb+1;
1839 const Int_t new_ncols = col_upb-col_lwb+1;
1841 if (this->fNelems > 0) {
1842 if (this->fNrows == new_nrows && this->fNcols == new_ncols &&
1843 this->fRowLwb == row_lwb && this->fColLwb == col_lwb &&
1844 (this->fNelems == nr_nonzeros || nr_nonzeros < 0))
1846 else if (new_nrows == 0 || new_ncols == 0 || nr_nonzeros == 0) {
1847 this->fNrows = new_nrows; this->fNcols = new_ncols;
1848 this->fRowLwb = row_lwb; this->fColLwb = col_lwb;
1853 const Int_t *rowIndex_old = GetRowIndexArray();
1854 const Int_t *colIndex_old = GetColIndexArray();
1855 const Element *elements_old = GetMatrixArray();
1857 const Int_t nrowIndex_old = this->fNrowIndex;
1859 const Int_t nrows_old = this->fNrows;
1860 const Int_t rowLwb_old = this->fRowLwb;
1861 const Int_t colLwb_old = this->fColLwb;
1864 if (nr_nonzeros > 0)
1865 nelems_new = nr_nonzeros;
1868 for (
Int_t irow = 0; irow < nrows_old; irow++) {
1869 if (irow+rowLwb_old > row_upb || irow+rowLwb_old < row_lwb)
continue;
1870 const Int_t sIndex = rowIndex_old[irow];
1871 const Int_t eIndex = rowIndex_old[irow+1];
1874 if (icol+colLwb_old <= col_upb && icol+colLwb_old >= col_lwb)
1880 Allocate(new_nrows,new_ncols,row_lwb,col_lwb,1,nelems_new);
1883 Int_t *rowIndex_new = GetRowIndexArray();
1884 Int_t *colIndex_new = GetColIndexArray();
1885 Element *elements_new = GetMatrixArray();
1887 Int_t nelems_copy = 0;
1888 rowIndex_new[0] = 0;
1889 const Int_t row_off = rowLwb_old-row_lwb;
1890 const Int_t col_off = colLwb_old-col_lwb;
1891 for (
Int_t irow = 0; irow < nrows_old; irow++) {
1892 if (irow+rowLwb_old > row_upb || irow+rowLwb_old < row_lwb)
continue;
1893 const Int_t sIndex = rowIndex_old[irow];
1894 const Int_t eIndex = rowIndex_old[irow+1];
1897 if (icol+colLwb_old <= col_upb && icol+colLwb_old >= col_lwb) {
1898 rowIndex_new[irow+row_off+1] = nelems_copy+1;
1899 colIndex_new[nelems_copy] = icol+col_off;
1900 elements_new[nelems_copy] = elements_old[
index];
1903 if (nelems_copy >= nelems_new) {
1909 if (rowIndex_old)
delete [] (
Int_t*) rowIndex_old;
1910 if (colIndex_old)
delete [] (
Int_t*) colIndex_old;
1911 if (elements_old)
delete [] (Element*) elements_old;
1913 if (nrowIndex_old < this->fNrowIndex) {
1914 for (
Int_t irow = nrowIndex_old; irow < this->fNrowIndex; irow++)
1915 rowIndex_new[irow] = rowIndex_new[nrowIndex_old-1];
1918 const Int_t nelems_new = (nr_nonzeros >= 0) ? nr_nonzeros : 0;
1919 Allocate(new_nrows,new_ncols,row_lwb,col_lwb,1,nelems_new);
1927template<
class Element>
1932 if (row_upb < row_lwb) {
1933 Error(
"Use",
"row_upb=%d < row_lwb=%d",row_upb,row_lwb);
1936 if (col_upb < col_lwb) {
1937 Error(
"Use",
"col_upb=%d < col_lwb=%d",col_upb,col_lwb);
1944 this->fNrows = row_upb-row_lwb+1;
1945 this->fNcols = col_upb-col_lwb+1;
1946 this->fRowLwb = row_lwb;
1947 this->fColLwb = col_lwb;
1948 this->fNrowIndex = this->fNrows+1;
1949 this->fNelems = nr_nonzeros;
1951 this->fTol = std::numeric_limits<Element>::epsilon();
1954 fRowIndex = pRowIndex;
1955 fColIndex = pColIndex;
1967template<
class Element>
1973 if (row_lwb < this->fRowLwb || row_lwb > this->fRowLwb+this->fNrows-1) {
1974 Error(
"GetSub",
"row_lwb out-of-bounds");
1977 if (col_lwb < this->fColLwb || col_lwb > this->fColLwb+this->fNcols-1) {
1978 Error(
"GetSub",
"col_lwb out-of-bounds");
1981 if (row_upb < this->fRowLwb || row_upb > this->fRowLwb+this->fNrows-1) {
1982 Error(
"GetSub",
"row_upb out-of-bounds");
1985 if (col_upb < this->fColLwb || col_upb > this->fColLwb+this->fNcols-1) {
1986 Error(
"GetSub",
"col_upb out-of-bounds");
1989 if (row_upb < row_lwb || col_upb < col_lwb) {
1990 Error(
"GetSub",
"row_upb < row_lwb || col_upb < col_lwb");
1999 const Int_t row_lwb_sub = (shift) ? 0 : row_lwb;
2000 const Int_t row_upb_sub = (shift) ? row_upb-row_lwb : row_upb;
2001 const Int_t col_lwb_sub = (shift) ? 0 : col_lwb;
2002 const Int_t col_upb_sub = (shift) ? col_upb-col_lwb : col_upb;
2004 Int_t nr_nonzeros = 0;
2005 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
2006 if (irow+this->fRowLwb > row_upb || irow+this->fRowLwb < row_lwb)
continue;
2007 const Int_t sIndex = fRowIndex[irow];
2008 const Int_t eIndex = fRowIndex[irow+1];
2011 if (icol+this->fColLwb <= col_upb && icol+this->fColLwb >= col_lwb)
2016 target.ResizeTo(row_lwb_sub,row_upb_sub,col_lwb_sub,col_upb_sub,nr_nonzeros);
2018 const Element *ep = this->GetMatrixArray();
2022 Element *ep_sub =
target.GetMatrixArray();
2024 if (
target.GetRowIndexArray() &&
target.GetColIndexArray()) {
2025 Int_t nelems_copy = 0;
2026 rowIndex_sub[0] = 0;
2027 const Int_t row_off = this->fRowLwb-row_lwb;
2028 const Int_t col_off = this->fColLwb-col_lwb;
2029 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
2030 if (irow+this->fRowLwb > row_upb || irow+this->fRowLwb < row_lwb)
continue;
2031 const Int_t sIndex = fRowIndex[irow];
2032 const Int_t eIndex = fRowIndex[irow+1];
2035 if (icol+this->fColLwb <= col_upb && icol+this->fColLwb >= col_lwb) {
2036 rowIndex_sub[irow+row_off+1] = nelems_copy+1;
2037 colIndex_sub[nelems_copy] = icol+col_off;
2038 ep_sub[nelems_copy] = ep[
index];
2044 const Int_t row_off = this->fRowLwb-row_lwb;
2045 const Int_t col_off = this->fColLwb-col_lwb;
2046 const Int_t ncols_sub = col_upb_sub-col_lwb_sub+1;
2047 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
2048 if (irow+this->fRowLwb > row_upb || irow+this->fRowLwb < row_lwb)
continue;
2049 const Int_t sIndex = fRowIndex[irow];
2050 const Int_t eIndex = fRowIndex[irow+1];
2051 const Int_t off = (irow+row_off)*ncols_sub;
2054 if (icol+this->fColLwb <= col_upb && icol+this->fColLwb >= col_lwb)
2055 ep_sub[off+icol+col_off] = ep[
index];
2067template<
class Element>
2074 if (row_lwb < this->fRowLwb || row_lwb > this->fRowLwb+this->fNrows-1) {
2075 Error(
"SetSub",
"row_lwb out-of-bounds");
2078 if (col_lwb < this->fColLwb || col_lwb > this->fColLwb+this->fNcols-1) {
2079 Error(
"SetSub",
"col_lwb out-of-bounds");
2082 if (row_lwb+source.
GetNrows() > this->fRowLwb+this->fNrows || col_lwb+source.
GetNcols() > this->fColLwb+this->fNcols) {
2083 Error(
"SetSub",
"source matrix too large");
2093 Int_t nr_nonzeros = 0;
2094 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
2095 if (irow+this->fRowLwb >= row_lwb+nRows_source || irow+this->fRowLwb < row_lwb)
continue;
2096 const Int_t sIndex = fRowIndex[irow];
2097 const Int_t eIndex = fRowIndex[irow+1];
2100 if (icol+this->fColLwb < col_lwb+nCols_source && icol+this->fColLwb >= col_lwb)
2109 const Int_t nelems_old = this->fNelems;
2110 const Int_t *rowIndex_old = GetRowIndexArray();
2111 const Int_t *colIndex_old = GetColIndexArray();
2112 const Element *elements_old = GetMatrixArray();
2114 const Int_t nelems_new = nelems_old+source.
NonZeros()-nr_nonzeros;
2115 fRowIndex =
new Int_t[this->fNrowIndex];
2116 fColIndex =
new Int_t[nelems_new];
2117 fElements =
new Element[nelems_new];
2118 this->fNelems = nelems_new;
2120 Int_t *rowIndex_new = GetRowIndexArray();
2121 Int_t *colIndex_new = GetColIndexArray();
2122 Element *elements_new = GetMatrixArray();
2124 const Int_t row_off = row_lwb-this->fRowLwb;
2125 const Int_t col_off = col_lwb-this->fColLwb;
2128 rowIndex_new[0] = 0;
2129 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
2130 rowIndex_new[irow+1] = rowIndex_new[irow];
2132 if (irow+this->fRowLwb < row_lwb+nRows_source && irow+this->fRowLwb >= row_lwb)
2135 const Int_t sIndex_o = rowIndex_old[irow];
2136 const Int_t eIndex_o = rowIndex_old[irow+1];
2139 const Int_t icol_left = col_off-1;
2142 rowIndex_new[irow+1]++;
2143 colIndex_new[nr] = colIndex_old[
index];
2144 elements_new[nr] = elements_old[
index];
2148 if (rowIndex_s && colIndex_s) {
2149 const Int_t sIndex_s = rowIndex_s[irow-row_off];
2150 const Int_t eIndex_s = rowIndex_s[irow-row_off+1];
2152 rowIndex_new[irow+1]++;
2153 colIndex_new[nr] = colIndex_s[
index]+col_off;
2154 elements_new[nr] = elements_s[
index];
2158 const Int_t off = (irow-row_off)*nCols_source;
2159 for (
Int_t icol = 0; icol < nCols_source; icol++) {
2160 rowIndex_new[irow+1]++;
2161 colIndex_new[nr] = icol+col_off;
2162 elements_new[nr] = elements_s[off+icol];
2167 const Int_t icol_right = col_off+nCols_source-1;
2170 while (right < eIndex_o-1 && colIndex_old[right+1] <= icol_right)
2175 rowIndex_new[irow+1]++;
2176 colIndex_new[nr] = colIndex_old[
index];
2177 elements_new[nr] = elements_old[
index];
2183 rowIndex_new[irow+1]++;
2184 colIndex_new[nr] = colIndex_old[
index];
2185 elements_new[nr] = elements_old[
index];
2191 R__ASSERT(this->fNelems == fRowIndex[this->fNrowIndex-1]);
2193 if (rowIndex_old)
delete [] (
Int_t*) rowIndex_old;
2194 if (colIndex_old)
delete [] (
Int_t*) colIndex_old;
2195 if (elements_old)
delete [] (Element*) elements_old;
2203template<
class Element>
2222 Element *pData_t =
new Element[nr_nonzeros];
2225 for (
Int_t irow_s = 0; irow_s < source.
GetNrows(); irow_s++) {
2226 const Int_t sIndex = pRowIndex_s[irow_s];
2227 const Int_t eIndex = pRowIndex_s[irow_s+1];
2229 rownr[ielem] = pColIndex_s[
index]+this->fRowLwb;
2230 colnr[ielem] = irow_s+this->fColLwb;
2231 pData_t[ielem] = pData_s[
index];
2239 SetMatrixArray(nr_nonzeros, source.
GetNcols(), source.
GetNrows(), rownr, colnr, pData_t);
2241 SetMatrixArray(nr_nonzeros, rownr, colnr, pData_t);
2244 R__ASSERT(this->fNelems == fRowIndex[this->fNrowIndex-1]);
2246 if (pData_t)
delete [] pData_t;
2247 if (rownr)
delete [] rownr;
2248 if (colnr)
delete [] colnr;
2255template<
class Element>
2260 if (fElements) {
delete [] fElements; fElements =
nullptr; }
2261 if (fColIndex) {
delete [] fColIndex; fColIndex =
nullptr; }
2263 memset(this->GetRowIndexArray(),0,this->fNrowIndex*
sizeof(
Int_t));
2271template<
class Element>
2278 Int_t nr_nonzeros = 0;
2279 for (i = this->fRowLwb; i <= this->fRowLwb+this->fNrows-1; i++)
2280 for (
Int_t j = this->fColLwb; j <= this->fColLwb+this->fNcols-1; j++)
2281 if (i == j) nr_nonzeros++;
2283 if (nr_nonzeros != this->fNelems) {
2284 this->fNelems = nr_nonzeros;
2285 Int_t *oIp = fColIndex;
2286 fColIndex =
new Int_t[nr_nonzeros];
2287 if (oIp)
delete [] oIp;
2288 Element *oDp = fElements;
2289 fElements =
new Element[nr_nonzeros];
2290 if (oDp)
delete [] oDp;
2295 for (i = this->fRowLwb; i <= this->fRowLwb+this->fNrows-1; i++) {
2296 for (
Int_t j = this->fColLwb; j <= this->fColLwb+this->fNcols-1; j++) {
2298 const Int_t irow = i-this->fRowLwb;
2299 fRowIndex[irow+1] = ielem+1;
2300 fElements[ielem] = 1.0;
2301 fColIndex[ielem++] = j-this->fColLwb;
2313template<
class Element>
2318 const Element * ep = GetMatrixArray();
2319 const Element *
const fp = ep+this->fNelems;
2320 const Int_t *
const pR = GetRowIndexArray();
2324 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
2325 const Int_t sIndex = pR[irow];
2326 const Int_t eIndex = pR[irow+1];
2342template<
class Element>
2350 const Element *
const fp = ep+this->fNcols;
2357 for (
Int_t i = 0; i < this->fNrows; i++,ep += this->fNcols)
2359 ep -= this->fNelems-1;
2370template<
class Element>
2375 const Int_t arown = rown-this->fRowLwb;
2376 const Int_t acoln = coln-this->fColLwb;
2377 if (arown >= this->fNrows || arown < 0) {
2378 Error(
"operator()",
"Request row(%d) outside matrix range of %d - %d",rown,this->fRowLwb,this->fRowLwb+this->fNrows);
2379 return fElements[0];
2381 if (acoln >= this->fNcols || acoln < 0) {
2382 Error(
"operator()",
"Request column(%d) outside matrix range of %d - %d",coln,this->fColLwb,this->fColLwb+this->fNcols);
2383 return fElements[0];
2389 if (this->fNrowIndex > 0 && fRowIndex[this->fNrowIndex-1] != 0) {
2390 sIndex = fRowIndex[arown];
2391 eIndex = fRowIndex[arown+1];
2395 if (
index >= sIndex && fColIndex[
index] == acoln)
2396 return fElements[
index];
2399 InsertRow(rown,coln,&val,1);
2400 sIndex = fRowIndex[arown];
2401 eIndex = fRowIndex[arown+1];
2403 if (
index >= sIndex && fColIndex[
index] == acoln)
2404 return fElements[
index];
2406 Error(
"operator()(Int_t,Int_t",
"Insert row failed");
2407 return fElements[0];
2414template <
class Element>
2418 if (this->fNrowIndex > 0 && this->fRowIndex[this->fNrowIndex-1] == 0) {
2419 Error(
"operator()(Int_t,Int_t) const",
"row/col indices are not set");
2420 Info(
"operator()",
"fNrowIndex = %d fRowIndex[fNrowIndex-1] = %d\n",this->fNrowIndex,this->fRowIndex[this->fNrowIndex-1]);
2423 const Int_t arown = rown-this->fRowLwb;
2424 const Int_t acoln = coln-this->fColLwb;
2426 if (arown >= this->fNrows || arown < 0) {
2427 Error(
"operator()",
"Request row(%d) outside matrix range of %d - %d",rown,this->fRowLwb,this->fRowLwb+this->fNrows);
2430 if (acoln >= this->fNcols || acoln < 0) {
2431 Error(
"operator()",
"Request column(%d) outside matrix range of %d - %d",coln,this->fColLwb,this->fColLwb+this->fNcols);
2435 const Int_t sIndex = fRowIndex[arown];
2436 const Int_t eIndex = fRowIndex[arown+1];
2438 if (
index < sIndex || fColIndex[
index] != acoln)
return 0.0;
2439 else return fElements[
index];
2446template<
class Element>
2450 Error(
"operator=(const TMatrixTSparse &)",
"matrices not compatible");
2458 Element *
const tp = this->GetMatrixArray();
2459 memcpy(tp,sp,this->fNelems*
sizeof(Element));
2460 this->fTol = source.
GetTol();
2469template<
class Element>
2473 Error(
"operator=(const TMatrixT &)",
"matrices not compatible");
2481 Element *
const tp = this->GetMatrixArray();
2482 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
2483 const Int_t sIndex = fRowIndex[irow];
2484 const Int_t eIndex = fRowIndex[irow+1];
2485 const Int_t off = irow*this->fNcols;
2488 tp[
index] = sp[off+icol];
2491 this->fTol = source.
GetTol();
2500template<
class Element>
2505 if (fRowIndex[this->fNrowIndex-1] == 0) {
2506 Error(
"operator=(Element",
"row/col indices are not set");
2510 Element *ep = this->GetMatrixArray();
2511 const Element *
const ep_last = ep+this->fNelems;
2512 while (ep < ep_last)
2521template<
class Element>
2526 Element *ep = this->GetMatrixArray();
2527 const Element *
const ep_last = ep+this->fNelems;
2528 while (ep < ep_last)
2537template<
class Element>
2542 Element *ep = this->GetMatrixArray();
2543 const Element *
const ep_last = ep+this->fNelems;
2544 while (ep < ep_last)
2553template<
class Element>
2558 Element *ep = this->GetMatrixArray();
2559 const Element *
const ep_last = ep+this->fNelems;
2560 while (ep < ep_last)
2569template<
class Element>
2574 const Element scale = beta-alpha;
2575 const Element shift = alpha/scale;
2577 Int_t *
const pRowIndex = GetRowIndexArray();
2578 Int_t *
const pColIndex = GetColIndexArray();
2579 Element *
const ep = GetMatrixArray();
2581 const Int_t m = this->GetNrows();
2582 const Int_t n = this->GetNcols();
2585 const Int_t nn = this->GetNrows()*this->GetNcols();
2586 const Int_t length = (this->GetNoElements() <= nn) ? this->GetNoElements() : nn;
2590 for (
Int_t k = 0; k < nn; k++) {
2591 const Element
r =
Drand(seed);
2593 if ((nn-k)*
r <
length-chosen) {
2594 pColIndex[chosen] = k%
n;
2597 if (irow > icurrent) {
2598 for ( ; icurrent < irow; icurrent++)
2599 pRowIndex[icurrent+1] = chosen;
2601 ep[chosen] = scale*(
Drand(seed)+shift);
2605 for ( ; icurrent <
m; icurrent++)
2606 pRowIndex[icurrent+1] =
length;
2616template<
class Element>
2619 const Element scale = beta-alpha;
2620 const Element shift = alpha/scale;
2625 if (this->fNrows != this->fNcols || this->fRowLwb != this->fColLwb) {
2626 Error(
"RandomizePD(Element &",
"matrix should be square");
2631 const Int_t n = this->fNcols;
2633 Int_t *
const pRowIndex = this->GetRowIndexArray();
2634 Int_t *
const pColIndex = this->GetColIndexArray();
2635 Element *
const ep = GetMatrixArray();
2642 ep[0] = 1
e-8+scale*(
Drand(seed)+shift);
2662 for (
Int_t k = 0; k < nn; k++ ) {
2663 const Element
r =
Drand(seed);
2665 if( (nn-k)*
r <
length-chosen) {
2672 Int_t col = k-row*(row+1)/2;
2677 if (row > icurrent) {
2681 for ( ; icurrent < row; icurrent++) {
2684 for (
Int_t ll = pRowIndex[icurrent]; ll < nnz; ll++)
2686 ep[nnz] += 1
e-8+scale*(
Drand(seed)+shift);
2687 pColIndex[nnz] = icurrent;
2690 pRowIndex[icurrent+1] = nnz;
2693 ep[nnz] = scale*(
Drand(seed)+shift);
2694 pColIndex[nnz] = col;
2697 ep[pRowIndex[col+1]-1] +=
TMath::Abs(ep[nnz]);
2707 for ( ; icurrent <
n; icurrent++) {
2710 for(
Int_t ll = pRowIndex[icurrent]; ll < nnz; ll++)
2712 ep[nnz] += 1
e-8+scale*(
Drand(seed)+shift);
2713 pColIndex[nnz] = icurrent;
2716 pRowIndex[icurrent+1] = nnz;
2718 this->fNelems = nnz;
2726 const Int_t *
const pR = this->GetRowIndexArray();
2727 const Int_t *
const pC = this->GetColIndexArray();
2728 Element *
const pD = GetMatrixArray();
2729 for (
Int_t irow = 0; irow < this->fNrows+1; irow++) {
2730 const Int_t sIndex = pR[irow];
2731 const Int_t eIndex = pR[irow+1];
2745template<
class Element>
2754template<
class Element>
2763template<
class Element>
2772template<
class Element>
2782template<
class Element>
2792template<
class Element>
2801template<
class Element>
2810template<
class Element>
2819template<
class Element>
2829template<
class Element>
2839template<
class Element>
2848template<
class Element>
2857template<
class Element>
2866template<
class Element>
2876template<
class Element>
2887template<
class Element>
2890 target += scalar * source;
2897template<
class Element>
2901 ::Error(
"ElementMult(TMatrixTSparse &,const TMatrixTSparse &)",
"matrices not compatible");
2906 Element *tp =
target.GetMatrixArray();
2907 const Element *ftp = tp+
target.GetNoElements();
2917template<
class Element>
2921 ::Error(
"ElementDiv(TMatrixT &,const TMatrixT &)",
"matrices not compatible");
2926 Element *tp =
target.GetMatrixArray();
2927 const Element *ftp = tp+
target.GetNoElements();
2928 while ( tp < ftp ) {
2932 Error(
"ElementDiv",
"source element is zero");
2942template<
class Element>
2947 ::Error(
"AreCompatible",
"matrix 1 not valid");
2952 ::Error(
"AreCompatible",
"matrix 2 not valid");
2959 ::Error(
"AreCompatible",
"matrices 1 and 2 not compatible");
2966 if (memcmp(pR1,pR2,(nRows+1)*
sizeof(
Int_t))) {
2968 ::Error(
"AreCompatible",
"matrices 1 and 2 have different rowIndex");
2969 for (
Int_t i = 0; i < nRows+1; i++)
2970 printf(
"%d: %d %d\n",i,pR1[i],pR2[i]);
2976 if (memcmp(pD1,pD2,nData*
sizeof(
Int_t))) {
2978 ::Error(
"AreCompatible",
"matrices 1 and 2 have different colIndex");
2979 for (
Int_t i = 0; i < nData; i++)
2980 printf(
"%d: %d %d\n",i,pD1[i],pD2[i]);
2990template<
class Element>
2998 if (this->fNelems < 0)
bool Bool_t
Boolean (0=false, 1=true) (bool)
int Int_t
Signed integer 4 bytes (int)
short Version_t
Class version identifier (short)
float Float_t
Float 4 bytes (float)
double Double_t
Double 8 bytes.
const char Option_t
Option string (const char)
#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)
Lexical sort on array data using indices first and second.
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) noexcept
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.
TCppObject_t Allocate(TCppScope_t scope)
static uint64_t sum(uint64_t i)