|
AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization 00005 // Copyright (2003) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 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 // non transposed 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 // transposed 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 // non transposed 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 // transposed 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 // scaled_max_ele = max|alpha*A| = alpha * max|A| 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 } // end namespace AbstractLinAlgPack 00133 00134 #endif // COO_MATRIX_TMPL_CONVERT_TO_SPARSE_COMPRESSED_COLUMN_DEF_H
1.7.4