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