DenseLinAlgPack_MatVecCompare.cpp

Go to the documentation of this file.
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 #include <limits>
00030 #include <algorithm>
00031 
00032 #include "DenseLinAlgPack_MatVecCompare.hpp"
00033 #include "DenseLinAlgPack_DMatrixClass.hpp"
00034 #include "DenseLinAlgPack_DMatrixAsTriSym.hpp"
00035 
00036 namespace {
00037 //
00038 using DenseLinAlgPack::value_type;
00039 //
00040 using DenseLinAlgPack::sqrt_eps;
00041 //
00042 template< class T >
00043 inline
00044 T my_max( const T& v1, const T& v2 ) { return v1 > v2 ? v1 : v2; }
00045 //
00046 template< class T >
00047 inline
00048 T my_min( const T& v1, const T& v2 ) { return v1 < v2 ? v1 : v2; }
00049 //
00050 inline
00051 bool _comp(value_type val1, value_type val2)
00052 {
00053   const value_type denom = my_max( ::fabs(val1), 1.0 ); // compare relative errors.
00054   return ::fabs(val1 - val2) / denom < sqrt_eps;
00055 } 
00056 
00057 } // end namespace
00058 
00059 bool DenseLinAlgPack::comp(const DVectorSlice& vs1, const DVectorSlice& vs2) {
00060   DVectorSlice::const_iterator
00061     vs1_itr = vs1.begin(),
00062     vs2_itr = vs2.begin();
00063   for(; vs1_itr != vs1.end() && vs2_itr != vs2.end(); ++vs1_itr, ++vs2_itr)
00064     if( !_comp(*vs1_itr,*vs2_itr) ) return false;
00065   return true;
00066 }
00067 
00068 bool DenseLinAlgPack::comp(const DVectorSlice& vs, value_type alpha) {
00069   DVectorSlice::const_iterator vs_itr = vs.begin();
00070   for(; vs_itr != vs.end(); ++vs_itr)
00071     if( !_comp(*vs_itr,alpha) ) return false;
00072   return true;
00073 }
00074 
00075 bool DenseLinAlgPack::comp(const DMatrixSlice& gms1, BLAS_Cpp::Transp trans1
00076   , const DMatrixSlice& gms2, BLAS_Cpp::Transp trans2)
00077 {
00078   for(size_type i = 1; i < my_min(gms1.cols(),gms2.cols()); ++i)
00079     if( !comp( col(gms1,trans1,i) , col( gms2, trans2, i ) ) ) return false;
00080   return true;
00081 }
00082 
00083 bool DenseLinAlgPack::comp(const DMatrixSlice& gms, value_type alpha)
00084 {
00085   for(size_type i = 1; i < gms.cols(); ++i)
00086     if( !comp( gms.col(i) , alpha ) ) return false;
00087   return true;
00088 }
00089 
00090 bool DenseLinAlgPack::comp(const DMatrixSliceTriEle& tri_gms1, const DMatrixSliceTriEle& tri_gms2)
00091 {
00092   using BLAS_Cpp::bool_to_trans;
00093   BLAS_Cpp::Transp
00094     trans1 = bool_to_trans(tri_gms1.uplo() != BLAS_Cpp::lower),
00095     trans2 = bool_to_trans(tri_gms2.uplo() != BLAS_Cpp::lower);
00096 
00097   const size_type n = tri_gms1.rows();  // same as cols()
00098   for(size_type i = 1; i < n; ++i) {
00099     if( !comp( col(tri_gms1.gms(),trans1,i)(i,n), col(tri_gms2.gms(),trans2,i)(i,n) ) )
00100       return false;
00101   }
00102   return true;
00103 }
00104 
00105 bool DenseLinAlgPack::comp(const DMatrixSliceTriEle& tri_gms1, value_type alpha)
00106 {
00107   using BLAS_Cpp::bool_to_trans;
00108   BLAS_Cpp::Transp
00109     trans1 = bool_to_trans(tri_gms1.uplo() != BLAS_Cpp::lower);
00110 
00111   const size_type n = tri_gms1.rows();  // same as cols()
00112   for(size_type i = 1; i < n; ++i) {
00113     if( !comp( col(tri_gms1.gms(),trans1,i)(i,n), alpha ) )
00114       return false;
00115   }
00116   return true;
00117 }
00118 
00119 bool DenseLinAlgPack::comp_less(const DVectorSlice& vs, value_type alpha)
00120 {
00121   DVectorSlice::const_iterator vs_itr = vs.begin();
00122   const value_type denom = my_max( ::fabs(alpha), 1.0 );
00123   for(; vs_itr != vs.end(); ++vs_itr)
00124     if( *vs_itr > alpha ) return false;
00125   return true;
00126 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 10:10:59 2011 for MOOCHO (Single Doxygen Collection) by  doxygen 1.6.3