matrix_sparse/Matrix_ComplexSparse.cxx

00001 // Copyright (C) 2001-2009 Vivien Mallet
00002 // Copyright (C) 2003-2009 Marc Duruflé
00003 //
00004 // This file is part of the linear-algebra library Seldon,
00005 // http://seldon.sourceforge.net/.
00006 //
00007 // Seldon is free software; you can redistribute it and/or modify it under the
00008 // terms of the GNU Lesser General Public License as published by the Free
00009 // Software Foundation; either version 2.1 of the License, or (at your option)
00010 // any later version.
00011 //
00012 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
00013 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
00015 // more details.
00016 //
00017 // You should have received a copy of the GNU Lesser General Public License
00018 // along with Seldon. If not, see http://www.gnu.org/licenses/.
00019 
00020 
00021 #ifndef SELDON_FILE_MATRIX_COMPLEXSPARSE_CXX
00022 
00023 #include "Matrix_ComplexSparse.hxx"
00024 
00025 namespace Seldon
00026 {
00027 
00028 
00029   /****************
00030    * CONSTRUCTORS *
00031    ****************/
00032 
00033 
00035 
00038   template <class T, class Prop, class Storage, class Allocator>
00039   inline Matrix_ComplexSparse<T, Prop, Storage, Allocator>
00040   ::Matrix_ComplexSparse(): Matrix_Base<T, Allocator>()
00041   {
00042     real_nz_ = 0;
00043     imag_nz_ = 0;
00044     real_ptr_ = NULL;
00045     imag_ptr_ = NULL;
00046     real_ind_ = NULL;
00047     imag_ind_ = NULL;
00048     real_data_ = NULL;
00049     imag_data_ = NULL;
00050   }
00051 
00052 
00054 
00059   template <class T, class Prop, class Storage, class Allocator>
00060   inline Matrix_ComplexSparse<T, Prop, Storage, Allocator>
00061   ::Matrix_ComplexSparse(int i, int j): Matrix_Base<T, Allocator>(i, j)
00062   {
00063     real_nz_ = 0;
00064     imag_nz_ = 0;
00065     real_ptr_ = NULL;
00066     imag_ptr_ = NULL;
00067     real_ind_ = NULL;
00068     imag_ind_ = NULL;
00069     real_data_ = NULL;
00070     imag_data_ = NULL;
00071   }
00072 
00073 
00075 
00085   template <class T, class Prop, class Storage, class Allocator>
00086   inline Matrix_ComplexSparse<T, Prop, Storage, Allocator>::
00087   Matrix_ComplexSparse(int i, int j, int real_nz, int imag_nz):
00088     Matrix_Base<T, Allocator>(i, j)
00089   {
00090     this->real_nz_ = real_nz;
00091     this->imag_nz_ = imag_nz;
00092 
00093 #ifdef SELDON_CHECK_DIMENSIONS
00094     if (real_nz_ < 0 || imag_nz_ < 0)
00095       {
00096         this->m_ = 0;
00097         this->n_ = 0;
00098         real_nz_ = 0;
00099         imag_nz_ = 0;
00100         real_ptr_ = NULL;
00101         imag_ptr_ = NULL;
00102         real_ind_ = NULL;
00103         imag_ind_ = NULL;
00104         this->real_data_ = NULL;
00105         this->imag_data_ = NULL;
00106         throw WrongDim(string("Matrix_ComplexSparse::")
00107                        + "Matrix_ComplexSparse(int, int, int, int)",
00108                        "Invalid number of non-zero elements: "
00109                        + to_str(real_nz) + " in the real part and "
00110                        + to_str(imag_nz) + " in the imaginary part.");
00111       }
00112     if ((real_nz_ > 0
00113          && (j == 0
00114              || static_cast<long int>(real_nz_-1) / static_cast<long int>(j)
00115              >= static_cast<long int>(i)))
00116         ||
00117         (imag_nz_ > 0
00118          && (j == 0
00119              || static_cast<long int>(imag_nz_-1) / static_cast<long int>(j)
00120              >= static_cast<long int>(i))))
00121       {
00122         this->m_ = 0;
00123         this->n_ = 0;
00124         real_nz_ = 0;
00125         imag_nz_ = 0;
00126         real_ptr_ = NULL;
00127         imag_ptr_ = NULL;
00128         real_ind_ = NULL;
00129         imag_ind_ = NULL;
00130         this->real_data_ = NULL;
00131         this->imag_data_ = NULL;
00132         throw WrongDim(string("Matrix_ComplexSparse::")
00133                        + "Matrix_ComplexSparse(int, int, int, int)",
00134                        string("There are more values (") + to_str(real_nz)
00135                        + " values for the real part and " + to_str(imag_nz)
00136                        + string(" values for the imaginary part) than")
00137                        + " elements in the matrix (" + to_str(i) + " by "
00138                        + to_str(j) + ").");
00139       }
00140 #endif
00141 
00142 #ifdef SELDON_CHECK_MEMORY
00143     try
00144       {
00145 #endif
00146 
00147         real_ptr_ = reinterpret_cast<int*>( calloc(Storage::GetFirst(i, j)+1,
00148                                                    sizeof(int)) );
00149 
00150 #ifdef SELDON_CHECK_MEMORY
00151       }
00152     catch (...)
00153       {
00154         this->m_ = 0;
00155         this->n_ = 0;
00156         real_nz_ = 0;
00157         imag_nz_ = 0;
00158         real_ptr_ = NULL;
00159         imag_ptr_ = NULL;
00160         real_ind_ = NULL;
00161         imag_ind_ = NULL;
00162         this->real_data_ = NULL;
00163         this->imag_data_ = NULL;
00164       }
00165     if (real_ptr_ == NULL)
00166       {
00167         this->m_ = 0;
00168         this->n_ = 0;
00169         real_nz_ = 0;
00170         imag_nz_ = 0;
00171         imag_ptr_ = 0;
00172         real_ind_ = NULL;
00173         imag_ind_ = NULL;
00174         this->real_data_ = NULL;
00175         this->imag_data_ = NULL;
00176       }
00177     if (real_ptr_ == NULL && i != 0 && j != 0)
00178       throw NoMemory(string("Matrix_ComplexSparse::")
00179                      + "Matrix_ComplexSparse(int, int, int, int)",
00180                      string("Unable to allocate ")
00181                      + to_str(sizeof(int) * (Storage::GetFirst(i, j)+1))
00182                      + " bytes to store " + to_str(Storage::GetFirst(i, j)+1)
00183                      + string(" row or column start indices (for the real")
00184                      + " part), for a "
00185                      + to_str(i) + " by " + to_str(j) + " matrix.");
00186 #endif
00187 
00188 #ifdef SELDON_CHECK_MEMORY
00189     try
00190       {
00191 #endif
00192 
00193         imag_ptr_ = reinterpret_cast<int*>( calloc(Storage::GetFirst(i, j)+1,
00194                                                    sizeof(int)) );
00195 
00196 #ifdef SELDON_CHECK_MEMORY
00197       }
00198     catch (...)
00199       {
00200         this->m_ = 0;
00201         this->n_ = 0;
00202         real_nz_ = 0;
00203         imag_nz_ = 0;
00204         free(real_ptr_);
00205         real_ptr_ = NULL;
00206         imag_ptr_ = NULL;
00207         real_ind_ = NULL;
00208         imag_ind_ = NULL;
00209         this->real_data_ = NULL;
00210         this->imag_data_ = NULL;
00211       }
00212     if (imag_ptr_ == NULL)
00213       {
00214         this->m_ = 0;
00215         this->n_ = 0;
00216         real_nz_ = 0;
00217         imag_nz_ = 0;
00218         free(real_ptr_);
00219         real_ptr_ = 0;
00220         real_ind_ = NULL;
00221         imag_ind_ = NULL;
00222         this->real_data_ = NULL;
00223         this->imag_data_ = NULL;
00224       }
00225     if (imag_ptr_ == NULL && i != 0 && j != 0)
00226       throw NoMemory(string("Matrix_ComplexSparse::")
00227                      + "Matrix_ComplexSparse(int, int, int, int)",
00228                      string("Unable to allocate ")
00229                      + to_str(sizeof(int) * (Storage::GetFirst(i, j)+1))
00230                      + " bytes to store " + to_str(Storage::GetFirst(i, j)+1)
00231                      + string(" row or column start indices (for the")
00232                      + string(" imaginary part), for a ")
00233                      + to_str(i) + " by " + to_str(j) + " matrix.");
00234 #endif
00235 
00236 #ifdef SELDON_CHECK_MEMORY
00237     try
00238       {
00239 #endif
00240 
00241         real_ind_ = reinterpret_cast<int*>( calloc(real_nz_, sizeof(int)) );
00242 
00243 #ifdef SELDON_CHECK_MEMORY
00244       }
00245     catch (...)
00246       {
00247         this->m_ = 0;
00248         this->n_ = 0;
00249         real_nz_ = 0;
00250         imag_nz_ = 0;
00251         free(real_ptr_);
00252         free(imag_ptr_);
00253         real_ptr_ = NULL;
00254         imag_ptr_ = NULL;
00255         real_ind_ = NULL;
00256         imag_ind_ = NULL;
00257         this->real_data_ = NULL;
00258         this->imag_data_ = NULL;
00259       }
00260     if (real_ind_ == NULL)
00261       {
00262         this->m_ = 0;
00263         this->n_ = 0;
00264         real_nz_ = 0;
00265         imag_nz_ = 0;
00266         free(real_ptr_);
00267         free(imag_ptr_);
00268         real_ptr_ = NULL;
00269         imag_ptr_ = NULL;
00270         this->real_data_ = NULL;
00271         this->imag_data_ = NULL;
00272       }
00273     if (real_ind_ == NULL && i != 0 && j != 0)
00274       throw NoMemory(string("Matrix_ComplexSparse::")
00275                      + "Matrix_ComplexSparse(int, int, int, int)",
00276                      string("Unable to allocate ")
00277                      + to_str(sizeof(int) * real_nz)
00278                      + " bytes to store " + to_str(real_nz)
00279                      + " row or column indices (real part), for a "
00280                      + to_str(i) + " by " + to_str(j) + " matrix.");
00281 #endif
00282 
00283 #ifdef SELDON_CHECK_MEMORY
00284     try
00285       {
00286 #endif
00287 
00288         imag_ind_ = reinterpret_cast<int*>( calloc(imag_nz_, sizeof(int)) );
00289 
00290 #ifdef SELDON_CHECK_MEMORY
00291       }
00292     catch (...)
00293       {
00294         this->m_ = 0;
00295         this->n_ = 0;
00296         real_nz_ = 0;
00297         imag_nz_ = 0;
00298         free(real_ptr_);
00299         free(imag_ptr_);
00300         real_ptr_ = NULL;
00301         imag_ptr_ = NULL;
00302         free(imag_ind_);
00303         real_ind_ = NULL;
00304         imag_ind_ = NULL;
00305         this->real_data_ = NULL;
00306         this->imag_data_ = NULL;
00307       }
00308     if (real_ind_ == NULL)
00309       {
00310         this->m_ = 0;
00311         this->n_ = 0;
00312         real_nz_ = 0;
00313         imag_nz_ = 0;
00314         free(real_ptr_);
00315         free(imag_ptr_);
00316         real_ptr_ = NULL;
00317         imag_ptr_ = NULL;
00318         free(imag_ind_);
00319         imag_ind_ = NULL;
00320         this->real_data_ = NULL;
00321         this->imag_data_ = NULL;
00322       }
00323     if (imag_ind_ == NULL && i != 0 && j != 0)
00324       throw NoMemory(string("Matrix_ComplexSparse::")
00325                      + "Matrix_ComplexSparse(int, int, int, int)",
00326                      string("Unable to allocate ")
00327                      + to_str(sizeof(int) * imag_nz)
00328                      + " bytes to store " + to_str(imag_nz)
00329                      + " row or column indices (imaginary part), for a "
00330                      + to_str(i) + " by " + to_str(j) + " matrix.");
00331 #endif
00332 
00333 #ifdef SELDON_CHECK_MEMORY
00334     try
00335       {
00336 #endif
00337 
00338         this->real_data_ = this->allocator_.allocate(real_nz_, this);
00339 
00340 #ifdef SELDON_CHECK_MEMORY
00341       }
00342     catch (...)
00343       {
00344         this->m_ = 0;
00345         this->n_ = 0;
00346         free(real_ptr_);
00347         free(imag_ptr_);
00348         real_ptr_ = NULL;
00349         imag_ptr_ = NULL;
00350         free(real_ind_);
00351         free(imag_ind_);
00352         real_ind_ = NULL;
00353         imag_ind_ = NULL;
00354         this->real_data_ = NULL;
00355         this->imag_data_ = NULL;
00356       }
00357     if (real_data_ == NULL)
00358       {
00359         this->m_ = 0;
00360         this->n_ = 0;
00361         free(real_ptr_);
00362         free(imag_ptr_);
00363         real_ptr_ = NULL;
00364         imag_ptr_ = NULL;
00365         free(real_ind_);
00366         free(imag_ind_);
00367         real_ind_ = NULL;
00368         imag_ind_ = NULL;
00369         imag_data_ = NULL;
00370       }
00371     if (real_data_ == NULL && i != 0 && j != 0)
00372       throw NoMemory(string("Matrix_ComplexSparse::")
00373                      + "Matrix_ComplexSparse(int, int, int, int)",
00374                      string("Unable to allocate ")
00375                      + to_str(sizeof(int) * real_nz)
00376                      + " bytes to store " + to_str(real_nz)
00377                      + " values (real part), for a "
00378                      + to_str(i) + " by " + to_str(j) + " matrix.");
00379 #endif
00380 
00381 #ifdef SELDON_CHECK_MEMORY
00382     try
00383       {
00384 #endif
00385 
00386         this->imag_data_ = this->allocator_.allocate(imag_nz_, this);
00387 
00388 #ifdef SELDON_CHECK_MEMORY
00389       }
00390     catch (...)
00391       {
00392         this->m_ = 0;
00393         this->n_ = 0;
00394         free(real_ptr_);
00395         free(imag_ptr_);
00396         real_ptr_ = NULL;
00397         imag_ptr_ = NULL;
00398         free(real_ind_);
00399         free(imag_ind_);
00400         real_ind_ = NULL;
00401         imag_ind_ = NULL;
00402         this->allocator_.deallocate(this->real_data_, real_nz_);
00403         this->real_data_ = NULL;
00404         this->imag_data_ = NULL;
00405       }
00406     if (real_data_ == NULL)
00407       {
00408         this->m_ = 0;
00409         this->n_ = 0;
00410         free(real_ptr_);
00411         free(imag_ptr_);
00412         real_ptr_ = NULL;
00413         imag_ptr_ = NULL;
00414         free(real_ind_);
00415         free(imag_ind_);
00416         real_ind_ = NULL;
00417         imag_ind_ = NULL;
00418         this->allocator_.deallocate(this->real_data_, real_nz_);
00419         real_data_ = NULL;
00420       }
00421     if (imag_data_ == NULL && i != 0 && j != 0)
00422       throw NoMemory(string("Matrix_ComplexSparse::")
00423                      + "Matrix_ComplexSparse(int, int, int, int)",
00424                      string("Unable to allocate ")
00425                      + to_str(sizeof(int) * imag_nz)
00426                      + " bytes to store " + to_str(imag_nz)
00427                      + " values (imaginary part), for a "
00428                      + to_str(i) + " by " + to_str(j) + " matrix.");
00429 #endif
00430 
00431   }
00432 
00433 
00435 
00453   template <class T, class Prop, class Storage, class Allocator>
00454   template <class Storage0, class Allocator0,
00455             class Storage1, class Allocator1,
00456             class Storage2, class Allocator2>
00457   inline Matrix_ComplexSparse<T, Prop, Storage, Allocator>::
00458   Matrix_ComplexSparse(int i, int j,
00459                        Vector<T, Storage0, Allocator0>& real_values,
00460                        Vector<int, Storage1, Allocator1>& real_ptr,
00461                        Vector<int, Storage2, Allocator2>& real_ind,
00462                        Vector<T, Storage0, Allocator0>& imag_values,
00463                        Vector<int, Storage1, Allocator1>& imag_ptr,
00464                        Vector<int, Storage2, Allocator2>& imag_ind):
00465     Matrix_Base<T, Allocator>(i, j)
00466   {
00467 
00468     real_nz_ = real_values.GetLength();
00469     imag_nz_ = imag_values.GetLength();
00470 
00471 #ifdef SELDON_CHECK_DIMENSIONS
00472     // Checks whether vector sizes are acceptable.
00473 
00474     if (real_ind.GetLength() != real_nz_)
00475       {
00476         this->m_ = 0;
00477         this->n_ = 0;
00478         real_nz_ = 0;
00479         imag_nz_ = 0;
00480         real_ptr_ = NULL;
00481         imag_ptr_ = NULL;
00482         real_ind_ = NULL;
00483         imag_ind_ = NULL;
00484         this->real_data_ = NULL;
00485         this->imag_data_ = NULL;
00486         throw WrongDim(string("Matrix_ComplexSparse::")
00487                        + string("Matrix_ComplexSparse(int, int, ")
00488                        + string("const Vector&, const Vector&, const Vector&")
00489                        + ", const Vector&, const Vector&, const Vector&)",
00490                        string("There are ") + to_str(real_nz_)
00491                        + " values (real part) but "
00492                        + to_str(real_ind.GetLength())
00493                        + " row or column indices.");
00494       }
00495 
00496     if (imag_ind.GetLength() != imag_nz_)
00497       {
00498         this->m_ = 0;
00499         this->n_ = 0;
00500         real_nz_ = 0;
00501         imag_nz_ = 0;
00502         real_ptr_ = NULL;
00503         imag_ptr_ = NULL;
00504         real_ind_ = NULL;
00505         imag_ind_ = NULL;
00506         this->real_data_ = NULL;
00507         this->imag_data_ = NULL;
00508         throw WrongDim(string("Matrix_ComplexSparse::")
00509                        + string("Matrix_ComplexSparse(int, int, ")
00510                        + string("const Vector&, const Vector&, const Vector&")
00511                        + ", const Vector&, const Vector&, const Vector&)",
00512                        string("There are ") + to_str(imag_nz_)
00513                        + " values (imaginary part) but "
00514                        + to_str(imag_ind.GetLength())
00515                        + " row or column indices.");
00516       }
00517 
00518     if (real_ptr.GetLength()-1 != Storage::GetFirst(i, j))
00519       {
00520         this->m_ = 0;
00521         this->n_ = 0;
00522         real_nz_ = 0;
00523         imag_nz_ = 0;
00524         real_ptr_ = NULL;
00525         imag_ptr_ = NULL;
00526         real_ind_ = NULL;
00527         imag_ind_ = NULL;
00528         this->real_data_ = NULL;
00529         this->imag_data_ = NULL;
00530         throw WrongDim(string("Matrix_ComplexSparse::")
00531                        + string("Matrix_ComplexSparse(int, int, ")
00532                        + string("const Vector&, const Vector&, const Vector&")
00533                        + ", const Vector&, const Vector&, const Vector&)",
00534                        string("The vector of start indices (real part)")
00535                        + " contains " + to_str(real_ptr.GetLength()-1)
00536                        + string(" row or column start indices (plus the")
00537                        + " number of non-zero entries) but there are "
00538                        + to_str(Storage::GetFirst(i, j))
00539                        + " rows or columns ("
00540                        + to_str(i) + " by " + to_str(j) + " matrix).");
00541       }
00542 
00543     if (imag_ptr.GetLength()-1 != Storage::GetFirst(i, j))
00544       {
00545         this->m_ = 0;
00546         this->n_ = 0;
00547         real_nz_ = 0;
00548         imag_nz_ = 0;
00549         real_ptr_ = NULL;
00550         imag_ptr_ = NULL;
00551         real_ind_ = NULL;
00552         imag_ind_ = NULL;
00553         this->real_data_ = NULL;
00554         this->imag_data_ = NULL;
00555         throw WrongDim(string("Matrix_ComplexSparse::")
00556                        + string("Matrix_ComplexSparse(int, int, ")
00557                        + string("const Vector&, const Vector&, const Vector&")
00558                        + ", const Vector&, const Vector&, const Vector&)",
00559                        string("The vector of start indices (imaginary part)")
00560                        + " contains " + to_str(imag_ptr.GetLength()-1)
00561                        + string(" row or column start indices (plus the")
00562                        + " number of non-zero entries) but there are "
00563                        + to_str(Storage::GetFirst(i, j))
00564                        + " rows or columns ("
00565                        + to_str(i) + " by " + to_str(j) + " matrix).");
00566       }
00567 
00568     if ((real_nz_ > 0
00569          && (j == 0
00570              || static_cast<long int>(real_nz_-1) / static_cast<long int>(j)
00571              >= static_cast<long int>(i)))
00572         ||
00573         (imag_nz_ > 0
00574          && (j == 0
00575              || static_cast<long int>(imag_nz_-1) / static_cast<long int>(j)
00576              >= static_cast<long int>(i))))
00577       {
00578         this->m_ = 0;
00579         this->n_ = 0;
00580         real_nz_ = 0;
00581         imag_nz_ = 0;
00582         real_ptr_ = NULL;
00583         imag_ptr_ = NULL;
00584         real_ind_ = NULL;
00585         imag_ind_ = NULL;
00586         this->real_data_ = NULL;
00587         this->imag_data_ = NULL;
00588         throw WrongDim(string("Matrix_ComplexSparse::")
00589                        + string("Matrix_ComplexSparse(int, int, ")
00590                        + string("const Vector&, const Vector&, const Vector&")
00591                        + ", const Vector&, const Vector&, const Vector&)",
00592                        string("There are more values (")
00593                        + to_str(real_values.GetLength())
00594                        + " values for the real part and "
00595                        + to_str(real_values.GetLength()) + string(" values")
00596                        + string(" for the imaginary part) than elements")
00597                        + " in the matrix ("
00598                        + to_str(i) + " by " + to_str(j) + ").");
00599       }
00600 #endif
00601 
00602     this->real_ptr_ = real_ptr.GetData();
00603     this->imag_ptr_ = imag_ptr.GetData();
00604     this->real_ind_ = real_ind.GetData();
00605     this->imag_ind_ = imag_ind.GetData();
00606     this->real_data_ = real_values.GetData();
00607     this->imag_data_ = imag_values.GetData();
00608 
00609     real_ptr.Nullify();
00610     imag_ptr.Nullify();
00611     real_ind.Nullify();
00612     imag_ind.Nullify();
00613     real_values.Nullify();
00614     imag_values.Nullify();
00615   }
00616 
00617 
00619   template <class T, class Prop, class Storage, class Allocator>
00620   Matrix_ComplexSparse<T, Prop, Storage, Allocator>
00621   ::Matrix_ComplexSparse(const Matrix_ComplexSparse<T, Prop,
00622                          Storage, Allocator>& A)
00623   {
00624     this->m_ = 0;
00625     this->n_ = 0;
00626     real_nz_ = 0;
00627     imag_nz_ = 0;
00628     real_ptr_ = NULL;
00629     imag_ptr_ = NULL;
00630     real_ind_ = NULL;
00631     imag_ind_ = NULL;
00632     real_data_ = NULL;
00633     imag_data_ = NULL;
00634 
00635     this->Copy(A);
00636   }
00637 
00638 
00639   /**************
00640    * DESTRUCTOR *
00641    **************/
00642 
00643 
00645   template <class T, class Prop, class Storage, class Allocator>
00646   inline Matrix_ComplexSparse<T, Prop, Storage, Allocator>
00647   ::~Matrix_ComplexSparse()
00648   {
00649     this->m_ = 0;
00650     this->n_ = 0;
00651 
00652 #ifdef SELDON_CHECK_MEMORY
00653     try
00654       {
00655 #endif
00656 
00657         if (real_ptr_ != NULL)
00658           {
00659             free(real_ptr_);
00660             real_ptr_ = NULL;
00661           }
00662 
00663 #ifdef SELDON_CHECK_MEMORY
00664       }
00665     catch (...)
00666       {
00667         real_ptr_ = NULL;
00668       }
00669 #endif
00670 
00671 #ifdef SELDON_CHECK_MEMORY
00672     try
00673       {
00674 #endif
00675 
00676         if (imag_ptr_ != NULL)
00677           {
00678             free(imag_ptr_);
00679             imag_ptr_ = NULL;
00680           }
00681 
00682 #ifdef SELDON_CHECK_MEMORY
00683       }
00684     catch (...)
00685       {
00686         imag_ptr_ = NULL;
00687       }
00688 #endif
00689 
00690 #ifdef SELDON_CHECK_MEMORY
00691     try
00692       {
00693 #endif
00694 
00695         if (real_ind_ != NULL)
00696           {
00697             free(real_ind_);
00698             real_ind_ = NULL;
00699           }
00700 
00701 #ifdef SELDON_CHECK_MEMORY
00702       }
00703     catch (...)
00704       {
00705         real_ind_ = NULL;
00706       }
00707 #endif
00708 
00709 #ifdef SELDON_CHECK_MEMORY
00710     try
00711       {
00712 #endif
00713 
00714         if (imag_ind_ != NULL)
00715           {
00716             free(imag_ind_);
00717             imag_ind_ = NULL;
00718           }
00719 
00720 #ifdef SELDON_CHECK_MEMORY
00721       }
00722     catch (...)
00723       {
00724         imag_ind_ = NULL;
00725       }
00726 #endif
00727 
00728 #ifdef SELDON_CHECK_MEMORY
00729     try
00730       {
00731 #endif
00732 
00733         if (this->real_data_ != NULL)
00734           {
00735             this->allocator_.deallocate(this->real_data_, real_nz_);
00736             this->real_data_ = NULL;
00737           }
00738 
00739 #ifdef SELDON_CHECK_MEMORY
00740       }
00741     catch (...)
00742       {
00743         this->real_nz_ = 0;
00744         this->real_data_ = NULL;
00745       }
00746 #endif
00747 
00748 #ifdef SELDON_CHECK_MEMORY
00749     try
00750       {
00751 #endif
00752 
00753         if (this->imag_data_ != NULL)
00754           {
00755             this->allocator_.deallocate(this->imag_data_, imag_nz_);
00756             this->imag_data_ = NULL;
00757           }
00758 
00759 #ifdef SELDON_CHECK_MEMORY
00760       }
00761     catch (...)
00762       {
00763         this->imag_nz_ = 0;
00764         this->imag_data_ = NULL;
00765       }
00766 #endif
00767 
00768     this->real_nz_ = 0;
00769     this->imag_nz_ = 0;
00770   }
00771 
00772 
00774 
00777   template <class T, class Prop, class Storage, class Allocator>
00778   inline void Matrix_ComplexSparse<T, Prop, Storage, Allocator>::Clear()
00779   {
00780     this->~Matrix_ComplexSparse();
00781   }
00782 
00783 
00784   /*********************
00785    * MEMORY MANAGEMENT *
00786    *********************/
00787 
00788 
00790 
00807   template <class T, class Prop, class Storage, class Allocator>
00808   template <class Storage0, class Allocator0,
00809             class Storage1, class Allocator1,
00810             class Storage2, class Allocator2>
00811   void Matrix_ComplexSparse<T, Prop, Storage, Allocator>::
00812   SetData(int i, int j,
00813           Vector<T, Storage0, Allocator0>& real_values,
00814           Vector<int, Storage1, Allocator1>& real_ptr,
00815           Vector<int, Storage2, Allocator2>& real_ind,
00816           Vector<T, Storage0, Allocator0>& imag_values,
00817           Vector<int, Storage1, Allocator1>& imag_ptr,
00818           Vector<int, Storage2, Allocator2>& imag_ind)
00819   {
00820     this->Clear();
00821     this->m_ = i;
00822     this->n_ = j;
00823     real_nz_ = real_values.GetLength();
00824     imag_nz_ = imag_values.GetLength();
00825 
00826 #ifdef SELDON_CHECK_DIMENSIONS
00827     // Checks whether vector sizes are acceptable.
00828 
00829     if (real_ind.GetLength() != real_nz_)
00830       {
00831         this->m_ = 0;
00832         this->n_ = 0;
00833         real_nz_ = 0;
00834         imag_nz_ = 0;
00835         real_ptr_ = NULL;
00836         imag_ptr_ = NULL;
00837         real_ind_ = NULL;
00838         imag_ind_ = NULL;
00839         this->real_data_ = NULL;
00840         this->imag_data_ = NULL;
00841         throw WrongDim(string("Matrix_ComplexSparse::SetData(int, int, ")
00842                        + string("const Vector&, const Vector&, const Vector&")
00843                        + ", const Vector&, const Vector&, const Vector&)",
00844                        string("There are ") + to_str(real_nz_)
00845                        + " values (real part) but "
00846                        + to_str(real_ind.GetLength())
00847                        + " row or column indices.");
00848       }
00849 
00850     if (imag_ind.GetLength() != imag_nz_)
00851       {
00852         this->m_ = 0;
00853         this->n_ = 0;
00854         real_nz_ = 0;
00855         imag_nz_ = 0;
00856         real_ptr_ = NULL;
00857         imag_ptr_ = NULL;
00858         real_ind_ = NULL;
00859         imag_ind_ = NULL;
00860         this->real_data_ = NULL;
00861         this->imag_data_ = NULL;
00862         throw WrongDim(string("Matrix_ComplexSparse::SetData(int, int, ")
00863                        + string("const Vector&, const Vector&, const Vector&")
00864                        + ", const Vector&, const Vector&, const Vector&)",
00865                        string("There are ") + to_str(imag_nz_)
00866                        + " values (imaginary part) but "
00867                        + to_str(imag_ind.GetLength())
00868                        + " row or column indices.");
00869       }
00870 
00871     if (real_ptr.GetLength()-1 != Storage::GetFirst(i, j))
00872       {
00873         this->m_ = 0;
00874         this->n_ = 0;
00875         real_nz_ = 0;
00876         imag_nz_ = 0;
00877         real_ptr_ = NULL;
00878         imag_ptr_ = NULL;
00879         real_ind_ = NULL;
00880         imag_ind_ = NULL;
00881         this->real_data_ = NULL;
00882         this->imag_data_ = NULL;
00883         throw WrongDim(string("Matrix_ComplexSparse::SetData(int, int, ")
00884                        + string("const Vector&, const Vector&, const Vector&")
00885                        + ", const Vector&, const Vector&, const Vector&)",
00886                        string("The vector of start indices (real part)")
00887                        + " contains " + to_str(real_ptr.GetLength()-1)
00888                        + string(" row or column start indices (plus the")
00889                        + " number of non-zero entries) but there are "
00890                        + to_str(Storage::GetFirst(i, j))
00891                        + " rows or columns ("
00892                        + to_str(i) + " by " + to_str(j) + " matrix).");
00893       }
00894 
00895     if (imag_ptr.GetLength()-1 != Storage::GetFirst(i, j))
00896       {
00897         this->m_ = 0;
00898         this->n_ = 0;
00899         real_nz_ = 0;
00900         imag_nz_ = 0;
00901         real_ptr_ = NULL;
00902         imag_ptr_ = NULL;
00903         real_ind_ = NULL;
00904         imag_ind_ = NULL;
00905         this->real_data_ = NULL;
00906         this->imag_data_ = NULL;
00907         throw WrongDim(string("Matrix_ComplexSparse::SetData(int, int, ")
00908                        + string("const Vector&, const Vector&, const Vector&")
00909                        + ", const Vector&, const Vector&, const Vector&)",
00910                        string("The vector of start indices (imaginary part)")
00911                        + " contains " + to_str(imag_ptr.GetLength()-1)
00912                        + string(" row or column start indices (plus the")
00913                        + " number of non-zero entries) but there are "
00914                        + to_str(Storage::GetFirst(i, j))
00915                        + " rows or columns ("
00916                        + to_str(i) + " by " + to_str(j) + " matrix).");
00917       }
00918 
00919     if ((real_nz_ > 0
00920          && (j == 0
00921              || static_cast<long int>(real_nz_-1) / static_cast<long int>(j)
00922              >= static_cast<long int>(i)))
00923         ||
00924         (imag_nz_ > 0
00925          && (j == 0
00926              || static_cast<long int>(imag_nz_-1) / static_cast<long int>(j)
00927              >= static_cast<long int>(i))))
00928       {
00929         this->m_ = 0;
00930         this->n_ = 0;
00931         real_nz_ = 0;
00932         imag_nz_ = 0;
00933         real_ptr_ = NULL;
00934         imag_ptr_ = NULL;
00935         real_ind_ = NULL;
00936         imag_ind_ = NULL;
00937         this->real_data_ = NULL;
00938         this->imag_data_ = NULL;
00939         throw WrongDim(string("Matrix_ComplexSparse::SetData(int, int, ")
00940                        + string("const Vector&, const Vector&, const Vector&")
00941                        + ", const Vector&, const Vector&, const Vector&)",
00942                        string("There are more values (")
00943                        + to_str(real_values.GetLength())
00944                        + " values for the real part and "
00945                        + to_str(real_values.GetLength()) + string(" values")
00946                        + string(" for the imaginary part) than elements")
00947                        + " in the matrix ("
00948                        + to_str(i) + " by " + to_str(j) + ").");
00949       }
00950 #endif
00951 
00952     this->real_ptr_ = real_ptr.GetData();
00953     this->imag_ptr_ = imag_ptr.GetData();
00954     this->real_ind_ = real_ind.GetData();
00955     this->imag_ind_ = imag_ind.GetData();
00956     this->real_data_ = real_values.GetData();
00957     this->imag_data_ = imag_values.GetData();
00958 
00959     real_ptr.Nullify();
00960     imag_ptr.Nullify();
00961     real_ind.Nullify();
00962     imag_ind.Nullify();
00963     real_values.Nullify();
00964     imag_values.Nullify();
00965   }
00966 
00967 
00969 
00990   template <class T, class Prop, class Storage, class Allocator>
00991   inline void Matrix_ComplexSparse<T, Prop, Storage, Allocator>::
00992   SetData(int i, int j, int real_nz,
00993           typename Matrix_ComplexSparse<T, Prop, Storage, Allocator>
00994           ::pointer real_values,
00995           int* real_ptr, int* real_ind, int imag_nz,
00996           typename Matrix_ComplexSparse<T, Prop, Storage, Allocator>
00997           ::pointer imag_values,
00998           int* imag_ptr, int* imag_ind)
00999   {
01000     this->Clear();
01001 
01002     this->m_ = i;
01003     this->n_ = j;
01004 
01005     this->real_nz_ = real_nz;
01006     this->imag_nz_ = imag_nz;
01007 
01008     real_data_ = real_values;
01009     imag_data_ = imag_values;
01010     real_ind_ = real_ind;
01011     imag_ind_ = imag_ind;
01012     real_ptr_ = real_ptr;
01013     imag_ptr_ = imag_ptr;
01014   }
01015 
01016 
01018 
01022   template <class T, class Prop, class Storage, class Allocator>
01023   inline void Matrix_ComplexSparse<T, Prop, Storage, Allocator>::Nullify()
01024   {
01025     this->data_ = NULL;
01026     this->m_ = 0;
01027     this->n_ = 0;
01028     real_nz_ = 0;
01029     real_ptr_ = NULL;
01030     real_ind_ = NULL;
01031     imag_nz_ = 0;
01032     imag_ptr_ = NULL;
01033     imag_ind_ = NULL;
01034     real_data_ = NULL;
01035     imag_data_ = NULL;
01036   }
01037 
01038 
01040   template <class T, class Prop, class Storage, class Allocator>
01041   inline void Matrix_ComplexSparse<T, Prop, Storage, Allocator>::
01042   Copy(const Matrix_ComplexSparse<T, Prop, Storage, Allocator>& A)
01043   {
01044     this->Clear();
01045     int i = A.m_;
01046     int j = A.n_;
01047     real_nz_ = A.real_nz_;
01048     imag_nz_ = A.imag_nz_;
01049     this->m_ = i;
01050     this->n_ = j;
01051     if ((i == 0)||(j == 0))
01052       {
01053         this->m_ = 0;
01054         this->n_ = 0;
01055         this->real_nz_ = 0;
01056         this->imag_nz_ = 0;
01057         return;
01058       }
01059 
01060 #ifdef SELDON_CHECK_DIMENSIONS
01061     if ((real_nz_ > 0
01062          && (j == 0
01063              || static_cast<long int>(real_nz_-1) / static_cast<long int>(j)
01064              >= static_cast<long int>(i)))
01065         ||
01066         (imag_nz_ > 0
01067          && (j == 0
01068              || static_cast<long int>(imag_nz_-1) / static_cast<long int>(j)
01069              >= static_cast<long int>(i))))
01070       {
01071         this->m_ = 0;
01072         this->n_ = 0;
01073         real_nz_ = 0;
01074         imag_nz_ = 0;
01075         real_ptr_ = NULL;
01076         imag_ptr_ = NULL;
01077         real_ind_ = NULL;
01078         imag_ind_ = NULL;
01079         this->real_data_ = NULL;
01080         this->imag_data_ = NULL;
01081         throw WrongDim(string("Matrix_ComplexSparse::")
01082                        + "Matrix_ComplexSparse(int, int, int, int)",
01083                        string("There are more values (") + to_str(real_nz_)
01084                        + " values for the real part and " + to_str(imag_nz_)
01085                        + string(" values for the imaginary part) than")
01086                        + " elements in the matrix (" + to_str(i) + " by "
01087                        + to_str(j) + ").");
01088       }
01089 #endif
01090 
01091 #ifdef SELDON_CHECK_MEMORY
01092     try
01093       {
01094 #endif
01095 
01096         real_ptr_ = reinterpret_cast<int*>( calloc(Storage::GetFirst(i, j)+1,
01097                                                    sizeof(int)) );
01098         memcpy(this->real_ptr_, A.real_ptr_,
01099                (Storage::GetFirst(i, j) + 1) * sizeof(int));
01100 
01101 #ifdef SELDON_CHECK_MEMORY
01102       }
01103     catch (...)
01104       {
01105         this->m_ = 0;
01106         this->n_ = 0;
01107         real_nz_ = 0;
01108         imag_nz_ = 0;
01109         real_ptr_ = NULL;
01110         imag_ptr_ = NULL;
01111         real_ind_ = NULL;
01112         imag_ind_ = NULL;
01113         this->real_data_ = NULL;
01114         this->imag_data_ = NULL;
01115       }
01116     if (real_ptr_ == NULL)
01117       {
01118         this->m_ = 0;
01119         this->n_ = 0;
01120         real_nz_ = 0;
01121         imag_nz_ = 0;
01122         imag_ptr_ = 0;
01123         real_ind_ = NULL;
01124         imag_ind_ = NULL;
01125         this->real_data_ = NULL;
01126         this->imag_data_ = NULL;
01127       }
01128     if (real_ptr_ == NULL && i != 0 && j != 0)
01129       throw NoMemory(string("Matrix_ComplexSparse::")
01130                      + "Matrix_ComplexSparse(int, int, int, int)",
01131                      string("Unable to allocate ")
01132                      + to_str(sizeof(int) * (Storage::GetFirst(i, j)+1))
01133                      + " bytes to store " + to_str(Storage::GetFirst(i, j)+1)
01134                      + string(" row or column start indices (for the real")
01135                      + " part), for a "
01136                      + to_str(i) + " by " + to_str(j) + " matrix.");
01137 #endif
01138 
01139 #ifdef SELDON_CHECK_MEMORY
01140     try
01141       {
01142 #endif
01143 
01144         imag_ptr_ = reinterpret_cast<int*>( calloc(Storage::GetFirst(i, j)+1,
01145                                                    sizeof(int)) );
01146         memcpy(this->imag_ptr_, A.imag_ptr_,
01147                (Storage::GetFirst(i, j) + 1) * sizeof(int));
01148 
01149 #ifdef SELDON_CHECK_MEMORY
01150       }
01151     catch (...)
01152       {
01153         this->m_ = 0;
01154         this->n_ = 0;
01155         real_nz_ = 0;
01156         imag_nz_ = 0;
01157         free(real_ptr_);
01158         real_ptr_ = NULL;
01159         imag_ptr_ = NULL;
01160         real_ind_ = NULL;
01161         imag_ind_ = NULL;
01162         this->real_data_ = NULL;
01163         this->imag_data_ = NULL;
01164       }
01165     if (imag_ptr_ == NULL)
01166       {
01167         this->m_ = 0;
01168         this->n_ = 0;
01169         real_nz_ = 0;
01170         imag_nz_ = 0;
01171         free(real_ptr_);
01172         real_ptr_ = 0;
01173         real_ind_ = NULL;
01174         imag_ind_ = NULL;
01175         this->real_data_ = NULL;
01176         this->imag_data_ = NULL;
01177       }
01178     if (imag_ptr_ == NULL && i != 0 && j != 0)
01179       throw NoMemory(string("Matrix_ComplexSparse::")
01180                      + "Matrix_ComplexSparse(int, int, int, int)",
01181                      string("Unable to allocate ")
01182                      + to_str(sizeof(int) * (Storage::GetFirst(i, j)+1))
01183                      + " bytes to store " + to_str(Storage::GetFirst(i, j)+1)
01184                      + string(" row or column start indices (for the")
01185                      + string(" imaginary part), for a ")
01186                      + to_str(i) + " by " + to_str(j) + " matrix.");
01187 #endif
01188 
01189 #ifdef SELDON_CHECK_MEMORY
01190     try
01191       {
01192 #endif
01193 
01194         real_ind_ = reinterpret_cast<int*>( calloc(real_nz_, sizeof(int)) );
01195         memcpy(this->real_ind_, A.real_ind_, real_nz_ * sizeof(int));
01196 
01197 #ifdef SELDON_CHECK_MEMORY
01198       }
01199     catch (...)
01200       {
01201         this->m_ = 0;
01202         this->n_ = 0;
01203         real_nz_ = 0;
01204         imag_nz_ = 0;
01205         free(real_ptr_);
01206         free(imag_ptr_);
01207         real_ptr_ = NULL;
01208         imag_ptr_ = NULL;
01209         real_ind_ = NULL;
01210         imag_ind_ = NULL;
01211         this->real_data_ = NULL;
01212         this->imag_data_ = NULL;
01213       }
01214     if (real_ind_ == NULL)
01215       {
01216         this->m_ = 0;
01217         this->n_ = 0;
01218         real_nz_ = 0;
01219         imag_nz_ = 0;
01220         free(real_ptr_);
01221         free(imag_ptr_);
01222         real_ptr_ = NULL;
01223         imag_ptr_ = NULL;
01224         this->real_data_ = NULL;
01225         this->imag_data_ = NULL;
01226       }
01227     if (real_ind_ == NULL && i != 0 && j != 0)
01228       throw NoMemory(string("Matrix_ComplexSparse::")
01229                      + "Matrix_ComplexSparse(int, int, int, int)",
01230                      string("Unable to allocate ")
01231                      + to_str(sizeof(int) * real_nz_)
01232                      + " bytes to store " + to_str(real_nz_)
01233                      + " row or column indices (real part), for a "
01234                      + to_str(i) + " by " + to_str(j) + " matrix.");
01235 #endif
01236 
01237 #ifdef SELDON_CHECK_MEMORY
01238     try
01239       {
01240 #endif
01241 
01242         imag_ind_ = reinterpret_cast<int*>( calloc(imag_nz_, sizeof(int)) );
01243         memcpy(this->imag_ind_, A.imag_ind_, imag_nz_ * sizeof(int));
01244 
01245 #ifdef SELDON_CHECK_MEMORY
01246       }
01247     catch (...)
01248       {
01249         this->m_ = 0;
01250         this->n_ = 0;
01251         real_nz_ = 0;
01252         imag_nz_ = 0;
01253         free(real_ptr_);
01254         free(imag_ptr_);
01255         real_ptr_ = NULL;
01256         imag_ptr_ = NULL;
01257         free(imag_ind_);
01258         real_ind_ = NULL;
01259         imag_ind_ = NULL;
01260         this->real_data_ = NULL;
01261         this->imag_data_ = NULL;
01262       }
01263     if (real_ind_ == NULL)
01264       {
01265         this->m_ = 0;
01266         this->n_ = 0;
01267         real_nz_ = 0;
01268         imag_nz_ = 0;
01269         free(real_ptr_);
01270         free(imag_ptr_);
01271         real_ptr_ = NULL;
01272         imag_ptr_ = NULL;
01273         free(imag_ind_);
01274         imag_ind_ = NULL;
01275         this->real_data_ = NULL;
01276         this->imag_data_ = NULL;
01277       }
01278     if (imag_ind_ == NULL && i != 0 && j != 0)
01279       throw NoMemory(string("Matrix_ComplexSparse::")
01280                      + "Matrix_ComplexSparse(int, int, int, int)",
01281                      string("Unable to allocate ")
01282                      + to_str(sizeof(int) * imag_nz_)
01283                      + " bytes to store " + to_str(imag_nz_)
01284                      + " row or column indices (imaginary part), for a "
01285                      + to_str(i) + " by " + to_str(j) + " matrix.");
01286 #endif
01287 
01288 #ifdef SELDON_CHECK_MEMORY
01289     try
01290       {
01291 #endif
01292 
01293         this->real_data_ = this->allocator_.allocate(real_nz_, this);
01294         this->allocator_.memorycpy(this->real_data_, A.real_data_, real_nz_);
01295 
01296 #ifdef SELDON_CHECK_MEMORY
01297       }
01298     catch (...)
01299       {
01300         this->m_ = 0;
01301         this->n_ = 0;
01302         free(real_ptr_);
01303         free(imag_ptr_);
01304         real_ptr_ = NULL;
01305         imag_ptr_ = NULL;
01306         free(real_ind_);
01307         free(imag_ind_);
01308         real_ind_ = NULL;
01309         imag_ind_ = NULL;
01310         this->real_data_ = NULL;
01311         this->imag_data_ = NULL;
01312       }
01313     if (real_data_ == NULL)
01314       {
01315         this->m_ = 0;
01316         this->n_ = 0;
01317         free(real_ptr_);
01318         free(imag_ptr_);
01319         real_ptr_ = NULL;
01320         imag_ptr_ = NULL;
01321         free(real_ind_);
01322         free(imag_ind_);
01323         real_ind_ = NULL;
01324         imag_ind_ = NULL;
01325         imag_data_ = NULL;
01326       }
01327     if (real_data_ == NULL && i != 0 && j != 0)
01328       throw NoMemory(string("Matrix_ComplexSparse::")
01329                      + "Matrix_ComplexSparse(int, int, int, int)",
01330                      string("Unable to allocate ")
01331                      + to_str(sizeof(int) * real_nz_)
01332                      + " bytes to store " + to_str(real_nz_)
01333                      + " values (real part), for a "
01334                      + to_str(i) + " by " + to_str(j) + " matrix.");
01335 #endif
01336 
01337 #ifdef SELDON_CHECK_MEMORY
01338     try
01339       {
01340 #endif
01341 
01342         this->imag_data_ = this->allocator_.allocate(imag_nz_, this);
01343         this->allocator_.memorycpy(this->imag_data_, A.imag_data_, imag_nz_);
01344 
01345 #ifdef SELDON_CHECK_MEMORY
01346       }
01347     catch (...)
01348       {
01349         this->m_ = 0;
01350         this->n_ = 0;
01351         free(real_ptr_);
01352         free(imag_ptr_);
01353         real_ptr_ = NULL;
01354         imag_ptr_ = NULL;
01355         free(real_ind_);
01356         free(imag_ind_);
01357         real_ind_ = NULL;
01358         imag_ind_ = NULL;
01359         this->allocator_.deallocate(this->real_data_, real_nz_);
01360         this->real_data_ = NULL;
01361         this->imag_data_ = NULL;
01362       }
01363     if (real_data_ == NULL)
01364       {
01365         this->m_ = 0;
01366         this->n_ = 0;
01367         free(real_ptr_);
01368         free(imag_ptr_);
01369         real_ptr_ = NULL;
01370         imag_ptr_ = NULL;
01371         free(real_ind_);
01372         free(imag_ind_);
01373         real_ind_ = NULL;
01374         imag_ind_ = NULL;
01375         this->allocator_.deallocate(this->real_data_, real_nz_);
01376         real_data_ = NULL;
01377       }
01378     if (imag_data_ == NULL && i != 0 && j != 0)
01379       throw NoMemory(string("Matrix_ComplexSparse::")
01380                      + "Matrix_ComplexSparse(int, int, int, int)",
01381                      string("Unable to allocate ")
01382                      + to_str(sizeof(int) * imag_nz_)
01383                      + " bytes to store " + to_str(imag_nz_)
01384                      + " values (imaginary part), for a "
01385                      + to_str(i) + " by " + to_str(j) + " matrix.");
01386 #endif
01387 
01388   }
01389 
01390 
01391   /*******************
01392    * BASIC FUNCTIONS *
01393    *******************/
01394 
01395 
01397 
01403   template <class T, class Prop, class Storage, class Allocator>
01404   int Matrix_ComplexSparse<T, Prop, Storage, Allocator>::GetDataSize() const
01405   {
01406     return real_nz_ + imag_nz_;
01407   }
01408 
01409 
01411 
01415   template <class T, class Prop, class Storage, class Allocator>
01416   int* Matrix_ComplexSparse<T, Prop, Storage, Allocator>::GetRealPtr() const
01417   {
01418     return real_ptr_;
01419   }
01420 
01421 
01423 
01427   template <class T, class Prop, class Storage, class Allocator>
01428   int* Matrix_ComplexSparse<T, Prop, Storage, Allocator>::GetImagPtr() const
01429   {
01430     return imag_ptr_;
01431   }
01432 
01433 
01435 
01442   template <class T, class Prop, class Storage, class Allocator>
01443   int* Matrix_ComplexSparse<T, Prop, Storage, Allocator>::GetRealInd() const
01444   {
01445     return real_ind_;
01446   }
01447 
01448 
01451 
01458   template <class T, class Prop, class Storage, class Allocator>
01459   int* Matrix_ComplexSparse<T, Prop, Storage, Allocator>::GetImagInd() const
01460   {
01461     return imag_ind_;
01462   }
01463 
01464 
01466 
01469   template <class T, class Prop, class Storage, class Allocator>
01470   int Matrix_ComplexSparse<T, Prop, Storage, Allocator>
01471   ::GetRealPtrSize() const
01472   {
01473     return (Storage::GetFirst(this->m_, this->n_) + 1);
01474   }
01475 
01476 
01478 
01481   template <class T, class Prop, class Storage, class Allocator>
01482   int Matrix_ComplexSparse<T, Prop, Storage, Allocator>
01483   ::GetImagPtrSize() const
01484   {
01485     return (Storage::GetFirst(this->m_, this->n_) + 1);
01486   }
01487 
01488 
01491 
01500   template <class T, class Prop, class Storage, class Allocator>
01501   int Matrix_ComplexSparse<T, Prop, Storage, Allocator>
01502   ::GetRealIndSize() const
01503   {
01504     return real_nz_;
01505   }
01506 
01507 
01510 
01519   template <class T, class Prop, class Storage, class Allocator>
01520   int Matrix_ComplexSparse<T, Prop, Storage, Allocator>
01521   ::GetImagIndSize() const
01522   {
01523     return imag_nz_;
01524   }
01525 
01526 
01528 
01531   template <class T, class Prop, class Storage, class Allocator>
01532   T* Matrix_ComplexSparse<T, Prop, Storage, Allocator>::GetRealData() const
01533   {
01534     return real_data_;
01535   }
01536 
01537 
01539 
01542   template <class T, class Prop, class Storage, class Allocator>
01543   T* Matrix_ComplexSparse<T, Prop, Storage, Allocator>::GetImagData() const
01544   {
01545     return imag_data_;
01546   }
01547 
01548 
01549   /**********************************
01550    * ELEMENT ACCESS AND AFFECTATION *
01551    **********************************/
01552 
01553 
01555 
01561   template <class T, class Prop, class Storage, class Allocator>
01562   inline complex<typename Matrix_ComplexSparse<T, Prop, Storage, Allocator>
01563                  ::value_type>
01564   Matrix_ComplexSparse<T, Prop, Storage, Allocator>
01565   ::operator() (int i, int j) const
01566   {
01567 
01568 #ifdef SELDON_CHECK_BOUNDS
01569     if (i < 0 || i >= this->m_)
01570       throw WrongRow("Matrix_ComplexSparse::operator()",
01571                      string("Index should be in [0, ") + to_str(this->m_-1)
01572                      + "], but is equal to " + to_str(i) + ".");
01573     if (j < 0 || j >= this->n_)
01574       throw WrongCol("Matrix_ComplexSparse::operator()",
01575                      string("Index should be in [0, ") + to_str(this->n_-1)
01576                      + "], but is equal to " + to_str(j) + ".");
01577 #endif
01578 
01579     int real_k, imag_k, l;
01580     int real_a, real_b;
01581     int imag_a, imag_b;
01582 
01583     real_a = real_ptr_[Storage::GetFirst(i, j)];
01584     real_b = real_ptr_[Storage::GetFirst(i, j) + 1];
01585 
01586     imag_a = imag_ptr_[Storage::GetFirst(i, j)];
01587     imag_b = imag_ptr_[Storage::GetFirst(i, j) + 1];
01588 
01589     if (real_a != real_b)
01590       {
01591         l = Storage::GetSecond(i, j);
01592         for (real_k = real_a;
01593              (real_k <real_b-1) && (real_ind_[real_k] < l);
01594              real_k++);
01595         if (imag_a != imag_b)
01596           {
01597             for (imag_k = imag_a;
01598                  (imag_k < imag_b-1) && (imag_ind_[imag_k] < l);
01599                  imag_k++);
01600             if (real_ind_[real_k] == l)
01601               {
01602                 if (imag_ind_[imag_k] == l)
01603                   return complex<T>(real_data_[real_k], imag_data_[imag_k]);
01604                 else
01605                   return complex<T>(real_data_[real_k], T(0));
01606               }
01607             else
01608               if (imag_ind_[imag_k] == l)
01609                 return complex<T>(T(0), imag_data_[imag_k]);
01610               else
01611                 return complex<T>(T(0), T(0));
01612           }
01613         else
01614           {
01615             if (real_ind_[real_k] == l)
01616               return complex<T>(real_data_[real_k], T(0));
01617             else
01618               return complex<T>(T(0), T(0));
01619           }
01620       }
01621     else
01622       {
01623         if (imag_a != imag_b)
01624           {
01625             l = Storage::GetSecond(i, j);
01626             for (imag_k = imag_a;
01627                  (imag_k < imag_b-1) && (imag_ind_[imag_k] < l);
01628                  imag_k++);
01629             if (imag_ind_[imag_k] == l)
01630               return complex<T>(T(0), imag_data_[imag_k]);
01631             else
01632               return complex<T>(T(0), T(0));
01633           }
01634         else
01635           return complex<T>(T(0), T(0));
01636       }
01637 
01638   }
01639 
01640 
01642 
01648   template <class T, class Prop, class Storage, class Allocator>
01649   inline complex<typename Matrix_ComplexSparse<T, Prop, Storage, Allocator>
01650                  ::value_type>&
01651   Matrix_ComplexSparse<T, Prop, Storage, Allocator>::Val(int i, int j)
01652   {
01653     throw Undefined("Matrix_ComplexSparse::Val(int i, int j)");
01654   }
01655 
01656 
01658 
01664   template <class T, class Prop, class Storage, class Allocator>
01665   inline
01666   const complex<typename Matrix_ComplexSparse<T, Prop, Storage, Allocator>
01667                 ::value_type>&
01668   Matrix_ComplexSparse<T, Prop, Storage, Allocator>::Val(int i, int j) const
01669   {
01670     throw Undefined("Matrix_ComplexSparse::Val(int i, int j)");
01671   }
01672 
01673 
01675 
01680   template <class T, class Prop, class Storage, class Allocator>
01681   inline Matrix_ComplexSparse<T, Prop, Storage, Allocator>&
01682   Matrix_ComplexSparse<T, Prop, Storage, Allocator>
01683   ::operator= (const Matrix_ComplexSparse<T, Prop, Storage, Allocator>& A)
01684   {
01685     this->Copy(A);
01686 
01687     return *this;
01688   }
01689 
01690 
01691   /************************
01692    * CONVENIENT FUNCTIONS *
01693    ************************/
01694 
01695 
01697 
01702   template <class T, class Prop, class Storage, class Allocator>
01703   void Matrix_ComplexSparse<T, Prop, Storage, Allocator>::Print() const
01704   {
01705     for (int i = 0; i < this->m_; i++)
01706       {
01707         for (int j = 0; j < this->n_; j++)
01708           cout << (*this)(i, j) << "\t";
01709         cout << endl;
01710       }
01711   }
01712 
01713 
01714 
01716   // MATRIX<COLCOMPLEXSPARSE> //
01718 
01719 
01720   /****************
01721    * CONSTRUCTORS *
01722    ****************/
01723 
01725 
01728   template <class T, class Prop, class Allocator>
01729   Matrix<T, Prop, ColComplexSparse, Allocator>::Matrix()  throw():
01730     Matrix_ComplexSparse<T, Prop, ColComplexSparse, Allocator>()
01731   {
01732   }
01733 
01734 
01736 
01740   template <class T, class Prop, class Allocator>
01741   Matrix<T, Prop, ColComplexSparse, Allocator>::Matrix(int i, int j):
01742     Matrix_ComplexSparse<T, Prop, ColComplexSparse, Allocator>(i, j, 0, 0)
01743   {
01744   }
01745 
01746 
01748 
01756   template <class T, class Prop, class Allocator>
01757   Matrix<T, Prop, ColComplexSparse, Allocator>::Matrix(int i, int j,
01758                                                        int real_nz,
01759                                                        int imag_nz):
01760     Matrix_ComplexSparse<T, Prop, ColComplexSparse, Allocator>(i, j,
01761                                                                real_nz,
01762                                                                imag_nz)
01763   {
01764   }
01765 
01766 
01768 
01786   template <class T, class Prop, class Allocator>
01787   template <class Storage0, class Allocator0,
01788             class Storage1, class Allocator1,
01789             class Storage2, class Allocator2>
01790   Matrix<T, Prop, ColComplexSparse, Allocator>::
01791   Matrix(int i, int j,
01792          Vector<T, Storage0, Allocator0>& real_values,
01793          Vector<int, Storage1, Allocator1>& real_ptr,
01794          Vector<int, Storage2, Allocator2>& real_ind,
01795          Vector<T, Storage0, Allocator0>& imag_values,
01796          Vector<int, Storage1, Allocator1>& imag_ptr,
01797          Vector<int, Storage2, Allocator2>& imag_ind):
01798     Matrix_ComplexSparse<T, Prop, ColComplexSparse, Allocator>(i, j,
01799                                                                real_values,
01800                                                                real_ptr,
01801                                                                real_ind,
01802                                                                imag_values,
01803                                                                imag_ptr,
01804                                                                imag_ind)
01805   {
01806   }
01807 
01808 
01809 
01811   // MATRIX<ROWCOMPLEXSPARSE> //
01813 
01814 
01815   /****************
01816    * CONSTRUCTORS *
01817    ****************/
01818 
01820 
01823   template <class T, class Prop, class Allocator>
01824   Matrix<T, Prop, RowComplexSparse, Allocator>::Matrix()  throw():
01825     Matrix_ComplexSparse<T, Prop, RowComplexSparse, Allocator>()
01826   {
01827   }
01828 
01829 
01831 
01835   template <class T, class Prop, class Allocator>
01836   Matrix<T, Prop, RowComplexSparse, Allocator>::Matrix(int i, int j):
01837     Matrix_ComplexSparse<T, Prop, RowComplexSparse, Allocator>(i, j, 0, 0)
01838   {
01839   }
01840 
01841 
01850   template <class T, class Prop, class Allocator>
01851   Matrix<T, Prop, RowComplexSparse, Allocator>::Matrix(int i, int j,
01852                                                        int real_nz,
01853                                                        int imag_nz):
01854     Matrix_ComplexSparse<T, Prop, RowComplexSparse, Allocator>(i, j,
01855                                                                real_nz,
01856                                                                imag_nz)
01857   {
01858   }
01859 
01860 
01862 
01880   template <class T, class Prop, class Allocator>
01881   template <class Storage0, class Allocator0,
01882             class Storage1, class Allocator1,
01883             class Storage2, class Allocator2>
01884   Matrix<T, Prop, RowComplexSparse, Allocator>::
01885   Matrix(int i, int j,
01886          Vector<T, Storage0, Allocator0>& real_values,
01887          Vector<int, Storage1, Allocator1>& real_ptr,
01888          Vector<int, Storage2, Allocator2>& real_ind,
01889          Vector<T, Storage0, Allocator0>& imag_values,
01890          Vector<int, Storage1, Allocator1>& imag_ptr,
01891          Vector<int, Storage2, Allocator2>& imag_ind):
01892     Matrix_ComplexSparse<T, Prop, RowComplexSparse, Allocator>(i, j,
01893                                                                real_values,
01894                                                                real_ptr,
01895                                                                real_ind,
01896                                                                imag_values,
01897                                                                imag_ptr,
01898                                                                imag_ind)
01899   {
01900   }
01901 
01902 
01903 } // namespace Seldon.
01904 
01905 #define SELDON_FILE_MATRIX_COMPLEXSPARSE_CXX
01906 #endif