21 #ifndef SELDON_FILE_MATRIX_SYMPACKED_CXX
23 #include "Matrix_SymPacked.hxx"
35 template <
class T,
class Prop,
class Storage,
class Allocator>
40 #ifdef SELDON_CHECK_MEMORY
45 this->data_ = Allocator::allocate((i * (i + 1)) / 2,
this);
47 #ifdef SELDON_CHECK_MEMORY
56 if (this->data_ == NULL)
68 template <
class T,
class Prop,
class Storage,
class Allocator>
86 template <
class T,
class Prop,
class Storage,
class Allocator>
89 #ifdef SELDON_CHECK_MEMORY
94 if (this->data_ != NULL)
96 Allocator::deallocate(this->data_,
97 (this->m_ * (this->m_ + 1)) / 2);
101 #ifdef SELDON_CHECK_MEMORY
128 template <
class T,
class Prop,
class Storage,
class Allocator>
138 #ifdef SELDON_CHECK_MEMORY
144 reinterpret_cast<pointer
>(Allocator::
145 reallocate(this->data_,
146 (i * (i + 1)) / 2,
this));
148 #ifdef SELDON_CHECK_MEMORY
155 throw NoMemory(
"Matrix_SymPacked::Reallocate(int, int)",
156 "Unable to reallocate memory for data_.");
158 if (this->data_ == NULL)
162 throw NoMemory(
"Matrix_SymPacked::Reallocate(int, int)",
163 "Unable to reallocate memory for data_.");
187 template <
class T,
class Prop,
class Storage,
class Allocator>
207 template <
class T,
class Prop,
class Storage,
class Allocator>
226 template <
class T,
class Prop,
class Storage,
class Allocator>
229 Allocator::memoryset(this->data_,
char(0),
230 this->GetDataSize() *
sizeof(value_type));
235 template <
class T,
class Prop,
class Storage,
class Allocator>
240 SetComplexZero(zero);
244 for (
int i = 0; i < min(this->m_, this->n_); i++)
254 template <
class T,
class Prop,
class Storage,
class Allocator>
257 for (
int i = 0; i < this->GetDataSize(); i++)
266 template <
class T,
class Prop,
class Storage,
class Allocator>
272 for (
int i = 0; i < this->GetDataSize(); i++)
281 template <
class T,
class Prop,
class Storage,
class Allocator>
296 template <
class T,
class Prop,
class Storage,
class Allocator>
299 #ifndef SELDON_WITHOUT_REINIT_RANDOM
302 for (
int i = 0; i < this->GetDataSize(); i++)
313 template <
class T,
class Prop,
class Storage,
class Allocator>
316 for (
int i = 0; i < this->m_; i++)
318 for (
int j = 0; j < this->n_; j++)
319 cout << (*
this)(i, j) <<
"\t";
337 template <
class T,
class Prop,
class Storage,
class Allocator>
341 for (
int i = a; i < min(this->m_, a + m); i++)
343 for (
int j = b; j < min(this->n_, b + n); j++)
344 cout << (*
this)(i, j) <<
"\t";
359 template <
class T,
class Prop,
class Storage,
class Allocator>
379 template <
class T,
class Prop,
class Storage,
class Allocator>
384 FileStream.open(FileName.c_str(), ofstream::binary);
386 #ifdef SELDON_CHECK_IO
388 if (!FileStream.is_open())
389 throw IOError(
"Matrix_SymPacked::Write(string FileName)",
390 string(
"Unable to open file \"") + FileName +
"\".");
393 this->Write(FileStream);
407 template <
class T,
class Prop,
class Storage,
class Allocator>
412 #ifdef SELDON_CHECK_IO
414 if (!FileStream.good())
415 throw IOError(
"Matrix_SymPacked::Write(ostream& FileStream)",
416 "The stream is not ready.");
419 FileStream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&this->m_)),
421 FileStream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&this->n_)),
424 FileStream.write(
reinterpret_cast<char*
>(this->data_),
425 this->GetDataSize() *
sizeof(value_type));
427 #ifdef SELDON_CHECK_IO
429 if (!FileStream.good())
430 throw IOError(
"Matrix_SymPacked::Write(ostream& FileStream)",
431 "Output operation failed.");
445 template <
class T,
class Prop,
class Storage,
class Allocator>
450 FileStream.precision(cout.precision());
451 FileStream.flags(cout.flags());
452 FileStream.open(FileName.c_str());
454 #ifdef SELDON_CHECK_IO
456 if (!FileStream.is_open())
457 throw IOError(
"Matrix_SymPacked::WriteText(string FileName)",
458 string(
"Unable to open file \"") + FileName +
"\".");
461 this->WriteText(FileStream);
475 template <
class T,
class Prop,
class Storage,
class Allocator>
480 #ifdef SELDON_CHECK_IO
482 if (!FileStream.good())
483 throw IOError(
"Matrix_SymPacked::WriteText(ostream& FileStream)",
484 "The stream is not ready.");
488 for (i = 0; i < this->GetM(); i++)
490 for (j = 0; j < this->GetN(); j++)
491 FileStream << (*
this)(i, j) <<
'\t';
495 #ifdef SELDON_CHECK_IO
497 if (!FileStream.good())
498 throw IOError(
"Matrix_SymPacked::WriteText(ostream& FileStream)",
499 "Output operation failed.");
513 template <
class T,
class Prop,
class Storage,
class Allocator>
517 FileStream.open(FileName.c_str(), ifstream::binary);
519 #ifdef SELDON_CHECK_IO
521 if (!FileStream.good())
522 throw IOError(
"Matrix_SymPacked::Read(string FileName)",
523 string(
"Unable to open file \"") + FileName +
"\".");
526 this->Read(FileStream);
540 template <
class T,
class Prop,
class Storage,
class Allocator>
545 #ifdef SELDON_CHECK_IO
547 if (!FileStream.good())
548 throw IOError(
"Matrix_SymPacked::Read(istream& FileStream)",
549 "The stream is not ready.");
553 FileStream.read(
reinterpret_cast<char*
>(&new_m),
sizeof(
int));
554 FileStream.read(
reinterpret_cast<char*
>(&new_n),
sizeof(
int));
555 this->Reallocate(new_m, new_n);
557 FileStream.read(
reinterpret_cast<char*
>(this->data_),
558 this->GetDataSize() *
sizeof(value_type));
560 #ifdef SELDON_CHECK_IO
562 if (!FileStream.good())
563 throw IOError(
"Matrix_SymPacked::Read(istream& FileStream)",
564 "Input operation failed.");
575 template <
class T,
class Prop,
class Storage,
class Allocator>
580 FileStream.open(FileName.c_str());
582 #ifdef SELDON_CHECK_IO
584 if (!FileStream.is_open())
585 throw IOError(
"Matrix_Pointers::ReadText(string FileName)",
586 string(
"Unable to open file \"") + FileName +
"\".");
589 this->ReadText(FileStream);
600 template <
class T,
class Prop,
class Storage,
class Allocator>
607 #ifdef SELDON_CHECK_IO
609 if (!FileStream.good())
610 throw IOError(
"Matrix_SymPacked::ReadText(istream& FileStream)",
611 "The stream is not ready.");
616 getline(FileStream, line);
617 if (FileStream.fail())
622 istringstream line_stream(line);
624 first_row.ReadText(line_stream);
628 other_row.ReadText(FileStream);
631 int n = first_row.GetM();
632 int m = 1 + other_row.GetM() / n;
634 #ifdef SELDON_CHECK_IO
636 if (other_row.GetM() != (m - 1) * n)
637 throw IOError(
"Matrix_SymPacked::ReadText(istream& FileStream)",
638 "Not all rows have the same number of columns.");
641 this->Reallocate(m,n);
644 for (
int j = 0; j < n; j++)
645 this->Val(0, j) = first_row(j);
647 for (
int i = 1; i < m; i++)
650 for (
int j = i; j < n; j++)
651 this->Val(i, j) = other_row(k++);
674 template <
class T,
class Prop,
class Allocator>
679 long nold = this->GetDataSize();
681 for (
long k = 0; k < nold; k++)
682 xold(k) = this->data_[k];
685 this->Reallocate(i,j);
688 long nmin = min(nold, this->GetDataSize());
689 for (
long k = 0; k < nmin; k++)
690 this->data_[k] = xold(k);
712 template <
class T,
class Prop,
class Allocator>
717 long nold = this->GetDataSize(), iold = this->m_;
719 for (
long k = 0; k < nold; k++)
720 xold(k) = this->data_[k];
723 this->Reallocate(i,j);
726 long imin = min(iold,
long(i));
729 for (
long k = 0; k < imin; k++)
731 for (
long l = k; l < imin; l++)
732 this->data_[n+l-k] = xold(nold+l-k);
742 #define SELDON_FILE_MATRIX_SYMPACKED_CXX