21 #ifndef SELDON_FILE_MATRIX_HERMPACKED_CXX
23 #include "Matrix_HermPacked.hxx"
35 template <
class T,
class Prop,
class Storage,
class Allocator>
41 #ifdef SELDON_CHECK_MEMORY
46 this->data_ = Allocator::allocate((
long(i) *
long(i + 1)) / 2,
this);
48 #ifdef SELDON_CHECK_MEMORY
57 if (this->data_ == NULL)
69 template <
class T,
class Prop,
class Storage,
class Allocator>
72 Storage, Allocator>& A):
88 template <
class T,
class Prop,
class Storage,
class Allocator>
92 #ifdef SELDON_CHECK_MEMORY
97 if (this->data_ != NULL)
99 Allocator::deallocate(this->data_,
100 (
long(this->m_) *
long(this->m_ + 1)) / 2);
104 #ifdef SELDON_CHECK_MEMORY
131 template <
class T,
class Prop,
class Storage,
class Allocator>
141 #ifdef SELDON_CHECK_MEMORY
147 reinterpret_cast<pointer
>(Allocator
148 ::reallocate(this->data_,
149 (
long(i)*
long(i + 1)) / 2,
this));
151 #ifdef SELDON_CHECK_MEMORY
158 throw NoMemory(
"Matrix_HermPacked::Reallocate(int, int)",
159 "Unable to reallocate memory for data_.");
161 if (this->data_ == NULL)
165 throw NoMemory(
"Matrix_HermPacked::Reallocate(int, int)",
166 "Unable to reallocate memory for data_.");
190 template <
class T,
class Prop,
class Storage,
class Allocator>
210 template <
class T,
class Prop,
class Storage,
class Allocator>
229 template <
class T,
class Prop,
class Storage,
class Allocator>
232 Allocator::memoryset(this->data_,
char(0),
233 this->GetDataSize() *
sizeof(value_type));
238 template <
class T,
class Prop,
class Storage,
class Allocator>
243 SetComplexZero(zero);
247 for (
int i = 0; i < min(this->m_, this->n_); i++)
248 this->Val(i,i) = one;
257 template <
class T,
class Prop,
class Storage,
class Allocator>
260 long taille = this->GetDataSize();
261 for (
long i = 0; i < taille; i++)
272 template <
class T,
class Prop,
class Storage,
class Allocator>
276 T x_;
long taille = this->GetDataSize();
278 for (
long i = 0; i < taille; i++)
289 template <
class T,
class Prop,
class Storage,
class Allocator>
304 template <
class T,
class Prop,
class Storage,
class Allocator>
307 #ifndef SELDON_WITHOUT_REINIT_RANDOM
310 long taille = this->GetDataSize();
311 for (
long i = 0; i < taille; i++)
322 template <
class T,
class Prop,
class Storage,
class Allocator>
325 for (
int i = 0; i < this->m_; i++)
327 for (
int j = 0; j < this->n_; j++)
328 cout << (*
this)(i, j) <<
"\t";
346 template <
class T,
class Prop,
class Storage,
class Allocator>
350 for (
int i = a; i < min(this->m_, a+m); i++)
352 for (
int j = b; j < min(this->n_, b+n); j++)
353 cout << (*
this)(i, j) <<
"\t";
368 template <
class T,
class Prop,
class Storage,
class Allocator>
388 template <
class T,
class Prop,
class Storage,
class Allocator>
394 FileStream.open(FileName.c_str(), ofstream::binary);
396 #ifdef SELDON_CHECK_IO
398 if (!FileStream.is_open())
399 throw IOError(
"Matrix_HermPacked::Write(string FileName)",
400 string(
"Unable to open file \"") + FileName +
"\".");
403 this->Write(FileStream);
418 template <
class T,
class Prop,
class Storage,
class Allocator>
423 #ifdef SELDON_CHECK_IO
425 if (!FileStream.good())
426 throw IOError(
"Matrix_HermPacked::Write(ofstream& FileStream)",
427 "Stream is not ready.");
430 FileStream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&this->m_)),
432 FileStream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&this->n_)),
435 FileStream.write(
reinterpret_cast<char*
>(this->data_),
436 this->GetDataSize() *
sizeof(value_type));
438 #ifdef SELDON_CHECK_IO
440 if (!FileStream.good())
441 throw IOError(
"Matrix_HermPacked::Write(ofstream& FileStream)",
442 string(
"Output operation failed.")
443 +
string(
" The output file may have been removed")
444 +
" or there is no space left on device.");
458 template <
class T,
class Prop,
class Storage,
class Allocator>
463 FileStream.precision(cout.precision());
464 FileStream.flags(cout.flags());
465 FileStream.open(FileName.c_str());
467 #ifdef SELDON_CHECK_IO
469 if (!FileStream.is_open())
470 throw IOError(
"Matrix_HermPacked::WriteText(string FileName)",
471 string(
"Unable to open file \"") + FileName +
"\".");
474 this->WriteText(FileStream);
488 template <
class T,
class Prop,
class Storage,
class Allocator>
493 #ifdef SELDON_CHECK_IO
495 if (!FileStream.good())
496 throw IOError(
"Matrix_HermPacked::WriteText(ofstream& FileStream)",
497 "Stream is not ready.");
501 for (i = 0; i < this->GetM(); i++)
503 for (j = 0; j < this->GetN(); j++)
504 FileStream << (*
this)(i, j) <<
'\t';
508 #ifdef SELDON_CHECK_IO
510 if (!FileStream.good())
511 throw IOError(
"Matrix_HermPacked::WriteText(ofstream& FileStream)",
512 string(
"Output operation failed.")
513 + string(
" The output file may have been removed")
514 +
" or there is no space left on device.");
528 template <
class T,
class Prop,
class Storage,
class Allocator>
532 FileStream.open(FileName.c_str(), ifstream::binary);
534 #ifdef SELDON_CHECK_IO
536 if (!FileStream.good())
537 throw IOError(
"Matrix_HermPacked::Read(string FileName)",
538 string(
"Unable to open file \"") + FileName +
"\".");
541 this->Read(FileStream);
555 template <
class T,
class Prop,
class Storage,
class Allocator>
560 #ifdef SELDON_CHECK_IO
562 if (!FileStream.good())
563 throw IOError(
"Matrix_HermPacked::Read(ifstream& FileStream)",
564 "Stream is not ready.");
568 FileStream.read(
reinterpret_cast<char*
>(&new_m),
sizeof(
int));
569 FileStream.read(
reinterpret_cast<char*
>(&new_n),
sizeof(
int));
570 this->Reallocate(new_m, new_n);
572 FileStream.read(
reinterpret_cast<char*
>(this->data_),
573 this->GetDataSize() *
sizeof(value_type));
575 #ifdef SELDON_CHECK_IO
577 if (!FileStream.good())
578 throw IOError(
"Matrix_HermPacked::Read(ifstream& FileStream)",
579 string(
"Input operation failed.")
580 +
string(
" The input file may have been removed")
581 +
" or may not contain enough data.");
592 template <
class T,
class Prop,
class Storage,
class Allocator>
596 FileStream.open(FileName.c_str());
598 #ifdef SELDON_CHECK_IO
600 if (!FileStream.is_open())
601 throw IOError(
"Matrix_Pointers::ReadText(string FileName)",
602 string(
"Unable to open file \"") + FileName +
"\".");
605 this->ReadText(FileStream);
616 template <
class T,
class Prop,
class Storage,
class Allocator>
623 #ifdef SELDON_CHECK_IO
625 if (!FileStream.good())
626 throw IOError(
"Matrix_Pointers::ReadText(ifstream& FileStream)",
627 "Stream is not ready.");
632 getline(FileStream, line);
634 if (FileStream.fail())
641 istringstream line_stream(line);
643 first_row.ReadText(line_stream);
647 other_rows.ReadText(FileStream);
650 int n = first_row.GetM();
651 int m = 1 + other_rows.GetM()/n;
653 #ifdef SELDON_CHECK_IO
655 if (other_rows.GetM() != (m-1)*n)
656 throw IOError(
"Matrix_Pointers::ReadText(ifstream& FileStream)",
657 "The file should contain same number of columns.");
660 this->Reallocate(m,n);
662 for (
int j = 0; j < n; j++)
663 this->Val(0, j) = first_row(j);
666 for (
int i = 1; i < m; i++)
668 for (
int j = 0; j < i; j++)
671 for (
int j = i; j < n; j++)
672 this->Val(i, j) = other_rows(nb++);
692 template <
class T,
class Prop,
class Allocator>
697 long taille = this->GetDataSize();
698 for (
long i = 0; i < taille;i++)
713 template <
class T,
class Prop,
class Allocator>
719 long nold = this->GetDataSize();
721 for (
long k = 0; k < nold; k++)
722 xold(k) = this->data_[k];
725 this->Reallocate(i, j);
728 long nmin = min(nold, this->GetDataSize());
729 for (
long k = 0; k < nmin; k++)
730 this->data_[k] = xold(k);
748 template <
class T,
class Prop,
class Allocator>
753 long taille = this->GetDataSize();
754 for (
long i = 0; i < taille;i++)
769 template <
class T,
class Prop,
class Allocator>
774 long nold = this->GetDataSize(), iold = this->m_;
776 for (
long k = 0; k < nold; k++)
777 xold(k) = this->data_[k];
780 this->Reallocate(i, j);
783 long imin = min(iold,
long(i));
786 for (
long k = 0; k < imin; k++)
788 for (
long l = k; l < imin; l++)
789 this->data_[n+l-k] = xold(nold+l-k);
799 #define SELDON_FILE_MATRIX_HERMPACKED_CXX