21 #ifndef SELDON_FILE_HETEROGENEOUS_MATRIX_COLLECTION_CXX
23 #include "HeterogeneousMatrixCollection.hxx"
43 template <
class Prop0,
class Storage0,
44 class Prop1,
class Storage1,
45 template <
class U>
class Allocator>
48 Matrix_Base<double, Allocator<double> >(), Mlocal_(), Mlocal_sum_(1),
49 Nlocal_(), Nlocal_sum_(1), collection_(), float_dense_c_(),
50 float_sparse_c_(), double_dense_c_(), double_sparse_c_()
66 template <
class Prop0,
class Storage0,
67 class Prop1,
class Storage1,
68 template <
class U>
class Allocator>
72 Mlocal_(i), Mlocal_sum_(i + 1),
73 Nlocal_(j), Nlocal_sum_(j + 1), collection_(i, j), float_dense_c_(i, j),
74 float_sparse_c_(i, j), double_dense_c_(i, j), double_sparse_c_(i, j)
88 template <
class Prop0,
class Storage0,
89 class Prop1,
class Storage1,
90 template <
class U>
class Allocator>
void
94 float_dense_c_.Nullify();
95 float_sparse_c_.Nullify();
96 double_dense_c_.Nullify();
97 double_sparse_c_.Nullify();
111 template <
class Prop0,
class Storage0,
112 class Prop1,
class Storage1,
113 template <
class U>
class Allocator>
void
117 float_dense_c_.Nullify();
118 float_sparse_c_.Nullify();
119 double_dense_c_.Nullify();
120 double_sparse_c_.Nullify();
138 template <
class Prop0,
class Storage0,
139 class Prop1,
class Storage1,
140 template <
class U>
class Allocator>
void
144 #ifdef SELDON_CHECK_BOUNDS
145 if (i < 0 || i >= Mmatrix_)
146 throw WrongRow(
"HeterogeneousMatrixCollection::Nullify()",
147 string(
"Index should be in [0, ")
148 +
to_str(Mmatrix_ - 1) +
"], but is equal to "
150 if (j < 0 || j >= Nmatrix_)
151 throw WrongCol(
"HeterogeneousMatrixCollection::Nullify()",
152 string(
"Index should be in [0, ")
153 +
to_str(Nmatrix_ - 1) +
"], but is equal to "
157 switch (collection_(i, j))
160 nz_ -= float_dense_c_.GetMatrix(i, j).GetDataSize();
161 float_dense_c_.Nullify(i, j);
163 nz_ -= float_sparse_c_.GetMatrix(i, j).GetDataSize();
164 float_sparse_c_.Nullify(i, j);
167 nz_ -= double_dense_c_.GetMatrix(i, j).GetDataSize();
168 double_dense_c_.Nullify(i, j);
171 nz_ -= double_sparse_c_.GetMatrix(i, j).GetDataSize();
172 double_sparse_c_.Nullify(i, j);
176 collection_(i, j) = -1;
181 template <
class Prop0,
class Storage0,
182 class Prop1,
class Storage1,
183 template <
class U>
class Allocator>
void
187 float_dense_c_.Deallocate();
188 float_sparse_c_.Deallocate();
189 double_dense_c_.Deallocate();
190 double_sparse_c_.Deallocate();
207 template <
class Prop0,
class Storage0,
208 class Prop1,
class Storage1,
209 template <
class U>
class Allocator>
void
216 Mlocal_.Reallocate(i);
217 Nlocal_.Reallocate(j);
218 Mlocal_sum_.Reallocate(i + 1);
219 Nlocal_sum_.Reallocate(j + 1);
225 collection_.Reallocate(i, j);
226 float_dense_c_.Reallocate(i, j);
227 float_sparse_c_.Reallocate(i, j);
228 double_dense_c_.Reallocate(i, j);
229 double_sparse_c_.Reallocate(i, j);
239 template <
class Prop0,
class Storage0,
240 class Prop1,
class Storage1,
241 template <
class U>
class Allocator>
void
244 Prop0, Storage0, Prop1, Storage1, Allocator>::float_dense_m& A)
246 #ifdef SELDON_CHECK_BOUNDS
247 if (i < 0 || i >= Mmatrix_)
248 throw WrongRow(
"HeterogeneousMatrixCollection::"
249 "SetMatrix(float_dense_m)",
250 string(
"Index should be in [0, ")
251 +
to_str(Mmatrix_ - 1) +
"], but is equal to "
253 if (j < 0 || j >= Nmatrix_)
254 throw WrongCol(
"HeterogeneousMatrixCollection::"
255 "SetMatrix(float_dense_m)",
256 string(
"Index should be in [0, ")
257 +
to_str(Nmatrix_ - 1) +
"], but is equal to "
259 if ((Mlocal_(i) != 0) && (Mlocal_(i) != A.GetM()))
260 throw WrongDim(
"HeterogeneousMatrixCollection::"
261 "SetMatrix(float_dense_m)",
262 string(
"The matrix expected should have ")
263 +
to_str(this->Mlocal_(i)) +
" lines, but has "
264 +
to_str(A.GetM()) +
" lines.");
265 if ((Nlocal_(j) != 0) && (Nlocal_(j) != A.GetN()))
266 throw WrongDim(
"HeterogeneousMatrixCollection::"
267 "SetMatrix(float_dense_m)",
268 string(
"The matrix expected should have ")
269 +
to_str(this->Nlocal_(j)) +
" columns, but has "
270 +
to_str(A.GetN()) +
" columns.");
275 collection_(i, j) = 0;
277 int Mdiff = A.GetM() - Mlocal_(i);
278 int Ndiff = A.GetN() - Nlocal_(j);
280 Mlocal_(i) = A.GetM();
281 Nlocal_(j) = A.GetN();
283 for (
int k = i + 1; k < Mmatrix_ + 1; k++)
284 Mlocal_sum_(k) += Mdiff;
286 for (
int k = j + 1; k < Nmatrix_ + 1; k++)
287 Nlocal_sum_(k) += Ndiff;
289 this->m_ = Mlocal_sum_(Mmatrix_);
290 this->n_ = Nlocal_sum_(Nmatrix_);
292 float_dense_c_.SetMatrix(i, j, A);
302 template <
class Prop0,
class Storage0,
303 class Prop1,
class Storage1,
304 template <
class U>
class Allocator>
void
305 HeterogeneousMatrixCollection<Prop0, Storage0, Prop1, Storage1, Allocator>
306 ::SetMatrix(
int i,
int j,
const typename HeterogeneousMatrixCollection<
307 Prop0, Storage0, Prop1, Storage1, Allocator>::float_sparse_m& A)
309 #ifdef SELDON_CHECK_BOUNDS
310 if (i < 0 || i >= Mmatrix_)
311 throw WrongRow(
"HeterogeneousMatrixCollection::"
312 "SetMatrix(float_sparse_m)",
313 string(
"Index should be in [0, ")
314 +
to_str(Mmatrix_ - 1) +
"], but is equal to "
316 if (j < 0 || j >= Nmatrix_)
317 throw WrongCol(
"HeterogeneousMatrixCollection::"
318 "SetMatrix(float_sparse_m)",
319 string(
"Index should be in [0, ")
320 +
to_str(Nmatrix_ - 1) +
"], but is equal to "
322 if ((Mlocal_(i) != 0) && (Mlocal_(i) != A.GetM()))
323 throw WrongDim(
"HeterogeneousMatrixCollection::"
324 "SetMatrix(float_sparse_m)",
325 string(
"The matrix expected should have ")
326 +
to_str(this->Mlocal_(i)) +
" lines, but has "
327 +
to_str(A.GetM()) +
" lines.");
328 if ((Nlocal_(j) != 0) && (Nlocal_(j) != A.GetN()))
329 throw WrongDim(
"HeterogeneousMatrixCollection::"
330 "SetMatrix(float_sparse_m)",
331 string(
"The matrix expected should have ")
332 +
to_str(this->Nlocal_(j)) +
" columns, but has "
333 +
to_str(A.GetN()) +
" columns.");
338 collection_(i, j) = 1;
340 int Mdiff = A.GetM() - Mlocal_(i);
341 int Ndiff = A.GetN() - Nlocal_(j);
343 Mlocal_(i) = A.GetM();
344 Nlocal_(j) = A.GetN();
346 for (
int k = i + 1; k < Mmatrix_ + 1; k++)
347 Mlocal_sum_(k) += Mdiff;
349 for (
int k = j + 1; k < Nmatrix_ + 1; k++)
350 Nlocal_sum_(k) += Ndiff;
352 this->m_ = Mlocal_sum_(Mmatrix_);
353 this->n_ = Nlocal_sum_(Nmatrix_);
355 float_sparse_c_.SetMatrix(i, j, A);
365 template <
class Prop0,
class Storage0,
366 class Prop1,
class Storage1,
367 template <
class U>
class Allocator>
void
368 HeterogeneousMatrixCollection<Prop0, Storage0, Prop1, Storage1, Allocator>
369 ::SetMatrix(
int i,
int j,
const typename HeterogeneousMatrixCollection<
370 Prop0, Storage0, Prop1, Storage1, Allocator>::double_dense_m& A)
372 #ifdef SELDON_CHECK_BOUNDS
373 if (i < 0 || i >= Mmatrix_)
374 throw WrongRow(
"HeterogeneousMatrixCollection::"
375 "SetMatrix(double_dense_m)",
376 string(
"Index should be in [0, ")
377 +
to_str(Mmatrix_ - 1) +
"], but is equal to "
379 if (j < 0 || j >= Nmatrix_)
380 throw WrongCol(
"HeterogeneousMatrixCollection::"
381 "SetMatrix(double_dense_m)",
382 string(
"Index should be in [0, ")
383 +
to_str(Nmatrix_ - 1) +
"], but is equal to "
385 if ((Mlocal_(i) != 0) && (Mlocal_(i) != A.GetM()))
386 throw WrongDim(
"HeterogeneousMatrixCollection::"
387 "SetMatrix(double_dense_m)",
388 string(
"The matrix expected should have ")
389 +
to_str(this->Mlocal_(i)) +
" lines, but has "
390 +
to_str(A.GetM()) +
" lines.");
391 if ((Nlocal_(j) != 0) && (Nlocal_(j) != A.GetN()))
392 throw WrongDim(
"HeterogeneousMatrixCollection::"
393 "SetMatrix(double_dense_m)",
394 string(
"The matrix expected should have ")
395 +
to_str(this->Nlocal_(j)) +
" columns, but has "
396 +
to_str(A.GetN()) +
" columns.");
401 collection_(i, j) = 2;
403 int Mdiff = A.GetM() - Mlocal_(i);
404 int Ndiff = A.GetN() - Nlocal_(j);
406 Mlocal_(i) = A.GetM();
407 Nlocal_(j) = A.GetN();
409 for (
int k = i + 1; k < Mmatrix_ + 1; k++)
410 Mlocal_sum_(k) += Mdiff;
412 for (
int k = j + 1; k < Nmatrix_ + 1; k++)
413 Nlocal_sum_(k) += Ndiff;
415 this->m_ = Mlocal_sum_(Mmatrix_);
416 this->n_ = Nlocal_sum_(Nmatrix_);
418 double_dense_c_.SetMatrix(i, j, A);
428 template <
class Prop0,
class Storage0,
429 class Prop1,
class Storage1,
430 template <
class U>
class Allocator>
void
431 HeterogeneousMatrixCollection<Prop0, Storage0, Prop1, Storage1, Allocator>
432 ::SetMatrix(
int i,
int j,
433 const typename HeterogeneousMatrixCollection< Prop0, Storage0,
434 Prop1, Storage1, Allocator>::double_sparse_m& A)
436 #ifdef SELDON_CHECK_BOUNDS
437 if (i < 0 || i >= Mmatrix_)
438 throw WrongRow(
"HeterogeneousMatrixCollection::"
439 "SetMatrix(double_sparse_m)",
440 string(
"Index should be in [0, ")
441 +
to_str(Mmatrix_ - 1) +
"], but is equal to "
443 if (j < 0 || j >= Nmatrix_)
444 throw WrongCol(
"HeterogeneousMatrixCollection::"
445 "SetMatrix(double_sparse_m)",
446 string(
"Index should be in [0, ")
447 +
to_str(Nmatrix_ - 1) +
"], but is equal to "
449 if ((Mlocal_(i) != 0) && (Mlocal_(i) != A.GetM()))
450 throw WrongDim(
"HeterogeneousMatrixCollection::"
451 "SetMatrix(double_sparse_m)",
452 string(
"The matrix expected should have ")
453 +
to_str(this->Mlocal_(i)) +
" lines, but has "
454 +
to_str(A.GetM()) +
" lines.");
455 if ((Nlocal_(j) != 0) && (Nlocal_(j) != A.GetN()))
456 throw WrongDim(
"HeterogeneousMatrixCollection::"
457 "SetMatrix(double_sparse_m)",
458 string(
"The matrix expected should have ")
459 +
to_str(this->Nlocal_(j)) +
" columns, but has "
460 +
to_str(A.GetN()) +
" columns.");
465 collection_(i, j) = 3;
467 int Mdiff = A.GetM() - Mlocal_(i);
468 int Ndiff = A.GetN() - Nlocal_(j);
470 Mlocal_(i) = A.GetM();
471 Nlocal_(j) = A.GetN();
473 for (
int k = i + 1; k < Mmatrix_ + 1; k++)
474 Mlocal_sum_(k) += Mdiff;
476 for (
int k = j + 1; k < Nmatrix_ + 1; k++)
477 Nlocal_sum_(k) += Ndiff;
479 this->m_ = Mlocal_sum_(Mmatrix_);
480 this->n_ = Nlocal_sum_(Nmatrix_);
482 double_sparse_c_.SetMatrix(i, j, A);
498 template <
class Prop0,
class Storage0,
499 class Prop1,
class Storage1,
500 template <
class U>
class Allocator>
void
501 HeterogeneousMatrixCollection<Prop0, Storage0, Prop1, Storage1, Allocator>
502 ::GetMatrix(
int i,
int j,
typename HeterogeneousMatrixCollection<
503 Prop0, Storage0, Prop1, Storage1, Allocator>::float_dense_m& M)
506 #ifdef SELDON_CHECK_BOUNDS
507 if (i < 0 || i >= Mmatrix_)
508 throw WrongRow(
"HeterogeneousMatrixCollection::"
509 "GetMatrix(float_dense_m)",
510 string(
"Row index should be in [0, ")
511 +
to_str(Mmatrix_ - 1) +
"], but is equal to "
513 if (j < 0 || j >= Nmatrix_)
514 throw WrongCol(
"HeterogeneousMatrixCollection::"
515 "GetMatrix(float_dense_m)",
516 string(
"Column index should be in [0, ")
517 +
to_str(Nmatrix_ - 1) +
"], but is equal to "
521 if (collection_(i, j) != 0)
524 switch(collection_(i, j))
527 matrix_type =
"float_sparse";
530 matrix_type =
"double_dense";
533 matrix_type =
"double_sparse";
537 WrongArgument(
"HeterogeneousMatrixCollection::GetMatrix(i, j,"
538 "Matrix<Float, Dense> M)",
539 "Underlying matrix (" +
to_str(i) +
" ,"
540 +
to_str(j) +
" ) not defined.");
543 throw WrongArgument(
"HeterogeneousMatrixCollection::GetMatrix(i, j, "
544 "Matrix<Float, Dense> M)",
545 string(
"Wrong type for matrix ")
546 + matrix_type +
" M.");
549 M.SetData(Mlocal_(i), Nlocal_(j),
550 float_dense_c_.GetMatrix(i, j).GetData());
561 template <
class Prop0,
class Storage0,
562 class Prop1,
class Storage1,
563 template <
class U>
class Allocator>
void
564 HeterogeneousMatrixCollection<Prop0, Storage0, Prop1, Storage1, Allocator>
565 ::GetMatrix(
int i,
int j,
typename HeterogeneousMatrixCollection<
566 Prop0, Storage0, Prop1, Storage1, Allocator>::float_sparse_m& M)
569 #ifdef SELDON_CHECK_BOUNDS
570 if (i < 0 || i >= Mmatrix_)
571 throw WrongRow(
"HeterogeneousMatrixCollection::"
572 "GetMatrix(float_sparse_m)",
573 string(
"Row index should be in [0, ")
574 +
to_str(Mmatrix_ - 1) +
"], but is equal to "
576 if (j < 0 || j >= Nmatrix_)
577 throw WrongCol(
"HeterogeneousMatrixCollection::"
578 "GetMatrix(float_sparse_m)",
579 string(
"Column index should be in [0, ")
580 +
to_str(Nmatrix_ - 1) +
"], but is equal to "
584 if (collection_(i, j) != 1)
587 switch(collection_(i, j))
590 matrix_type =
"float_dense";
593 matrix_type =
"double_dense";
596 matrix_type =
"double_sparse";
600 WrongArgument(
"HeterogeneousMatrixCollection::GetMatrix(i, j, "
601 "Matrix<Float, Sparse> M)",
602 "Underlying matrix (" +
to_str(i) +
" ,"
603 +
to_str(j) +
" ) not defined.");
606 throw WrongArgument(
"HeterogeneousMatrixCollection::GetMatrix(i, j, "
607 "Matrix<Float, Sparse> M)",
608 string(
"Wrong type for matrix ")
609 + matrix_type +
" M.");
612 M.SetData(float_sparse_c_.GetMatrix(i, j).GetM(),
613 float_sparse_c_.GetMatrix(i, j).GetN(),
614 float_sparse_c_.GetMatrix(i, j).GetNonZeros(),
615 float_sparse_c_.GetMatrix(i, j).GetData(),
616 float_sparse_c_.GetMatrix(i, j).GetPtr(),
617 float_sparse_c_.GetMatrix(i, j).GetInd());
628 template <
class Prop0,
class Storage0,
629 class Prop1,
class Storage1,
630 template <
class U>
class Allocator>
void
631 HeterogeneousMatrixCollection<Prop0, Storage0, Prop1, Storage1, Allocator>
632 ::GetMatrix(
int i,
int j,
typename HeterogeneousMatrixCollection<
633 Prop0, Storage0, Prop1, Storage1, Allocator>::double_dense_m& M)
636 #ifdef SELDON_CHECK_BOUNDS
637 if (i < 0 || i >= Mmatrix_)
638 throw WrongRow(
"HeterogeneousMatrixCollection::"
639 "GetMatrix(double_dense_m)",
640 string(
"Row index should be in [0, ")
641 +
to_str(Mmatrix_ - 1) +
"], but is equal to "
643 if (j < 0 || j >= Nmatrix_)
644 throw WrongCol(
"HeterogeneousMatrixCollection::"
645 "GetMatrix(double_dense_m)",
646 string(
"Column index should be in [0, ")
647 +
to_str(Nmatrix_ - 1) +
"], but is equal to "
651 if (collection_(i, j) != 2)
654 switch(collection_(i, j))
657 matrix_type =
"float_dense";
660 matrix_type =
"float_sparse";
663 matrix_type =
"double_sparse";
667 WrongArgument(
"HeterogeneousMatrixCollection::GetMatrix(i, j, "
668 "Matrix<Double, Dense> M)",
669 "Underlying matrix (" +
to_str(i) +
" ,"
670 +
to_str(j) +
" ) not defined.");
673 throw WrongArgument(
"HeterogeneousMatrixCollection::GetMatrix(i, j, "
674 "Matrix<Double, Dense> M)",
675 string(
"Wrong type for matrix ")
676 + matrix_type +
" M.");
679 M.SetData(Mlocal_(i), Nlocal_(j),
680 double_dense_c_.GetMatrix(i, j).GetData());
691 template <
class Prop0,
class Storage0,
692 class Prop1,
class Storage1,
693 template <
class U>
class Allocator>
void
694 HeterogeneousMatrixCollection<Prop0, Storage0, Prop1, Storage1, Allocator>
695 ::GetMatrix(
int i,
int j,
typename HeterogeneousMatrixCollection<Prop0,
696 Storage0, Prop1, Storage1, Allocator>::double_sparse_m& M)
699 #ifdef SELDON_CHECK_BOUNDS
700 if (i < 0 || i >= Mmatrix_)
701 throw WrongRow(
"HeterogeneousMatrixCollection::"
702 "GetMatrix(double_sparse_m)",
703 string(
"Row index should be in [0, ")
704 +
to_str(Mmatrix_ - 1) +
"], but is equal to "
706 if (j < 0 || j >= Nmatrix_)
707 throw WrongCol(
"HeterogeneousMatrixCollection::"
708 "GetMatrix(double_sparse_m)",
709 string(
"Column index should be in [0, ")
710 +
to_str(Nmatrix_ - 1) +
"], but is equal to "
714 if (collection_(i, j) != 3)
717 switch(collection_(i, j))
720 matrix_type =
"float_dense";
723 matrix_type =
"float_sparse";
726 matrix_type =
"double_dense";
730 WrongArgument(
"HeterogeneousMatrixCollection::GetMatrix(i, j,"
731 "Matrix<Double, Sparse> M)",
732 "Underlying matrix (" +
to_str(i) +
" ,"
733 +
to_str(j) +
" ) not defined.");
736 throw WrongArgument(
"HeterogeneousMatrixCollection::GetMatrix(i, j,"
737 "Matrix<Double, Sparse> M)",
738 string(
"Wrong type for matrix ")
739 + matrix_type +
" M.");
743 M.SetData(double_sparse_c_.GetMatrix(i, j).GetM(),
744 double_sparse_c_.GetMatrix(i, j).GetN(),
745 double_sparse_c_.GetMatrix(i, j).GetNonZeros(),
746 double_sparse_c_.GetMatrix(i, j).GetData(),
747 double_sparse_c_.GetMatrix(i, j).GetPtr(),
748 double_sparse_c_.GetMatrix(i, j).GetInd());
759 template <
class Prop0,
class Storage0,
760 class Prop1,
class Storage1,
761 template <
class U>
class Allocator>
762 double HeterogeneousMatrixCollection<Prop0, Storage0,
763 Prop1, Storage1, Allocator>
764 ::operator() (
int i,
int j)
const
767 #ifdef SELDON_CHECK_BOUNDS
768 if (i < 0 || i >= this->Mlocal_sum_(Mmatrix_))
769 throw WrongRow(
"HeterogeneousMatrixCollection::operator()",
770 string(
"Index should be in [0, ")
771 +
to_str(this->Mlocal_sum_(Mmatrix_) - 1)
772 +
"], but is equal to "
774 if (j < 0 || j >= this->Nlocal_sum_(Nmatrix_))
775 throw WrongCol(
"HeterogeneousMatrixCollection::operator()",
776 string(
"Index should be in [0, ")
777 +
to_str(this->Nlocal_sum_(Nmatrix_) - 1)
778 +
"], but is equal to "
783 while (i >= Mlocal_sum_(i_global))
788 while (j >= Nlocal_sum_(j_global))
793 switch(collection_(i_global, j_global))
796 res = double(float_dense_c_.GetMatrix(i_global, j_global)
797 (i - Mlocal_sum_(i_global), j - Nlocal_sum_(j_global)));
800 res = double(float_sparse_c_.GetMatrix(i_global, j_global)
801 (i - Mlocal_sum_(i_global), j - Nlocal_sum_(j_global)));
804 res = double_dense_c_.GetMatrix(i_global, j_global)
805 (i - Mlocal_sum_(i_global), j - Nlocal_sum_(j_global));
808 res = double_sparse_c_.GetMatrix(i_global, j_global)
809 (i - Mlocal_sum_(i_global), j - Nlocal_sum_(j_global));
813 WrongArgument(
"HeterogeneousMatrixCollection::operator(int, int)",
814 "Underlying matrix (" +
to_str(i) +
" ,"
815 +
to_str(j) +
" ) not defined.");
827 template <
class Prop0,
class Storage0,
828 class Prop1,
class Storage1,
829 template <
class U>
class Allocator>
833 Prop1, Storage1, Allocator>& A)
846 template <
class Prop0,
class Storage0,
847 class Prop1,
class Storage1,
848 template <
class U>
class Allocator>
851 Storage1, Allocator>& A)
855 Mmatrix_ = A.Mmatrix_;
856 Nmatrix_ = A.Nmatrix_;
860 this->Mlocal_ = A.Mlocal_;
861 this->Mlocal_sum_ = A.Mlocal_sum_;
862 this->Nlocal_ = A.Nlocal_;
863 this->Nlocal_sum_ = A.Nlocal_sum_;
865 collection_.Copy(A.collection_);
867 float_dense_c_.Reallocate(Mmatrix_, Nmatrix_);
868 float_sparse_c_.Reallocate(Mmatrix_, Nmatrix_);
869 double_dense_c_.Reallocate(Mmatrix_, Nmatrix_);
870 double_sparse_c_.Reallocate(Mmatrix_, Nmatrix_);
877 for (
int i = 0; i < Mmatrix_; i++ )
878 for (
int j = 0; j < Nmatrix_; j++)
880 switch (A.GetType(i, j))
883 A.GetMatrix(i, j, m0a);
884 SetMatrix(i, j, m0a);
888 A.GetMatrix(i, j, m1a);
889 SetMatrix(i, j, m1a);
893 A.GetMatrix(i, j, m2a);
894 SetMatrix(i, j, m2a);
898 A.GetMatrix(i, j, m3a);
899 SetMatrix(i, j, m3a);
903 throw WrongArgument(
"Matrix<FloatDouble, DenseSparseCollection>"
904 "::MltAdd(alpha, A, B, beta, C) ",
905 "Underlying matrix C (" +
to_str(i) +
" ,"
906 +
to_str(j) +
" ) not defined.");
921 template <
class Prop0,
class Storage0,
922 class Prop1,
class Storage1,
923 template <
class U>
class Allocator>
void
927 for (
int i = 0; i < Mlocal_sum_(Mmatrix_); i++)
929 for (
int j = 0; j < Nlocal_sum_(Nmatrix_); j++)
930 cout << (*
this)(i, j) << endl;
945 template <
class Prop0,
class Storage0,
946 class Prop1,
class Storage1,
947 template <
class U>
class Allocator>
void
949 ::Write(
string FileName,
bool with_size)
const
952 FileStream.open(FileName.c_str(), ofstream::binary);
954 #ifdef SELDON_CHECK_IO
956 if (!FileStream.is_open())
957 throw IOError(
"Matrix_Pointers::Write(string FileName)",
958 string(
"Unable to open file \"") + FileName +
"\".");
961 this->Write(FileStream, with_size);
976 template <
class Prop0,
class Storage0,
977 class Prop1,
class Storage1,
978 template <
class U>
class Allocator>
void
980 ::Write(ostream& FileStream,
bool with_size =
true)
const
983 #ifdef SELDON_CHECK_IO
985 if (!FileStream.good())
986 throw IOError(
"HeterogeneousMatrixCollection"
987 "::Write(ostream& FileStream)",
988 "The stream is not ready.");
993 FileStream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&Mmatrix_)),
995 FileStream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&Nmatrix_)),
999 collection_.Write(FileStream, with_size);
1007 for (i = 0; i < Mmatrix_; i++)
1008 for (j = 0; j < Nmatrix_; j++)
1010 switch (GetType(i, j))
1013 GetMatrix(i, j, m0a);
1014 m0a.Write(FileStream, with_size);
1018 throw Undefined(
"Matrix<FloatDouble, DenseSparseCollection>"
1019 "Storage0, Prop1, Storage1, Allocator>"
1020 "::Write(ostream& FileStream, bool "
1021 "with_size = true) ");
1023 GetMatrix(i, j, m2a);
1024 m2a.Write(FileStream, with_size);
1028 throw Undefined(
"Matrix<FloatDouble, DenseSparseCollection>"
1029 "Storage0, Prop1, Storage1, Allocator>"
1030 "::Write(ostream& FileStream, bool "
1031 "with_size = true) ");
1033 throw WrongArgument(
"Matrix<FloatDouble, DenseSparseCollection>"
1034 "::Write(ostream& FileStream, "
1035 "bool with_size = true) ",
1036 "Underlying matrix A (" +
to_str(i) +
" ,"
1037 +
to_str(j) +
" ) not defined.");
1042 #ifdef SELDON_CHECK_IO
1044 if (!FileStream.good())
1045 throw IOError(
"HeterogeneousMatrixCollection"
1046 "::Write(ostream& FileStream)",
1047 "Output operation failed.");
1059 template <
class Prop0,
class Storage0,
1060 class Prop1,
class Storage1,
1061 template <
class U>
class Allocator>
void
1065 ofstream FileStream;
1066 FileStream.precision(cout.precision());
1067 FileStream.flags(cout.flags());
1068 FileStream.open(FileName.c_str());
1070 #ifdef SELDON_CHECK_IO
1072 if (!FileStream.is_open())
1073 throw IOError(
"HeterogeneousMatrixCollection"
1074 "::WriteText(string FileName)",
1075 string(
"Unable to open file \"") + FileName +
"\".");
1078 this->WriteText(FileStream);
1091 template <
class Prop0,
class Storage0,
1092 class Prop1,
class Storage1,
1093 template <
class U>
class Allocator>
void
1098 #ifdef SELDON_CHECK_IO
1100 if (!FileStream.good())
1101 throw IOError(
"HeterogeneousMatrixCollection"
1102 "::WriteText(ostream& FileStream)",
1103 "The stream is not ready.");
1112 for (i = 0; i < Mmatrix_; i++)
1113 for (j = 0; j < Nmatrix_; j++)
1115 switch (GetType(i, j))
1118 GetMatrix(i, j, m0a);
1119 m0a.WriteText(FileStream);
1123 GetMatrix(i, j, m1a);
1124 m1a.WriteText(FileStream);
1128 GetMatrix(i, j, m2a);
1129 m2a.WriteText(FileStream);
1133 GetMatrix(i, j, m3a);
1134 m3a.WriteText(FileStream);
1138 throw WrongArgument(
"Matrix<FloatDouble, DenseSparseCollection>"
1139 "::Write(ostream& FileStream, "
1140 "bool with_size = true) ",
1141 "Underlying matrix A (" +
to_str(i) +
" ,"
1142 +
to_str(j) +
" ) not defined.");
1147 #ifdef SELDON_CHECK_IO
1149 if (!FileStream.good())
1150 throw IOError(
"HeterogeneousMatrixCollection"
1151 "::WriteText(ostream& FileStream)",
1152 "Output operation failed.");
1165 template <
class Prop0,
class Storage0,
1166 class Prop1,
class Storage1,
1167 template <
class U>
class Allocator>
void
1171 ifstream FileStream;
1172 FileStream.open(FileName.c_str(), ifstream::binary);
1174 #ifdef SELDON_CHECK_IO
1176 if (!FileStream.is_open())
1177 throw IOError(
"HeterogeneousMatrixCollection<Prop0, Storage0, Prop1,"
1178 " Storage1, Allocator>::Read(string FileName)",
1179 string(
"Unable to open file \"") + FileName +
"\".");
1182 this->Read(FileStream);
1195 template <
class Prop0,
class Storage0,
1196 class Prop1,
class Storage1,
1197 template <
class U>
class Allocator>
void
1202 #ifdef SELDON_CHECK_IO
1204 if (!FileStream.good())
1205 throw IOError(
"HeterogeneousMatrixCollection<Prop0, Storage0, Prop1,"
1206 " Storage1, Allocator>::Read(istream& FileStream)",
1207 "The stream is not ready.");
1214 FileStream.read(
reinterpret_cast<char*
>(new_m),
sizeof(
int));
1215 FileStream.read(
reinterpret_cast<char*
>(new_n),
sizeof(
int));
1217 this->Reallocate(*new_m, *new_n);
1219 collection_.Read(FileStream);
1226 for (i = 0; i < Mmatrix_; i++)
1227 for (j = 0; j < Nmatrix_; j++)
1229 switch (GetType(i, j))
1232 m0a.Read(FileStream);
1233 SetMatrix(i, j, m0a);
1237 throw Undefined(
"Matrix<FloatDouble, DenseSparseCollection>"
1238 "Storage0, Prop1, Storage1, Allocator>"
1239 "::Read(istream& FileStream)");
1241 m2a.Read(FileStream);
1242 SetMatrix(i, j, m2a);
1246 throw Undefined(
"Matrix<FloatDouble, DenseSparseCollection>"
1247 "Storage0, Prop1, Storage1, Allocator>"
1248 "::Read(istream& FileStream)");
1252 "Storage0, Prop1, Storage1, Allocator>"
1253 "::Read(istream& FileStream) ",
1254 "Underlying matrix A (" +
to_str(i) +
" ,"
1255 +
to_str(j) +
" ) not defined.");
1263 #ifdef SELDON_CHECK_IO
1265 if (!FileStream.good())
1266 throw IOError(
"HeterogeneousMatrixCollection"
1267 "::Read(istream& FileStream)",
1268 "Input operation failed.");
1275 #define SELDON_FILE_MATRIX_HETEROGENEOUS_COLLECTION_CXX