20 #ifndef SELDON_FILE_MATRIX_ARRAY_SPARSE_CXX
22 #include "Matrix_ArraySparse.hxx"
40 template <
class T,
class Prop,
class Storage,
class Allocator>
50 int n = Storage::GetFirst(i, j);
62 template <
class T,
class Prop,
class Storage,
class Allocator>
65 int n = Storage::GetFirst(this->m_, this->n_);
66 int new_n = Storage::GetFirst(i, j);
72 new_val.Reallocate(new_n);
74 for (
int k = 0 ; k < min(n, new_n) ; k++)
75 Swap(new_val(k), this->val_(k));
77 val_.SetData(new_n, new_val.GetData());
96 template <
class T,
class Prop,
class Storage,
class Allocator>
101 for (
int i = 0; i < this->val_.GetM(); i++)
102 nnz += this->val_(i).GetM();
109 template<
class T,
class Prop,
class Storage,
class Allocator>
112 size_t taille =
sizeof(*this) +
sizeof(pointer)*this->val_.GetM();
113 for (
int i = 0; i < this->val_.GetM(); i++)
114 taille += this->val_(i).GetMemorySize();
131 template <
class T,
class Prop,
class Storage,
class Allocator>
134 if (Storage::GetFirst(1, 0) == 1)
135 for (
int i = 0; i < this->m_; i++)
137 for (
int j = 0; j < this->val_(i).GetM(); j++)
138 cout << (i+1) <<
" " << this->val_(i).Index(j)+1
139 <<
" " << this->val_(i).Value(j) << endl;
142 for (
int i = 0; i < this->n_; i++)
144 for (
int j = 0; j < this->val_(i).GetM(); j++)
145 cout << this->val_(i).Index(j)+1 <<
" " << i+1
146 <<
" " << this->val_(i).Value(j) << endl;
158 template <
class T,
class Prop,
class Storage,
class Allocator>
161 for (
int i = 0; i < val_.GetM(); i++)
170 template <
class T,
class Prop,
class Storage,
class Allocator>
175 for (
int i = 0; i < val_.GetM(); i++)
176 val_(i).RemoveSmallEntry(epsilon);
181 template <
class T,
class Prop,
class Storage,
class Allocator>
184 T one; SetComplexOne(one);
186 for (
int i = 0; i < this->m_; i++)
188 val_(i).Reallocate(1);
189 val_(i).Index(0) = i;
190 val_(i).Value(0) = one;
196 template <
class T,
class Prop,
class Storage,
class Allocator>
199 for (
int i = 0; i < val_.GetM(); i++)
205 template <
class T,
class Prop,
class Storage,
class Allocator>
209 for (
int i = 0; i < val_.GetM(); i++)
210 for (
int j = 0; j < val_(i).GetM(); j++)
219 template <
class T,
class Prop,
class Storage,
class Allo>
template<
class T0>
222 for (
int i = 0; i < val_.GetM(); i++)
228 template <
class T,
class Prop,
class Storage,
class Allocator>
238 template <
class T,
class Prop,
class Storage,
class Allocator>
241 #ifndef SELDON_WITHOUT_REINIT_RANDOM
244 for (
int i = 0; i < val_.GetM(); i++)
257 template <
class T,
class Prop,
class Storage,
class Allocator>
262 FileStream.open(FileName.c_str(), ofstream::binary);
264 #ifdef SELDON_CHECK_IO
266 if (!FileStream.is_open())
267 throw IOError(
"Matrix_ArraySparse::Write(string FileName)",
268 string(
"Unable to open file \"") + FileName +
"\".");
271 this->Write(FileStream);
285 template <
class T,
class Prop,
class Storage,
class Allocator>
290 #ifdef SELDON_CHECK_IO
292 if (!FileStream.good())
293 throw IOError(
"Matrix_ArraySparse::Write(ofstream& FileStream)",
294 "Stream is not ready.");
297 FileStream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&this->m_)),
299 FileStream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&this->n_)),
302 for (
int i = 0; i < val_.GetM(); i++)
303 val_(i).Write(FileStream);
312 template <
class T,
class Prop,
class Storage,
class Allocator>
316 ofstream FileStream; FileStream.precision(14);
317 FileStream.open(FileName.c_str());
320 FileStream.precision(cout.precision());
322 #ifdef SELDON_CHECK_IO
324 if (!FileStream.is_open())
325 throw IOError(
"Matrix_ArraySparse::Write(string FileName)",
326 string(
"Unable to open file \"") + FileName +
"\".");
329 this->WriteText(FileStream, cplx);
340 template <
class T,
class Prop,
class Storage,
class Allocator>
345 #ifdef SELDON_CHECK_IO
347 if (!FileStream.good())
348 throw IOError(
"Matrix_ArraySparse::Write(ofstream& FileStream)",
349 "Stream is not ready.");
356 T zero;
int index = 1;
357 WriteCoordinateMatrix(leaf_class, FileStream, zero, index, cplx);
369 template <
class T,
class Prop,
class Storage,
class Allocator>
374 FileStream.open(FileName.c_str(), ifstream::binary);
376 #ifdef SELDON_CHECK_IO
378 if (!FileStream.is_open())
379 throw IOError(
"Matrix_ArraySparse::Read(string FileName)",
380 string(
"Unable to open file \"") + FileName +
"\".");
383 this->Read(FileStream);
397 template <
class T,
class Prop,
class Storage,
class Allocator>
402 #ifdef SELDON_CHECK_IO
404 if (!FileStream.good())
405 throw IOError(
"Matrix_ArraySparse::Read(ofstream& FileStream)",
406 "Stream is not ready.");
409 FileStream.read(
reinterpret_cast<char*
>(
const_cast<int*
>(&this->m_)),
411 FileStream.read(
reinterpret_cast<char*
>(
const_cast<int*
>(&this->n_)),
414 val_.Reallocate(Storage::GetFirst(this->m_, this->n_));
415 for (
int i = 0; i < val_.GetM(); i++)
416 val_(i).Read(FileStream);
418 #ifdef SELDON_CHECK_IO
420 if (!FileStream.good())
421 throw IOError(
"Matrix_ArraySparse::Read(istream& FileStream)",
422 string(
"Input operation failed.")
423 +
string(
" The input file may have been removed")
424 +
" or may not contain enough data.");
435 template <
class T,
class Prop,
class Storage,
class Allocator>
440 FileStream.open(FileName.c_str());
442 #ifdef SELDON_CHECK_IO
444 if (!FileStream.is_open())
445 throw IOError(
"Matrix_ArraySparse::ReadText(string FileName)",
446 string(
"Unable to open file \"") + FileName +
"\".");
449 this->ReadText(FileStream, cplx);
460 template <
class T,
class Prop,
class Storage,
class Allocator>
467 T zero;
int index = 1;
468 ReadCoordinateMatrix(leaf_class, FileStream, zero, index, -1, cplx);
484 template <
class T,
class Prop,
class Allocator>
490 col.SetData(nb, col_);
492 val.SetData(nb, value_);
493 AddInteractionRow(i, nb, col, val, already_sorted);
506 template <
class T,
class Prop,
class Allocator>
512 row.SetData(nb, row_);
514 val.SetData(nb, value_);
515 AddInteractionColumn(i, nb, row, val, already_sorted);
528 template <
class T,
class Prop,
class Allocator>
531 const Vector<T>& val,
bool already_sorted)
533 for (
int j = 0; j < nb; j++)
534 this->val_(col(j)).AddInteraction(i, val(j));
545 template <
class T,
class Prop,
class Allocator>
548 const Vector<T>& val,
bool already_sorted)
550 this->val_(i).AddInteractionRow(nb, row, val, already_sorted);
566 template <
class T,
class Prop,
class Allocator>
572 col.SetData(nb, col_);
574 val.SetData(nb, value_);
575 AddInteractionRow(i, nb, col, val, already_sorted);
588 template <
class T,
class Prop,
class Allocator>
594 row.SetData(nb, row_);
596 val.SetData(nb, value_);
597 AddInteractionColumn(i, nb, row, val, already_sorted);
610 template <
class T,
class Prop,
class Allocator>
613 const Vector<T>& val,
bool already_sorted)
615 this->val_(i).AddInteractionRow(nb, col, val, already_sorted);
626 template <
class T,
class Prop,
class Allocator>
629 const Vector<T>& val,
bool already_sorted)
631 for (
int j = 0; j < nb; j++)
632 this->val_(row(j)).AddInteraction(i, val(j));
648 template <
class T,
class Prop,
class Allocator>
654 col.SetData(nb, col_);
656 val.SetData(nb, value_);
657 AddInteractionRow(i, nb, col, val, already_sorted);
670 template <
class T,
class Prop,
class Allocator>
676 row.SetData(nb, row_);
678 val.SetData(nb, value_);
679 AddInteractionColumn(i, nb, row, val, already_sorted);
692 template <
class T,
class Prop,
class Allocator>
695 const Vector<T>& val,
bool already_sorted)
697 for (
int j = 0; j < nb; j++)
699 this->val_(col(j)).AddInteraction(i, val(j));
710 template <
class T,
class Prop,
class Allocator>
713 const Vector<T>& val,
bool already_sorted)
718 for (
int j = 0; j < new_row.GetM(); j++)
721 new_row(nb) = row(j);
722 new_val(nb) = val(j); nb++;
725 this->val_(i).AddInteractionRow(nb, new_row, new_val, already_sorted);
741 template <
class T,
class Prop,
class Allocator>
747 col.SetData(nb, col_);
749 val.SetData(nb, value_);
750 AddInteractionRow(i, nb, col, val, already_sorted);
763 template <
class T,
class Prop,
class Allocator>
769 row.SetData(nb, row_);
771 val.SetData(nb, value_);
772 AddInteractionColumn(i, nb, row, val, already_sorted);
785 template <
class T,
class Prop,
class Allocator>
788 const Vector<T>& val,
bool already_sorted)
793 for (
int j = 0; j < new_col.GetM(); j++)
796 new_col(nb) = col(j);
797 new_val(nb) = val(j); nb++;
800 this->val_(i).AddInteractionRow(nb, new_col, new_val, already_sorted);
811 template <
class T,
class Prop,
class Allocator>
814 const Vector<T>& val,
bool already_sorted)
816 for (
int j = 0; j < nb; j++)
818 this->val_(row(j)).AddInteraction(i, val(j));
823 #define SELDON_FILE_MATRIX_ARRAY_SPARSE_CXX