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