21 #ifndef SELDON_FILE_MATRIX_COMPLEXSPARSE_CXX
23 #include "Matrix_ComplexSparse.hxx"
38 template <
class T,
class Prop,
class Storage,
class Allocator>
59 template <
class T,
class Prop,
class Storage,
class Allocator>
87 template <
class T,
class Prop,
class Storage,
class Allocator>
101 Reallocate(i, j, real_nz, imag_nz);
124 template <
class T,
class Prop,
class Storage,
class Allocator>
125 template <
class Storage0,
class Allocator0,
126 class Storage1,
class Allocator1,
127 class Storage2,
class Allocator2>
139 real_nz_ = real_values.GetM();
140 imag_nz_ = imag_values.GetM();
142 #ifdef SELDON_CHECK_DIMENSIONS
145 if (real_ind.GetM() != real_nz_)
155 this->real_data_ = NULL;
156 this->imag_data_ = NULL;
157 throw WrongDim(
string(
"Matrix_ComplexSparse::")
158 +
string(
"Matrix_ComplexSparse(int, int, ")
159 +
string(
"const Vector&, const Vector&, const Vector&")
160 +
", const Vector&, const Vector&, const Vector&)",
161 string(
"There are ") +
to_str(real_nz_)
162 +
" values (real part) but "
164 +
" row or column indices.");
167 if (imag_ind.GetM() != imag_nz_)
177 this->real_data_ = NULL;
178 this->imag_data_ = NULL;
179 throw WrongDim(
string(
"Matrix_ComplexSparse::")
180 +
string(
"Matrix_ComplexSparse(int, int, ")
181 +
string(
"const Vector&, const Vector&, const Vector&")
182 +
", const Vector&, const Vector&, const Vector&)",
183 string(
"There are ") +
to_str(imag_nz_)
184 +
" values (imaginary part) but "
186 +
" row or column indices.");
189 if (real_ptr.GetM()-1 != Storage::GetFirst(i, j))
199 this->real_data_ = NULL;
200 this->imag_data_ = NULL;
201 throw WrongDim(
string(
"Matrix_ComplexSparse::")
202 +
string(
"Matrix_ComplexSparse(int, int, ")
203 +
string(
"const Vector&, const Vector&, const Vector&")
204 +
", const Vector&, const Vector&, const Vector&)",
205 string(
"The vector of start indices (real part)")
206 +
" contains " +
to_str(real_ptr.GetM()-1)
207 +
string(
" row or column start indices (plus the")
208 +
" number of non-zero entries) but there are "
209 +
to_str(Storage::GetFirst(i, j))
210 +
" rows or columns ("
214 if (imag_ptr.GetM()-1 != Storage::GetFirst(i, j))
224 this->real_data_ = NULL;
225 this->imag_data_ = NULL;
226 throw WrongDim(
string(
"Matrix_ComplexSparse::")
227 +
string(
"Matrix_ComplexSparse(int, int, ")
228 +
string(
"const Vector&, const Vector&, const Vector&")
229 +
", const Vector&, const Vector&, const Vector&)",
230 string(
"The vector of start indices (imaginary part)")
231 +
" contains " +
to_str(imag_ptr.GetM()-1)
232 +
string(
" row or column start indices (plus the")
233 +
" number of non-zero entries) but there are "
234 +
to_str(Storage::GetFirst(i, j))
235 +
" rows or columns ("
241 ||
static_cast<long int>(real_nz_-1) /
static_cast<long int>(j)
242 >=
static_cast<long int>(i)))
246 ||
static_cast<long int>(imag_nz_-1) /
static_cast<long int>(j)
247 >=
static_cast<long int>(i))))
257 this->real_data_ = NULL;
258 this->imag_data_ = NULL;
259 throw WrongDim(
string(
"Matrix_ComplexSparse::")
260 +
string(
"Matrix_ComplexSparse(int, int, ")
261 +
string(
"const Vector&, const Vector&, const Vector&")
262 +
", const Vector&, const Vector&, const Vector&)",
263 string(
"There are more values (")
264 +
to_str(real_values.GetM())
265 +
" values for the real part and "
266 +
to_str(real_values.GetM()) +
string(
" values")
267 +
string(
" for the imaginary part) than elements")
273 this->real_ptr_ = real_ptr.GetData();
274 this->imag_ptr_ = imag_ptr.GetData();
275 this->real_ind_ = real_ind.GetData();
276 this->imag_ind_ = imag_ind.GetData();
277 this->real_data_ = real_values.GetData();
278 this->imag_data_ = imag_values.GetData();
284 real_values.Nullify();
285 imag_values.Nullify();
290 template <
class T,
class Prop,
class Storage,
class Allocator>
293 Storage, Allocator>& A)
315 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;
448 template<
class T,
class Prop,
class Storage,
class Allocator>
452 size_t taille =
sizeof(*this) + 2*this->GetRealPtrSize()*
sizeof(long);
453 int coef =
sizeof(value_type) +
sizeof(
int);
454 taille += coef*size_t(this->real_nz_ + this->imag_nz_);
482 template <
class T,
class Prop,
class Storage,
class Allocator>
483 template <
class Storage0,
class Allocator0,
484 class Storage1,
class Allocator1,
485 class Storage2,
class Allocator2>
498 real_nz_ = real_values.GetM();
499 imag_nz_ = imag_values.GetM();
501 #ifdef SELDON_CHECK_DIMENSIONS
504 if (real_ind.GetM() != real_nz_)
514 this->real_data_ = NULL;
515 this->imag_data_ = NULL;
516 throw WrongDim(
string(
"Matrix_ComplexSparse::SetData(int, int, ")
517 +
string(
"const Vector&, const Vector&, const Vector&")
518 +
", const Vector&, const Vector&, const Vector&)",
519 string(
"There are ") +
to_str(real_nz_)
520 +
" values (real part) but "
522 +
" row or column indices.");
525 if (imag_ind.GetM() != imag_nz_)
535 this->real_data_ = NULL;
536 this->imag_data_ = NULL;
537 throw WrongDim(
string(
"Matrix_ComplexSparse::SetData(int, int, ")
538 +
string(
"const Vector&, const Vector&, const Vector&")
539 +
", const Vector&, const Vector&, const Vector&)",
540 string(
"There are ") +
to_str(imag_nz_)
541 +
" values (imaginary part) but "
543 +
" row or column indices.");
546 if (real_ptr.GetM()-1 != Storage::GetFirst(i, j))
556 this->real_data_ = NULL;
557 this->imag_data_ = NULL;
558 throw WrongDim(
string(
"Matrix_ComplexSparse::SetData(int, int, ")
559 +
string(
"const Vector&, const Vector&, const Vector&")
560 +
", const Vector&, const Vector&, const Vector&)",
561 string(
"The vector of start indices (real part)")
562 +
" contains " +
to_str(real_ptr.GetM()-1)
563 +
string(
" row or column start indices (plus the")
564 +
" number of non-zero entries) but there are "
565 +
to_str(Storage::GetFirst(i, j))
566 +
" rows or columns ("
570 if (imag_ptr.GetM()-1 != Storage::GetFirst(i, j))
580 this->real_data_ = NULL;
581 this->imag_data_ = NULL;
582 throw WrongDim(
string(
"Matrix_ComplexSparse::SetData(int, int, ")
583 +
string(
"const Vector&, const Vector&, const Vector&")
584 +
", const Vector&, const Vector&, const Vector&)",
585 string(
"The vector of start indices (imaginary part)")
586 +
" contains " +
to_str(imag_ptr.GetM()-1)
587 +
string(
" row or column start indices (plus the")
588 +
" number of non-zero entries) but there are "
589 +
to_str(Storage::GetFirst(i, j))
590 +
" rows or columns ("
596 ||
static_cast<long int>(real_nz_-1) /
static_cast<long int>(j)
597 >=
static_cast<long int>(i)))
601 ||
static_cast<long int>(imag_nz_-1) /
static_cast<long int>(j)
602 >=
static_cast<long int>(i))))
612 this->real_data_ = NULL;
613 this->imag_data_ = NULL;
614 throw WrongDim(
string(
"Matrix_ComplexSparse::SetData(int, int, ")
615 +
string(
"const Vector&, const Vector&, const Vector&")
616 +
", const Vector&, const Vector&, const Vector&)",
617 string(
"There are more values (")
618 +
to_str(real_values.GetM())
619 +
" values for the real part and "
620 +
to_str(real_values.GetM()) +
string(
" values")
621 +
string(
" for the imaginary part) than elements")
627 this->real_ptr_ = real_ptr.GetData();
628 this->imag_ptr_ = imag_ptr.GetData();
629 this->real_ind_ = real_ind.GetData();
630 this->imag_ind_ = imag_ind.GetData();
631 this->real_data_ = real_values.GetData();
632 this->imag_data_ = imag_values.GetData();
638 real_values.Nullify();
639 imag_values.Nullify();
665 template <
class T,
class Prop,
class Storage,
class Allocator>
669 ::pointer real_values,
670 long* real_ptr,
int* real_ind,
long imag_nz,
672 ::pointer imag_values,
673 long* imag_ptr,
int* imag_ind)
680 this->real_nz_ = real_nz;
681 this->imag_nz_ = imag_nz;
683 real_data_ = real_values;
684 imag_data_ = imag_values;
685 real_ind_ = real_ind;
686 imag_ind_ = imag_ind;
687 real_ptr_ = real_ptr;
688 imag_ptr_ = imag_ptr;
697 template <
class T,
class Prop,
class Storage,
class Allocator>
715 template <
class T,
class Prop,
class Storage,
class Allocator>
726 #ifdef SELDON_CHECK_MEMORY
732 =
reinterpret_cast<long*
>( AllocatorLong::
733 allocate(Storage::GetFirst(i, j)+1) );
736 =
reinterpret_cast<long*
>( AllocatorLong::
737 allocate(Storage::GetFirst(i, j)+1) );
739 #ifdef SELDON_CHECK_MEMORY
754 if ((real_ptr_ == NULL) || (imag_ptr_ == NULL))
767 if (((real_ptr_ == NULL) || (imag_ptr_ == NULL)) && i != 0 && j != 0)
768 throw NoMemory(
"Matrix_ComplexSparse::Reallocate(int, int)",
769 string(
"Unable to allocate ")
770 +
to_str(
sizeof(
int) * (Storage::GetFirst(i, j)+1) )
771 +
" bytes to store " +
to_str(Storage::GetFirst(i, j)+1)
772 +
" row or column start indices, for a "
777 for (
int k = 0; k <= Storage::GetFirst(i, j); k++)
786 template <
class T,
class Prop,
class Storage,
class Allocator>
795 this->real_nz_ = real_nz;
796 this->imag_nz_ = imag_nz;
798 #ifdef SELDON_CHECK_DIMENSIONS
799 if (real_nz_ < 0 || imag_nz_ < 0)
809 this->real_data_ = NULL;
810 this->imag_data_ = NULL;
811 throw WrongDim(
string(
"Matrix_ComplexSparse::")
812 +
"Matrix_ComplexSparse(int, int, int, int)",
813 "Invalid number of non-zero elements: "
814 +
to_str(real_nz) +
" in the real part and "
815 +
to_str(imag_nz) +
" in the imaginary part.");
819 ||
static_cast<long int>(real_nz_-1) /
static_cast<long int>(j)
820 >=
static_cast<long int>(i)))
824 ||
static_cast<long int>(imag_nz_-1) /
static_cast<long int>(j)
825 >=
static_cast<long int>(i))))
835 this->real_data_ = NULL;
836 this->imag_data_ = NULL;
837 throw WrongDim(
string(
"Matrix_ComplexSparse::")
838 +
"Matrix_ComplexSparse(int, int, int, int)",
839 string(
"There are more values (") +
to_str(real_nz)
840 +
" values for the real part and " +
to_str(imag_nz)
841 +
string(
" values for the imaginary part) than")
842 +
" elements in the matrix (" +
to_str(i) +
" by "
847 #ifdef SELDON_CHECK_MEMORY
853 =
reinterpret_cast<long*
>( AllocatorLong::
854 allocate(Storage::GetFirst(i, j)+1) );
856 #ifdef SELDON_CHECK_MEMORY
868 this->real_data_ = NULL;
869 this->imag_data_ = NULL;
871 if (real_ptr_ == NULL)
880 this->real_data_ = NULL;
881 this->imag_data_ = NULL;
883 if (real_ptr_ == NULL && i != 0 && j != 0)
884 throw NoMemory(
string(
"Matrix_ComplexSparse::")
885 +
"Matrix_ComplexSparse(int, int, int, int)",
886 string(
"Unable to allocate ")
887 +
to_str(
sizeof(
int) * (Storage::GetFirst(i, j)+1))
888 +
" bytes to store " +
to_str(Storage::GetFirst(i, j)+1)
889 +
string(
" row or column start indices (for the real")
894 #ifdef SELDON_CHECK_MEMORY
900 =
reinterpret_cast<long*
>( AllocatorLong::
901 allocate(Storage::GetFirst(i, j)+1) );
903 #ifdef SELDON_CHECK_MEMORY
911 AllocatorLong::deallocate(real_ptr_,
912 Storage::GetFirst(i, j)+1);
917 this->real_data_ = NULL;
918 this->imag_data_ = NULL;
920 if (imag_ptr_ == NULL)
927 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
931 this->real_data_ = NULL;
932 this->imag_data_ = NULL;
934 if (imag_ptr_ == NULL && i != 0 && j != 0)
935 throw NoMemory(
string(
"Matrix_ComplexSparse::")
936 +
"Matrix_ComplexSparse(int, int, int, int)",
937 string(
"Unable to allocate ")
938 +
to_str(
sizeof(
int) * (Storage::GetFirst(i, j)+1))
939 +
" bytes to store " +
to_str(Storage::GetFirst(i, j)+1)
940 +
string(
" row or column start indices (for the")
941 +
string(
" imaginary part), for a ")
945 #ifdef SELDON_CHECK_MEMORY
951 reinterpret_cast<int*
>( AllocatorInt::allocate(real_nz_,
this) );
953 #ifdef SELDON_CHECK_MEMORY
962 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
964 deallocate(imag_ptr_, Storage::GetFirst(i, j)+1);
969 this->real_data_ = NULL;
970 this->imag_data_ = NULL;
972 if (real_ind_ == NULL)
979 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
981 deallocate(imag_ptr_, Storage::GetFirst(i, j)+1);
984 this->real_data_ = NULL;
985 this->imag_data_ = NULL;
987 if (real_ind_ == NULL && i != 0 && j != 0)
988 throw NoMemory(
string(
"Matrix_ComplexSparse::")
989 +
"Matrix_ComplexSparse(int, int, int, int)",
990 string(
"Unable to allocate ")
991 +
to_str(
sizeof(
int) * real_nz)
992 +
" bytes to store " +
to_str(real_nz)
993 +
" row or column indices (real part), for a "
997 #ifdef SELDON_CHECK_MEMORY
1003 reinterpret_cast<int*
>( AllocatorInt::allocate(imag_nz_,
this) );
1005 #ifdef SELDON_CHECK_MEMORY
1014 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
1016 deallocate(imag_ptr_, Storage::GetFirst(i, j)+1);
1019 AllocatorInt::deallocate(imag_ind_, imag_nz);
1022 this->real_data_ = NULL;
1023 this->imag_data_ = NULL;
1025 if (imag_ind_ == NULL)
1032 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
1034 deallocate(imag_ptr_, Storage::GetFirst(i, j)+1);
1037 AllocatorInt::deallocate(imag_ind_, imag_nz);
1039 this->real_data_ = NULL;
1040 this->imag_data_ = NULL;
1042 if (imag_ind_ == NULL && i != 0 && j != 0)
1043 throw NoMemory(
string(
"Matrix_ComplexSparse::")
1044 +
"Matrix_ComplexSparse(int, int, int, int)",
1045 string(
"Unable to allocate ")
1046 +
to_str(
sizeof(
int) * imag_nz)
1047 +
" bytes to store " +
to_str(imag_nz)
1048 +
" row or column indices (imaginary part), for a "
1052 #ifdef SELDON_CHECK_MEMORY
1057 this->real_data_ = Allocator::allocate(real_nz_,
this);
1059 #ifdef SELDON_CHECK_MEMORY
1066 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
1068 deallocate(imag_ptr_, Storage::GetFirst(i, j)+1);
1071 AllocatorInt::deallocate(real_ind_, real_nz);
1072 AllocatorInt::deallocate(imag_ind_, imag_nz);
1075 this->real_data_ = NULL;
1076 this->imag_data_ = NULL;
1078 if (real_data_ == NULL)
1083 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
1085 deallocate(imag_ptr_, Storage::GetFirst(i, j)+1);
1088 AllocatorInt::deallocate(real_ind_, real_nz);
1089 AllocatorInt::deallocate(imag_ind_, imag_nz);
1094 if (real_data_ == NULL && i != 0 && j != 0)
1095 throw NoMemory(
string(
"Matrix_ComplexSparse::")
1096 +
"Matrix_ComplexSparse(int, int, int, int)",
1097 string(
"Unable to allocate ")
1098 +
to_str(
sizeof(
int) * real_nz)
1099 +
" bytes to store " +
to_str(real_nz)
1100 +
" values (real part), for a "
1104 #ifdef SELDON_CHECK_MEMORY
1109 this->imag_data_ = Allocator::allocate(imag_nz_,
this);
1111 #ifdef SELDON_CHECK_MEMORY
1118 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
1120 deallocate(imag_ptr_, Storage::GetFirst(i, j)+1);
1123 AllocatorInt::deallocate(real_ind_, real_nz);
1124 AllocatorInt::deallocate(imag_ind_, imag_nz);
1127 Allocator::deallocate(this->real_data_, real_nz_);
1128 this->real_data_ = NULL;
1129 this->imag_data_ = NULL;
1131 if (real_data_ == NULL)
1136 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
1138 deallocate(imag_ptr_, Storage::GetFirst(i, j)+1);
1141 AllocatorInt::deallocate(real_ind_, real_nz);
1142 AllocatorInt::deallocate(imag_ind_, imag_nz);
1145 Allocator::deallocate(this->real_data_, real_nz_);
1148 if (imag_data_ == NULL && i != 0 && j != 0)
1149 throw NoMemory(
string(
"Matrix_ComplexSparse::")
1150 +
"Matrix_ComplexSparse(int, int, int, int)",
1151 string(
"Unable to allocate ")
1152 +
to_str(
sizeof(
int) * imag_nz)
1153 +
" bytes to store " +
to_str(imag_nz)
1154 +
" values (imaginary part), for a "
1159 for (
int k = 0; k <= Storage::GetFirst(i, j); k++)
1172 template <
class T,
class Prop,
class Storage,
class Allocator>
1176 if (Storage::GetFirst(i, j) < Storage::GetFirst(this->m_, this->n_))
1177 Resize(i, j, real_ptr_[Storage::GetFirst(i, j)],
1178 imag_ptr_[Storage::GetFirst(i, j)]);
1180 Resize(i, j, real_nz_, imag_nz_);
1190 template <
class T,
class Prop,
class Storage,
class Allocator>
1194 #ifdef SELDON_CHECK_DIMENSIONS
1195 if (real_nz < 0 || imag_nz < 0)
1205 this->real_data_ = NULL;
1206 this->imag_data_ = NULL;
1207 throw WrongDim(
string(
"Matrix_ComplexSparse::")
1208 +
"Resize(int, int, int, int)",
1209 "Invalid number of non-zero elements: "
1210 +
to_str(real_nz) +
" in the real part and "
1211 +
to_str(imag_nz) +
" in the imaginary part.");
1215 ||
static_cast<long int>(real_nz-1) /
static_cast<long int>(j)
1216 >=
static_cast<long int>(i)))
1220 ||
static_cast<long int>(imag_nz-1) /
static_cast<long int>(j)
1221 >=
static_cast<long int>(i))))
1231 this->real_data_ = NULL;
1232 this->imag_data_ = NULL;
1233 throw WrongDim(
string(
"Matrix_ComplexSparse::")
1234 +
"Resize(int, int, int, int)",
1235 string(
"There are more values (") +
to_str(real_nz)
1236 +
" values for the real part and " +
to_str(imag_nz)
1237 +
string(
" values for the imaginary part) than")
1238 +
" elements in the matrix (" +
to_str(i) +
" by "
1243 if (Storage::GetFirst(this->m_, this->n_) != Storage::GetFirst(i, j))
1245 #ifdef SELDON_CHECK_MEMORY
1251 reinterpret_cast<long*
>( AllocatorLong::
1252 reallocate(real_ptr_,
1253 (Storage::GetFirst(i, j)+1)) );
1255 #ifdef SELDON_CHECK_MEMORY
1267 this->real_data_ = NULL;
1268 this->imag_data_ = NULL;
1270 if (real_ptr_ == NULL)
1279 this->real_data_ = NULL;
1280 this->imag_data_ = NULL;
1282 if (real_ptr_ == NULL && i != 0 && j != 0)
1283 throw NoMemory(
string(
"Matrix_ComplexSparse::")
1284 +
"Resize(int, int, int, int)",
1285 string(
"Unable to allocate ")
1286 +
to_str(
sizeof(
int) * (Storage::GetFirst(i, j)+1))
1287 +
" bytes to store " +
to_str(Storage::GetFirst(i, j)+1)
1288 +
string(
" row or column start indices (for the real")
1293 #ifdef SELDON_CHECK_MEMORY
1299 reinterpret_cast<long*
>( AllocatorLong::
1300 reallocate(imag_ptr_,
1301 (Storage::GetFirst(i, j)+1)) );
1303 #ifdef SELDON_CHECK_MEMORY
1312 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
1317 this->real_data_ = NULL;
1318 this->imag_data_ = NULL;
1320 if (imag_ptr_ == NULL)
1327 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
1331 this->real_data_ = NULL;
1332 this->imag_data_ = NULL;
1334 if (imag_ptr_ == NULL && i != 0 && j != 0)
1335 throw NoMemory(
string(
"Matrix_ComplexSparse::")
1336 +
"Resize(int, int, int, int)",
1337 string(
"Unable to allocate ")
1338 +
to_str(
sizeof(
int) * (Storage::GetFirst(i, j)+1))
1339 +
" bytes to store " +
to_str(Storage::GetFirst(i, j)+1)
1340 +
string(
" row or column start indices (for the")
1341 +
string(
" imaginary part), for a ")
1346 if (real_nz != real_nz_)
1348 #ifdef SELDON_CHECK_MEMORY
1354 reinterpret_cast<int*
>( AllocatorInt::
1355 reallocate(real_ind_,
1358 #ifdef SELDON_CHECK_MEMORY
1367 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
1369 deallocate(imag_ptr_, Storage::GetFirst(i, j)+1);
1374 this->real_data_ = NULL;
1375 this->imag_data_ = NULL;
1377 if (real_ind_ == NULL)
1384 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
1386 deallocate(imag_ptr_, Storage::GetFirst(i, j)+1);
1389 this->real_data_ = NULL;
1390 this->imag_data_ = NULL;
1392 if (real_ind_ == NULL && i != 0 && j != 0)
1393 throw NoMemory(
string(
"Matrix_ComplexSparse::")
1394 +
"Resize(int, int, int, int)",
1395 string(
"Unable to allocate ")
1396 +
to_str(
sizeof(
int) * real_nz)
1397 +
" bytes to store " +
to_str(real_nz)
1398 +
" row or column indices (real part), for a "
1403 if (imag_nz != imag_nz_)
1405 #ifdef SELDON_CHECK_MEMORY
1411 reinterpret_cast<int*
>( AllocatorInt::
1412 reallocate(imag_ind_,
1414 #ifdef SELDON_CHECK_MEMORY
1423 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
1425 deallocate(imag_ptr_, Storage::GetFirst(i, j)+1);
1428 AllocatorInt::deallocate(imag_ind_, imag_nz);
1431 this->real_data_ = NULL;
1432 this->imag_data_ = NULL;
1434 if (imag_ind_ == NULL)
1441 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
1443 deallocate(imag_ptr_, Storage::GetFirst(i, j)+1);
1446 AllocatorInt::deallocate(imag_ind_, imag_nz);
1448 this->real_data_ = NULL;
1449 this->imag_data_ = NULL;
1451 if (imag_ind_ == NULL && i != 0 && j != 0)
1452 throw NoMemory(
string(
"Matrix_ComplexSparse::")
1453 +
"Resize(int, int, int, int)",
1454 string(
"Unable to allocate ")
1455 +
to_str(
sizeof(
int) * imag_nz)
1456 +
" bytes to store " +
to_str(imag_nz)
1457 +
" row or column indices (imaginary part), for a "
1462 if (real_nz != real_nz_)
1465 val.SetData(real_nz_, real_data_);
1466 val.Resize(real_nz);
1468 real_data_ = val.GetData();
1472 if (imag_nz != imag_nz_)
1475 val.SetData(imag_nz_, imag_data_);
1476 val.Resize(imag_nz);
1478 imag_data_ = val.GetData();
1483 for (
int k = Storage::GetFirst(this->m_, this->n_);
1484 k <= Storage::GetFirst(i, j); k++)
1486 real_ptr_[k] = real_nz_;
1487 imag_ptr_[k] = imag_nz_;
1498 template <
class T,
class Prop,
class Storage,
class Allocator>
1505 real_nz_ = A.real_nz_;
1506 imag_nz_ = A.imag_nz_;
1509 if ((i == 0)||(j == 0))
1518 #ifdef SELDON_CHECK_DIMENSIONS
1521 ||
static_cast<long int>(real_nz_-1) /
static_cast<long int>(j)
1522 >=
static_cast<long int>(i)))
1526 ||
static_cast<long int>(imag_nz_-1) /
static_cast<long int>(j)
1527 >=
static_cast<long int>(i))))
1537 this->real_data_ = NULL;
1538 this->imag_data_ = NULL;
1539 throw WrongDim(
string(
"Matrix_ComplexSparse::")
1540 +
"Matrix_ComplexSparse(int, int, int, int)",
1541 string(
"There are more values (") +
to_str(real_nz_)
1542 +
" values for the real part and " +
to_str(imag_nz_)
1543 +
string(
" values for the imaginary part) than")
1544 +
" elements in the matrix (" +
to_str(i) +
" by "
1549 #ifdef SELDON_CHECK_MEMORY
1555 reinterpret_cast<long*
>( AllocatorLong::
1556 allocate(Storage::GetFirst(i, j)+1) );
1559 memorycpy(this->real_ptr_, A.real_ptr_,
1560 (Storage::GetFirst(i, j) + 1) );
1562 #ifdef SELDON_CHECK_MEMORY
1574 this->real_data_ = NULL;
1575 this->imag_data_ = NULL;
1577 if (real_ptr_ == NULL)
1586 this->real_data_ = NULL;
1587 this->imag_data_ = NULL;
1589 if (real_ptr_ == NULL && i != 0 && j != 0)
1590 throw NoMemory(
string(
"Matrix_ComplexSparse::")
1591 +
"Matrix_ComplexSparse(int, int, int, int)",
1592 string(
"Unable to allocate ")
1593 +
to_str(
sizeof(
int) * (Storage::GetFirst(i, j)+1))
1594 +
" bytes to store " +
to_str(Storage::GetFirst(i, j)+1)
1595 +
string(
" row or column start indices (for the real")
1600 #ifdef SELDON_CHECK_MEMORY
1606 reinterpret_cast<long*
>( AllocatorLong::
1607 allocate(Storage::GetFirst(i, j)+1) );
1610 memorycpy(this->imag_ptr_, A.imag_ptr_,
1611 (Storage::GetFirst(i, j) + 1) );
1613 #ifdef SELDON_CHECK_MEMORY
1622 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
1627 this->real_data_ = NULL;
1628 this->imag_data_ = NULL;
1630 if (imag_ptr_ == NULL)
1637 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
1641 this->real_data_ = NULL;
1642 this->imag_data_ = NULL;
1644 if (imag_ptr_ == NULL && i != 0 && j != 0)
1645 throw NoMemory(
string(
"Matrix_ComplexSparse::")
1646 +
"Matrix_ComplexSparse(int, int, int, int)",
1647 string(
"Unable to allocate ")
1648 +
to_str(
sizeof(
int) * (Storage::GetFirst(i, j)+1))
1649 +
" bytes to store " +
to_str(Storage::GetFirst(i, j)+1)
1650 +
string(
" row or column start indices (for the")
1651 +
string(
" imaginary part), for a ")
1655 #ifdef SELDON_CHECK_MEMORY
1661 reinterpret_cast<int*
>( AllocatorInt::
1662 allocate(real_nz_,
this) );
1665 memorycpy(this->real_ind_, A.real_ind_, real_nz_);
1667 #ifdef SELDON_CHECK_MEMORY
1676 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
1678 deallocate(imag_ptr_, Storage::GetFirst(i, j)+1);
1683 this->real_data_ = NULL;
1684 this->imag_data_ = NULL;
1686 if (real_ind_ == NULL)
1693 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
1695 deallocate(imag_ptr_, Storage::GetFirst(i, j)+1);
1698 this->real_data_ = NULL;
1699 this->imag_data_ = NULL;
1701 if (real_ind_ == NULL && i != 0 && j != 0)
1702 throw NoMemory(
string(
"Matrix_ComplexSparse::")
1703 +
"Matrix_ComplexSparse(int, int, int, int)",
1704 string(
"Unable to allocate ")
1705 +
to_str(
sizeof(
int) * real_nz_)
1706 +
" bytes to store " +
to_str(real_nz_)
1707 +
" row or column indices (real part), for a "
1711 #ifdef SELDON_CHECK_MEMORY
1717 reinterpret_cast<int*
>( AllocatorInt::
1718 allocate(imag_nz_,
this) );
1721 memorycpy(this->imag_ind_, A.imag_ind_, imag_nz_);
1723 #ifdef SELDON_CHECK_MEMORY
1732 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
1734 deallocate(imag_ptr_, Storage::GetFirst(i, j)+1);
1737 AllocatorInt::deallocate(imag_ind_, A.imag_nz_);
1740 this->real_data_ = NULL;
1741 this->imag_data_ = NULL;
1743 if (real_ind_ == NULL)
1750 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
1752 deallocate(imag_ptr_, Storage::GetFirst(i, j)+1);
1755 AllocatorInt::deallocate(imag_ind_, A.imag_nz_);
1757 this->real_data_ = NULL;
1758 this->imag_data_ = NULL;
1760 if (imag_ind_ == NULL && i != 0 && j != 0)
1761 throw NoMemory(
string(
"Matrix_ComplexSparse::")
1762 +
"Matrix_ComplexSparse(int, int, int, int)",
1763 string(
"Unable to allocate ")
1764 +
to_str(
sizeof(
int) * imag_nz_)
1765 +
" bytes to store " +
to_str(imag_nz_)
1766 +
" row or column indices (imaginary part), for a "
1770 #ifdef SELDON_CHECK_MEMORY
1775 this->real_data_ = Allocator::allocate(real_nz_,
this);
1776 Allocator::memorycpy(this->real_data_, A.real_data_, real_nz_);
1778 #ifdef SELDON_CHECK_MEMORY
1785 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
1787 deallocate(imag_ptr_, Storage::GetFirst(i, j)+1);
1790 AllocatorInt::deallocate(real_ind_, A.real_nz_);
1791 AllocatorInt::deallocate(imag_ind_, A.imag_nz_);
1794 this->real_data_ = NULL;
1795 this->imag_data_ = NULL;
1797 if (real_data_ == NULL)
1802 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
1804 deallocate(imag_ptr_, Storage::GetFirst(i, j)+1);
1807 AllocatorInt::deallocate(real_ind_, A.real_nz_);
1808 AllocatorInt::deallocate(imag_ind_, A.imag_nz_);
1813 if (real_data_ == NULL && i != 0 && j != 0)
1814 throw NoMemory(
string(
"Matrix_ComplexSparse::")
1815 +
"Matrix_ComplexSparse(int, int, int, int)",
1816 string(
"Unable to allocate ")
1817 +
to_str(
sizeof(
int) * real_nz_)
1818 +
" bytes to store " +
to_str(real_nz_)
1819 +
" values (real part), for a "
1823 #ifdef SELDON_CHECK_MEMORY
1828 this->imag_data_ = Allocator::allocate(imag_nz_,
this);
1829 Allocator::memorycpy(this->imag_data_, A.imag_data_, imag_nz_);
1831 #ifdef SELDON_CHECK_MEMORY
1838 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
1840 deallocate(imag_ptr_, Storage::GetFirst(i, j)+1);
1843 AllocatorInt::deallocate(real_ind_, A.real_nz_);
1844 AllocatorInt::deallocate(imag_ind_, A.imag_nz_);
1847 Allocator::deallocate(this->real_data_, real_nz_);
1848 this->real_data_ = NULL;
1849 this->imag_data_ = NULL;
1851 if (real_data_ == NULL)
1856 deallocate(real_ptr_, Storage::GetFirst(i, j)+1);
1858 deallocate(imag_ptr_, Storage::GetFirst(i, j)+1);
1861 AllocatorInt::deallocate(real_ind_, A.real_nz_);
1862 AllocatorInt::deallocate(imag_ind_, A.imag_nz_);
1865 Allocator::deallocate(this->real_data_, real_nz_);
1868 if (imag_data_ == NULL && i != 0 && j != 0)
1869 throw NoMemory(
string(
"Matrix_ComplexSparse::")
1870 +
"Matrix_ComplexSparse(int, int, int, int)",
1871 string(
"Unable to allocate ")
1872 +
to_str(
sizeof(
int) * imag_nz_)
1873 +
" bytes to store " +
to_str(imag_nz_)
1874 +
" values (imaginary part), for a "
1893 template <
class T,
class Prop,
class Storage,
class Allocator>
1894 const typename Matrix_ComplexSparse<T, Prop, Storage, Allocator>::entry_type
1899 #ifdef SELDON_CHECK_BOUNDS
1900 if (i < 0 || i >= this->m_)
1901 throw WrongRow(
"Matrix_ComplexSparse::operator()",
1902 string(
"Index should be in [0, ") +
to_str(this->m_-1)
1903 +
"], but is equal to " +
to_str(i) +
".");
1904 if (j < 0 || j >= this->n_)
1905 throw WrongCol(
"Matrix_ComplexSparse::operator()",
1906 string(
"Index should be in [0, ") +
to_str(this->n_-1)
1907 +
"], but is equal to " +
to_str(j) +
".");
1910 long real_k, imag_k;
int l;
1911 long real_a, real_b;
1912 long imag_a, imag_b;
1914 real_a = real_ptr_[Storage::GetFirst(i, j)];
1915 real_b = real_ptr_[Storage::GetFirst(i, j) + 1];
1917 imag_a = imag_ptr_[Storage::GetFirst(i, j)];
1918 imag_b = imag_ptr_[Storage::GetFirst(i, j) + 1];
1919 if (real_a != real_b)
1921 l = Storage::GetSecond(i, j);
1922 for (real_k = real_a;
1923 (real_k <real_b-1) && (real_ind_[real_k] < l);
1925 if (imag_a != imag_b)
1927 for (imag_k = imag_a;
1928 (imag_k < imag_b-1) && (imag_ind_[imag_k] < l);
1930 if (real_ind_[real_k] == l)
1932 if (imag_ind_[imag_k] == l)
1933 return entry_type(real_data_[real_k], imag_data_[imag_k]);
1935 return entry_type(real_data_[real_k], value_type(0));
1938 if (imag_ind_[imag_k] == l)
1939 return entry_type(value_type(0), imag_data_[imag_k]);
1941 return entry_type(value_type(0), value_type(0));
1945 if (real_ind_[real_k] == l)
1946 return entry_type(real_data_[real_k], value_type(0));
1948 return entry_type(value_type(0), value_type(0));
1953 if (imag_a != imag_b)
1955 l = Storage::GetSecond(i, j);
1956 for (imag_k = imag_a;
1957 (imag_k < imag_b-1) && (imag_ind_[imag_k] < l);
1959 if (imag_ind_[imag_k] == l)
1960 return entry_type(value_type(0), imag_data_[imag_k]);
1962 return entry_type(value_type(0), value_type(0));
1965 return entry_type(value_type(0), value_type(0));
1980 template <
class T,
class Prop,
class Storage,
class Allocator>
1986 #ifdef SELDON_CHECK_BOUNDS
1987 if (i < 0 || i >= this->m_)
1988 throw WrongRow(
"Matrix_ComplexSparse::ValReal(int, int)",
1989 string(
"Index should be in [0, ") +
to_str(this->m_-1)
1990 +
"], but is equal to " +
to_str(i) +
".");
1991 if (j < 0 || j >= this->n_)
1992 throw WrongCol(
"Matrix_ComplexSparse::ValReal(int, int)",
1993 string(
"Index should be in [0, ") +
to_str(this->n_-1)
1994 +
"], but is equal to " +
to_str(j) +
".");
2000 a = real_ptr_[Storage::GetFirst(i, j)];
2001 b = real_ptr_[Storage::GetFirst(i, j) + 1];
2004 throw WrongArgument(
"Matrix_ComplexSparse::ValReal(int, int)",
2005 "No reference to element (" +
to_str(i) +
", "
2007 +
") can be returned: it is a zero entry.");
2009 l = Storage::GetSecond(i, j);
2011 for (k = a; (k < b-1) && (real_ind_[k] < l); k++);
2013 if (real_ind_[k] == l)
2014 return this->real_data_[k];
2016 throw WrongArgument(
"Matrix_ComplexSparse::ValReal(int, int)",
2017 "No reference to element (" +
to_str(i) +
", "
2019 +
") can be returned: it is a zero entry.");
2032 template <
class T,
class Prop,
class Storage,
class Allocator>
2038 #ifdef SELDON_CHECK_BOUNDS
2039 if (i < 0 || i >= this->m_)
2040 throw WrongRow(
"Matrix_ComplexSparse::ValReal(int, int)",
2041 string(
"Index should be in [0, ") +
to_str(this->m_-1)
2042 +
"], but is equal to " +
to_str(i) +
".");
2043 if (j < 0 || j >= this->n_)
2044 throw WrongCol(
"Matrix_ComplexSparse::ValReal(int, int)",
2045 string(
"Index should be in [0, ") +
to_str(this->n_-1)
2046 +
"], but is equal to " +
to_str(j) +
".");
2052 a = real_ptr_[Storage::GetFirst(i, j)];
2053 b = real_ptr_[Storage::GetFirst(i, j) + 1];
2056 throw WrongArgument(
"Matrix_ComplexSparse::ValReal(int, int)",
2057 "No reference to element (" +
to_str(i) +
", "
2059 +
") can be returned: it is a zero entry.");
2061 l = Storage::GetSecond(i, j);
2063 for (k = a; (k < b-1) && (real_ind_[k] < l); k++);
2065 if (real_ind_[k] == l)
2066 return this->real_data_[k];
2068 throw WrongArgument(
"Matrix_ComplexSparse::ValReal(int, int)",
2069 "No reference to element (" +
to_str(i) +
", "
2071 +
") can be returned: it is a zero entry.");
2084 template <
class T,
class Prop,
class Storage,
class Allocator>
2090 #ifdef SELDON_CHECK_BOUNDS
2091 if (i < 0 || i >= this->m_)
2092 throw WrongRow(
"Matrix_ComplexSparse::ValImag(int, int)",
2093 string(
"Index should be in [0, ") +
to_str(this->m_-1)
2094 +
"], but is equal to " +
to_str(i) +
".");
2095 if (j < 0 || j >= this->n_)
2096 throw WrongCol(
"Matrix_ComplexSparse::ValImag(int, int)",
2097 string(
"Index should be in [0, ") +
to_str(this->n_-1)
2098 +
"], but is equal to " +
to_str(j) +
".");
2104 a = imag_ptr_[Storage::GetFirst(i, j)];
2105 b = imag_ptr_[Storage::GetFirst(i, j) + 1];
2108 throw WrongArgument(
"Matrix_ComplexSparse::ValImag(int, int)",
2109 "No reference to element (" +
to_str(i) +
", "
2111 +
") can be returned: it is a zero entry.");
2113 l = Storage::GetSecond(i, j);
2115 for (k = a; (k < b-1) && (imag_ind_[k] < l); k++);
2117 if (imag_ind_[k] == l)
2118 return this->imag_data_[k];
2120 throw WrongArgument(
"Matrix_ComplexSparse::ValImag(int, int)",
2121 "No reference to element (" +
to_str(i) +
", "
2123 +
") can be returned: it is a zero entry.");
2136 template <
class T,
class Prop,
class Storage,
class Allocator>
2142 #ifdef SELDON_CHECK_BOUNDS
2143 if (i < 0 || i >= this->m_)
2144 throw WrongRow(
"Matrix_ComplexSparse::ValImag(int, int)",
2145 string(
"Index should be in [0, ") +
to_str(this->m_-1)
2146 +
"], but is equal to " +
to_str(i) +
".");
2147 if (j < 0 || j >= this->n_)
2148 throw WrongCol(
"Matrix_ComplexSparse::ValImag(int, int)",
2149 string(
"Index should be in [0, ") +
to_str(this->n_-1)
2150 +
"], but is equal to " +
to_str(j) +
".");
2156 a = imag_ptr_[Storage::GetFirst(i, j)];
2157 b = imag_ptr_[Storage::GetFirst(i, j) + 1];
2160 throw WrongArgument(
"Matrix_ComplexSparse::ValImag(int, int)",
2161 "No reference to element (" +
to_str(i) +
", "
2163 +
") can be returned: it is a zero entry.");
2165 l = Storage::GetSecond(i, j);
2167 for (k = a; (k < b-1) && (imag_ind_[k] < l); k++);
2169 if (imag_ind_[k] == l)
2170 return this->imag_data_[k];
2172 throw WrongArgument(
"Matrix_ComplexSparse::ValImag(int, int)",
2173 "No reference to element (" +
to_str(i) +
", "
2175 +
") can be returned: it is a zero entry.");
2187 template <
class T,
class Prop,
class Storage,
class Allocator>
2193 #ifdef SELDON_CHECK_BOUNDS
2194 if (i < 0 || i >= this->m_)
2195 throw WrongRow(
"Matrix_ComplexSparse::GetReal(int, int)",
2196 string(
"Index should be in [0, ") +
to_str(this->m_-1)
2197 +
"], but is equal to " +
to_str(i) +
".");
2198 if (j < 0 || j >= this->n_)
2199 throw WrongCol(
"Matrix_ComplexSparse::GetReal(int, int)",
2200 string(
"Index should be in [0, ") +
to_str(this->n_-1)
2201 +
"], but is equal to " +
to_str(j) +
".");
2207 a = real_ptr_[Storage::GetFirst(i, j)];
2208 b = real_ptr_[Storage::GetFirst(i, j) + 1];
2212 l = Storage::GetSecond(i, j);
2214 for (k = a; (k < b) && (real_ind_[k] < l); k++);
2216 if ( (k < b) && (real_ind_[k] == l))
2217 return this->real_data_[k];
2223 Resize(this->m_, this->n_, real_nz_+1, imag_nz_);
2225 for (
int m = Storage::GetFirst(i, j)+1;
2226 m <= Storage::GetFirst(this->m_, this->n_); m++)
2229 for (
long m = real_nz_-1; m >= k+1; m--)
2231 real_ind_[m] = real_ind_[m-1];
2232 this->real_data_[m] = this->real_data_[m-1];
2235 real_ind_[k] = Storage::GetSecond(i, j);
2238 SetComplexZero(this->real_data_[k]);
2240 return this->real_data_[k];
2252 template <
class T,
class Prop,
class Storage,
class Allocator>
2258 #ifdef SELDON_CHECK_BOUNDS
2259 if (i < 0 || i >= this->m_)
2260 throw WrongRow(
"Matrix_ComplexSparse::GetImag(int, int)",
2261 string(
"Index should be in [0, ") +
to_str(this->m_-1)
2262 +
"], but is equal to " +
to_str(i) +
".");
2263 if (j < 0 || j >= this->n_)
2264 throw WrongCol(
"Matrix_ComplexSparse::GetImag(int, int)",
2265 string(
"Index should be in [0, ") +
to_str(this->n_-1)
2266 +
"], but is equal to " +
to_str(j) +
".");
2272 a = imag_ptr_[Storage::GetFirst(i, j)];
2273 b = imag_ptr_[Storage::GetFirst(i, j) + 1];
2277 l = Storage::GetSecond(i, j);
2279 for (k = a; (k < b) && (imag_ind_[k] < l); k++);
2281 if ( (k < b) && (imag_ind_[k] == l))
2282 return this->imag_data_[k];
2288 Resize(this->m_, this->n_, real_nz_, imag_nz_+1);
2289 for (
int m = Storage::GetFirst(i, j)+1;
2290 m <= Storage::GetFirst(this->m_, this->n_); m++)
2293 for (
long m = imag_nz_-1; m >= k+1; m--)
2295 imag_ind_[m] = imag_ind_[m-1];
2296 this->imag_data_[m] = this->imag_data_[m-1];
2299 imag_ind_[k] = Storage::GetSecond(i, j);
2302 SetComplexZero(this->imag_data_[k]);
2304 return this->imag_data_[k];
2315 template <
class T,
class Prop,
class Storage,
class Allocator>
2318 Allocator::memoryset(this->real_data_,
char(0),
2319 this->real_nz_ *
sizeof(value_type));
2321 Allocator::memoryset(this->imag_data_,
char(0),
2322 this->imag_nz_ *
sizeof(value_type));
2330 template <
class T,
class Prop,
class Storage,
class Allocator>
2344 real_ptr(Storage::GetFirst(m, n) + 1);
2349 real_values.Fill(value_type(1));
2354 for (i = 0; i < nz + 1; i++)
2357 for (i = nz + 1; i < real_ptr.GetM(); i++)
2360 SetData(m, n, real_values, real_ptr, real_ind,
2361 imag_values, imag_ptr, imag_ind);
2369 template <
class T,
class Prop,
class Storage,
class Allocator>
2372 for (
long i = 0; i < this->real_nz_; i++)
2375 for (
long i = 0; i < this->imag_nz_; i++)
2376 this->imag_data_[i] = value_type(0);
2384 template <
class T,
class Prop,
class Storage,
class Allocator>
2388 for (
long i = 0; i < this->real_nz_; i++)
2389 this->real_data_[i] = real(x);
2391 for (
long i = 0; i < this->imag_nz_; i++)
2392 this->imag_data_[i] = imag(x);
2400 template <
class T,
class Prop,
class Storage,
class Allocator>
2403 #ifndef SELDON_WITHOUT_REINIT_RANDOM
2406 for (
long i = 0; i < this->real_nz_; i++)
2409 for (
long i = 0; i < this->imag_nz_; i++)
2420 template <
class T,
class Prop,
class Storage,
class Allocator>
2423 for (
int i = 0; i < this->m_; i++)
2425 for (
int j = 0; j < this->n_; j++)
2426 cout << (*
this)(i, j) <<
"\t";
2437 template <
class T,
class Prop,
class Storage,
class Allocator>
2441 ofstream FileStream;
2442 FileStream.open(FileName.c_str(), ofstream::binary);
2444 #ifdef SELDON_CHECK_IO
2446 if (!FileStream.is_open())
2447 throw IOError(
"Matrix_ComplexSparse::Write(string FileName)",
2448 string(
"Unable to open file \"") + FileName +
"\".");
2451 this->Write(FileStream);
2462 template <
class T,
class Prop,
class Storage,
class Allocator>
2466 #ifdef SELDON_CHECK_IO
2468 if (!FileStream.good())
2469 throw IOError(
"Matrix_ComplexSparse::Write(ofstream& FileStream)",
2470 "Stream is not ready.");
2473 FileStream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&this->m_)),
2475 FileStream.write(
reinterpret_cast<char*
>(
const_cast<int*
>(&this->n_)),
2477 FileStream.write(
reinterpret_cast<char*
>(
const_cast<long*
>(&this->real_nz_)),
2479 FileStream.write(
reinterpret_cast<char*
>(
const_cast<long*
>(&this->imag_nz_)),
2482 FileStream.write(
reinterpret_cast<char*
>(this->real_ptr_),
2483 sizeof(
long)*(Storage::GetFirst(this->m_, this->n_)+1));
2484 FileStream.write(
reinterpret_cast<char*
>(this->real_ind_),
2485 sizeof(
int)*this->real_nz_);
2486 FileStream.write(
reinterpret_cast<char*
>(this->real_data_),
2487 sizeof(value_type)*this->real_nz_);
2489 FileStream.write(
reinterpret_cast<char*
>(this->imag_ptr_),
2490 sizeof(
long)*(Storage::GetFirst(this->m_, this->n_)+1));
2491 FileStream.write(
reinterpret_cast<char*
>(this->imag_ind_),
2492 sizeof(
int)*this->imag_nz_);
2493 FileStream.write(
reinterpret_cast<char*
>(this->imag_data_),
2494 sizeof(value_type)*this->imag_nz_);
2505 template <
class T,
class Prop,
class Storage,
class Allocator>
2509 ofstream FileStream; FileStream.precision(14);
2510 FileStream.open(FileName.c_str());
2513 FileStream.precision(cout.precision());
2515 #ifdef SELDON_CHECK_IO
2517 if (!FileStream.is_open())
2518 throw IOError(
"Matrix_ComplexSparse::Write(string FileName)",
2519 string(
"Unable to open file \"") + FileName +
"\".");
2522 this->WriteText(FileStream, cplx);
2535 template <
class T,
class Prop,
class Storage,
class Allocator>
2540 #ifdef SELDON_CHECK_IO
2542 if (!FileStream.good())
2543 throw IOError(
"Matrix_ComplexSparse::Write(ofstream& FileStream)",
2544 "Stream is not ready.");
2551 entry_type zero;
int index = 1;
2552 WriteCoordinateMatrix(leaf_class, FileStream, zero, index, cplx);
2561 template <
class T,
class Prop,
class Storage,
class Allocator>
2565 ifstream FileStream;
2566 FileStream.open(FileName.c_str(), ifstream::binary);
2568 #ifdef SELDON_CHECK_IO
2570 if (!FileStream.is_open())
2571 throw IOError(
"Matrix_ComplexSparse::Read(string FileName)",
2572 string(
"Unable to open file \"") + FileName +
"\".");
2575 this->Read(FileStream);
2586 template <
class T,
class Prop,
class Storage,
class Allocator>
2591 #ifdef SELDON_CHECK_IO
2593 if (!FileStream.good())
2594 throw IOError(
"Matrix_ComplexSparse::Read(istream& FileStream)",
2595 "Stream is not ready.");
2598 int m, n, real_nz, imag_nz;
2599 FileStream.read(
reinterpret_cast<char*
>(&m),
sizeof(
int));
2600 FileStream.read(
reinterpret_cast<char*
>(&n),
sizeof(
int));
2601 FileStream.read(
reinterpret_cast<char*
>(&real_nz),
sizeof(
long));
2602 FileStream.read(
reinterpret_cast<char*
>(&imag_nz),
sizeof(
long));
2604 Reallocate(m, n, real_nz, imag_nz);
2606 FileStream.read(
reinterpret_cast<char*
>(real_ptr_),
2607 sizeof(
long)*(Storage::GetFirst(m, n)+1));
2608 FileStream.read(
reinterpret_cast<char*
>(real_ind_),
sizeof(
int)*real_nz);
2609 FileStream.read(
reinterpret_cast<char*
>(this->real_data_),
2610 sizeof(value_type)*real_nz);
2612 FileStream.read(
reinterpret_cast<char*
>(imag_ptr_),
2613 sizeof(
long)*(Storage::GetFirst(m, n)+1));
2614 FileStream.read(
reinterpret_cast<char*
>(imag_ind_),
sizeof(
int)*imag_nz);
2615 FileStream.read(
reinterpret_cast<char*
>(this->imag_data_),
2616 sizeof(value_type)*imag_nz);
2618 #ifdef SELDON_CHECK_IO
2620 if (!FileStream.good())
2621 throw IOError(
"Matrix_ComplexSparse::Read(istream& FileStream)",
2622 string(
"Input operation failed.")
2623 +
string(
" The input file may have been removed")
2624 +
" or may not contain enough data.");
2635 template <
class T,
class Prop,
class Storage,
class Allocator>
2639 ifstream FileStream;
2640 FileStream.open(FileName.c_str());
2642 #ifdef SELDON_CHECK_IO
2644 if (!FileStream.is_open())
2645 throw IOError(
"Matrix_ComplexSparse::ReadText(string FileName)",
2646 string(
"Unable to open file \"") + FileName +
"\".");
2649 this->ReadText(FileStream, cplx);
2660 template <
class T,
class Prop,
class Storage,
class Allocator>
2667 entry_type zero;
int index = 1;
2668 ReadCoordinateMatrix(leaf_class, FileStream, zero, index, -1, cplx);
2674 #define SELDON_FILE_MATRIX_COMPLEXSPARSE_CXX