2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
4 #include "bbstdMathOperationVector.h"
5 #include "bbstdPackage.h"
14 BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,MathOperationVector)
15 BBTK_BLACK_BOX_IMPLEMENTATION(MathOperationVector,bbtk::AtomicBlackBox);
17 double MathOperationVector::g(std::vector<double>*v,unsigned int i,double defValue )
19 double result=defValue;
27 void MathOperationVector::SumVector(std::vector<double> *v,std::vector<double> *vr)
31 unsigned int sizeVec=v->size();
34 for (i=0;i<sizeVec;i++)
36 tmpResult = (*v)[i] + tmpResult;
38 vr->push_back( tmpResult );
43 void MathOperationVector::MinVector(std::vector<double> *v,std::vector<double> *vr)
47 unsigned int sizeVec=v->size();
51 for (i=1;i<sizeVec;i++)
53 tmpResult = fmin ( (*v)[i] , tmpResult ) ;
55 vr->push_back( tmpResult );
60 void MathOperationVector::MaxVector(std::vector<double> *v,std::vector<double> *vr)
64 unsigned int sizeVec=v->size();
68 for (i=1;i<sizeVec;i++)
70 tmpResult = fmax ( (*v)[i] , tmpResult ) ;
72 vr->push_back( tmpResult );
77 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
79 void MathOperationVector::Process()
81 // THE MAIN PROCESSING METHOD BODY
82 // Here we simply set the input 'In' value to the output 'Out'
83 // And print out the output value
84 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
85 // void bbSet{Input|Output}NAME(const TYPE&)
86 // const TYPE& bbGet{Input|Output}NAME() const
88 // * NAME is the name of the input/output
89 // (the one provided in the attribute 'name' of the tag 'input')
90 // * TYPE is the C++ type of the input/output
91 // (the one provided in the attribute 'type' of the tag 'input')
95 unsigned int sizeVec = bbGetInputIn0().size();
97 std::vector<double> resultVec;
98 std::vector<double> _v0=bbGetInputIn0();
99 std::vector<double> _v1=bbGetInputIn1();
100 std::vector<double> _v2=bbGetInputIn2();
101 std::vector<double> _v3=bbGetInputIn3();
102 std::vector<double> _v4=bbGetInputIn4();
103 std::vector<double> _v5=bbGetInputIn5();
104 std::vector<double> _v6=bbGetInputIn6();
105 std::vector<double> _v7=bbGetInputIn7();
106 std::vector<double> _v8=bbGetInputIn8();
107 std::vector<double> _v9=bbGetInputIn9();
109 std::vector<double> *v0 = &_v0;
110 std::vector<double> *v1 = &_v1;
111 std::vector<double> *v2 = &_v2;
112 std::vector<double> *v3 = &_v3;
113 std::vector<double> *v4 = &_v4;
114 std::vector<double> *v5 = &_v5;
115 std::vector<double> *v6 = &_v6;
116 std::vector<double> *v7 = &_v7;
117 std::vector<double> *v8 = &_v8;
118 std::vector<double> *v9 = &_v9;
126 /* initialize random seed: */
128 if (bbGetInputType()==7)
130 for (i=0;i<sizeVec;i++)
132 acum.push_back(bbGetInputIn0()[i]);
138 if (bbGetInputType()==0)
140 for (i=0;i<sizeVec;i++)
142 tmpResult = g(v0,i,0) + g(v1,i,0) + g(v2,i,0) + g(v3,i,0) +
143 g(v4,i,0) + g(v5,i,0) + g(v6,i,0) +
144 g(v7,i,0) + g(v8,i,0) + g(v9,i,0) ;
145 resultVec.push_back( tmpResult );
147 bbSetOutputOut( resultVec );
150 if (bbGetInputType()==-99)
152 SumVector(v0,&resultVec);
153 SumVector(v1,&resultVec);
154 SumVector(v2,&resultVec);
155 SumVector(v3,&resultVec);
156 SumVector(v4,&resultVec);
157 SumVector(v5,&resultVec);
158 SumVector(v6,&resultVec);
159 SumVector(v7,&resultVec);
160 SumVector(v8,&resultVec);
161 SumVector(v9,&resultVec);
163 bbSetOutputOut( resultVec );
168 if (bbGetInputType()==1)
170 for (i=0;i<sizeVec;i++)
172 tmpResult = g(v0,i,0) - g(v1,i,0) - g(v2,i,0) - g(v3,i,0) -
173 g(v4,i,0) - g(v5,i,0) - g(v6,i,0) -
174 g(v7,i,0) - g(v8,i,0) - g(v9,i,0) ;
175 resultVec.push_back( tmpResult );
177 bbSetOutputOut( resultVec );
181 if (bbGetInputType()==2)
183 for (i=0;i<sizeVec;i++)
185 tmpResult = g(v0,i,0) * g(v1,i,1) * g(v2,i,1) * g(v3,i,1) *
186 g(v4,i,1) * g(v5,i,1) * g(v6,i,1) *
187 g(v7,i,1) * g(v8,i,1) * g(v9,i,1) ;
188 resultVec.push_back( tmpResult );
190 bbSetOutputOut( resultVec );
195 if (bbGetInputType()==3)
198 for (i=0;i<sizeVec;i++)
200 if (g(v1,i,1)!=0) tmpResult = g(v0,i,0) / g(v1,i,1); else error=true;
201 if (g(v2,i,1)!=0) tmpResult = tmpResult / g(v2,i,1); else error=true;
202 if (g(v3,i,1)!=0) tmpResult = tmpResult / g(v3,i,1); else error=true;
203 if (g(v4,i,1)!=0) tmpResult = tmpResult / g(v4,i,1); else error=true;
204 if (g(v5,i,1)!=0) tmpResult = tmpResult / g(v5,i,1); else error=true;
205 if (g(v6,i,1)!=0) tmpResult = tmpResult / g(v6,i,1); else error=true;
206 if (g(v7,i,1)!=0) tmpResult = tmpResult / g(v7,i,1); else error=true;
207 if (g(v8,i,1)!=0) tmpResult = tmpResult / g(v8,i,1); else error=true;
208 if (g(v9,i,1)!=0) tmpResult = tmpResult / g(v9,i,1); else error=true;
209 if (error==true) tmpResult = 99999;
210 resultVec.push_back( tmpResult );
212 bbSetOutputOut( resultVec );
216 if (bbGetInputType()==4)
218 for (i=0;i<sizeVec;i++)
220 if (bbGetInputIn0()[i]>=0) tmpResult = sqrt( bbGetInputIn0()[i] ) ;
222 resultVec.push_back( tmpResult );
224 bbSetOutputOut( resultVec );
228 if (bbGetInputType()==5)
230 for (i=0;i<sizeVec;i++)
232 if (bbGetInputIn0()[i]>0) tmpResult = log( bbGetInputIn0()[i] ) ;
233 else tmpResult = -99999 ;
234 resultVec.push_back( tmpResult );
236 bbSetOutputOut( resultVec );
241 if (bbGetInputType()==6)
243 for (i=0;i<sizeVec;i++)
245 resultVec.push_back( exp( bbGetInputIn0()[i] ) );
247 bbSetOutputOut( resultVec );
251 if (bbGetInputType()==7)
253 bbSetOutputOut( acum );
254 for (i=0;i<sizeVec;i++)
257 if (acum[i]>g(v1,i,0)) acum[i]=g(v0,i,0);
261 if (bbGetInputType()==8 )
263 for (i=0;i<sizeVec;i++)
265 resultVec.push_back( rand() % (int)( g(v1,i,0)-g(v0,i,0) ) + g(v0,i,0) );
267 bbSetOutputOut( resultVec );
270 if (bbGetInputType()==9)
272 for (i=0;i<sizeVec;i++)
274 resultVec.push_back( sin( bbGetInputIn0()[i] ) );
276 bbSetOutputOut( resultVec );
279 if (bbGetInputType()==10)
281 for (i=0;i<sizeVec;i++)
283 resultVec.push_back( cos( bbGetInputIn0()[i] ) );
285 bbSetOutputOut( resultVec );
288 if (bbGetInputType()==11)
290 for (i=0;i<sizeVec;i++)
292 resultVec.push_back( tan( bbGetInputIn0()[i] ) );
294 bbSetOutputOut( resultVec );
297 if (bbGetInputType()==12)
299 for (i=0;i<sizeVec;i++)
301 resultVec.push_back( asin( bbGetInputIn0()[i] ) );
303 bbSetOutputOut( resultVec );
306 if (bbGetInputType()==13)
308 for (i=0;i<sizeVec;i++)
310 resultVec.push_back( acos( bbGetInputIn0()[i] ) );
312 bbSetOutputOut( resultVec );
315 if (bbGetInputType()==14)
317 for (i=0;i<sizeVec;i++)
319 resultVec.push_back( atan( bbGetInputIn0()[i] ) );
321 bbSetOutputOut( resultVec );
324 if (bbGetInputType()==15)
326 for (i=0;i<sizeVec;i++)
328 resultVec.push_back( atan2( g(v0,i,0) , g(v1,i,0) ) );
330 bbSetOutputOut( resultVec );
334 if (bbGetInputType()==16)
336 for (i=0;i<sizeVec;i++)
338 minTmp = fmin( g(v0,i,999999) , g(v1,i,999999) );
339 minTmp = fmin( g(v2,i,999999) , minTmp );
340 minTmp = fmin( g(v3,i,999999) , minTmp );
341 minTmp = fmin( g(v4,i,999999) , minTmp );
342 minTmp = fmin( g(v5,i,999999) , minTmp );
343 minTmp = fmin( g(v6,i,999999) , minTmp );
344 minTmp = fmin( g(v7,i,999999) , minTmp );
345 minTmp = fmin( g(v8,i,999999) , minTmp );
346 minTmp = fmin( g(v9,i,999999) , minTmp );
347 resultVec.push_back( minTmp );
349 bbSetOutputOut( resultVec );
352 if (bbGetInputType()==-16)
354 MinVector(v0,&resultVec);
355 MinVector(v1,&resultVec);
356 MinVector(v2,&resultVec);
357 MinVector(v3,&resultVec);
358 MinVector(v4,&resultVec);
359 MinVector(v5,&resultVec);
360 MinVector(v6,&resultVec);
361 MinVector(v7,&resultVec);
362 MinVector(v8,&resultVec);
363 MinVector(v9,&resultVec);
365 bbSetOutputOut( resultVec );
368 if (bbGetInputType()==17)
370 for (i=0;i<sizeVec;i++)
372 maxTmp = fmax( g(v0,i,-999999) , g(v1,i,-999999) );
373 maxTmp = fmax( g(v2,i,-999999) , maxTmp );
374 maxTmp = fmax( g(v3,i,-999999) , maxTmp );
375 maxTmp = fmax( g(v4,i,-999999) , maxTmp );
376 maxTmp = fmax( g(v5,i,-999999) , maxTmp );
377 maxTmp = fmax( g(v6,i,-999999) , maxTmp );
378 maxTmp = fmax( g(v7,i,-999999) , maxTmp );
379 maxTmp = fmax( g(v8,i,-999999) , maxTmp );
380 maxTmp = fmax( g(v9,i,-999999) , maxTmp );
381 resultVec.push_back( maxTmp );
383 bbSetOutputOut( resultVec );
387 if (bbGetInputType()==-17)
389 MaxVector(v0,&resultVec);
390 MaxVector(v1,&resultVec);
391 MaxVector(v2,&resultVec);
392 MaxVector(v3,&resultVec);
393 MaxVector(v4,&resultVec);
394 MaxVector(v5,&resultVec);
395 MaxVector(v6,&resultVec);
396 MaxVector(v7,&resultVec);
397 MaxVector(v8,&resultVec);
398 MaxVector(v9,&resultVec);
399 bbSetOutputOut( resultVec );
403 if (bbGetInputType()==18)
405 for (i=0;i<sizeVec;i++)
407 resultVec.push_back( fabs( bbGetInputIn0()[i] ) );
409 bbSetOutputOut( resultVec );
416 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
418 void MathOperationVector::bbUserSetDefaultValues()
421 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
422 // Here we initialize the input 'In' to 0
430 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
432 void MathOperationVector::bbUserInitializeProcessing()
435 // THE INITIALIZATION METHOD BODY :
437 // but this is where you should allocate the internal/output pointers
443 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
445 void MathOperationVector::bbUserFinalizeProcessing()
448 // THE FINALIZATION METHOD BODY :
450 // but this is where you should desallocate the internal/output pointers
455 // EO namespace bbstd