00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef COO_MATRIX_TMPL_CONVERT_TO_SPARSE_COMPRESSED_COLUMN_DEF_H
00030 #define COO_MATRIX_TMPL_CONVERT_TO_SPARSE_COMPRESSED_COLUMN_DEF_H
00031
00032 #include "AbstractLinAlgPack_COOMatrixTmplConvertToSparseCompressedColumnDecl.hpp"
00033
00034 namespace AbstractLinAlgPack {
00035
00036 template<class T_COOM>
00037 size_type COOM_num_in_column(
00038 const T_COOM& m
00039 , BLAS_Cpp::Transp trans
00040 , size_type col_offset
00041 , const IVector::value_type* col_perm
00042 , size_type* num_in_col )
00043 {
00044 if(!m.nz()) return 0;
00045 if( trans == BLAS_Cpp::no_trans ) {
00046
00047 typename T_COOM::difference_type loc_co = m.col_offset();
00048 for( typename T_COOM::const_iterator itr = m.begin(); itr != m.end(); ++itr )
00049 num_in_col[ col_perm[ col_offset + loc_co + itr->col_j() -1 ] -1 ]++;
00050 }
00051 else {
00052
00053 typename T_COOM::difference_type loc_ro = m.row_offset();
00054 for( typename T_COOM::const_iterator itr = m.begin(); itr != m.end(); ++itr ) {
00055 const size_type i = itr->row_i();
00056 num_in_col[ col_perm[ col_offset + loc_ro + i - 1 ] - 1 ]++;
00057 }
00058 }
00059 return m.nz();
00060 }
00061
00062 template<class T_COOM>
00063 void COOM_insert_nonzeros(
00064 const T_COOM& m
00065 , BLAS_Cpp::Transp trans
00066 , value_type alpha
00067 , size_type row_offset
00068 , size_type col_offset
00069 , const IVector::value_type* row_perm
00070 , const IVector::value_type* col_perm
00071 , size_type* next_nz_in_col
00072 , FortranTypes::f_dbl_prec* D_val
00073 , FortranTypes::f_int* D_row_i )
00074 {
00075 if(!m.nz()) return;
00076 typename T_COOM::difference_type
00077 loc_ro = m.row_offset(),
00078 loc_co = m.col_offset();
00079 if( trans == BLAS_Cpp::no_trans ) {
00080
00081 for( typename T_COOM::const_iterator itr = m.begin(); itr != m.end(); ++itr ) {
00082 const size_type
00083 i = loc_ro + itr->row_i(),
00084 j = loc_co + itr->col_j();
00085 const size_type
00086 ele = next_nz_in_col[ col_perm[ col_offset + j - 1 ] - 1 ]++;
00087 D_val[ ele - 1 ] = alpha * itr->value();
00088 if(D_row_i)
00089 D_row_i[ ele - 1 ] = row_perm[ row_offset + i - 1 ];
00090 }
00091 }
00092 else {
00093
00094 for( typename T_COOM::const_iterator itr = m.begin(); itr != m.end(); ++itr ) {
00095 const size_type
00096 i = loc_co + itr->col_j(),
00097 j = loc_ro + itr->row_i();
00098 const size_type
00099 ele = next_nz_in_col[ col_perm[ col_offset + j - 1 ] - 1 ]++;
00100 D_val[ ele - 1 ] = alpha * itr->value();
00101 if(D_row_i)
00102 D_row_i[ ele - 1 ] = row_perm[ row_offset + i - 1 ];
00103 }
00104 }
00105 }
00106
00107 template<class T_COOM>
00108 value_type COOM_insert_scaled_nonzeros(
00109 const T_COOM& m
00110 , BLAS_Cpp::Transp trans
00111 , value_type scaled_max_ele
00112 , size_type row_offset
00113 , size_type col_offset
00114 , const IVector::value_type* row_perm
00115 , const IVector::value_type* col_perm
00116 , size_type* next_nz_in_col
00117 , FortranTypes::f_dbl_prec* D_val
00118 , FortranTypes::f_int* D_row_i )
00119 {
00120 value_type alpha = 0;
00121 for( typename T_COOM::const_iterator itr = m.begin(); itr != m.end(); ++itr ) {
00122 register const value_type val = ::fabs( itr->value() );
00123 if( val > alpha ) alpha = val;
00124 }
00125
00126 alpha = scaled_max_ele / alpha;
00127 COOM_insert_nonzeros( m, trans, alpha, row_offset
00128 , col_offset, row_perm, col_perm, next_nz_in_col, D_val, D_row_i );
00129 return alpha;
00130 }
00131
00132 }
00133
00134 #endif // COO_MATRIX_TMPL_CONVERT_TO_SPARSE_COMPRESSED_COLUMN_DEF_H