23 #ifndef SELDON_FILE_FUNCTIONS_MATRIX_CXX
24 #define SELDON_FILE_FUNCTIONS_MATRIX_CXX
27 #include "Functions_Matrix.hxx"
89 class T1,
class Prop1,
class Storage1,
class Allocator1>
96 long taille = A.GetDataSize();
97 for (
long i = 0; i < taille; i++)
108 class T1,
class Prop1,
class Allocator1>
112 typename T1::value_type alpha_ = alpha;
113 for (
int i = 0; i < A.GetMmatrix(); i++)
114 for (
int j = 0; j < A.GetNmatrix(); j++)
115 Mlt(alpha, A.GetMatrix(i, j));
125 class T1,
class Prop1,
class Allocator1>
129 typename T1::value_type alpha_ = alpha;
130 for (
int i = 0; i < A.GetMmatrix(); i++)
131 for (
int j = 0; j < A.GetNmatrix(); j++)
132 Mlt(alpha_, A.GetMatrix(i, j));
141 template <
class T0,
class Allocator>
152 ::double_sparse_m m3;
154 for (
int i = 0; i < A.GetMmatrix(); i++)
155 for (
int j = 0; j < A.GetNmatrix(); j++)
157 switch (A.GetType(i, j))
160 A.GetMatrix(i, j, m0);
161 Mlt(
float(alpha), m0);
162 A.SetMatrix(i, j, m0);
166 A.GetMatrix(i, j, m1);
167 Mlt(
float(alpha), m1);
168 A.SetMatrix(i, j, m1);
172 A.GetMatrix(i, j, m2);
173 Mlt(
double(alpha), m2);
174 A.SetMatrix(i, j, m2);
178 A.GetMatrix(i, j, m3);
179 Mlt(
double(alpha), m3);
180 A.SetMatrix(i, j, m3);
185 "DenseSparseCollection)",
186 "Underlying matrix (" +
to_str(i) +
" ,"
187 +
to_str(j) +
" ) not defined.");
204 template <
class T0,
class Prop0,
class Allocator0,
205 class T1,
class Prop1,
class Allocator1,
206 class T2,
class Prop2,
class Allocator2>
211 #ifdef SELDON_CHECK_DIMENSIONS
212 CheckDim(A, B,
"Mlt(const Matrix<RowSparse>& A, const "
213 "Matrix<RowSparse>& B, Matrix<RowSparse>& C)");
216 #ifdef SELDON_CHECK_MEMORY
217 if (!Allocator2::KeepDataReallocate)
218 throw Undefined(
"Mlt(RowSparse)",
"Function not defined for"
219 " NewAlloc allocator");
222 int h, i, col;
long k, l;
223 long Nnonzero;
int Nnonzero_row, Nnonzero_row_max;
226 typedef typename SeldonDefaultAllocator<VectFull, int>::allocator AllocInt;
227 typedef typename SeldonDefaultAllocator<VectFull, long>::allocator AllocLong;
237 #ifdef SELDON_CHECK_MEMORY
242 c_ptr = AllocLong::allocate(m + 1);
244 #ifdef SELDON_CHECK_MEMORY
252 throw NoMemory(
"Mlt(const Matrix<RowSparse>& A, const "
253 "Matrix<RowSparse>& B, Matrix<RowSparse>& C)",
254 "Unable to allocate memory for an array of "
255 +
to_str(m + 1) +
" integers.");
262 for (i = 0; i < m; i++)
264 c_ptr[i + 1] = c_ptr[i];
266 if (A.GetPtr()[i + 1] != A.GetPtr()[i])
273 Nnonzero_row_max = 0;
275 for (k = A.GetPtr()[i]; k < A.GetPtr()[i + 1]; k++)
278 Nnonzero_row_max += B.GetPtr()[col + 1] - B.GetPtr()[col];
281 column_index.Reallocate(Nnonzero_row_max);
282 row_value.Reallocate(Nnonzero_row_max);
285 for (k = A.GetPtr()[i]; k < A.GetPtr()[i + 1]; k++)
290 value = A.GetData()[k];
293 for (l = B.GetPtr()[col]; l < B.GetPtr()[col + 1]; l++)
295 column_index(h) = B.GetInd()[l];
296 row_value(h) = value * B.GetData()[l];
301 Nnonzero_row = column_index.GetLength();
302 Assemble(Nnonzero_row, column_index, row_value);
304 #ifdef SELDON_CHECK_MEMORY
312 reinterpret_cast<int*
>(AllocInt::
313 reallocate(c_ind, Nnonzero + Nnonzero_row));
316 reinterpret_cast<T2*
>(Allocator2::
317 reallocate(c_data, Nnonzero + Nnonzero_row));
319 #ifdef SELDON_CHECK_MEMORY
327 if ((c_ind == NULL || c_data == NULL)
328 && Nnonzero + Nnonzero_row != 0)
329 throw NoMemory(
"Mlt(const Matrix<RowSparse>& A, const "
330 "Matrix<RowSparse>& B, Matrix<RowSparse>& C)",
331 "Unable to allocate memory for an array of "
332 +
to_str(Nnonzero + Nnonzero_row) +
" integers "
333 "and for an array of "
334 +
to_str(
sizeof(T2) * (Nnonzero + Nnonzero_row))
338 c_ptr[i + 1] += Nnonzero_row;
339 for (h = 0; h < Nnonzero_row; h++)
341 c_ind[Nnonzero + h] = column_index(h);
342 c_data[Nnonzero + h] = row_value(h);
344 Nnonzero += Nnonzero_row;
348 C.SetData(A.GetM(), B.GetN(), Nnonzero, c_data, c_ptr, c_ind);
361 template <
class T0,
class Prop0,
class Allocator0,
362 class T1,
class Prop1,
class Allocator1,
363 class T2,
class Prop2,
class Allocator2>
368 #ifdef SELDON_CHECK_DIMENSIONS
369 CheckDim(A, B,
"Mlt(const Matrix<RowMajor>& A, const "
370 "Matrix<RowSparse>& B, Matrix<RowMajor>& C)");
376 C.Reallocate(A.GetM(), B.GetN());
379 for (
int i = 0; i < m; i++)
381 for (
int k = 0; k < n; k++)
385 for (
long l = B.GetPtr()[k]; l < B.GetPtr()[k + 1]; l++)
386 C(i, B.GetInd()[l]) += A(i, k) * B.GetData()[l];
401 template <
class T0,
class Prop0,
class Allocator0,
402 class T1,
class Prop1,
class Allocator1,
403 class T2,
class Prop2,
class Allocator2>
410 #ifdef SELDON_CHECK_DIMENSIONS
411 CheckDim(SeldonNoTrans, A, SeldonTrans, B,
412 "Mlt(const Matrix<RowMajor>& A, const "
413 "Matrix<RowSparse>& B, Matrix<RowMajor>& C)");
417 C.Reallocate(A.GetM(), B.GetM());
419 for (
int i = 0; i < m; i++)
421 for (
int j = 0; j < B.GetM(); j++)
425 for (
long l = B.GetPtr()[j]; l < B.GetPtr()[j + 1]; l++)
426 C(i, j) += A(i, B.GetInd()[l]) * B.GetData()[l];
443 template <
class T0,
class Prop0,
class Allocator0,
444 class T1,
class Prop1,
class Allocator1,
445 class T2,
class Prop2,
class Allocator2>
452 #ifdef SELDON_CHECK_DIMENSIONS
453 CheckDim(SeldonNoTrans, A, SeldonTrans, B,
454 "Mlt(const Matrix<RowSparse>& A, "
455 "const Matrix<RowSparse>& B, Matrix<RowSparse>& C)");
458 #ifdef SELDON_CHECK_MEMORY
459 if (!Allocator2::KeepDataReallocate)
460 throw Undefined(
"Mlt(RowSparse)",
"Function not defined for"
461 " NewAlloc allocator");
464 int h, i, col, ib;
long k, kb;
469 typedef typename SeldonDefaultAllocator<VectFull, int>::allocator AllocInt;
470 typedef typename SeldonDefaultAllocator<VectFull, long>::allocator AllocLong;
481 #ifdef SELDON_CHECK_MEMORY
486 c_ptr = AllocLong::allocate(m + 1);
488 #ifdef SELDON_CHECK_MEMORY
496 throw NoMemory(
"MltNoTransTrans(const Matrix<RowSparse>& A, "
497 "const Matrix<RowSparse>& B, Matrix<RowSparse>& C)",
498 "Unable to allocate memory for an array of "
499 +
to_str(m + 1) +
" integers.");
507 SetComplexZero(zero);
509 for (i = 0; i < m; i++)
511 c_ptr[i + 1] = c_ptr[i];
513 if (A.GetPtr()[i + 1] != A.GetPtr()[i])
520 for (k = A.GetPtr()[i]; k < A.GetPtr()[i + 1]; k++)
524 for (ib = 0; ib < n; ib++)
526 for (kb = B.GetPtr()[ib]; kb < B.GetPtr()[ib + 1]; kb++)
527 if (col == B.GetInd()[kb])
528 value += A.GetData()[k] * B.GetData()[kb];
531 row_value.Append(value);
532 column_index.Append(ib);
538 Nnonzero_row = column_index.GetLength();
539 Assemble(Nnonzero_row, column_index, row_value);
541 #ifdef SELDON_CHECK_MEMORY
549 reinterpret_cast<int*
>(AllocInt::
550 reallocate(c_ind, Nnonzero + Nnonzero_row));
553 reinterpret_cast<T2*
>(Allocator2::
554 reallocate(c_data, Nnonzero + Nnonzero_row));
556 #ifdef SELDON_CHECK_MEMORY
564 if ((c_ind == NULL || c_data == NULL)
565 && Nnonzero_row != 0)
566 throw NoMemory(
"MltNoTransTrans(const Matrix<RowSparse>& A, "
567 "const Matrix<RowSparse>& B, "
568 "Matrix<RowSparse>& C)",
569 "Unable to allocate memory for an array of "
570 +
to_str(Nnonzero + Nnonzero_row) +
" integers "
571 "and for an array of "
572 +
to_str(
sizeof(T2) * (Nnonzero + Nnonzero_row))
576 c_ptr[i + 1] += Nnonzero_row;
577 for (h = 0; h < Nnonzero_row; h++)
579 c_ind[Nnonzero + h] = column_index(h);
580 c_data[Nnonzero + h] = row_value(h);
582 Nnonzero += Nnonzero_row;
585 column_index.Clear();
589 C.SetData(A.GetM(), B.GetM(), Nnonzero, c_data, c_ptr, c_ind);
613 class T1,
class Prop1,
class Storage1,
class Allocator1,
614 class T2,
class Prop2,
class Storage2,
class Allocator2,
616 class T4,
class Prop4,
class Storage4,
class Allocator4>
627 #ifdef SELDON_CHECK_DIMENSIONS
628 CheckDim(A, B, C,
"MltAdd(alpha, A, B, beta, C)");
631 if ( (Storage1::Sparse) || (Storage2::Sparse) || (Storage4::Sparse))
632 throw WrongArgument(
"MltAdd",
"This function is intended to dense"
633 " matrices only and not to sparse matrices");
636 SetComplexZero(zero_T3);
639 SetComplexZero(zero);
642 for (
int i = 0; i < Storage4::GetFirst(mc, nc); i++)
643 for (
int j = Storage4::GetBeginLoop(i);
644 j < Storage4::GetEndLoop(mc, nc, i); j++)
645 C.Get(Storage4::GetFirst(i, j), Storage4::GetSecond(i, j))
648 for (
int i = 0; i < Storage4::GetFirst(mc, nc); i++)
649 for (
int j = Storage4::GetBeginLoop(i);
650 j < Storage4::GetEndLoop(mc, nc, i); j++)
651 C.Get(Storage4::GetFirst(i, j), Storage4::GetSecond(i, j)) = zero;
653 for (
int i = 0; i < Storage4::GetFirst(mc, nc); i++)
654 for (
int j = Storage4::GetBeginLoop(i);
655 j < Storage4::GetEndLoop(mc, nc, i); j++)
658 for (
int k = 0; k < na; k++)
659 temp += A(Storage4::GetFirst(i, j), k)
660 * B(k, Storage4::GetSecond(i, j));
661 C.Get(Storage4::GetFirst(i, j), Storage4::GetSecond(i, j))
684 class T1,
class Prop1,
class Storage1,
class Allocator1,
685 class T2,
class Prop2,
class Storage2,
class Allocator2,
687 class T4,
class Prop4,
class Storage4,
class Allocator4>
696 if ( (Storage1::Sparse) || (Storage2::Sparse) || (Storage4::Sparse))
697 throw WrongArgument(
"MltAdd",
"This function is intended to dense"
698 " matrices only and not to sparse matrices");
705 #ifdef SELDON_CHECK_DIMENSIONS
707 "MltAdd(alpha, TransA, A, TransB, B, beta, C)");
711 SetComplexZero(zero_T3);
712 SetComplexOne(one_T3);
715 SetComplexZero(zero);
727 if (TransB.NoTrans())
729 if (TransA.NoTrans())
731 else if (TransA.Trans())
734 for (
int i = 0; i < Storage4::GetFirst(mc, nc); i++)
735 for (
int j = Storage4::GetBeginLoop(i);
736 j < Storage4::GetEndLoop(mc, nc, i); j++)
739 for (
int k = 0; k < ma; k++)
740 temp += A(k, Storage4::GetFirst(i, j))
741 * B(k, Storage4::GetSecond(i, j));
743 C.Get(Storage4::GetFirst(i, j), Storage4::GetSecond(i, j))
750 for (
int i = 0; i < Storage4::GetFirst(mc, nc); i++)
751 for (
int j = Storage4::GetBeginLoop(i);
752 j < Storage4::GetEndLoop(mc, nc, i); j++)
755 for (
int k = 0; k < ma; k++)
756 temp += conjugate(A(k, Storage4::GetFirst(i, j)))
757 * B(k, Storage4::GetSecond(i, j));
759 C.Get(Storage4::GetFirst(i, j), Storage4::GetSecond(i, j))
764 else if (TransB.ConjTrans())
766 if (TransA.NoTrans())
769 for (
int i = 0; i < Storage4::GetFirst(mc, nc); i++)
770 for (
int j = Storage4::GetBeginLoop(i);
771 j < Storage4::GetEndLoop(mc, nc, i); j++)
774 for (
int k = 0; k < na; k++)
775 temp += A(Storage4::GetFirst(i, j), k)
776 * conjugate(B(Storage4::GetSecond(i, j), k));
778 C.Get(Storage4::GetFirst(i, j), Storage4::GetSecond(i, j))
782 else if (TransA.Trans())
785 for (
int i = 0; i < Storage4::GetFirst(mc, nc); i++)
786 for (
int j = Storage4::GetBeginLoop(i);
787 j < Storage4::GetEndLoop(mc, nc, i); j++)
790 for (
int k = 0; k < ma; k++)
791 temp += A(k, Storage4::GetFirst(i, j))
792 * conjugate(B(Storage4::GetSecond(i, j), k));
794 C.Get(Storage4::GetFirst(i, j), Storage4::GetSecond(i, j))
801 for (
int i = 0; i < Storage4::GetFirst(mc, nc); i++)
802 for (
int j = Storage4::GetBeginLoop(i);
803 j < Storage4::GetEndLoop(mc, nc, i); j++)
806 for (
int k = 0; k < ma; k++)
807 temp += conjugate(A(k, Storage4::GetFirst(i, j)))
808 * conjugate(B(Storage4::GetSecond(i, j), k));
810 C.Get(Storage4::GetFirst(i, j), Storage4::GetSecond(i, j))
817 if (TransA.NoTrans())
820 for (
int i = 0; i < Storage4::GetFirst(mc, nc); i++)
821 for (
int j = Storage4::GetBeginLoop(i);
822 j < Storage4::GetEndLoop(mc, nc, i); j++)
825 for (
int k = 0; k < na; k++)
826 temp += A(Storage4::GetFirst(i, j), k)
827 * B(Storage4::GetSecond(i, j), k);
829 C.Get(Storage4::GetFirst(i, j), Storage4::GetSecond(i, j))
833 else if (TransA.Trans())
836 for (
int i = 0; i < Storage4::GetFirst(mc, nc); i++)
837 for (
int j = Storage4::GetBeginLoop(i);
838 j < Storage4::GetEndLoop(mc, nc, i); j++)
841 for (
int k = 0; k < ma; k++)
842 temp += A(k, Storage4::GetFirst(i, j))
843 * B(Storage4::GetSecond(i, j), k);
845 C.Get(Storage4::GetFirst(i, j), Storage4::GetSecond(i, j))
852 for (
int i = 0; i < Storage4::GetFirst(mc, nc); i++)
853 for (
int j = Storage4::GetBeginLoop(i);
854 j < Storage4::GetEndLoop(mc, nc, i); j++)
857 for (
int k = 0; k < ma; k++)
858 temp += conjugate(A(k, Storage4::GetFirst(i, j)))
859 * B(Storage4::GetSecond(i, j), k);
861 C.Get(Storage4::GetFirst(i, j), Storage4::GetSecond(i, j))
881 class T1,
class Prop1,
class Allocator1,
882 class T2,
class Allocator2,
884 class T4,
class Prop4,
class Allocator4>
894 #ifdef SELDON_CHECK_DIMENSIONS
895 CheckDim(A, B, C,
"MltAdd(alpha, A, B, beta, C)");
898 MatGetArray(A.GetPetscMatrix(), &local_a);
901 MatGetLocalSize(A.GetPetscMatrix(), &mlocal_A, &nlocal_A);
903 local_A.SetData(mlocal_A, na, local_a);
906 MatGetArray(C.GetPetscMatrix(), &local_c);
909 MatGetLocalSize(C.GetPetscMatrix(), &mlocal_C, &nlocal_C);
911 local_C.SetData(mlocal_C, nc, local_c);
913 MltAdd(alpha, local_A, B, beta, local_C);
916 MatRestoreArray(A.GetPetscMatrix(), &local_a);
920 MatRestoreArray(C.GetPetscMatrix(), &local_c);
937 class T1,
class Prop1,
class Allocator1,
938 class T2,
class Prop2,
class Allocator2,
940 class T4,
class Prop4,
class Allocator4>
947 int na = A.GetNmatrix();
948 int mc = C.GetMmatrix();
949 int nc = C.GetNmatrix();
951 #ifdef SELDON_CHECK_DIMENSIONS
952 CheckDim(A, B, C,
"MltAdd(alpha, A, B, beta, C)");
955 typedef typename T4::value_type value_type;
959 for (
int i = 0; i < mc; i++ )
960 for (
int j = 0; j < nc; j++)
961 for (
int k = 0; k < na; k++)
962 MltAdd(value_type(alpha), A.GetMatrix(i, k), B.GetMatrix(k, j),
963 value_type(1), C.GetMatrix(i, j));
979 class T1,
class Prop1,
class Allocator1,
980 class T2,
class Prop2,
class Allocator2,
982 class T4,
class Prop4,
class Allocator4>
989 int na = A.GetNmatrix();
990 int mc = C.GetMmatrix();
991 int nc = C.GetNmatrix();
993 #ifdef SELDON_CHECK_DIMENSIONS
994 CheckDim(A, B, C,
"MltAdd(alpha, A, B, beta, C)");
997 typedef typename T4::value_type value_type;
1001 for (
int i = 0; i < mc; i++ )
1002 for (
int j = 0; j < nc; j++)
1003 for (
int k = 0; k < na; k++)
1004 MltAdd(value_type(alpha), A.GetMatrix(i, k), B.GetMatrix(k, j),
1005 value_type(1), C.GetMatrix(i, j));
1010 class T1,
class Allocator1,
1011 class T2,
class Allocator2,
1013 class T4,
class Allocator4>
1015 const Matrix<T1, General, RowMajor, Allocator1>& A,
1016 const Matrix<T2, General, RowMajor, Allocator2>& B,
1018 Matrix<T4, General, RowSparse, Allocator4>& C)
1020 throw Undefined(
"void MltAdd(const T0 alpha,"
1021 "const Matrix<T1, General, RowMajor, Allocator1>& A,"
1022 "const Matrix<T2, General, RowMajor, Allocator2>& B,"
1024 "Matrix<T4, General, RowSparse, Allocator4>& C)");
1029 class T1,
class Allocator1,
1030 class T2,
class Allocator2,
1032 class T4,
class Allocator4>
1034 const Matrix<T1, General, RowMajor, Allocator1>& A,
1035 const Matrix<T2, General, RowSparse, Allocator2>& B,
1037 Matrix<T4, General, RowSparse, Allocator4>& C)
1039 throw Undefined(
"void MltAdd(const T0 alpha,"
1040 "const Matrix<T1, General, RowMajor, Allocator1>& A,"
1041 "const Matrix<T2, General, RowSparse, Allocator2>& B,"
1043 "Matrix<T4, General, RowSparse, Allocator4>& C)");
1048 class T1,
class Allocator1,
1049 class T2,
class Allocator2,
1051 class T4,
class Allocator4>
1053 const Matrix<T1, General, RowSparse, Allocator1>& A,
1054 const Matrix<T2, General, RowMajor, Allocator2>& B,
1056 Matrix<T4, General, RowSparse, Allocator4>& C)
1058 throw Undefined(
"void MltAdd(const T0 alpha,"
1059 "const Matrix<T1, General, RowSparse, Allocator1>& A,"
1060 "const Matrix<T2, General, RowMajor, Allocator2>& B,"
1062 "Matrix<T4, General, RowSparse, Allocator4>& C)");
1070 class T4,
class Prop4,
class Storage4,
class Allocator4>
1071 void MltAdd_heterogeneous(
const T0& alpha,
1072 const Matrix<FloatDouble, General,
1073 DenseSparseCollection, Allocator1>& A,
1074 const Matrix<FloatDouble, General,
1075 DenseSparseCollection, Allocator2>& B,
1076 Matrix<FloatDouble, General,
1077 DenseSparseCollection, Allocator3>& C,
1078 Matrix<T4, Prop4, Storage4, Allocator4>& mc,
1081 typename Matrix<FloatDouble, General, DenseSparseCollection, Allocator1>
1082 ::float_dense_m m0a;
1083 typename Matrix<FloatDouble, General, DenseSparseCollection, Allocator1>
1084 ::float_sparse_m m1a;
1085 typename Matrix<FloatDouble, General, DenseSparseCollection, Allocator1>
1086 ::double_dense_m m2a;
1087 typename Matrix<FloatDouble, General, DenseSparseCollection, Allocator1>
1088 ::double_sparse_m m3a;
1090 int na = A.GetNmatrix();
1091 for (
int k = 0; k < na; k++)
1093 switch (A.GetType(i, k))
1096 A.GetMatrix(i, k, m0a);
1097 MltAdd_heterogeneous2(alpha, m0a, B, C, mc, j, k);
1101 A.GetMatrix(i, k, m1a);
1102 MltAdd_heterogeneous2(alpha, m1a, B, C, mc, j, k);
1106 A.GetMatrix(i, k, m2a);
1107 MltAdd_heterogeneous2(alpha, m2a, B, C, mc, j, k);
1111 A.GetMatrix(i, k, m3a);
1112 MltAdd_heterogeneous2(alpha, m3a, B, C, mc, j, k);
1116 throw WrongArgument(
"Matrix<FloatDouble, DenseSparseCollection>::"
1117 "MltAdd_heterogeneous(alpha, A, B, beta, C) ",
1118 "Underlying matrix A (" +
to_str(i) +
" ,"
1119 +
to_str(k) +
" ) not defined.");
1126 class T1,
class Prop1,
class Storage1,
class Allocator1,
1129 class T4,
class Prop4,
class Storage4,
class Allocator4>
1130 void MltAdd_heterogeneous2(
const T0& alpha,
1131 const Matrix<T1, Prop1,
1132 Storage1, Allocator1>& ma,
1133 const Matrix<FloatDouble, General,
1134 DenseSparseCollection, Allocator2>& B,
1135 Matrix<FloatDouble, General,
1136 DenseSparseCollection, Allocator3>& C,
1137 Matrix<T4, Prop4, Storage4, Allocator4>& mc,
1140 typename Matrix<FloatDouble, General, DenseSparseCollection, Allocator2>
1141 ::float_dense_m m0b;
1142 typename Matrix<FloatDouble, General, DenseSparseCollection, Allocator2>
1143 ::float_sparse_m m1b;
1144 typename Matrix<FloatDouble, General, DenseSparseCollection, Allocator2>
1145 ::double_dense_m m2b;
1146 typename Matrix<FloatDouble, General, DenseSparseCollection, Allocator2>
1147 ::double_sparse_m m3b;
1149 switch (B.GetType(k, j))
1152 B.GetMatrix(k, j, m0b);
1157 B.GetMatrix(k, j, m1b);
1162 B.GetMatrix(k, j, m2b);
1167 B.GetMatrix(k, j, m3b);
1172 throw WrongArgument(
"Matrix<FloatDouble, DenseSparseCollection>"
1173 "::MltAdd_heterogeneous2(alpha, A, B, beta, C)",
1174 "Underlying matrix B (" +
to_str(k) +
" ,"
1175 +
to_str(j) +
" ) not defined.");
1186 template <
class T0,
class Allocator1,
class Allocator2,
class T3,
1198 ::float_dense_m m0c;
1200 ::float_sparse_m m1c;
1202 ::double_dense_m m2c;
1204 ::double_sparse_m m3c;
1208 int mc = C.GetMmatrix();
1209 int nc = C.GetNmatrix();
1210 for (
int i = 0; i < mc; i++ )
1211 for (
int j = 0; j < nc; j++)
1213 switch (C.GetType(i, j))
1216 C.GetMatrix(i, j, m0c);
1217 MltAdd_heterogeneous(
float(alpha), A, B, C, m0c, i, j);
1218 C.SetMatrix(i, j, m0c);
1222 C.GetMatrix(i, j, m1c);
1223 MltAdd_heterogeneous(
float(alpha), A, B, C, m1c, i, j);
1224 C.SetMatrix(i, j, m1c);
1228 C.GetMatrix(i, j, m2c);
1229 MltAdd_heterogeneous(
double(alpha), A, B, C, m2c, i, j);
1230 C.SetMatrix(i, j, m2c);
1234 C.GetMatrix(i, j, m3c);
1235 MltAdd_heterogeneous(
double(alpha), A, B, C, m3c, i, j);
1236 C.SetMatrix(i, j, m3c);
1240 throw WrongArgument(
"Matrix<FloatDouble, DenseSparseCollection>"
1241 "::MltAdd(alpha, A, B, beta, C) ",
1242 "Underlying matrix C (" +
to_str(i) +
" ,"
1243 +
to_str(j) +
" ) not defined.");
1261 class T1,
class Prop1,
class Allocator1,
1262 class T2,
class Prop2,
class Allocator2,
1264 class T4,
class Prop4,
class Allocator4>
1272 SetComplexZero(zero);
1320 class T1,
class Prop1,
class Allocator1,
1321 class T2,
class Prop2,
class Allocator2,
1323 class T4,
class Prop4,
class Allocator4>
1332 if (!TransA.NoTrans())
1333 throw WrongArgument(
"MltAdd(T0 alpha, SeldonTranspose TransA, "
1334 "const Matrix<RowSparse>& A, SeldonTranspose "
1335 "TransB, const Matrix<RowSparse>& B, T3 beta, "
1336 "Matrix<RowSparse>& C)",
1337 "'TransA' must be equal to 'SeldonNoTrans'.");
1338 if (!TransB.NoTrans() && !TransB.Trans())
1339 throw WrongArgument(
"MltAdd(T0 alpha, SeldonTranspose TransA, "
1340 "const Matrix<RowSparse>& A, SeldonTranspose "
1341 "TransB, const Matrix<RowSparse>& B, T3 beta, "
1342 "Matrix<RowSparse>& C)",
1343 "'TransB' must be equal to 'SeldonNoTrans' or "
1349 SetComplexZero(zero);
1358 MltMatrix(SeldonNoTrans, A, SeldonTrans, B, C);
1370 MltMatrix(SeldonNoTrans, A, SeldonTrans, B, tmp);
1384 template<
class T0,
class T1,
class Prop1,
class Allocator1,
class T4,
1385 class T2,
class Prop2,
class Storage2,
class Allocator2,
1386 class T3,
class Prop3,
class Storage3,
class Allocator3>
1393 if (Storage2::Sparse || Storage3::Sparse)
1395 " between a sparse matrix and a dense matrix");
1397 #ifdef SELDON_CHECK_DIMENSIONS
1401 long* ptr = A.GetPtr();
1402 int* ind = A.GetInd();
1403 T1* data = A.GetData();
1405 SetComplexZero(zero);
1414 for (
int i = 0; i < m; i++)
1415 for (
long k2 = ptr[i]; k2 < ptr[i+1]; k2++)
1418 val = data[k2] * alpha;
1420 for (
int j = 0; j < n; j++)
1421 C(i, j) += val*B(k, j);
1427 template<
class T0,
class T1,
class Prop1,
class Allocator1,
class T4,
1428 class T2,
class Prop2,
class Storage2,
class Allocator2,
1429 class T3,
class Prop3,
class Storage3,
class Allocator3>
1438 if (Storage2::Sparse || Storage3::Sparse)
1440 " between a sparse matrix and a dense matrix");
1442 long* ptr = A.GetPtr();
1443 int* ind = A.GetInd();
1444 T1* data = A.GetData();
1446 SetComplexZero(zero);
1451 if (TransA.NoTrans())
1453 if (TransB.NoTrans())
1455 else if (TransB.Trans())
1458 #ifdef SELDON_CHECK_DIMENSIONS
1459 CheckDim(SeldonNoTrans, A, SeldonTrans, B, C,
"MltAdd(A, B, C)");
1467 for (
int i = 0; i < m; i++)
1468 for (
long k2 = ptr[i]; k2 < ptr[i+1]; k2++)
1471 val = data[k2] * alpha;
1473 for (
int j = 0; j < B.GetM(); j++)
1474 C(i, j) += val*B(j, k);
1478 throw Undefined(
"MltAdd",
"Not implemented for ConjTrans");
1480 else if (TransA.Trans())
1482 if (TransB.NoTrans())
1484 #ifdef SELDON_CHECK_DIMENSIONS
1485 CheckDim(SeldonTrans, A, SeldonNoTrans, B, C,
"MltAdd(A, B, C)");
1493 for (
int i = 0; i < m; i++)
1494 for (
long k2 = ptr[i]; k2 < ptr[i+1]; k2++)
1497 val = data[k2] * alpha;
1499 for (
int j = 0; j < n; j++)
1500 C(k, j) += val*B(i, j);
1503 else if (TransB.Trans())
1505 #ifdef SELDON_CHECK_DIMENSIONS
1506 CheckDim(SeldonTrans, A, SeldonTrans, B, C,
"MltAdd(A, B, C)");
1514 for (
int i = 0; i < m; i++)
1515 for (
long k2 = ptr[i]; k2 < ptr[i+1]; k2++)
1518 val = data[k2] * alpha;
1520 for (
int j = 0; j < B.GetM(); j++)
1521 C(k, j) += val*B(j, i);
1525 throw Undefined(
"MltAdd",
"Not implemented for ConjTrans");
1528 throw Undefined(
"MltAdd",
"Not implemented for ConjTrans");
1543 class T1,
class Prop1,
class Allocator1,
1544 class T2,
class Prop2,
class Allocator2,
1546 class T4,
class Prop4,
class Allocator4>
1555 if (!TransA.NoTrans())
1556 throw WrongArgument(
"MltAdd(T0 alpha, SeldonTranspose TransA, "
1557 "const Matrix<RowMajor>& A, SeldonTranspose "
1558 "TransB, const Matrix<RowSparse>& B, T3 beta, "
1559 "Matrix<RowSparse>& C)",
1560 "'TransA' must be equal to 'SeldonNoTrans'.");
1561 if (!TransB.NoTrans() && !TransB.Trans())
1562 throw WrongArgument(
"MltAdd(T0 alpha, SeldonTranspose TransA, "
1563 "const Matrix<RowMajor>& A, SeldonTranspose "
1564 "TransB, const Matrix<RowSparse>& B, T3 beta, "
1565 "Matrix<RowMajor>& C)",
1566 "'TransB' must be equal to 'SeldonNoTrans' or "
1569 #ifdef SELDON_CHECK_DIMENSIONS
1570 CheckDim(SeldonNoTrans, A, SeldonTrans, B, C,
1571 "MltAdd(T0 alpha, const Matrix<RowMajor>& A, const "
1572 "Matrix<RowSparse>& B, T3 beta, Matrix<RowMajor>& C)");
1578 SetComplexZero(zero);
1586 for (
int i = 0; i < m; i++)
1587 for (
int j = 0; j < B.GetM(); j++)
1591 for (
long l = B.GetPtr()[j]; l < B.GetPtr()[j + 1]; l++)
1592 C(i, j) += alpha * A(i, B.GetInd()[l]) * B.GetData()[l];
1617 template<
class T0,
class T1,
class Prop1,
class Storage1,
class Allocator1,
1618 class T2,
class Prop2,
class Storage2,
class Allocator2>
1623 if ( (Storage1::Sparse) || (Storage2::Sparse) )
1624 throw WrongArgument(
"Add",
"This function is intended to dense"
1625 " matrices only and not to sparse matrices");
1628 int mb = B.GetM(), nb = B.GetN();
1629 for (i = 0; i < Storage2::GetFirst(mb, nb); i++)
1630 for (j = Storage2::GetBeginLoop(i);
1631 j < Storage2::GetEndLoop(mb, nb, i); j++)
1632 B.Get(Storage2::GetFirst(i, j), Storage2::GetSecond(i, j))
1633 += alpha * A(Storage2::GetFirst(i, j), Storage2::GetSecond(i, j));
1646 class T1,
class Prop1,
class Allocator1,
1647 class T2,
class Prop2,
class Allocator2>
1652 int na = A.GetNmatrix();
1653 int ma = A.GetMmatrix();
1655 typedef typename T2::value_type value_type;
1657 for (
int i = 0; i < ma; i++ )
1658 for (
int j = 0; j < na; j++)
1659 Add(value_type(alpha), A.GetMatrix(i, j), B.GetMatrix(i, j));
1672 class T1,
class Prop1,
class Allocator1,
1673 class T2,
class Prop2,
class Allocator2>
1678 int na = A.GetNmatrix();
1679 int ma = A.GetMmatrix();
1681 typedef typename T2::value_type value_type;
1683 for (
int i = 0; i < ma; i++ )
1684 for (
int j = 0; j < na; j++)
1685 Add(value_type(alpha), A.GetMatrix(i, j), B.GetMatrix(i, j));
1690 class T1,
class Prop1,
class Storage1,
class Allocator1,
1692 void Add_heterogeneous(
const T0& alpha,
1693 const Matrix<T1, Prop1, Storage1, Allocator1 >& ma,
1694 Matrix<FloatDouble, General,
1695 DenseSparseCollection, Allocator2>& B,
1698 typename Matrix<FloatDouble, General, DenseSparseCollection, Allocator2>
1699 ::float_dense_m m0b;
1700 typename Matrix<FloatDouble, General, DenseSparseCollection, Allocator2>
1701 ::float_sparse_m m1b;
1702 typename Matrix<FloatDouble, General, DenseSparseCollection, Allocator2>
1703 ::double_dense_m m2b;
1704 typename Matrix<FloatDouble, General, DenseSparseCollection, Allocator2>
1705 ::double_sparse_m m3b;
1709 switch (B.GetType(i, j))
1712 B.GetMatrix(i, j, m0b);
1713 Add(
float(alpha_), ma, m0b);
1714 B.SetMatrix(i, j, m0b);
1718 B.GetMatrix(i, j, m1b);
1719 Add(
float(alpha_), ma, m1b);
1720 B.SetMatrix(i, j, m1b);
1724 B.GetMatrix(i, j, m2b);
1725 Add(
double(alpha_), ma, m2b);
1726 B.SetMatrix(i, j, m2b);
1730 B.GetMatrix(i, j, m3b);
1731 Add(
double(alpha_), ma, m3b);
1732 B.SetMatrix(i, j, m3b);
1736 throw WrongArgument(
"Add_heterogeneous(alpha, Matrix<FloatDouble, "
1737 "DenseSparseCollection>, Matrix<FloatDouble,"
1738 "DenseSparseCollection> )",
1739 "Underlying matrix (" +
to_str(i) +
" ,"
1740 +
to_str(j) +
" ) not defined.");
1750 template <
class T0,
class Allocator1,
class Allocator2>
1757 ::float_dense_m m0a;
1759 ::float_sparse_m m1a;
1761 ::double_dense_m m2a;
1763 ::double_sparse_m m3a;
1767 for (
int i = 0; i < B.GetMmatrix(); i++)
1768 for (
int j = 0; j < B.GetNmatrix(); j++)
1770 switch (B.GetType(i, j))
1773 A.GetMatrix(i, j, m0a);
1774 Add_heterogeneous(
float(alpha_), m0a, B, i, j);
1778 A.GetMatrix(i, j, m1a);
1779 Add_heterogeneous(
float(alpha_), m1a, B, i, j);
1783 A.GetMatrix(i, j, m2a);
1784 Add_heterogeneous(
double(alpha_), m2a, B, i, j);
1788 A.GetMatrix(i, j, m3a);
1789 Add_heterogeneous(
double(alpha_), m3a, B, i, j);
1795 "DenseSparseCollection>, Matrix<FloatDouble,"
1796 "DenseSparseCollection> )",
1797 "Underlying matrix (" +
to_str(i) +
" ,"
1798 +
to_str(j) +
" ) not defined.");
1804 template<
class T0,
class T1,
class Prop1,
class Allocator1,
1805 class T2,
class Prop2,
class Allocator2>
1807 const Matrix<T1, Prop1, RowMajor, Allocator1>& A,
1808 Matrix<T2, Prop2, RowSparse, Allocator2>& B)
1810 throw Undefined(
"void Add(const T0& alpha,"
1811 "const Matrix<T1, Prop1, RowMajor, Allocator1>& A,"
1812 "Matrix<T2, Prop2, RowSparse, Allocator2>& B)");
1816 template<
class T0,
class T1,
class Prop1,
class Allocator1,
1817 class T2,
class Prop2,
class Allocator2>
1819 const Matrix<T1, Prop1, ColMajor, Allocator1>& A,
1820 Matrix<T2, Prop2, RowSparse, Allocator2>& B)
1822 throw Undefined(
"void Add(const T0& alpha,"
1823 "const Matrix<T1, Prop1, RowMajor, Allocator1>& A,"
1824 "Matrix<T2, Prop2, RowSparse, Allocator2>& B)");
1828 template<
class T0,
class T1,
class Prop1,
class Allocator1,
1829 class T2,
class Prop2,
class Storage,
class Allocator2>
1830 void Add_csr(
const T0& alpha,
1831 const Matrix<T1, Prop1, Storage, Allocator1>& A,
1832 Matrix<T2, Prop2, Storage, Allocator2>& B,
int p)
1834 #ifdef SELDON_CHECK_BOUNDS
1835 if (A.GetM() != B.GetM() || A.GetN() != B.GetN())
1836 throw WrongDim(
"Add(alpha, const Matrix<RowSparse>& A, "
1837 "Matrix<RowSparse>& B)",
1838 "Unable to add a " +
to_str(A.GetM()) +
" x "
1839 +
to_str(A.GetN()) +
" matrix with a "
1848 if (A.GetNonZeros() == B.GetNonZeros())
1853 for (i = 0; i < p; i++)
1854 if (A.GetPtr()[i + 1] == B.GetPtr()[i + 1])
1856 for (j = A.GetPtr()[i]; j < A.GetPtr()[i + 1]; j++)
1857 if (A.GetInd()[j] == B.GetInd()[j])
1858 B.GetData()[j] += alpha * A.GetData()[j];
1861 if (j != A.GetPtr()[i + 1])
1874 for (k = A.GetPtr()[i]; k < j; k++)
1875 if (A.GetInd()[k] == B.GetInd()[k])
1876 B.GetData()[k] -= alpha * A.GetData()[k];
1879 long Nnonzero = A.GetPtr()[i];
1882 long kb, jb(0), ka, ja(0);
1883 for (
int i2 = i; i2 < p; i2++)
1885 kb = B.GetPtr()[i2];
1887 for (ka = A.GetPtr()[i2]; ka < A.GetPtr()[i2 + 1]; ka++)
1889 ja = A.GetInd()[ka];
1890 while (kb < B.GetPtr()[i2 + 1] && B.GetInd()[kb] < ja)
1896 if (kb < B.GetPtr()[i2 + 1] && ja == B.GetInd()[kb])
1902 while (kb < B.GetPtr()[i2 + 1])
1912 Vector<long> Ptr(p+1); Vector<int> Ind(Nnonzero);
1913 Vector<T2, VectFull, Allocator2> Val(Nnonzero);
1915 for (
int i2 = 0; i2 <= i; i2++)
1916 Ptr(i2) = B.GetPtr()[i2];
1918 for (j = 0; j < B.GetPtr()[i]; j++)
1920 Ind(j) = B.GetInd()[j];
1921 Val(j) = B.GetData()[j];
1925 Nnonzero = A.GetPtr()[i];
1929 if (kb < B.GetPtr()[i + 1])
1930 jb = B.GetInd()[kb];
1931 for (ka = A.GetPtr()[i]; ka < A.GetPtr()[i + 1]; ka++)
1933 ja = A.GetInd()[ka];
1934 while (kb < B.GetPtr()[i + 1] && jb < ja)
1938 Val(Nnonzero) = B.GetData()[kb];
1940 if (kb < B.GetPtr()[i + 1])
1941 jb = B.GetInd()[kb];
1945 if (kb < B.GetPtr()[i + 1] && ja == jb)
1949 Val(Nnonzero) = B.GetData()[kb] + alpha * A.GetData()[ka];
1951 if (kb < B.GetPtr()[i + 1])
1952 jb = B.GetInd()[kb];
1957 Val(Nnonzero) = alpha * A.GetData()[ka];
1963 while (kb < B.GetPtr()[i + 1])
1966 Val(Nnonzero) = B.GetData()[kb];
1968 if (kb < B.GetPtr()[i + 1])
1969 jb = B.GetInd()[kb];
1973 Ptr(i + 1) = Nnonzero;
1976 B.SetData(B.GetM(), B.GetN(), Val, Ptr, Ind);
1988 template<
class T0,
class T1,
class Prop1,
class Allocator1,
1989 class T2,
class Prop2,
class Allocator2>
1994 Add_csr(alpha, A, B, B.GetM());
2006 template<
class T0,
class T1,
class Prop1,
class Allocator1,
2007 class T2,
class Prop2,
class Allocator2>
2012 Add_csr(alpha, A, B, B.GetN());
2024 template<
class T0,
class T1,
class Prop1,
class Allocator1,
2025 class T2,
class Prop2,
class Allocator2>
2030 Add_csr(alpha, A, B, B.GetM());
2042 template<
class T0,
class T1,
class Prop1,
class Allocator1,
2043 class T2,
class Prop2,
class Allocator2>
2048 Add_csr(alpha, A, B, B.GetN());
2072 template <
class T0,
class Prop0,
class Storage0,
class Allocator0>
2077 SetComplexZero(zero);
2081 #ifdef SELDON_CHECK_BOUNDS
2084 throw WrongDim(
"GetLU(A)",
"The matrix must be squared.");
2087 if (Storage0::Sparse)
2088 throw WrongArgument(
"GetLU",
"This function is intended to dense"
2089 " matrices only and not to sparse matrices");
2091 for (i = 0; i < ma; i++)
2093 for (p = i; p < ma; p++)
2096 for (k = 0; k < i; k++)
2097 temp += A(p, k) * A(k, i);
2100 for (q = i+1; q < ma; q++)
2103 for (k = 0; k < i; k++)
2104 temp += A(i, k) * A(k, q);
2105 A(i, q) = (A(i,q ) - temp) / A(i, i);
2129 template <
class T0,
class Prop0,
class Storage0,
class Allocator0,
2130 class T1,
class Prop1,
class Storage1,
class Allocator1,
2131 class T2,
class Prop2,
class Storage2,
class Allocator2>
2137 #ifndef SELDON_WITHOUT_TO_STR_CHECKDIM
2140 string Achar(
"A"), Bchar(
"B"), Cchar(
"C");
2143 if (B.GetM() != A.GetN() || C.GetM() != A.GetM() || B.GetN() != C.GetN())
2144 throw WrongDim(
function,
string(
"Operation A B + C -> C not permitted:")
2145 +
string(
"\n A (") + Achar +
string(
") is a ")
2147 +
string(
" matrix;\n B (") + Bchar
2148 +
string(
") is a ") +
to_str(B.GetM()) +
string(
" x ")
2149 +
to_str(B.GetN()) +
string(
" matrix;\n C (")
2150 + Cchar +
string(
") is a ") +
to_str(C.GetM())
2151 +
string(
" x ") +
to_str(C.GetN()) +
string(
" matrix."));
2166 template <
class T0,
class Prop0,
class Storage0,
class Allocator0,
2167 class T1,
class Prop1,
class Storage1,
class Allocator1,
2168 class T2,
class Prop2,
class Storage2,
class Allocator2>
2175 #ifndef SELDON_WITHOUT_TO_STR_CHECKDIM
2178 string Achar(
"A"), Bchar(
"B"), Cchar(
"C");
2182 (B.GetM() != A.GetN() || C.GetM() != A.GetM()
2183 || B.GetN() != C.GetN()) )
2184 throw WrongDim(
function,
string(
"Operation A B + C -> C not permitted:")
2185 +
string(
"\n A (") + Achar +
string(
") is a ")
2187 +
string(
" matrix;\n B (") + Bchar
2188 +
string(
") is a ") +
to_str(B.GetM()) +
string(
" x ")
2189 +
to_str(B.GetN()) +
string(
" matrix;\n C (")
2190 + Cchar +
string(
") is a ") +
to_str(C.GetM())
2191 +
string(
" x ") +
to_str(C.GetN()) +
string(
" matrix."));
2193 (B.GetN() != A.GetM() || C.GetM() != B.GetM()
2194 || A.GetN() != C.GetN()) )
2195 throw WrongDim(
function,
string(
"Operation B A + C -> C not permitted:")
2196 +
string(
"\n A (") + Achar +
string(
") is a ")
2198 +
string(
" matrix;\n B (") + Bchar
2199 +
string(
") is a ") +
to_str(B.GetM()) +
string(
" x ")
2200 +
to_str(B.GetN()) +
string(
" matrix;\n C (")
2201 + Cchar +
string(
") is a ") +
to_str(C.GetM())
2202 +
string(
" x ") +
to_str(C.GetN()) +
string(
" matrix."));
2217 template <
class T0,
class Prop0,
class Storage0,
class Allocator0,
2218 class T1,
class Prop1,
class Storage1,
class Allocator1>
2225 #ifndef SELDON_WITHOUT_TO_STR_CHECKDIM
2228 string Achar(
"A"), Bchar(
"B");
2234 if (status_A.Trans())
2236 else if (status_A.ConjTrans())
2240 if (status_B.Trans())
2241 op += string(
" B'");
2242 else if (status_B.ConjTrans())
2243 op += string(
" B*");
2246 op = string(
"Operation ") + op + string(
" not permitted:");
2247 if (B.GetM(status_B) != A.GetN(status_A))
2249 +
string(
"\n A (") + Achar +
string(
") is a ")
2251 +
string(
" matrix;\n B (") + Bchar
2252 +
string(
") is a ") +
to_str(B.GetM()) +
string(
" x ")
2253 +
to_str(B.GetN()) +
string(
" matrix."));
2269 template <
class T0,
class Prop0,
class Storage0,
class Allocator0,
2270 class T1,
class Prop1,
class Storage1,
class Allocator1,
2271 class T2,
class Prop2,
class Storage2,
class Allocator2>
2279 #ifndef SELDON_WITHOUT_TO_STR_CHECKDIM
2282 string Achar(
"A"), Bchar(
"B"), Cchar(
"C");
2288 else if (TransA.ConjTrans())
2293 op += string(
" B' + C");
2294 else if (TransB.ConjTrans())
2295 op += string(
" B* + C");
2297 op += string(
" B + C");
2298 op = string(
"Operation ") + op + string(
" not permitted:");
2299 if (B.GetM(TransB) != A.GetN(TransA) || C.GetM() != A.GetM(TransA)
2300 || B.GetN(TransB) != C.GetN())
2302 +
string(
"\n A (") + Achar +
string(
") is a ")
2304 +
string(
" matrix;\n B (") + Bchar
2305 +
string(
") is a ") +
to_str(B.GetM()) +
string(
" x ")
2306 +
to_str(B.GetN()) +
string(
" matrix;\n C (")
2307 + Cchar +
string(
") is a ") +
to_str(C.GetM())
2308 +
string(
" x ") +
to_str(C.GetN()) +
string(
" matrix."));
2321 template <
class T0,
class Prop0,
class Storage0,
class Allocator0,
2322 class T1,
class Prop1,
class Storage1,
class Allocator1>
2327 CheckDim(SeldonLeft, A, B,
function);
2341 template <
class T0,
class Prop0,
class Storage0,
class Allocator0,
2342 class T1,
class Prop1,
class Storage1,
class Allocator1>
2348 #ifndef SELDON_WITHOUT_TO_STR_CHECKDIM
2351 string Achar(
"A"), Bchar(
"B");
2354 if (side.Left() && B.GetM() != A.GetN())
2355 throw WrongDim(
function,
string(
"Operation A B not permitted:")
2356 +
string(
"\n A (") + Achar +
string(
") is a ")
2358 +
string(
" matrix;\n B (") + Bchar
2359 +
string(
") is a ") +
to_str(B.GetM()) +
string(
" x ")
2360 +
to_str(B.GetN()) +
string(
" matrix."));
2361 else if (side.Right() && B.GetN() != A.GetM())
2362 throw WrongDim(
function,
string(
"Operation B A not permitted:")
2363 +
string(
"\n A (") + Achar +
string(
") is a ")
2365 +
string(
" matrix;\n B (") + Bchar
2366 +
string(
") is a ") +
to_str(B.GetM()) +
string(
" x ")
2367 +
to_str(B.GetN()) +
string(
" matrix."));
2384 template <
class T,
class Prop,
class Storage,
class Allocator>
2385 typename ClassComplexType<T>::Treal
2388 if (Storage::Sparse)
2389 throw WrongArgument(
"MaxAbs",
"This function is intended to dense"
2390 " matrices only and not to sparse matrices");
2392 typename ClassComplexType<T>::Treal res(0);
2393 for (
int i = 0; i < A.GetM(); i++)
2394 for (
int j = 0; j < A.GetN(); j++)
2406 template <
class T,
class Prop,
class Storage,
class Allocator>
2407 typename ClassComplexType<T>::Treal
2410 if (Storage::Sparse)
2411 throw WrongArgument(
"Norm1",
"This function is intended to dense"
2412 " matrices only and not to sparse matrices");
2414 typename ClassComplexType<T>::Treal res(0), sum;
2415 for (
int j = 0; j < A.GetN(); j++)
2418 for (
int i = 0; i < A.GetM(); i++)
2421 res = max(res, sum);
2433 template <
class T,
class Prop,
class Storage,
class Allocator>
2434 typename ClassComplexType<T>::Treal
2437 if (Storage::Sparse)
2438 throw WrongArgument(
"NormInf",
"This function is intended to dense"
2439 " matrices only and not to sparse matrices");
2441 typename ClassComplexType<T>::Treal res(0), sum;
2442 for (
int i = 0; i < A.GetM(); i++)
2445 for (
int j = 0; j < A.GetN(); j++)
2448 res = max(res, sum);
2460 template <
class T,
class Prop,
class Allocator>
2461 typename ClassComplexType<T>::Treal
2464 typename ClassComplexType<T>::Treal res(0);
2466 for (
long i = 0; i < taille; i++)
2478 template <
class T,
class Prop,
class Allocator>
2479 typename ClassComplexType<T>::Treal
2482 typedef typename ClassComplexType<T>::Treal Treal;
2485 for (
int i = 0; i < A.
GetM(); i++)
2489 return sum.GetNormInf();
2498 template <
class T,
class Prop,
class Allocator>
2499 typename ClassComplexType<T>::Treal
2502 typedef typename ClassComplexType<T>::Treal Treal;
2504 for (
int i = 0; i < A.
GetM(); i++)
2510 res = max(res, sum);
2522 template <
class T,
class Prop,
class Allocator>
2523 typename ClassComplexType<T>::Treal
2526 typename ClassComplexType<T>::Treal res(0);
2528 for (
long i = 0; i < taille; i++)
2540 template <
class T,
class Prop,
class Allocator>
2541 typename ClassComplexType<T>::Treal
2544 typedef typename ClassComplexType<T>::Treal Treal;
2546 for (
int i = 0; i < A.
GetN(); i++)
2552 res = max(res, sum);
2564 template <
class T,
class Prop,
class Allocator>
2565 typename ClassComplexType<T>::Treal
2568 typedef typename ClassComplexType<T>::Treal Treal;
2571 for (
int i = 0; i < A.
GetN(); i++)
2575 return sum.GetNormInf();
2584 template <
class T,
class Prop,
class Allocator>
2585 typename ClassComplexType<T>::Treal
2588 typename ClassComplexType<T>::Treal res(0);
2590 for (
long i = 0; i < taille; i++)
2602 template <
class T,
class Prop,
class Allocator>
2603 typename ClassComplexType<T>::Treal
2606 typedef typename ClassComplexType<T>::Treal Treal;
2609 for (
int i = 0; i < A.
GetM(); i++)
2617 return sum.GetNormInf();
2626 template <
class T,
class Prop,
class Allocator>
2627 typename ClassComplexType<T>::Treal
2639 template <
class T,
class Prop,
class Allocator>
2640 typename ClassComplexType<T>::Treal
2643 typename ClassComplexType<T>::Treal res(0);
2645 for (
long i = 0; i < taille; i++)
2657 template <
class T,
class Prop,
class Allocator>
2658 typename ClassComplexType<T>::Treal
2661 typedef typename ClassComplexType<T>::Treal Treal;
2664 for (
int i = 0; i < A.
GetM(); i++)
2672 return sum.GetNormInf();
2681 template <
class T,
class Prop,
class Allocator>
2682 typename ClassComplexType<T>::Treal
2698 template<
class T,
class Prop,
class Storage,
class Allocator>
2701 if (Storage::Sparse)
2702 throw WrongArgument(
"Transpose",
"This function is intended to dense"
2703 " matrices only and not to sparse matrices");
2712 for (
int i = 0; i < m; i++)
2713 for (
int j = 0; j < i; j++)
2725 for (
int i = 0; i < m; i++)
2726 for (
int j = 0; j < n; j++)
2727 A.Get(j,i) = B(i,j);
2734 template<
class T,
class Prop,
class Storage,
class Allocator>
2738 if (Storage::Sparse)
2739 throw WrongArgument(
"Transpose",
"This function is intended to dense"
2740 " matrices only and not to sparse matrices");
2742 B.Reallocate(A.GetN(), A.GetM());
2743 for (
int i = 0; i < A.GetM(); i++)
2744 for (
int j = 0; j < A.GetN(); j++)
2750 template<
class T,
class Storage,
class Allocator>
2758 template<
class T,
class Storage,
class Allocator>
2767 template<
class T,
class Storage,
class Allocator>
2777 template<
class T,
class Storage,
class Allocator>
2788 template<
class T,
class Allocator>
2795 long nnz = A.GetDataSize();
2800 ptr.SetData(m+1, A.GetPtr());
2801 ind.SetData(nnz, A.GetInd());
2802 data.SetData(nnz, A.GetData());
2810 for (
long i = 0; i < nnz; i++)
2811 ptr_T(ind(i) + 1)++;
2814 for (
int j = 1; j < n + 1; j++)
2815 ptr_T(j) += ptr_T(j - 1);
2819 for (
int i = 0; i < m; i++)
2820 for (
long jp = ptr(i); jp < ptr(i+1); jp++)
2823 long k = ptr_T(j) + row_ind(j);
2825 data_T(k) = data(jp);
2830 for (
int i = 0; i < n; i++)
2831 Sort(ptr_T(i), ptr_T(i+1)-1, ind_T, data_T);
2833 B.SetData(n, m, data_T, ptr_T, ind_T);
2842 template<
class T,
class Allocator>
2851 template<
class T,
class Allocator>
2858 long nnz = A.GetDataSize();
2863 ptr.SetData(n+1, A.GetPtr());
2864 ind.SetData(nnz, A.GetInd());
2865 data.SetData(nnz, A.GetData());
2873 for (
long i = 0; i < nnz; i++)
2874 ptr_T(ind(i) + 1)++;
2877 for (
int j = 1; j < m + 1; j++)
2878 ptr_T(j) += ptr_T(j - 1);
2882 for (
int i = 0; i < n; i++)
2883 for (
long jp = ptr(i); jp < ptr(i+1); jp++)
2886 long k = ptr_T(j) + row_ind(j);
2888 data_T(k) = data(jp);
2893 for (
int i = 0; i < m; i++)
2894 Sort(ptr_T(i), ptr_T(i+1)-1, ind_T, data_T);
2896 B.SetData(n, m, data_T, ptr_T, ind_T);
2905 template<
class T,
class Allocator>
2914 template<
class T,
class Prop,
class Storage,
class Allocator>
2917 long taille = A.GetDataSize();
2918 for (
long i = 0; i < taille; i++)
2919 A.GetData()[i] = conjugate(A.GetData()[i]);
2924 template<
class T,
class Prop,
class Storage,
class Allocator>
2934 template<
class T,
class Prop,
class Storage,
class Allocator>