scalar_math.h

00001 
00006 #pragma once
00007 
00008 #include <usml/ublas/math_traits.h>
00009 
00010 namespace usml {
00011 namespace ublas {
00012 
00035     //**********************************************************
00036     // limiting functions
00037 
00042     template<class T1, class T2>
00043     struct scalar_max:
00044         public scalar_binary_functor<T1, T2> {
00045         typedef typename scalar_binary_functor<T1, T2>::argument1_type
00046                          argument1_type;
00047         typedef typename scalar_binary_functor<T1, T2>::argument2_type
00048                          argument2_type;
00049         typedef typename scalar_binary_functor<T1, T2>::result_type
00050                          result_type;
00051 
00052         static inline result_type apply(argument1_type t1, argument2_type t2) {
00053             return math_traits<result_type>::max(t1,t2) ;
00054         }
00055     };
00056 
00061     template<class T1, class T2>
00062     struct scalar_min:
00063         public scalar_binary_functor<T1, T2> {
00064         typedef typename scalar_binary_functor<T1, T2>::argument1_type
00065                          argument1_type;
00066         typedef typename scalar_binary_functor<T1, T2>::argument2_type
00067                          argument2_type;
00068         typedef typename scalar_binary_functor<T1, T2>::result_type
00069                          result_type;
00070 
00071         static inline result_type apply(argument1_type t1, argument2_type t2) {
00072             return math_traits<result_type>::min(t1,t2) ;
00073         }
00074     };
00075 
00080     template<class T>
00081     struct scalar_floor:
00082         public scalar_unary_functor<T> {
00083         typedef typename scalar_unary_functor<T>::argument_type argument_type;
00084         typedef typename scalar_unary_functor<T>::result_type result_type;
00085 
00086         static inline result_type apply(argument_type t) {
00087             return math_traits<result_type>::floor(t) ;
00088         }
00089     };
00090 
00095     template<class T>
00096     struct scalar_ceil:
00097         public scalar_unary_functor<T> {
00098         typedef typename scalar_unary_functor<T>::argument_type argument_type;
00099         typedef typename scalar_unary_functor<T>::result_type result_type;
00100 
00101         static inline result_type apply(argument_type t) {
00102             return math_traits<result_type>::ceil(t) ;
00103         }
00104     };
00105 
00106     //**********************************************************
00107     // conversion functions
00108 
00113     template<class T>
00114     struct scalar_to_degrees:
00115         public scalar_real_unary_functor<T> {
00116         typedef typename scalar_real_unary_functor<T>::argument_type
00117                          argument_type;
00118         typedef typename scalar_real_unary_functor<T>::result_type
00119                          result_type;
00120 
00121         static inline result_type apply(argument_type t) {
00122             return math_traits<result_type>::to_degrees(t);
00123         }
00124     };
00125 
00130     template<class T>
00131     struct scalar_to_radians:
00132         public scalar_real_unary_functor<T> {
00133         typedef typename scalar_real_unary_functor<T>::argument_type
00134                          argument_type;
00135         typedef typename scalar_real_unary_functor<T>::result_type
00136                          result_type;
00137 
00138         static inline result_type apply(argument_type t) {
00139             return math_traits<result_type>::to_radians(t);
00140         }
00141     };
00142 
00148     template<class T>
00149     struct scalar_to_latitude:
00150         public scalar_real_unary_functor<T> {
00151         typedef typename scalar_real_unary_functor<T>::argument_type
00152                          argument_type;
00153         typedef typename scalar_real_unary_functor<T>::result_type
00154                          result_type;
00155 
00156         static inline result_type apply(argument_type t) {
00157             return math_traits<result_type>::to_latitude(t);
00158         }
00159     };
00160 
00166     template<class T>
00167     struct scalar_to_colatitude:
00168         public scalar_real_unary_functor<T> {
00169         typedef typename scalar_real_unary_functor<T>::argument_type
00170                          argument_type;
00171         typedef typename scalar_real_unary_functor<T>::result_type
00172                          result_type;
00173 
00174         static inline result_type apply(argument_type t) {
00175             return math_traits<result_type>::to_colatitude(t);
00176         }
00177     };
00178 
00179     //**********************************************************
00180     // algebraic functions
00181 
00186     template<class T>
00187     struct scalar_abs:
00188         public scalar_real_unary_functor<T> {
00189         typedef typename scalar_real_unary_functor<T>::argument_type
00190                          argument_type;
00191         typedef typename scalar_real_unary_functor<T>::result_type
00192                          result_type;
00193 
00194         static inline result_type apply(argument_type t) {
00195             return math_traits<result_type>::abs(t);
00196         }
00197     };
00198 
00203     template<class T>
00204     struct scalar_abs2:
00205         public scalar_real_unary_functor<T> {
00206         typedef typename scalar_real_unary_functor<T>::argument_type
00207                          argument_type;
00208         typedef typename scalar_real_unary_functor<T>::result_type
00209                          result_type;
00210 
00211         static inline result_type apply(argument_type t) {
00212             return math_traits<result_type>::abs2(t);
00213         }
00214     };
00215 
00220     template<class T>
00221     struct scalar_arg:
00222         public scalar_real_unary_functor<T> {
00223         typedef typename scalar_real_unary_functor<T>::argument_type
00224                          argument_type;
00225         typedef typename scalar_real_unary_functor<T>::result_type
00226                          result_type;
00227 
00228         static inline result_type apply(argument_type t) {
00229             return math_traits<result_type>::arg(t);
00230         }
00231     };
00232 
00237     template<class T>
00238     struct scalar_sqrt:
00239         public scalar_unary_functor<T> {
00240         typedef typename scalar_unary_functor<T>::argument_type argument_type;
00241         typedef typename scalar_unary_functor<T>::result_type result_type;
00242 
00243         static inline result_type apply(argument_type t) {
00244             return math_traits<result_type>::sqrt(t);
00245         }
00246     };
00247 
00252     template<class T1, class T2>
00253     struct scalar_copysign:
00254         public scalar_binary_functor<T1, T2> {
00255         typedef typename scalar_binary_functor<T1, T2>::argument1_type
00256                          argument1_type;
00257         typedef typename scalar_binary_functor<T1, T2>::argument2_type
00258                          argument2_type;
00259         typedef typename scalar_binary_functor<T1, T2>::result_type
00260                          result_type;
00261 
00262         static inline result_type apply(argument1_type t1, argument2_type t2) {
00263             return math_traits<result_type>::copysign(t1,t2) ;
00264         }
00265     };
00266 
00267     //**********************************************************
00268     // trigonometric functions
00269 
00274     template<class T>
00275     struct scalar_cos:
00276         public scalar_unary_functor<T> {
00277         typedef typename scalar_unary_functor<T>::argument_type argument_type;
00278         typedef typename scalar_unary_functor<T>::result_type result_type;
00279 
00280         static inline result_type apply(argument_type t) {
00281             return math_traits<result_type>::cos(t);
00282         }
00283     };
00284 
00289     template<class T>
00290     struct scalar_cosh:
00291         public scalar_unary_functor<T> {
00292         typedef typename scalar_unary_functor<T>::argument_type argument_type;
00293         typedef typename scalar_unary_functor<T>::result_type result_type;
00294 
00295         static inline result_type apply(argument_type t) {
00296             return math_traits<result_type>::cosh(t);
00297         }
00298     };
00299 
00304     template<class T>
00305     struct scalar_sin:
00306         public scalar_unary_functor<T> {
00307         typedef typename scalar_unary_functor<T>::argument_type argument_type;
00308         typedef typename scalar_unary_functor<T>::result_type result_type;
00309 
00310         static inline result_type apply(argument_type t) {
00311             return math_traits<result_type>::sin(t);
00312         }
00313     };
00314 
00319     template<class T>
00320     struct scalar_sinh:
00321         public scalar_unary_functor<T> {
00322         typedef typename scalar_unary_functor<T>::argument_type argument_type;
00323         typedef typename scalar_unary_functor<T>::result_type result_type;
00324 
00325         static inline result_type apply(argument_type t) {
00326             return math_traits<result_type>::sinh(t);
00327         }
00328     };
00329 
00334     template<class T>
00335     struct scalar_tan:
00336         public scalar_unary_functor<T> {
00337         typedef typename scalar_unary_functor<T>::argument_type argument_type;
00338         typedef typename scalar_unary_functor<T>::result_type result_type;
00339 
00340         static inline result_type apply(argument_type t) {
00341             return math_traits<result_type>::tan(t);
00342         }
00343     };
00344 
00349     template<class T>
00350     struct scalar_tanh:
00351         public scalar_unary_functor<T> {
00352         typedef typename scalar_unary_functor<T>::argument_type argument_type;
00353         typedef typename scalar_unary_functor<T>::result_type result_type;
00354 
00355         static inline result_type apply(argument_type t) {
00356             return math_traits<result_type>::tanh(t);
00357         }
00358     };
00359 
00360     //**********************************************************
00361     // inverse trigonometric functions
00362 
00367     template<class T>
00368     struct scalar_acos:
00369         public scalar_unary_functor<T> {
00370         typedef typename scalar_unary_functor<T>::argument_type argument_type;
00371         typedef typename scalar_unary_functor<T>::result_type result_type;
00372 
00373         static inline result_type apply(argument_type t) {
00374             return math_traits<result_type>::acos(t);
00375         }
00376     };
00377 
00382     template<class T>
00383     struct scalar_acosh:
00384         public scalar_unary_functor<T> {
00385         typedef typename scalar_unary_functor<T>::argument_type argument_type;
00386         typedef typename scalar_unary_functor<T>::result_type result_type;
00387 
00388         static inline result_type apply(argument_type t) {
00389             return math_traits<result_type>::acosh(t);
00390         }
00391     };
00392 
00397     template<class T>
00398     struct scalar_asin:
00399         public scalar_unary_functor<T> {
00400         typedef typename scalar_unary_functor<T>::argument_type argument_type;
00401         typedef typename scalar_unary_functor<T>::result_type result_type;
00402 
00403         static inline result_type apply(argument_type t) {
00404             return math_traits<result_type>::asin(t);
00405         }
00406     };
00407 
00412     template<class T>
00413     struct scalar_asinh:
00414         public scalar_unary_functor<T> {
00415         typedef typename scalar_unary_functor<T>::argument_type argument_type;
00416         typedef typename scalar_unary_functor<T>::result_type result_type;
00417 
00418         static inline result_type apply(argument_type t) {
00419             return math_traits<result_type>::asinh(t);
00420         }
00421     };
00422 
00427     template<class T>
00428     struct scalar_atan:
00429         public scalar_unary_functor<T> {
00430         typedef typename scalar_unary_functor<T>::argument_type argument_type;
00431         typedef typename scalar_unary_functor<T>::result_type result_type;
00432 
00433         static inline result_type apply(argument_type t) {
00434             return math_traits<result_type>::atan(t);
00435         }
00436     };
00437 
00442     template<class T1, class T2>
00443     struct scalar_atan2:
00444         public scalar_binary_functor<T1, T2> {
00445         typedef typename scalar_binary_functor<T1, T2>::argument1_type
00446                          argument1_type;
00447         typedef typename scalar_binary_functor<T1, T2>::argument2_type
00448                          argument2_type;
00449         typedef typename scalar_binary_functor<T1, T2>::result_type
00450                          result_type;
00451 
00452         static inline result_type apply(argument1_type y, argument2_type x) {
00453             return math_traits<result_type>::atan2(y,x) ;
00454         }
00455     };
00456 
00461     template<class T>
00462     struct scalar_atanh:
00463         public scalar_unary_functor<T> {
00464         typedef typename scalar_unary_functor<T>::argument_type argument_type;
00465         typedef typename scalar_unary_functor<T>::result_type result_type;
00466 
00467         static inline result_type apply(argument_type t) {
00468             return math_traits<result_type>::atanh(t);
00469         }
00470     };
00471 
00472     //**********************************************************
00473     // exponential functions
00474 
00479     template<class T>
00480     struct scalar_exp:
00481         public scalar_unary_functor<T> {
00482         typedef typename scalar_unary_functor<T>::argument_type argument_type;
00483         typedef typename scalar_unary_functor<T>::result_type result_type;
00484 
00485         static inline result_type apply(argument_type t) {
00486             return math_traits<result_type>::exp(t);
00487         }
00488     };
00489 
00494     template<class T>
00495     struct scalar_log:
00496         public scalar_unary_functor<T> {
00497         typedef typename scalar_unary_functor<T>::argument_type argument_type;
00498         typedef typename scalar_unary_functor<T>::result_type result_type;
00499 
00500         static inline result_type apply(argument_type t) {
00501             return math_traits<result_type>::log(t);
00502         }
00503     };
00504 
00509     template<class T>
00510     struct scalar_log10:
00511         public scalar_unary_functor<T> {
00512         typedef typename scalar_unary_functor<T>::argument_type argument_type;
00513         typedef typename scalar_unary_functor<T>::result_type result_type;
00514 
00515         static inline result_type apply(argument_type t) {
00516             return math_traits<result_type>::log10(t);
00517         }
00518     };
00519 
00524     template<class T1, class T2>
00525     struct scalar_pow:
00526         public scalar_binary_functor<T1, T2> {
00527         typedef typename scalar_binary_functor<T1, T2>::argument1_type
00528                          argument1_type;
00529         typedef typename scalar_binary_functor<T1, T2>::argument2_type
00530                          argument2_type;
00531         typedef typename scalar_binary_functor<T1, T2>::result_type
00532                          result_type;
00533 
00534         static inline result_type apply(argument1_type t1, argument2_type t2) {
00535             return math_traits<result_type>::pow(t1,t2) ;
00536         }
00537     };
00538 
00539     //**********************************************************
00540     // signal processing functions
00541 
00547     template<class T>
00548     struct scalar_signal:
00549         public scalar_real_unary_functor<T> {
00550         typedef typename scalar_real_unary_functor<T>::argument_type
00551                          argument_type;
00552         typedef typename scalar_real_unary_functor<T>::result_type
00553                          result_type;
00554 
00555         static inline result_type apply(argument_type t) {
00556             return math_traits<result_type>::sin(t);
00557         }
00558     };
00559 
00565     template<class T>
00566     struct scalar_asignal {
00567         typedef T argument_type;
00568         typedef complex<T> result_type ;
00569 
00570         static inline result_type apply(argument_type t) {
00571             return math_traits<result_type>::sin(t);
00572             return result_type( math_traits<T>::sin(t),
00573                                 math_traits<T>::cos(t) ) ;
00574         }
00575     };
00576 
00577 } // end of ublas namespace
00578 } // end of usml namespace

Generated on 4 May 2015 for USML by  doxygen 1.6.1