108template<
class Element>
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);
175template <
class Element>
177 Int_t *col, Element *data)
179 Int_t n = row_upb - row_lwb + 1;
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);
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);
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);
405 this->
fTol = std::numeric_limits<Element>::epsilon();
427template<
class Element>
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);
459 Int_t lIndex = sIndex-1;
460 Int_t rIndex = sIndex-1;
462 for (index = sIndex; index < eIndex; index++) {
465 if (icol >= acoln+nr)
break;
466 if (icol >= acoln) nslots++;
474 const Int_t ndiff = nr-nslots;
479 for (
Int_t irow = arown+1; irow < this->
fNrows+1; irow++)
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++) {
499 if (colIndex_old)
delete [] (
Int_t*) colIndex_old;
500 if (elements_old)
delete [] (Element*) elements_old;
510template<
class Element>
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);
537 memset(
v,0,nr*
sizeof(Element));
540 for (
Int_t index = sIndex; index < eIndex; index++) {
541 const Int_t icol = pColIndex[index];
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);
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");
676 Error(
"AMultB",
"this = &a");
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);
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;
723 const Element *
const pDataa =
a.GetMatrixArray();
724 const Element *
const pDatab =
b.GetMatrixArray();
728 const Int_t sIndexa = pRowIndexa[irowc];
729 const Int_t eIndexa = pRowIndexa[irowc+1];
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;
754template<
class Element>
761 if (
a.GetNcols() !=
b.GetNcols() ||
a.GetColLwb() !=
b.GetColLwb()) {
762 Error(
"AMultBt",
"A and B columns incompatible");
767 Error(
"AMultB",
"this = &a");
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);
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;
815 const Element *
const pDataa =
a.GetMatrixArray();
816 const Element *
const pDatab =
b.GetMatrixArray();
820 const Int_t off = irowc*
a.GetNcols();
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;
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");
860 Error(
"APlusB",
"this = &a");
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());
883 const Element *
const pDataa =
a.GetMatrixArray();
884 const Element *
const pDatab =
b.GetMatrixArray();
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;
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;
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");
942 Error(
"APlusB",
"this = &a");
947 Error(
"APlusB",
"this = &b");
953 Allocate(
a.GetNrows(),
a.GetNcols(),
a.GetRowLwb(),
a.GetColLwb());
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();
968 const Int_t sIndexa = pRowIndexa[irowc];
969 const Int_t eIndexa = pRowIndexa[irowc+1];
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;
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");
1013 Error(
"AMinusB",
"this = &a");
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());
1036 const Element *
const pDataa =
a.GetMatrixArray();
1037 const Element *
const pDatab =
b.GetMatrixArray();
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;
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;
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");
1095 Error(
"AMinusB",
"this = &a");
1100 Error(
"AMinusB",
"this = &b");
1106 Allocate(
a.GetNrows(),
a.GetNcols(),
a.GetRowLwb(),
a.GetColLwb());
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();
1121 const Int_t sIndexa = pRowIndexa[irowc];
1122 const Int_t eIndexa = pRowIndexa[irowc+1];
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;
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");
1166 Error(
"AMinusB",
"this = &a");
1171 Error(
"AMinusB",
"this = &b");
1177 Allocate(
a.GetNrows(),
a.GetNcols(),
a.GetRowLwb(),
a.GetColLwb());
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();
1192 const Int_t sIndexb = pRowIndexb[irowc];
1193 const Int_t eIndexb = pRowIndexb[irowc+1];
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;
1222template<
class Element>
1228 memcpy(data,elem,this->
fNelems*
sizeof(Element));
1236template<
class Element>
1241 Error(
"SetMatrixArray(Int_t,Int_t*,Int_t*,Element*",
"nr <= 0");
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]);
1260 Info(
"SetMatrixArray",
"row index upper bound adjusted to %d",row[irowmax]);
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]);
1271 Info(
"SetMatrixArray",
"column index upper bound adjusted to %d",col[icolmax]);
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) {
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) {
1314 if (ielem >= nr || row[ielem] != row[ielem-1])
1329template <
class Element>
1336 while (i < nz - 1) {
1337 if ((row[i] == row[i + 1]) && (col[i] == col[i + 1])) {
1339 data[i] += data[i + 1];
1342 for (
Int_t j = i + 1; j < nz; j++) {
1343 data[j] = data[j + 1];
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) {
1379 if (ncols != this->
fNcols) {
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]);
1404 Info(
"SetMatrixArray",
"row index upper bound adjusted to %d", row[irowmax]);
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]);
1415 Info(
"SetMatrixArray",
"column index upper bound adjusted to %d", col[icolmax]);
1423 Int_t nr_nonzeros = 0;
1424 const Element *ep = data;
1425 const Element *
const fp = data + nr;
1431 if (nr_nonzeros != this->
fNelems) {
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) {
1465 if (ielem >= nr || row[ielem] != row[ielem - 1])
1478template<
class Element>
1481 if (nelems_new != this->
fNelems) {
1492 memmove(
fElements,oDp,nr*
sizeof(Element));
1496 if (nelems_new > nr) {
1497 memset(
fElements+nr,0,(nelems_new-nr)*
sizeof(Element));
1512template<
class Element>
1518 this->GetRowLwb() != source.
GetRowLwb() || this->GetColLwb() != source.
GetColLwb()) {
1519 Error(
"SetSparseIndex",
"matrices not compatible");
1526 if (nr_nonzeros != this->
fNelems)
1535 for (
Int_t irow = 0; irow < this->
fNrows; irow++) {
1537 for (
Int_t icol = 0; icol < this->
fNcols; icol++) {
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)
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();
1677 const Int_t sIndexb = pRowIndexb[irowc];
1678 const Int_t eIndexb = pRowIndexb[irowc+1];
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) {
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];
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>
1739 Error(
"ResizeTo(Int_t,Int_t,Int_t)",
"Not owner of data array,cannot resize");
1745 (this->
fNelems == nr_nonzeros || nr_nonzeros < 0))
1747 else if (nrows == 0 || ncols == 0 || nr_nonzeros == 0) {
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];
1769 for (
Int_t index = sIndex; index < eIndex; index++) {
1770 const Int_t icol = colIndex_old[index];
1777 Allocate(nrows,ncols,0,0,1,nelems_new);
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];
1791 for (
Int_t index = sIndex; index < eIndex; index++) {
1792 const Int_t icol = colIndex_old[index];
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;
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>
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;
1842 if (this->
fNrows == new_nrows && this->
fNcols == new_ncols &&
1844 (this->
fNelems == nr_nonzeros || nr_nonzeros < 0))
1846 else if (new_nrows == 0 || new_ncols == 0 || nr_nonzeros == 0) {
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];
1872 for (
Int_t index = sIndex; index < eIndex; index++) {
1873 const Int_t icol = colIndex_old[index];
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);
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];
1895 for (
Int_t index = sIndex; index < eIndex; index++) {
1896 const Int_t icol = colIndex_old[index];
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;
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;
1951 this->
fTol = std::numeric_limits<Element>::epsilon();
1967template<
class Element>
1974 Error(
"GetSub",
"row_lwb out-of-bounds");
1978 Error(
"GetSub",
"col_lwb out-of-bounds");
1982 Error(
"GetSub",
"row_upb out-of-bounds");
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;
2009 for (
Int_t index = sIndex; index < eIndex; index++) {
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);
2025 Int_t nelems_copy = 0;
2026 rowIndex_sub[0] = 0;
2029 for (
Int_t irow = 0; irow < this->fNrows; irow++) {
2030 if (irow+this->
fRowLwb > row_upb || irow+this->
fRowLwb < row_lwb)
continue;
2033 for (
Int_t index = sIndex; index < eIndex; index++) {
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];
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;
2051 const Int_t off = (irow+row_off)*ncols_sub;
2052 for (
Int_t index = sIndex; index < eIndex; index++) {
2054 if (icol+this->fColLwb <= col_upb && icol+this->
fColLwb >= col_lwb)
2055 ep_sub[off+icol+col_off] = ep[index];
2067template<
class Element>
2075 Error(
"SetSub",
"row_lwb out-of-bounds");
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;
2098 for (
Int_t index = sIndex; index < eIndex; index++) {
2100 if (icol+this->fColLwb < col_lwb+nCols_source && icol+this->
fColLwb >= col_lwb)
2114 const Int_t nelems_new = nelems_old+source.
NonZeros()-nr_nonzeros;
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;
2141 for (
Int_t index = sIndex_o; index <= left; index++) {
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];
2151 for (
Int_t index = sIndex_s; index < eIndex_s; index++) {
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)
2174 for (
Int_t index = right; index < eIndex_o; index++) {
2175 rowIndex_new[irow+1]++;
2176 colIndex_new[nr] = colIndex_old[index];
2177 elements_new[nr] = elements_old[index];
2182 for (
Int_t index = sIndex_o; index < eIndex_o; index++) {
2183 rowIndex_new[irow+1]++;
2184 colIndex_new[nr] = colIndex_old[index];
2185 elements_new[nr] = elements_old[index];
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];
2228 for (
Int_t index = sIndex; index < eIndex; index++) {
2229 rownr[ielem] = pColIndex_s[index]+this->
fRowLwb;
2230 colnr[ielem] = irow_s+this->
fColLwb;
2231 pData_t[ielem] = pData_s[index];
2246 if (pData_t)
delete [] pData_t;
2247 if (rownr)
delete [] rownr;
2248 if (colnr)
delete [] colnr;
2255template<
class Element>
2271template<
class Element>
2278 Int_t nr_nonzeros = 0;
2281 if (i == j) nr_nonzeros++;
2283 if (nr_nonzeros != this->
fNelems) {
2287 if (oIp)
delete [] oIp;
2290 if (oDp)
delete [] oDp;
2295 for (i = this->
fRowLwb; i <= this->
fRowLwb+this->fNrows-1; i++) {
2313template<
class Element>
2319 const Element *
const fp = ep+this->
fNelems;
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];
2328 for (
Int_t index = sIndex; index < eIndex; index++)
2342template<
class Element>
2350 const Element *
const fp = ep+this->
fNcols;
2357 for (
Int_t i = 0; i < this->
fNrows; i++,ep += this->fNcols)
2370template<
class Element>
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);
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);
2395 if (index >= sIndex &&
fColIndex[index] == acoln)
2403 if (index >= sIndex &&
fColIndex[index] == acoln)
2406 Error(
"operator()(Int_t,Int_t",
"Insert row failed");
2414template <
class Element>
2419 Error(
"operator()(Int_t,Int_t) const",
"row/col indices are not set");
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);
2438 if (index < sIndex ||
fColIndex[index] != acoln)
return 0.0;
2446template<
class Element>
2450 Error(
"operator=(const TMatrixTSparse &)",
"matrices not compatible");
2459 memcpy(tp,sp,this->
fNelems*
sizeof(Element));
2469template<
class Element>
2473 Error(
"operator=(const TMatrixT &)",
"matrices not compatible");
2482 for (
Int_t irow = 0; irow < this->
fNrows; irow++) {
2486 for (
Int_t index = sIndex; index < eIndex; index++) {
2488 tp[index] = sp[off+icol];
2500template<
class Element>
2506 Error(
"operator=(Element",
"row/col indices are not set");
2511 const Element *
const ep_last = ep+this->
fNelems;
2512 while (ep < ep_last)
2521template<
class Element>
2527 const Element *
const ep_last = ep+this->
fNelems;
2528 while (ep < ep_last)
2537template<
class Element>
2543 const Element *
const ep_last = ep+this->
fNelems;
2544 while (ep < ep_last)
2553template<
class Element>
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;
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;
2626 Error(
"RandomizePD(Element &",
"matrix should be square");
2642 ep[0] = 1
e-8+scale*(
Drand(seed)+shift);
2652 length = (length <= nn) ? length : nn;
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;
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];
2732 for (
Int_t index = sIndex; index < eIndex; index++) {
2733 const Int_t icol = pC[index];
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");
2917template<
class Element>
2921 ::Error(
"ElementDiv(TMatrixT &,const TMatrixT &)",
"matrices not compatible");
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>
int Int_t
Signed integer 4 bytes (int).
short Version_t
Class version identifier (short).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
float Float_t
Float 4 bytes (float).
const char Option_t
Option string (const char).
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
TMatrixTSparse< Double_t > TMatrixDSparse
TMatrixT< Double_t > TMatrixD
TMatrixTSparse< Float_t > TMatrixFSparse
TMatrixT< Float_t > TMatrixF
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
Bool_t fIsOwner
!default kTRUE, when Use array kFALSE
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
virtual TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t nr_nonzeros=-1)=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.
void Clear(Option_t *="") override
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.
static uint64_t sum(uint64_t i)