84 template<class Element>
94 template<
class Element>
97 Allocate(row_upb-row_lwb+1,col_upb-col_lwb+1,row_lwb,col_lwb,1);
104 template<
class Element>
113 if (row[irowmin] < row_lwb || row[irowmax] > row_upb) {
114 Error(
"TMatrixTSparse",
"Inconsistency between row index and its range");
115 if (row[irowmin] < row_lwb) {
116 Info(
"TMatrixTSparse",
"row index lower bound adjusted to %d",row[irowmin]);
117 row_lwb = row[irowmin];
119 if (row[irowmax] > row_upb) {
120 Info(
"TMatrixTSparse",
"row index upper bound adjusted to %d",row[irowmax]);
121 col_lwb = col[irowmax];
124 if (col[icolmin] < col_lwb || col[icolmax] > col_upb) {
125 Error(
"TMatrixTSparse",
"Inconsistency between column index and its range");
126 if (col[icolmin] < col_lwb) {
127 Info(
"TMatrixTSparse",
"column index lower bound adjusted to %d",col[icolmin]);
128 col_lwb = col[icolmin];
130 if (col[icolmax] > col_upb) {
131 Info(
"TMatrixTSparse",
"column index upper bound adjusted to %d",col[icolmax]);
132 col_upb = col[icolmax];
136 Allocate(row_upb-row_lwb+1,col_upb-col_lwb+1,row_lwb,col_lwb,1,nr);
138 SetMatrixArray(nr,row,col,data);
143 template<
class Element>
156 template<
class Element>
169 template<
class Element>
174 Int_t nr_nonzeros = 0;
189 for (
Int_t i = rowLwb; i <= rowLwb+nrows-1; i++)
190 for (
Int_t j = colLwb; j <= colLwb+ncols-1; j++)
191 if (i==j) nr_nonzeros++;
192 Allocate(nrows,ncols,rowLwb,colLwb,1,nr_nonzeros);
211 Error(
"TMatrixTSparse(EMatrixCreatorOp1)",
"operation %d not yet implemented", op);
219 template<
class Element>
243 Error(
"TMatrixTSparse(EMatrixCreatorOp2)",
"operation %d not yet implemented",op);
251 template<
class Element>
275 Error(
"TMatrixTSparse(EMatrixCreatorOp2)",
"operation %d not yet implemented",op);
283 template<
class Element>
307 Error(
"TMatrixTSparse(EMatrixCreatorOp2)",
"operation %d not yet implemented",op);
316 template<
class Element>
320 if ( (nr_nonzeros > 0 && (no_rows == 0 || no_cols == 0)) ||
321 (no_rows < 0 || no_cols < 0 || nr_nonzeros < 0) )
323 Error(
"Allocate",
"no_rows=%d no_cols=%d non_zeros=%d",no_rows,no_cols,nr_nonzeros);
358 template<
class Element>
366 if (arown >= this->
fNrows || arown < 0) {
367 Error(
"InsertRow",
"row %d out of matrix range",rown);
371 if (acoln >= this->
fNcols || acoln < 0) {
372 Error(
"InsertRow",
"column %d out of matrix range",coln);
376 if (acoln+nr > this->
fNcols || nr < 0) {
377 Error(
"InsertRow",
"row length %d out of range",nr);
390 Int_t lIndex = sIndex-1;
391 Int_t rIndex = sIndex-1;
393 for (index = sIndex; index < eIndex; index++) {
396 if (icol >= acoln+nr)
break;
397 if (icol >= acoln) nslots++;
405 const Int_t ndiff = nr-nslots;
410 for (
Int_t irow = arown+1; irow < this->
fNrows+1; irow++)
415 memmove(
fElements,elements_old,(lIndex+1)*
sizeof(Element));
418 if (nelems_old > 0 && nelems_old-rIndex > 0) {
419 memmove(
fColIndex+rIndex+ndiff,colIndex_old+rIndex,(nelems_old-rIndex)*
sizeof(
Int_t));
420 memmove(
fElements+rIndex+ndiff,elements_old+rIndex,(nelems_old-rIndex)*
sizeof(Element));
424 for (
Int_t i = 0; i < nr; i++) {
430 if (colIndex_old)
delete [] (
Int_t*) colIndex_old;
431 if (elements_old)
delete [] (Element*) elements_old;
441 template<
class Element>
449 if (arown >= this->
fNrows || arown < 0) {
450 Error(
"ExtractRow",
"row %d out of matrix range",rown);
454 if (acoln >= this->
fNcols || acoln < 0) {
455 Error(
"ExtractRow",
"column %d out of matrix range",coln);
459 if (acoln+nr > this->
fNcols || nr < 0) {
460 Error(
"ExtractRow",
"row length %d out of range",nr);
468 memset(v,0,nr*
sizeof(Element));
471 for (
Int_t index = sIndex; index < eIndex; index++) {
472 const Int_t icol = pColIndex[index];
473 if (icol < acoln || icol >= acoln+nr)
continue;
474 v[icol-acoln] = pData[index];
482 template<
class Element>
490 Error(
"AMultBt",
"A and B columns incompatible");
495 Error(
"AMultB",
"this = &a");
500 Error(
"AMultB",
"this = &b");
516 Int_t nr_nonzero_rowa = 0;
519 if (pRowIndexa[irowa] < pRowIndexa[irowa+1])
522 Int_t nr_nonzero_rowb = 0;
525 if (pRowIndexb[irowb] < pRowIndexb[irowb+1])
529 const Int_t nc = nr_nonzero_rowa*nr_nonzero_rowb;
538 pRowIndexc[irowa+1] = pRowIndexc[irowa];
539 if (pRowIndexa[irowa] >= pRowIndexa[irowa+1])
continue;
541 if (pRowIndexb[irowb] >= pRowIndexb[irowb+1])
continue;
542 pRowIndexc[irowa+1]++;
543 pColIndexc[ielem++] = irowb;
556 const Int_t sIndexa = pRowIndexa[irowc];
557 const Int_t eIndexa = pRowIndexa[irowc+1];
559 const Int_t sIndexb = pRowIndexb[icolc];
560 const Int_t eIndexb = pRowIndexb[icolc+1];
562 Int_t indexb = sIndexb;
563 for (
Int_t indexa = sIndexa; indexa < eIndexa && indexb < eIndexb; indexa++) {
564 const Int_t icola = pColIndexa[indexa];
565 while (indexb < eIndexb && pColIndexb[indexb] <= icola) {
566 if (icola == pColIndexb[indexb]) {
567 sum += pDataa[indexa]*pDatab[indexb];
574 pColIndexc[indexc_r] = icolc;
575 pDatac[indexc_r] = sum;
579 pRowIndexc[irowc+1] = indexc_r;
590 template<
class Element>
598 Error(
"AMultBt",
"A and B columns incompatible");
603 Error(
"AMultB",
"this = &a");
608 Error(
"AMultB",
"this = &b");
622 Int_t nr_nonzero_rowa = 0;
625 if (pRowIndexa[irowa] < pRowIndexa[irowa+1])
630 const Int_t nc = nr_nonzero_rowa*nr_nonzero_rowb;
639 pRowIndexc[irowa+1] = pRowIndexc[irowa];
641 pRowIndexc[irowa+1]++;
642 pColIndexc[ielem++] = irowb;
655 const Int_t sIndexa = pRowIndexa[irowc];
656 const Int_t eIndexa = pRowIndexa[irowc+1];
660 for (
Int_t indexa = sIndexa; indexa < eIndexa; indexa++) {
661 const Int_t icola = pColIndexa[indexa];
662 sum += pDataa[indexa]*pDatab[off+icola];
665 pColIndexc[indexc_r] = icolc;
666 pDatac[indexc_r] = sum;
670 pRowIndexc[irowc+1]= indexc_r;
681 template<
class Element>
689 Error(
"AMultBt",
"A and B columns incompatible");
694 Error(
"AMultB",
"this = &a");
699 Error(
"AMultB",
"this = &b");
714 Int_t nr_nonzero_rowb = 0;
717 if (pRowIndexb[irowb] < pRowIndexb[irowb+1])
721 const Int_t nc = nr_nonzero_rowa*nr_nonzero_rowb;
730 pRowIndexc[irowa+1] = pRowIndexc[irowa];
732 if (pRowIndexb[irowb] >= pRowIndexb[irowb+1])
continue;
733 pRowIndexc[irowa+1]++;
734 pColIndexc[ielem++] = irowb;
749 const Int_t sIndexb = pRowIndexb[icolc];
750 const Int_t eIndexb = pRowIndexb[icolc+1];
752 for (
Int_t indexb = sIndexb; indexb < eIndexb; indexb++) {
753 const Int_t icolb = pColIndexb[indexb];
754 sum += pDataa[off+icolb]*pDatab[indexb];
757 pColIndexc[indexc_r] = icolc;
758 pDatac[indexc_r] = sum;
762 pRowIndexc[irowc+1] = indexc_r;
773 template<
class Element>
782 Error(
"APlusB(const TMatrixTSparse &,const TMatrixTSparse &",
"matrices not compatible");
787 Error(
"APlusB",
"this = &a");
792 Error(
"APlusB",
"this = &b");
815 const Int_t sIndexa = pRowIndexa[irowc];
816 const Int_t eIndexa = pRowIndexa[irowc+1];
817 const Int_t sIndexb = pRowIndexb[irowc];
818 const Int_t eIndexb = pRowIndexb[irowc+1];
819 Int_t indexa = sIndexa;
820 Int_t indexb = sIndexb;
823 while (indexa < eIndexa && pColIndexa[indexa] <= icolc) {
824 if (icolc == pColIndexa[indexa]) {
825 sum += pDataa[indexa];
830 while (indexb < eIndexb && pColIndexb[indexb] <= icolc) {
831 if (icolc == pColIndexb[indexb]) {
832 sum += pDatab[indexb];
839 pColIndexc[indexc_r] = icolc;
840 pDatac[indexc_r] = sum;
844 pRowIndexc[irowc+1] = indexc_r;
855 template<
class Element>
864 Error(
"APlusB(const TMatrixTSparse &,const TMatrixT &",
"matrices not compatible");
869 Error(
"APlusB",
"this = &a");
874 Error(
"APlusB",
"this = &b");
895 const Int_t sIndexa = pRowIndexa[irowc];
896 const Int_t eIndexa = pRowIndexa[irowc+1];
898 Int_t indexa = sIndexa;
900 Element sum = pDatab[off+icolc];
901 while (indexa < eIndexa && pColIndexa[indexa] <= icolc) {
902 if (icolc == pColIndexa[indexa]) {
903 sum += pDataa[indexa];
910 pColIndexc[indexc_r] = icolc;
911 pDatac[indexc_r] = sum;
915 pRowIndexc[irowc+1] = indexc_r;
926 template<
class Element>
935 Error(
"AMinusB(const TMatrixTSparse &,const TMatrixTSparse &",
"matrices not compatible");
940 Error(
"AMinusB",
"this = &a");
945 Error(
"AMinusB",
"this = &b");
968 const Int_t sIndexa = pRowIndexa[irowc];
969 const Int_t eIndexa = pRowIndexa[irowc+1];
970 const Int_t sIndexb = pRowIndexb[irowc];
971 const Int_t eIndexb = pRowIndexb[irowc+1];
972 Int_t indexa = sIndexa;
973 Int_t indexb = sIndexb;
976 while (indexa < eIndexa && pColIndexa[indexa] <= icolc) {
977 if (icolc == pColIndexa[indexa]) {
978 sum += pDataa[indexa];
983 while (indexb < eIndexb && pColIndexb[indexb] <= icolc) {
984 if (icolc == pColIndexb[indexb]) {
985 sum -= pDatab[indexb];
992 pColIndexc[indexc_r] = icolc;
993 pDatac[indexc_r] = sum;
997 pRowIndexc[irowc+1] = indexc_r;
1008 template<
class Element>
1017 Error(
"AMinusB(const TMatrixTSparse &,const TMatrixT &",
"matrices not compatible");
1022 Error(
"AMinusB",
"this = &a");
1027 Error(
"AMinusB",
"this = &b");
1048 const Int_t sIndexa = pRowIndexa[irowc];
1049 const Int_t eIndexa = pRowIndexa[irowc+1];
1051 Int_t indexa = sIndexa;
1053 Element sum = -pDatab[off+icolc];
1054 while (indexa < eIndexa && pColIndexa[indexa] <= icolc) {
1055 if (icolc == pColIndexa[indexa]) {
1056 sum += pDataa[indexa];
1063 pColIndexc[indexc_r] = icolc;
1064 pDatac[indexc_r] = sum;
1068 pRowIndexc[irowc+1] = indexc_r;
1079 template<
class Element>
1088 Error(
"AMinusB(const TMatrixT &,const TMatrixTSparse &",
"matrices not compatible");
1093 Error(
"AMinusB",
"this = &a");
1098 Error(
"AMinusB",
"this = &b");
1119 const Int_t sIndexb = pRowIndexb[irowc];
1120 const Int_t eIndexb = pRowIndexb[irowc+1];
1122 Int_t indexb = sIndexb;
1124 Element sum = pDataa[off+icolc];
1125 while (indexb < eIndexb && pColIndexb[indexb] <= icolc) {
1126 if (icolc == pColIndexb[indexb]) {
1127 sum -= pDatab[indexb];
1134 pColIndexc[indexc_r] = icolc;
1135 pDatac[indexc_r] = sum;
1139 pRowIndexc[irowc+1] = indexc_r;
1149 template<
class Element>
1155 memcpy(data,elem,this->
fNelems*
sizeof(Element));
1163 template<
class Element>
1168 Error(
"SetMatrixArray(Int_t,Int_t*,Int_t*,Element*",
"nr <= 0");
1181 Error(
"SetMatrixArray",
"Inconsistency between row index and its range");
1182 if (row[irowmin] < this->
fRowLwb) {
1183 Info(
"SetMatrixArray",
"row index lower bound adjusted to %d",row[irowmin]);
1187 Info(
"SetMatrixArray",
"row index upper bound adjusted to %d",row[irowmax]);
1192 Error(
"SetMatrixArray",
"Inconsistency between column index and its range");
1193 if (col[icolmin] < this->
fColLwb) {
1194 Info(
"SetMatrixArray",
"column index lower bound adjusted to %d",col[icolmin]);
1198 Info(
"SetMatrixArray",
"column index upper bound adjusted to %d",col[icolmax]);
1205 Int_t nr_nonzeros = 0;
1206 const Element *ep = data;
1207 const Element *
const fp = data+nr;
1210 if (*ep++ != 0.0) nr_nonzeros++;
1212 if (nr_nonzeros != this->
fNelems) {
1231 for (
Int_t irow = 1; irow < this->
fNrows+1; irow++) {
1232 if (ielem < nr && row[ielem] < irow) {
1233 while (ielem < nr) {
1234 if (data[ielem] != 0.0) {
1240 if (ielem >= nr || row[ielem] != row[ielem-1])
1253 template<
class Element>
1256 if (nelems_new != this->
fNelems) {
1267 memmove(
fElements,oDp,nr*
sizeof(Element));
1271 if (nelems_new > nr) {
1272 memset(
fElements+nr,0,(nelems_new-nr)*
sizeof(Element));
1287 template<
class Element>
1294 Error(
"SetSparseIndex",
"matrices not compatible");
1301 if (nr_nonzeros != this->
fNelems)
1310 for (
Int_t irow = 0; irow < this->
fNrows; irow++) {
1312 for (
Int_t icol = 0; icol < this->
fNcols; icol++) {
1330 template<
class Element>
1339 Error(
"SetSparseIndexAB",
"source matrices not compatible");
1345 Error(
"SetSparseIndexAB",
"matrix not compatible with source matrices");
1358 const Int_t sIndexa = pRowIndexa[irowc];
1359 const Int_t eIndexa = pRowIndexa[irowc+1];
1360 const Int_t sIndexb = pRowIndexb[irowc];
1361 const Int_t eIndexb = pRowIndexb[irowc+1];
1362 nc += eIndexa-sIndexa;
1363 Int_t indexb = sIndexb;
1364 for (
Int_t indexa = sIndexa; indexa < eIndexa; indexa++) {
1365 const Int_t icola = pColIndexa[indexa];
1366 for (; indexb < eIndexb; indexb++) {
1367 if (pColIndexb[indexb] >= icola) {
1368 if (pColIndexb[indexb] == icola)
1375 while (indexb < eIndexb) {
1376 const Int_t icola = (eIndexa > sIndexa && eIndexa > 0) ? pColIndexa[eIndexa-1] : -1;
1377 if (pColIndexb[indexb++] > icola)
1392 const Int_t sIndexa = pRowIndexa[irowc];
1393 const Int_t eIndexa = pRowIndexa[irowc+1];
1394 const Int_t sIndexb = pRowIndexb[irowc];
1395 const Int_t eIndexb = pRowIndexb[irowc+1];
1396 Int_t indexb = sIndexb;
1397 for (
Int_t indexa = sIndexa; indexa < eIndexa; indexa++) {
1398 const Int_t icola = pColIndexa[indexa];
1399 for (; indexb < eIndexb; indexb++) {
1400 if (pColIndexb[indexb] >= icola) {
1401 if (pColIndexb[indexb] == icola)
1405 pColIndexc[nc++] = pColIndexb[indexb];
1407 pColIndexc[nc++] = pColIndexa[indexa];
1409 while (indexb < eIndexb) {
1410 const Int_t icola = (eIndexa > 0) ? pColIndexa[eIndexa-1] : -1;
1411 if (pColIndexb[indexb++] > icola)
1412 pColIndexc[nc++] = pColIndexb[indexb-1];
1414 pRowIndexc[irowc+1] = nc;
1424 template<
class Element>
1433 Error(
"SetSparseIndexAB",
"source matrices not compatible");
1439 Error(
"SetSparseIndexAB",
"matrix not compatible with source matrices");
1452 const Int_t sIndexb = pRowIndexb[irowc];
1453 const Int_t eIndexb = pRowIndexb[irowc+1];
1455 Int_t indexb = sIndexb;
1457 if (pDataa[off+icolc] != 0.0 || pColIndexb[indexb] > icolc)
continue;
1458 for (; indexb < eIndexb; indexb++) {
1459 if (pColIndexb[indexb] >= icolc) {
1460 if (pColIndexb[indexb] == icolc) {
1480 const Int_t sIndexb = pRowIndexb[irowc];
1481 const Int_t eIndexb = pRowIndexb[irowc+1];
1483 Int_t indexb = sIndexb;
1485 if (pDataa[off+icolc] != 0.0)
1486 pColIndexc[nc++] = icolc;
1487 else if (pColIndexb[indexb] <= icolc) {
1488 for (; indexb < eIndexb; indexb++) {
1489 if (pColIndexb[indexb] >= icolc) {
1490 if (pColIndexb[indexb] == icolc)
1491 pColIndexc[nc++] = pColIndexb[indexb++];
1497 pRowIndexc[irowc+1] = nc;
1509 template<
class Element>
1514 Error(
"ResizeTo(Int_t,Int_t,Int_t)",
"Not owner of data array,cannot resize");
1520 (this->
fNelems == nr_nonzeros || nr_nonzeros < 0))
1522 else if (nrows == 0 || ncols == 0 || nr_nonzeros == 0) {
1536 if (nr_nonzeros > 0)
1537 nelems_new = nr_nonzeros;
1540 for (
Int_t irow = 0; irow < nrows_old; irow++) {
1541 if (irow >= nrows)
continue;
1542 const Int_t sIndex = rowIndex_old[irow];
1543 const Int_t eIndex = rowIndex_old[irow+1];
1544 for (
Int_t index = sIndex; index < eIndex; index++) {
1545 const Int_t icol = colIndex_old[index];
1552 Allocate(nrows,ncols,0,0,1,nelems_new);
1559 Int_t nelems_copy = 0;
1560 rowIndex_new[0] = 0;
1562 for (
Int_t irow = 0; irow < nrows_old && cont; irow++) {
1563 if (irow >= nrows)
continue;
1564 const Int_t sIndex = rowIndex_old[irow];
1565 const Int_t eIndex = rowIndex_old[irow+1];
1566 for (
Int_t index = sIndex; index < eIndex; index++) {
1567 const Int_t icol = colIndex_old[index];
1569 rowIndex_new[irow+1] = nelems_copy+1;
1570 colIndex_new[nelems_copy] = icol;
1571 elements_new[nelems_copy] = elements_old[index];
1574 if (nelems_copy >= nelems_new) {
1581 if (rowIndex_old)
delete [] (
Int_t*) rowIndex_old;
1582 if (colIndex_old)
delete [] (
Int_t*) colIndex_old;
1583 if (elements_old)
delete [] (Element*) elements_old;
1587 rowIndex_new[irow] = rowIndex_new[nrowIndex_old-1];
1590 const Int_t nelems_new = (nr_nonzeros >= 0) ? nr_nonzeros : 0;
1591 Allocate(nrows,ncols,0,0,1,nelems_new);
1603 template<
class Element>
1609 Error(
"ResizeTo(Int_t,Int_t,Int_t,Int_t,Int_t)",
"Not owner of data array,cannot resize");
1613 const Int_t new_nrows = row_upb-row_lwb+1;
1614 const Int_t new_ncols = col_upb-col_lwb+1;
1617 if (this->
fNrows == new_nrows && this->
fNcols == new_ncols &&
1619 (this->
fNelems == nr_nonzeros || nr_nonzeros < 0))
1621 else if (new_nrows == 0 || new_ncols == 0 || nr_nonzeros == 0) {
1639 if (nr_nonzeros > 0)
1640 nelems_new = nr_nonzeros;
1643 for (
Int_t irow = 0; irow < nrows_old; irow++) {
1644 if (irow+rowLwb_old > row_upb || irow+rowLwb_old < row_lwb)
continue;
1645 const Int_t sIndex = rowIndex_old[irow];
1646 const Int_t eIndex = rowIndex_old[irow+1];
1647 for (
Int_t index = sIndex; index < eIndex; index++) {
1648 const Int_t icol = colIndex_old[index];
1649 if (icol+colLwb_old <= col_upb && icol+colLwb_old >= col_lwb)
1655 Allocate(new_nrows,new_ncols,row_lwb,col_lwb,1,nelems_new);
1662 Int_t nelems_copy = 0;
1663 rowIndex_new[0] = 0;
1664 const Int_t row_off = rowLwb_old-row_lwb;
1665 const Int_t col_off = colLwb_old-col_lwb;
1666 for (
Int_t irow = 0; irow < nrows_old; irow++) {
1667 if (irow+rowLwb_old > row_upb || irow+rowLwb_old < row_lwb)
continue;
1668 const Int_t sIndex = rowIndex_old[irow];
1669 const Int_t eIndex = rowIndex_old[irow+1];
1670 for (
Int_t index = sIndex; index < eIndex; index++) {
1671 const Int_t icol = colIndex_old[index];
1672 if (icol+colLwb_old <= col_upb && icol+colLwb_old >= col_lwb) {
1673 rowIndex_new[irow+row_off+1] = nelems_copy+1;
1674 colIndex_new[nelems_copy] = icol+col_off;
1675 elements_new[nelems_copy] = elements_old[index];
1678 if (nelems_copy >= nelems_new) {
1684 if (rowIndex_old)
delete [] (
Int_t*) rowIndex_old;
1685 if (colIndex_old)
delete [] (
Int_t*) colIndex_old;
1686 if (elements_old)
delete [] (Element*) elements_old;
1690 rowIndex_new[irow] = rowIndex_new[nrowIndex_old-1];
1693 const Int_t nelems_new = (nr_nonzeros >= 0) ? nr_nonzeros : 0;
1694 Allocate(new_nrows,new_ncols,row_lwb,col_lwb,1,nelems_new);
1702 template<
class Element>
1707 if (row_upb < row_lwb) {
1708 Error(
"Use",
"row_upb=%d < row_lwb=%d",row_upb,row_lwb);
1711 if (col_upb < col_lwb) {
1712 Error(
"Use",
"col_upb=%d < col_lwb=%d",col_upb,col_lwb);
1719 this->
fNrows = row_upb-row_lwb+1;
1720 this->
fNcols = col_upb-col_lwb+1;
1742 template<
class Element>
1749 Error(
"GetSub",
"row_lwb out-of-bounds");
1753 Error(
"GetSub",
"col_lwb out-of-bounds");
1757 Error(
"GetSub",
"row_upb out-of-bounds");
1761 Error(
"GetSub",
"col_upb out-of-bounds");
1764 if (row_upb < row_lwb || col_upb < col_lwb) {
1765 Error(
"GetSub",
"row_upb < row_lwb || col_upb < col_lwb");
1774 const Int_t row_lwb_sub = (shift) ? 0 : row_lwb;
1775 const Int_t row_upb_sub = (shift) ? row_upb-row_lwb : row_upb;
1776 const Int_t col_lwb_sub = (shift) ? 0 : col_lwb;
1777 const Int_t col_upb_sub = (shift) ? col_upb-col_lwb : col_upb;
1779 Int_t nr_nonzeros = 0;
1780 for (
Int_t irow = 0; irow < this->
fNrows; irow++) {
1781 if (irow+this->
fRowLwb > row_upb || irow+this->
fRowLwb < row_lwb)
continue;
1784 for (
Int_t index = sIndex; index < eIndex; index++) {
1786 if (icol+this->fColLwb <= col_upb && icol+this->
fColLwb >= col_lwb)
1791 target.
ResizeTo(row_lwb_sub,row_upb_sub,col_lwb_sub,col_upb_sub,nr_nonzeros);
1800 Int_t nelems_copy = 0;
1801 rowIndex_sub[0] = 0;
1804 for (
Int_t irow = 0; irow < this->
fNrows; irow++) {
1805 if (irow+this->
fRowLwb > row_upb || irow+this->
fRowLwb < row_lwb)
continue;
1808 for (
Int_t index = sIndex; index < eIndex; index++) {
1810 if (icol+this->fColLwb <= col_upb && icol+this->
fColLwb >= col_lwb) {
1811 rowIndex_sub[irow+row_off+1] = nelems_copy+1;
1812 colIndex_sub[nelems_copy] = icol+col_off;
1813 ep_sub[nelems_copy] = ep[index];
1821 const Int_t ncols_sub = col_upb_sub-col_lwb_sub+1;
1822 for (
Int_t irow = 0; irow < this->
fNrows; irow++) {
1823 if (irow+this->
fRowLwb > row_upb || irow+this->
fRowLwb < row_lwb)
continue;
1826 const Int_t off = (irow+row_off)*ncols_sub;
1827 for (
Int_t index = sIndex; index < eIndex; index++) {
1829 if (icol+this->fColLwb <= col_upb && icol+this->
fColLwb >= col_lwb)
1830 ep_sub[off+icol+col_off] = ep[index];
1842 template<
class Element>
1850 Error(
"SetSub",
"row_lwb out-of-bounds");
1854 Error(
"SetSub",
"col_lwb out-of-bounds");
1858 Error(
"SetSub",
"source matrix too large");
1868 Int_t nr_nonzeros = 0;
1869 for (
Int_t irow = 0; irow < this->
fNrows; irow++) {
1870 if (irow+this->
fRowLwb >= row_lwb+nRows_source || irow+this->
fRowLwb < row_lwb)
continue;
1873 for (
Int_t index = sIndex; index < eIndex; index++) {
1875 if (icol+this->fColLwb < col_lwb+nCols_source && icol+this->
fColLwb >= col_lwb)
1889 const Int_t nelems_new = nelems_old+source.
NonZeros()-nr_nonzeros;
1903 rowIndex_new[0] = 0;
1904 for (
Int_t irow = 0; irow < this->
fNrows; irow++) {
1905 rowIndex_new[irow+1] = rowIndex_new[irow];
1907 if (irow+this->fRowLwb < row_lwb+nRows_source && irow+this->fRowLwb >= row_lwb)
1910 const Int_t sIndex_o = rowIndex_old[irow];
1911 const Int_t eIndex_o = rowIndex_old[irow+1];
1914 const Int_t icol_left = col_off-1;
1916 for (
Int_t index = sIndex_o; index <= left; index++) {
1917 rowIndex_new[irow+1]++;
1918 colIndex_new[nr] = colIndex_old[index];
1919 elements_new[nr] = elements_old[index];
1923 if (rowIndex_s && colIndex_s) {
1924 const Int_t sIndex_s = rowIndex_s[irow-row_off];
1925 const Int_t eIndex_s = rowIndex_s[irow-row_off+1];
1926 for (
Int_t index = sIndex_s; index < eIndex_s; index++) {
1927 rowIndex_new[irow+1]++;
1928 colIndex_new[nr] = colIndex_s[index]+col_off;
1929 elements_new[nr] = elements_s[index];
1933 const Int_t off = (irow-row_off)*nCols_source;
1934 for (
Int_t icol = 0; icol < nCols_source; icol++) {
1935 rowIndex_new[irow+1]++;
1936 colIndex_new[nr] = icol+col_off;
1937 elements_new[nr] = elements_s[off+icol];
1942 const Int_t icol_right = col_off+nCols_source-1;
1945 while (right < eIndex_o-1 && colIndex_old[right+1] <= icol_right)
1949 for (
Int_t index = right; index < eIndex_o; index++) {
1950 rowIndex_new[irow+1]++;
1951 colIndex_new[nr] = colIndex_old[index];
1952 elements_new[nr] = elements_old[index];
1957 for (
Int_t index = sIndex_o; index < eIndex_o; index++) {
1958 rowIndex_new[irow+1]++;
1959 colIndex_new[nr] = colIndex_old[index];
1960 elements_new[nr] = elements_old[index];
1968 if (rowIndex_old)
delete [] (
Int_t*) rowIndex_old;
1969 if (colIndex_old)
delete [] (
Int_t*) colIndex_old;
1970 if (elements_old)
delete [] (Element*) elements_old;
1978 template<
class Element>
1987 Error(
"Transpose",
"matrix has wrong shape");
2003 Element *pData_t =
new Element[nr_nonzeros];
2006 for (
Int_t irow_s = 0; irow_s < source.
GetNrows(); irow_s++) {
2007 const Int_t sIndex = pRowIndex_s[irow_s];
2008 const Int_t eIndex = pRowIndex_s[irow_s+1];
2009 for (
Int_t index = sIndex; index < eIndex; index++) {
2010 rownr[ielem] = pColIndex_s[index]+this->
fRowLwb;
2011 colnr[ielem] = irow_s+this->
fColLwb;
2012 pData_t[ielem] = pData_s[index];
2024 if (pData_t)
delete [] pData_t;
2025 if (rownr)
delete [] rownr;
2026 if (colnr)
delete [] colnr;
2033 template<
class Element>
2049 template<
class Element>
2056 Int_t nr_nonzeros = 0;
2059 if (i == j) nr_nonzeros++;
2061 if (nr_nonzeros != this->
fNelems) {
2065 if (oIp)
delete [] oIp;
2068 if (oDp)
delete [] oDp;
2073 for (i = this->
fRowLwb; i <= this->
fRowLwb+this->fNrows-1; i++) {
2091 template<
class Element>
2097 const Element *
const fp = ep+this->
fNelems;
2102 for (
Int_t irow = 0; irow < this->
fNrows; irow++) {
2103 const Int_t sIndex = pR[irow];
2104 const Int_t eIndex = pR[irow+1];
2106 for (
Int_t index = sIndex; index < eIndex; index++)
2120 template<
class Element>
2128 const Element *
const fp = ep+this->
fNcols;
2148 template<
class Element>
2155 if (arown >= this->
fNrows || arown < 0) {
2156 Error(
"operator()",
"Request row(%d) outside matrix range of %d - %d",rown,this->fRowLwb,this->fRowLwb+this->
fNrows);
2159 if (acoln >= this->
fNcols || acoln < 0) {
2160 Error(
"operator()",
"Request column(%d) outside matrix range of %d - %d",coln,this->fColLwb,this->fColLwb+this->
fNcols);
2173 if (index >= sIndex &&
fColIndex[index] == acoln)
2181 if (index >= sIndex &&
fColIndex[index] == acoln)
2184 Error(
"operator()(Int_t,Int_t",
"Insert row failed");
2192 template <
class Element>
2197 Error(
"operator()(Int_t,Int_t) const",
"row/col indices are not set");
2204 if (arown >= this->
fNrows || arown < 0) {
2205 Error(
"operator()",
"Request row(%d) outside matrix range of %d - %d",rown,this->fRowLwb,this->fRowLwb+this->
fNrows);
2208 if (acoln >= this->
fNcols || acoln < 0) {
2209 Error(
"operator()",
"Request column(%d) outside matrix range of %d - %d",coln,this->fColLwb,this->fColLwb+this->
fNcols);
2216 if (index < sIndex ||
fColIndex[index] != acoln)
return 0.0;
2224 template<
class Element>
2228 Error(
"operator=(const TMatrixTSparse &)",
"matrices not compatible");
2237 memcpy(tp,sp,this->
fNelems*
sizeof(Element));
2247 template<
class Element>
2251 Error(
"operator=(const TMatrixT &)",
"matrices not compatible");
2260 for (
Int_t irow = 0; irow < this->
fNrows; irow++) {
2264 for (
Int_t index = sIndex; index < eIndex; index++) {
2266 tp[index] = sp[off+icol];
2278 template<
class Element>
2284 Error(
"operator=(Element",
"row/col indices are not set");
2289 const Element *
const ep_last = ep+this->
fNelems;
2290 while (ep < ep_last)
2299 template<
class Element>
2305 const Element *
const ep_last = ep+this->
fNelems;
2306 while (ep < ep_last)
2315 template<
class Element>
2321 const Element *
const ep_last = ep+this->
fNelems;
2322 while (ep < ep_last)
2331 template<
class Element>
2337 const Element *
const ep_last = ep+this->
fNelems;
2338 while (ep < ep_last)
2347 template<
class Element>
2352 const Element scale = beta-alpha;
2353 const Element shift = alpha/scale;
2368 for (
Int_t k = 0; k < nn; k++) {
2369 const Element
r =
Drand(seed);
2371 if ((nn-k)*r < length-chosen) {
2372 pColIndex[chosen] = k%
n;
2375 if (irow > icurrent) {
2376 for ( ; icurrent < irow; icurrent++)
2377 pRowIndex[icurrent+1] = chosen;
2379 ep[chosen] = scale*(
Drand(seed)+shift);
2383 for ( ; icurrent <
m; icurrent++)
2384 pRowIndex[icurrent+1] = length;
2394 template<
class Element>
2397 const Element scale = beta-alpha;
2398 const Element shift = alpha/scale;
2404 Error(
"RandomizePD(Element &",
"matrix should be square");
2420 ep[0] = 1e-8+scale*(
Drand(seed)+shift);
2424 const Int_t nn = n*(n-1)/2;
2430 length = (length <= nn) ? length : nn;
2440 for (
Int_t k = 0; k < nn; k++ ) {
2441 const Element
r =
Drand(seed);
2443 if( (nn-k)*r < length-chosen) {
2450 Int_t col = k-row*(row+1)/2;
2455 if (row > icurrent) {
2459 for ( ; icurrent < row; icurrent++) {
2462 for (
Int_t ll = pRowIndex[icurrent]; ll < nnz; ll++)
2464 ep[nnz] += 1e-8+scale*(
Drand(seed)+shift);
2465 pColIndex[nnz] = icurrent;
2468 pRowIndex[icurrent+1] = nnz;
2471 ep[nnz] = scale*(
Drand(seed)+shift);
2472 pColIndex[nnz] = col;
2475 ep[pRowIndex[col+1]-1] +=
TMath::Abs(ep[nnz]);
2485 for ( ; icurrent <
n; icurrent++) {
2488 for(
Int_t ll = pRowIndex[icurrent]; ll < nnz; ll++)
2490 ep[nnz] += 1e-8+scale*(
Drand(seed)+shift);
2491 pColIndex[nnz] = icurrent;
2494 pRowIndex[icurrent+1] = nnz;
2507 for (
Int_t irow = 0; irow < this->
fNrows+1; irow++) {
2508 const Int_t sIndex = pR[irow];
2509 const Int_t eIndex = pR[irow+1];
2510 for (
Int_t index = sIndex; index < eIndex; index++) {
2511 const Int_t icol = pC[index];
2523 template<
class Element>
2532 template<
class Element>
2541 template<
class Element>
2550 template<
class Element>
2560 template<
class Element>
2570 template<
class Element>
2579 template<
class Element>
2588 template<
class Element>
2597 template<
class Element>
2607 template<
class Element>
2617 template<
class Element>
2626 template<
class Element>
2635 template<
class Element>
2644 template<
class Element>
2654 template<
class Element>
2665 template<
class Element>
2668 target += scalar * source;
2675 template<
class Element>
2679 ::Error(
"ElementMult(TMatrixTSparse &,const TMatrixTSparse &)",
"matrices not compatible");
2695 template<
class Element>
2699 ::Error(
"ElementDiv(TMatrixT &,const TMatrixT &)",
"matrices not compatible");
2706 while ( tp < ftp ) {
2710 Error(
"ElementDiv",
"source element is zero");
2720 template<
class Element>
2725 ::Error(
"AreCompatible",
"matrix 1 not valid");
2730 ::Error(
"AreCompatible",
"matrix 2 not valid");
2737 ::Error(
"AreCompatible",
"matrices 1 and 2 not compatible");
2744 if (memcmp(pR1,pR2,(nRows+1)*
sizeof(
Int_t))) {
2746 ::Error(
"AreCompatible",
"matrices 1 and 2 have different rowIndex");
2747 for (
Int_t i = 0; i < nRows+1; i++)
2748 printf(
"%d: %d %d\n",i,pR1[i],pR2[i]);
2754 if (memcmp(pD1,pD2,nData*
sizeof(
Int_t))) {
2756 ::Error(
"AreCompatible",
"matrices 1 and 2 have different colIndex");
2757 for (
Int_t i = 0; i < nData; i++)
2758 printf(
"%d: %d %d\n",i,pD1[i],pD2[i]);
2768 template<
class Element>
2785 #ifndef ROOT_TMatrixFSparsefwd 2788 #ifndef ROOT_TMatrixFfwd 2814 #ifndef ROOT_TMatrixDSparsefwd 2817 #ifndef ROOT_TMatrixDfwd void AMinusB(const TMatrixTSparse< Element > &a, const TMatrixTSparse< Element > &b, Int_t constr=0)
General matrix subtraction.
virtual const Element * GetMatrixArray() const =0
virtual const Element * GetMatrixArray() const
virtual Int_t NonZeros() const
Compute the number of elements != 0.0.
virtual Int_t NonZeros() const
Compute the number of elements != 0.0.
virtual TMatrixTBase< Element > & InsertRow(Int_t row, Int_t col, const Element *v, Int_t n=-1)
Insert in row rown, n elements of array v at column coln.
virtual void GetMatrix2Array(Element *data, Option_t *="") const
Copy matrix data to array . It is assumed that array is of size >= fNelems.
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Double_t Floor(Double_t x)
Long64_t LocMax(Long64_t n, const T *a)
virtual const Int_t * GetRowIndexArray() const
TMatrixTSparse< Element > & Transpose(const TMatrixTSparse< Element > &source)
Transpose a matrix.
virtual const Element * GetMatrixArray() const
virtual TMatrixTBase< Element > & UnitMatrix()
Make a unit matrix (matrix need not be a square one).
template TMatrixDSparse & Add< Double_t >(TMatrixDSparse &target, Double_t scalar, const TMatrixDSparse &source)
void ToUpper()
Change string to upper case.
Buffer base class used for serializing objects.
template TMatrixDSparse & ElementMult< Double_t >(TMatrixDSparse &target, const TMatrixDSparse &source)
template TMatrixFSparse & ElementDiv< Float_t >(TMatrixFSparse &target, const TMatrixFSparse &source)
virtual TMatrixTBase< Element > & SetMatrixArray(const Element *data, Option_t *="")
Copy array data to matrix .
Short_t Min(Short_t a, Short_t b)
Element operator()(Int_t rown, Int_t coln) const
virtual TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t nr_nonzeros=-1)=0
template TMatrixFSparse & Add< Float_t >(TMatrixFSparse &target, Float_t scalar, const TMatrixFSparse &source)
double beta(double x, double y)
Calculates the beta function.
template TMatrixFSparse & ElementMult< Float_t >(TMatrixFSparse &target, const TMatrixFSparse &source)
Int_t GetNoElements() const
static void DoubleLexSort(Int_t n, Int_t *first, Int_t *second, Element *data)
default kTRUE, when Use array kFALSE
#define templateClassImp(name)
template Bool_t AreCompatible< Float_t >(const TMatrixFSparse &m1, const TMatrixFSparse &m2, Int_t verbose)
void Info(const char *location, const char *msgfmt,...)
Bool_t AreCompatible(const TMatrixTSparse< Element > &m1, const TMatrixTSparse< Element > &m2, Int_t verbose)
virtual TMatrixTBase< Element > & Randomize(Element alpha, Element beta, Double_t &seed)
randomize matrix element values
void AMultBt(const TMatrixTSparse< Element > &a, const TMatrixTSparse< Element > &b, Int_t constr=0)
General matrix multiplication.
TMatrixTSparse< Element > & ElementMult(TMatrixTSparse< Element > &target, const TMatrixTSparse< Element > &source)
Multiply target by the source, element-by-element.
TObject & operator=(const TObject &rhs)
TObject assignment operator.
virtual TMatrixTSparse< Element > & RandomizePD(Element alpha, Element beta, Double_t &seed)
randomize matrix element values but keep matrix symmetric positive definite
TMatrixTSparse< Element > & Add(TMatrixTSparse< Element > &target, Element scalar, const TMatrixTSparse< Element > &source)
Modify addition: target += scalar * source.
void Error(const char *location, const char *msgfmt,...)
virtual Element ColNorm() const
Column matrix norm, MAX{ SUM{ |M(i,j)|, over i}, over j}.
TMatrixTSparse< Element > & operator-=(Element val)
Subtract val from every element of the matrix.
virtual TMatrixTBase< Element > & Zero()
Set matrix elements to zero.
Double_t length(const TVector2 &v)
template TMatrixDSparse & ElementDiv< Double_t >(TMatrixDSparse &target, const TMatrixDSparse &source)
virtual void Clear(Option_t *="")
TMatrixTSparse< Element > & operator*=(Element val)
Multiply every element of the matrix with val.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
TMatrixTSparse< Element > & SetSparseIndex(Int_t nelem_new)
Increase/decrease the number of non-zero elements to nelems_new.
TMatrixTSparse< Element > operator+(const TMatrixTSparse< Element > &source1, const TMatrixTSparse< Element > &source2)
R__EXTERN Int_t gMatrixCheck
virtual const Int_t * GetColIndexArray() const
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.
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
TMatrixTSparse< Element > & ElementDiv(TMatrixTSparse< Element > &target, const TMatrixTSparse< Element > &source)
Divide target by the source, element-by-element.
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)
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 ...
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
template Bool_t AreCompatible< Double_t >(const TMatrixDSparse &m1, const TMatrixDSparse &m2, Int_t verbose)
TCppObject_t Allocate(TCppType_t type)
virtual TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t nr_nonzeros=-1)
Set size of the matrix to nrows x ncols with nr_nonzeros non-zero entries if nr_nonzeros > 0 ...
TMatrixTSparse< Element > & operator+=(Element val)
Add val to every element of the matrix.
Short_t Max(Short_t a, Short_t b)
virtual Element RowNorm() const
Row matrix norm, MAX{ SUM{ |M(i,j)|, over j}, over i}.
TMatrixTSparse< Element > & operator=(const TMatrixT< Element > &source)
Notice that the sparsity of the matrix is NOT changed : its fRowIndex/fColIndex are used ! ...
Double_t Sqrt(Double_t x)
void AMultB(const TMatrixTSparse< Element > &a, const TMatrixTSparse< Element > &b, Int_t constr=0)
virtual 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
Get submatrix [row_lwb..row_upb][col_lwb..col_upb]; The indexing range of the returned matrix depends...
virtual void ExtractRow(Int_t row, Int_t col, Element *v, Int_t n=-1) const
Store in array v, n matrix elements of row rown starting at column coln.
Long64_t LocMin(Long64_t n, const T *a)
TMatrixTSparse< Element > operator-(const TMatrixTSparse< Element > &source1, const TMatrixTSparse< Element > &source2)
void APlusB(const TMatrixTSparse< Element > &a, const TMatrixTSparse< Element > &b, Int_t constr=0)
General matrix addition.
double norm(double *x, double *p)
Double_t Drand(Double_t &ix)
Random number generator [0....1] with seed ix.
TMatrixTSparse< Element > operator*(const TMatrixTSparse< Element > &source1, const TMatrixTSparse< Element > &source2)
Long64_t BinarySearch(Long64_t n, const T *array, T value)
virtual TMatrixTBase< Element > & SetSub(Int_t row_lwb, Int_t col_lwb, const TMatrixTBase< Element > &source)
Insert matrix source starting at [row_lwb][col_lwb], thereby overwriting the part [row_lwb...
virtual const Int_t * GetColIndexArray() const =0
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
virtual const Int_t * GetRowIndexArray() const =0