|
Anasazi Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Anasazi: Block Eigensolvers Package 00005 // Copyright (2010) 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 Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #ifndef __TSQR_Tsqr_ScalarTraits_hpp 00030 #define __TSQR_Tsqr_ScalarTraits_hpp 00031 00032 #include <cmath> // std::abs 00033 #include <complex> 00034 00037 00038 namespace TSQR { 00039 00059 template< class Scalar > 00060 class ScalarTraits { 00061 public: 00065 static const bool is_specialized = false; 00068 static const bool is_complex = false; 00074 typedef Scalar magnitude_type; 00077 static Scalar zero(); 00080 static Scalar one(); 00088 static magnitude_type pi() { 00089 return 6.2831853071795864769252867663e+0; 00090 } 00093 inline static Scalar conj (const Scalar& z); 00096 inline static magnitude_type abs (const Scalar& z); 00097 }; 00098 00099 template<> 00100 class ScalarTraits< double > { 00101 public: 00102 static const bool is_specialized = true; 00103 static const bool is_complex = false; 00104 typedef double magnitude_type; 00105 00106 static double zero() { return 0.0; } 00107 static double one() { return 1.0; } 00108 static magnitude_type pi() { 00109 // In double precision, 17 digits suffice. We include 20 just 00110 // for good measure. Hopefully the C++ compiler won't do a 00111 // stupid thing with them. 00112 return 3.14159265358979323846; 00113 } 00114 00115 inline static double conj (const double& z) { return z; } 00116 inline static magnitude_type abs (const double& z) { 00117 return std::abs (z); 00118 } 00119 }; 00120 00121 template<> 00122 class ScalarTraits< float > { 00123 public: 00124 static const bool is_specialized = true; 00125 static const bool is_complex = false; 00126 typedef float magnitude_type; 00127 00128 static float zero() { return 0.0; } 00129 static float one() { return 1.0; } 00130 static magnitude_type pi() { 00131 return 3.14159265358979323846; 00132 } 00133 00134 inline static float conj (const float& z) { return z; } 00135 inline static magnitude_type abs (const float& z) { 00136 return std::abs (z); 00137 } 00138 }; 00139 00140 template<> 00141 class ScalarTraits< std::complex< double > > { 00142 public: 00143 static const bool is_specialized = true; 00144 static const bool is_complex = true; 00145 typedef double magnitude_type; 00146 00147 static std::complex<double> zero() { return std::complex<double>(0.0, 0.0); } 00148 static std::complex<double> one() { return std::complex<double>(1.0, 0.0); } 00149 static magnitude_type pi() { return ScalarTraits< magnitude_type >::pi(); } 00150 00151 inline static std::complex<double> conj (const std::complex<double>& z) { 00152 return std::conj (z); 00153 } 00154 inline static magnitude_type abs (const std::complex<double>& z) { 00155 return std::abs (z); 00156 } 00157 }; 00158 00159 template<> 00160 class ScalarTraits< std::complex< float > > { 00161 public: 00162 static const bool is_specialized = true; 00163 static const bool is_complex = true; 00164 typedef float magnitude_type; 00165 00166 static std::complex<float> zero() { return std::complex<float>(0.0, 0.0); } 00167 static std::complex<float> one() { return std::complex<float>(1.0, 0.0); } 00168 static magnitude_type pi() { return ScalarTraits< magnitude_type >::pi(); } 00169 00170 inline static std::complex<float> conj (const std::complex<float>& z) { 00171 return std::conj (z); 00172 } 00173 inline static magnitude_type abs (const std::complex<float>& z) { 00174 return std::abs (z); 00175 } 00176 }; 00177 00178 00179 } // namespace TSQR 00180 00181 #endif // __TSQR_Tsqr_ScalarTraits_hpp
1.7.4