RealMatrixSparse HyperbolicEquationUpwindRHSFunction::evaldFdY(Real time, RealVector& y,IntegerVector& ref){ // this is not the exact Jacobian! Integer y_size = y.size(); Integer elem_ref = ref.sum(); RealMatrixSparse J(elem_ref,elem_ref); Integer col = 0; Real epsi = 1.e-3; Real iepsi = 1.0 / 1.e-3; RealVector F = evalF(time,y,ref); for (Integer j = 0; j < y_size; ++j){ if(ref(j) == 1){ RealVector yd = y; yd(j) = yd(j) + epsi; RealVector Fd = evalF(time,yd,ref); for(Integer i=0; i< Fd.size(); i++){ J.insert(i,col) = (Fd[i] - F[i]) * iepsi; } col = col + 1; } } return J; }
void Peer::evalJ(const double& t, const double* y, double* T, IContinuous *continuousSystem, ITime *timeSystem, double factor) { double* f=new double[_dimSys]; double* fh=new double[_dimSys]; double* z=new double[_dimSys]; std::copy(y,y+_dimSys,z); evalF(t, z, f, continuousSystem, timeSystem); for(int j=0; j<_dimSys; ++j) { // reset m_pYhelp for every colum z[j] += 1e-8; // delta_f berechnen evalF(t, z, fh, continuousSystem, timeSystem); // Jacobimatrix aufbauen for(int i=0; i<_dimSys; ++i) { T[i+j*_dimSys] = factor*(fh[i] - f[i]) / 1e-8; } z[j] -= 1e-8; } delete [] f; delete [] fh; delete [] z; }
RealMatrixSparse HyperbolicEquationUpwindRHSFunction::evaldFdY(Real time, RealVector& y){ /// /// this is not the exact Jacobian! /// Integer y_size = y.size(); RealMatrixSparse J(y_size,y_size); Integer col = 0; Real epsi = 1.e-3; Real iepsi = 1.0 / 1.e-3; RealVector F = evalF(time,y); for (Integer j = 0; j < y_size; ++j){ RealVector yd = y; yd(j) = yd(j) + epsi; RealVector Fd = evalF(time,yd); for(Integer i=0; i< Fd.size(); i++){ J.insert(i,col) = (Fd[i] - F[i]) * iepsi; } col = col + 1; } return J; }
void Peer::ros2(double * y, double& tstart, double tend, IContinuous *continuousSystem, ITime *timeSystem) { double *T=new double[_dimSys*_dimSys]; double *D=new double[_dimSys]; double *k1=new double[_dimSys]; double *k2=new double[_dimSys]; long int *P=new long int[_dimSys]; long int info; long int dim=1; double t=tstart; const double gamma=1.-sqrt(2.)/2.; char trans='N'; double hu=(tend-tstart)/10.; for(int count=0; count<10; ++count) { evalJ(t,y,T,continuousSystem, timeSystem,-hu*gamma); for(int i=0; i<_dimSys;++ i) T[i*_dimSys+i]+=1.; dgetrf_(&_dimSys, &_dimSys, T, &_dimSys, P, &info); evalF(t,y,k1,continuousSystem, timeSystem); evalD(t,y,D,continuousSystem, timeSystem); for(int i=0; i<_dimSys;++ i) k1[i]+=gamma*hu*D[i]; dgetrs_(&trans, &_dimSys, &dim, T, &_dimSys, P, k1, &_dimSys, &info); for(int i=0; i<_dimSys;++ i) y[i]+=hu*k1[i]; evalF(t,y,k2,continuousSystem, timeSystem); for(int i=0; i<_dimSys;++ i) k2[i]+= hu*gamma*D[i]-2.*k1[i]; dgetrs_(&trans, &_dimSys, &dim, T, &_dimSys, P, k2, &_dimSys, &info); for(int i=0; i<_dimSys;++ i) y[i]+=0.5*hu*(k1[i]+k2[i]); } }
void Peer::evalD(const double& t, const double* y, double* T, IContinuous *continuousSystem, ITime *timeSystem) { double* f=new double[_dimSys]; double* fh=new double[_dimSys]; evalF(t, y, f, continuousSystem, timeSystem); evalF(t+1e-6,y,fh,continuousSystem, timeSystem); for(int j=0; j<_dimSys; ++j) { T[j] = (fh[j] - f[j]) / 1e-6; } delete [] f; delete [] fh; }
real NLF1::evalLagrangian(const ColumnVector& xc , ColumnVector& multiplier, const ColumnVector& type) { real result = evalF(xc); if( hasConstraints()){ ColumnVector resid = constraint_->evalResidual(xc); result -= Dot(resid, multiplier); } return result; }
uint8_t readB(){ switch (type){ case A_BYTE: return evalB(); case A_UINT: return evalU(); case A_INT: return evalI(); case A_LONG: return evalL(); case A_FLOAT: return evalF(); case A_DOUBLE: return evalD(); case A_TIME: return evalT(); default: return 0; } return 0; }
uint32_t readT(){ switch (type){ case A_BYTE: return evalB(); case A_UINT: return evalU(); case A_INT: return evalI(); case A_LONG: return evalL(); case A_FLOAT: return evalF(); case A_DOUBLE: return evalD(); case A_TIME: return evalT(); case A_STRING: return 0; case BAD_TYPE: return 0; } return 0; }
HlExprList *HlExprList::simp_tan() { switch (First()->typeOfHead()) { case NUMBER: if (eval_functions) { changed = true; double v = evalF(); delete this; return N(v); } break; default: break; } return this; }
HlExprList *HlExprList::simp_sqrt() { HlExprList *q; switch (First()->typeOfHead()) { case NUMBER: if (eval_functions) { changed = true; double v = evalF(); delete this; return N(v); } default: changed = true; q = C(N(POWER), N(First()), N(0.5)); delete this; return q; break; } return this; }
void Peer::solve(const SOLVERCALL action) { if ((action & RECORDCALL) && (action & FIRST_CALL)) { initialize(); return; } double t=_tCurrent; // Initialization phase _continuous_system[0]->evaluateAll(IContinuous::ALL); SolverDefaultImplementation::writeToFile(0, t, _h); #ifdef MPIPEER std::copy(_y,_y+_dimSys,_Y1); if (abs(_c[_rank]+1.)>1e-12) { ros2(_Y1,_tCurrent,_tCurrent+_h*(_c[_rank]+1.)); t=_tCurrent; } MPI_Barrier(MPI_COMM_WORLD); if(_rank==0) { MPI_Gather(MPI_IN_PLACE,_dimSys,MPI_DOUBLE,_Y1,_dimSys,MPI_DOUBLE,0,MPI_COMM_WORLD); } else { MPI_Gather(_Y1,_dimSys,MPI_DOUBLE,_Y1,_dimSys,MPI_DOUBLE,0,MPI_COMM_WORLD); } t+=_h; #else #pragma omp parallel for for(int _rank=0; _rank<5; ++_rank) { std::copy(_y,_y+_dimSys,&_Y1[_rank*_dimSys]); if (abs(_c[_rank]+1.)>1e-12) { ros2(&_Y1[_rank*_dimSys],_tCurrent,_tCurrent+_h*(_c[_rank]+1.), _continuous_system[_rank], _time_system[_rank]); t=_tCurrent; } } t+=_h; _time_system[0]->setTime(t); _continuous_system[0]->setContinuousStates(&_Y1[2*_dimSys]); _continuous_system[0]->evaluateAll(IContinuous::ALL); SolverDefaultImplementation::writeToFile(0, t, _h); #endif // std::cerr << "Finished init at rank " << _rank<<std::endl; // Solution phase t+=_h; char trans='N'; long int dim=1; while(std::abs(t-_tEnd)>1e-8) { #ifdef MPIPEER if(_rank==0) { for(int i=0; i<_rstages; ++i) { for(int j=0; j<_dimSys; ++j) { _Y2[i*_dimSys+j]=0.; for(int k=0; k<_rstages;++k) { _Y2[i*_dimSys+j]+=_Y1[k*_dimSys+j]*_Theta[i*_rstages+k]; } } // Y2.vector(i)=Y1*mtl::vector::trans(Theta[i][iall]); } std::cout<<"_Y2 vals on rank "<<_rank<<": "; for(int i=0; i<_rstages*_dimSys;++i) { if(!(i%20)) std::cout<<std::endl; std::cout<<_Y2[i]<<" "; } std::cout<<std::endl; for(int i=0; i<_rstages; i++) { for(int j=0; j<_dimSys; ++j) { _Y3[i*_dimSys+j]=0.; for(int k=0; k<_rstages;++k) { _Y3[i*_dimSys+j]+=_Y2[k*_dimSys+j]*_E[i*_rstages+k]; } } // Y3.vector(i)=Y2*mtl::vector::trans(E[i][iall]); } } MPI_Barrier(MPI_COMM_WORLD); // std::cerr << "Finished rank 0 calculation step at rank " << _rank<<std::endl; if(_rank==0) { MPI_Scatter( _Y2,_dimSys,MPI_DOUBLE,MPI_IN_PLACE,_dimSys,MPI_DOUBLE,0,MPI_COMM_WORLD); MPI_Scatter( _Y3,_dimSys,MPI_DOUBLE,MPI_IN_PLACE,_dimSys,MPI_DOUBLE,0,MPI_COMM_WORLD); } else { MPI_Scatter(_Y2,_dimSys,MPI_DOUBLE,_Y2,_dimSys,MPI_DOUBLE,0,MPI_COMM_WORLD); MPI_Scatter(_Y3,_dimSys,MPI_DOUBLE,_Y3,_dimSys,MPI_DOUBLE,0,MPI_COMM_WORLD); } evalF(t+_c[_rank]*_h,_Y2,_F); evalJ(t+_c[_rank]*_h,_Y2,_T); if(_rank==0) { std::cout<<"Jac: "; for(int i(0); i<_dimSys*_dimSys;++i) { if(!(i%20)) std::cout<<std::endl; std::cout<<_T[i]<<" "; } std::cout<<std::endl; } for(int i=0; i<_dimSys; ++i) { for(int j=0; j<_dimSys; ++j) { _T[i*_dimSys+j]*=-_h*_G[_rank]; } _T[i*_dimSys+i]+=1.; } // std::cerr << "Finished iteration matrix calculation step at rank " << _rank<<std::endl; dgetrf_(&_dimSys, &_dimSys, _T, &_dimSys, _P, &info); for(int i=0; i<_dimSys; ++i) { _F[i]*=_h; _F[i]-=_Y3[i]; _F[i]*=_G[_rank]; } dgetrs_(&trans, &_dimSys, &dim, _T, &_dimSys, _P, _F, &_dimSys, &info); for(int i=0; i<_dimSys; ++i) { _Y1[i]=_F[i]+_Y2[i]; } MPI_Barrier(MPI_COMM_WORLD); if(_rank==0) { MPI_Gather(MPI_IN_PLACE,_dimSys,MPI_DOUBLE,_Y1,_dimSys,MPI_DOUBLE,0,MPI_COMM_WORLD); } else { MPI_Gather(_Y1,_dimSys,MPI_DOUBLE,_Y1,_dimSys,MPI_DOUBLE,0,MPI_COMM_WORLD); } if(t+_h>_tEnd) _h=_tEnd-t; if(_rank==0) { SolverDefaultImplementation::writeToFile(0, t, _h); } t+=_h; #else for(int i=0; i<_rstages; ++i) { for(int j=0; j<_dimSys; ++j) { _Y2[i*_dimSys+j]=0.; for(int k=0; k<_rstages;++k) { _Y2[i*_dimSys+j]+=_Y1[k*_dimSys+j]*_Theta[i*_rstages+k]; } } // Y2.vector(i)=Y1*mtl::vector::trans(Theta[i][iall]); } for(int i=0; i<_rstages; i++) { for(int j=0; j<_dimSys; ++j) { _Y3[i*_dimSys+j]=0.; for(int k=0; k<_rstages;++k) { _Y3[i*_dimSys+j]+=_Y2[k*_dimSys+j]*_E[i*_rstages+k]; } } // Y3.vector(i)=Y2*mtl::vector::trans(E[i][iall]); } #pragma omp parallel for for(int _rank=0; _rank<5; ++_rank) { long int info; evalF(t+_c[_rank]*_h,&_Y2[_rank*_dimSys],&_F[_rank*_dimSys],_continuous_system[_rank], _time_system[_rank]); evalJ(t+_c[_rank]*_h,&_Y2[_rank*_dimSys],&_T[_rank*_dimSys*_dimSys], _continuous_system[_rank], _time_system[_rank]); for(int i=0; i<_dimSys; ++i) { for(int j=0; j<_dimSys; ++j) { _T[_rank*_dimSys*_dimSys+i*_dimSys+j]*=-_h*_G[_rank]; } _T[_rank*_dimSys*_dimSys+i*_dimSys+i]+=1.; } // std::cerr << "Finished iteration matrix calculation step at rank " << _rank<<std::endl; dgetrf_(&_dimSys, &_dimSys, &_T[_rank*_dimSys*_dimSys], &_dimSys, &_P[_rank*_dimSys], &info); for(int i=0; i<_dimSys; ++i) { _F[_rank*_dimSys+i]*=_h; _F[_rank*_dimSys+i]-=_Y3[_rank*_dimSys+i]; _F[_rank*_dimSys+i]*=_G[_rank]; } dgetrs_(&trans, &_dimSys, &dim, &_T[_rank*_dimSys*_dimSys], &_dimSys, &_P[_rank*_dimSys], &_F[_rank*_dimSys], &_dimSys, &info); for(int i=0; i<_dimSys; ++i) { _Y1[_rank*_dimSys+i]=_F[_rank*_dimSys+i]+_Y2[_rank*_dimSys+i]; } } if(t+_h>_tEnd) _h=_tEnd-t; _time_system[0]->setTime(t); _continuous_system[0]->setContinuousStates(&_Y1[2*_dimSys]); _continuous_system[0]->evaluateAll(IContinuous::ALL); SolverDefaultImplementation::writeToFile(0, t, _h); t+=_h; #endif } #ifdef MPIPEER MPI_Barrier(MPI_COMM_WORLD); if(_rank==0) { for(int i=0; i<_dimSys; i++) _y[i]=_Y1[(_rstages-1)*_dimSys+i]; } MPI_Bcast(_y, _dimSys, MPI_DOUBLE, 0, MPI_COMM_WORLD); #else for(int i=0; i<_dimSys; i++) _y[i]=_Y1[(_rstages-1)*_dimSys+i]; #endif _tCurrent=_tEnd; _time_system[0]->setTime(_tCurrent); _continuous_system[0]->setContinuousStates(&_Y1[4*_dimSys]); _continuous_system[0]->evaluateAll(IContinuous::ALL); SolverDefaultImplementation::writeToFile(0, t, _h); _solverStatus = ISolver::DONE; }
int main(int argc, char** argv) { //VL_PRINT ("Hello world!") ; try { TCLAP::CmdLine cmd("EmbAttSpotter tester", ' ', "0.1"); TCLAP::SwitchArg evalF("e","eval","Evaluate against dataset", cmd, false); TCLAP::SwitchArg evalSubF("s","evalSubwordSpotting","Evaluate subword spotting results", cmd, false); TCLAP::SwitchArg evalSubCombF("a","evalSubwordSpottingCombine","Evaluate subword spotting results when combining exemplars", cmd, false); TCLAP::ValueArg<int> primeSubwordArg("p","primeSubword","save the cca att for the given string length", false, -1,"int"); cmd.add( primeSubwordArg ); TCLAP::ValueArg<string> modelArg("l","location","load/save prefix", false,"model/evalGW","string"); cmd.add( modelArg ); TCLAP::SwitchArg testF("t","test","Run unit tests", cmd, false); TCLAP::ValueArg<int> imageArg("i","image","show visual result", false,-1,"int"); cmd.add( imageArg ); TCLAP::ValueArg<int> image2Arg("c","image2","compare images", false,-1,"int"); cmd.add( image2Arg ); TCLAP::ValueArg<string> compare1Arg("1","compare1","1st image for comparison", false,"","string"); cmd.add( compare1Arg ); TCLAP::ValueArg<string> compare2Arg("2","compare2","2nd image for comparison", false,"","string"); cmd.add( compare2Arg ); TCLAP::SwitchArg retrainAttReprTrF("6","attReprTr","Retrain attReprTr", cmd, false); TCLAP::SwitchArg retrainEmbeddingF("5","embedding","Retrain embedding", cmd, false); TCLAP::ValueArg<string> trainFileArg("9","trainfile","training file: *.gtp for 'docimagefile lx ty rx by gt', *.txt for 'imagefile gt'", false,"test/queries_train.gtp","string"); cmd.add( trainFileArg ); TCLAP::ValueArg<string> testFileArg("8","testfile","testing file: *.gtp for 'docimagefile lx ty rx by gt', *.txt for 'imagefile gt'", false,"test/queries_test.gtp","string"); cmd.add( testFileArg ); TCLAP::ValueArg<string> exemplarFileArg("7","exemplars","exemplar file: *.gtp for 'docimagefile lx ty rx by gt', *.txt for 'imagefile gt'", false,"test/exemplars.txt","string"); cmd.add( exemplarFileArg ); //TCLAP::ValueArg<string> exemplarLocArg("7","exemplar_locations","exemplar locations file", false,"test/exemplars.txt","string"); //cmd.add( exemplarLocArg ); TCLAP::ValueArg<string> imageDirArg("d","images","directory containing images", false,"/home/brian/intel_index/brian_handwriting/EmbeddedAtt_Almazan/datasets/GW/images/","string"); cmd.add( imageDirArg ); TCLAP::ValueArg<string> exemplarDirArg("x","exemplarsDir","directory containing exemplar images", false,"/home/brian/intel_index/data/gw_20p_wannot/bigrams_clean_deslant/","string"); cmd.add( exemplarDirArg ); TCLAP::ValueArg<string> fullFileArg("f","full","do a full sliding window subword spotting on this image", false,"","string"); cmd.add( fullFileArg ); TCLAP::ValueArg<float> hyarg("y","hybridalpha","hybrid alpha, 0 text only, 1 image only", false,-1,"float"); cmd.add( hyarg ); TCLAP::ValueArg<string> charSegCSVArg("3","charSeg","char seg csv file: 'word,pageId,x1,y1,x2,y2,char1start,char1end,char2start,...'", false,"","string"); cmd.add( charSegCSVArg ); cmd.parse( argc, argv ); if ( testF.getValue() ) { EmbAttSpotter spotter("testing",false,true,1); spotter.test(); } if ( evalF.getValue() ) { EmbAttSpotter spotter(modelArg.getValue()); GWDataset train(trainFileArg.getValue(),imageDirArg.getValue()); GWDataset test(testFileArg.getValue(),imageDirArg.getValue()); spotter.setTraining_dataset(&train); if ( retrainAttReprTrF.getValue() ) spotter.attReprTr(true); if ( retrainEmbeddingF.getValue() ) spotter.embedding(true); spotter.eval(&test); } if (primeSubwordArg.getValue()>=0) { EmbAttSpotter spotter(modelArg.getValue()); GWDataset train(trainFileArg.getValue(),imageDirArg.getValue()); GWDataset test(testFileArg.getValue(),imageDirArg.getValue()); spotter.setTraining_dataset(&train); spotter.setCorpus_dataset(&test); spotter.primeSubwordSpotting(primeSubwordArg.getValue()); } if ( evalSubF.getValue() || evalSubCombF.getValue()) { EmbAttSpotter spotter(modelArg.getValue()); GWDataset train(trainFileArg.getValue(),imageDirArg.getValue()); GWDataset test(testFileArg.getValue(),imageDirArg.getValue()); GWDataset exemplars(exemplarFileArg.getValue(),exemplarDirArg.getValue()); spotter.setTraining_dataset(&train); if ( retrainAttReprTrF.getValue() ) spotter.attReprTr(true); if ( retrainEmbeddingF.getValue() ) spotter.embedding(true); if (charSegCSVArg.getValue().length()>0) { vector< vector<int> > corpusXLetterStartBoundsRel; vector< vector<int> > corpusXLetterEndBoundsRel; ifstream in (charSegCSVArg.getValue()); string line; //getline(in,line);//header while (getline(in,line)) { string s; std::stringstream ss(line); getline(ss,s,','); getline(ss,s,','); getline(ss,s,',');//x1 int x1=stoi(s); getline(ss,s,','); getline(ss,s,',');//x2 getline(ss,s,','); vector<int> lettersStartRel, lettersEndRel; while (getline(ss,s,',')) { lettersStartRel.push_back(stoi(s)-x1); getline(ss,s,','); lettersEndRel.push_back(stoi(s)-x1); //getline(ss,s,',');//conf } corpusXLetterStartBoundsRel.push_back(lettersStartRel); corpusXLetterEndBoundsRel.push_back(lettersEndRel); } in.close(); spotter.evalSubwordSpottingWithCharBounds(&exemplars, &test, &corpusXLetterStartBoundsRel, &corpusXLetterEndBoundsRel, hyarg.getValue()); } else if ( evalSubF.getValue() ) spotter.evalSubwordSpotting(&exemplars, &test, hyarg.getValue()); else spotter.evalSubwordSpottingCombine(&exemplars, &test, hyarg.getValue()); } if ( imageArg.getValue()>=0 ) { EmbAttSpotter spotter(modelArg.getValue()); GWDataset train(trainFileArg.getValue(),imageDirArg.getValue()); GWDataset test(testFileArg.getValue(),imageDirArg.getValue()); spotter.setTraining_dataset(&train); spotter.setCorpus_dataset(&test); int ex=imageArg.getValue(); if ( image2Arg.getValue()>=0 ) { int ex2= image2Arg.getValue(); double score = spotter.compare(test.image(ex),test.image(ex2)); cout <<"score: "<<score<<endl; } else { cout <<"test word "<<test.labels()[ex]<<endl; imshow("test word",test.image(ex)); vector<float> scores = spotter.spot(test.image(ex), "", 1); multimap<float, int> ranked; for (int i=0; i<scores.size(); i++) ranked.emplace(scores[i],i); auto iter = ranked.end(); for (int i=1; i<=5; i++) { iter--; cout<<"I rank "<<i<<" is "<<iter->second<<" with score "<<iter->first<<endl; imshow("I "+to_string(i),test.image(iter->second)); } scores = spotter.spot(test.image(ex), test.labels()[ex], 0); ranked.clear(); for (int i=0; i<scores.size(); i++) ranked.emplace(scores[i],i); iter = ranked.end(); for (int i=1; i<=5; i++) { iter--; cout<<"T rank "<<i<<" is "<<iter->second<<" with score "<<iter->first<<endl; imshow("T "+to_string(i),test.image(iter->second)); } waitKey(); } } if (compare1Arg.getValue().length()>0 && compare2Arg.getValue().length()>0) { EmbAttSpotter spotter(modelArg.getValue()); Mat im1 = imread(compare1Arg.getValue(),CV_LOAD_IMAGE_GRAYSCALE); Mat im2 = imread(compare2Arg.getValue(),CV_LOAD_IMAGE_GRAYSCALE); //im1 = GWDataset::preprocess(im1); //im2 = GWDataset::preprocess(im2); cout<<spotter.compare(im1,im2)<<endl;; } if (fullFileArg.getValue().length()>0) { assert(compare1Arg.getValue().length()>0); EmbAttSpotter spotter(modelArg.getValue()); StrideDataset im(fullFileArg.getValue()); spotter.setCorpus_dataset_fullSub(&im); Mat ex = imread(compare1Arg.getValue(),CV_LOAD_IMAGE_GRAYSCALE); clock_t start = clock(); time_t start2 = time(0); vector< SubwordSpottingResult > res = spotter.subwordSpot_full(ex,"",1); clock_t end = clock(); time_t end2 = time(0); double time = (double) (end-start) / CLOCKS_PER_SEC; double time2 = difftime(end2, start2) * 1000.0; cout<<"Took "<<time<<" secs."<<endl; cout<<"Took "<<time2<<" secs."<<endl; Mat img = imread(fullFileArg.getValue()); Mat orig = img.clone(); int top=100; float maxS = res[0].score; float minS = res[top].score; for (int i=0; i<top; i++) { float s = 1-((res[i].score-minS)/(maxS-minS)); //cout <<res[i].score<<": "<<s<<endl; for (int x=res[i].startX; x<=res[i].endX; x++) for (int y=res[i].imIdx*3; y<res[i].imIdx*3 +65; y++) { Vec3b& p = img.at<Vec3b>(y,x); Vec3b o = orig.at<Vec3b>(y,x); p[0] = min(p[0],(unsigned char)(o[0]*s)); } } imwrite("spotting.png",img); imshow("spotting",img); waitKey(); } } catch (TCLAP::ArgException &e) // catch any exceptions { std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl; } }
double area(double a, double h) { return (evalF(a) + evalF(a + h)) * h / 2; }
// virtual void CLsodaMethod::stateChanged() { if (!mNoODE && mLsodaStatus != 1) { // Compare the independent state variables // This an be done directly by comparing mMethodState and *mpCurrentState C_FLOAT64 *pMethod = mY; C_FLOAT64 *pMethodEnd = pMethod + mData.dim; C_FLOAT64 *pCurrent = mpCurrentState->beginIndependent(); for (; pMethod != pMethodEnd; ++pMethod, ++pCurrent) { // We may need to use the absolute and relative tolerance if (*pMethod != *pCurrent) { mLsodaStatus = 1; mMethodState = *mpCurrentState; mTime = mMethodState.getTime(); break; } } if (mLsodaStatus != 1) { // Compare the rates of the independent state variables // we need to call evalF for mMethodState and *mpCurrentState and compare the returned rates. CVector< C_FLOAT64 > MethodRate(mData.dim); CVector< C_FLOAT64 > CurrentRate(mData.dim); evalF(&mTime, mY, MethodRate.array()); mMethodState = *mpCurrentState; mTime = mMethodState.getTime(); evalF(&mTime, mY, CurrentRate.array()); pMethod = MethodRate.array(); pMethodEnd = pMethod + mData.dim; pCurrent = CurrentRate.array(); for (; pMethod != pMethodEnd; ++pMethod, ++pCurrent) { // We may need to use the absolute and relative tolerance if (*pMethod != *pCurrent) { mLsodaStatus = 1; break; } } } } else { mMethodState = *mpCurrentState; mTime = mMethodState.getTime(); } destroyRootMask(); mRootMasking = NONE; }