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