promote_type.hpp
Go to the documentation of this file.
00001 // Copyright (C) 2009-2011 NICTA (www.nicta.com.au)
00002 // Copyright (C) 2009-2011 Conrad Sanderson
00003 // 
00004 // This file is part of the Armadillo C++ library.
00005 // It is provided without any warranty of fitness
00006 // for any purpose. You can redistribute this file
00007 // and/or modify it under the terms of the GNU
00008 // Lesser General Public License (LGPL) as published
00009 // by the Free Software Foundation, either version 3
00010 // of the License or (at your option) any later version.
00011 // (see http://www.opensource.org/licenses for more info)
00012 
00013 
00016 
00017 
00018 template<typename T1, typename T2>
00019 struct is_promotable
00020   {
00021   static const bool value = false;
00022   typedef T1 result;
00023   };
00024 
00025 
00026 struct is_promotable_ok
00027   {
00028   static const bool value = true;
00029   };
00030 
00031 
00032 template<typename T> struct is_promotable<T,               T> : public is_promotable_ok { typedef T               result; };
00033 template<typename T> struct is_promotable<std::complex<T>, T> : public is_promotable_ok { typedef std::complex<T> result; };
00034 
00035 template<> struct is_promotable<std::complex<double>, std::complex<float> > : public is_promotable_ok { typedef std::complex<double> result; };
00036 template<> struct is_promotable<std::complex<double>, float>                : public is_promotable_ok { typedef std::complex<double> result; };
00037 template<> struct is_promotable<std::complex<float>,  double>               : public is_promotable_ok { typedef std::complex<double> result; };
00038 
00039 #if defined(ARMA_64BIT_WORD)
00040 template<typename t> struct is_promotable<std::complex<t>, u64> : public is_promotable_ok { typedef std::complex<t> result; };
00041 template<typename t> struct is_promotable<std::complex<t>, s64> : public is_promotable_ok { typedef std::complex<t> result; };
00042 #endif
00043 template<typename T> struct is_promotable<std::complex<T>, s32> : public is_promotable_ok { typedef std::complex<T> result; };
00044 template<typename T> struct is_promotable<std::complex<T>, u32> : public is_promotable_ok { typedef std::complex<T> result; };
00045 template<typename T> struct is_promotable<std::complex<T>, s16> : public is_promotable_ok { typedef std::complex<T> result; };
00046 template<typename T> struct is_promotable<std::complex<T>, u16> : public is_promotable_ok { typedef std::complex<T> result; };
00047 template<typename T> struct is_promotable<std::complex<T>, s8>  : public is_promotable_ok { typedef std::complex<T> result; };
00048 template<typename T> struct is_promotable<std::complex<T>, u8>  : public is_promotable_ok { typedef std::complex<T> result; };
00049 
00050 
00051 template<> struct is_promotable<double, float> : public is_promotable_ok { typedef double result; };
00052 #if defined(ARMA_64BIT_WORD)
00053 template<> struct is_promotable<double, s64  > : public is_promotable_ok { typedef double result; };
00054 template<> struct is_promotable<double, u64  > : public is_promotable_ok { typedef double result; };
00055 #endif
00056 template<> struct is_promotable<double, s32  > : public is_promotable_ok { typedef double result; };
00057 template<> struct is_promotable<double, u32  > : public is_promotable_ok { typedef double result; };
00058 template<> struct is_promotable<double, s16  > : public is_promotable_ok { typedef double result; };
00059 template<> struct is_promotable<double, u16  > : public is_promotable_ok { typedef double result; };
00060 template<> struct is_promotable<double, s8   > : public is_promotable_ok { typedef double result; };
00061 template<> struct is_promotable<double, u8   > : public is_promotable_ok { typedef double result; };
00062 
00063 #if defined(ARMA_64BIT_WORD)
00064 template<> struct is_promotable<float, s64> : public is_promotable_ok { typedef float result; };
00065 template<> struct is_promotable<float, u64> : public is_promotable_ok { typedef float result; };
00066 #endif
00067 template<> struct is_promotable<float, s32> : public is_promotable_ok { typedef float result; };
00068 template<> struct is_promotable<float, u32> : public is_promotable_ok { typedef float result; };
00069 template<> struct is_promotable<float, s16> : public is_promotable_ok { typedef float result; };
00070 template<> struct is_promotable<float, u16> : public is_promotable_ok { typedef float result; };
00071 template<> struct is_promotable<float, s8 > : public is_promotable_ok { typedef float result; };
00072 template<> struct is_promotable<float, u8 > : public is_promotable_ok { typedef float result; };
00073 
00074 #if defined(ARMA_64BIT_WORD)
00075 template<> struct is_promotable<u64, u32> : public is_promotable_ok { typedef u64 result; };
00076 template<> struct is_promotable<u64, u16> : public is_promotable_ok { typedef u64 result; };
00077 template<> struct is_promotable<u64, u8 > : public is_promotable_ok { typedef u64 result; };
00078 #endif
00079 
00080 #if defined(ARMA_64BIT_WORD)
00081 template<> struct is_promotable<s64, u64> : public is_promotable_ok { typedef s64 result; };  // float ?  
00082 template<> struct is_promotable<s64, u32> : public is_promotable_ok { typedef s64 result; };
00083 template<> struct is_promotable<s64, s32> : public is_promotable_ok { typedef s64 result; };
00084 template<> struct is_promotable<s64, s16> : public is_promotable_ok { typedef s64 result; };
00085 template<> struct is_promotable<s64, u16> : public is_promotable_ok { typedef s64 result; };
00086 template<> struct is_promotable<s64, s8 > : public is_promotable_ok { typedef s64 result; };
00087 template<> struct is_promotable<s64, u8 > : public is_promotable_ok { typedef s64 result; };
00088 #endif
00089 
00090 template<> struct is_promotable<s32, u32> : public is_promotable_ok { typedef s32 result; };  // float ?  
00091 template<> struct is_promotable<s32, s16> : public is_promotable_ok { typedef s32 result; };
00092 template<> struct is_promotable<s32, u16> : public is_promotable_ok { typedef s32 result; };
00093 template<> struct is_promotable<s32, s8 > : public is_promotable_ok { typedef s32 result; };
00094 template<> struct is_promotable<s32, u8 > : public is_promotable_ok { typedef s32 result; };
00095 
00096 template<> struct is_promotable<u32, s16> : public is_promotable_ok { typedef s32 result; };  // float ?
00097 template<> struct is_promotable<u32, u16> : public is_promotable_ok { typedef u32 result; };
00098 template<> struct is_promotable<u32, s8 > : public is_promotable_ok { typedef s32 result; };  // float ?
00099 template<> struct is_promotable<u32, u8 > : public is_promotable_ok { typedef u32 result; };
00100 
00101 template<> struct is_promotable<s16, u16> : public is_promotable_ok { typedef s16 result; };  // s32 ?
00102 template<> struct is_promotable<s16, s8 > : public is_promotable_ok { typedef s16 result; };
00103 template<> struct is_promotable<s16, u8 > : public is_promotable_ok { typedef s16 result; };
00104 
00105 template<> struct is_promotable<u16, s8> : public is_promotable_ok { typedef s16 result; };  // s32 ?
00106 template<> struct is_promotable<u16, u8> : public is_promotable_ok { typedef u16 result; };
00107 
00108 template<> struct is_promotable<s8, u8> : public is_promotable_ok { typedef s8 result; };  // s16 ?
00109 
00110 
00111 
00112 
00113 //
00114 // mirrored versions
00115 
00116 template<typename T> struct is_promotable<T, std::complex<T> > : public is_promotable_ok { typedef std::complex<T> result; };
00117 
00118 template<> struct is_promotable<std::complex<float>, std::complex<double> > : public is_promotable_ok { typedef std::complex<double> result; };
00119 template<> struct is_promotable<float,               std::complex<double> > : public is_promotable_ok { typedef std::complex<double> result; };
00120 template<> struct is_promotable<double,              std::complex<float>  > : public is_promotable_ok { typedef std::complex<double> result; };
00121 
00122 #if defined(ARMA_64BIT_WORD)
00123 template<typename T> struct is_promotable<s64, std::complex<T> > : public is_promotable_ok { typedef std::complex<T> result; };
00124 template<typename T> struct is_promotable<u64, std::complex<T> > : public is_promotable_ok { typedef std::complex<T> result; };
00125 #endif
00126 template<typename T> struct is_promotable<s32, std::complex<T> > : public is_promotable_ok { typedef std::complex<T> result; };
00127 template<typename T> struct is_promotable<u32, std::complex<T> > : public is_promotable_ok { typedef std::complex<T> result; };
00128 template<typename T> struct is_promotable<s16, std::complex<T> > : public is_promotable_ok { typedef std::complex<T> result; };
00129 template<typename T> struct is_promotable<u16, std::complex<T> > : public is_promotable_ok { typedef std::complex<T> result; };
00130 template<typename T> struct is_promotable<s8,  std::complex<T> > : public is_promotable_ok { typedef std::complex<T> result; };
00131 template<typename T> struct is_promotable<u8,  std::complex<T> > : public is_promotable_ok { typedef std::complex<T> result; };
00132 
00133 
00134 template<> struct is_promotable<float, double> : public is_promotable_ok { typedef double result; };
00135 #if defined(ARMA_64BIT_WORD)
00136 template<> struct is_promotable<s64  , double> : public is_promotable_ok { typedef double result; };
00137 template<> struct is_promotable<u64  , double> : public is_promotable_ok { typedef double result; };
00138 #endif
00139 template<> struct is_promotable<s32  , double> : public is_promotable_ok { typedef double result; };
00140 template<> struct is_promotable<u32  , double> : public is_promotable_ok { typedef double result; };
00141 template<> struct is_promotable<s16  , double> : public is_promotable_ok { typedef double result; };
00142 template<> struct is_promotable<u16  , double> : public is_promotable_ok { typedef double result; };
00143 template<> struct is_promotable<s8   , double> : public is_promotable_ok { typedef double result; };
00144 template<> struct is_promotable<u8   , double> : public is_promotable_ok { typedef double result; };
00145 
00146 #if defined(ARMA_64BIT_WORD)
00147 template<> struct is_promotable<s64, float> : public is_promotable_ok { typedef float result; };
00148 template<> struct is_promotable<u64, float> : public is_promotable_ok { typedef float result; };
00149 #endif
00150 template<> struct is_promotable<s32, float> : public is_promotable_ok { typedef float result; };
00151 template<> struct is_promotable<u32, float> : public is_promotable_ok { typedef float result; };
00152 template<> struct is_promotable<s16, float> : public is_promotable_ok { typedef float result; };
00153 template<> struct is_promotable<u16, float> : public is_promotable_ok { typedef float result; };
00154 template<> struct is_promotable<s8 , float> : public is_promotable_ok { typedef float result; };
00155 template<> struct is_promotable<u8 , float> : public is_promotable_ok { typedef float result; };
00156 
00157 #if defined(ARMA_64BIT_WORD)
00158 template<> struct is_promotable<u32, u64> : public is_promotable_ok { typedef u64 result; };
00159 template<> struct is_promotable<u16, u64> : public is_promotable_ok { typedef u64 result; };
00160 template<> struct is_promotable<u8,  u64> : public is_promotable_ok { typedef u64 result; };
00161 #endif
00162 
00163 #if defined(ARMA_64BIT_WORD)
00164 template<> struct is_promotable<u64, s64> : public is_promotable_ok { typedef s64 result; };  // float ?  
00165 template<> struct is_promotable<u32, s64> : public is_promotable_ok { typedef s64 result; };
00166 template<> struct is_promotable<s16, s64> : public is_promotable_ok { typedef s64 result; };
00167 template<> struct is_promotable<u16, s64> : public is_promotable_ok { typedef s64 result; };
00168 template<> struct is_promotable<s8 , s64> : public is_promotable_ok { typedef s64 result; };
00169 template<> struct is_promotable<u8 , s64> : public is_promotable_ok { typedef s64 result; };
00170 #endif
00171 
00172 template<> struct is_promotable<u32, s32> : public is_promotable_ok { typedef s32 result; };  // float ?  
00173 template<> struct is_promotable<s16, s32> : public is_promotable_ok { typedef s32 result; };
00174 template<> struct is_promotable<u16, s32> : public is_promotable_ok { typedef s32 result; };
00175 template<> struct is_promotable<s8 , s32> : public is_promotable_ok { typedef s32 result; };
00176 template<> struct is_promotable<u8 , s32> : public is_promotable_ok { typedef s32 result; };
00177 
00178 template<> struct is_promotable<s16, u32> : public is_promotable_ok { typedef s32 result; };  // float ?
00179 template<> struct is_promotable<u16, u32> : public is_promotable_ok { typedef u32 result; };
00180 template<> struct is_promotable<s8 , u32> : public is_promotable_ok { typedef s32 result; };  // float ?
00181 template<> struct is_promotable<u8 , u32> : public is_promotable_ok { typedef u32 result; };
00182 
00183 template<> struct is_promotable<u16, s16> : public is_promotable_ok { typedef s16 result; };  // s32 ?
00184 template<> struct is_promotable<s8 , s16> : public is_promotable_ok { typedef s16 result; };
00185 template<> struct is_promotable<u8 , s16> : public is_promotable_ok { typedef s16 result; };
00186 
00187 template<> struct is_promotable<s8, u16> : public is_promotable_ok { typedef s16 result; };  // s32 ?
00188 template<> struct is_promotable<u8, u16> : public is_promotable_ok { typedef u16 result; };
00189 
00190 template<> struct is_promotable<u8, s8> : public is_promotable_ok { typedef s8 result; };  // s16 ?
00191 
00192 
00193 
00194 
00195 
00196 template<typename T1, typename T2>
00197 struct promote_type
00198   {
00199   inline static void check()
00200     {
00201     arma_type_check(( is_promotable<T1,T2>::value == false ));
00202     }
00203   
00204   typedef typename is_promotable<T1,T2>::result result;
00205   };
00206 
00207 
00208 
00209 template<typename T1, typename T2>
00210 struct eT_promoter
00211   {
00212   typedef typename promote_type<typename T1::elem_type, typename T2::elem_type>::result eT;
00213   };
00214 
00215 
00216 


armadillo_matrix
Author(s): Conrad Sanderson - NICTA (www.nicta.com.au), (Wrapper by Sjoerd van den Dries)
autogenerated on Tue Jan 7 2014 11:42:05