21 #ifndef SELDON_FILE_FUNCTIONS_MATRIX_ARRAY_CXX
89 template<
class T0,
class Allocator0,
90 class T1,
class Allocator1>
94 #ifdef SELDON_CHECK_BOUNDS
98 string(
"Index should be in [0, ") +
to_str(m - 1)
99 +
"], but is equal to " +
to_str(i) +
".");
102 int size_row = A.GetRowSize(i);
103 X.Reallocate(size_row);
104 for (
int j = 0; j < size_row; j++)
106 X.Index(j) = A.Index(i, j);
107 X.Value(j) = A.Value(i, j);
119 template <
class T0,
class Allocator0,
class T1,
class Allocator1>
123 #ifdef SELDON_CHECK_BOUNDS
127 string(
"Index should be in [0, ") +
to_str(m - 1)
128 +
"], but is equal to " +
to_str(i) +
".");
131 list<pair<int, T0> > vec;
132 for (
int j = 0; j < M.GetN(); j++)
133 for (
int k = 0; k < M.GetColumnSize(j); k++)
134 if (M.Index(j, k) == i)
135 vec.push_back(make_pair(j, M.Value(j, k)));
137 typename list<pair<int, T0> >::iterator it;
138 X.Reallocate(vec.size());
140 for (it = vec.begin(); it != vec.end(); it++)
142 X.Index(j) = it->first;
143 X.Value(j) = it->second;
156 template <
class T0,
class Allocator0,
class T1,
class Allocator1>
160 #ifdef SELDON_CHECK_BOUNDS
164 string(
"Index should be in [0, ") +
to_str(m - 1)
165 +
"], but is equal to " +
to_str(i) +
".");
168 list<pair<int, T0> > vec;
170 for (
int j = 0; j < i; j++)
171 for (
int k = 0; k < M.GetRowSize(j); k++)
172 if (M.Index(j, k) == i)
173 vec.push_back(make_pair(j, M.Value(j, k)));
176 for (
int k = 0; k < M.GetRowSize(i); k++)
177 vec.push_back(make_pair(M.Index(i, k), M.Value(i, k)));
179 typename list<pair<int, T0> >::iterator it;
180 X.Reallocate(vec.size());
182 for (it = vec.begin(); it != vec.end(); it++)
184 X.Index(j) = it->first;
185 X.Value(j) = it->second;
198 template <
class T0,
class Allocator0,
class T1,
class Allocator1>
202 #ifdef SELDON_CHECK_BOUNDS
206 string(
"Index should be in [0, ") +
to_str(m - 1)
207 +
"], but is equal to " +
to_str(i) +
".");
210 list<pair<int, T0> > vec;
212 for (
int k = 0; k < M.GetColumnSize(i); k++)
213 vec.push_back(make_pair(M.Index(i, k), M.Value(i, k)));
216 for (
int j = i+1; j < M.GetN(); j++)
217 for (
int k = 0; k < M.GetColumnSize(j); k++)
218 if (M.Index(j, k) == i)
219 vec.push_back(make_pair(j, M.Value(j, k)));
221 typename list<pair<int, T0> >::iterator it;
222 X.Reallocate(vec.size());
224 for (it = vec.begin(); it != vec.end(); it++)
226 X.Index(j) = it->first;
227 X.Value(j) = it->second;
240 template <
class T0,
class Allocator0,
241 class T1,
class Allocator1>
246 M.ReallocateRow(i, X.GetM());
247 for (
int k = 0; k < X.GetM(); k++)
249 M.Index(i, k) = X.Index(k);
250 M.Value(i, k) = X.Value(k);
262 template <
class T0,
class Allocator0,
263 class T1,
class Allocator1>
269 for (
int j = 0; j < M.GetN(); j++)
271 while ( (p < X.GetM()) && (X.Index(p) < j))
274 bool present_X =
false;
275 if ( (p < X.GetM()) && (X.Index(p) == j))
281 int size_col = M.GetColumnSize(j);
282 bool present_val =
false;
284 while ( (k < size_col) && (M.Index(j, k) < i))
287 if ( (k < size_col) && (M.Index(j, k) == i))
295 M.ResizeColumn(j, size_col-1);
298 int last_col = M.Index(j, size_col-1);
299 val = M.Value(j, size_col-1);
300 M.ResizeColumn(j, size_col-1);
301 for (
int q = k; q < size_col-2; q++)
303 M.Index(j, q) = M.Index(j, q+1);
304 M.Value(j, q) = M.Value(j, q+1);
307 M.Index(j, size_col-2) = last_col;
308 M.Value(j, size_col-2) = val;
320 if (!present_val && present_X)
323 M.ResizeColumn(j, size_col+1);
324 for (
int q = size_col; q > k; q--)
326 M.Index(j, q) = M.Index(j, q-1);
327 M.Value(j, q) = M.Value(j, q-1);
344 template <
class T0,
class Allocator0,
345 class T1,
class Allocator1>
352 for (
int j = 0; j < i; j++)
354 while ( (p < X.GetM()) && (X.Index(p) < j))
357 bool present_X =
false;
358 if ( (p < X.GetM()) && (X.Index(p) == j))
365 int size_row = M.GetRowSize(j);
366 bool present_val =
false;
368 while ( (k < size_row) && (M.Index(j, k) < i))
371 if ( (k < size_row) && (M.Index(j, k) == i))
379 M.ResizeRow(j, size_row-1);
382 int last_col = M.Index(j, size_row-1);
383 val = M.Value(j, size_row-1);
384 M.ResizeRow(j, size_row-1);
385 for (
int q = k; q < size_row-2; q++)
387 M.Index(j, q) = M.Index(j, q+1);
388 M.Value(j, q) = M.Value(j, q+1);
391 M.Index(j, size_row-2) = last_col;
392 M.Value(j, size_row-2) = val;
404 if (!present_val && present_X)
407 M.ResizeRow(j, size_row+1);
408 for (
int q = size_row; q > k; q--)
410 M.Index(j, q) = M.Index(j, q-1);
411 M.Value(j, q) = M.Value(j, q-1);
423 M.ReallocateRow(i, X.GetM() - p);
427 M.Index(i, k) = X.Index(p);
428 M.Value(i, k) = X.Value(p);
443 template <
class T0,
class Allocator0,
444 class T1,
class Allocator1>
452 while ( (p < X.GetM()) && (X.Index(p) <= i))
457 M.ReallocateColumn(i, p);
458 for (
int k = 0; k < p; k++)
460 M.Index(i, k) = X.Index(k);
461 M.Value(i, k) = X.Value(k);
466 for (
int j = i+1; j < M.GetN(); j++)
468 while ( (p < X.GetM()) && (X.Index(p) < j))
471 bool present_X =
false;
472 if ( (p < X.GetM()) && (X.Index(p) == j))
478 int size_col = M.GetColumnSize(j);
479 bool present_val =
false;
481 while ( (k < size_col) && (M.Index(j, k) < i))
484 if ( (k < size_col) && (M.Index(j, k) == i))
492 M.ResizeColumn(j, size_col-1);
495 int last_col = M.Index(j, size_col-1);
496 val = M.Value(j, size_col-1);
497 M.ResizeColumn(j, size_col-1);
498 for (
int q = k; q < size_col-2; q++)
500 M.Index(j, q) = M.Index(j, q+1);
501 M.Value(j, q) = M.Value(j, q+1);
504 M.Index(j, size_col-2) = last_col;
505 M.Value(j, size_col-2) = val;
517 if (!present_val && present_X)
520 M.ResizeColumn(j, size_col+1);
521 for (
int q = size_col; q > k; q--)
523 M.Index(j, q) = M.Index(j, q-1);
524 M.Value(j, q) = M.Value(j, q-1);
550 template <
class T0,
class Allocator0,
class T1,
class Allocator1>
554 #ifdef SELDON_CHECK_BOUNDS
558 string(
"Index should be in [0, ") +
to_str(n - 1)
559 +
"], but is equal to " +
to_str(j) +
".");
564 list<pair<int, T0> > vec;
565 for (
int i = 0; i < m; i++)
566 for (
int k = 0; k < M.GetRowSize(i); k++)
567 if (M.Index(i, k) == j)
568 vec.push_back(make_pair(i, M.Value(i, k)));
570 typename list<pair<int, T0> >::iterator it;
571 X.Reallocate(vec.size());
573 for (it = vec.begin(); it != vec.end(); it++)
575 X.Index(i) = it->first;
576 X.Value(i) = it->second;
589 template<
class T0,
class Allocator0,
590 class T1,
class Allocator1>
594 #ifdef SELDON_CHECK_BOUNDS
598 string(
"Index should be in [0, ") +
to_str(n - 1)
599 +
"], but is equal to " +
to_str(j) +
".");
602 int size_col = A.GetColumnSize(j);
603 X.Reallocate(size_col);
604 for (
int k = 0; k < size_col; k++)
606 X.Index(k) = A.Index(j, k);
607 X.Value(k) = A.Value(j, k);
619 template <
class T0,
class Allocator0,
class T1,
class Allocator1>
635 template <
class T0,
class Allocator0,
class T1,
class Allocator1>
651 template <
class T0,
class Allocator0,
652 class T1,
class Allocator1>
659 for (
int i = 0; i < M.GetM(); i++)
661 while ( (p < X.GetM()) && (X.Index(p) < i))
664 bool present_X =
false;
665 if ( (p < X.GetM()) && (X.Index(p) == i))
671 int size_row = M.GetRowSize(i);
672 bool present_val =
false;
674 while ( (k < size_row) && (M.Index(i, k) < j))
678 if ( (k < size_row) && (M.Index(i, k) == j))
686 M.ResizeRow(j, size_row-1);
689 int last_row = M.Index(i, size_row-1);
690 val = M.Value(i, size_row-1);
691 M.ResizeRow(i, size_row-1);
692 for (
int q = k; q < size_row-2; q++)
694 M.Index(i, q) = M.Index(i, q+1);
695 M.Value(i, q) = M.Value(i, q+1);
698 M.Index(i, size_row-2) = last_row;
699 M.Value(i, size_row-2) = val;
711 if (!present_val && present_X)
714 M.ResizeRow(i, size_row+1);
715 for (
int q = size_row; q > k; q--)
717 M.Index(i, q) = M.Index(i, q-1);
718 M.Value(i, q) = M.Value(i, q-1);
735 template <
class T0,
class Allocator0,
736 class T1,
class Allocator1>
741 M.ReallocateColumn(j, X.GetM());
742 for (
int k = 0; k < X.GetM(); k++)
744 M.Index(j, k) = X.Index(k);
745 M.Value(j, k) = X.Value(k);
757 template <
class T0,
class Allocator0,
758 class T1,
class Allocator1>
774 template <
class T0,
class Allocator0,
775 class T1,
class Allocator1>
794 template<
class T1,
class T2,
class T3,
795 class Allocator1,
class Allocator2,
class Allocator3>
796 void MltVector(
const Matrix<T1, Symmetric,
797 ArrayRowSymSparse, Allocator1>& A,
798 const Vector<T2, VectFull, Allocator2>& B,
799 Vector<T3, VectFull, Allocator3>& C)
802 int m = A.GetM(), n, p;
804 for (
int i = 0 ; i < m ; i++)
807 for (
int k = 0; k < n ; k++)
824 template<
class T1,
class T2,
class T3,
825 class Allocator1,
class Allocator2,
class Allocator3>
826 void MltVector(
const SeldonTranspose& Trans,
const Matrix<T1, Symmetric,
827 ArrayRowSymSparse, Allocator1>& A,
828 const Vector<T2, VectFull, Allocator2>& B,
829 Vector<T3, VectFull, Allocator3>& C)
831 if (!Trans.ConjTrans())
839 int m = A.GetM(), n, p;
841 for (
int i = 0 ; i < m ; i++)
844 for (
int k = 0; k < n ; k++)
847 val = conjugate(A.Value(i, k));
864 template<
class T1,
class T2,
class T3,
865 class Allocator1,
class Allocator2,
class Allocator3>
866 void MltVector(
const Matrix<T1, Symmetric,
867 ArrayColSymSparse, Allocator1>& A,
868 const Vector<T2, VectFull, Allocator2>& B,
869 Vector<T3, VectFull, Allocator3>& C)
872 int m = A.GetM(), n, p;
874 for (
int i = 0 ; i < m ; i++)
876 n = A.GetColumnSize(i);
877 for (
int k = 0; k < n ; k++)
894 template<
class T1,
class T2,
class T3,
895 class Allocator1,
class Allocator2,
class Allocator3>
896 void MltVector(
const SeldonTranspose& Trans,
const Matrix<T1, Symmetric,
897 ArrayColSymSparse, Allocator1>& A,
898 const Vector<T2, VectFull, Allocator2>& B,
899 Vector<T3, VectFull, Allocator3>& C)
901 if (!Trans.ConjTrans())
909 int m = A.GetM(), n, p;
911 for (
int i = 0 ; i < m ; i++)
913 n = A.GetColumnSize(i);
914 for (
int k = 0; k < n ; k++)
917 val = conjugate(A.Value(i, k));
934 template<
class T1,
class T2,
class T3,
935 class Allocator1,
class Allocator2,
class Allocator3>
936 void MltVector(
const Matrix<T1, General, ArrayRowSparse, Allocator1>& A,
937 const Vector<T2, VectFull, Allocator2>& B,
938 Vector<T3, VectFull, Allocator3>& C)
940 T3 zero, temp; SetComplexZero(zero);
942 for (
int i = 0 ; i < m ; i++)
946 for (
int k = 0; k < n ; k++)
947 temp += A.Value(i, k)*B(A.Index(i, k));
954 template<
class T1,
class T2,
class T3,
955 class Allocator1,
class Allocator2,
class Allocator3>
956 void MltVector(
const SeldonTranspose& Trans,
957 const Matrix<T1, General, ArrayRowSparse, Allocator1>& A,
958 const Vector<T2, VectFull, Allocator2>& B,
959 Vector<T3, VectFull, Allocator3>& C)
972 for (
int i = 0 ; i < m ; i++)
975 for (
int k = 0; k < n ; k++)
976 C(A.Index(i, k)) += A.Value(i, k)*B(i);
981 for (
int i = 0 ; i < m ; i++)
984 for (
int k = 0; k < n ; k++)
985 C(A.Index(i, k)) += conjugate(A.Value(i, k))*B(i);
994 template<
class T1,
class T2,
class T3,
995 class Allocator1,
class Allocator2,
class Allocator3>
996 void MltVector(
const Matrix<T1, General, ArrayColSparse, Allocator1>& A,
997 const Vector<T2, VectFull, Allocator2>& B,
998 Vector<T3, VectFull, Allocator3>& C)
1001 for (
int i = 0 ; i < A.GetN(); i++)
1002 for (
int k = 0; k < A.GetColumnSize(i); k++)
1003 C(A.Index(i, k)) += A.Value(i, k) * B(i);
1007 template<
class T1,
class T2,
class T3,
1008 class Allocator1,
class Allocator2,
class Allocator3>
1009 void MltVector(
const SeldonTranspose& Trans,
1010 const Matrix<T1, General, ArrayColSparse, Allocator1>& A,
1011 const Vector<T2, VectFull, Allocator2>& B,
1012 Vector<T3, VectFull, Allocator3>& C)
1014 if (Trans.NoTrans())
1021 SetComplexZero(zero);
1025 for (
int i = 0 ; i < A.GetN(); i++)
1028 for (
int k = 0; k < A.GetColumnSize(i); k++)
1029 temp += A.Value(i, k) * B(A.Index(i, k));
1036 for (
int i = 0 ; i < A.GetN(); i++)
1039 for (
int k = 0; k < A.GetColumnSize(i); k++)
1040 temp += conjugate(A.Value(i, k)) * B(A.Index(i, k));
1059 template<
class T0,
class T1,
class T2,
class T3,
class T4,
1060 class Allocator1,
class Allocator2,
class Allocator3>
1061 void MltAddVector(
const T0& alpha,
const Matrix<T1, Symmetric,
1062 ArrayRowSymSparse, Allocator1>& A,
1063 const Vector<T2, VectFull, Allocator2>& B,
1065 Vector<T3, VectFull, Allocator3>& C)
1068 SetComplexZero(zero);
1076 int m = A.GetM(), n, p;
1080 for (
int i = 0 ; i < m ; i++)
1082 n = A.GetRowSize(i);
1083 for (
int k = 0; k < n ; k++)
1086 val = A.Value(i, k);
1101 for (
int i = 0 ; i < m ; i++)
1103 n = A.GetRowSize(i);
1104 for (
int k = 0; k < n ; k++)
1107 val = A.Value(i, k);
1110 C(i) += alpha * val * B(i);
1113 C(i) += alpha * val * B(p);
1114 C(p) += alpha * val * B(i);
1122 template<
class T0,
class T1,
class T2,
class T3,
class T4,
1123 class Allocator1,
class Allocator2,
class Allocator3>
1124 void MltAddVector(
const T0& alpha,
1125 const SeldonTranspose& Trans,
const Matrix<T1, Symmetric,
1126 ArrayRowSymSparse, Allocator1>& A,
1127 const Vector<T2, VectFull, Allocator2>& B,
1129 Vector<T3, VectFull, Allocator3>& C)
1131 if (!Trans.ConjTrans())
1133 MltAddVector(alpha, A, B, beta, C);
1138 SetComplexZero(zero);
1146 int m = A.GetM(), n, p;
1150 for (
int i = 0 ; i < m ; i++)
1152 n = A.GetRowSize(i);
1153 for (
int k = 0; k < n ; k++)
1156 val = conjugate(A.Value(i, k));
1171 for (
int i = 0 ; i < m ; i++)
1173 n = A.GetRowSize(i);
1174 for (
int k = 0; k < n ; k++)
1177 val = conjugate(A.Value(i, k));
1180 C(i) += alpha * val * B(i);
1183 C(i) += alpha * val * B(p);
1184 C(p) += alpha * val * B(i);
1195 template<
class T0,
class T1,
class T2,
class T3,
class T4,
1196 class Allocator1,
class Allocator2,
class Allocator3>
1197 void MltAddVector(
const T0& alpha,
const Matrix<T1, Symmetric,
1198 ArrayColSymSparse, Allocator1>& A,
1199 const Vector<T2, VectFull, Allocator2>& B,
1201 Vector<T3, VectFull, Allocator3>& C)
1204 SetComplexZero(zero);
1212 int m = A.GetM(), n, p;
1216 for (
int i = 0 ; i < m ; i++)
1218 n = A.GetColumnSize(i);
1219 for (
int k = 0; k < n ; k++)
1222 val = A.Value(i, k);
1237 for (
int i = 0 ; i < m ; i++)
1239 n = A.GetColumnSize(i);
1240 for (
int k = 0; k < n ; k++)
1243 val = A.Value(i, k);
1246 C(i) += alpha * val * B(i);
1249 C(i) += alpha * val * B(p);
1250 C(p) += alpha * val * B(i);
1258 template<
class T0,
class T1,
class T2,
class T3,
class T4,
1259 class Allocator1,
class Allocator2,
class Allocator3>
1260 void MltAddVector(
const T0& alpha,
1261 const SeldonTranspose& Trans,
const Matrix<T1, Symmetric,
1262 ArrayColSymSparse, Allocator1>& A,
1263 const Vector<T2, VectFull, Allocator2>& B,
1265 Vector<T3, VectFull, Allocator3>& C)
1267 if (!Trans.ConjTrans())
1269 MltAddVector(alpha, A, B, beta, C);
1274 SetComplexZero(zero);
1282 int m = A.GetM(), n, p;
1286 for (
int i = 0 ; i < m ; i++)
1288 n = A.GetColumnSize(i);
1289 for (
int k = 0; k < n ; k++)
1292 val = conjugate(A.Value(i, k));
1307 for (
int i = 0 ; i < m ; i++)
1309 n = A.GetColumnSize(i);
1310 for (
int k = 0; k < n ; k++)
1313 val = alpha * conjugate(A.Value(i, k));
1331 template<
class T0,
class T1,
class T2,
class T3,
class T4,
1332 class Allocator1,
class Allocator2,
class Allocator3>
1333 void MltAddVector(
const T0& alpha,
1334 const Matrix<T1, General, ArrayRowSparse, Allocator1>& A,
1335 const Vector<T2, VectFull, Allocator2>& B,
1337 Vector<T3, VectFull, Allocator3>& C)
1339 T4 zero; SetComplexZero(zero);
1340 T0 one; SetComplexOne(one);
1347 int m = A.GetM(), n, p;
1351 for (
int i = 0 ; i < m ; i++)
1353 n = A.GetRowSize(i);
1354 for (
int k = 0; k < n ; k++)
1357 val = A.Value(i, k);
1364 for (
int i = 0 ; i < m ; i++)
1366 n = A.GetRowSize(i);
1367 for (
int k = 0; k < n ; k++)
1370 val = A.Value(i, k);
1371 C(i) += alpha * val * B(p);
1378 template<
class T0,
class T1,
class T2,
class T3,
class T4,
1379 class Allocator1,
class Allocator2,
class Allocator3>
1380 void MltAddVector(
const T0& alpha,
1381 const SeldonTranspose& Trans,
1382 const Matrix<T1, General, ArrayRowSparse, Allocator1>& A,
1383 const Vector<T2, VectFull, Allocator2>& B,
1385 Vector<T3, VectFull, Allocator3>& C)
1387 if (Trans.NoTrans())
1389 MltAddVector(alpha, A, B, beta, C);
1393 T4 zero; SetComplexZero(zero);
1394 T0 one; SetComplexOne(one);
1401 int m = A.GetM(), n, p;
1408 for (
int i = 0 ; i < m ; i++)
1410 n = A.GetRowSize(i);
1411 for (
int k = 0; k < n ; k++)
1414 val = A.Value(i, k);
1421 for (
int i = 0 ; i < m ; i++)
1423 n = A.GetRowSize(i);
1424 for (
int k = 0; k < n ; k++)
1427 val = A.Value(i, k);
1428 C(p) += alpha * val * B(i);
1437 for (
int i = 0 ; i < m ; i++)
1439 n = A.GetRowSize(i);
1440 for (
int k = 0; k < n ; k++)
1443 val = conjugate(A.Value(i, k));
1450 for (
int i = 0 ; i < m ; i++)
1452 n = A.GetRowSize(i);
1453 for (
int k = 0; k < n ; k++)
1456 val = conjugate(A.Value(i, k));
1457 C(p) += alpha * val * B(i);
1468 template<
class T0,
class T1,
class T2,
class T3,
class T4,
1469 class Allocator1,
class Allocator2,
class Allocator3>
1470 void MltAddVector(
const T0& alpha,
1471 const Matrix<T1, General, ArrayColSparse, Allocator1>& A,
1472 const Vector<T2, VectFull, Allocator2>& B,
1474 Vector<T3, VectFull, Allocator3>& C)
1477 SetComplexZero(zero);
1487 for (
int i = 0 ; i < A.GetN(); i++)
1488 for (
int k = 0; k < A.GetColumnSize(i); k++)
1489 C(A.Index(i, k)) += A.Value(i, k) * B(i);
1493 for (
int i = 0 ; i < A.GetN(); i++)
1494 for (
int k = 0; k < A.GetColumnSize(i); k++)
1495 C(A.Index(i, k)) += alpha * A.Value(i, k) * B(i);
1500 template<
class T0,
class T1,
class T2,
class T3,
class T4,
1501 class Allocator1,
class Allocator2,
class Allocator3>
1502 void MltAddVector(
const T0& alpha,
1503 const SeldonTranspose& Trans,
1504 const Matrix<T1, General, ArrayColSparse, Allocator1>& A,
1505 const Vector<T2, VectFull, Allocator2>& B,
1507 Vector<T3, VectFull, Allocator3>& C)
1509 if (Trans.NoTrans())
1511 MltAddVector(alpha, A, B, beta, C);
1516 SetComplexZero(zero);
1528 for (
int i = 0 ; i < A.GetN(); i++)
1529 for (
int k = 0; k < A.GetColumnSize(i); k++)
1530 C(i) += A.Value(i, k) * B(A.Index(i, k));
1534 for (
int i = 0 ; i < A.GetN(); i++)
1535 for (
int k = 0; k < A.GetColumnSize(i); k++)
1536 C(i) += alpha * A.Value(i, k) * B(A.Index(i, k));
1543 for (
int i = 0 ; i < A.GetN(); i++)
1544 for (
int k = 0; k < A.GetColumnSize(i); k++)
1545 C(i) += conjugate(A.Value(i, k)) * B(A.Index(i, k));
1549 for (
int i = 0 ; i < A.GetN(); i++)
1550 for (
int k = 0; k < A.GetColumnSize(i); k++)
1551 C(i) += alpha * conjugate(A.Value(i, k)) * B(A.Index(i, k));
1566 template<
class T0,
class T1,
class T2,
class Allocator1,
class Allocator2>
1568 const Matrix<T1, General, ArrayRowSparse, Allocator1>& A,
1569 Matrix<T2, General, ArrayRowSparse, Allocator2>& B)
1571 int m = B.GetM(), n;
1572 Vector<T2, VectFull, Allocator2> value(B.GetN());
1573 for (
int i = 0 ; i < m ; i++)
1575 n = A.GetRowSize(i);
1576 for (
int j = 0; j < n; j++)
1577 value(j) = alpha*A.Value(i, j);
1579 B.AddInteractionRow(i, n, A.GetIndex(i), value.GetData());
1584 template<
class T0,
class T1,
class T2,
class Allocator1,
class Allocator2>
1586 const Matrix<T1, General, ArrayColSparse, Allocator1>& A,
1587 Matrix<T2, General, ArrayColSparse, Allocator2>& B)
1589 int m = B.GetN(), n;
1590 Vector<T2, VectFull, Allocator2> value;
1591 for (
int i = 0 ; i < m ; i++)
1593 n = A.GetColumnSize(i);
1594 value.Reallocate(n);
1595 for (
int j = 0; j < n; j++)
1596 value(j) = A.Value(i, j);
1599 B.AddInteractionColumn(i, n, A.GetIndex(i), value.GetData());
1604 template<
class T0,
class T1,
class T2,
class Allocator1,
class Allocator2>
1606 const Matrix<T1, Symmetric, ArrayRowSymSparse, Allocator1>& A,
1607 Matrix<T2, Symmetric, ArrayRowSymSparse, Allocator2>& B)
1610 Vector<T2, VectFull, Allocator2> value(B.GetN());
1611 for (
int i = 0 ; i < m ; i++)
1613 n = A.GetRowSize(i);
1614 for (
int j = 0; j < n; j++)
1615 value(j) = alpha*A.Value(i, j);
1617 B.AddInteractionRow(i, n, A.GetIndex(i), value.GetData());
1622 template<
class T0,
class T1,
class T2,
class Allocator1,
class Allocator2>
1624 const Matrix<T1, Symmetric, ArrayColSymSparse, Allocator1>& A,
1625 Matrix<T2, Symmetric, ArrayColSymSparse, Allocator2>& B)
1627 int m = B.GetN(), n;
1628 Vector<T2, VectFull, Allocator2> value;
1629 for (
int i = 0 ; i < m ; i++)
1631 n = A.GetColumnSize(i);
1632 value.Reallocate(n);
1633 for (
int j = 0; j < n; j++)
1634 value(j) = A.Value(i, j);
1637 B.AddInteractionColumn(i, n, A.GetIndex(i), value.GetData());
1643 template<
class T0,
class T1,
class T2,
class T3,
class Allocator1,
1644 class Allocator2,
class Allocator3>
1646 const Matrix<T1, General, ArrayRowSparse, Allocator1>& A,
1647 const Matrix<T2, General, ArrayRowSparse, Allocator2>& B,
1648 Matrix<complex<T3>, General, ArrayRowSparse, Allocator3>& C)
1650 int m = B.GetM(),n1,n2,size_row;;
1651 Vector<complex<T3>, VectFull, Allocator3> val_row;
1653 for (
int i = 0 ; i < m ; i++)
1655 n1 = A.GetRowSize(i);
1656 n2 = B.GetRowSize(i);
1658 val_row.Reallocate(size_row);
1659 ind_row.Reallocate(size_row);
1660 for (
int j = 0 ; j < n1 ; j++)
1662 ind_row(j) = A.Index(i, j);
1663 val_row(j) = alpha*complex<T3>(A.Value(i, j), 0);
1666 for (
int j = 0 ; j < n2 ; j++)
1668 ind_row(j+n1) = B.Index(i, j);
1669 val_row(j+n1) = alpha * complex<T3>(0, B.Value(i, j));
1672 C.AddInteractionRow(i, size_row, ind_row, val_row);
1678 template<
class T0,
class T1,
class T2,
class T3,
1679 class Allocator1,
class Allocator2,
class Allocator3>
1681 const Matrix<T1, Symmetric, ArrayRowSymSparse, Allocator1>& A,
1682 const Matrix<T2, Symmetric, ArrayRowSymSparse, Allocator2>& B,
1683 Matrix<complex<T3>, Symmetric, ArrayRowSymSparse, Allocator3>& C)
1685 int m = B.GetM(), n1, n2, size_row;
1686 Vector<complex<T3>, VectFull, Allocator3> val_row;
1688 for (
int i = 0 ; i < m ; i++)
1690 n1 = A.GetRowSize(i);
1691 n2 = B.GetRowSize(i);
1693 val_row.Reallocate(size_row);
1694 ind_row.Reallocate(size_row);
1695 for (
int j = 0 ; j < n1 ; j++)
1697 ind_row(j) = A.Index(i, j);
1698 val_row(j) = alpha * complex<T3>(A.Value(i, j), 0);
1701 for (
int j = 0 ; j < n2 ; j++)
1703 ind_row(j+n1) = B.Index(i, j);
1704 val_row(j+n1) = alpha * complex<T3>(0, B.Value(i, j));
1707 C.AddInteractionRow(i, size_row, ind_row, val_row);
1712 template<
class T0,
class T1,
class T2,
class Allocator1,
class Allocator2>
1714 const Matrix<T1, Symmetric, ArrayRowSymSparse, Allocator1>& A,
1715 Matrix<T2, General, ArrayRowSparse, Allocator2>& B)
1717 Vector<T2, VectFull, Allocator2> value;
1718 for (
int i = 0; i < B.GetM(); i++)
1720 int n = A.GetRowSize(i);
1721 value.Reallocate(n);
1722 for (
int j = 0; j < n; j++)
1724 value(j) = A.Value(i, j);
1725 if (A.Index(i, j) != i)
1726 B.AddInteraction(A.Index(i, j), i, alpha*value(j));
1730 B.AddInteractionRow(i, n, A.GetIndex(i), value.GetData());
1744 template<
class T0,
class T,
class Allocator>
1745 void MltScalar(
const T0& alpha, Matrix<T, General, ArrayRowSparse, Allocator>& A)
1747 for (
int i = 0; i < A.GetM(); i++)
1748 for (
int j = 0; j < A.GetRowSize(i); j++)
1749 A.Value(i,j) *= alpha;
1753 template<
class T0,
class T,
class Allocator>
1754 void MltScalar(
const T0& alpha, Matrix<T, General, ArrayColSparse, Allocator>& A)
1756 for (
int i = 0; i < A.GetN(); i++)
1757 for (
int j = 0; j < A.GetColumnSize(i); j++)
1758 A.Value(i,j) *= alpha;
1762 template<
class T0,
class T,
class Allocator>
1764 Matrix<T, Symmetric, ArrayRowSymSparse, Allocator>& A)
1766 for (
int i = 0; i < A.GetM(); i++)
1767 for (
int j = 0; j < A.GetRowSize(i); j++)
1768 A.Value(i,j) *= alpha;
1772 template<
class T0,
class T,
class Allocator>
1774 Matrix<T, Symmetric, ArrayColSymSparse, Allocator>& A)
1776 for (
int i = 0; i < A.GetN(); i++)
1777 for (
int j = 0; j < A.GetColumnSize(i); j++)
1778 A.Value(i,j) *= alpha;
1783 template<
class T0,
class T1,
class Prop1,
class Allocator1,
class T4,
1784 class T2,
class Prop2,
class Storage2,
class Allocator2,
1785 class T3,
class Prop3,
class Storage3,
class Allocator3>
1787 const Matrix<T1, Prop1, ArrayRowSparse, Allocator1>& A,
1788 const Matrix<T2, Prop2, Storage2, Allocator2>& B,
1790 Matrix<T3, Prop3, Storage3, Allocator3>& C)
1792 if (Storage2::Sparse || Storage3::Sparse)
1793 throw WrongArgument(
"Mlt",
"Function intended for product "
1794 " between a sparse matrix and a dense matrix");
1796 #ifdef SELDON_CHECK_DIMENSIONS
1797 CheckDim(A, B,
"MltAdd(alpha, A, B, beta, C)");
1800 T4 zero; SetComplexZero(zero);
1809 for (
int i = 0; i < m; i++)
1810 for (
int j = 0; j < n; j++)
1812 SetComplexZero(val);
1813 for (
int ind = 0; ind < A.GetRowSize(i); ind++)
1815 int k = A.Index(i, ind);
1816 val += A.Value(i, ind) * B(k, j);
1819 C(i, j) += alpha*val;
1825 template<
class T0,
class T1,
class Prop1,
class Storage1,
class Allocator1,
1826 class T4,
class T2,
class Prop2,
class Allocator2,
1827 class T3,
class Prop3,
class Storage3,
class Allocator3>
1829 const Matrix<T1, Prop1, Storage1, Allocator1>& A,
1830 const Matrix<T2, Prop2, ArrayRowSparse, Allocator2>& B,
1832 Matrix<T3, Prop3, Storage3, Allocator3>& C)
1834 if (Storage1::Sparse || Storage3::Sparse)
1835 throw WrongArgument(
"Mlt",
"Function intended for product "
1836 " between a sparse matrix and a dense matrix");
1838 #ifdef SELDON_CHECK_DIMENSIONS
1839 CheckDim(A, B,
"MltAdd(alpha, A, B, beta, C)");
1842 T4 zero; SetComplexZero(zero);
1850 for (
int j = 0; j < B.GetM(); j++)
1852 for (
int ind = 0; ind < B.GetRowSize(j); ind++)
1854 int k = B.Index(j, ind);
1855 val = B.Value(j, ind);
1856 for (
int i = 0; i < m; i++)
1857 C(i, k) += alpha*val*A(i, j);
1876 template <
class T,
class Prop,
class Allocator>
1877 typename ClassComplexType<T>::Treal
1880 typename ClassComplexType<T>::Treal res(0);
1881 for (
int i = 0; i < A.
GetM(); i++)
1894 template <
class T,
class Prop,
class Allocator>
1895 typename ClassComplexType<T>::Treal
1898 typedef typename ClassComplexType<T>::Treal Treal;
1901 for (
int i = 0; i < A.
GetM(); i++)
1905 return sum.GetNormInf();
1914 template <
class T,
class Prop,
class Allocator>
1915 typename ClassComplexType<T>::Treal
1918 typedef typename ClassComplexType<T>::Treal Treal;
1920 for (
int i = 0; i < A.
GetM(); i++)
1926 res = max(res, sum);
1938 template <
class T,
class Prop,
class Allocator>
1939 typename ClassComplexType<T>::Treal
1942 typename ClassComplexType<T>::Treal res(0);
1943 for (
int i = 0; i < A.
GetN(); i++)
1956 template <
class T,
class Prop,
class Allocator>
1957 typename ClassComplexType<T>::Treal
1960 typedef typename ClassComplexType<T>::Treal Treal;
1962 for (
int i = 0; i < A.
GetN(); i++)
1968 res = max(res, sum);
1980 template <
class T,
class Prop,
class Allocator>
1981 typename ClassComplexType<T>::Treal
1984 typedef typename ClassComplexType<T>::Treal Treal;
1987 for (
int i = 0; i < A.
GetN(); i++)
1991 return sum.GetNormInf();
2000 template <
class T,
class Prop,
class Allocator>
2001 typename ClassComplexType<T>::Treal
2004 typename ClassComplexType<T>::Treal res(0);
2005 for (
int i = 0; i < A.
GetM(); i++)
2018 template <
class T,
class Prop,
class Allocator>
2019 typename ClassComplexType<T>::Treal
2022 typedef typename ClassComplexType<T>::Treal Treal;
2025 for (
int i = 0; i < A.
GetM(); i++)
2029 if (A.
Index(i, j) != i)
2033 return sum.GetNormInf();
2042 template <
class T,
class Prop,
class Allocator>
2043 typename ClassComplexType<T>::Treal
2055 template <
class T,
class Prop,
class Allocator>
2056 typename ClassComplexType<T>::Treal
2059 typename ClassComplexType<T>::Treal res(0);
2060 for (
int i = 0; i < A.
GetM(); i++)
2073 template <
class T,
class Prop,
class Allocator>
2074 typename ClassComplexType<T>::Treal
2077 typedef typename ClassComplexType<T>::Treal Treal;
2080 for (
int i = 0; i < A.
GetM(); i++)
2084 if (A.
Index(i, j) != i)
2088 return sum.GetNormInf();
2097 template <
class T,
class Prop,
class Allocator>
2098 typename ClassComplexType<T>::Treal
2106 template<
class T,
class Prop,
class Allocator>
2107 typename ClassComplexType<T>::Treal
2110 typename ClassComplexType<T>::Treal res(0);
2111 for (
int i = 0; i < A.
GetM(); i++)
2121 template<
class T,
class Prop,
class Allocator>
2122 typename ClassComplexType<T>::Treal
2125 typename ClassComplexType<T>::Treal res(0);
2126 for (
int i = 0; i < A.
GetM(); i++)
2129 if (i == A.
Index(i, j))
2149 template<
class T,
class Allocator>
2164 for (
int i = 0; i < m; i++)
2165 for (
int j = 0; j < A.GetRowSize(i); j++)
2166 ptr_T(A.Index(i, j))++;
2168 for (
int i = 0; i < n; i++)
2169 B.ReallocateRow(i, ptr_T(i));
2173 for (
int i = 0; i < m; i++)
2174 for (
int jp = 0; jp < A.GetRowSize(i); jp++)
2176 int j = A.Index(i, jp);
2179 B.Value(j, k) = A.Value(i, jp);
2188 template<
class T,
class Allocator>
2197 template<
class T,
class Allocator>
2212 for (
int i = 0; i < n; i++)
2213 for (
int j = 0; j < A.GetColumnSize(i); j++)
2214 ptr_T(A.Index(i, j))++;
2216 for (
int i = 0; i < m; i++)
2217 B.ReallocateColumn(i, ptr_T(i));
2221 for (
int i = 0; i < n; i++)
2222 for (
int jp = 0; jp < A.GetColumnSize(i); jp++)
2224 int j = A.Index(i, jp);
2227 B.Value(j, k) = A.Value(i, jp);
2236 template<
class T,
class Allocator>
2245 template<
class T,
class Allocator>
2248 for (
int i = 0; i < A.GetM(); i++)
2249 for (
int j = 0; j < A.GetRowSize(i); j++)
2250 A.Value(i, j) = conjugate(A.Value(i, j));
2255 template<
class T,
class Allocator>
2258 for (
int i = 0; i < A.GetN(); i++)
2259 for (
int j = 0; j < A.GetColumnSize(i); j++)
2260 A.Value(i, j) = conjugate(A.Value(i, j));
2265 template<
class T,
class Allocator>
2268 for (
int i = 0; i < A.GetM(); i++)
2269 for (
int j = 0; j < A.GetRowSize(i); j++)
2270 A.Value(i, j) = conjugate(A.Value(i, j));
2275 template<
class T,
class Allocator>
2278 for (
int i = 0; i < A.GetN(); i++)
2279 for (
int j = 0; j < A.GetColumnSize(i); j++)
2280 A.Value(i, j) = conjugate(A.Value(i, j));
2292 template<
class T1,
class Prop1,
class Allocator1,
2293 class T2,
class Prop2,
class Allocator2,
2294 class T4,
class Prop4,
class Allocator4>
2295 void MltMatrix(
const Matrix<T1, Prop1, ArrayRowSparse, Allocator1>& A,
2296 const Matrix<T2, Prop2, ArrayRowSparse, Allocator2>& B,
2297 Matrix<T4, Prop4, ArrayRowSparse, Allocator4>& C)
2301 SetComplexZero(zero);
2302 MltAdd(one, A, B, zero, C);
2307 template<
class T0,
class T1,
class Prop1,
class Allocator1,
2308 class T2,
class Prop2,
class Allocator2,
class T3,
2309 class T4,
class Prop4,
class Allocator4>
2311 const Matrix<T1, Prop1, ArrayRowSparse, Allocator1>& A,
2312 const Matrix<T2, Prop2, ArrayRowSparse, Allocator2>& B,
2314 Matrix<T4, Prop4, ArrayRowSparse, Allocator4>& C)
2320 SetComplexZero(zero);
2329 #ifdef SELDON_CHECK_DIMENSIONS
2330 CheckDim(A, B, C,
"MltAdd(alpha, A, B, beta, C)");
2333 Vector<int> Index(n), IndCol(n);
2334 Vector<T4, VectFull, Allocator4> Value(n);
2336 int col, ind; T4 vloc;
2338 for (
int i = 0; i < m; i++)
2341 for (
int j = 0; j < A.GetRowSize(i); j++)
2343 col = A.Index(i, j);
2346 for (
int k = 0; k < B.GetRowSize(col); k++)
2348 ind = B.Index(col, k);
2349 vloc = alpha*A.Value(i, j)*B.Value(col, k);
2350 if (Index(ind) >= 0)
2353 Value(Index(ind)) += vloc;
2366 Sort(nnz, IndCol, Value);
2369 C.AddInteractionRow(i, nnz, IndCol, Value,
true);
2372 for (
int j = 0; j < nnz; j++)
2373 Index(IndCol(j)) = -1;
2379 template<
class T0,
class T1,
class Prop1,
class Allocator1,
2380 class T2,
class Prop2,
class Allocator2,
class T3,
2381 class T4,
class Prop4,
class Allocator4>
2383 const SeldonTranspose& TransA,
2384 const Matrix<T1, Prop1, ArrayRowSparse, Allocator1>& A,
2385 const SeldonTranspose& TransB,
2386 const Matrix<T2, Prop2, ArrayRowSparse, Allocator2>& B,
2388 Matrix<T4, Prop4, ArrayRowSparse, Allocator4>& C)
2392 if (!TransA.NoTrans())
2395 if (!TransB.NoTrans())
2399 SetComplexZero(zero);
2408 if ((!TransA.NoTrans()) || (!TransB.NoTrans()))
2412 #ifdef SELDON_CHECK_DIMENSIONS
2413 CheckDim(TransA, A, TransB, B, C,
"MltAdd(alpha, A, B, beta, C)");
2416 int col, ind; T4 vloc;
2418 if (TransA.NoTrans())
2420 if (TransB.NoTrans())
2421 MltAdd(alpha, A, B, beta, C);
2422 else if (TransB.Trans())
2424 Vector<int> Index(n), IndCol(n);
2425 Vector<T4, VectFull, Allocator4> Value(n);
2429 for (
int i = 0; i < A.GetM(); i++)
2432 for (
int j = 0; j < A.GetRowSize(i); j++)
2434 col = A.Index(i, j);
2437 for (
int ib = 0; ib < B.GetM(); ib++)
2438 for (
int k = 0; k < B.GetRowSize(ib); k++)
2439 if (B.Index(ib, k) == col)
2442 vloc = alpha*A.Value(i, j)*B.Value(ib, k);
2443 if (Index(ind) >= 0)
2446 Value(Index(ind)) += vloc;
2459 Sort(nnz, IndCol, Value);
2462 C.AddInteractionRow(i, nnz, IndCol, Value,
true);
2465 for (
int j = 0; j < nnz; j++)
2466 Index(IndCol(j)) = -1;
2471 Vector<int> Index(n), IndCol(n);
2472 Vector<T4, VectFull, Allocator4> Value(n);
2476 for (
int i = 0; i < A.GetM(); i++)
2479 for (
int j = 0; j < A.GetRowSize(i); j++)
2481 col = A.Index(i, j);
2484 for (
int ib = 0; ib < B.GetM(); ib++)
2485 for (
int k = 0; k < B.GetRowSize(ib); k++)
2486 if (B.Index(ib, k) == col)
2489 vloc = alpha*A.Value(i, j)*conjugate(B.Value(ib, k));
2490 if (Index(ind) >= 0)
2493 Value(Index(ind)) += vloc;
2506 Sort(nnz, IndCol, Value);
2509 C.AddInteractionRow(i, nnz, IndCol, Value,
true);
2512 for (
int j = 0; j < nnz; j++)
2513 Index(IndCol(j)) = -1;
2517 else if (TransA.Trans())
2519 if (TransB.NoTrans())
2522 for (
int i = 0; i < B.GetM(); i++)
2524 for (
int j = 0; j < B.GetRowSize(i); j++)
2526 col = B.Index(i, j);
2527 for (
int k = 0; k < A.GetRowSize(i); k++)
2529 ind = A.Index(i, k);
2530 vloc = alpha*B.Value(i, j)*A.Value(i, k);
2531 C.AddInteraction(ind, col, vloc);
2536 else if (TransB.Trans())
2538 Vector<int> Index(m), IndCol(m);
2539 Vector<T4, VectFull, Allocator4> Value(m);
2543 for (
int i = 0; i < B.GetM(); i++)
2546 for (
int j = 0; j < B.GetRowSize(i); j++)
2548 col = B.Index(i, j);
2551 for (
int k = 0; k < A.GetRowSize(col); k++)
2553 ind = A.Index(col, k);
2554 vloc = alpha*B.Value(i, j)*A.Value(col, k);
2555 if (Index(ind) >= 0)
2558 Value(Index(ind)) += vloc;
2571 Sort(nnz, IndCol, Value);
2574 C.AddInteractionColumn(i, nnz, IndCol, Value);
2577 for (
int j = 0; j < nnz; j++)
2578 Index(IndCol(j)) = -1;
2583 Vector<int> Index(m), IndCol(m);
2584 Vector<T4, VectFull, Allocator4> Value(m);
2588 for (
int i = 0; i < B.GetM(); i++)
2591 for (
int j = 0; j < B.GetRowSize(i); j++)
2593 col = B.Index(i, j);
2596 for (
int k = 0; k < A.GetRowSize(col); k++)
2598 ind = A.Index(col, k);
2599 vloc = alpha*conjugate(B.Value(i, j))*A.Value(col, k);
2600 if (Index(ind) >= 0)
2603 Value(Index(ind)) += vloc;
2616 Sort(nnz, IndCol, Value);
2619 C.AddInteractionColumn(i, nnz, IndCol, Value);
2622 for (
int j = 0; j < nnz; j++)
2623 Index(IndCol(j)) = -1;
2627 else if (TransA.ConjTrans())
2629 if (TransB.NoTrans())
2632 for (
int i = 0; i < B.GetM(); i++)
2634 for (
int j = 0; j < B.GetRowSize(i); j++)
2636 col = B.Index(i, j);
2637 for (
int k = 0; k < A.GetRowSize(i); k++)
2639 ind = A.Index(i, k);
2640 vloc = alpha*B.Value(i, j)*conjugate(A.Value(i, k));
2641 C.AddInteraction(ind, col, vloc);
2646 else if (TransB.Trans())
2648 Vector<int> Index(m), IndCol(m);
2649 Vector<T4, VectFull, Allocator4> Value(m);
2653 for (
int i = 0; i < B.GetM(); i++)
2656 for (
int j = 0; j < B.GetRowSize(i); j++)
2658 col = B.Index(i, j);
2661 for (
int k = 0; k < A.GetRowSize(col); k++)
2663 ind = A.Index(col, k);
2664 vloc = alpha*B.Value(i, j)*conjugate(A.Value(col, k));
2665 if (Index(ind) >= 0)
2668 Value(Index(ind)) += vloc;
2681 Sort(nnz, IndCol, Value);
2684 C.AddInteractionColumn(i, nnz, IndCol, Value);
2687 for (
int j = 0; j < nnz; j++)
2688 Index(IndCol(j)) = -1;
2693 Vector<int> Index(m), IndCol(m);
2694 Vector<T4, VectFull, Allocator4> Value(m);
2698 for (
int i = 0; i < B.GetM(); i++)
2701 for (
int j = 0; j < B.GetRowSize(i); j++)
2703 col = B.Index(i, j);
2706 for (
int k = 0; k < A.GetRowSize(col); k++)
2708 ind = A.Index(col, k);
2709 vloc = alpha*conjugate(B.Value(i, j))*conjugate(A.Value(col, k));
2710 if (Index(ind) >= 0)
2713 Value(Index(ind)) += vloc;
2726 Sort(nnz, IndCol, Value);
2729 C.AddInteractionColumn(i, nnz, IndCol, Value);
2732 for (
int j = 0; j < nnz; j++)
2733 Index(IndCol(j)) = -1;
2745 template<
class T,
class Prop,
class Storage,
class Allocator,
class T0>
2749 A.RemoveSmallEntry(epsilon);
2754 template<
class T,
class Prop,
class Allocator,
class T0>
2763 template<
class T,
class Prop,
class Allocator,
class T0>
2776 template<
class T1,
class Prop,
class Allocator>
2780 int m = col_number.GetM();
2782 IVect index(A.GetM()); index.Fill(-1);
2783 for (
int i = 0; i < m; i++)
2784 index(col_number(i)) = i;
2787 for (
int i = 0; i < A.GetM(); i++)
2794 for (
int i = 0; i < A.GetM(); i++)
2796 bool something_to_remove =
false;
2797 for (
int j = 0; j < A.GetRowSize(i); j++)
2798 if (index(A.Index(i,j)) != -1)
2799 something_to_remove =
true;
2801 if (something_to_remove)
2804 for (
int j = 0; j < A.GetRowSize(i); j++)
2805 if (index(A.Index(i,j)) == -1)
2807 A.Index(i, nb) = A.Index(i, j);
2808 A.Value(i, nb) = A.Value(i, j);
2823 template<
class T1,
class Prop,
class Allocator>
2827 int m = col_number.GetM();
2829 IVect index(A.GetM()); index.Fill(-1);
2830 for (
int i = 0; i < m; i++)
2831 index(col_number(i)) = i;
2833 for (
int i = 0; i < A.GetM(); i++)
2835 bool something_to_remove =
false;
2836 for (
int j = 0; j < A.GetRowSize(i); j++)
2837 if (index(A.Index(i,j)) != -1)
2838 something_to_remove =
true;
2840 if (something_to_remove)
2843 for (
int j = 0; j < A.GetRowSize(i); j++)
2844 if (index(A.Index(i,j)) == -1)
2846 A.Index(i, nb) = A.Index(i, j);
2847 A.Value(i, nb) = A.Value(i, j);
2862 template<
class T1,
class Prop,
class Allocator>
2866 int m = A.GetM(), n = A.GetN();
2867 long nnz = A.GetIndSize();
2868 long* ptr = A.GetPtr();
2869 int* ind = A.GetInd();
2870 T1* data = A.GetData();
2872 ColToKeep.Fill(
true);
2873 for (
int i = 0; i < col_number.GetM(); i++)
2874 ColToKeep(col_number(i)) =
false;
2876 for (
long i = 0; i < A.GetIndSize(); i++)
2877 if (!ColToKeep(ind[i]))
2880 if (nnz == A.GetIndSize())
2886 for (
int i = 0; i < m; i++)
2888 long jA = Ptr(i);
int size_row = 0;
2889 for (
long j = ptr[i]; j < ptr[i+1]; j++)
2890 if (ColToKeep(ind[j]))
2897 Ptr(i+1) = Ptr(i) + size_row;
2900 A.SetData(m, n, Val, Ptr, Ind);
2909 template<
class T1,
class Prop,
class Allocator>
2913 int m = A.GetM(), n = A.GetN();
2914 long nnz = A.GetIndSize();
2915 long* ptr = A.GetPtr();
2916 int* ind = A.GetInd();
2917 T1* data = A.GetData();
2919 ColToKeep.Fill(
true);
2920 for (
int i = 0; i < col_number.GetM(); i++)
2921 ColToKeep(col_number(i)) =
false;
2923 for (
int i = 0; i < m; i++)
2926 nnz -= ptr[i+1] - ptr[i];
2929 for (
long j = ptr[i]; j < ptr[i+1]; j++)
2930 if (!ColToKeep(ind[j]))
2935 if (nnz == A.GetIndSize())
2941 for (
int i = 0; i < m; i++)
2943 long jA = Ptr(i);
int size_row = 0;
2945 for (
long j = ptr[i]; j < ptr[i+1]; j++)
2946 if (ColToKeep(ind[j]))
2953 Ptr(i+1) = Ptr(i) + size_row;
2956 A.SetData(m, n, Val, Ptr, Ind);
2965 template<
class T1,
class Prop,
class Storage,
class Allocator>
2969 cout <<
"Not implemented for any matrix" << endl;
2979 template<
class T1,
class Prop,
class Storage,
class Allocator>
2983 cout <<
"Not implemented for any matrix" << endl;
2993 template<
class T1,
class Prop,
class Allocator>
2997 EraseCol(col_number, A);
3006 template<
class T1,
class Prop,
class Allocator>
3010 for (
int i = 0; i < col_number.GetM(); i++)
3011 A.ClearRow(col_number(i));
3020 template<
class T1,
class Prop,
class Allocator>
3024 int m = A.GetM(), n = A.GetN();
3025 long nnz = A.GetIndSize();
3026 long* ptr = A.GetPtr();
3027 int* ind = A.GetInd();
3028 T1* data = A.GetData();
3030 RowToKeep.Fill(
true);
3031 for (
int i = 0; i < col_number.GetM(); i++)
3032 RowToKeep(col_number(i)) =
false;
3034 for (
int i = 0; i < m; i++)
3036 nnz -= ptr[i+1] - ptr[i];
3041 for (
int i = 0; i < m; i++)
3045 int size_row = ptr[i+1] - ptr[i];
3046 for (
int j = 0; j < size_row; j++)
3048 Ind(Ptr(i) + j) = ind[ptr[i] + j];
3049 Val(Ptr(i) + j) = data[ptr[i] + j];
3052 Ptr(i+1) = Ptr(i) + size_row;
3058 A.SetData(m, n, Val, Ptr, Ind);
3066 template<
class T1,
class Prop,
class Allocator>
3070 EraseCol(col_number, A);
3080 template<
class T,
class Complexe,
class Allocator>
3085 int n = mat_direct.GetM();
3086 diagonal_scale_left.Reallocate(n);
3087 diagonal_scale_left.Fill(0);
3088 for (
int i = 0; i < n; i++)
3089 for (
int j = 0; j < mat_direct.GetRowSize(i); j++)
3090 diagonal_scale_left(i) += abs(mat_direct.Value(i,j));
3101 template<
class T,
class Complexe,
class Allocator>
3106 int n = mat_direct.GetM();
3107 diagonal_scale_left.Reallocate(n);
3108 diagonal_scale_left.Fill(0);
3109 for (
int i = 0; i < n; i++)
3110 for (
int j = 0; j < mat_direct.GetRowSize(i); j++)
3112 diagonal_scale_left(i) += abs(mat_direct.Value(i,j));
3113 if (i != mat_direct.Index(i,j))
3114 diagonal_scale_left(mat_direct.Index(i,j))
3115 += abs(mat_direct.Value(i,j));
3126 template<
class T,
class Complexe,
class Allocator>
3131 int n = mat_direct.GetM();
3132 diagonal_scale_left.Reallocate(n);
3133 diagonal_scale_left.Fill(0);
3134 long* ptr = mat_direct.GetPtr();
3135 Complexe* data = mat_direct.GetData();
3136 for (
int i = 0; i < n; i++)
3137 for (
long j = ptr[i]; j < ptr[i+1]; j++)
3138 diagonal_scale_left(i) += abs(data[j]);
3149 template<
class T,
class Complexe,
class Allocator>
3154 int n = mat_direct.GetM();
3155 diagonal_scale_left.Reallocate(n);
3156 diagonal_scale_left.Fill(0);
3157 long* ptr = mat_direct.GetPtr();
3158 int* ind = mat_direct.GetInd();
3159 Complexe* data = mat_direct.GetData();
3160 for (
int i = 0; i < n; i++)
3161 for (
long j = ptr[i]; j < ptr[i+1]; j++)
3163 diagonal_scale_left(i) += abs(data[j]);
3165 diagonal_scale_left(ind[j]) += abs(data[j]);
3176 template<
class T,
class Complexe,
class Allocator>
3181 int n = mat_direct.GetM();
3182 diagonal_scale.Reallocate(mat_direct.GetN());
3183 diagonal_scale.Fill(0);
3184 for (
int i = 0; i < n; i++)
3185 for (
int j = 0; j < mat_direct.GetRowSize(i); j++)
3186 diagonal_scale(mat_direct.Index(i, j)) += abs(mat_direct.Value(i, j));
3197 template<
class T,
class Complexe,
class Allocator>
3202 GetRowSum(diagonal_scale, mat_direct);
3212 template<
class T,
class Complexe,
class Allocator>
3217 int n = mat_direct.GetM();
3218 diagonal_scale.Reallocate(mat_direct.GetN());
3219 diagonal_scale.Fill(0);
3220 long* ptr = mat_direct.GetPtr();
3221 int* ind = mat_direct.GetInd();
3222 Complexe* data = mat_direct.GetData();
3223 for (
int i = 0; i < n; i++)
3224 for (
long j = ptr[i]; j < ptr[i+1]; j++)
3225 diagonal_scale(ind[j]) += abs(data[j]);
3236 template<
class T,
class Complexe,
class Allocator>
3241 GetRowSum(diagonal_scale, mat_direct);
3254 template<
class T,
class Complexe,
class Allocator>
3261 sum_row.Reallocate(n);
3262 sum_col.Reallocate(A.GetN());
3265 for (
int i = 0; i < n; i++)
3266 for (
int j = 0; j < A.GetRowSize(i); j++)
3268 sum_row(i) += abs(A.Value(i,j));
3269 sum_col(A.Index(i, j)) += abs(A.Value(i,j));
3283 template<
class T,
class Complexe,
class Allocator>
3289 GetRowSum(sum_row, A);
3303 template<
class T,
class Complexe,
class Allocator>
3310 sum_row.Reallocate(n);
3311 sum_col.Reallocate(A.GetN());
3314 long* ptr = A.GetPtr();
3315 int* ind = A.GetInd();
3316 Complexe* data = A.GetData();
3317 for (
int i = 0; i < n; i++)
3318 for (
long j = ptr[i]; j < ptr[i+1]; j++)
3320 sum_row(i) += abs(data[j]);
3321 sum_col(ind[j]) += abs(data[j]);
3335 template<
class T,
class Complexe,
class Allocator>
3341 GetRowSum(sum_row, A);
3347 template<
class T0,
class Prop0,
class Allocator0,
3348 class T1,
class Allocator1>
3355 int m = A.GetM(), n = A.GetN();
3356 if ((m <= 0) || (n <= 0) || (row.GetM() <= 0) || (col.GetM() <= 0))
3358 RowNum.Clear(); ColNum.Clear(); Value.Clear();
3363 RowKept.Fill(
false); ColKept.Fill(
false);
3364 for (
int i = 0; i < row.GetM(); i++)
3365 RowKept(row(i)) =
true;
3367 for (
int i = 0; i < col.GetM(); i++)
3368 ColKept(col(i)) =
true;
3371 for (
int i = 0; i < A.GetM(); i++)
3373 for (
int j = 0; j < A.GetRowSize(i); j++)
3374 if (ColKept(A.Index(i, j)))
3377 RowNum.Reallocate(nnz);
3378 ColNum.Reallocate(nnz);
3379 Value.Reallocate(nnz);
3381 for (
int i = 0; i < A.GetM(); i++)
3383 for (
int j = 0; j < A.GetRowSize(i); j++)
3384 if (ColKept(A.Index(i, j)))
3387 ColNum(nnz) = A.Index(i, j);
3388 Value(nnz) = A.Value(i, j);
3395 template<
class T0,
class Prop0,
class Allocator0,
3396 class T1,
class Allocator1>
3404 int m = A.GetM(), n = A.GetN();
3405 if ((m <= 0) || (n <= 0) || (row.GetM() <= 0) || (col.GetM() <= 0))
3407 RowNum.Clear(); ColNum.Clear(); Value.Clear();
3412 RowKept.Fill(
false); ColKept.Fill(
false);
3413 for (
int i = 0; i < row.GetM(); i++)
3414 RowKept(row(i)) =
true;
3416 for (
int i = 0; i < col.GetM(); i++)
3417 ColKept(col(i)) =
true;
3420 for (
int i = 0; i < A.GetM(); i++)
3421 for (
int j = 0; j < A.GetRowSize(i); j++)
3423 if (ColKept(A.Index(i, j)) && RowKept(i))
3426 if (A.Index(i, j) != i)
3427 if (RowKept(A.Index(i, j)) && ColKept(i))
3431 RowNum.Reallocate(nnz);
3432 ColNum.Reallocate(nnz);
3433 Value.Reallocate(nnz);
3435 for (
int i = 0; i < A.GetM(); i++)
3436 for (
int j = 0; j < A.GetRowSize(i); j++)
3438 if (ColKept(A.Index(i, j)) && RowKept(i))
3441 ColNum(nnz) = A.Index(i, j);
3442 Value(nnz) = A.Value(i, j);
3446 if (A.Index(i, j) != i)
3447 if (RowKept(A.Index(i, j)) && ColKept(i))
3449 RowNum(nnz) = A.Index(i, j);
3451 Value(nnz) = A.Value(i, j);
3459 template<
class T0,
class Prop0,
class Allocator0,
3460 class T1,
class Allocator1>
3467 int m = A.GetM(), n = A.GetN();
3468 if ((m <= 0) || (n <= 0) || (row.GetM() <= 0) || (col.GetM() <= 0))
3470 RowNum.Clear(); ColNum.Clear(); Value.Clear();
3474 long* ptr = A.GetPtr();
3475 int* ind = A.GetInd();
3476 T0* data = A.GetData();
3478 RowKept.Fill(
false); ColKept.Fill(
false);
3479 for (
int i = 0; i < row.GetM(); i++)
3480 RowKept(row(i)) =
true;
3482 for (
int i = 0; i < col.GetM(); i++)
3483 ColKept(col(i)) =
true;
3486 for (
int i = 0; i < m; i++)
3488 for (
long j = ptr[i]; j < ptr[i+1]; j++)
3489 if (ColKept(ind[j]))
3492 RowNum.Reallocate(nnz);
3493 ColNum.Reallocate(nnz);
3494 Value.Reallocate(nnz);
3496 for (
int i = 0; i < m; i++)
3498 for (
long j = ptr[i]; j < ptr[i+1]; j++)
3499 if (ColKept(ind[j]))
3502 ColNum(nnz) = ind[j];
3503 Value(nnz) = data[j];
3510 template<
class T0,
class Prop0,
class Allocator0,
3511 class T1,
class Allocator1>
3518 int m = A.GetM(), n = A.GetN();
3519 if ((m <= 0) || (n <= 0) || (row.GetM() <= 0) || (col.GetM() <= 0))
3521 RowNum.Clear(); ColNum.Clear(); Value.Clear();
3525 long* ptr = A.GetPtr();
3526 int* ind = A.GetInd();
3527 T0* data = A.GetData();
3529 RowKept.Fill(
false); ColKept.Fill(
false);
3530 for (
int i = 0; i < row.GetM(); i++)
3531 RowKept(row(i)) =
true;
3533 for (
int i = 0; i < col.GetM(); i++)
3534 ColKept(col(i)) =
true;
3537 for (
int i = 0; i < m; i++)
3538 for (
long j = ptr[i]; j < ptr[i+1]; j++)
3540 if (ColKept(ind[j]) && RowKept(i))
3544 if (RowKept(ind[j]) && ColKept(i))
3548 RowNum.Reallocate(nnz);
3549 ColNum.Reallocate(nnz);
3550 Value.Reallocate(nnz);
3552 for (
int i = 0; i < m; i++)
3553 for (
long j = ptr[i]; j < ptr[i+1]; j++)
3555 if (ColKept(ind[j]) && RowKept(i))
3558 ColNum(nnz) = ind[j];
3559 Value(nnz) = data[j];
3564 if (RowKept(ind[j]) && ColKept(i))
3566 RowNum(nnz) = ind[j];
3568 Value(nnz) = data[j];
3576 template<
class T0,
class Prop0,
class Storage0,
class Allocator0,
3577 class T1,
class Prop1,
class Storage1,
class Allocator1>
3587 CopySubMatrix(A, row, col, RowNum, ColNum, Value);
3590 B.Reallocate(A.GetM(), A.GetN());
3591 ConvertMatrix_from_Coordinates(RowNum, ColNum, Value, B);
3596 #define SELDON_FILE_FUNCTIONS_MATRIX_ARRAY_CXX