Warning: this documentation for the development version is under construction.
00001 // Copyright (C) 2010 INRIA 00002 // Author(s): Marc Fragu 00003 // 00004 // This file is part of the linear-algebra library Seldon, 00005 // http://seldon.sourceforge.net/. 00006 // 00007 // Seldon is free software; you can redistribute it and/or modify it under the 00008 // terms of the GNU Lesser General Public License as published by the Free 00009 // Software Foundation; either version 2.1 of the License, or (at your option) 00010 // any later version. 00011 // 00012 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY 00013 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00014 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 00015 // more details. 00016 // 00017 // You should have received a copy of the GNU Lesser General Public License 00018 // along with Seldon. If not, see http://www.gnu.org/licenses/. 00019 00020 00021 #ifndef SELDON_FILE_MATRIX_COLLECTION_CXX 00022 00023 #include "MatrixCollection.hxx" 00024 00025 00026 namespace Seldon 00027 { 00028 00029 00031 // MATRIXCOLLECTION // 00033 00034 00035 /**************** 00036 * CONSTRUCTORS * 00037 ****************/ 00038 00039 00041 00044 template <class T, class Prop, class Storage, class Allocator> 00045 inline MatrixCollection<T, Prop, Storage, Allocator>::MatrixCollection(): 00046 Matrix_Base<T, Allocator>(), Mlocal_(), Mlocal_sum_(1), 00047 Nlocal_(), Nlocal_sum_(1), matrix_() 00048 { 00049 nz_ = 0; 00050 Mmatrix_ = 0; 00051 Nmatrix_ = 0; 00052 Mlocal_sum_.Fill(0); 00053 Nlocal_sum_.Fill(0); 00054 } 00055 00056 00058 00062 template <class T, class Prop, class Storage, class Allocator> 00063 inline MatrixCollection<T, Prop, Storage, Allocator> 00064 ::MatrixCollection(int i, int j): Matrix_Base<T, Allocator>(i, j), 00065 Mlocal_(i), Mlocal_sum_(i + 1), 00066 Nlocal_(j), Nlocal_sum_(j + 1), 00067 matrix_(i, j) 00068 { 00069 nz_ = 0; 00070 Mmatrix_ = i; 00071 Nmatrix_ = j; 00072 Mlocal_.Fill(0); 00073 Nlocal_.Fill(0); 00074 Mlocal_sum_.Fill(0); 00075 Nlocal_sum_.Fill(0); 00076 } 00077 00078 00080 template <class T, class Prop, class Storage, class Allocator> 00081 inline MatrixCollection<T, Prop, Storage, Allocator> 00082 ::MatrixCollection(const MatrixCollection<T, Prop, Storage, Allocator>& A) 00083 : Matrix_Base<T, Allocator>() 00084 { 00085 this->Copy(A); 00086 } 00087 00088 00089 /************** 00090 * DESTRUCTOR * 00091 **************/ 00092 00093 00095 template <class T, class Prop, class Storage, class Allocator> 00096 inline MatrixCollection<T, Prop, Storage, Allocator>::~MatrixCollection() 00097 { 00098 Clear(); 00099 } 00100 00101 00103 00107 template <class T, class Prop, class Storage, class Allocator> 00108 inline void MatrixCollection<T, Prop, Storage, Allocator>::Clear() 00109 { 00110 for (int i = 0; i < Mmatrix_; i++) 00111 for (int j = 0; j < Nmatrix_; j++) 00112 matrix_(i, j).Nullify(); 00113 00114 matrix_.Clear(); 00115 00116 nz_ = 0; 00117 Mmatrix_ = 0; 00118 Nmatrix_ = 0; 00119 Mlocal_.Clear(); 00120 Nlocal_.Clear(); 00121 Mlocal_sum_.Clear(); 00122 Nlocal_sum_.Clear(); 00123 } 00124 00125 00127 00131 template <class T, class Prop, class Storage, class Allocator> 00132 inline void MatrixCollection<T, Prop, Storage, Allocator>::Nullify() 00133 { 00134 for (int i = 0; i < Mmatrix_; i++) 00135 for (int j = 0; j < Nmatrix_; j++) 00136 matrix_(i, j).Nullify(); 00137 00138 nz_ = 0; 00139 Mmatrix_ = 0; 00140 Nmatrix_ = 0; 00141 Mlocal_.Clear(); 00142 Nlocal_.Clear(); 00143 Mlocal_sum_.Clear(); 00144 Nlocal_sum_.Clear(); 00145 } 00146 00147 00149 00153 template <class T, class Prop, class Storage, class Allocator> 00154 inline void MatrixCollection<T, Prop, Storage, Allocator> 00155 ::Nullify(int i, int j) 00156 { 00157 nz_ -= matrix_(i, j).GetDataSize(); 00158 matrix_(i, j).Nullify(); 00159 } 00160 00161 00163 template <class T, class Prop, class Storage, class Allocator> 00164 inline void MatrixCollection<T, Prop, Storage, Allocator>::Deallocate() 00165 { 00166 for (int i = 0; i < Mmatrix_; i++) 00167 for (int j = 0; j < Nmatrix_; j++) 00168 GetMatrix(i, j).Clear(); 00169 this->~MatrixCollection(); 00170 } 00171 00172 00173 /******************* 00174 * BASIC FUNCTIONS * 00175 *******************/ 00176 00177 00179 00183 template <class T, class Prop, class Storage, class Allocator> 00184 int MatrixCollection<T, Prop, Storage, Allocator>::GetM() const 00185 { 00186 return this->m_; 00187 } 00188 00189 00191 00195 template <class T, class Prop, class Storage, class Allocator> 00196 int MatrixCollection<T, Prop, Storage, Allocator>::GetMmatrix() const 00197 { 00198 return Mmatrix_; 00199 } 00200 00201 00203 00207 template <class T, class Prop, class Storage, class Allocator> 00208 int MatrixCollection<T, Prop, Storage, Allocator>::GetM(int i) const 00209 { 00210 #ifdef SELDON_CHECK_BOUNDS 00211 if (i < 0 || i >= Mmatrix_) 00212 throw WrongRow("MatrixCollection::GetM()", 00213 string("Index should be in [0, ") 00214 + to_str(Mmatrix_ - 1) + "], but is equal to " 00215 + to_str(i) + "."); 00216 #endif 00217 00218 return Mlocal_(i); 00219 } 00220 00221 00223 00227 template <class T, class Prop, class Storage, class Allocator> 00228 int MatrixCollection<T, Prop, Storage, Allocator>::GetN() const 00229 { 00230 return this->n_; 00231 } 00232 00233 00235 00239 template <class T, class Prop, class Storage, class Allocator> 00240 int MatrixCollection<T, Prop, Storage, Allocator>::GetNmatrix() const 00241 { 00242 return Nmatrix_; 00243 } 00244 00245 00247 00252 template <class T, class Prop, class Storage, class Allocator> 00253 int MatrixCollection<T, Prop, Storage, Allocator>::GetN(int j) const 00254 { 00255 #ifdef SELDON_CHECK_BOUNDS 00256 if (j < 0 || j >= Nmatrix_) 00257 throw WrongCol("MatrixCollection::GetN()", 00258 string("Index should be in [0, ") 00259 + to_str(Nmatrix_ - 1) + "], but is equal to " 00260 + to_str(j) + "."); 00261 #endif 00262 00263 return Nlocal_(j); 00264 } 00265 00266 00268 00271 template <class T, class Prop, class Storage, class Allocator> 00272 int MatrixCollection<T, Prop, Storage, Allocator>::GetSize() const 00273 { 00274 return this->m_ * this->n_; 00275 } 00276 00277 00279 00282 template <class T, class Prop, class Storage, class Allocator> 00283 int MatrixCollection<T, Prop, Storage, Allocator>::GetDataSize() const 00284 { 00285 return nz_; 00286 } 00287 00288 00289 /********************* 00290 * MEMORY MANAGEMENT * 00291 *********************/ 00292 00293 00295 00301 template <class T, class Prop, class Storage, class Allocator> 00302 inline void MatrixCollection<T, Prop, Storage, Allocator> 00303 ::Reallocate(int i, int j) 00304 { 00305 nz_ = 0; 00306 Mmatrix_ = i; 00307 Nmatrix_ = j; 00308 Mlocal_.Reallocate(i); 00309 Nlocal_.Reallocate(j); 00310 Mlocal_sum_.Reallocate(i + 1); 00311 Nlocal_sum_.Reallocate(j + 1); 00312 Mlocal_.Fill(0.); 00313 Nlocal_.Fill(0.); 00314 Mlocal_sum_.Fill(0.); 00315 Nlocal_sum_.Fill(0.); 00316 matrix_.Reallocate(i, j); 00317 } 00318 00319 00321 00326 template <class T, class Prop, class Storage, class Allocator> 00327 template <class T0, class Prop0, class Storage0, class Allocator0> 00328 inline void MatrixCollection<T, Prop, Storage, Allocator> 00329 ::SetMatrix(int i, int j, const Matrix<T0, Prop0, Storage0, Allocator0>& A) 00330 { 00331 #ifdef SELDON_CHECK_BOUNDS 00332 if (i < 0 || i >= Mmatrix_) 00333 throw WrongRow("MatrixCollection::SetMatrix()", 00334 string("Line index should be in [0, ") 00335 + to_str(Mmatrix_ - 1) + "], but is equal to " 00336 + to_str(i) + "."); 00337 if (j < 0 || j >= Nmatrix_) 00338 throw WrongCol("MatrixCollection::SetMatrix()", 00339 string("Column index should be in [0, ") 00340 + to_str(Nmatrix_ - 1) + "], but is equal to " 00341 + to_str(j) + "."); 00342 if ((Mlocal_(i) != 0) && (Mlocal_(i) != A.GetM())) 00343 throw WrongDim("MatrixCollection::SetMatrix()", 00344 string("The matrix expected should have ") 00345 + to_str(this->Mlocal_(i)) + " rows, but has " 00346 + to_str(A.GetM()) + " rows."); 00347 if ((Nlocal_(j) != 0) && (Nlocal_(j) != A.GetN())) 00348 throw WrongDim("MatrixCollection::SetMatrix()", 00349 string("The matrix expected should have ") 00350 + to_str(this->Nlocal_(j)) + " columns, but has " 00351 + to_str(A.GetN()) + " columns."); 00352 #endif 00353 00354 nz_ = A.GetDataSize() - matrix_(i, j).GetDataSize(); 00355 00356 int Mdiff = A.GetM() - Mlocal_(i); 00357 int Ndiff = A.GetN() - Nlocal_(j); 00358 00359 Mlocal_(i) = A.GetM(); 00360 Nlocal_(j) = A.GetN(); 00361 00362 for (int k = i + 1; k < Mmatrix_ + 1; k++) 00363 Mlocal_sum_(k) += Mdiff; 00364 00365 for (int k = j + 1; k < Nmatrix_ + 1; k++) 00366 Nlocal_sum_(k) += Ndiff; 00367 00368 this->m_ = Mlocal_sum_(Mmatrix_); 00369 this->n_ = Nlocal_sum_(Nmatrix_); 00370 00371 matrix_(i, j).SetData(A.GetM(), A.GetN(), A.GetData()); 00372 } 00373 00374 00376 00381 template <class T, class Prop, class Storage, class Allocator> 00382 template <class T0, class Prop0, class Allocator0> 00383 inline void MatrixCollection<T, Prop, Storage, Allocator> 00384 ::SetMatrix(int i, int j, const Matrix<T0, Prop0, RowSparse, Allocator0>& A) 00385 { 00386 #ifdef SELDON_CHECK_BOUNDS 00387 if (i < 0 || i >= Mmatrix_) 00388 throw WrongRow("MatrixCollection::SetMatrix()", 00389 string("Index should be in [0, ") 00390 + to_str(Mmatrix_ - 1) + "], but is equal to " 00391 + to_str(i) + "."); 00392 if (j < 0 || j >= Nmatrix_) 00393 throw WrongCol("MatrixCollection::SetMatrix()", 00394 string("Index should be in [0, ") 00395 + to_str(Nmatrix_ - 1) + "], but is equal to " 00396 + to_str(j) + "."); 00397 if ((Mlocal_(i) != 0) && (Mlocal_(i) != A.GetM())) 00398 throw WrongDim("MatrixCollection::SetMatrix()", 00399 string("The matrix expected should have ") 00400 + to_str(this->Mlocal_(i)) + " rows, but has " 00401 + to_str(A.GetM()) + " rows."); 00402 if ((Nlocal_(j) != 0) && (Nlocal_(j) != A.GetN())) 00403 throw WrongDim("MatrixCollection::SetMatrix()", 00404 string("The matrix expected should have ") 00405 + to_str(this->Nlocal_(j)) + " columns, but has " 00406 + to_str(A.GetN()) + " columns."); 00407 #endif 00408 00409 nz_ = A.GetDataSize() - matrix_(i, j).GetDataSize(); 00410 00411 int Mdiff = A.GetM() - Mlocal_(i); 00412 int Ndiff = A.GetN() - Nlocal_(j); 00413 00414 Mlocal_(i) = A.GetM(); 00415 Nlocal_(j) = A.GetN(); 00416 00417 for (int k = i + 1; k < Mmatrix_ + 1; k++) 00418 Mlocal_sum_(k) += Mdiff; 00419 00420 for (int k = j + 1; k < Nmatrix_ + 1; k++) 00421 Nlocal_sum_(k) += Ndiff; 00422 00423 this->m_ = Mlocal_sum_(Mmatrix_); 00424 this->n_ = Nlocal_sum_(Nmatrix_); 00425 00426 matrix_(i, j).SetData(A.GetM(), A.GetN(), A.GetNonZeros(), A.GetData(), 00427 A.GetPtr(), A.GetInd()); 00428 } 00429 00430 00431 /********************************** 00432 * ELEMENT ACCESS AND AFFECTATION * 00433 **********************************/ 00434 00435 00437 00443 template <class T, class Prop, class Storage, class Allocator> 00444 inline 00445 typename MatrixCollection<T, Prop, Storage, Allocator>::matrix_reference 00446 MatrixCollection<T, Prop, Storage, Allocator>::GetMatrix(int i, int j) 00447 { 00448 #ifdef SELDON_CHECK_BOUNDS 00449 if (i < 0 || i >= Mmatrix_) 00450 throw WrongRow("MatrixCollection::GetMatrix(int, int)", 00451 string("Row index should be in [0, ") 00452 + to_str(Mmatrix_ - 1) + "], but is equal to " 00453 + to_str(i) + "."); 00454 if (j < 0 || j >= Nmatrix_) 00455 throw WrongCol("MatrixCollection::GetMatrix(int, int)", 00456 string("Column index should be in [0, ") 00457 + to_str(Nmatrix_ - 1) + "], but is equal to " 00458 + to_str(j) + "."); 00459 #endif 00460 00461 return matrix_(i, j); 00462 } 00463 00464 00466 00472 template <class T, class Prop, class Storage, class Allocator> 00473 inline typename MatrixCollection<T, Prop, Storage, Allocator> 00474 ::const_matrix_reference 00475 MatrixCollection<T, Prop, Storage, Allocator>::GetMatrix(int i, 00476 int j) const 00477 { 00478 #ifdef SELDON_CHECK_BOUNDS 00479 if (i < 0 || i >= Mmatrix_) 00480 throw WrongRow("MatrixCollection::GetMatrix(int, int)", 00481 string("Row index should be in [0, ") 00482 + to_str(Mmatrix_ - 1) + "], but is equal to " 00483 + to_str(i) + "."); 00484 if (j < 0 || j >= Nmatrix_) 00485 throw WrongCol("MatrixCollection::GetMatrix(int, int)", 00486 string("Column index should be in [0, ") 00487 + to_str(Nmatrix_ - 1) + "], but is equal to " 00488 + to_str(j) + "."); 00489 #endif 00490 00491 return matrix_(i, j); 00492 } 00493 00494 00496 00502 template <class T, class Prop, class Storage, class Allocator> 00503 inline typename MatrixCollection<T, Prop, Storage, Allocator> 00504 ::value_type 00505 MatrixCollection<T, Prop, Storage, Allocator>::operator() (int i, 00506 int j) const 00507 { 00508 #ifdef SELDON_CHECK_BOUNDS 00509 if (i < 0 || i >= this->Mlocal_sum_(Mmatrix_)) 00510 throw WrongRow("MatrixCollection::operator(int, int)", 00511 string("Row index should be in [0, ") 00512 + to_str(this->Mlocal_sum_(Mmatrix_) - 1) 00513 + "], but is equal to " + to_str(i) + "."); 00514 if (j < 0 || j >= this->Nlocal_sum_(Nmatrix_)) 00515 throw WrongCol("MatrixCollection::operator(int, int)", 00516 string("Column index should be in [0, ") 00517 + to_str(this->Nlocal_sum_(Nmatrix_) - 1) 00518 + "], but is equal to " + to_str(j) + "."); 00519 #endif 00520 00521 int i_global = 0; 00522 while (i >= Mlocal_sum_(i_global)) 00523 i_global++; 00524 i_global--; 00525 00526 int j_global = 0; 00527 while (j >= Nlocal_sum_(j_global)) 00528 j_global++; 00529 j_global--; 00530 00531 return matrix_(i_global, j_global)(i - Mlocal_sum_(i_global), 00532 j - Nlocal_sum_(j_global)); 00533 } 00534 00535 00537 00542 template <class T, class Prop, class Storage, class Allocator> 00543 inline MatrixCollection<T, Prop, Storage, Allocator>& 00544 MatrixCollection<T, Prop, Storage, Allocator> 00545 ::operator= (const MatrixCollection<T, Prop, Storage, Allocator>& A) 00546 { 00547 this->Copy(A); 00548 return *this; 00549 } 00550 00551 00553 00558 template <class T, class Prop, class Storage, class Allocator> 00559 inline void MatrixCollection<T, Prop, Storage, Allocator> 00560 ::Copy(const MatrixCollection<T, Prop, Storage, Allocator>& A) 00561 { 00562 Clear(); 00563 00564 this->nz_ = A.nz_; 00565 this->m_ = A.GetM(); 00566 this->n_ = A.GetN(); 00567 Mmatrix_ = A.Mmatrix_; 00568 Nmatrix_ = A.Nmatrix_; 00569 this->Mlocal_ = A.Mlocal_; 00570 this->Mlocal_sum_ = A.Mlocal_sum_; 00571 this->Nlocal_ = A.Nlocal_; 00572 this->Nlocal_sum_ = A.Nlocal_sum_; 00573 00574 matrix_.Reallocate(Mmatrix_, Nmatrix_); 00575 00576 for (int i = 0; i < Mmatrix_; i++) 00577 for (int j = 0; j < Nmatrix_; j++) 00578 SetMatrix(i, j, A.GetMatrix(i, j)); 00579 } 00580 00581 00582 /************************ 00583 * CONVENIENT FUNCTIONS * 00584 ************************/ 00585 00586 00588 00591 template <class T, class Prop, class Storage, class Allocator> 00592 void MatrixCollection<T, Prop, Storage, Allocator>::Print() const 00593 { 00594 for (int i = 0; i < Mmatrix_; i++) 00595 { 00596 for (int j = 0; j < Nmatrix_; j++) 00597 cout << GetMatrix(i, j) << endl; 00598 cout << endl; 00599 } 00600 } 00601 00602 00604 00608 template <class T, class Prop, class Storage, class Allocator> 00609 void MatrixCollection<T, Prop, Storage, Allocator> 00610 ::Print(int i, int j) const 00611 { 00612 #ifdef SELDON_CHECK_BOUNDS 00613 if (i < 0 || i >= Mmatrix_) 00614 throw WrongRow("MatrixCollection::Print(int, int)", 00615 string("Row index should be in [0, ") 00616 + to_str(Mmatrix_ - 1) + "], but is equal to " 00617 + to_str(i) + "."); 00618 if (j < 0 || j >= Nmatrix_) 00619 throw WrongCol("MatrixCollection::Print(int, int)", 00620 string("Column index should be in [0, ") 00621 + to_str(Nmatrix_ - 1) + "], but is equal to " 00622 + to_str(j) + "."); 00623 #endif 00624 00625 cout << matrix_(i, j) << endl; 00626 } 00627 00628 00630 00638 template <class T, class Prop, class Storage, class Allocator> 00639 void MatrixCollection<T, Prop, Storage, Allocator> 00640 ::Write(string FileName, bool with_size) const 00641 { 00642 ofstream FileStream; 00643 FileStream.open(FileName.c_str(), ofstream::binary); 00644 00645 #ifdef SELDON_CHECK_IO 00646 // Checks if the file was opened. 00647 if (!FileStream.is_open()) 00648 throw IOError("MatrixCollection::Write(string FileName, bool)", 00649 string("Unable to open file \"") + FileName + "\"."); 00650 #endif 00651 00652 this->Write(FileStream, with_size); 00653 00654 FileStream.close(); 00655 } 00656 00657 00659 00667 template <class T, class Prop, class Storage, class Allocator> 00668 void MatrixCollection<T, Prop, Storage, Allocator> 00669 ::Write(ostream& FileStream, bool with_size = true) const 00670 { 00671 00672 #ifdef SELDON_CHECK_IO 00673 // Checks if the stream is ready. 00674 if (!FileStream.good()) 00675 throw IOError("MatrixCollection::Write(ostream& FileStream, bool)", 00676 "The stream is not ready."); 00677 #endif 00678 00679 if (with_size) 00680 { 00681 FileStream.write(reinterpret_cast<char*>(const_cast<int*>(&Mmatrix_)), 00682 sizeof(int)); 00683 FileStream.write(reinterpret_cast<char*>(const_cast<int*>(&Nmatrix_)), 00684 sizeof(int)); 00685 } 00686 00687 int i, j; 00688 for (i = 0; i < this->GetMmatrix(); i++) 00689 { 00690 for (j = 0; j < this->GetNmatrix(); j++) 00691 GetMatrix(i, j).Write(FileStream, with_size); 00692 } 00693 00694 #ifdef SELDON_CHECK_IO 00695 // Checks if data was written. 00696 if (!FileStream.good()) 00697 throw IOError("MatrixCollection::Write(ostream& FileStream, bool)", 00698 "Output operation failed."); 00699 #endif 00700 00701 } 00702 00703 00705 00710 template <class T, class Prop, class Storage, class Allocator> 00711 void MatrixCollection<T, Prop, Storage, Allocator> 00712 ::WriteText(string FileName) const 00713 { 00714 ofstream FileStream; 00715 FileStream.precision(cout.precision()); 00716 FileStream.flags(cout.flags()); 00717 FileStream.open(FileName.c_str()); 00718 00719 #ifdef SELDON_CHECK_IO 00720 // Checks if the file was opened. 00721 if (!FileStream.is_open()) 00722 throw IOError("MatrixCollection::WriteText(string FileName)", 00723 string("Unable to open file \"") + FileName + "\"."); 00724 #endif 00725 00726 this->WriteText(FileStream); 00727 00728 FileStream.close(); 00729 } 00730 00731 00733 00739 template <class T, class Prop, class Storage, class Allocator> 00740 void MatrixCollection<T, Prop, Storage, Allocator> 00741 ::WriteText(ostream& FileStream) const 00742 { 00743 00744 #ifdef SELDON_CHECK_IO 00745 // Checks if the file is ready. 00746 if (!FileStream.good()) 00747 throw IOError("MatrixCollection::WriteText(ostream& FileStream)", 00748 "The stream is not ready."); 00749 #endif 00750 00751 int i, j; 00752 for (i = 0; i < this->GetMmatrix(); i++) 00753 { 00754 for (j = 0; j < this->GetNmatrix(); j++) 00755 GetMatrix(i, j).WriteText(FileStream); 00756 FileStream << endl; 00757 } 00758 00759 #ifdef SELDON_CHECK_IO 00760 // Checks if data was written. 00761 if (!FileStream.good()) 00762 throw IOError("MatrixCollection::WriteText(ostream& FileStream)", 00763 "Output operation failed."); 00764 #endif 00765 00766 } 00767 00768 00770 00776 template <class T, class Prop, class Storage, class Allocator> 00777 void MatrixCollection<T, Prop, Storage, Allocator>::Read(string FileName) 00778 { 00779 ifstream FileStream; 00780 FileStream.open(FileName.c_str(), ifstream::binary); 00781 00782 #ifdef SELDON_CHECK_IO 00783 // Checks if the file was opened. 00784 if (!FileStream.is_open()) 00785 throw IOError("MatrixCollection::Read(string FileName)", 00786 string("Unable to open file \"") + FileName + "\"."); 00787 #endif 00788 00789 this->Read(FileStream); 00790 00791 FileStream.close(); 00792 } 00793 00794 00796 00802 template <class T, class Prop, class Storage, class Allocator> 00803 void MatrixCollection<T, Prop, Storage, Allocator> 00804 ::Read(istream& FileStream) 00805 { 00806 00807 #ifdef SELDON_CHECK_IO 00808 // Checks if the stream is ready. 00809 if (!FileStream.good()) 00810 throw IOError("MatrixCollection::Read(istream& FileStream)", 00811 "The stream is not ready."); 00812 #endif 00813 00814 int *new_m, *new_n; 00815 new_m = new int; 00816 new_n = new int; 00817 00818 FileStream.read(reinterpret_cast<char*>(new_m), sizeof(int)); 00819 FileStream.read(reinterpret_cast<char*>(new_n), sizeof(int)); 00820 00821 this->Reallocate(*new_m, *new_n); 00822 00823 T working_matrix; 00824 int i, j; 00825 for (i = 0; i < *new_m; i++) 00826 for (j = 0; j < *new_n; j++) 00827 { 00828 working_matrix.Read(FileStream); 00829 SetMatrix(i, j, working_matrix); 00830 working_matrix.Nullify(); 00831 } 00832 00833 00834 delete new_n; 00835 delete new_m; 00836 00837 #ifdef SELDON_CHECK_IO 00838 // Checks if data was read. 00839 if (!FileStream.good()) 00840 throw IOError("MatrixCollection::Read(istream& FileStream)", 00841 "Input operation failed."); 00842 #endif 00843 00844 } 00845 00846 00848 // COLMAJORCOLLECTION // 00850 00851 00852 /**************** 00853 * CONSTRUCTORS * 00854 ****************/ 00855 00856 00858 00861 template <class T, class Prop, class Allocator> 00862 inline Matrix<T, Prop, ColMajorCollection, Allocator>::Matrix(): 00863 MatrixCollection<T, Prop, ColMajor, Allocator>() 00864 { 00865 } 00866 00867 00869 00873 template <class T, class Prop, class Allocator> 00874 inline Matrix<T, Prop, ColMajorCollection, Allocator>::Matrix(int i, int j): 00875 MatrixCollection<T, Prop, ColMajor, Allocator>(i, j) 00876 { 00877 } 00878 00879 00881 // ROWMAJORCOLLECTION // 00883 00884 00885 /**************** 00886 * CONSTRUCTORS * 00887 ****************/ 00888 00889 00891 00894 template <class T, class Prop, class Allocator> 00895 inline Matrix<T, Prop, RowMajorCollection, Allocator>::Matrix(): 00896 MatrixCollection<T, Prop, RowMajor, Allocator>() 00897 { 00898 } 00899 00900 00902 00906 template <class T, class Prop, class Allocator> 00907 inline Matrix<T, Prop, RowMajorCollection, Allocator>::Matrix(int i, int j): 00908 MatrixCollection<T, Prop, RowMajor, Allocator>(i, j) 00909 { 00910 } 00911 00912 00914 // COLSYMPACKEDCOLLECTION // 00916 00917 00918 /**************** 00919 * CONSTRUCTORS * 00920 ****************/ 00921 00922 00924 00927 template <class T, class Prop, class Allocator> 00928 inline Matrix<T, Prop, ColSymPackedCollection, Allocator>::Matrix(): 00929 MatrixCollection<T, Prop, ColSymPacked, Allocator>() 00930 { 00931 } 00932 00933 00935 00939 template <class T, class Prop, class Allocator> 00940 inline Matrix<T, Prop, ColSymPackedCollection, Allocator> 00941 ::Matrix(int i, int j): 00942 MatrixCollection<T, Prop, ColSymPacked, Allocator>(i, j) 00943 { 00944 } 00945 00946 00948 // ROWSYMPACKEDCOLLECTION // 00950 00951 00952 /**************** 00953 * CONSTRUCTORS * 00954 ****************/ 00955 00956 00958 00961 template <class T, class Prop, class Allocator> 00962 inline Matrix<T, Prop, RowSymPackedCollection, Allocator>::Matrix(): 00963 MatrixCollection<T, Prop, RowSymPacked, Allocator>() 00964 { 00965 } 00966 00967 00969 00973 template <class T, class Prop, class Allocator> 00974 inline Matrix<T, Prop, RowSymPackedCollection, Allocator> 00975 ::Matrix(int i, int j): 00976 MatrixCollection<T, Prop, RowSymPacked, Allocator>(i, j) 00977 { 00978 } 00979 00980 00981 } // namespace Seldon. 00982 00983 00984 #define SELDON_FILE_MATRIX_COLLECTION_CXX 00985 #endif