21 #ifndef SELDON_FILE_MATRIX_SPARSE_CXX
23 #include "Matrix_Sparse.hxx"
60 template <
class T,
class Prop,
class Storage,
class Allocator>
61 template <
class Storage0,
class Allocator0,
62 class Storage1,
class Allocator1,
63 class Storage2,
class Allocator2>
71 nz_ = values.GetLength();
73 #ifdef SELDON_CHECK_DIMENSIONS
76 if (ind.GetLength() != nz_)
84 throw WrongDim(
string(
"Matrix_Sparse::Matrix_Sparse(int, int, ")
85 +
"const Vector&, const Vector&, const Vector&)",
86 string(
"There are ") +
to_str(nz_) +
" values but "
87 +
to_str(ind.GetLength()) +
" row or column indices.");
90 if (ptr.GetLength()-1 != Storage::GetFirst(i, j))
98 throw WrongDim(
string(
"Matrix_Sparse::Matrix_Sparse(int, int, ")
99 +
"const Vector&, const Vector&, const Vector&)",
100 string(
"The vector of start indices contains ")
101 +
to_str(ptr.GetLength()-1) +
string(
" row or column")
102 +
string(
" start indices (plus the number")
103 +
" of non-zero entries) but there are "
104 +
to_str(Storage::GetFirst(i, j))
105 +
" rows or columns (" +
to_str(i) +
" by "
106 +
to_str(j) +
" matrix).");
111 ||
static_cast<long int>(nz_-1) /
static_cast<long int>(j)
112 >=
static_cast<long int>(i)))
120 throw WrongDim(
string(
"Matrix_Sparse::Matrix_Sparse(int, int, ")
121 +
"const Vector&, const Vector&, const Vector&)",
122 string(
"There are more values (")
123 +
to_str(values.GetLength())
124 +
" values) than elements in the matrix ("
129 this->ptr_ = ptr.GetData();
130 this->ind_ = ind.GetData();
131 this->data_ = values.GetData();
140 template <
class T,
class Prop,
class Storage,
class Allocator>
158 template <
class T,
class Prop,
class Storage,
class Allocator>
161 #ifdef SELDON_CHECK_MEMORY
168 AllocatorLong::deallocate(ptr_, this->m_+1);
172 #ifdef SELDON_CHECK_MEMORY
180 #ifdef SELDON_CHECK_MEMORY
187 AllocatorInt::deallocate(ind_, this->nz_);
191 #ifdef SELDON_CHECK_MEMORY
199 #ifdef SELDON_CHECK_MEMORY
204 if (this->data_ != NULL)
206 Allocator::deallocate(this->data_, nz_);
210 #ifdef SELDON_CHECK_MEMORY
236 template <
class T,
class Prop,
class Storage,
class Allocator>
237 template <
class Storage0,
class Allocator0,
238 class Storage1,
class Allocator1,
239 class Storage2,
class Allocator2>
249 this->nz_ = values.GetLength();
251 #ifdef SELDON_CHECK_DIMENSIONS
254 if (ind.GetM() != nz_)
262 throw WrongDim(
string(
"Matrix_Sparse::SetData(int, int, ")
263 +
"const Vector&, const Vector&, const Vector&)",
264 string(
"There are ") +
to_str(nz_) +
" values but "
265 +
to_str(ind.GetLength()) +
" row or column indices.");
268 if (ptr.GetM()-1 != Storage::GetFirst(i, j))
276 throw WrongDim(
string(
"Matrix_Sparse::SetData(int, int, ")
277 +
"const Vector&, const Vector&, const Vector&)",
278 string(
"The vector of start indices contains ")
279 +
to_str(ptr.GetLength()-1) +
string(
" row or column")
280 +
string(
" start indices (plus the number")
281 +
" of non-zero entries) but there are "
282 +
to_str(Storage::GetFirst(i, j))
283 +
" rows or columns (" +
to_str(i) +
" by "
284 +
to_str(j) +
" matrix).");
289 ||
static_cast<long int>(nz_-1) /
static_cast<long int>(j)
290 >=
static_cast<long int>(i)))
298 throw WrongDim(
string(
"Matrix_Sparse::SetData(int, int, ")
299 +
"const Vector&, const Vector&, const Vector&)",
300 string(
"There are more values (")
301 +
to_str(values.GetLength())
302 +
" values) than elements in the matrix ("
307 this->ptr_ = ptr.GetData();
308 this->ind_ = ind.GetData();
309 this->data_ = values.GetData();
331 template <
class T,
class Prop,
class Storage,
class Allocator>
335 ::pointer values,
long* ptr,
int* ind)
344 this->data_ = values;
355 template <
class T,
class Prop,
class Storage,
class Allocator>
372 template <
class T,
class Prop,
class Storage,
class Allocator>
382 #ifdef SELDON_CHECK_MEMORY
387 ptr_ =
reinterpret_cast<long*
>( AllocatorLong::
388 allocate(Storage::GetFirst(i, j)+1,
this) );
390 #ifdef SELDON_CHECK_MEMORY
409 if (ptr_ == NULL && i != 0 && j != 0)
410 throw NoMemory(
"Matrix_Sparse::Reallocate(int, int)",
411 string(
"Unable to allocate ")
412 +
to_str(
sizeof(
int) * (Storage::GetFirst(i, j)+1) )
413 +
" bytes to store " +
to_str(Storage::GetFirst(i, j)+1)
414 +
" row or column start indices, for a "
419 for (
int k = 0; k <= Storage::GetFirst(i, j); k++)
431 template <
class T,
class Prop,
class Storage,
class Allocator>
441 #ifdef SELDON_CHECK_DIMENSIONS
450 throw WrongDim(
"Matrix_Sparse::Matrix_Sparse(int, int, int)",
451 "Invalid number of non-zero elements: " +
to_str(nz)
456 ||
static_cast<long int>(nz_-1) /
static_cast<long int>(j)
457 >=
static_cast<long int>(i)))
465 throw WrongDim(
"Matrix_Sparse::Matrix_Sparse(int, int, int)",
466 string(
"There are more values (") +
to_str(nz)
467 +
" values) than elements in the matrix ("
472 #ifdef SELDON_CHECK_MEMORY
477 ptr_ =
reinterpret_cast<long*
>( AllocatorLong::
478 allocate(Storage::GetFirst(i, j)+1,
this) );
480 #ifdef SELDON_CHECK_MEMORY
499 if (ptr_ == NULL && i != 0 && j != 0)
500 throw NoMemory(
"Matrix_Sparse::Matrix_Sparse(int, int, int)",
501 string(
"Unable to allocate ")
502 +
to_str(
sizeof(
int) * (Storage::GetFirst(i, j)+1) )
503 +
" bytes to store " +
to_str(Storage::GetFirst(i, j)+1)
504 +
" row or column start indices, for a "
508 #ifdef SELDON_CHECK_MEMORY
513 ind_ =
reinterpret_cast<int*
>( AllocatorInt::
514 allocate(nz_,
this) );
516 #ifdef SELDON_CHECK_MEMORY
524 deallocate(ptr_, Storage::GetFirst(i, j)+1);
535 deallocate(ptr_, Storage::GetFirst(i, j)+1);
539 if (ind_ == NULL && i != 0 && j != 0)
540 throw NoMemory(
"Matrix_Sparse::Matrix_Sparse(int, int, int)",
541 string(
"Unable to allocate ") +
to_str(
sizeof(
int) * nz)
542 +
" bytes to store " +
to_str(nz)
543 +
" row or column indices, for a "
547 #ifdef SELDON_CHECK_MEMORY
552 this->data_ = Allocator::allocate(nz_,
this);
554 #ifdef SELDON_CHECK_MEMORY
561 deallocate(ptr_, Storage::GetFirst(i, j)+1);
563 AllocatorInt::deallocate(ind_, nz);
567 if (this->data_ == NULL)
572 deallocate(ptr_, Storage::GetFirst(i, j)+1);
574 AllocatorInt::deallocate(ind_, nz);
577 if (this->data_ == NULL && i != 0 && j != 0)
578 throw NoMemory(
"Matrix_Sparse::Matrix_Sparse(int, int, int)",
579 string(
"Unable to allocate ") +
to_str(
sizeof(
int) * nz)
580 +
" bytes to store " +
to_str(nz) +
" values, for a "
584 for (
int k = 0; k <= Storage::GetFirst(i, j); k++)
595 template <
class T,
class Prop,
class Storage,
class Allocator>
598 if (Storage::GetFirst(i, j) < Storage::GetFirst(this->m_, this->n_))
599 Resize(i, j, ptr_[Storage::GetFirst(i, j)]);
612 template <
class T,
class Prop,
class Storage,
class Allocator>
616 #ifdef SELDON_CHECK_DIMENSIONS
625 throw WrongDim(
"Matrix_Sparse::Resize(int, int, int)",
626 "Invalid number of non-zero elements: " +
to_str(nz)
631 ||
static_cast<long int>(nz_-1) /
static_cast<long int>(j)
632 >=
static_cast<long int>(i)))
640 throw WrongDim(
"Matrix_Sparse::Resize(int, int, int)",
641 string(
"There are more values (") +
to_str(nz)
642 +
" values) than elements in the matrix ("
650 #ifdef SELDON_CHECK_MEMORY
655 =
reinterpret_cast<int*
>( AllocatorInt::
656 reallocate(ind_, nz,
this) );
658 #ifdef SELDON_CHECK_MEMORY
666 deallocate(ptr_, Storage::GetFirst(i, j)+1);
677 deallocate(ptr_, Storage::GetFirst(i, j)+1);
681 if (ind_ == NULL && i != 0 && j != 0)
682 throw NoMemory(
"Matrix_Sparse::Resize(int, int, int)",
683 string(
"Unable to allocate ") +
to_str(
sizeof(
int) * nz)
684 +
" bytes to store " +
to_str(nz)
685 +
" row or column indices, for a "
690 val.SetData(nz_, this->data_);
698 if (Storage::GetFirst(this->m_, this->n_) != Storage::GetFirst(i, j))
700 #ifdef SELDON_CHECK_MEMORY
705 ptr_ =
reinterpret_cast<long*
>( AllocatorLong::
706 reallocate(ptr_, Storage::GetFirst(i, j)+1) );
708 #ifdef SELDON_CHECK_MEMORY
727 if (ptr_ == NULL && i != 0 && j != 0)
728 throw NoMemory(
"Matrix_Sparse::Resize(int, int)",
729 string(
"Unable to allocate ")
730 +
to_str(
sizeof(
int) * (Storage::GetFirst(i, j)+1) )
731 +
" bytes to store " +
to_str(Storage::GetFirst(i, j)+1)
732 +
" row or column start indices, for a "
737 for (
int k = Storage::GetFirst(this->m_, this->n_);
738 k <= Storage::GetFirst(i, j); k++)
748 template <
class T,
class Prop,
class Storage,
class Allocator>
759 if ((i == 0)||(j == 0))
767 #ifdef SELDON_CHECK_DIMENSIONS
770 ||
static_cast<long int>(nz_-1) /
static_cast<long int>(j)
771 >=
static_cast<long int>(i)))
779 throw WrongDim(
"Matrix_Sparse::Matrix_Sparse(int, int, int)",
780 string(
"There are more values (") +
to_str(nz)
781 +
" values) than elements in the matrix ("
786 #ifdef SELDON_CHECK_MEMORY
791 ptr_ =
reinterpret_cast<long*
>( AllocatorLong::
792 allocate(Storage::GetFirst(i, j)+1) );
794 AllocatorLong::memorycpy(this->ptr_, A.ptr_,
795 Storage::GetFirst(i, j) + 1);
796 #ifdef SELDON_CHECK_MEMORY
815 if (ptr_ == NULL && i != 0 && j != 0)
816 throw NoMemory(
"Matrix_Sparse::Matrix_Sparse(int, int, int)",
817 string(
"Unable to allocate ")
818 +
to_str(
sizeof(
int) * (Storage::GetFirst(i, j)+1) )
819 +
" bytes to store " +
to_str(Storage::GetFirst(i, j)+1)
820 +
" row or column start indices, for a "
824 #ifdef SELDON_CHECK_MEMORY
829 ind_ =
reinterpret_cast<int*
>( AllocatorInt::
830 allocate(nz_,
this) );
831 AllocatorInt::memorycpy(this->ind_, A.ind_, nz_);
833 #ifdef SELDON_CHECK_MEMORY
841 deallocate(ptr_, Storage::GetFirst(i, j)+1);
852 deallocate(ptr_, Storage::GetFirst(i, j)+1);
856 if (ind_ == NULL && i != 0 && j != 0)
857 throw NoMemory(
"Matrix_Sparse::Matrix_Sparse(int, int, int)",
858 string(
"Unable to allocate ") +
to_str(
sizeof(
int) * nz)
859 +
" bytes to store " +
to_str(nz)
860 +
" row or column indices, for a "
864 #ifdef SELDON_CHECK_MEMORY
869 this->data_ = Allocator::allocate(nz_,
this);
870 Allocator::memorycpy(this->data_, A.data_, nz_);
872 #ifdef SELDON_CHECK_MEMORY
879 deallocate(ptr_, Storage::GetFirst(i, j)+1);
881 AllocatorInt::deallocate(ind_, nz);
885 if (this->data_ == NULL)
890 deallocate(ptr_, Storage::GetFirst(i, j)+1);
892 AllocatorInt::deallocate(ind_, nz);
895 if (this->data_ == NULL && i != 0 && j != 0)
896 throw NoMemory(
"Matrix_Sparse::Matrix_Sparse(int, int, int)",
897 string(
"Unable to allocate ") +
to_str(
sizeof(
int) * nz)
898 +
" bytes to store " +
to_str(nz) +
" values, for a "
906 template<
class T,
class Prop,
class Storage,
class Allocator>
909 size_t taille =
sizeof(*this) + this->GetPtrSize()*
sizeof(long);
910 int coef =
sizeof(T) +
sizeof(
int);
911 taille += coef*size_t(this->nz_);
917 template<
class T,
class Prop,
class Storage,
class Allocator>
920 Ptr.Reallocate(this->m_+1);
921 for (
int i = 0; i <= this->m_; i++)
938 template <
class T,
class Prop,
class Storage,
class Allocator>
939 const typename Matrix_Sparse<T, Prop, Storage, Allocator>::value_type
943 #ifdef SELDON_CHECK_BOUNDS
944 if (i < 0 || i >= this->m_)
945 throw WrongRow(
"Matrix_Sparse::operator()",
946 string(
"Index should be in [0, ") +
to_str(this->m_-1)
947 +
"], but is equal to " +
to_str(i) +
".");
948 if (j < 0 || j >= this->n_)
949 throw WrongCol(
"Matrix_Sparse::operator()",
950 string(
"Index should be in [0, ") +
to_str(this->n_-1)
951 +
"], but is equal to " +
to_str(j) +
".");
957 SetComplexZero(zero);
959 a = ptr_[Storage::GetFirst(i, j)];
960 b = ptr_[Storage::GetFirst(i, j) + 1];
965 l = Storage::GetSecond(i, j);
967 for (k = a; (k < b-1) && (ind_[k] < l); k++);
970 return this->data_[k];
985 template <
class T,
class Prop,
class Storage,
class Allocator>
986 typename Matrix_Sparse<T, Prop, Storage, Allocator>::value_type&
990 #ifdef SELDON_CHECK_BOUNDS
991 if (i < 0 || i >= this->m_)
992 throw WrongRow(
"Matrix_Sparse::Val(int, int)",
993 string(
"Index should be in [0, ") +
to_str(this->m_-1)
994 +
"], but is equal to " +
to_str(i) +
".");
995 if (j < 0 || j >= this->n_)
996 throw WrongCol(
"Matrix_Sparse::Val(int, int)",
997 string(
"Index should be in [0, ") +
to_str(this->n_-1)
998 +
"], but is equal to " +
to_str(j) +
".");
1004 a = ptr_[Storage::GetFirst(i, j)];
1005 b = ptr_[Storage::GetFirst(i, j) + 1];
1009 "No reference to element (" +
to_str(i) +
", "
1011 +
") can be returned: it is a zero entry.");
1013 l = Storage::GetSecond(i, j);
1015 for (k = a; (k < b-1) && (ind_[k] < l); k++);
1018 return this->data_[k];
1021 "No reference to element (" +
to_str(i) +
", "
1023 +
") can be returned: it is a zero entry.");
1036 template <
class T,
class Prop,
class Storage,
class Allocator>
1037 const typename Matrix_Sparse<T, Prop, Storage, Allocator>::value_type&
1041 #ifdef SELDON_CHECK_BOUNDS
1042 if (i < 0 || i >= this->m_)
1043 throw WrongRow(
"Matrix_Sparse::Val(int, int)",
1044 string(
"Index should be in [0, ") +
to_str(this->m_-1)
1045 +
"], but is equal to " +
to_str(i) +
".");
1046 if (j < 0 || j >= this->n_)
1047 throw WrongCol(
"Matrix_Sparse::Val(int, int)",
1048 string(
"Index should be in [0, ") +
to_str(this->n_-1)
1049 +
"], but is equal to " +
to_str(j) +
".");
1055 a = ptr_[Storage::GetFirst(i, j)];
1056 b = ptr_[Storage::GetFirst(i, j) + 1];
1060 "No reference to element (" +
to_str(i) +
", "
1062 +
") can be returned: it is a zero entry.");
1064 l = Storage::GetSecond(i, j);
1066 for (k = a; (k < b-1) && (ind_[k] < l); k++);
1069 return this->data_[k];
1072 "No reference to element (" +
to_str(i) +
", "
1074 +
") can be returned: it is a zero entry.");
1086 template <
class T,
class Prop,
class Storage,
class Allocator>
1087 typename Matrix_Sparse<T, Prop, Storage, Allocator>::value_type&
1091 #ifdef SELDON_CHECK_BOUNDS
1092 if (i < 0 || i >= this->m_)
1093 throw WrongRow(
"Matrix_Sparse::Get(int, int)",
1094 string(
"Index should be in [0, ") +
to_str(this->m_-1)
1095 +
"], but is equal to " +
to_str(i) +
".");
1096 if (j < 0 || j >= this->n_)
1097 throw WrongCol(
"Matrix_Sparse::Get(int, int)",
1098 string(
"Index should be in [0, ") +
to_str(this->n_-1)
1099 +
"], but is equal to " +
to_str(j) +
".");
1105 a = ptr_[Storage::GetFirst(i, j)];
1106 b = ptr_[Storage::GetFirst(i, j) + 1];
1110 l = Storage::GetSecond(i, j);
1112 for (k = a; (k < b) && (ind_[k] < l); k++);
1114 if ( (k < b) && (ind_[k] == l))
1115 return this->data_[k];
1121 Resize(this->m_, this->n_, nz_+1);
1123 for (
int m = Storage::GetFirst(i, j)+1;
1124 m <= Storage::GetFirst(this->m_, this->n_); m++)
1127 for (
long m = nz_-1; m >= k+1; m--)
1129 ind_[m] = ind_[m-1];
1130 this->data_[m] = this->data_[m-1];
1133 ind_[k] = Storage::GetSecond(i, j);
1136 SetComplexZero(this->data_[k]);
1138 return this->data_[k];
1149 template <
class T,
class Prop,
class Storage,
class Allocator>
1152 Allocator::memoryset(this->data_,
char(0),
1153 this->nz_ *
sizeof(value_type));
1161 template <
class T,
class Prop,
class Storage,
class Allocator>
1166 long nz = min(m, n);
1177 T one; SetComplexOne(one);
1181 for (i = 0; i < nz + 1; i++)
1184 for (i = nz + 1; i < ptr.GetM(); i++)
1187 SetData(m, n, values, ptr, ind);
1195 template <
class T,
class Prop,
class Storage,
class Allocator>
1198 for (
long i = 0; i < this->GetDataSize(); i++)
1207 template <
class T,
class Prop,
class Storage,
class Allocator>
1213 for (
long i = 0; i < this->GetDataSize(); i++)
1214 this->data_[i] = x_;
1222 template <
class T,
class Prop,
class Storage,
class Allocator>
1225 #ifndef SELDON_WITHOUT_REINIT_RANDOM
1228 for (
long i = 0; i < this->GetDataSize(); i++)
1242 template <
class T,
class Prop,
class Storage,
class Allocator>
1246 if (this->m_ == 0 || this->n_ == 0)
1252 set<pair<int, int> > skeleton;
1253 set<pair<int, int> >::iterator it;
1255 #ifndef SELDON_WITHOUT_REINIT_RANDOM
1260 while (
static_cast<int>(skeleton.size()) != Nelement)
1261 skeleton.insert(make_pair(rand() % this->m_, rand() % this->n_));
1264 for (it = skeleton.begin(); it != skeleton.end(); it++)
1276 ConvertMatrix_from_Coordinates(i, j, value, leaf_class, 0);
1291 template <
class T,
class Prop,
class Storage,
class Allocator>
1295 if (this->m_ == 0 || this->n_ == 0)
1302 #ifndef SELDON_WITHOUT_REINIT_RANDOM
1306 for (
long l = 0; l < Nelement; l++)
1308 i(l) = rand() % this->m_;
1309 j(l) = rand() % this->n_;
1315 ConvertMatrix_from_Coordinates(i, j, value, leaf_class, 0);
1325 template <
class T,
class Prop,
class Storage,
class Allocator>
1328 for (
int i = 0; i < this->m_; i++)
1330 for (
int j = 0; j < this->n_; j++)
1331 cout << (*
this)(i, j) <<
"\t";
1342 template <
class T,
class Prop,
class Storage,
class Allocator>
1346 ofstream FileStream;
1347 FileStream.open(FileName.c_str(), ofstream::binary);
1349 #ifdef SELDON_CHECK_IO
1351 if (!FileStream.is_open())
1352 throw IOError(
"Matrix_Sparse::Write(string FileName)",
1353 string(
"Unable to open file \"") + FileName +
"\".");
1356 this->Write(FileStream);
1367 template <
class T,
class Prop,
class Storage,
class Allocator>
1371 #ifdef SELDON_CHECK_IO
1373 if (!FileStream.good())
1374 throw IOError(
"Matrix_Sparse::Write(ofstream& FileStream)",
1375 "Stream is not ready.");
1378 FileStream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&this->m_)),
1380 FileStream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&this->n_)),
1382 FileStream.write(
reinterpret_cast<char*
>(
const_cast<long*
>(&this->nz_)),
1385 FileStream.write(
reinterpret_cast<char*
>(this->ptr_),
1386 sizeof(
long)*(Storage::GetFirst(this->m_, this->n_)+1));
1387 FileStream.write(
reinterpret_cast<char*
>(this->ind_),
1388 sizeof(
int)*this->nz_);
1389 FileStream.write(
reinterpret_cast<char*
>(this->data_),
1390 sizeof(T)*this->nz_);
1404 template <
class T,
class Prop,
class Storage,
class Allocator>
1408 ofstream FileStream; FileStream.precision(14);
1409 FileStream.open(FileName.c_str());
1412 FileStream.precision(cout.precision());
1414 #ifdef SELDON_CHECK_IO
1416 if (!FileStream.is_open())
1417 throw IOError(
"Matrix_Sparse::Write(string FileName)",
1418 string(
"Unable to open file \"") + FileName +
"\".");
1421 this->WriteText(FileStream, cplx);
1437 template <
class T,
class Prop,
class Storage,
class Allocator>
1442 #ifdef SELDON_CHECK_IO
1444 if (!FileStream.good())
1445 throw IOError(
"Matrix_Sparse::Write(ofstream& FileStream)",
1446 "Stream is not ready.");
1453 T zero;
int index = 1;
1454 WriteCoordinateMatrix(leaf_class, FileStream, zero, index, cplx);
1463 template <
class T,
class Prop,
class Storage,
class Allocator>
1467 ifstream FileStream;
1468 FileStream.open(FileName.c_str(), ifstream::binary);
1470 #ifdef SELDON_CHECK_IO
1472 if (!FileStream.is_open())
1473 throw IOError(
"Matrix_Sparse::Read(string FileName)",
1474 string(
"Unable to open file \"") + FileName +
"\".");
1477 this->Read(FileStream);
1488 template <
class T,
class Prop,
class Storage,
class Allocator>
1493 #ifdef SELDON_CHECK_IO
1495 if (!FileStream.good())
1496 throw IOError(
"Matrix_Sparse::Read(istream& FileStream)",
1497 "Stream is not ready.");
1501 FileStream.read(
reinterpret_cast<char*
>(&m),
sizeof(
int));
1502 FileStream.read(
reinterpret_cast<char*
>(&n),
sizeof(
int));
1503 FileStream.read(
reinterpret_cast<char*
>(&nz),
sizeof(
long));
1505 Reallocate(m, n, nz);
1507 FileStream.read(
reinterpret_cast<char*
>(ptr_),
1508 sizeof(
long)*(Storage::GetFirst(m, n)+1));
1509 FileStream.read(
reinterpret_cast<char*
>(ind_),
sizeof(
int)*nz);
1510 FileStream.read(
reinterpret_cast<char*
>(this->data_),
sizeof(T)*nz);
1512 #ifdef SELDON_CHECK_IO
1514 if (!FileStream.good())
1515 throw IOError(
"Matrix_Sparse::Read(istream& FileStream)",
1516 string(
"Input operation failed.")
1517 +
string(
" The input file may have been removed")
1518 +
" or may not contain enough data.");
1532 template <
class T,
class Prop,
class Storage,
class Allocator>
1536 ifstream FileStream;
1537 FileStream.open(FileName.c_str());
1539 #ifdef SELDON_CHECK_IO
1541 if (!FileStream.is_open())
1542 throw IOError(
"Matrix_Sparse::ReadText(string FileName)",
1543 string(
"Unable to open file \"") + FileName +
"\".");
1546 this->ReadText(FileStream, cplx);
1557 template <
class T,
class Prop,
class Storage,
class Allocator>
1564 T zero;
int index = 1;
1565 ReadCoordinateMatrix(leaf_class, FileStream, zero, index, -1, cplx);
1571 #define SELDON_FILE_MATRIX_SPARSE_CXX