CPPLapack
 All Classes Files Functions Variables Friends
zgbmatrix-misc.hpp
Go to the documentation of this file.
00001 //=============================================================================
00002 /*! clear all the matrix data and set the sizes 0 */
00003 inline void zgbmatrix::clear()
00004 {VERBOSE_REPORT;
00005   m =0;
00006   n =0;
00007   kl =0;
00008   ku =0;
00009   delete [] array;
00010   array =NULL;
00011   delete [] darray;
00012   darray =NULL;
00013 }
00014 
00015 
00016 //=============================================================================
00017 /*! change the matrix into a zero matrix */
00018 inline zgbmatrix& zgbmatrix::zero()
00019 {VERBOSE_REPORT;
00020   for(long i=0; i<(kl+ku+1)*n; i++){
00021     array[i] =comple(0.0,0.0);
00022   }
00023   return *this;
00024 }
00025 
00026 //=============================================================================
00027 /*! change the matrix into an identity matrix */
00028 inline zgbmatrix& zgbmatrix::identity()
00029 {VERBOSE_REPORT;
00030 #ifdef  CPPL_DEBUG
00031   if(m!=n){
00032     ERROR_REPORT;
00033     std::cerr << "Only square matrix can be a identity matrix." << std::endl
00034               << "The matrix size was " << m << "x" << n << "." << std::endl;
00035     exit(1);
00036   }
00037 #endif//CPPL_DEBUG
00038   
00039   for(long i=0; i<(kl+ku+1)*n; i++){ array[i] =comple(0.0,0.0); }
00040   for(long i=0; i<m; i++){ operator()(i,i) =comple(1.0,0.0); }
00041   
00042   return *this;
00043 }
00044 
00045 //=============================================================================
00046 /*! change sign(+/-) of the matrix */
00047 inline void zgbmatrix::chsign()
00048 {VERBOSE_REPORT;
00049   for(long i=0; i<(kl+ku+1)*n; i++){ array[i] =-array[i]; }
00050 }
00051 
00052 //=============================================================================
00053 /*! make a deep copy of the matrix */
00054 inline void zgbmatrix::copy(const zgbmatrix& mat)
00055 {VERBOSE_REPORT;
00056   m =mat.m;
00057   n =mat.n;
00058   kl =mat.kl;
00059   ku =mat.ku;
00060   delete [] array;
00061   array =new comple[(mat.kl+mat.ku+1)*mat.n];
00062   delete [] darray;
00063   darray =new comple*[n];
00064   for(int i=0; i<n; i++){ darray[i] =&array[i*(kl+ku+1)]; }
00065   
00066   zcopy_((mat.kl+mat.ku+1)*mat.n, mat.array, 1, array, 1);
00067 }
00068 
00069 //=============================================================================
00070 /*! make a shallow copy of the matrix\n
00071   This function is not designed to be used in project codes. */
00072 inline void zgbmatrix::shallow_copy(const _zgbmatrix& mat)
00073 {VERBOSE_REPORT;
00074   m =mat.m;
00075   n =mat.n;
00076   kl =mat.kl;
00077   ku =mat.ku;
00078   delete [] array;
00079   array =mat.array;
00080   delete [] darray;
00081   darray =mat.darray;
00082   
00083   mat.nullify();
00084 }
00085 
00086 //=============================================================================
00087 /*! resize the matrix */
00088 inline void zgbmatrix::resize(const long& _m, const long& _n,
00089                               const long& _kl, const long& _ku)
00090 {VERBOSE_REPORT;
00091 #ifdef  CPPL_DEBUG
00092   if( _m<0 || _n<0 || _kl<0 || _ku<0 || _m<_kl || _n<_ku ){
00093     ERROR_REPORT;
00094     std::cerr << "It is impossible to make a matrix you ordered. " << std::endl
00095               << "Your input was (" << _m << "," << _n << ","<< _ku << "," << _kl << ")." << std::endl;
00096     exit(1);
00097   }
00098 #endif//CPPL_DEBUG
00099   
00100   m =_m;
00101   n =_n;
00102   kl =_kl;
00103   ku =_ku;
00104   delete [] array;
00105   array =new comple[(kl+ku+1)*n];
00106   delete [] darray;
00107   darray =new comple*[n];
00108   for(int i=0; i<n; i++){ darray[i] =&array[i*(kl+ku+1)]; }
00109 }
00110 
00111 ///////////////////////////////////////////////////////////////////////////////
00112 ///////////////////////////////////////////////////////////////////////////////
00113 ///////////////////////////////////////////////////////////////////////////////
00114 
00115 //=============================================================================
00116 /*! get row of the matrix */
00117 inline _zrovector zgbmatrix::row(const long& _m) const
00118 {VERBOSE_REPORT;
00119 #ifdef  CPPL_DEBUG
00120   if( _m<0 || _m>m ){
00121     ERROR_REPORT;
00122     std::cerr << "Input row number must be between 0 and " << m << "." << std::endl
00123               << "Your input was " << _m << "." << std::endl;
00124     exit(1);
00125   }
00126 #endif//CPPL_DEBUG
00127   
00128   zrovector v( zrovector(n).zero() );
00129   for(long j=std::max(long(0),_m-kl); j<std::min(n,_m+ku+1); j++){ v(j)=(*this)(_m,j); }
00130   return _(v);
00131 }
00132 
00133 //=============================================================================
00134 /*! get column of the matrix */
00135 inline _zcovector zgbmatrix::col(const long& _n) const
00136 {VERBOSE_REPORT;
00137 #ifdef  CPPL_DEBUG
00138   if( _n<0 || _n>n ){
00139     ERROR_REPORT;
00140     std::cerr << "Input row number must be between 0 and " << n << "." << std::endl
00141               << "Your input was " << _n << "." << std::endl;
00142     exit(1);
00143   }
00144 #endif//CPPL_DEBUG
00145   
00146   zcovector v( zcovector(m).zero() );
00147   for(long i=std::max(long(0),_n-ku); i<std::min(m,_n+kl+1); i++){ v(i)=(*this)(i,_n); }
00148   return _(v);
00149 }
00150 
00151 ///////////////////////////////////////////////////////////////////////////////
00152 ///////////////////////////////////////////////////////////////////////////////
00153 ///////////////////////////////////////////////////////////////////////////////
00154 
00155 //=============================================================================
00156 /*! swap two matrices */
00157 inline void swap(zgbmatrix& A, zgbmatrix& B)
00158 {VERBOSE_REPORT;
00159   long A_m(A.m), A_n(A.n), A_kl(A.kl), A_ku(A.ku);
00160   comple* A_array(A.array);
00161   //comple** A_darray(A.darray);
00162   comple** A_darray=A.darray; //corruption to support VC++
00163 
00164   A.m=B.m; A.n=B.n; A.kl=B.kl; A.ku=B.ku; A.array=B.array; A.darray=B.darray;
00165   B.m=A_m; B.n=A_n; B.kl=A_kl; B.ku=A_ku; B.array=A_array; B.darray=A_darray;
00166 }
00167 
00168 //=============================================================================
00169 /*! convert user object to smart-temporary object */
00170 inline _zgbmatrix _(zgbmatrix& mat)
00171 {VERBOSE_REPORT;
00172   _zgbmatrix newmat;
00173   
00174   //////// shallow copy ////////
00175   newmat.m =mat.m;
00176   newmat.n =mat.n;
00177   newmat.kl =mat.kl;
00178   newmat.ku =mat.ku;
00179   newmat.array =mat.array;
00180   newmat.darray =mat.darray;
00181   
00182   //////// nullify ////////
00183   mat.m =0;
00184   mat.n =0;
00185   mat.kl =0;
00186   mat.ku =0;
00187   mat.array =NULL;
00188   mat.darray =NULL;
00189   
00190   return newmat;
00191 }
 All Classes Files Functions Variables Friends