+//=====
+// 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)
+//=====
+#include "bbstdMathOperationVector.h"
+#include "bbstdPackage.h"
+
+#include <math.h>
+#include <stdlib.h>
+#include <time.h>
+
+namespace bbstd
+{
+
+BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,MathOperationVector)
+BBTK_BLACK_BOX_IMPLEMENTATION(MathOperationVector,bbtk::AtomicBlackBox);
+
+double MathOperationVector::g(std::vector<double>*v,unsigned int i,double defValue )
+{
+ double result=defValue;
+ if (i < (*v).size())
+ {
+ result= (*v)[i];
+ }
+ return result;
+}
+
+void MathOperationVector::SumVector(std::vector<double> *v,std::vector<double> *vr)
+{
+ unsigned int i;
+ double tmpResult=0;
+ unsigned int sizeVec=v->size();
+ if ( sizeVec>0)
+ {
+ for (i=0;i<sizeVec;i++)
+ {
+ tmpResult = (*v)[i] + tmpResult;
+ } // for i
+ vr->push_back( tmpResult );
+ } // if sizeVec
+}
+
+
+void MathOperationVector::MinVector(std::vector<double> *v,std::vector<double> *vr)
+{
+ unsigned int i;
+ double tmpResult;
+ unsigned int sizeVec=v->size();
+ if ( sizeVec>0)
+ {
+ tmpResult=(*v)[0];
+ for (i=1;i<sizeVec;i++)
+ {
+ tmpResult = fmin ( (*v)[i] , tmpResult ) ;
+ } // for i
+ vr->push_back( tmpResult );
+ } // if sizeVec
+}
+
+
+void MathOperationVector::MaxVector(std::vector<double> *v,std::vector<double> *vr)
+{
+ unsigned int i;
+ double tmpResult;
+ unsigned int sizeVec=v->size();
+ if ( sizeVec>0)
+ {
+ tmpResult=(*v)[0];
+ for (i=1;i<sizeVec;i++)
+ {
+ tmpResult = fmax ( (*v)[i] , tmpResult ) ;
+ } // for i
+ vr->push_back( tmpResult );
+ } // if sizeVec
+}
+
+//=====
+// 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)
+//=====
+void MathOperationVector::Process()
+{
+// THE MAIN PROCESSING METHOD BODY
+// Here we simply set the input 'In' value to the output 'Out'
+// And print out the output value
+// INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
+// void bbSet{Input|Output}NAME(const TYPE&)
+// const TYPE& bbGet{Input|Output}NAME() const
+// Where :
+// * NAME is the name of the input/output
+// (the one provided in the attribute 'name' of the tag 'input')
+// * TYPE is the C++ type of the input/output
+// (the one provided in the attribute 'type' of the tag 'input')
+
+ bool error;
+ unsigned int i;
+ unsigned int sizeVec = bbGetInputIn0().size();
+ double tmpResult;
+ std::vector<double> resultVec;
+ std::vector<double> _v0=bbGetInputIn0();
+ std::vector<double> _v1=bbGetInputIn1();
+ std::vector<double> _v2=bbGetInputIn2();
+ std::vector<double> _v3=bbGetInputIn3();
+ std::vector<double> _v4=bbGetInputIn4();
+ std::vector<double> _v5=bbGetInputIn5();
+ std::vector<double> _v6=bbGetInputIn6();
+ std::vector<double> _v7=bbGetInputIn7();
+ std::vector<double> _v8=bbGetInputIn8();
+ std::vector<double> _v9=bbGetInputIn9();
+
+ std::vector<double> *v0 = &_v0;
+ std::vector<double> *v1 = &_v1;
+ std::vector<double> *v2 = &_v2;
+ std::vector<double> *v3 = &_v3;
+ std::vector<double> *v4 = &_v4;
+ std::vector<double> *v5 = &_v5;
+ std::vector<double> *v6 = &_v6;
+ std::vector<double> *v7 = &_v7;
+ std::vector<double> *v8 = &_v8;
+ std::vector<double> *v9 = &_v9;
+
+ double minTmp;
+ double maxTmp;
+
+ if (firsttime==true)
+ {
+ firsttime=false;
+ /* initialize random seed: */
+ srand (time(NULL));
+ if (bbGetInputType()==7)
+ {
+ for (i=0;i<sizeVec;i++)
+ {
+ acum.push_back(bbGetInputIn0()[i]);
+ } // for
+ } // if 7
+ } // if firsttime
+
+
+ if (bbGetInputType()==0)
+ {
+ for (i=0;i<sizeVec;i++)
+ {
+ tmpResult = g(v0,i,0) + g(v1,i,0) + g(v2,i,0) + g(v3,i,0) +
+ g(v4,i,0) + g(v5,i,0) + g(v6,i,0) +
+ g(v7,i,0) + g(v8,i,0) + g(v9,i,0) ;
+ resultVec.push_back( tmpResult );
+ } // for i
+ bbSetOutputOut( resultVec );
+ } // if Type 0
+
+ if (bbGetInputType()==-99)
+ {
+ SumVector(v0,&resultVec);
+ SumVector(v1,&resultVec);
+ SumVector(v2,&resultVec);
+ SumVector(v3,&resultVec);
+ SumVector(v4,&resultVec);
+ SumVector(v5,&resultVec);
+ SumVector(v6,&resultVec);
+ SumVector(v7,&resultVec);
+ SumVector(v8,&resultVec);
+ SumVector(v9,&resultVec);
+
+ bbSetOutputOut( resultVec );
+ } // if Type -99
+
+
+
+ if (bbGetInputType()==1)
+ {
+ for (i=0;i<sizeVec;i++)
+ {
+ tmpResult = g(v0,i,0) - g(v1,i,0) - g(v2,i,0) - g(v3,i,0) -
+ g(v4,i,0) - g(v5,i,0) - g(v6,i,0) -
+ g(v7,i,0) - g(v8,i,0) - g(v9,i,0) ;
+ resultVec.push_back( tmpResult );
+ } // for i
+ bbSetOutputOut( resultVec );
+ } // if Type 1
+
+
+ if (bbGetInputType()==2)
+ {
+ for (i=0;i<sizeVec;i++)
+ {
+ tmpResult = g(v0,i,0) * g(v1,i,1) * g(v2,i,1) * g(v3,i,1) *
+ g(v4,i,1) * g(v5,i,1) * g(v6,i,1) *
+ g(v7,i,1) * g(v8,i,1) * g(v9,i,1) ;
+ resultVec.push_back( tmpResult );
+ } // for i
+ bbSetOutputOut( resultVec );
+ } // if Type 2
+
+
+
+ if (bbGetInputType()==3)
+ {
+ error = false;
+ for (i=0;i<sizeVec;i++)
+ {
+ if (g(v1,i,1)!=0) tmpResult = g(v0,i,0) / g(v1,i,1); else error=true;
+ if (g(v2,i,1)!=0) tmpResult = tmpResult / g(v2,i,1); else error=true;
+ if (g(v3,i,1)!=0) tmpResult = tmpResult / g(v3,i,1); else error=true;
+ if (g(v4,i,1)!=0) tmpResult = tmpResult / g(v4,i,1); else error=true;
+ if (g(v5,i,1)!=0) tmpResult = tmpResult / g(v5,i,1); else error=true;
+ if (g(v6,i,1)!=0) tmpResult = tmpResult / g(v6,i,1); else error=true;
+ if (g(v7,i,1)!=0) tmpResult = tmpResult / g(v7,i,1); else error=true;
+ if (g(v8,i,1)!=0) tmpResult = tmpResult / g(v8,i,1); else error=true;
+ if (g(v9,i,1)!=0) tmpResult = tmpResult / g(v9,i,1); else error=true;
+ if (error==true) tmpResult = 99999;
+ resultVec.push_back( tmpResult );
+ } // for i
+ bbSetOutputOut( resultVec );
+ } // if Type 3
+
+
+ if (bbGetInputType()==4)
+ {
+ for (i=0;i<sizeVec;i++)
+ {
+ if (bbGetInputIn0()[i]>=0) tmpResult = sqrt( bbGetInputIn0()[i] ) ;
+ else tmpResult = 0 ;
+ resultVec.push_back( tmpResult );
+ } // for i
+ bbSetOutputOut( resultVec );
+ } // if Type 4
+
+
+ if (bbGetInputType()==5)
+ {
+ for (i=0;i<sizeVec;i++)
+ {
+ if (bbGetInputIn0()[i]>0) tmpResult = log( bbGetInputIn0()[i] ) ;
+ else tmpResult = -99999 ;
+ resultVec.push_back( tmpResult );
+ } // for i
+ bbSetOutputOut( resultVec );
+ } // if Type 5
+
+
+
+ if (bbGetInputType()==6)
+ {
+ for (i=0;i<sizeVec;i++)
+ {
+ resultVec.push_back( exp( bbGetInputIn0()[i] ) );
+ } // for i
+ bbSetOutputOut( resultVec );
+ } // Type 6
+
+
+ if (bbGetInputType()==7)
+ {
+ bbSetOutputOut( acum );
+ for (i=0;i<sizeVec;i++)
+ {
+ acum[i]++;
+ if (acum[i]>g(v1,i,0)) acum[i]=g(v0,i,0);
+ } // for
+ } // if Type 7
+
+ if (bbGetInputType()==8 )
+ {
+ for (i=0;i<sizeVec;i++)
+ {
+ resultVec.push_back( rand() % (int)( g(v1,i,0)-g(v0,i,0) ) + g(v0,i,0) );
+ } // for i
+ bbSetOutputOut( resultVec );
+ } // Type 8
+
+ if (bbGetInputType()==9)
+ {
+ for (i=0;i<sizeVec;i++)
+ {
+ resultVec.push_back( sin( bbGetInputIn0()[i] ) );
+ } // for i
+ bbSetOutputOut( resultVec );
+ } // Type 9
+
+ if (bbGetInputType()==10)
+ {
+ for (i=0;i<sizeVec;i++)
+ {
+ resultVec.push_back( cos( bbGetInputIn0()[i] ) );
+ } // for i
+ bbSetOutputOut( resultVec );
+ } // Type 10
+
+ if (bbGetInputType()==11)
+ {
+ for (i=0;i<sizeVec;i++)
+ {
+ resultVec.push_back( tan( bbGetInputIn0()[i] ) );
+ } // for i
+ bbSetOutputOut( resultVec );
+ } // Type 11
+
+ if (bbGetInputType()==12)
+ {
+ for (i=0;i<sizeVec;i++)
+ {
+ resultVec.push_back( asin( bbGetInputIn0()[i] ) );
+ } // for i
+ bbSetOutputOut( resultVec );
+ } // Type 12
+
+ if (bbGetInputType()==13)
+ {
+ for (i=0;i<sizeVec;i++)
+ {
+ resultVec.push_back( acos( bbGetInputIn0()[i] ) );
+ } // for i
+ bbSetOutputOut( resultVec );
+ } // Type 13
+
+ if (bbGetInputType()==14)
+ {
+ for (i=0;i<sizeVec;i++)
+ {
+ resultVec.push_back( atan( bbGetInputIn0()[i] ) );
+ } // for i
+ bbSetOutputOut( resultVec );
+ } // Type 14
+
+ if (bbGetInputType()==15)
+ {
+ for (i=0;i<sizeVec;i++)
+ {
+ resultVec.push_back( atan2( g(v0,i,0) , g(v1,i,0) ) );
+ } // for i
+ bbSetOutputOut( resultVec );
+ } // Type 15
+
+
+ if (bbGetInputType()==16)
+ {
+ for (i=0;i<sizeVec;i++)
+ {
+ minTmp = fmin( g(v0,i,999999) , g(v1,i,999999) );
+ minTmp = fmin( g(v2,i,999999) , minTmp );
+ minTmp = fmin( g(v3,i,999999) , minTmp );
+ minTmp = fmin( g(v4,i,999999) , minTmp );
+ minTmp = fmin( g(v5,i,999999) , minTmp );
+ minTmp = fmin( g(v6,i,999999) , minTmp );
+ minTmp = fmin( g(v7,i,999999) , minTmp );
+ minTmp = fmin( g(v8,i,999999) , minTmp );
+ minTmp = fmin( g(v9,i,999999) , minTmp );
+ resultVec.push_back( minTmp );
+ } // for i
+ bbSetOutputOut( resultVec );
+ } // Type 16
+
+ if (bbGetInputType()==-16)
+ {
+ MinVector(v0,&resultVec);
+ MinVector(v1,&resultVec);
+ MinVector(v2,&resultVec);
+ MinVector(v3,&resultVec);
+ MinVector(v4,&resultVec);
+ MinVector(v5,&resultVec);
+ MinVector(v6,&resultVec);
+ MinVector(v7,&resultVec);
+ MinVector(v8,&resultVec);
+ MinVector(v9,&resultVec);
+
+ bbSetOutputOut( resultVec );
+ } // Type -16
+
+ if (bbGetInputType()==17)
+ {
+ for (i=0;i<sizeVec;i++)
+ {
+ maxTmp = fmax( g(v0,i,-999999) , g(v1,i,-999999) );
+ maxTmp = fmax( g(v2,i,-999999) , maxTmp );
+ maxTmp = fmax( g(v3,i,-999999) , maxTmp );
+ maxTmp = fmax( g(v4,i,-999999) , maxTmp );
+ maxTmp = fmax( g(v5,i,-999999) , maxTmp );
+ maxTmp = fmax( g(v6,i,-999999) , maxTmp );
+ maxTmp = fmax( g(v7,i,-999999) , maxTmp );
+ maxTmp = fmax( g(v8,i,-999999) , maxTmp );
+ maxTmp = fmax( g(v9,i,-999999) , maxTmp );
+ resultVec.push_back( maxTmp );
+ } // for i
+ bbSetOutputOut( resultVec );
+ } // Type 17
+
+
+ if (bbGetInputType()==-17)
+ {
+ MaxVector(v0,&resultVec);
+ MaxVector(v1,&resultVec);
+ MaxVector(v2,&resultVec);
+ MaxVector(v3,&resultVec);
+ MaxVector(v4,&resultVec);
+ MaxVector(v5,&resultVec);
+ MaxVector(v6,&resultVec);
+ MaxVector(v7,&resultVec);
+ MaxVector(v8,&resultVec);
+ MaxVector(v9,&resultVec);
+ bbSetOutputOut( resultVec );
+ } // Type -17
+
+
+ if (bbGetInputType()==18)
+ {
+ for (i=0;i<sizeVec;i++)
+ {
+ resultVec.push_back( fabs( bbGetInputIn0()[i] ) );
+ } // for i
+ bbSetOutputOut( resultVec );
+ } // Type 18
+
+
+}
+
+//=====
+// 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)
+//=====
+void MathOperationVector::bbUserSetDefaultValues()
+{
+
+// SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
+// Here we initialize the input 'In' to 0
+
+ bbSetInputType(0);
+ firsttime=true;
+
+
+}
+//=====
+// 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)
+//=====
+void MathOperationVector::bbUserInitializeProcessing()
+{
+
+// THE INITIALIZATION METHOD BODY :
+// Here does nothing
+// but this is where you should allocate the internal/output pointers
+// if any
+
+
+}
+//=====
+// 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)
+//=====
+void MathOperationVector::bbUserFinalizeProcessing()
+{
+
+// THE FINALIZATION METHOD BODY :
+// Here does nothing
+// but this is where you should desallocate the internal/output pointers
+// if any
+
+}
+}
+// EO namespace bbstd
+
+