Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

primitive_functions.h

Go to the documentation of this file.
00001 /***
00002  * Copyright (c) 2005, SkeTo Project
00003  * All rights reserved.
00004  */
00010 #ifndef __PRIMITIVE_FUNCTIONS_H__
00011 #define __PRIMITIVE_FUNCTIONS_H__
00012 
00013 #include "matrix.h"
00014 #include <ctime>
00015 #include <cstdlib>
00016 
00020 namespace primitive_functions {
00021 
00025 template<typename A>
00026 class Id : public skeleton::unary_function< A, A >{
00027 public:
00028     void operator()(const A &a, A *r) const {
00029         *r = a;
00030     }
00031 };
00032 
00036 template<typename A, typename B>
00037 class Fst : public skeleton::binary_function< A, A, B >{
00038 public:
00039     void operator()(const A &a, const B &, A *r) const {
00040         *r = a;
00041     }
00042 };
00046 template<typename A, typename B>
00047 class Snd : public skeleton::binary_function< A, B, B >{
00048 public:
00049     void operator()(const A &, const B &b, B *r) const {
00050         *r = b;
00051     }
00052 };
00053 
00057 template<typename A>
00058 class Singleton : public skeleton::unary_function< A, matrix <A> >{
00059 public:
00060     void operator()(const A &a, matrix <A> *mat) const {
00061         mat->singleton(a);
00062     }
00063 };
00064 
00065 
00069 template <typename A>
00070 class The {
00071 public:
00072     void operator()(const matrix <A> &mat, A *r) const{
00073         *r = mat.at(0,0);
00074     }
00075 };
00076 
00080 template<typename A>
00081 class Singleton2 {
00082 public:
00083     void operator()(const A &a, matrix <matrix <A> > *mat) const {
00084         matrix <A> singl;
00085         singl.singleton(a);
00086         mat->singleton(singl);
00087     }
00088 };
00089 
00093 template <typename A>
00094 class Abv : public skeleton::binary_function<matrix <A>, matrix <A>, matrix <A> >{
00095 public:
00096     void operator()(const matrix <A> &a, const matrix <A> &b, matrix <A> *mat) const {
00097         m_skeletons::abv(&a, &b, mat);
00098     }
00099 };
00100 
00104 template <typename A>
00105 class Bsd  : public skeleton::binary_function<matrix <A>, matrix <A>, matrix <A> >{
00106 public:
00107     void operator()(const matrix <A> &a, const matrix <A> &b, matrix <A> *mat) const {
00108         m_skeletons::bsd(&a, &b, mat);
00109     }
00110 };
00111 
00112 
00116 template <typename A>
00117 class Zipwbsd {
00118 public:
00119     void operator()(const matrix <matrix <A> >&a, const matrix <matrix <A> > &b, matrix <matrix <A> > *mat) const {
00120         m_skeletons::zipwith(Bsd<A>(), &a, &b, mat);
00121     }
00122 };
00123 
00127 template <typename A>
00128 class Zipwabv {
00129 public:
00130     void operator()(const matrix <matrix <A> > &a, const matrix <matrix <A> > &b, matrix <matrix <A> > *mat) const {
00131         m_skeletons::zipwith(Abv<A>(), &a, &b, mat);
00132     }
00133 };
00134 
00135     
00139 template <typename A>
00140 class Tr : public skeleton::unary_function<A , A >{
00141 public:
00142     void operator()(const A &a, A *r) const {
00143         *r = a;
00144         r->tr();
00145     }
00146 };
00147 
00151 template <typename A>
00152 class Left : public skeleton::binary_function< A, A, A > {
00153 public:
00154     void operator()(const A &a, const A &, A *r) const {
00155         *r = a;
00156     }
00157 };
00161 template <typename A>
00162 class Right : public skeleton::binary_function< A, A, A > {
00163 public:
00164     void operator()(const A &, const A &b, A*r) const{
00165         *r = b;
00166     }
00167 };
00168 
00172 template<typename A>
00173 class SquareI {
00174 public:
00175     void operator()(A *r) const { 
00176         *r = *r * *r;
00177     }
00178 };
00179 
00183 template<typename A>
00184 class Square : public skeleton::unary_function<A , A >{
00185 public:
00186     void operator()(const A&a, A *r) const { 
00187         *r = a * a;
00188     }
00189 };
00190 
00194 template<typename A>
00195 class Add : public skeleton::binary_function< A, A, A > {
00196 public:
00197     void operator()(const A &i, const A &j, A *r) const {
00198         *r = i + j;
00199     }
00200 };
00201 
00205 template<typename A>
00206 class Sub : public skeleton::binary_function< A, A, A > {
00207 public:
00208     void operator()(const A &i, const A &j, A *r) const {
00209         *r = i - j;
00210     }
00211 };
00212 
00216 template<typename A>
00217 class Mul : public skeleton::binary_function< A, A, A > {
00218 public:
00219     void operator()(const A &i, const A &j, A *r) const {
00220         *r = i * j;
00221     }
00222 };
00223 
00227 template<typename A>
00228 class Div : public skeleton::binary_function< A, A, A > {
00229 public:
00230     void operator()(const A &i, const A &j, A *r) const {
00231         *r = i / j;
00232     }
00233 };
00234 
00238 template<typename A>
00239 class Mod : public skeleton::binary_function< A, A, A > {
00240 public:
00241     void operator()(const A &i, const A &j, A *r) const {
00242         *r = i % j;
00243     }
00244 };
00245 
00249 template<typename A>
00250 class Max : public skeleton::binary_function< A, A, A > {
00251 public:
00252     void operator()(const A &i, const A &j, A *r) const {
00253         *r = (i >= j) ? i : j;
00254     }
00255 };
00256 
00260 template<typename A>
00261 class Min : public skeleton::binary_function< A, A, A > {
00262 public:
00263     void operator()(const A &i, const A &j, A *r) const {
00264         *r = (i <= j) ? i : j;
00265     }
00266 };
00267 
00268 
00272 template<typename A>
00273 class GenZero {
00274 public:
00275     void operator()(int , int , A *r) const {
00276         *r = 0;
00277     }
00278 };
00279 
00283 template<typename A>
00284 class GenAdd {
00285 public:
00286     void operator()(int i, int j, A *r) const {
00287         *r = i + j;
00288     }
00289 };
00290 
00294 template<typename A>
00295 class GenSub {
00296 public:
00297     void operator()(int i, int j, A *r) const {
00298         *r = i - j;
00299     }
00300 };
00301 
00305 template<typename A>
00306 class GenMul {
00307 public:
00308     void operator()(int i, int j, A *r) const {
00309         *r = i * j;
00310     }
00311 };
00312 
00316 class GenRand1 {
00317 public:
00318     GenRand1(){
00319         srand((unsigned int)time(NULL));
00320     }
00321     void operator()(int i, int j, double *r) const {
00322         i = j = 0;
00323         *r = rand()/(double)RAND_MAX;
00324     }
00325 };
00329 class GenRandN {
00330     int n;
00331 public:
00332     GenRandN(int nn){
00333         n = nn;
00334         srand((unsigned int)time(NULL));
00335     }
00336     void operator()(int i, int j, int *r) const {
00337         i = j = 0;
00338         *r = (int)((rand()/(double)RAND_MAX)*n);
00339     }
00340 };
00341 
00342 
00346 template <typename A>
00347 class DivBy : public skeleton::unary_function < A, A >{
00348     A d;
00349 public:
00350     DivBy(A dd){
00351         d = dd;
00352     }
00353     void operator()(A i, A *r) const {
00354         *r = i / d;
00355     }
00356 };
00357     
00358 }
00359 #endif // __PRIMITIVE_FUNCTIONS_H__

Generated on Wed Jan 18 22:19:28 2006 for SkeTo -- Skeleton Library in Tokyo by  doxygen 1.4.4