Main Page | Class List | File List | Class Members | File Members | Related Pages

dgematrix-misc.hpp

Go to the documentation of this file.
00001 //=============================================================================
00002 /*! clear all the matrix data and set the sizes 0 */
00003 inline void dgematrix::clear()
00004 {
00005 #ifdef  CPPSL_DEBUG
00006   std::cerr << "# [NOTE] dgematrix::clear() "
00007             << "An array at " << array << " is going to be cleared."
00008             << std::endl;
00009 #endif//CPPSL_DEBUG
00010   
00011   M =N =0;
00012   Ml =Nl =0;
00013   for(int i=0; i<9; i++){ Desc[i]=0; }
00014   delete [] Array;
00015   Array =new double[0];
00016 }
00017 
00018 //=============================================================================
00019 /*! change the matrix into a zero matrix */
00020 inline void dgematrix::zero()
00021 {
00022   for(long i=0; i<Ml*Nl; i++){ Array[i] =0.0; }
00023 }
00024 
00025 //=============================================================================
00026 /*! change the matrix into an identity matrix */
00027 inline void dgematrix::identity()
00028 {
00029 #ifdef  CPPSL_DEBUG
00030   if(M!=N){
00031     std::cerr << "[ERROR] dgematrix::identity()" << std::endl
00032               << "Only square matrix can be a identity matrix." << std::endl
00033               << "The matrix size was " << M << "x" << N << "." << std::endl;
00034     exit(1);
00035   }
00036 #endif//CPPSL_DEBUG
00037   
00038   for(long i=0; i<Ml*Nl; i++){ Array[i] =0.0; }
00039   for(long i=0; i<M; i++){ operator()(i,i) =1.0; }
00040 }
00041 
00042 //=============================================================================
00043 /*! change sign(+/-) of the matrix */
00044 inline void dgematrix::chsign()
00045 {
00046   for(long i=0; i<Ml*Nl; i++){ Array[i] =-Array[i]; }
00047 }
00048 
00049 //=============================================================================
00050 /*! make a deep copy of the matrix */
00051 inline void dgematrix::copy(const dgematrix& mat)
00052 {
00053 #ifdef  CPPSL_DEBUG
00054   std::cerr << "# [NOTE] dgematrix::copy(const dgematrix&) "
00055             << "A dgematrix at " << Array << " is going to be deleted.";
00056 #endif//CPPSL_DEBUG
00057   
00058   delete [] Array;
00059   M =mat.M; N =mat.N;
00060   Ml =mat.Ml; Nl =mat.Nl;
00061   for(int i=0; i<9; i++){ Desc[i] =mat.Desc[i]; }
00062   Array =new double[Ml*Nl];
00063   dcopy_(Ml*Nl, mat.Array, 1, Array, 1);
00064   
00065 #ifdef  CPPSL_DEBUG
00066   std::cerr << " Then, a COPY of a dgematrix has been cleated at "
00067             << Array << "." << std::endl;
00068 #endif//CPPSL_DEBUG
00069 }
00070 
00071 //=============================================================================
00072 /*! make a shallow copy of the matrix\n
00073   This function is not designed to be used in project codes. */
00074 inline void dgematrix::shallow_copy(const _dgematrix& mat)
00075 {
00076 #ifdef  CPPSL_DEBUG
00077   std::cerr << "# [NOTE] dgematrix:shallow_copy(const _dgematrix&) "
00078             << "A dgematrix at " << Array << " is going to be deleted, "
00079             << "and point to " << mat.Array << " instead." << std::endl;
00080 #endif//CPPSL_DEBUG
00081 
00082   delete [] Array;
00083   M =mat.M; N =mat.N;
00084   Ml =mat.Ml; Nl =mat.Nl;
00085   for(int i=0; i<9; i++){ Desc[i] =mat.Desc[i]; }
00086   Array =mat.Array;
00087 }
00088 
00089 //=============================================================================
00090 /*! resize the matrix */
00091 inline void dgematrix::resize(const long& _m, const long& _n)
00092 {
00093 #ifdef  CPPSL_DEBUG
00094   if( _m<0 || _n<0 ){
00095     std::cerr << "[ERROR] dgematrix::resize(const long&, const long&)"
00096               << std::endl
00097               << "Matrix sizes must be positive integers." << std::endl
00098               << "Your input was (" << _m << "," << _n << ")." << std::endl;
00099     exit(1);
00100   }
00101 #endif//CPPSL_DEBUG
00102   
00103   delete [] Array;
00104   M =_m; N =_n;
00105   Ml =numroc_( M, mb, myrow, 0, nprow );
00106   Nl =numroc_( N, nb, mycol, 0, npcol );
00107   desc[0]=1; desc[1]=icontxt; desc[2]=M; desc[3]=N; desc[4]=mb; desc[5]=nb;
00108   desc[6]=0; desc[7]=0; desc[8]=max(1,Ml);
00109   Array =new double[Ml*Nl];
00110 }
00111 
00112 //=============================================================================
00113 /*! swap two matrices */
00114 inline void swap(dgematrix& A, dgematrix& B)
00115 {
00116   long A_M(A.M), A_N(A.N), A_Ml(A.Ml), A_Nl(A.Nl), A_Desc[9];
00117   double* A_Array(A.Array);
00118   A.M=B.M; A.N=B.N; A.Ml=B.Ml; A.Nl=B.Nl;  A.Array=B.Array;
00119   B.M=A_M; B.N=A_N; B.Ml=A_Ml; B.Nl=A_Nl;  B.Array=A_Array;
00120   for(int i=0; i<9; i++){
00121     A_Desc[i] =A.Desc[i];
00122     A.Desc[i] =B.Desc[i];
00123     B.Desc[i] =A_Desc[i];
00124   }
00125 }

Generated on Sat Jan 31 19:25:43 2004 for CPPScaLapack by doxygen 1.3.5