21 #ifndef SELDON_FILE_MATRIX_SYMCOMPLEXSPARSE_CXX
23 #include "Matrix_SymComplexSparse.hxx"
37 template <
class T,
class Prop,
class Storage,
class Allocator>
59 template <
class T,
class Prop,
class Storage,
class Allocator>
89 template <
class T,
class Prop,
class Storage,
class Allocator>
103 Reallocate(i, i, real_nz, imag_nz);
127 template <
class T,
class Prop,
class Storage,
class Allocator>
128 template <
class Storage0,
class Allocator0,
129 class Storage1,
class Allocator1,
130 class Storage2,
class Allocator2>
141 real_nz_ = real_values.GetM();
142 imag_nz_ = imag_values.GetM();
144 #ifdef SELDON_CHECK_DIMENSIONS
147 if (real_ind.GetM() != real_nz_)
157 this->real_data_ = NULL;
158 this->imag_data_ = NULL;
159 throw WrongDim(
string(
"Matrix_SymComplexSparse::")
160 +
string(
"Matrix_SymComplexSparse(int, int, ")
161 +
string(
"const Vector&, const Vector&, const Vector&")
162 +
", const Vector&, const Vector&, const Vector&)",
163 string(
"There are ") +
to_str(real_nz_)
164 +
" values (real part) but "
166 +
" row or column indices.");
169 if (imag_ind.GetM() != imag_nz_)
179 this->real_data_ = NULL;
180 this->imag_data_ = NULL;
181 throw WrongDim(
string(
"Matrix_SymComplexSparse::")
182 +
string(
"Matrix_SymComplexSparse(int, int, ")
183 +
string(
"const Vector&, const Vector&, const Vector&")
184 +
", const Vector&, const Vector&, const Vector&)",
185 string(
"There are ") +
to_str(imag_nz_)
186 +
" values (imaginary part) but "
188 +
" row or column indices.");
191 if (real_ptr.GetM() - 1 != i)
201 this->real_data_ = NULL;
202 this->imag_data_ = NULL;
203 throw WrongDim(
string(
"Matrix_SymComplexSparse::")
204 +
string(
"Matrix_SymComplexSparse(int, int, ")
205 +
string(
"const Vector&, const Vector&, const Vector&")
206 +
", const Vector&, const Vector&, const Vector&)",
207 string(
"The vector of start indices (real part)")
208 +
" contains " +
to_str(real_ptr.GetM()-1)
209 +
string(
" row or column start indices (plus the")
210 +
" number of non-zero entries) but there are "
211 +
to_str(i) +
" rows or columns ("
215 if (imag_ptr.GetM() - 1 != i)
225 this->real_data_ = NULL;
226 this->imag_data_ = NULL;
227 throw WrongDim(
string(
"Matrix_SymComplexSparse::")
228 +
string(
"Matrix_SymComplexSparse(int, int, ")
229 +
string(
"const Vector&, const Vector&, const Vector&")
230 +
", const Vector&, const Vector&, const Vector&)",
231 string(
"The vector of start indices (imaginary part)")
232 +
" contains " +
to_str(imag_ptr.GetM()-1)
233 +
string(
" row or column start indices (plus the")
234 +
" number of non-zero entries) but there are "
235 +
to_str(i) +
" rows or columns ("
239 if ( (
static_cast<long int>(2 * real_nz_ - 2)
240 /
static_cast<long int>(i + 1)
241 >=
static_cast<long int>(i)) ||
242 (
static_cast<long int>(2 * imag_nz_ - 2)
243 /
static_cast<long int>(i + 1)
244 >=
static_cast<long int>(i)) )
254 this->real_data_ = NULL;
255 this->imag_data_ = NULL;
256 throw WrongDim(
string(
"Matrix_SymComplexSparse::")
257 +
string(
"Matrix_SymComplexSparse(int, int, ")
258 +
string(
"const Vector&, const Vector&, const Vector&")
259 +
", const Vector&, const Vector&, const Vector&)",
260 string(
"There are more values (")
261 +
to_str(real_values.GetM())
262 +
" values for the real part and "
263 +
to_str(real_values.GetM()) +
" values for"
264 +
string(
" the imaginary part) than elements in the")
269 this->real_ptr_ = real_ptr.GetData();
270 this->imag_ptr_ = imag_ptr.GetData();
271 this->real_ind_ = real_ind.GetData();
272 this->imag_ind_ = imag_ind.GetData();
273 this->real_data_ = real_values.GetData();
274 this->imag_data_ = imag_values.GetData();
280 real_values.Nullify();
281 imag_values.Nullify();
286 template <
class T,
class Prop,
class Storage,
class Allocator>
289 Storage, Allocator>& A)
316 template <
class T,
class Prop,
class Storage,
class Allocator>
319 #ifdef SELDON_CHECK_MEMORY
324 if (real_ptr_ != NULL)
326 AllocatorLong::deallocate(real_ptr_, this->m_+1);
330 #ifdef SELDON_CHECK_MEMORY
338 #ifdef SELDON_CHECK_MEMORY
343 if (imag_ptr_ != NULL)
345 AllocatorLong::deallocate(imag_ptr_, this->m_+1);
349 #ifdef SELDON_CHECK_MEMORY
357 #ifdef SELDON_CHECK_MEMORY
362 if (real_ind_ != NULL)
364 AllocatorInt::deallocate(real_ind_, this->real_nz_);
368 #ifdef SELDON_CHECK_MEMORY
376 #ifdef SELDON_CHECK_MEMORY
381 if (imag_ind_ != NULL)
383 AllocatorInt::deallocate(imag_ind_, this->imag_nz_);
387 #ifdef SELDON_CHECK_MEMORY
395 #ifdef SELDON_CHECK_MEMORY
400 if (this->real_data_ != NULL)
402 Allocator::deallocate(this->real_data_, real_nz_);
403 this->real_data_ = NULL;
406 #ifdef SELDON_CHECK_MEMORY
411 this->real_data_ = NULL;
415 #ifdef SELDON_CHECK_MEMORY
420 if (this->imag_data_ != NULL)
422 Allocator::deallocate(this->imag_data_, imag_nz_);
423 this->imag_data_ = NULL;
426 #ifdef SELDON_CHECK_MEMORY
431 this->imag_data_ = NULL;
461 template <
class T,
class Prop,
class Storage,
class Allocator>
462 template <
class Storage0,
class Allocator0,
463 class Storage1,
class Allocator1,
464 class Storage2,
class Allocator2>
477 real_nz_ = real_values.GetM();
478 imag_nz_ = imag_values.GetM();
480 #ifdef SELDON_CHECK_DIMENSIONS
483 if (real_ind.GetM() != real_nz_)
493 this->real_data_ = NULL;
494 this->imag_data_ = NULL;
495 throw WrongDim(
string(
"Matrix_SymComplexSparse::SetData(int, int, ")
496 +
string(
"const Vector&, const Vector&, const Vector&")
497 +
", const Vector&, const Vector&, const Vector&)",
498 string(
"There are ") +
to_str(real_nz_)
499 +
" values (real part) but "
501 +
" row or column indices.");
504 if (imag_ind.GetM() != imag_nz_)
514 this->real_data_ = NULL;
515 this->imag_data_ = NULL;
516 throw WrongDim(
string(
"Matrix_SymComplexSparse::SetData(int, int, ")
517 +
string(
"const Vector&, const Vector&, const Vector&")
518 +
", const Vector&, const Vector&, const Vector&)",
519 string(
"There are ") +
to_str(imag_nz_)
520 +
" values (imaginary part) but "
522 +
" row or column indices.");
525 if (real_ptr.GetM() - 1 != i)
535 this->real_data_ = NULL;
536 this->imag_data_ = NULL;
537 throw WrongDim(
string(
"Matrix_SymComplexSparse::SetData(int, int, ")
538 +
string(
"const Vector&, const Vector&, const Vector&")
539 +
", const Vector&, const Vector&, const Vector&)",
540 string(
"The vector of start indices (real part)")
541 +
" contains " +
to_str(real_ptr.GetM() - 1)
542 +
string(
" row or column start indices (plus the")
543 +
" number of non-zero entries) but there are "
544 +
to_str(i) +
" rows or columns ("
548 if (imag_ptr.GetM() - 1 != i)
558 this->real_data_ = NULL;
559 this->imag_data_ = NULL;
560 throw WrongDim(
string(
"Matrix_SymComplexSparse::SetData(int, int, ")
561 +
string(
"const Vector&, const Vector&, const Vector&")
562 +
", const Vector&, const Vector&, const Vector&)",
563 string(
"The vector of start indices (imaginary part)")
564 +
" contains " +
to_str(imag_ptr.GetM()-1)
565 +
string(
" row or column start indices (plus the")
566 +
" number of non-zero entries) but there are "
567 +
to_str(i) +
" rows or columns ("
571 if ( (
static_cast<long int>(2 * real_nz_ - 2) /
static_cast<long int>(i)
572 >=
static_cast<long int>(i + 1)) ||
573 (
static_cast<long int>(2 * imag_nz_ - 2) /
static_cast<long int>(i)
574 >=
static_cast<long int>(i + 1)) )
584 this->real_data_ = NULL;
585 this->imag_data_ = NULL;
586 throw WrongDim(
string(
"Matrix_SymComplexSparse::SetData(int, int, ")
587 +
string(
"const Vector&, const Vector&, const Vector&")
588 +
", const Vector&, const Vector&, const Vector&)",
589 string(
"There are more values (")
590 +
to_str(real_values.GetM())
591 +
" values for the real part and "
592 +
to_str(real_values.GetM()) +
string(
" values")
593 +
string(
" for the imaginary part) than elements in")
594 +
" the matrix (" +
to_str(i)
595 +
" by " +
to_str(i) +
").");
599 this->real_ptr_ = real_ptr.GetData();
600 this->imag_ptr_ = imag_ptr.GetData();
601 this->real_ind_ = real_ind.GetData();
602 this->imag_ind_ = imag_ind.GetData();
603 this->real_data_ = real_values.GetData();
604 this->imag_data_ = imag_values.GetData();
610 real_values.Nullify();
611 imag_values.Nullify();
638 template <
class T,
class Prop,
class Storage,
class Allocator>
642 ::pointer real_values,
643 long* real_ptr,
int* real_ind,
long imag_nz,
645 ::pointer imag_values,
646 long* imag_ptr,
int* imag_ind)
653 this->real_nz_ = real_nz;
654 this->imag_nz_ = imag_nz;
656 real_data_ = real_values;
657 imag_data_ = imag_values;
658 real_ind_ = real_ind;
659 imag_ind_ = imag_ind;
660 real_ptr_ = real_ptr;
661 imag_ptr_ = imag_ptr;
670 template <
class T,
class Prop,
class Storage,
class Allocator>
688 template <
class T,
class Prop,
class Storage,
class Allocator>
699 #ifdef SELDON_CHECK_MEMORY
705 =
reinterpret_cast<long*
>( AllocatorLong::allocate(i+1) );
708 =
reinterpret_cast<long*
>( AllocatorLong::allocate(i+1) );
710 #ifdef SELDON_CHECK_MEMORY
725 if ((real_ptr_ == NULL) || (imag_ptr_ == NULL))
738 if (((real_ptr_ == NULL) || (imag_ptr_ == NULL)) && i != 0 && j != 0)
739 throw NoMemory(
"Matrix_SymComplexSparse::Reallocate(int, int)",
740 string(
"Unable to allocate ")
741 +
to_str(
sizeof(
int) * (i+1) )
742 +
" bytes to store " +
to_str(i+1)
743 +
" row or column start indices, for a "
748 for (
int k = 0; k <= i; k++)
757 template <
class T,
class Prop,
class Storage,
class Allocator>
766 this->real_nz_ = real_nz;
767 this->imag_nz_ = imag_nz;
769 #ifdef SELDON_CHECK_DIMENSIONS
770 if ( (
static_cast<long int>(2 * real_nz_ - 2) /
static_cast<long int>(i+1)
771 >=
static_cast<long int>(i)) ||
772 (
static_cast<long int>(2 * imag_nz_ - 2) /
static_cast<long int>(i+1)
773 >=
static_cast<long int>(i)) )
783 this->real_data_ = NULL;
784 this->imag_data_ = NULL;
785 throw WrongDim(
string(
"Matrix_SymComplexSparse::")
786 +
"Matrix_SymComplexSparse(int, int, int, int)",
787 string(
"There are more values to be stored (")
788 +
to_str(real_nz) +
" values for the real part and "
789 +
to_str(imag_nz) +
string(
" values for the imaginary")
790 +
" part) than elements in the matrix ("
795 #ifdef SELDON_CHECK_MEMORY
801 reinterpret_cast<long*
>( AllocatorLong::allocate(i + 1) );
803 #ifdef SELDON_CHECK_MEMORY
815 this->real_data_ = NULL;
816 this->imag_data_ = NULL;
818 if (real_ptr_ == NULL)
827 this->real_data_ = NULL;
828 this->imag_data_ = NULL;
830 if (real_ptr_ == NULL && i != 0)
831 throw NoMemory(
string(
"Matrix_SymComplexSparse::")
832 +
"Matrix_SymComplexSparse(int, int, int, int)",
833 string(
"Unable to allocate ")
834 +
to_str(
sizeof(
int) * (i + 1)) +
" bytes to store "
835 +
to_str(i + 1) +
string(
" row or column")
836 +
" start indices (for the real part), for a "
840 #ifdef SELDON_CHECK_MEMORY
846 reinterpret_cast<long*
>( AllocatorLong::allocate(i + 1) );
848 #ifdef SELDON_CHECK_MEMORY
856 AllocatorLong::deallocate(real_ptr_, i+1);
861 this->real_data_ = NULL;
862 this->imag_data_ = NULL;
864 if (imag_ptr_ == NULL)
870 AllocatorLong::deallocate(real_ptr_, i+1);
874 this->real_data_ = NULL;
875 this->imag_data_ = NULL;
877 if (imag_ptr_ == NULL && i != 0)
878 throw NoMemory(
string(
"Matrix_SymComplexSparse::")
879 +
"Matrix_SymComplexSparse(int, int, int, int)",
880 string(
"Unable to allocate ")
881 +
to_str(
sizeof(
int) * (i + 1) ) +
" bytes to store "
882 +
to_str(i + 1) +
string(
" row or column")
883 +
" start indices (for the imaginary part), for a "
887 #ifdef SELDON_CHECK_MEMORY
892 real_ind_ =
reinterpret_cast<int*
>( AllocatorInt::allocate(real_nz_) );
894 #ifdef SELDON_CHECK_MEMORY
902 AllocatorLong::deallocate(real_ptr_, i+1);
903 AllocatorLong::deallocate(imag_ptr_, i+1);
908 this->real_data_ = NULL;
909 this->imag_data_ = NULL;
911 if (real_ind_ == NULL)
917 AllocatorLong::deallocate(real_ptr_, i+1);
918 AllocatorLong::deallocate(imag_ptr_, i+1);
921 this->real_data_ = NULL;
922 this->imag_data_ = NULL;
924 if (real_ind_ == NULL && i != 0)
925 throw NoMemory(
string(
"Matrix_SymComplexSparse::")
926 +
"Matrix_SymComplexSparse(int, int, int, int)",
927 string(
"Unable to allocate ")
928 +
to_str(
sizeof(
int) * real_nz) +
" bytes to store "
930 +
" row or column indices (real part), for a "
934 #ifdef SELDON_CHECK_MEMORY
940 reinterpret_cast<int*
>( AllocatorInt::allocate(imag_nz_) );
942 #ifdef SELDON_CHECK_MEMORY
950 AllocatorLong::deallocate(real_ptr_, i+1);
951 AllocatorLong::deallocate(imag_ptr_, i+1);
954 AllocatorInt::deallocate(imag_ind_, imag_nz);
957 this->real_data_ = NULL;
958 this->imag_data_ = NULL;
960 if (real_ind_ == NULL)
966 AllocatorLong::deallocate(real_ptr_, i+1);
967 AllocatorLong::deallocate(imag_ptr_, i+1);
970 AllocatorInt::deallocate(imag_ind_, imag_nz);
972 this->real_data_ = NULL;
973 this->imag_data_ = NULL;
975 if (imag_ind_ == NULL && i != 0)
976 throw NoMemory(
string(
"Matrix_SymComplexSparse::")
977 +
"Matrix_SymComplexSparse(int, int, int, int)",
978 string(
"Unable to allocate ")
979 +
to_str(
sizeof(
int) * imag_nz) +
" bytes to store "
981 +
" row or column indices (imaginary part), for a "
985 #ifdef SELDON_CHECK_MEMORY
990 this->real_data_ = Allocator::allocate(real_nz_,
this);
992 #ifdef SELDON_CHECK_MEMORY
998 AllocatorLong::deallocate(real_ptr_, i+1);
999 AllocatorLong::deallocate(imag_ptr_, i+1);
1002 AllocatorInt::deallocate(real_ind_, real_nz);
1003 AllocatorInt::deallocate(imag_ind_, imag_nz);
1006 this->real_data_ = NULL;
1007 this->imag_data_ = NULL;
1009 if (real_data_ == NULL)
1013 AllocatorLong::deallocate(real_ptr_, i+1);
1014 AllocatorLong::deallocate(imag_ptr_, i+1);
1017 AllocatorInt::deallocate(real_ind_, real_nz);
1018 AllocatorInt::deallocate(imag_ind_, imag_nz);
1023 if (real_data_ == NULL && i != 0)
1024 throw NoMemory(
string(
"Matrix_SymComplexSparse::")
1025 +
"Matrix_SymComplexSparse(int, int, int, int)",
1026 string(
"Unable to allocate ")
1027 +
to_str(
sizeof(
int) * real_nz) +
" bytes to store "
1028 +
to_str(real_nz) +
" values (real part), for a "
1032 #ifdef SELDON_CHECK_MEMORY
1037 this->imag_data_ = Allocator::allocate(imag_nz_,
this);
1039 #ifdef SELDON_CHECK_MEMORY
1045 AllocatorLong::deallocate(real_ptr_, i+1);
1046 AllocatorLong::deallocate(imag_ptr_, i+1);
1049 AllocatorInt::deallocate(real_ind_, real_nz);
1050 AllocatorInt::deallocate(imag_ind_, imag_nz);
1053 Allocator::deallocate(this->real_data_, real_nz_);
1054 this->real_data_ = NULL;
1055 this->imag_data_ = NULL;
1057 if (real_data_ == NULL)
1061 AllocatorLong::deallocate(real_ptr_, i+1);
1062 AllocatorLong::deallocate(imag_ptr_, i+1);
1065 AllocatorInt::deallocate(real_ind_, real_nz);
1066 AllocatorInt::deallocate(imag_ind_, imag_nz);
1069 Allocator::deallocate(this->real_data_, real_nz_);
1072 if (imag_data_ == NULL && i != 0)
1073 throw NoMemory(
string(
"Matrix_SymComplexSparse::")
1074 +
"Matrix_SymComplexSparse(int, int, int, int)",
1075 string(
"Unable to allocate ")
1076 +
to_str(
sizeof(
int) * imag_nz) +
" bytes to store "
1077 +
to_str(imag_nz) +
" values (imaginary part), for a "
1082 for (
int k = 0; k <= Storage::GetFirst(i, j); k++)
1095 template <
class T,
class Prop,
class Storage,
class Allocator>
1100 Resize(i, i, real_ptr_[i], imag_ptr_[i]);
1102 Resize(i, i, real_nz_, imag_nz_);
1112 template <
class T,
class Prop,
class Storage,
class Allocator>
1116 #ifdef SELDON_CHECK_DIMENSIONS
1117 if (real_nz < 0 || imag_nz < 0)
1127 this->real_data_ = NULL;
1128 this->imag_data_ = NULL;
1129 throw WrongDim(
string(
"Matrix_SymComplexSparse::")
1130 +
"Resize(int, int, int, int)",
1131 "Invalid number of non-zero elements: "
1132 +
to_str(real_nz) +
" in the real part and "
1133 +
to_str(imag_nz) +
" in the imaginary part.");
1137 ||
static_cast<long int>(real_nz-1) /
static_cast<long int>(j)
1138 >=
static_cast<long int>(i)))
1142 ||
static_cast<long int>(imag_nz-1) /
static_cast<long int>(j)
1143 >=
static_cast<long int>(i))))
1153 this->real_data_ = NULL;
1154 this->imag_data_ = NULL;
1155 throw WrongDim(
string(
"Matrix_SymComplexSparse::")
1156 +
"Resize(int, int, int, int)",
1157 string(
"There are more values (") +
to_str(real_nz)
1158 +
" values for the real part and " +
to_str(imag_nz)
1159 +
string(
" values for the imaginary part) than")
1160 +
" elements in the matrix (" +
to_str(i) +
" by "
1167 #ifdef SELDON_CHECK_MEMORY
1173 =
reinterpret_cast<long*
>( AllocatorLong::
1174 reallocate(real_ptr_, (i+1)) );
1176 #ifdef SELDON_CHECK_MEMORY
1188 this->real_data_ = NULL;
1189 this->imag_data_ = NULL;
1191 if (real_ptr_ == NULL)
1200 this->real_data_ = NULL;
1201 this->imag_data_ = NULL;
1203 if (real_ptr_ == NULL && i != 0 && j != 0)
1204 throw NoMemory(
string(
"Matrix_SymComplexSparse::")
1205 +
"Resize(int, int, int, int)",
1206 string(
"Unable to allocate ")
1207 +
to_str(
sizeof(
int) * (i+1))
1208 +
" bytes to store " +
to_str(i+1)
1209 +
string(
" row or column start indices (for the real")
1214 #ifdef SELDON_CHECK_MEMORY
1220 reinterpret_cast<long*
>( AllocatorLong::
1221 reallocate(imag_ptr_, (i+1)) );
1223 #ifdef SELDON_CHECK_MEMORY
1231 AllocatorLong::deallocate(real_ptr_, i+1);
1236 this->real_data_ = NULL;
1237 this->imag_data_ = NULL;
1239 if (imag_ptr_ == NULL)
1245 AllocatorLong::deallocate(real_ptr_, i+1);
1249 this->real_data_ = NULL;
1250 this->imag_data_ = NULL;
1252 if (imag_ptr_ == NULL && i != 0 && j != 0)
1253 throw NoMemory(
string(
"Matrix_SymComplexSparse::")
1254 +
"Resize(int, int, int, int)",
1255 string(
"Unable to allocate ")
1256 +
to_str(
sizeof(
int) * (i+1))
1257 +
" bytes to store " +
to_str(i+1)
1258 +
string(
" row or column start indices (for the")
1259 +
string(
" imaginary part), for a ")
1264 if (real_nz != real_nz_)
1266 #ifdef SELDON_CHECK_MEMORY
1272 reinterpret_cast<int*
>( AllocatorInt::
1273 reallocate(real_ind_, real_nz) );
1275 #ifdef SELDON_CHECK_MEMORY
1283 AllocatorLong::deallocate(real_ptr_, i+1);
1284 AllocatorLong::deallocate(imag_ptr_, i+1);
1289 this->real_data_ = NULL;
1290 this->imag_data_ = NULL;
1292 if (real_ind_ == NULL)
1298 AllocatorLong::deallocate(real_ptr_, i+1);
1299 AllocatorLong::deallocate(imag_ptr_, i+1);
1302 this->real_data_ = NULL;
1303 this->imag_data_ = NULL;
1305 if (real_ind_ == NULL && i != 0 && j != 0)
1306 throw NoMemory(
string(
"Matrix_SymComplexSparse::")
1307 +
"Resize(int, int, int, int)",
1308 string(
"Unable to allocate ")
1309 +
to_str(
sizeof(
int) * real_nz)
1310 +
" bytes to store " +
to_str(real_nz)
1311 +
" row or column indices (real part), for a "
1316 if (imag_nz != imag_nz_)
1318 #ifdef SELDON_CHECK_MEMORY
1324 reinterpret_cast<int*
>( AllocatorInt::
1325 reallocate(imag_ind_, imag_nz) );
1327 #ifdef SELDON_CHECK_MEMORY
1335 AllocatorLong::deallocate(real_ptr_, i+1);
1336 AllocatorLong::deallocate(imag_ptr_, i+1);
1339 AllocatorInt::deallocate(imag_ind_, imag_nz);
1342 this->real_data_ = NULL;
1343 this->imag_data_ = NULL;
1345 if (imag_ind_ == NULL)
1351 AllocatorLong::deallocate(real_ptr_, i+1);
1352 AllocatorLong::deallocate(imag_ptr_, i+1);
1355 AllocatorInt::deallocate(imag_ind_, imag_nz);
1357 this->real_data_ = NULL;
1358 this->imag_data_ = NULL;
1360 if (imag_ind_ == NULL && i != 0 && j != 0)
1361 throw NoMemory(
string(
"Matrix_SymComplexSparse::")
1362 +
"Resize(int, int, int, int)",
1363 string(
"Unable to allocate ")
1364 +
to_str(
sizeof(
int) * imag_nz)
1365 +
" bytes to store " +
to_str(imag_nz)
1366 +
" row or column indices (imaginary part), for a "
1371 if (real_nz != real_nz_)
1374 val.SetData(real_nz_, real_data_);
1375 val.Resize(real_nz);
1377 real_data_ = val.GetData();
1381 if (imag_nz != imag_nz_)
1384 val.SetData(imag_nz_, imag_data_);
1385 val.Resize(imag_nz);
1387 imag_data_ = val.GetData();
1392 for (
int k = this->m_; k <= i; k++)
1394 real_ptr_[k] = real_nz_;
1395 imag_ptr_[k] = imag_nz_;
1406 template <
class T,
class Prop,
class Storage,
class Allocator>
1413 real_nz_ = A.real_nz_;
1414 imag_nz_ = A.imag_nz_;
1417 if ((i == 0)||(j == 0))
1426 #ifdef SELDON_CHECK_DIMENSIONS
1427 if ( (
static_cast<long int>(2 * real_nz_ - 2) /
static_cast<long int>(i+1)
1428 >=
static_cast<long int>(i)) ||
1429 (
static_cast<long int>(2 * imag_nz_ - 2) /
static_cast<long int>(i+1)
1430 >=
static_cast<long int>(i)) )
1440 this->real_data_ = NULL;
1441 this->imag_data_ = NULL;
1442 throw WrongDim(
string(
"Matrix_SymComplexSparse::")
1443 +
"Matrix_SymComplexSparse(int, int, int, int)",
1444 string(
"There are more values to be stored (")
1445 +
to_str(real_nz_) +
" values for the real part and "
1446 +
to_str(imag_nz_) +
string(
" values for the imaginary")
1447 +
" part) than elements in the matrix ("
1452 #ifdef SELDON_CHECK_MEMORY
1458 reinterpret_cast<long*
>( AllocatorLong::allocate(i + 1) );
1461 memorycpy(this->real_ptr_, A.real_ptr_, (i + 1));
1463 #ifdef SELDON_CHECK_MEMORY
1475 this->real_data_ = NULL;
1476 this->imag_data_ = NULL;
1478 if (real_ptr_ == NULL)
1487 this->real_data_ = NULL;
1488 this->imag_data_ = NULL;
1490 if (real_ptr_ == NULL && i != 0)
1491 throw NoMemory(
string(
"Matrix_SymComplexSparse::")
1492 +
"Matrix_SymComplexSparse(int, int, int, int)",
1493 string(
"Unable to allocate ")
1494 +
to_str(
sizeof(
int) * (i + 1)) +
" bytes to store "
1495 +
to_str(i + 1) +
string(
" row or column")
1496 +
" start indices (for the real part), for a "
1500 #ifdef SELDON_CHECK_MEMORY
1506 reinterpret_cast<long*
>( AllocatorLong::allocate(i + 1) );
1508 AllocatorLong::memorycpy(this->imag_ptr_, A.imag_ptr_, (i + 1));
1510 #ifdef SELDON_CHECK_MEMORY
1518 AllocatorLong::deallocate(real_ptr_, i+1);
1523 this->real_data_ = NULL;
1524 this->imag_data_ = NULL;
1526 if (imag_ptr_ == NULL)
1532 AllocatorLong::deallocate(real_ptr_, i+1);
1536 this->real_data_ = NULL;
1537 this->imag_data_ = NULL;
1539 if (imag_ptr_ == NULL && i != 0)
1540 throw NoMemory(
string(
"Matrix_SymComplexSparse::")
1541 +
"Matrix_SymComplexSparse(int, int, int, int)",
1542 string(
"Unable to allocate ")
1543 +
to_str(
sizeof(
int) * (i + 1) ) +
" bytes to store "
1544 +
to_str(i + 1) +
string(
" row or column")
1545 +
" start indices (for the imaginary part), for a "
1549 #ifdef SELDON_CHECK_MEMORY
1555 reinterpret_cast<int*
>( AllocatorInt::allocate(real_nz_) );
1557 AllocatorInt::memorycpy(this->real_ind_, A.real_ind_, real_nz_);
1559 #ifdef SELDON_CHECK_MEMORY
1567 AllocatorLong::deallocate(real_ptr_, i+1);
1568 AllocatorLong::deallocate(imag_ptr_, i+1);
1573 this->real_data_ = NULL;
1574 this->imag_data_ = NULL;
1576 if (real_ind_ == NULL)
1582 AllocatorLong::deallocate(real_ptr_, i+1);
1583 AllocatorLong::deallocate(imag_ptr_, i+1);
1586 this->real_data_ = NULL;
1587 this->imag_data_ = NULL;
1589 if (real_ind_ == NULL && i != 0)
1590 throw NoMemory(
string(
"Matrix_SymComplexSparse::")
1591 +
"Matrix_SymComplexSparse(int, int, int, int)",
1592 string(
"Unable to allocate ")
1593 +
to_str(
sizeof(
int) * real_nz_) +
" bytes to store "
1595 +
" row or column indices (real part), for a "
1599 #ifdef SELDON_CHECK_MEMORY
1605 reinterpret_cast<int*
>( AllocatorInt::allocate(imag_nz_) );
1607 AllocatorInt::memorycpy(this->imag_ind_, A.imag_ind_, imag_nz_);
1609 #ifdef SELDON_CHECK_MEMORY
1617 AllocatorLong::deallocate(real_ptr_, i+1);
1618 AllocatorLong::deallocate(imag_ptr_, i+1);
1621 AllocatorInt::deallocate(imag_ind_, A.imag_nz_);
1624 this->real_data_ = NULL;
1625 this->imag_data_ = NULL;
1627 if (real_ind_ == NULL)
1633 AllocatorLong::deallocate(real_ptr_, i+1);
1634 AllocatorLong::deallocate(imag_ptr_, i+1);
1637 AllocatorInt::deallocate(imag_ind_, A.imag_nz_);
1639 this->real_data_ = NULL;
1640 this->imag_data_ = NULL;
1642 if (imag_ind_ == NULL && i != 0)
1643 throw NoMemory(
string(
"Matrix_SymComplexSparse::")
1644 +
"Matrix_SymComplexSparse(int, int, int, int)",
1645 string(
"Unable to allocate ")
1646 +
to_str(
sizeof(
int) * imag_nz_) +
" bytes to store "
1648 +
" row or column indices (imaginary part), for a "
1652 #ifdef SELDON_CHECK_MEMORY
1657 this->real_data_ = Allocator::allocate(real_nz_,
this);
1658 Allocator::memorycpy(this->real_data_, A.real_data_, real_nz_);
1660 #ifdef SELDON_CHECK_MEMORY
1666 AllocatorLong::deallocate(real_ptr_, i+1);
1667 AllocatorLong::deallocate(imag_ptr_, i+1);
1670 AllocatorInt::deallocate(real_ind_, A.real_nz_);
1671 AllocatorInt::deallocate(imag_ind_, A.imag_nz_);
1674 this->real_data_ = NULL;
1675 this->imag_data_ = NULL;
1677 if (real_data_ == NULL)
1681 AllocatorLong::deallocate(real_ptr_, i+1);
1682 AllocatorLong::deallocate(imag_ptr_, i+1);
1685 AllocatorInt::deallocate(real_ind_, A.real_nz_);
1686 AllocatorInt::deallocate(imag_ind_, A.imag_nz_);
1691 if (real_data_ == NULL && i != 0)
1692 throw NoMemory(
string(
"Matrix_SymComplexSparse::")
1693 +
"Matrix_SymComplexSparse(int, int, int, int)",
1694 string(
"Unable to allocate ")
1695 +
to_str(
sizeof(
int) * real_nz_) +
" bytes to store "
1696 +
to_str(real_nz_) +
" values (real part), for a "
1700 #ifdef SELDON_CHECK_MEMORY
1705 this->imag_data_ = Allocator::allocate(imag_nz_,
this);
1706 Allocator::memorycpy(this->imag_data_, A.imag_data_, imag_nz_);
1708 #ifdef SELDON_CHECK_MEMORY
1714 AllocatorLong::deallocate(real_ptr_, i+1);
1715 AllocatorLong::deallocate(imag_ptr_, i+1);
1718 AllocatorInt::deallocate(real_ind_, A.real_nz_);
1719 AllocatorInt::deallocate(imag_ind_, A.imag_nz_);
1722 Allocator::deallocate(this->real_data_, real_nz_);
1723 this->real_data_ = NULL;
1724 this->imag_data_ = NULL;
1726 if (real_data_ == NULL)
1730 AllocatorLong::deallocate(real_ptr_, i+1);
1731 AllocatorLong::deallocate(imag_ptr_, i+1);
1734 AllocatorInt::deallocate(real_ind_, A.real_nz_);
1735 AllocatorInt::deallocate(imag_ind_, A.imag_nz_);
1738 Allocator::deallocate(this->real_data_, real_nz_);
1741 if (imag_data_ == NULL && i != 0)
1742 throw NoMemory(
string(
"Matrix_SymComplexSparse::")
1743 +
"Matrix_SymComplexSparse(int, int, int, int)",
1744 string(
"Unable to allocate ")
1745 +
to_str(
sizeof(
int) * imag_nz_) +
" bytes to store "
1746 +
to_str(imag_nz_) +
" values (imaginary part), for a "
1765 template <
class T,
class Prop,
class Storage,
class Allocator>
1767 complex<typename Matrix_SymComplexSparse<T, Prop, Storage, Allocator>
1773 #ifdef SELDON_CHECK_BOUNDS
1774 if (i < 0 || i >= this->m_)
1775 throw WrongRow(
"Matrix_SymComplexSparse::operator()",
1776 string(
"Index should be in [0, ") +
to_str(this->m_-1)
1777 +
"], but is equal to " +
to_str(i) +
".");
1778 if (j < 0 || j >= this->n_)
1779 throw WrongCol(
"Matrix_SymComplexSparse::operator()",
1780 string(
"Index should be in [0, ") +
to_str(this->n_-1)
1781 +
"], but is equal to " +
to_str(j) +
".");
1784 long real_k, imag_k;
int l;
1785 long real_a, real_b;
1786 long imag_a, imag_b;
1796 real_a = real_ptr_[Storage::GetFirst(i, j)];
1797 real_b = real_ptr_[Storage::GetFirst(i, j) + 1];
1799 imag_a = imag_ptr_[Storage::GetFirst(i, j)];
1800 imag_b = imag_ptr_[Storage::GetFirst(i, j) + 1];
1802 if (real_a != real_b)
1804 l = Storage::GetSecond(i, j);
1805 for (real_k = real_a;
1806 (real_k < real_b - 1) && (real_ind_[real_k] < l);
1808 if (imag_a != imag_b)
1810 for (imag_k = imag_a;
1811 (imag_k < imag_b - 1) && (imag_ind_[imag_k] < l);
1813 if (real_ind_[real_k] == l)
1815 if (imag_ind_[imag_k] == l)
1816 return entry_type(real_data_[real_k], imag_data_[imag_k]);
1818 return entry_type(real_data_[real_k], value_type(0));
1821 if (imag_ind_[imag_k] == l)
1822 return entry_type(value_type(0), imag_data_[imag_k]);
1824 return entry_type(value_type(0), value_type(0));
1828 if (real_ind_[real_k] == l)
1829 return entry_type(real_data_[real_k], value_type(0));
1831 return entry_type(value_type(0), value_type(0));
1836 if (imag_a != imag_b)
1838 l = Storage::GetSecond(i, j);
1839 for (imag_k = imag_a;
1840 (imag_k < imag_b - 1) && (imag_ind_[imag_k] < l);
1842 if (imag_ind_[imag_k] == l)
1843 return entry_type(value_type(0), imag_data_[imag_k]);
1845 return entry_type(value_type(0), value_type(0));
1848 return entry_type(value_type(0), value_type(0));
1862 template <
class T,
class Prop,
class Storage,
class Allocator>
1868 #ifdef SELDON_CHECK_BOUNDS
1869 if (i < 0 || i >= this->m_)
1870 throw WrongRow(
"Matrix_SymComplexSparse::ValReal(int, int)",
1871 string(
"Index should be in [0, ") +
to_str(this->m_-1)
1872 +
"], but is equal to " +
to_str(i) +
".");
1873 if (j < 0 || j >= this->n_)
1874 throw WrongCol(
"Matrix_SymComplexSparse::ValReal(int, int)",
1875 string(
"Index should be in [0, ") +
to_str(this->n_-1)
1876 +
"], but is equal to " +
to_str(j) +
".");
1890 a = real_ptr_[Storage::GetFirst(i, j)];
1891 b = real_ptr_[Storage::GetFirst(i, j) + 1];
1894 throw WrongArgument(
"Matrix_SymComplexSparse::ValReal(int, int)",
1895 "No reference to element (" +
to_str(i) +
", "
1897 +
") can be returned: it is a zero entry.");
1899 l = Storage::GetSecond(i, j);
1901 for (k = a; (k < b-1) && (real_ind_[k] < l); k++);
1903 if (real_ind_[k] == l)
1904 return this->real_data_[k];
1906 throw WrongArgument(
"Matrix_SymComplexSparse::ValReal(int, int)",
1907 "No reference to element (" +
to_str(i) +
", "
1909 +
") can be returned: it is a zero entry.");
1922 template <
class T,
class Prop,
class Storage,
class Allocator>
1928 #ifdef SELDON_CHECK_BOUNDS
1929 if (i < 0 || i >= this->m_)
1930 throw WrongRow(
"Matrix_SymComplexSparse::ValReal(int, int)",
1931 string(
"Index should be in [0, ") +
to_str(this->m_-1)
1932 +
"], but is equal to " +
to_str(i) +
".");
1933 if (j < 0 || j >= this->n_)
1934 throw WrongCol(
"Matrix_SymComplexSparse::ValReal(int, int)",
1935 string(
"Index should be in [0, ") +
to_str(this->n_-1)
1936 +
"], but is equal to " +
to_str(j) +
".");
1950 a = real_ptr_[Storage::GetFirst(i, j)];
1951 b = real_ptr_[Storage::GetFirst(i, j) + 1];
1954 throw WrongArgument(
"Matrix_SymComplexSparse::ValReal(int, int)",
1955 "No reference to element (" +
to_str(i) +
", "
1957 +
") can be returned: it is a zero entry.");
1959 l = Storage::GetSecond(i, j);
1961 for (k = a; (k < b-1) && (real_ind_[k] < l); k++);
1963 if (real_ind_[k] == l)
1964 return this->real_data_[k];
1966 throw WrongArgument(
"Matrix_SymComplexSparse::ValReal(int, int)",
1967 "No reference to element (" +
to_str(i) +
", "
1969 +
") can be returned: it is a zero entry.");
1982 template <
class T,
class Prop,
class Storage,
class Allocator>
1988 #ifdef SELDON_CHECK_BOUNDS
1989 if (i < 0 || i >= this->m_)
1990 throw WrongRow(
"Matrix_SymComplexSparse::ValImag(int, int)",
1991 string(
"Index should be in [0, ") +
to_str(this->m_-1)
1992 +
"], but is equal to " +
to_str(i) +
".");
1993 if (j < 0 || j >= this->n_)
1994 throw WrongCol(
"Matrix_SymComplexSparse::ValImag(int, int)",
1995 string(
"Index should be in [0, ") +
to_str(this->n_-1)
1996 +
"], but is equal to " +
to_str(j) +
".");
2010 a = imag_ptr_[Storage::GetFirst(i, j)];
2011 b = imag_ptr_[Storage::GetFirst(i, j) + 1];
2014 throw WrongArgument(
"Matrix_SymComplexSparse::ValImag(int, int)",
2015 "No reference to element (" +
to_str(i) +
", "
2017 +
") can be returned: it is a zero entry.");
2019 l = Storage::GetSecond(i, j);
2021 for (k = a; (k < b-1) && (imag_ind_[k] < l); k++);
2023 if (imag_ind_[k] == l)
2024 return this->imag_data_[k];
2026 throw WrongArgument(
"Matrix_SymComplexSparse::ValImag(int, int)",
2027 "No reference to element (" +
to_str(i) +
", "
2029 +
") can be returned: it is a zero entry.");
2042 template <
class T,
class Prop,
class Storage,
class Allocator>
2048 #ifdef SELDON_CHECK_BOUNDS
2049 if (i < 0 || i >= this->m_)
2050 throw WrongRow(
"Matrix_SymComplexSparse::ValImag(int, int)",
2051 string(
"Index should be in [0, ") +
to_str(this->m_-1)
2052 +
"], but is equal to " +
to_str(i) +
".");
2053 if (j < 0 || j >= this->n_)
2054 throw WrongCol(
"Matrix_SymComplexSparse::ValImag(int, int)",
2055 string(
"Index should be in [0, ") +
to_str(this->n_-1)
2056 +
"], but is equal to " +
to_str(j) +
".");
2070 a = imag_ptr_[Storage::GetFirst(i, j)];
2071 b = imag_ptr_[Storage::GetFirst(i, j) + 1];
2074 throw WrongArgument(
"Matrix_SymComplexSparse::ValImag(int, int)",
2075 "No reference to element (" +
to_str(i) +
", "
2077 +
") can be returned: it is a zero entry.");
2079 l = Storage::GetSecond(i, j);
2081 for (k = a; (k < b-1) && (imag_ind_[k] < l); k++);
2083 if (imag_ind_[k] == l)
2084 return this->imag_data_[k];
2086 throw WrongArgument(
"Matrix_SymComplexSparse::ValImag(int, int)",
2087 "No reference to element (" +
to_str(i) +
", "
2089 +
") can be returned: it is a zero entry.");
2101 template <
class T,
class Prop,
class Storage,
class Allocator>
2107 #ifdef SELDON_CHECK_BOUNDS
2108 if (i < 0 || i >= this->m_)
2109 throw WrongRow(
"Matrix_SymComplexSparse::GetReal(int, int)",
2110 string(
"Index should be in [0, ") +
to_str(this->m_-1)
2111 +
"], but is equal to " +
to_str(i) +
".");
2112 if (j < 0 || j >= this->n_)
2113 throw WrongCol(
"Matrix_SymComplexSparse::GetReal(int, int)",
2114 string(
"Index should be in [0, ") +
to_str(this->n_-1)
2115 +
"], but is equal to " +
to_str(j) +
".");
2129 a = real_ptr_[Storage::GetFirst(i, j)];
2130 b = real_ptr_[Storage::GetFirst(i, j) + 1];
2134 l = Storage::GetSecond(i, j);
2136 for (k = a; (k < b) && (real_ind_[k] < l); k++);
2138 if ( (k < b) && (real_ind_[k] == l))
2139 return this->real_data_[k];
2145 Resize(this->m_, this->n_, real_nz_+1, imag_nz_);
2147 for (
int m = Storage::GetFirst(i, j)+1;
2148 m <= Storage::GetFirst(this->m_, this->n_); m++)
2151 for (
long m = real_nz_-1; m >= k+1; m--)
2153 real_ind_[m] = real_ind_[m-1];
2154 this->real_data_[m] = this->real_data_[m-1];
2157 real_ind_[k] = Storage::GetSecond(i, j);
2160 SetComplexZero(this->real_data_[k]);
2162 return this->real_data_[k];
2174 template <
class T,
class Prop,
class Storage,
class Allocator>
2180 #ifdef SELDON_CHECK_BOUNDS
2181 if (i < 0 || i >= this->m_)
2182 throw WrongRow(
"Matrix_SymComplexSparse::GetImag(int, int)",
2183 string(
"Index should be in [0, ") +
to_str(this->m_-1)
2184 +
"], but is equal to " +
to_str(i) +
".");
2185 if (j < 0 || j >= this->n_)
2186 throw WrongCol(
"Matrix_SymComplexSparse::GetImag(int, int)",
2187 string(
"Index should be in [0, ") +
to_str(this->n_-1)
2188 +
"], but is equal to " +
to_str(j) +
".");
2202 a = imag_ptr_[Storage::GetFirst(i, j)];
2203 b = imag_ptr_[Storage::GetFirst(i, j) + 1];
2207 l = Storage::GetSecond(i, j);
2209 for (k = a; (k < b) && (imag_ind_[k] < l); k++);
2211 if ( (k < b) && (imag_ind_[k] == l))
2212 return this->imag_data_[k];
2218 Resize(this->m_, this->n_, real_nz_, imag_nz_+1);
2220 for (
int m = Storage::GetFirst(i, j)+1;
2221 m <= Storage::GetFirst(this->m_, this->n_); m++)
2224 for (
long m = imag_nz_-1; m >= k+1; m--)
2226 imag_ind_[m] = imag_ind_[m-1];
2227 this->imag_data_[m] = this->imag_data_[m-1];
2230 imag_ind_[k] = Storage::GetSecond(i, j);
2233 SetComplexZero(this->imag_data_[k]);
2235 return this->imag_data_[k];
2245 template<
class T,
class Prop,
class Storage,
class Allocator>
2249 size_t taille =
sizeof(*this) + 2*this->GetRealPtrSize()*
sizeof(long);
2250 int coef =
sizeof(value_type) +
sizeof(
int);
2251 taille += coef*size_t(this->real_nz_ + this->imag_nz_);
2258 template <
class T,
class Prop,
class Storage,
class Allocator>
2261 Allocator::memoryset(this->real_data_,
char(0),
2262 this->real_nz_ *
sizeof(value_type));
2264 Allocator::memoryset(this->imag_data_,
char(0),
2265 this->imag_nz_ *
sizeof(value_type));
2272 template <
class T,
class Prop,
class Storage,
class Allocator>
2290 real_values.Fill(value_type(1));
2296 SetData(m, n, real_values, real_ptr, real_ind,
2297 imag_values, imag_ptr, imag_ind);
2305 template <
class T,
class Prop,
class Storage,
class Allocator>
2308 for (
long i = 0; i < this->real_nz_; i++)
2309 this->real_data_[i] = i;
2311 for (
long i = 0; i < this->imag_nz_; i++)
2312 this->imag_data_[i] = value_type(0);
2320 template <
class T,
class Prop,
class Storage,
class Allocator>
2324 for (
long i = 0; i < this->real_nz_; i++)
2325 this->real_data_[i] = real(x);
2327 for (
long i = 0; i < this->imag_nz_; i++)
2328 this->imag_data_[i] = imag(x);
2336 template <
class T,
class Prop,
class Storage,
class Allocator>
2339 #ifndef SELDON_WITHOUT_REINIT_RANDOM
2342 for (
long i = 0; i < this->real_nz_; i++)
2345 for (
long i = 0; i < this->imag_nz_; i++)
2356 template <
class T,
class Prop,
class Storage,
class Allocator>
2359 for (
int i = 0; i < this->m_; i++)
2361 for (
int j = 0; j < this->n_; j++)
2362 cout << (*
this)(i, j) <<
"\t";
2373 template <
class T,
class Prop,
class Storage,
class Allocator>
2377 ofstream FileStream;
2378 FileStream.open(FileName.c_str(), ofstream::binary);
2380 #ifdef SELDON_CHECK_IO
2382 if (!FileStream.is_open())
2383 throw IOError(
"Matrix_SymComplexSparse::Write(string FileName)",
2384 string(
"Unable to open file \"") + FileName +
"\".");
2387 this->Write(FileStream);
2398 template <
class T,
class Prop,
class Storage,
class Allocator>
2402 #ifdef SELDON_CHECK_IO
2404 if (!FileStream.good())
2405 throw IOError(
"Matrix_SymComplexSparse::Write(ofstream& FileStream)",
2406 "Stream is not ready.");
2409 FileStream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&this->m_)),
2411 FileStream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&this->n_)),
2413 FileStream.write(
reinterpret_cast<char*
>(
const_cast<long*
>(&this->real_nz_)),
2415 FileStream.write(
reinterpret_cast<char*
>(
const_cast<long*
>(&this->imag_nz_)),
2418 FileStream.write(
reinterpret_cast<char*
>(this->real_ptr_),
2419 sizeof(
long)*(Storage::GetFirst(this->m_, this->n_)+1));
2420 FileStream.write(
reinterpret_cast<char*
>(this->real_ind_),
2421 sizeof(
int)*this->real_nz_);
2422 FileStream.write(
reinterpret_cast<char*
>(this->real_data_),
2423 sizeof(value_type)*this->real_nz_);
2425 FileStream.write(
reinterpret_cast<char*
>(this->imag_ptr_),
2426 sizeof(
long)*(Storage::GetFirst(this->m_, this->n_)+1));
2427 FileStream.write(
reinterpret_cast<char*
>(this->imag_ind_),
2428 sizeof(
int)*this->imag_nz_);
2429 FileStream.write(
reinterpret_cast<char*
>(this->imag_data_),
2430 sizeof(value_type)*this->imag_nz_);
2441 template <
class T,
class Prop,
class Storage,
class Allocator>
2445 ofstream FileStream; FileStream.precision(14);
2446 FileStream.open(FileName.c_str());
2449 FileStream.precision(cout.precision());
2451 #ifdef SELDON_CHECK_IO
2453 if (!FileStream.is_open())
2454 throw IOError(
"Matrix_SymComplexSparse::Write(string FileName)",
2455 string(
"Unable to open file \"") + FileName +
"\".");
2458 this->WriteText(FileStream, cplx);
2471 template <
class T,
class Prop,
class Storage,
class Allocator>
2476 #ifdef SELDON_CHECK_IO
2478 if (!FileStream.good())
2479 throw IOError(
"Matrix_SymComplexSparse::Write(ofstream& FileStream)",
2480 "Stream is not ready.");
2487 entry_type zero;
int index = 1;
2488 WriteCoordinateMatrix(leaf_class, FileStream, zero, index, cplx);
2497 template <
class T,
class Prop,
class Storage,
class Allocator>
2501 ifstream FileStream;
2502 FileStream.open(FileName.c_str(), ifstream::binary);
2504 #ifdef SELDON_CHECK_IO
2506 if (!FileStream.is_open())
2507 throw IOError(
"Matrix_SymComplexSparse::Read(string FileName)",
2508 string(
"Unable to open file \"") + FileName +
"\".");
2511 this->Read(FileStream);
2522 template <
class T,
class Prop,
class Storage,
class Allocator>
2527 #ifdef SELDON_CHECK_IO
2529 if (!FileStream.good())
2530 throw IOError(
"Matrix_SymComplexSparse::Read(istream& FileStream)",
2531 "Stream is not ready.");
2534 int m, n, real_nz, imag_nz;
2535 FileStream.read(
reinterpret_cast<char*
>(&m),
sizeof(
int));
2536 FileStream.read(
reinterpret_cast<char*
>(&n),
sizeof(
int));
2537 FileStream.read(
reinterpret_cast<char*
>(&real_nz),
sizeof(
long));
2538 FileStream.read(
reinterpret_cast<char*
>(&imag_nz),
sizeof(
long));
2540 Reallocate(m, n, real_nz, imag_nz);
2542 FileStream.read(
reinterpret_cast<char*
>(real_ptr_),
2543 sizeof(
long)*(Storage::GetFirst(m, n)+1));
2544 FileStream.read(
reinterpret_cast<char*
>(real_ind_),
sizeof(
int)*real_nz);
2545 FileStream.read(
reinterpret_cast<char*
>(this->real_data_),
2546 sizeof(value_type)*real_nz);
2548 FileStream.read(
reinterpret_cast<char*
>(imag_ptr_),
2549 sizeof(
long)*(Storage::GetFirst(m, n)+1));
2550 FileStream.read(
reinterpret_cast<char*
>(imag_ind_),
sizeof(
int)*imag_nz);
2551 FileStream.read(
reinterpret_cast<char*
>(this->imag_data_),
2552 sizeof(value_type)*imag_nz);
2554 #ifdef SELDON_CHECK_IO
2556 if (!FileStream.good())
2557 throw IOError(
"Matrix_SymComplexSparse::Read(istream& FileStream)",
2558 string(
"Input operation failed.")
2559 +
string(
" The input file may have been removed")
2560 +
" or may not contain enough data.");
2571 template <
class T,
class Prop,
class Storage,
class Allocator>
2575 ifstream FileStream;
2576 FileStream.open(FileName.c_str());
2578 #ifdef SELDON_CHECK_IO
2580 if (!FileStream.is_open())
2581 throw IOError(
"Matrix_SymComplexSparse::ReadText(string FileName)",
2582 string(
"Unable to open file \"") + FileName +
"\".");
2585 this->ReadText(FileStream, cplx);
2596 template <
class T,
class Prop,
class Storage,
class Allocator>
2603 entry_type zero;
int index = 1;
2604 ReadCoordinateMatrix(leaf_class, FileStream, zero, index, -1, cplx);
2610 #define SELDON_FILE_MATRIX_SYMCOMPLEXSPARSE_CXX