00001 #ifndef __RVL_FCN_FO__
00002 #define __RVL_FCN_FO__
00003
00004 #include "local.hh"
00005
00013 namespace RVL {
00014
00016 float test1(float x) { return x*x; }
00017
00019 double test2(double x, double y) { return x*y; }
00020
00022 template<typename T>
00023 int ScalarFOSanity(int na,
00024 LocalDataContainer<T> & target,
00025 vector<LocalDataContainer<T> const *> & sources) {
00026 try {
00027 int n=sources.size();
00028 if (n!=na) {
00029 RVLException e;
00030 e<<"Error: ScalarFO::operator\n";
00031 e<<"size of sources = "<<n<<" != na\n";
00032 throw e;
00033 }
00034 int nt=target.getSize();
00035 for (int i=0;i<n;i++) {
00036 if ((sources.at(i))->getSize() != nt) {
00037 RVLException e;
00038 e<<"Error: ScalarFO::operator\n";
00039 e<<"input data len of sources "<<i<<" = "<<sources.at(i)->getSize()<<" not = target data len= "<<nt<<"\n";
00040 throw e;
00041 }
00042 }
00043 return nt;
00044 }
00045 catch (out_of_range) {
00046 RVLException e;
00047 e<<"Error: ScalarFOSanity\n";
00048 e<<"dimensional mismatch - most likely in number of args\n";
00049 throw e;
00050 }
00051 }
00052
00054 template<typename T, T f(T)>
00055 class ScalarFO1: public LocalFunctionObject<T> {
00056
00057 public:
00058
00059 virtual void operator()(LocalDataContainer<T> & target,
00060 vector<LocalDataContainer<T> const *> & sources) {
00061 try {
00062 int nt=ScalarFOSanity(1,target,sources);
00063 for (int it=0;it<nt;it++)
00064 target.getData()[it] = f(sources.at(0)->getData()[it]);
00065 }
00066 catch (RVLException & e) {
00067 e<<"\ncalled from ScalarFO1\n";
00068 }
00069 }
00070
00071 string getName() const { string tmp="ScalarFO1"; return tmp; }
00072 };
00073
00075 template<typename T, T f(T,T)>
00076 class ScalarFO2: public LocalFunctionObject<T> {
00077
00078 public:
00079
00080 virtual void operator()(LocalDataContainer<T> & target,
00081 vector<LocalDataContainer<T> const *> & sources) {
00082 try {
00083 int nt=ScalarFOSanity(2,target,sources);
00084 for (int it=0;it<nt;it++)
00085 target.getData()[it] = f(sources.at(0)->getData()[it],
00086 sources.at(1)->getData()[it]);
00087 }
00088 catch (RVLException & e) {
00089 e<<"\ncalled from ScalarFO3\n";
00090 }
00091 }
00092
00093 string getName() const { string tmp="ScalarFO"; return tmp; }
00094 };
00095
00097 template<typename T, T f(T,T,T)>
00098 class ScalarFO3: public LocalFunctionObject<T> {
00099
00100 public:
00101
00102 virtual void operator()(LocalDataContainer<T> & target,
00103 vector<LocalDataContainer<T> const *> & sources) {
00104 try {
00105
00106 int n=sources.size();
00107 if (n!=3) {
00108 RVLException e;
00109 e<<"Error: ScalarFO::operator\n";
00110 e<<"size of sources = "<<n<<" != 3\n";
00111 throw e;
00112 }
00113 int nt=target.getSize();
00114 for (int i=0;i<n;i++) {
00115 if ((sources.at(i))->getSize() != nt) {
00116 RVLException e;
00117 e<<"Error: ScalarFO::operator\n";
00118 e<<"input data len of sources "<<i<<" = "<<sources.at(i)->getSize()<<" not = target data len= "<<nt<<"\n";
00119 throw e;
00120 }
00121 }
00122 for (int it=0;it<nt;it++)
00123 target.getData()[it] = f(sources.at(0)->getData()[it],
00124 sources.at(1)->getData()[it],
00125 sources.at(2)->getData()[it]);
00126 }
00127
00128 catch (out_of_range) {
00129 RVLException e;
00130 e<<"Error: ScalarFO::operator()\n";
00131 e<<"dimensional mismatch - most likely in number of args\n";
00132 throw e;
00133 }
00134 }
00135
00136 string getName() const { string tmp="ScalarFO"; return tmp; }
00137 };
00138
00139 template<typename T, T f(T,T,T,T)>
00140 class ScalarFO4: public LocalFunctionObject<T> {
00141
00142 public:
00143
00144 virtual void operator()(LocalDataContainer<T> & target,
00145 vector<LocalDataContainer<T> const *> & sources) {
00146 try {
00147
00148 int n=sources.size();
00149 if (n!=4) {
00150 RVLException e;
00151 e<<"Error: ScalarFO::operator\n";
00152 e<<"size of sources = "<<n<<" != 4\n";
00153 throw e;
00154 }
00155 int nt=target.getSize();
00156 for (int i=0;i<n;i++) {
00157 if ((sources.at(i))->getSize() != nt) {
00158 RVLException e;
00159 e<<"Error: ScalarFO::operator\n";
00160 e<<"input data len of sources "<<i<<" = "<<sources.at(i)->getSize()<<" not = target data len= "<<nt<<"\n";
00161 throw e;
00162 }
00163 }
00164 for (int it=0;it<nt;it++)
00165 target.getData()[it] = f(sources.at(0)->getData()[it],
00166 sources.at(1)->getData()[it],
00167 sources.at(2)->getData()[it],
00168 sources.at(3)->getData()[it]);
00169 }
00170
00171 catch (out_of_range) {
00172 RVLException e;
00173 e<<"Error: ScalarFO::operator()\n";
00174 e<<"dimensional mismatch - most likely in number of args\n";
00175 throw e;
00176 }
00177 }
00178
00179 string getName() const { string tmp="ScalarFO"; return tmp; }
00180 };
00181
00182 template<typename T, T f(T,T,T,T,T)>
00183 class ScalarFO5: public LocalFunctionObject<T> {
00184
00185 public:
00186
00187 virtual void operator()(LocalDataContainer<T> & target,
00188 vector<LocalDataContainer<T> const *> & sources) {
00189 try {
00190
00191 int n=sources.size();
00192 if (n!=5) {
00193 RVLException e;
00194 e<<"Error: ScalarFO::operator\n";
00195 e<<"size of sources = "<<n<<" != 5\n";
00196 throw e;
00197 }
00198 int nt=target.getSize();
00199 for (int i=0;i<n;i++) {
00200 if ((sources.at(i))->getSize() != nt) {
00201 RVLException e;
00202 e<<"Error: ScalarFO::operator\n";
00203 e<<"input data len of sources "<<i<<" = "<<sources.at(i)->getSize()<<" not = target data len= "<<nt<<"\n";
00204 throw e;
00205 }
00206 }
00207 for (int it=0;it<nt;it++)
00208 target.getData()[it] = f(sources.at(0)->getData()[it],
00209 sources.at(1)->getData()[it],
00210 sources.at(2)->getData()[it],
00211 sources.at(3)->getData()[it],
00212 sources.at(4)->getData()[it]);
00213 }
00214
00215 catch (out_of_range) {
00216 RVLException e;
00217 e<<"Error: ScalarFO::operator()\n";
00218 e<<"dimensional mismatch - most likely in number of args\n";
00219 throw e;
00220 }
00221 }
00222
00223 string getName() const { string tmp="ScalarFO"; return tmp; }
00224 };
00225
00226 template<typename T, T f(T,T,T,T,T,T)>
00227 class ScalarFO6: public LocalFunctionObject<T> {
00228
00229 public:
00230
00231 virtual void operator()(LocalDataContainer<T> & target,
00232 vector<LocalDataContainer<T> const *> & sources) {
00233 try {
00234
00235 int n=sources.size();
00236 if (n!=6) {
00237 RVLException e;
00238 e<<"Error: ScalarFO::operator\n";
00239 e<<"size of sources = "<<n<<" != 6\n";
00240 throw e;
00241 }
00242 int nt=target.getSize();
00243 for (int i=0;i<n;i++) {
00244 if ((sources.at(i))->getSize() != nt) {
00245 RVLException e;
00246 e<<"Error: ScalarFO::operator\n";
00247 e<<"input data len of sources "<<i<<" = "<<sources.at(i)->getSize()<<" not = target data len= "<<nt<<"\n";
00248 throw e;
00249 }
00250 }
00251 for (int it=0;it<nt;it++)
00252 target.getData()[it] = f(sources.at(0)->getData()[it],
00253 sources.at(1)->getData()[it],
00254 sources.at(2)->getData()[it],
00255 sources.at(3)->getData()[it],
00256 sources.at(4)->getData()[it],
00257 sources.at(5)->getData()[it]);
00258 }
00259 catch (out_of_range) {
00260 RVLException e;
00261 e<<"Error: ScalarFO::operator()\n";
00262 e<<"dimensional mismatch - most likely in number of args\n";
00263 throw e;
00264 }
00265 }
00266
00267 string getName() const { string tmp="ScalarFO"; return tmp; }
00268 };
00269
00270 }
00271
00272 #endif