Update of /cvsroot/pure-data/externals/tbext/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30617
Modified Files: him.cpp Log Message: hopefully a speedup
Index: him.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/tbext/source/him.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** him.cpp 9 Apr 2004 13:42:01 -0000 1.3 --- him.cpp 13 Jul 2004 20:04:52 -0000 1.4 *************** *** 63,67 **** protected: virtual void m_signal (int n, float *const *in, float *const *out); - t_float *outs;
void set_mu(t_float); --- 63,66 ---- *************** *** 78,88 **** // contains DGL-System t_float deriv(t_float x[],int eq); - t_float result;
// 4th order Runge Kutta update of the dynamical variables void runge_kutta_4(t_float dt); - int i; - t_float k1[NUMB_EQ],k2[NUMB_EQ],k3[NUMB_EQ],k4[NUMB_EQ]; - t_float temp1[NUMB_EQ], temp2[NUMB_EQ], temp3[NUMB_EQ];
//these are our data --- 77,83 ---- *************** *** 113,118 **** (data[0]*data[0]*data[0]*data[0]*data[1]*data[1]) + 16); } ! void reset_muv() { --- 108,115 ---- (data[0]*data[0]*data[0]*data[0]*data[1]*data[1]) + 16); + if (fabs((data[3]))<1e-5) + data[3]=0; } ! void reset_muv() { *************** *** 122,125 **** --- 119,124 ---- (data[0]*data[0]*data[0]*data[0]*data[1]*data[1]) + 16); + if (fabs((data[1]))<1e-5) + data[1]=0; }
*************** *** 164,170 **** }
! t_float him::deriv(t_float x[], int eq) { ! // set DGL-System here if (eq == 0) result = x[1]; if (eq == 1) result = 2*E*x[0]-0.25*x[0]*x[2]*x[2]*(2*x[0]*x[0]+x[2]*x[2]); --- 163,170 ---- }
! inline t_float him::deriv(t_float * x, int eq) { ! t_float result; ! // set DGL-System here if (eq == 0) result = x[1]; if (eq == 1) result = 2*E*x[0]-0.25*x[0]*x[2]*x[2]*(2*x[0]*x[0]+x[2]*x[2]); *************** *** 175,216 **** }
! void him::runge_kutta_4(t_float dt) { ! for(i=0;i<=NUMB_EQ-1;i++) // iterate over equations ! { ! k1[i] = dt * deriv(data,i); ! temp1[i] = data[i] + 0.5*k1[i]; ! }
! for(i=0;i<=NUMB_EQ-1;i++) ! { ! k2[i] = dt * deriv(temp1,i); ! temp2[i] = data[i] + 0.5*k2[i]; ! }
! for(i=0;i<=NUMB_EQ-1;i++) ! { ! k3[i] = dt * deriv(temp2,i); ! temp3[i] = data[i] + k3[i]; ! }
! for(i=0;i<=NUMB_EQ-1;i++) ! { ! k4[i] = dt * deriv(temp3,i); ! data[i] = data[i] + (k1[i] + (2.*(k2[i]+k3[i])) + k4[i])/6.; ! }
! /* the system might become unstable ... in this case, we'll reset the system */
! for(i=0;i<=NUMB_EQ-1;i++) if(data[i]>2) reset(); ! else ! if(PD_BADFLOAT(data[i])) //not that we get some troubles with denormals ! data[i]=0; ! }
--- 175,221 ---- }
! inline void him::runge_kutta_4(t_float dt) { ! t_float k1[NUMB_EQ],k2[NUMB_EQ],k3[NUMB_EQ],k4[NUMB_EQ]; ! t_float temp1[NUMB_EQ], temp2[NUMB_EQ], temp3[NUMB_EQ];
! for(int i=0;i<=NUMB_EQ-1;i++) // iterate over equations ! { ! k1[i] = dt * deriv(data,i); ! temp1[i] = data[i] + 0.5*k1[i]; ! }
! for(int i=0;i<=NUMB_EQ-1;i++) ! { ! k2[i] = dt * deriv(temp1,i); ! temp2[i] = data[i] + 0.5*k2[i]; ! }
! for(int i=0;i<=NUMB_EQ-1;i++) ! { ! k3[i] = dt * deriv(temp2,i); ! temp3[i] = data[i] + k3[i]; ! } ! ! for(int i=0;i<=NUMB_EQ-1;i++) ! { ! k4[i] = dt * deriv(temp3,i); ! data[i] = data[i] + (k1[i] + (2.*(k2[i]+k3[i])) + k4[i])/6.; ! ! // we don't want to experience denormals in the next step */ ! if(fabs((data[i]))<1e-5) ! data[i]=0; ! }
! /* the system might become unstable ... in this case, we'll reset the system */
! for(int i=0;i<=NUMB_EQ-1;i++) ! { if(data[i]>2) reset(); ! } }
*************** *** 219,249 **** void him::m_signal(int n, t_float *const *in, t_float *const *out) { if (regtime) { ! for (int j=0;j!=n;++j) ! { ! runge_kutta_4(dt); ! *(out[0]+j)=data[0]; ! *(out[1]+j)=data[1]; ! *(out[2]+j)=data[2]; ! *(out[3]+j)=data[3]; ! *(out[4]+j)=data[0]*data[2]; ! *(out[5]+j)=(data[0]*data[0]-data[2]*data[2])*0.5; ! } } else { ! for (int j=0;j!=n;++j) ! { ! runge_kutta_4(dt/ ! (2*sqrt(data[0]*data[0]+data[2]*data[2]))); ! *(out[0]+j)=data[0]; ! *(out[1]+j)=data[1]; ! *(out[2]+j)=data[2]; ! *(out[3]+j)=data[3]; ! *(out[4]+j)=data[0]*data[2]; ! *(out[5]+j)=(data[0]*data[0]-data[2]*data[2])*0.5; ! } } }
--- 224,261 ---- void him::m_signal(int n, t_float *const *in, t_float *const *out) { + t_float * out0 = out[0]; + t_float * out1 = out[1]; + t_float * out2 = out[2]; + t_float * out3 = out[3]; + t_float * out4 = out[4]; + t_float * out5 = out[5]; + + if (regtime) + { + for (int j=0;j!=n;++j) { ! runge_kutta_4(dt); ! (*(out0)++)=data[0]; ! (*(out1)++)=data[1]; ! (*(out2)++)=data[2]; ! (*(out3)++)=data[3]; ! (*(out4)++)=data[0]*data[2]; ! (*(out5)++)=(data[0]*data[0]-data[2]*data[2])*0.5; } + } else + { + for (int j=0;j!=n;++j) { ! runge_kutta_4(dt/(2*sqrt(data[0]*data[0]+data[2]*data[2]))); ! (*(out0)++)=data[0]; ! (*(out1)++)=data[1]; ! (*(out2)++)=data[2]; ! (*(out3)++)=data[3]; ! (*(out4)++)=data[0]*data[2]; ! (*(out5)++)=(data[0]*data[0]-data[2]*data[2])*0.5; } + } }