Go to the documentation of this file.00001 #ifndef _DENSE_MATRIX_H_
00002 #define _DENSE_MATRIX_H_
00003
00004 #include <map>
00005 #include <vector>
00006 #include <complex>
00007
00008
00009 namespace MeshLib
00010 {
00011
00012 double _inner_product( double * v1, double *v2, int num )
00013 {
00014 double sum = 0;
00015 for( int i = 0; i < num; i ++ )
00016 {
00017 sum += v1[i] * v2[i];
00018 }
00019 return sum;
00020 };
00021
00022 void _scale( double * v, double s, int num )
00023 {
00024 for( int i = 0; i < num; i ++ )
00025 {
00026 v[i] *= s;
00027 }
00028 };
00029
00030 double norm( double * v, int num )
00031 {
00032 double inner_product = _inner_product( v,v, num );
00033 return sqrt( inner_product );
00034 };
00035
00036 void _normalize( double * v, int num )
00037 {
00038 double mag = norm( v, num );
00039
00040 for( int i = 0; i < num; i ++ )
00041 {
00042 v[i] /= mag;
00043 };
00044 };
00045
00046
00047 class CDenseMatrix
00048 {
00049 public:
00050 CDenseMatrix( int row, int col )
00051 {
00052 m_row = row;
00053 m_col = col;
00054
00055 m_ptr = new double*[m_row];
00056 assert( m_ptr );
00057
00058 for( int i = 0 ; i < m_row ; i ++ )
00059 {
00060 m_ptr[i] = new double[m_col];
00061 assert( m_ptr[i] );
00062 };
00063
00064 reset();
00065 };
00066
00067 ~CDenseMatrix()
00068 {
00069 for( int i = 0 ; i < m_row ; i ++ )
00070 {
00071 delete m_ptr[i];
00072 };
00073
00074 delete m_ptr;
00075 };
00076
00077 double * operator[]( int idx ){ assert(0<= idx && idx < m_row ); return m_ptr[idx]; };
00078
00079 void reset();
00080
00081 void Gram_Schmidt_Orghonomralization();
00082
00083 int row() { return m_row; };
00084 int col() { return m_col; };
00085
00086 protected:
00087
00088 int m_row;
00089 int m_col;
00090
00091 double ** m_ptr;
00092
00093 };
00094
00095 inline void CDenseMatrix::Gram_Schmidt_Orghonomralization()
00096 {
00097 for( int i = 0; i < m_row; i ++ )
00098 {
00099 for( int j = 0; j < i; j ++ )
00100 {
00101 double inner = _inner_product( m_ptr[i], m_ptr[j], m_col );
00102
00103 for( int k = 0; k < m_col; k ++ )
00104 {
00105 m_ptr[i][k] = m_ptr[i][k] - m_ptr[j][k] * inner;
00106 }
00107 }
00108
00109 _normalize( m_ptr[i], m_col );
00110 if( i % 150 == 0 )
00111 printf("%d/%d\n", i, m_row );
00112
00113 };
00114 };
00115
00116 inline void CDenseMatrix::reset()
00117 {
00118 for( int i = 0; i < m_row; i ++ )
00119 {
00120 for( int j = 0; j < m_col; j ++ )
00121 {
00122 m_ptr[i][j] = 0;
00123 }
00124 };
00125 };
00126
00127 };
00128 #endif