Kokkos Node API and Local Linear Algebra Kernels Version of the Day
Tsqr_ScalarTraits.hpp
00001 //@HEADER
00002 // ************************************************************************
00003 // 
00004 //          Kokkos: Node API and Parallel Node Kernels
00005 //              Copyright (2009) 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 <Tsqr_ConfigDefs.hpp>
00033 
00034 #include <cmath> // std::abs
00035 #include <complex>
00036 
00037 
00038 namespace TSQR {
00039 
00059   template< class Scalar >
00060   class ScalarTraits {
00061   public:
00067     static const bool is_specialized = false;
00068 
00070     static const bool is_complex = false;
00076     typedef Scalar magnitude_type;
00079     static Scalar zero();
00082     static Scalar one();
00083 
00086     static magnitude_type pi();
00087 
00089     inline static Scalar conj (const Scalar& z);
00090 
00092     inline static magnitude_type abs (const Scalar& z);
00093   };
00094 
00095   template<>
00096   class ScalarTraits< double > {
00097   public:
00098     static const bool is_specialized = true;
00099     static const bool is_complex = false;
00100     typedef double magnitude_type;
00101 
00102     static double zero() { return 0.0; }
00103     static double one() { return 1.0; }
00104     static magnitude_type pi() {
00105       // In double precision, 17 digits suffice.  We include 20 just
00106       // for good measure.  Hopefully the C++ compiler won't do a
00107       // stupid thing with them.
00108       return 3.14159265358979323846;
00109     }
00110 
00111     inline static double conj (const double& z) { return z; }
00112     inline static magnitude_type abs (const double& z) {
00113       return std::abs (z);
00114     }
00115   };
00116 
00117   template<>
00118   class ScalarTraits< float > {
00119   public:
00120     static const bool is_specialized = true;
00121     static const bool is_complex = false;
00122     typedef float magnitude_type;
00123 
00124     static float zero() { return 0.0; }
00125     static float one() { return 1.0; }
00126     static magnitude_type pi() {
00127       return 3.14159265358979323846;
00128     }
00129 
00130     inline static float conj (const float& z) { return z; }
00131     inline static magnitude_type abs (const float& z) {
00132       return std::abs (z);
00133     }
00134   };
00135 
00136   template<>
00137   class ScalarTraits< std::complex< double > > {
00138   public:
00139     static const bool is_specialized = true;
00140     static const bool is_complex = true;
00141     typedef double magnitude_type;
00142 
00143     static std::complex<double> zero() { return std::complex<double>(0.0, 0.0); }
00144     static std::complex<double> one()  { return std::complex<double>(1.0, 0.0); }
00145     static magnitude_type pi() { return ScalarTraits< magnitude_type >::pi(); }
00146 
00147     inline static std::complex<double> conj (const std::complex<double>& z) {
00148       return std::conj (z);
00149     }
00150     inline static magnitude_type abs (const std::complex<double>& z) {
00151       return std::abs (z);
00152     }
00153   };
00154 
00155   template<>
00156   class ScalarTraits< std::complex< float > > {
00157   public:
00158     static const bool is_specialized = true;
00159     static const bool is_complex = true;
00160     typedef float magnitude_type;
00161 
00162     static std::complex<float> zero() { return std::complex<float>(0.0, 0.0); }
00163     static std::complex<float> one()  { return std::complex<float>(1.0, 0.0); }
00164     static magnitude_type pi() { return ScalarTraits< magnitude_type >::pi(); }
00165 
00166     inline static std::complex<float> conj (const std::complex<float>& z) {
00167       return std::conj (z);
00168     }
00169     inline static magnitude_type abs (const std::complex<float>& z) {
00170       return std::abs (z);
00171     }
00172   };
00173 
00174 
00175 } // namespace TSQR
00176 
00177 #endif // __TSQR_Tsqr_ScalarTraits_hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends