21 #ifndef SELDON_FILE_MATRIX_CONVERSIONS_CXX
24 #include "Matrix_Conversions.hxx"
38 template<
class T,
class Prop,
class Allocator1,
class Allocator2,
39 class Tint,
class Allocator3,
class Allocator4>
50 long nnz = A.GetDataSize();
51 IndRow.Reallocate(nnz);
52 IndCol.Reallocate(nnz);
54 long* ptr = A.GetPtr();
55 int* ind = A.GetInd();
57 for (i = 0; i < m; i++)
58 for (j = ptr[i]; j< ptr[i+1]; j++)
60 IndRow(j) = i + index;
61 IndCol(j) = ind[j] + index;
68 template<
class T,
class Prop,
class Allocator1,
class Allocator2,
69 class Tint,
class Allocator3,
class Allocator4>
80 long nnz = A.GetDataSize();
81 IndCol.Reallocate(nnz);
82 IndRow.Reallocate(nnz);
84 long* ptr = A.GetPtr();
85 int* ind = A.GetInd();
87 for (i = 0; i < n; i++)
88 for (j = ptr[i]; j< ptr[i+1]; j++)
90 IndCol(j) = i + index;
91 IndRow(j) = ind[j] + index;
98 template<
class T,
class Prop,
class Allocator1,
class Allocator2,
99 class Tint,
class Allocator3,
class Allocator4>
110 long nnz = A.GetDataSize();
111 long* ptr = A.GetPtr();
112 int* ind = A.GetInd();
113 T* val = A.GetData();
120 for (i = 0; i < m; i++)
121 for (j = ptr[i]; j < ptr[i + 1]; j++)
123 NumNnzRow(ind[j] + 1)++;
127 for (i = 0; i < m; i++)
128 nnz += NumNnzRow(i+1) + ptr[i+1] - ptr[i];
131 for (i = 0; i < m; i++)
132 NumNnzRow(i+1) += NumNnzRow(i);
135 IndRow.Reallocate(nnz);
136 IndCol.Reallocate(nnz);
140 for (i = 0; i < m; i++)
141 for (j = ptr[i]; j < ptr[i + 1]; j++)
144 long num = NumNnzRow(i+1) + j;
145 IndRow(num) = i + index;
146 IndCol(num) = ind[j] + index;
152 num = NumNnzRow(ind[j]) + ptr[ind[j]] + Ptr(ind[j]);
153 IndRow(num) = ind[j] + index;
154 IndCol(num) = i + index;
162 IndRow.Reallocate(nnz);
163 IndCol.Reallocate(nnz);
165 for (i = 0; i < m; i++)
166 for (j = ptr[i]; j < ptr[i + 1]; j++)
168 IndRow(j) = i + index;
169 IndCol(j) = ind[j] + index;
177 template<
class T,
class Prop,
class Allocator1,
class Allocator2,
178 class Tint,
class Allocator3,
class Allocator4>
189 long nnz = A.GetDataSize();
190 long* ptr = A.GetPtr();
191 int* ind = A.GetInd();
192 T* val = A.GetData();
199 for (i = 0; i < m; i++)
200 for (j = ptr[i]; j < ptr[i + 1]; j++)
202 NumNnzCol(ind[j] + 1)++;
206 for (i = 0; i < m; i++)
207 nnz += NumNnzCol(i+1) + ptr[i+1] - ptr[i];
210 for (i = 0; i < m; i++)
211 NumNnzCol(i+1) += NumNnzCol(i);
214 IndRow.Reallocate(nnz);
215 IndCol.Reallocate(nnz);
219 for (i = 0; i < m; i++)
220 for (j = ptr[i]; j < ptr[i + 1]; j++)
223 long num = NumNnzCol(i) + j;
224 IndRow(num) = ind[j] + index;
225 IndCol(num) = i + index;
231 num = NumNnzCol(ind[j]) + ptr[ind[j]+1] + Ptr(ind[j]);
232 IndRow(num) = i + index;
233 IndCol(num) = ind[j] + index;
241 IndRow.Reallocate(nnz);
242 IndCol.Reallocate(nnz);
244 for (i = 0; i < m; i++)
245 for (j = ptr[i]; j < ptr[i + 1]; j++)
247 IndCol(j) = i + index;
248 IndRow(j) = ind[j] + index;
261 template<
class T,
class Prop,
class Allocator1,
class Allocator2,
262 class Tint,
class Allocator3,
class Allocator4>
273 long nnz = A.GetDataSize();
276 IndRow.Reallocate(nnz);
277 IndCol.Reallocate(nnz);
280 for (i = 0; i < m; i++)
281 for (j = 0; j < A.GetRowSize(i); j++)
283 IndRow(nb) = i + index;
284 IndCol(nb) = A.Index(i, j) + index;
285 Val(nb) = A.Value(i, j);
292 template<
class T,
class Prop,
class Allocator1,
class Allocator2,
293 class Tint,
class Allocator3,
class Allocator4>
304 long nnz = A.GetDataSize();
307 IndRow.Reallocate(nnz);
308 IndCol.Reallocate(nnz);
311 for (i = 0; i < n; i++)
312 for (j = 0; j < A.GetColumnSize(i); j++)
314 IndRow(nb) = A.Index(i, j) + index;
315 IndCol(nb) = i + index;
316 Val(nb) = A.Value(i, j);
323 template<
class T,
class Prop,
class Allocator1,
class Allocator2,
324 class Tint,
class Allocator3,
class Allocator4>
335 long nnz = A.GetDataSize();
342 for (i = 0; i < m; i++)
343 for (j = 0; j < A.GetRowSize(i); j++)
344 if (A.Index(i, j) != i)
345 NumNnzRow(A.Index(i, j) + 1)++;
349 for (i = 0; i < m; i++)
350 nnz += NumNnzRow(i+1) + A.GetRowSize(i);
355 for (i = 0; i < m; i++)
357 NumNnzRow(i+1) += NumNnzRow(i);
358 NumUpper(i+1) = NumUpper(i) + A.GetRowSize(i);
362 IndRow.Reallocate(nnz);
363 IndCol.Reallocate(nnz);
367 for (i = 0; i < m; i++)
368 for (j = 0; j < A.GetRowSize(i); j++)
371 long num = NumNnzRow(i+1) + NumUpper(i) + j;
372 int jcol = A.Index(i, j);
373 IndRow(num) = i + index;
374 IndCol(num) = jcol + index;
375 Val(num) = A.Value(i, j);
380 num = NumNnzRow(jcol) + NumUpper(jcol) + Ptr(jcol);
381 IndRow(num) = jcol + index;
382 IndCol(num) = i + index;
383 Val(num) = A.Value(i, j);
391 IndRow.Reallocate(nnz);
392 IndCol.Reallocate(nnz);
395 for (i = 0; i < m; i++)
396 for (j = 0; j < A.GetRowSize(i); j++)
398 IndRow(nb) = i + index;
399 IndCol(nb) = A.Index(i, j) + index;
400 Val(nb) = A.Value(i, j);
408 template<
class T,
class Prop,
class Allocator1,
class Allocator2,
409 class Tint,
class Allocator3,
class Allocator4>
419 long nnz = A.GetDataSize();
426 for (
int i = 0; i < m; i++)
427 for (
int j = 0; j < A.GetColumnSize(i); j++)
428 if (A.Index(i, j) != i)
429 NumNnzCol(A.Index(i, j) + 1)++;
433 for (
int i = 0; i < m; i++)
434 nnz += NumNnzCol(i+1) + A.GetColumnSize(i);
439 for (
int i = 0; i < m; i++)
441 NumNnzCol(i+1) += NumNnzCol(i);
442 NumUpper(i+1) = NumUpper(i) + A.GetColumnSize(i);
446 IndRow.Reallocate(nnz);
447 IndCol.Reallocate(nnz);
451 for (
int i = 0; i < m; i++)
452 for (
int j = 0; j < A.GetColumnSize(i); j++)
455 long num = NumNnzCol(i) + NumUpper(i) + j;
456 int jrow = A.Index(i, j);
457 IndRow(num) = jrow + index;
458 IndCol(num) = i + index;
459 Val(num) = A.Value(i, j);
464 num = NumNnzCol(jrow) + NumUpper(jrow+1) + Ptr(jrow);
465 IndRow(num) = i + index;
466 IndCol(num) = jrow + index;
467 Val(num) = A.Value(i, j);
475 IndRow.Reallocate(nnz);
476 IndCol.Reallocate(nnz);
479 for (
int i = 0; i < m; i++)
480 for (
int j = 0; j < A.GetColumnSize(i); j++)
482 IndRow(nb) = A.Index(i, j) + index;
483 IndCol(nb) = i + index;
484 Val(nb) = A.Value(i, j);
512 template<
class T,
class Prop,
class Allocator1,
513 class Allocator2,
class Allocator3>
521 if (IndRow.GetM() <= 0)
524 long Nelement = IndRow.GetLength();
527 int row_max = IndRow.GetNormInf() - index;
528 int col_max = IndCol.GetNormInf() - index;
533 m = max(m, A.GetM());
534 n = max(n, A.GetN());
539 for (
int i = 0; i < Nelement; i++)
540 NumNnzRow(IndRow(i)-index)++;
545 for (
int i = 0; i < m; i++)
546 Ptr(i+1) = Ptr(i) + NumNnzRow(i);
552 for (
long i = 0; i < Nelement; i++)
554 int irow = IndRow(i) - index;
555 int icol = IndCol(i) - index;
556 long num = Ptr(irow) + NumNnzRow(irow);
558 Val(num) = Values(i);
563 for (
int i = 0; i < m; i++)
564 Sort(Ptr(i), Ptr(i+1)-1, Ind, Val);
567 A.SetData(m, n, Val, Ptr, Ind);
578 template<
class T,
class Prop,
class Allocator1,
579 class Allocator2,
class Allocator3>
587 if (IndRow.GetM() <= 0)
590 long Nelement = IndRow.GetLength();
593 int row_max = IndRow.GetNormInf() - index;
594 int col_max = IndCol.GetNormInf() - index;
599 m = max(m, A.GetM());
600 n = max(n, A.GetN());
605 for (
int i = 0; i < Nelement; i++)
606 NumNnzCol(IndCol(i)-index)++;
611 for (
int i = 0; i < n; i++)
612 Ptr(i+1) = Ptr(i) + NumNnzCol(i);
618 for (
long i = 0; i < Nelement; i++)
620 int irow = IndRow(i) - index;
621 int icol = IndCol(i) - index;
622 int num = Ptr(icol) + NumNnzCol(icol);
624 Val(num) = Values(i);
629 for (
int i = 0; i < n; i++)
630 Sort(Ptr(i), Ptr(i+1)-1, Ind, Val);
633 A.SetData(m, n, Val, Ptr, Ind);
638 template<
class T,
class Prop,
class Allocator1,
639 class Allocator2,
class Allocator3>
647 if (IndRow.GetM() <= 0)
650 long Nelement = IndRow.GetM();
653 int row_max = IndRow.GetNormInf() - index;
654 int col_max = IndCol.GetNormInf() - index;
659 m = max(m, n); n = m;
660 m = max(m, A.GetM());
661 n = max(n, A.GetN());
668 for (
int i = 0; i < Nelement; i++)
669 if (IndRow(i) <= IndCol(i))
670 NumNnzRow(IndRow(i)-index)++;
675 for (
int i = 0; i < m; i++)
676 Ptr(i+1) = Ptr(i) + NumNnzRow(i);
683 for (
long i = 0; i < Nelement; i++)
684 if (IndRow(i) <= IndCol(i))
686 int irow = IndRow(i) - index;
687 int icol = IndCol(i) - index;
688 long num = Ptr(irow) + NumNnzRow(irow);
690 Val(num) = Values(i);
695 for (
int i = 0; i < m; i++)
696 Sort(Ptr(i), Ptr(i+1)-1, Ind, Val);
698 A.SetData(m, n, Val, Ptr, Ind);
703 template<
class T,
class Prop,
class Allocator1,
704 class Allocator2,
class Allocator3>
712 if (IndRow.GetM() <= 0)
715 long Nelement = IndRow.GetM();
718 int row_max = IndRow.GetNormInf() - index;
719 int col_max = IndCol.GetNormInf() - index;
724 m = max(m, n); n = m;
725 m = max(m, A.GetM());
726 n = max(n, A.GetN());
733 for (
int i = 0; i < Nelement; i++)
734 if (IndRow(i) <= IndCol(i))
735 NumNnzCol(IndCol(i)-index)++;
740 for (
int i = 0; i < n; i++)
741 Ptr(i+1) = Ptr(i) + NumNnzCol(i);
748 for (
long i = 0; i < Nelement; i++)
749 if (IndRow(i) <= IndCol(i))
751 int irow = IndRow(i) - index;
752 int icol = IndCol(i) - index;
753 long num = Ptr(icol) + NumNnzCol(icol);
755 Val(num) = Values(i);
760 for (
int i = 0; i < n; i++)
761 Sort(Ptr(i), Ptr(i+1)-1, Ind, Val);
763 A.SetData(m, n, Val, Ptr, Ind);
773 template<
class T,
class Prop,
class Allocator1,
774 class Allocator2,
class Allocator3>
780 Allocator3>& A,
int index)
782 if (IndRow.GetM() <= 0)
785 long Nelement = IndRow.GetLength();
788 int row_max = IndRow.GetNormInf() - index;
789 int col_max = IndCol.GetNormInf() - index;
794 m = max(m, A.GetM());
795 n = max(n, A.GetN());
801 for (
int i = 0; i < Nelement; i++)
802 NumNnzRow(IndRow(i)-index)++;
805 for (
int i = 0; i < m; i++)
806 A.ReallocateRow(i, NumNnzRow(i));
810 for (
long i = 0; i < Nelement; i++)
812 int irow = IndRow(i) - index;
813 int icol = IndCol(i) - index;
814 int num = NumNnzRow(irow);
815 A.Index(irow, num) = icol;
816 A.Value(irow, num) = Values(i);
826 template<
class T,
class Prop,
class Allocator1,
827 class Allocator2,
class Allocator3>
833 Allocator3>& A,
int index)
835 if (IndRow.GetM() <= 0)
838 long Nelement = IndRow.GetLength();
841 int row_max = IndRow.GetNormInf() - index;
842 int col_max = IndCol.GetNormInf() - index;
847 m = max(m, A.GetM());
848 n = max(n, A.GetN());
854 for (
int i = 0; i < Nelement; i++)
855 NumNnzCol(IndCol(i)-index)++;
858 for (
int i = 0; i < n; i++)
859 A.ReallocateColumn(i, NumNnzCol(i));
863 for (
long i = 0; i < Nelement; i++)
865 int irow = IndRow(i) - index;
866 int icol = IndCol(i) - index;
867 int num = NumNnzCol(icol);
868 A.Index(icol, num) = irow;
869 A.Value(icol, num) = Values(i);
879 template<
class T,
class Prop,
class Allocator1,
880 class Allocator2,
class Allocator3>
886 Allocator3>& A,
int index)
888 if (IndRow.GetM() <= 0)
891 long Nelement = IndRow.GetLength();
894 int row_max = IndRow.GetNormInf() - index;
895 int col_max = IndCol.GetNormInf() - index;
900 m = max(m, n); n = m;
901 m = max(m, A.GetM());
902 n = max(n, A.GetN());
910 for (
int i = 0; i < Nelement; i++)
911 if (IndRow(i) <= IndCol(i))
912 NumNnzRow(IndRow(i)-index)++;
915 for (
int i = 0; i < m; i++)
916 A.ReallocateRow(i, NumNnzRow(i));
920 for (
long i = 0; i < Nelement; i++)
921 if (IndRow(i) <= IndCol(i))
923 int irow = IndRow(i) - index;
924 int icol = IndCol(i) - index;
925 int num = NumNnzRow(irow);
926 A.Index(irow, num) = icol;
927 A.Value(irow, num) = Values(i);
937 template<
class T,
class Prop,
class Allocator1,
938 class Allocator2,
class Allocator3>
947 if (IndRow.GetM() <= 0)
950 long Nelement = IndRow.GetLength();
953 int row_max = IndRow.GetNormInf() - index;
954 int col_max = IndCol.GetNormInf() - index;
959 m = max(m, n); n = m;
960 m = max(m, A.GetM());
961 n = max(n, A.GetN());
967 for (
int i = 0; i < Nelement; i++)
968 if (IndRow(i) <= IndCol(i))
969 NumNnzCol(IndCol(i)-index)++;
972 for (
int i = 0; i < n; i++)
973 A.ReallocateColumn(i, NumNnzCol(i));
977 for (
long i = 0; i < Nelement; i++)
978 if (IndRow(i) <= IndCol(i))
980 int irow = IndRow(i) - index;
981 int icol = IndCol(i) - index;
982 int num = NumNnzCol(icol);
983 A.Index(icol, num) = irow;
984 A.Value(icol, num) = Values(i);
1004 template<
class T,
class Prop,
class Alloc1,
class Tint0,
1005 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
1012 long nnz = A.GetDataSize();
1014 long* ptr_ = A.GetPtr();
1015 int* ind_ = A.GetInd();
1016 T* data_ = A.GetData();
1021 for (
int i = 0; i < nnz; i++)
1022 NumNnzCol(ind_[i])++;
1025 Ptr.Reallocate(n+1);
1027 for (
int i = 0; i < n; i++)
1028 Ptr(i+1) = Ptr(i) + NumNnzCol(i);
1032 IndRow.Reallocate(nnz);
1033 Val.Reallocate(nnz);
1035 for (
int i = 0; i < A.GetM(); i++)
1036 for (
long j = ptr_[i]; j < ptr_[i+1]; j++)
1038 long num = Ptr(ind_[j]) + NumNnzCol(ind_[j]);
1040 Val(num) = data_[j];
1041 NumNnzCol(ind_[j])++;
1044 long nb_new_val = 0;
1049 for (
int i = 0; i < n; i++)
1052 for (
long j = ptr_[i]; j < ptr_[i+1]; j++)
1055 while (k < Ptr(i+1) && IndRow(k) < irow)
1058 if (k < Ptr(i+1) && IndRow(k) == irow)
1071 if (sym_pat && (nb_new_val > 0))
1076 IndRow.Reallocate(nnz + nb_new_val);
1077 Val.Reallocate(nnz + nb_new_val);
1079 T zero; SetComplexZero(zero);
1080 for (
int i = 0; i < n; i++)
1083 for (
long j = ptr_[i]; j < ptr_[i+1]; j++)
1086 while (k < Ptr(i+1) && OldInd(k) < irow)
1088 IndRow(nb) = OldInd(k);
1089 Val(nb) = OldVal(k);
1094 if (k < Ptr(i+1) && OldInd(k) == irow)
1097 IndRow(nb) = OldInd(k);
1098 Val(nb) = OldVal(k);
1112 while (k < Ptr(i+1))
1114 IndRow(nb) = OldInd(k);
1115 Val(nb) = OldVal(k);
1123 for (
int i = 0; i < n; i++)
1124 Ptr(i + 1) = Ptr(i) + NumNnzCol(i);
1130 template<
class T,
class Prop,
class Alloc1,
class Tint0,
1131 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
1138 long nnz = A.GetDataSize();
1144 for (
int i = 0; i < A.GetM(); i++)
1145 for (
int j = 0; j < A.GetRowSize(i); j++)
1146 NumNnzCol(A.Index(i, j))++;
1149 Ptr.Reallocate(n+1);
1151 for (
int i = 0; i < n; i++)
1152 Ptr(i+1) = Ptr(i) + NumNnzCol(i);
1156 IndRow.Reallocate(nnz);
1157 Val.Reallocate(nnz);
1159 for (
int i = 0; i < A.GetM(); i++)
1160 for (
int j = 0; j < A.GetRowSize(i); j++)
1162 int jcol = A.Index(i, j);
1163 long num = Ptr(jcol) + NumNnzCol(jcol);
1165 Val(num) = A.Value(i, j);
1169 long nb_new_val = 0;
1174 for (
int i = 0; i < n; i++)
1177 for (
int j = 0; j < A.GetRowSize(i); j++)
1179 int irow = A.Index(i, j);
1180 while (k < Ptr(i+1) && IndRow(k) < irow)
1183 if (k < Ptr(i+1) && IndRow(k) == irow)
1196 if (sym_pat && (nb_new_val > 0))
1201 IndRow.Reallocate(nnz + nb_new_val);
1202 Val.Reallocate(nnz + nb_new_val);
1204 T zero; SetComplexZero(zero);
1205 for (
int i = 0; i < n; i++)
1207 for (
int j = 0; j < A.GetRowSize(i); j++)
1209 int irow = A.Index(i, j);
1210 while (k < Ptr(i+1) && OldInd(k) < irow)
1212 IndRow(nb) = OldInd(k);
1213 Val(nb) = OldVal(k);
1218 if (k < Ptr(i+1) && OldInd(k) == irow)
1221 IndRow(nb) = OldInd(k);
1222 Val(nb) = OldVal(k);
1235 while (k < Ptr(i+1))
1237 IndRow(nb) = OldInd(k);
1238 Val(nb) = OldVal(k);
1246 for (
int i = 0; i < n; i++)
1247 Ptr(i + 1) = Ptr(i) + NumNnzCol(i);
1253 template<
class T,
class Prop,
class Alloc1,
class Tint0,
1254 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
1261 long nnz = A.GetDataSize();
1263 long* ptr_ = A.GetPtr();
1264 int* ind_ = A.GetInd();
1265 T* data_ = A.GetData();
1270 Ptr.Reallocate(n+1);
1271 IndRow.Reallocate(nnz);
1272 Val.Reallocate(nnz);
1273 for (
int i = 0; i <= n; i++)
1276 for (
long i = 0; i < nnz; i++)
1278 IndRow(i) = ind_[i];
1287 for (
int i = 0; i < nnz; i++)
1288 PtrRow(ind_[i]+1)++;
1291 for (
int i = 0; i < A.GetM(); i++)
1292 PtrRow(i+1) += PtrRow(i);
1296 for (
int i = 0; i < n; i++)
1297 for (
long j = ptr_[i]; j < ptr_[i+1]; j++)
1299 long num = PtrRow(ind_[j]);
1305 for (
int i = A.GetM()-1; i >= 1; i--)
1306 PtrRow(i) -= PtrRow(i) - PtrRow(i-1);
1310 Ptr.Reallocate(n+1);
1311 for (
int i = 0; i <= n; i++)
1314 long nb_new_val = 0;
1317 for (
int i = 0; i < n; i++)
1321 for (
long j = PtrRow(i); j < PtrRow(i+1); j++)
1323 int irow = IndCol(j);
1324 while (k < ptr_[i+1] && ind_[k] < irow)
1327 if (k < ptr_[i+1] && ind_[k] == irow)
1341 IndRow.Reallocate(nnz + nb_new_val);
1342 Val.Reallocate(nnz + nb_new_val);
1344 T zero; SetComplexZero(zero);
1346 for (
int i = 0; i < n; i++)
1349 for (
long j = PtrRow(i); j < PtrRow(i+1); j++)
1351 int irow = IndCol(j);
1352 while (k < ptr_[i+1] && ind_[k] < irow)
1354 IndRow(nb) = ind_[k];
1360 if (k < ptr_[i+1] && ind_[k] == irow)
1363 IndRow(nb) = ind_[k];
1378 while (k < ptr_[i+1])
1380 IndRow(nb) = ind_[k];
1394 template<
class T,
class Prop,
class Alloc1,
class Tint0,
1395 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
1407 Ptr.Reallocate(n+1);
1410 for (
int i = 0; i < n; i++)
1412 nnz += A.GetColumnSize(i);
1416 IndRow.Reallocate(nnz);
1417 Val.Reallocate(nnz);
1418 for (
int i = 0; i < n; i++)
1419 for (
int j = 0; j < A.GetColumnSize(i); j++)
1421 IndRow(Ptr(i) + j) = A.Index(i, j);
1422 Val(Ptr(i) + j) = A.Value(i, j);
1430 for (
int i = 0; i < n; i++)
1431 for (
int j = 0; j < A.GetColumnSize(i); j++)
1432 PtrRow(A.Index(i, j) + 1)++;
1435 for (
int i = 0; i < A.GetM(); i++)
1436 PtrRow(i+1) += PtrRow(i);
1439 long nnz = PtrRow(A.GetM());
1441 for (
int i = 0; i < n; i++)
1442 for (
int j = 0; j < A.GetColumnSize(i); j++)
1444 long num = PtrRow(A.Index(i, j));
1446 PtrRow(A.Index(i, j))++;
1450 for (
long i = A.GetM()-1; i >= 1; i--)
1451 PtrRow(i) -= PtrRow(i) - PtrRow(i-1);
1455 Ptr.Reallocate(n+1);
1457 for (
int i = 0; i < n; i++)
1458 Ptr(i+1) = Ptr(i) + A.GetColumnSize(i);
1460 long nb_new_val = 0;
1463 for (
int i = 0; i < n; i++)
1466 for (
long j = PtrRow(i); j < PtrRow(i+1); j++)
1468 int irow = IndCol(j);
1469 while (k < A.GetColumnSize(i) && A.Index(i, k) < irow)
1472 if (k < A.GetColumnSize(i) && A.Index(i, k) == irow)
1486 IndRow.Reallocate(nnz + nb_new_val);
1487 Val.Reallocate(nnz + nb_new_val);
1489 T zero; SetComplexZero(zero);
1491 for (
int i = 0; i < n; i++)
1495 for (
long j = PtrRow(i); j < PtrRow(i+1); j++)
1497 int irow = IndCol(j);
1498 while (k < A.GetColumnSize(i) && A.Index(i, k) < irow)
1500 IndRow(nb) = A.Index(i, k);
1501 Val(nb) = A.Value(i, k);
1506 if (k < A.GetColumnSize(i) && A.Index(i, k) == irow)
1509 IndRow(nb) = A.Index(i, k);
1510 Val(nb) = A.Value(i, k);
1524 while (k < A.GetColumnSize(i))
1526 IndRow(nb) = A.Index(i, k);
1527 Val(nb) = A.Value(i, k);
1540 template<
class T,
class Prop,
class Alloc1,
class Tint0,
1541 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
1548 long nnz = A.GetDataSize();
1550 Ptr.Reallocate(n+1);
1551 Ind.Reallocate(nnz);
1552 Value.Reallocate(nnz);
1554 long* ptr_ = A.GetPtr();
1555 int* ind_ = A.GetInd();
1556 T* data_ = A.GetData();
1557 for (
int i = 0; i <= n; i++)
1560 for (
long i = 0; i < nnz; i++)
1563 Value(i) = data_[i];
1569 template<
class T,
class Prop,
class Alloc1,
class Tint0,
1570 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
1581 ConvertMatrix_to_Coordinates(A, IndRow, IndCol, Value, 0,
true);
1583 Ptr.Reallocate(n+1);
1587 for (
long i = 0; i < IndCol.GetM(); i++)
1589 Ptr(IndCol(i) + 1)++;
1594 for (
int i = 2; i <= n; i++)
1601 template<
class T,
class Prop,
class Alloc1,
class Tint0,
1602 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
1609 long nnz = A.GetDataSize();
1611 Ptr.Reallocate(n+1);
1612 Ind.Reallocate(nnz);
1613 Value.Reallocate(nnz);
1616 for (
int i = 1; i <= n; i++)
1617 Ptr(i) = Ptr(i-1) + A.GetColumnSize(i-1);
1620 for (
int i = 0; i < n; i++)
1621 for (
int j = 0; j < A.GetColumnSize(i); j++)
1623 Ind(nb) = A.Index(i, j);
1624 Value(nb) = A.Value(i, j);
1631 template<
class T,
class Prop,
class Alloc1,
class Tint0,
1632 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
1643 ConvertMatrix_to_Coordinates(A, IndRow, IndCol, Value, 0,
true);
1645 Ptr.Reallocate(n+1);
1649 for (
long i = 0; i < IndCol.GetM(); i++)
1651 Ptr(IndCol(i) + 1)++;
1656 for (
int i = 2; i <= n; i++)
1663 template<
class T,
class Prop,
class Alloc1,
class Tint0,
1664 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
1670 long nnz = A.GetDataSize();
1672 long* ptr_ = A.GetPtr();
1673 int* ind_ = A.GetInd();
1674 T* data_ = A.GetData();
1679 for (
long i = 0; i < nnz; i++)
1680 NumNnzCol(ind_[i])++;
1683 Ptr.Reallocate(n+1);
1685 for (
int i = 0; i < n; i++)
1686 Ptr(i+1) = Ptr(i) + NumNnzCol(i);
1690 IndRow.Reallocate(nnz);
1691 Val.Reallocate(nnz);
1693 for (
int i = 0; i < A.GetM(); i++)
1694 for (
long j = ptr_[i]; j < ptr_[i+1]; j++)
1696 long num = Ptr(ind_[j]) + NumNnzCol(ind_[j]);
1698 Val(num) = data_[j];
1699 NumNnzCol(ind_[j])++;
1705 template<
class T,
class Prop,
class Alloc1,
class Tint0,
1706 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
1719 ConvertMatrix_to_Coordinates(A, IndCol, IndRow, Value, 0,
true);
1721 Ptr.Reallocate(n+1);
1725 for (
long i = 0; i < IndCol.GetM(); i++)
1727 Ptr(IndCol(i) + 1)++;
1732 for (
int i = 2; i <= n; i++)
1738 template<
class T,
class Prop,
class Alloc1,
class Tint0,
1739 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
1745 long nnz = A.GetDataSize();
1751 for (
int i = 0; i < A.GetM(); i++)
1752 for (
int j = 0; j < A.GetRowSize(i); j++)
1753 NumNnzCol(A.Index(i, j))++;
1756 Ptr.Reallocate(n+1);
1758 for (
int i = 0; i < n; i++)
1759 Ptr(i+1) = Ptr(i) + NumNnzCol(i);
1763 IndRow.Reallocate(nnz);
1764 Val.Reallocate(nnz);
1766 for (
int i = 0; i < A.GetM(); i++)
1767 for (
int j = 0; j < A.GetRowSize(i); j++)
1769 int icol = A.Index(i, j);
1770 long num = Ptr(icol) + NumNnzCol(icol);
1772 Val(num) = A.Value(i, j);
1779 template<
class T,
class Prop,
class Alloc1,
class Tint0,
1780 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
1793 ConvertMatrix_to_Coordinates(A, IndCol, IndRow, Value, 0,
true);
1795 Ptr.Reallocate(n+1);
1799 for (
long i = 0; i < IndCol.GetM(); i++)
1801 Ptr(IndCol(i) + 1)++;
1806 for (
int i = 2; i <= n; i++)
1812 template<
class T,
class Prop,
class Allocator>
1821 template<
class T,
class Prop,
class Allocator>
1829 template<
class T,
class Prop,
class Allocator>
1838 template<
class T,
class Prop,
class Allocator>
1847 template<
class T,
class Prop,
class Allocator>
1856 template<
class T,
class Prop,
class Allocator>
1865 template<
class T,
class Prop,
class Allocator>
1874 template<
class T,
class Prop,
class Allocator>
1883 template<
class T,
class Prop,
class Allocator>
1892 template<
class T,
class Prop,
class Allocator>
1901 template<
class T,
class Prop,
class Allocator>
1910 template<
class T,
class Prop,
class Allocator>
1919 template<
class T0,
class Prop0,
class Allocator0,
1920 class T1,
class Prop1,
class Allocator1>
1929 ConvertToCSC(mat_array, sym, IndCol, IndRow, Val);
1931 int m = mat_array.GetM();
1932 int n = mat_array.GetN();
1934 mat_csc.SetData(m, n, Val, IndCol, IndRow);
1939 template<
class T,
class Prop,
class Alloc1,
class Alloc2>
1947 int m = A.GetM(), n = A.GetN();
1949 ConvertToCSC(A, sym, Ptr, Ind, Val);
1951 B.SetData(m, n, Val, Ptr, Ind);
1956 template<
class T,
class Prop,
class Alloc1,
class Alloc2>
1964 int m = A.GetM(), n = A.GetN();
1966 ConvertToCSC(A, sym, Ptr, Ind, Val);
1969 for (
int i = 0; i < n; i++)
1971 int size_col = Ptr(i+1) - Ptr(i);
1972 B.ReallocateColumn(i, size_col);
1973 for (
long j = Ptr(i); j < Ptr(i+1); j++)
1975 B.Index(i, j-Ptr(i)) = Ind(j);
1976 B.Value(i, j-Ptr(i)) = Val(j);
1983 template<
class T0,
class Prop0,
class Allocator0,
1984 class T1,
class Prop1,
class Allocator1>
1991 int m = mat_array.GetM();
1992 int n = mat_array.GetN();
1994 ConvertToCSC(mat_array, sym, Ptr, IndRow, Val);
1996 mat_csr.SetData(m, n, Val, Ptr, IndRow);
2001 template<
class T,
class Prop,
class Alloc1,
class Alloc2>
2009 int m = A.GetM(), n = A.GetN();
2011 ConvertToCSC(A, sym, Ptr, Ind, Val);
2013 B.SetData(m, n, Val, Ptr, Ind);
2018 template<
class T,
class Prop,
class Alloc1,
class Alloc2>
2026 int m = A.GetM(), n = A.GetN();
2028 ConvertToCSC(A, sym, Ptr, Ind, Val);
2030 B.SetData(m, n, Val, Ptr, Ind);
2035 template<
class T,
class Prop,
class Alloc1,
class Alloc2>
2043 int m = A.GetM(), n = A.GetN();
2045 ConvertToCSC(A, sym, Ptr, Ind, Val);
2047 B.SetData(m, n, Val, Ptr, Ind);
2052 template<
class T,
class Prop1,
class Prop2,
class Alloc1,
class Alloc2>
2060 int m = A.GetM(), n = A.GetN();
2062 ConvertToCSC(A, sym, Ptr, Ind, Val);
2064 B.SetData(m, n, Val, Ptr, Ind);
2069 template<
class T0,
class Prop0,
class Allocator0,
2070 class T1,
class Prop1,
class Allocator1>
2079 ConvertToCSC(A, sym, Ptr, Ind, AllVal);
2081 B.SetData(n, n, AllVal, Ptr, Ind);
2086 template<
class T,
class Prop1,
class Prop2,
class Alloc1,
class Alloc2>
2094 int m = A.GetM(), n = A.GetN();
2096 ConvertToCSC(A, sym, Ptr, Ind, Val);
2098 B.SetData(m, n, Val, Ptr, Ind);
2103 template<
class T,
class Prop1,
class Prop2,
class Alloc1,
class Alloc2>
2111 int m = A.GetM(), n = A.GetN();
2113 ConvertToCSC(A, sym, Ptr, Ind, Val);
2115 B.SetData(m, n, Val, Ptr, Ind);
2125 template<
class T,
class Prop,
class Alloc1,
class Tint0,
2126 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
2133 long nnz = A.GetDataSize();
2142 long* ptr_ = A.GetPtr();
2143 int* ind_ = A.GetInd();
2144 T* data_ = A.GetData();
2146 Ptr.Reallocate(m+1);
2147 IndCol.Reallocate(nnz);
2148 Value.Reallocate(nnz);
2149 for (
int i = 0; i <= m; i++)
2152 for (
long i = 0; i < nnz; i++)
2154 IndCol(i) = ind_[i];
2155 Value(i) = data_[i];
2161 template<
class T,
class Prop,
class Alloc1,
class Tint0,
2162 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
2170 long nnz = A.GetDataSize();
2179 long* ptr_ = A.GetPtr();
2180 int* ind_ = A.GetInd();
2181 T* data_ = A.GetData();
2184 Ptr.Reallocate(m + 1);
2187 for (
long i = 0; i < nnz; i++)
2191 long increment = 0, size;
int num_row;
2192 for (
int i = 0; i < m; i++)
2204 IndCol.Reallocate(nnz);
2205 Value.Reallocate(nnz);
2208 for (
int j = 0; j < n; j++)
2209 for (
long i = ptr_[j]; i < ptr_[j + 1]; i++)
2212 IndCol(Offset(num_row)) = j;
2213 Value(Offset(num_row)) = data_[i];
2220 template<
class T,
class Prop,
class Alloc1,
class Tint0,
2221 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
2229 long nnz = A.GetDataSize();
2239 Ptr.Reallocate(m + 1);
2242 for (
int i = 0; i < n; i++)
2243 for (
int j = 0; j < A.GetColumnSize(i); j++)
2244 Ptr(A.Index(i, j))++;
2247 long increment = 0, size;
int num_row;
2248 for (
int i = 0; i < m; i++)
2260 IndCol.Reallocate(nnz);
2261 Value.Reallocate(nnz);
2264 for (
int j = 0; j < n; j++)
2265 for (
int i = 0; i < A.GetColumnSize(j); i++)
2267 num_row = A.Index(j, i);
2268 IndCol(Offset(num_row)) = j;
2269 Value(Offset(num_row)) = A.Value(j, i);
2276 template<
class T,
class Prop,
class Alloc1,
class Tint0,
2277 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
2284 long nnz = A.GetDataSize();
2293 Ptr.Reallocate(m+1);
2294 IndCol.Reallocate(nnz);
2295 Value.Reallocate(nnz);
2296 nnz = 0; Ptr(0) = 0;
2297 for (
int i = 0; i < m; i++)
2299 for (
int j = 0; j < A.GetRowSize(i); j++)
2301 IndCol(nnz + j) = A.Index(i, j);
2302 Value(nnz + j) = A.Value(i, j);
2305 nnz += A.GetRowSize(i);
2312 template<
class T,
class Prop,
class Alloc1,
class Tint0,
2313 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
2330 for (
int i = 0; i < m; i++)
2331 for (
int j = 0; j < A.GetRowSize(i); j++)
2332 if (A.Index(i, j) >= i)
2335 Ptr.Reallocate(m+1);
2336 IndCol.Reallocate(nnz);
2337 Value.Reallocate(nnz);
2338 nnz = 0; Ptr(0) = 0;
2339 for (
int i = 0; i < m; i++)
2341 for (
int j = 0; j < A.GetRowSize(i); j++)
2342 if (A.Index(i, j) >= i)
2344 IndCol(nnz) = A.Index(i, j);
2345 Value(nnz) = A.Value(i, j);
2355 template<
class T,
class Prop,
class Alloc1,
class Tint0,
2356 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
2362 long nnz = A.GetDataSize();
2364 long* ptr_ = A.GetPtr();
2365 int* ind_ = A.GetInd();
2366 T* data_ = A.GetData();
2371 for (
long i = 0; i < nnz; i++)
2372 NumNnzRow(ind_[i])++;
2375 Ptr.Reallocate(m+1);
2377 for (
int i = 0; i < m; i++)
2378 Ptr(i+1) = Ptr(i) + NumNnzRow(i);
2382 IndCol.Reallocate(nnz);
2383 Val.Reallocate(nnz);
2385 for (
int i = 0; i < m; i++)
2386 for (
long j = ptr_[i]; j < ptr_[i+1]; j++)
2388 long num = Ptr(ind_[j]) + NumNnzRow(ind_[j]);
2390 Val(num) = data_[j];
2391 NumNnzRow(ind_[j])++;
2397 template<
class T,
class Prop,
class Alloc1,
class Tint0,
2398 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
2409 ConvertMatrix_to_Coordinates(A, IndCol, IndRow, Value, 0,
true);
2412 Ptr.Reallocate(m+1);
2415 for (
int i = 0; i < IndCol.GetM(); i++)
2416 Ptr(IndRow(i) + 1)++;
2419 for (
int i = 2; i <= m; i++)
2426 template<
class T,
class Prop,
class Alloc1,
class Tint0,
2427 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
2433 long nnz = A.GetDataSize();
2439 for (
int i = 0; i < m; i++)
2440 for (
int j = 0; j < A.GetColumnSize(i); j++)
2441 NumNnzRow(A.Index(i, j))++;
2444 Ptr.Reallocate(m+1);
2446 for (
int i = 0; i < m; i++)
2447 Ptr(i+1) = Ptr(i) + NumNnzRow(i);
2451 IndCol.Reallocate(nnz);
2452 Val.Reallocate(nnz);
2454 for (
int i = 0; i < m; i++)
2455 for (
int j = 0; j < A.GetColumnSize(i); j++)
2457 int icol = A.Index(i, j);
2458 long num = Ptr(icol) + NumNnzRow(icol);
2460 Val(num) = A.Value(i, j);
2467 template<
class T,
class Prop,
class Alloc1,
class Tint0,
2468 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
2479 ConvertMatrix_to_Coordinates(A, IndCol, IndRow, Value, 0,
true);
2482 Ptr.Reallocate(m+1);
2485 for (
long i = 0; i < IndCol.GetM(); i++)
2486 Ptr(IndRow(i) + 1)++;
2489 for (
int i = 2; i <= m; i++)
2495 template<
class T,
class Prop,
class Alloc1,
class Tint0,
2496 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
2503 long nnz = A.GetDataSize();
2505 long* ptr_ = A.GetPtr();
2506 int* ind_ = A.GetInd();
2507 T* data_ = A.GetData();
2510 Val.Reallocate(nnz);
2511 IndRow.Reallocate(m + 1);
2512 IndCol.Reallocate(nnz);
2516 for (
int i = 0; i < m; i++)
2518 for (
long k = ptr_[i]; k < ptr_[i+1]; k++)
2520 IndCol(ind) = ind_[k];
2521 Val(ind) = data_[k];
2525 IndRow(i + 1) = ind;
2531 template<
class T,
class Prop,
class Alloc1,
class Tint0,
2532 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
2541 ConvertMatrix_to_Coordinates(A, IndRow, IndCol, Value, 0,
true);
2544 Ptr.Reallocate(m+1);
2547 for (
long i = 0; i < IndCol.GetM(); i++)
2548 Ptr(IndRow(i) + 1)++;
2551 for (
int i = 2; i <= m; i++)
2558 template<
class T,
class Prop,
class Alloc1,
class Tint0,
2559 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
2566 long nnz = A.GetDataSize();
2570 Val.Reallocate(nnz);
2571 IndRow.Reallocate(m + 1);
2572 IndCol.Reallocate(nnz);
2576 for (
int i = 0; i < m; i++)
2578 for (
int k = 0; k < A.GetRowSize(i); k++)
2580 IndCol(ind) = A.Index(i, k);
2581 Val(ind) = A.Value(i, k);
2584 IndRow(i + 1) = ind;
2590 template<
class T,
class Prop,
class Alloc1,
class Tint0,
2591 class Tint1,
class Alloc2,
class Alloc3,
class Alloc4>
2600 ConvertMatrix_to_Coordinates(A, IndRow, IndCol, Value, 0,
true);
2603 Ptr.Reallocate(m+1);
2606 for (
long i = 0; i < IndCol.GetM(); i++)
2607 Ptr(IndRow(i) + 1)++;
2610 for (
int i = 2; i <= m; i++)
2621 template<
class T1,
class T2,
class Prop1,
class Prop2,
2622 class Alloc1,
class Alloc2>
2630 ConvertToCSR(A, sym, Ptr, Ind, Value);
2635 B.SetData(m, n, Value, Ptr, Ind);
2644 template<
class T1,
class T2,
class Prop1,
class Prop2,
2645 class Alloc1,
class Alloc2>
2653 ConvertToCSR(A, sym, Ptr, Ind, Value);
2658 B.SetData(m, n, Value, Ptr, Ind);
2663 template<
class T0,
class Prop0,
class Allocator0,
2664 class T1,
class Prop1,
class Allocator1>
2673 ConvertToCSR(mat_array, sym, IndRow, IndCol, Val);
2675 int m = mat_array.GetM();
2676 int n = mat_array.GetN();
2677 mat_csr.SetData(m, n, Val, IndRow, IndCol);
2682 template<
class T0,
class Prop0,
class Allocator0,
2683 class T1,
class Prop1,
class Allocator1>
2692 ConvertToCSR(mat_array, sym, IndRow, IndCol, Val);
2694 int m = mat_array.GetM();
2695 int n = mat_array.GetN();
2696 mat_csr.SetData(m, n, Val, IndRow, IndCol);
2701 template<
class T,
class Prop,
class Alloc1,
class Alloc2>
2709 ConvertToCSR(A, sym, Ptr, Ind, Value);
2714 B.SetData(m, n, Value, Ptr, Ind);
2719 template<
class T,
class Prop1,
class Prop2,
class Alloc1,
class Alloc2>
2727 ConvertToCSR(A, unsym, Ptr, Ind, Value);
2732 B.SetData(m, n, Value, Ptr, Ind);
2737 template<
class T,
class Prop,
class Alloc1,
class Alloc2>
2745 ConvertToCSR(A, sym, Ptr, Ind, Value);
2750 B.SetData(m, n, Value, Ptr, Ind);
2755 template<
class T,
class Prop1,
class Prop2,
class Alloc1,
class Alloc2>
2763 ConvertToCSR(A, unsym, Ptr, Ind, Value);
2768 B.SetData(m, n, Value, Ptr, Ind);
2773 template<
class T0,
class Prop0,
class Allocator0,
2774 class T1,
class Prop1,
class Allocator1>
2783 ConvertToCSR(mat_array, unsym, IndRow, IndCol, Val);
2785 int m = mat_array.GetM();
2786 mat_csr.SetData(m, m, Val, IndRow, IndCol);
2791 template<
class T0,
class Prop0,
class Allocator0,
2792 class T1,
class Prop1,
class Allocator1>
2801 ConvertToCSR(mat_array, sym, IndRow, IndCol, Val);
2803 int m = mat_array.GetM();
2804 mat_csr.SetData(m, m, Val, IndRow, IndCol);
2809 template<
class T0,
class Prop0,
class Allocator0,
2810 class T1,
class Prop1,
class Allocator1>
2819 ConvertToCSR(mat_array, unsym, IndRow, IndCol, Val);
2821 int m = mat_array.GetM();
2822 mat_csr.SetData(m, m, Val, IndRow, IndCol);
2831 template<
class T0,
class Prop0,
class Allocator0,
2832 class T1,
class Prop1,
class Allocator1>
2833 void CopyMatrix(
const Matrix<T0, Prop0, RowSymSparse, Allocator0>& A,
2834 Matrix<T1, Prop1, ArrayRowSymSparse, Allocator1>& B)
2843 long* ptr_ = A.GetPtr();
2844 int* ind_ = A.GetInd();
2845 T0* data_ = A.GetData();
2848 for (
int i = 0; i < n; i++)
2850 int size_row = ptr_[i+1] - ptr_[i];
2851 B.ReallocateRow(i, size_row);
2852 for (
int j = 0; j < size_row; j++)
2854 B.Index(i, j) = ind_[ptr_[i] + j];
2855 B.Value(i, j) = data_[ptr_[i] + j];
2862 template<
class T0,
class Prop0,
class Allocator0,
2863 class T1,
class Prop1,
class Allocator1>
2864 void CopyMatrix(
const Matrix<T0, Prop0, ColSymSparse, Allocator0>& A,
2865 Matrix<T1, Prop1, ArrayRowSymSparse, Allocator1>& B)
2874 Vector<long> Ptr; Vector<int> Ind;
2875 Vector<T0, VectFull, Allocator0> Value;
2878 ConvertToCSR(A, sym, Ptr, Ind, Value);
2881 for (
int i = 0; i < n; i++)
2883 int size_row = Ptr(i+1) - Ptr(i);
2884 B.ReallocateRow(i, size_row);
2885 for (
int j = 0; j < size_row; j++)
2887 B.Index(i, j) = Ind(Ptr(i) + j);
2888 B.Value(i, j) = Value(Ptr(i) + j);
2894 template<
class T0,
class Prop0,
class Allocator0,
2895 class T1,
class Prop1,
class Allocator1>
2896 void CopyMatrix(
const Matrix<T0, Prop0, RowSymSparse, Allocator0>& A,
2897 Matrix<T1, Prop1, ArrayColSymSparse, Allocator1>& B)
2906 Vector<long> Ptr; Vector<int> Ind;
2907 Vector<T0, VectFull, Allocator0> Value;
2910 ConvertToCSC(A, sym, Ptr, Ind, Value);
2913 for (
int i = 0; i < n; i++)
2915 int size_col = Ptr(i+1) - Ptr(i);
2916 B.ReallocateColumn(i, size_col);
2917 for (
int j = 0; j < size_col; j++)
2919 B.Index(i, j) = Ind(Ptr(i) + j);
2920 B.Value(i, j) = Value(Ptr(i) + j);
2926 template<
class T0,
class Prop0,
class Allocator0,
2927 class T1,
class Prop1,
class Allocator1>
2928 void CopyMatrix(
const Matrix<T0, Prop0, RowSymSparse, Allocator0>& A,
2929 Matrix<T1, Prop1, ArrayRowSparse, Allocator1>& B)
2933 long* ptr = A.GetPtr();
2934 int* ind = A.GetInd();
2935 T0* val = A.GetData();
2939 Vector<int> NumNnzRow(m);
2941 for (i = 0; i < m; i++)
2942 for (j = ptr[i]; j < ptr[i + 1]; j++)
2944 NumNnzRow(ind[j])++;
2948 for (i = 0; i < m; i++)
2949 B.ReallocateRow(i, ptr[i+1] - ptr[i] + NumNnzRow(i));
2954 for (i = 0; i < m; i++)
2955 for (j = ptr[i]; j < ptr[i + 1]; j++)
2958 int num = NumNnzRow(i) + j - ptr[i];
2959 B.Index(i, num) = ind[j];
2960 B.Value(i, num) = val[j];
2966 B.Index(ind[j], num) = i;
2967 B.Value(ind[j], num) = val[j];
2974 template<
class T0,
class Prop0,
class Allocator0,
2975 class T1,
class Prop1,
class Allocator1>
2976 void CopyMatrix(
const Matrix<T0, Prop0, RowSparse, Allocator0>& A,
2977 Matrix<T1, Prop1, ArrayRowSparse, Allocator1>& B)
2987 long* ptr_ = A.GetPtr();
2988 int* ind_ = A.GetInd();
2989 T0* data_ = A.GetData();
2992 for (
int i = 0; i < m; i++)
2994 int size_row = ptr_[i+1] - ptr_[i];
2995 B.ReallocateRow(i, size_row);
2996 for (
int j = 0; j < size_row; j++)
2998 B.Index(i, j) = ind_[ptr_[i] + j];
2999 B.Value(i, j) = data_[ptr_[i] + j];
3006 template<
class T0,
class Prop0,
class Allocator0,
3007 class T1,
class Prop1,
class Allocator1>
3008 void CopyMatrix(
const Matrix<T0, Prop0, ColSparse, Allocator0>& A,
3009 Matrix<T1, Prop1, ArrayColSparse, Allocator1>& B)
3019 long* ptr_ = A.GetPtr();
3020 int* ind_ = A.GetInd();
3021 T0* data_ = A.GetData();
3024 for (
int i = 0; i < n; i++)
3026 int size_col = ptr_[i+1] - ptr_[i];
3027 B.ReallocateColumn(i, size_col);
3028 for (
int j = 0; j < size_col; j++)
3030 B.Index(i, j) = ind_[ptr_[i] + j];
3031 B.Value(i, j) = data_[ptr_[i] + j];
3037 template<
class T0,
class Prop0,
class Allocator0,
3038 class T1,
class Prop1,
class Allocator1>
3039 void CopyMatrix(
const Matrix<T0, Prop0, ColSparse, Allocator0>& Acsc,
3040 Matrix<T1, Prop1, ArrayRowSparse, Allocator1>& B)
3042 int m = Acsc.GetM();
3043 int n = Acsc.GetN();
3051 Matrix<T0, Prop0, RowSparse, Allocator0> A;
3052 CopyMatrix(Acsc, A);
3054 long* ptr_ = A.GetPtr();
3055 int* ind_ = A.GetInd();
3056 T0* data_ = A.GetData();
3059 for (
int i = 0; i < m; i++)
3061 int size_row = ptr_[i+1] - ptr_[i];
3062 B.ReallocateRow(i, size_row);
3063 for (
int j = 0; j < size_row; j++)
3065 B.Index(i, j) = ind_[ptr_[i] + j];
3066 B.Value(i, j) = data_[ptr_[i] + j];
3078 template<
class T0,
class Prop0,
class Allocator0,
3079 class T1,
class Prop1,
class Allocator1>
3086 for (
int i = 0; i < m; i++)
3088 int size_row = A.GetRowSize(i);
3089 B.ReallocateRow(i, size_row);
3090 for (
int j = 0; j < size_row; j++)
3092 B.Index(i, j) = A.Index(i, j);
3093 B.Value(i, j) = A.Value(i, j);
3100 template<
class T0,
class Prop0,
class Allocator0,
3101 class T1,
class Prop1,
class Allocator1>
3108 for (
int i = 0; i < m; i++)
3110 int size_row = A.GetRowSize(i);
3111 B.ReallocateRow(i, size_row);
3112 for (
int j = 0; j < size_row; j++)
3114 B.Index(i, j) = A.Index(i, j);
3115 B.Value(i, j) = A.Value(i, j);
3122 template<
class T0,
class Prop0,
class Allocator0,
3123 class T1,
class Prop1,
class Allocator1>
3127 B.Reallocate(A.GetM(), A.GetN());
3128 for (
int i = 0; i < A.GetM(); i++)
3131 while ( (k < A.GetRowSize(i)) && (A.Index(i, k) < i))
3134 if (k < A.GetRowSize(i))
3136 int size_row = A.GetRowSize(i) - k;
3137 B.ReallocateRow(i, size_row);
3138 for (
int j = k; j < A.GetRowSize(i); j++)
3140 B.Index(i, j-k) = A.Index(i, j);
3141 B.Value(i, j-k) = A.Value(i, j);
3149 template<
class T0,
class Prop0,
class Allocator0,
3150 class T1,
class Prop1,
class Allocator1>
3165 ConvertToCSR(A, sym, Ptr, Ind, Value);
3168 for (
int i = 0; i < n; i++)
3170 int size_row = Ptr(i+1) - Ptr(i);
3171 B.ReallocateRow(i, size_row);
3172 for (
int j = 0; j < size_row; j++)
3174 B.Index(i, j) = Ind(Ptr(i) + j);
3175 B.Value(i, j) = Value(Ptr(i) + j);
3181 template<
class T0,
class Prop0,
class Allocator0,
3182 class T1,
class Prop1,
class Allocator1>
3183 void CopyMatrix(
const Matrix<T0, Prop0, ArrayColSparse, Allocator0>& Acsc,
3184 Matrix<T1, Prop1, ArrayRowSparse, Allocator1>& B)
3186 int m = Acsc.GetM();
3187 int n = Acsc.GetN();
3195 Matrix<T0, Prop0, RowSparse, Allocator0> A;
3196 CopyMatrix(Acsc, A);
3198 long* ptr_ = A.GetPtr();
3199 int* ind_ = A.GetInd();
3200 T0* data_ = A.GetData();
3203 for (
int i = 0; i < m; i++)
3205 int size_row = ptr_[i+1] - ptr_[i];
3206 B.ReallocateRow(i, size_row);
3207 for (
int j = 0; j < size_row; j++)
3209 B.Index(i, j) = ind_[ptr_[i] + j];
3210 B.Value(i, j) = data_[ptr_[i] + j];
3216 template<
class T0,
class Prop0,
class Allocator0,
3217 class T1,
class Prop1,
class Allocator1>
3218 void CopyMatrix(
const Matrix<T0, Prop0, ArrayRowSymSparse, Allocator0>& A,
3219 Matrix<T1, Prop1, ArrayRowSparse, Allocator1>& B)
3226 Vector<int> NumNnzRow(m);
3228 for (i = 0; i < m; i++)
3229 for (j = 0; j < A.GetRowSize(i); j++)
3230 if (A.Index(i, j) != i)
3231 NumNnzRow(A.Index(i, j))++;
3235 for (i = 0; i < m; i++)
3236 B.ReallocateRow(i, A.GetRowSize(i) + NumNnzRow(i));
3241 for (i = 0; i < m; i++)
3242 for (j = 0; j < A.GetRowSize(i); j++)
3245 int num = NumNnzRow(i) + j;
3246 int jcol = A.Index(i, j);
3247 B.Index(i, num) = jcol;
3248 B.Value(i, num) = A.Value(i, j);
3254 B.Index(jcol, num) = i;
3255 B.Value(jcol, num) = A.Value(i, j);
3262 template<
class T0,
class Prop0,
class Allocator0,
3263 class T1,
class Prop1,
class Allocator1>
3264 void CopyMatrix(
const Matrix<T0, Prop0, ArrayRowSymSparse, Allocator0>& A,
3265 Matrix<T1, Prop1, ArrayColSparse, Allocator1>& B)
3272 Vector<int> NumNnzRow(m);
3274 for (i = 0; i < m; i++)
3275 for (j = 0; j < A.GetRowSize(i); j++)
3276 if (A.Index(i, j) != i)
3277 NumNnzRow(A.Index(i, j))++;
3281 for (i = 0; i < m; i++)
3282 B.ReallocateColumn(i, A.GetRowSize(i) + NumNnzRow(i));
3287 for (i = 0; i < m; i++)
3288 for (j = 0; j < A.GetRowSize(i); j++)
3291 int num = NumNnzRow(i) + j;
3292 int jcol = A.Index(i, j);
3293 B.Index(i, num) = jcol;
3294 B.Value(i, num) = A.Value(i, j);
3300 B.Index(jcol, num) = i;
3301 B.Value(jcol, num) = A.Value(i, j);
3309 template<
class T0,
class Prop0,
class Allocator0,
3310 class T1,
class Prop1,
class Allocator1>
3320 for (
int i = 0; i < A.GetM(); i++)
3321 for (
int j = 0; j < A.GetRowSize(i); j++)
3322 NumNnzCol(A.Index(i, j))++;
3325 B.Reallocate(A.GetM(), n);
3326 for (
int i = 0; i < n; i++)
3327 B.ReallocateColumn(i, NumNnzCol(i));
3332 for (
int i = 0; i < A.GetM(); i++)
3333 for (
int j = 0; j < A.GetRowSize(i); j++)
3335 int jcol = A.Index(i, j);
3336 int num = NumNnzCol(jcol);
3337 B.Index(jcol, num) = i;
3338 B.Value(jcol, num) = A.Value(i, j);
3354 template<
class T,
class Prop,
class Storage,
class Allocator,
3355 class Tint0,
class Tint1,
class Allocator2,
class Allocator3>
3366 ConvertMatrix_to_Coordinates(A, IndRow, IndCol, Value);
3378 for (
long i = 0; i < IndRow.GetM(); i++)
3380 NumNnzRow(IndRow(i))++;
3381 NumNnzCol(IndCol(i))++;
3385 PtrRow(0) = 0; PtrCol(0) = 0;
3386 for (
int i = 0; i < n; i++)
3388 PtrRow(i+1) = PtrRow(i) + NumNnzRow(i);
3389 PtrCol(i+1) = PtrCol(i) + NumNnzCol(i);
3394 for (
long i = 0; i < IndRow.GetM(); i++)
3396 int irow = IndRow2(i);
3397 long num = PtrRow(irow) + NumNnzRow(irow);
3399 IndCol(num) = IndCol2(i);
3405 for (
long i = 0; i < IndRow.GetM(); i++)
3407 int icol = IndCol(i);
3408 long num = PtrCol(icol) + NumNnzCol(icol);
3409 IndRow2(num) = IndRow(i);
3410 IndCol2(num) = icol;
3415 NumNnzRow.Clear(); NumNnzCol.Clear();
3416 PtrRow.Clear(); PtrCol.Clear();
3419 for (
long i = 0; i < IndRow.GetM(); i++)
3420 if (IndRow(i) <= IndCol(i))
3423 for (
long i = 0; i < IndRow.GetM(); i++)
3424 if (IndCol2(i) <= IndRow2(i))
3429 Ptr.Reallocate(n+1);
3430 Ind.Reallocate(max_nnz);
3435 for (
int i = 0; i < A.GetM(); i++)
3439 while ( (j_end < IndRow.GetM()) && (IndRow(j_end) == i))
3441 if (IndRow(j_end) <= IndCol(j_end))
3443 Index(size_row) = IndCol(j_end);
3450 while ( (j2_end < IndCol2.GetM()) && (IndCol2(j2_end) == i))
3452 if (IndCol2(j2_end) <= IndRow2(j2_end))
3454 Index(size_row) = IndRow2(j2_end);
3462 Assemble(size_row, Index);
3465 for (
int j = 0; j < size_row; j++)
3466 Ind(Ptr(i) + j) = Index(j);
3468 Ptr(i+1) = Ptr(i) + size_row;
3471 IndRow2.Clear(); IndCol2.Clear();
3472 IndRow.Clear(); IndCol.Clear();
3477 template<
class T,
class Prop,
class Storage,
class Allocator,
class AllocI>
3478 void GetSymmetricPattern(
const Matrix<T, Prop, Storage, Allocator>& A,
3479 Matrix<int, Symmetric, RowSymSparse, AllocI>& B)
3481 Vector<long> Ptr; Vector<int> Ind;
3483 GetSymmetricPattern(A, Ptr, Ind);
3486 Vector<int, VectFull, AllocI> Val(Ptr(n));
3488 B.SetData(n, n, Val, Ptr, Ind);
3498 template<
class T,
class Prop,
class Allocator1,
class Allocator2>
3504 long* ptr = A.GetPtr();
3505 int* ind = A.GetInd();
3506 T* data = A.GetData();
3510 SetComplexZero(zero);
3512 for (
int i = 0; i < m; i++)
3513 for (
long j = ptr[i]; j < ptr[i+1]; j++)
3514 B(i, ind[j]) = data[j];
3520 template<
class T1,
class T2,
class Prop1,
3521 class Prop2,
class Allocator1,
class Allocator2>
3530 SetComplexZero(zero);
3532 for (
int i = 0; i < m; i++)
3533 for (
int j = 0; j < A.GetRowSize(i); j++)
3534 B(i, A.Index(i, j)) = A.Value(i, j);
3540 template<
class T,
class Prop,
class Allocator1,
class Allocator2>
3546 long* ptr = A.GetPtr();
3547 int* ind = A.GetInd();
3548 T* data = A.GetData();
3552 SetComplexZero(zero);
3554 for (
int i = 0; i < m; i++)
3555 for (
long j = ptr[i]; j < ptr[i+1]; j++)
3556 B(i, ind[j]) = data[j];
3562 template<
class T,
class Prop,
class Allocator1,
class Allocator2>
3570 SetComplexZero(zero);
3572 for (
int i = 0; i < m; i++)
3573 for (
int j = 0; j < A.GetRowSize(i); j++)
3574 B(i, A.Index(i, j)) = A.Value(i, j);
3580 template<
class T,
class Prop,
class Allocator1,
class Allocator2>
3588 SetComplexZero(zero);
3590 for (
int i = 0; i < m; i++)
3591 for (
int j = 0; j < A.GetRowSize(i); j++)
3592 B(i, A.Index(i, j)) = A.Value(i, j);
3598 template<
class T,
class Prop,
class Allocator1,
class Allocator2>
3606 SetComplexZero(zero);
3608 for (
int i = 0; i < m; i++)
3609 for (
int j = 0; j < A.GetRowSize(i); j++)
3610 B.Val(i, A.Index(i, j)) = A.Value(i, j);
3616 template<
class T,
class Prop,
class Allocator1,
class Allocator2>
3624 SetComplexZero(zero);
3626 for (
int i = 0; i < m; i++)
3627 for (
int j = 0; j < A.GetRowSize(i); j++)
3628 B.Val(i, A.Index(i, j)) = A.Value(i, j);
3633 template<
class T,
class Prop1,
class Prop2,
class Alloc1,
class Alloc2>
3634 void CopyMatrix(
const Matrix<T, Prop1, PETScMPIDense, Alloc1>& A,
3635 Matrix<T, Prop2, RowMajor, Alloc2>& B)
3638 MatGetLocalSize(A.GetPetscMatrix(), &m, &n);
3642 MatGetArray(A.GetPetscMatrix(), &local_a);
3643 for (
int i = 0; i < m; i++)
3644 for(
int j = 0; j < n; j++)
3645 B(i, j) = local_a[i + j * m];
3646 MatRestoreArray(A.GetPetscMatrix(), &local_a);
3650 template<
class T,
class Prop1,
class Prop2,
class Alloc1,
class Alloc2>
3651 void CopyMatrix(
const Matrix<T, Prop1, RowMajor, Alloc1>& A,
3652 Matrix<T, Prop2, PETScMPIDense, Alloc2>& B)
3655 MatGetArray(B.GetPetscMatrix(), &local_data);
3657 MatGetLocalSize(B.GetPetscMatrix(), &mlocal, &nlocal);
3658 Matrix<T, Prop1, ColMajor, Alloc1> local_D;
3659 local_D.SetData(mlocal, B.GetN(), local_data);
3660 for (
int i = 0; i < A.GetM(); i++)
3661 for (
int j = 0; j < A.GetN(); j++)
3662 local_D(i, j) = A(i, j);
3664 MatRestoreArray(B.GetPetscMatrix(), &local_data);
3681 for (
int i = 0; i < n; i++)
3682 for (
int j = i; j < n; j++)
3683 if (abs(A(i, j)) > threshold)
3688 nnz = 0; IndRow(0) = 0;
3689 for (
int i = 0; i < n; i++)
3691 for (
int j = i; j < n; j++)
3692 if (abs(A(i, j)) > threshold)
3695 Value(nnz) = A(i, j);
3702 B.SetData(n, n, Value, IndRow, IndCol);
3716 for (
int i = 0; i < m; i++)
3719 for (
int j = 0; j < n; j++)
3720 if (abs(A(i, j)) > threshold)
3723 B.ReallocateRow(i, size_row);
3726 for (
int j = 0; j < n; j++)
3727 if (abs(A(i, j)) > threshold)
3729 B.Index(i, size_row) = j;
3730 B.Value(i, size_row) = A(i, j);
3746 for (
int i = 0; i < m; i++)
3747 for (
int j = 0; j < n; j++)
3748 if (abs(A(i, j)) > threshold)
3753 nnz = 0; IndRow(0) = 0;
3754 for (
int i = 0; i < m; i++)
3756 for (
int j = 0; j < n; j++)
3757 if (abs(A(i, j)) > threshold)
3760 Value(nnz) = A(i, j);
3767 B.SetData(m, n, Value, IndRow, IndCol);
3773 #define SELDON_FILE_MATRIX_CONVERSIONS_CXX