void CNAnalysisMethodMosaicism::runmed(double* p, int iCount, int iWindowSize) { std::vector<float>vOut(iCount); if ((iWindowSize % 2) == 0) {iWindowSize++;} // Window size should be odd. if (iCount <= iWindowSize) { iWindowSize = iCount - 2; if ((iWindowSize % 2) == 0) {iWindowSize--;} // Window size should be odd. if (iWindowSize < 0) {return;} } int iHalfWindow = (int)((double)iWindowSize/2.0); for (int iIndex = iHalfWindow; (iIndex < (iCount - iHalfWindow)); iIndex++) { vOut[iIndex] = percentile(50, (p + iIndex - iHalfWindow), iWindowSize); } for (int iIndex = (iHalfWindow - 1); (iIndex >= 0); iIndex--) { vOut[iIndex] = vOut[iIndex + 1]; } for (int iIndex = (iCount - iHalfWindow); (iIndex < iCount); iIndex++) { vOut[iIndex] = vOut[iIndex - 1]; } for (int iIndex = 0; (iIndex < iCount); iIndex++) { p[iIndex] = vOut[iIndex]; } }
void GrayScott::save_fields() { char stepString[10]; std::sprintf(stepString, "%05d_", currStep_); std::string fname(dirPath_ + stepString + "u.dat"); std::ofstream uOut(fname); fname = dirPath_ + stepString + "v.dat"; std::ofstream vOut(fname); int w = 12; for (int j=0; j<N_; ++j) { for (int i=0; i<N_; ++i) { uOut << std::setw(w) << U(i,j) << " "; vOut << std::setw(w) << V(i,j) << " "; } uOut << "\n"; vOut << "\n"; } uOut.close(); vOut.close(); }
Vector3 ETHEntity::GetVector3(const str_type::string &name) const { Vector3 vOut(0,0,0); m_properties.GetVector3(name, vOut); return vOut; }
std::vector<std::vector<float> > sortHvector2(std::vector<std::vector<float> > vIn, int sortCol) { // note: horizontal vectors like: // < <H0, F0>, <H1, F1>, ... , <H(N-1), F(N-1)> > // we sort a vector-o-vectors by sortCol in ascending order. // we scan the vector for the max and min values and build the return vector from both ends. // note: in retrospect this is an unnecessary level of complexity. it would be equivalent // and maybe better to look for either the max OR min value, place said value appropriately, // and then 'continue'. this way, we scan the minimal number of rows each time. // printf ("vIn.size(): %d\n", vIn[0].size()); int vWidth=vIn[0].size(); int nRows=vIn.size(); // printf("assigning sort stuff...\n"); std::vector<float> vRow(vWidth, 0); std::vector<std::vector<float> > vOut(vIn.size(), vRow); // int nStill=nRows; int outMaxRow=nRows-1, outMinRow=0; // // now, walk through the vIn; look for min and max values. watch for optimization tricks: int maxRow, minRow; // printf("declarations done. now, start many walks...\n"); while (nStill>0) { // printf("walk number (%d)\n", nRows-nStill); float maxVal = vIn[0][sortCol], minVal = vIn[0][sortCol]; // maxRow=nStill-1, minRow=0; maxRow=0; // source row(s) minRow=0; for (int iRows=0; iRows<nStill; iRows++) { if (vIn[iRows][sortCol] >= maxVal) { maxVal=vIn[iRows][sortCol]; maxRow=iRows; }; if (vIn[iRows][sortCol] <= minVal) { minVal=vIn[iRows][sortCol]; minRow=iRows; }; // // if (maxRow!=0 and minRow!=0) break; // optimize: exit loop. }; // printf("finished walk (%d)\n", nRows-nStill); // now, we've spun through the unsorted array and identified the max and min remaining values: // copy to sorted array: // printf("min,max: %f, %f\n", minVal, maxVal); vOut[outMaxRow]=vIn[maxRow]; vOut[outMinRow]=vIn[minRow]; outMaxRow--; outMinRow++; // printf("finished assigning to sorted vector.\n"); // // remove these values; move last two values into their places: vIn[maxRow]=vIn[nStill-1]; nStill--; if (maxRow!=minRow) { vIn[minRow]=vIn[nStill-1]; // note: odd count arrays have one element at the final step... nStill--; }; // printf("finished compressing vector. nStill=%d\n", nStill); // now, we only use the top part of the parent array. we can also do this with v.erase, but this way should be faster // since it does not require a resize (of course, the vector class might resize more intelligently...). }; // return vOut; };
void readWriteMatrix::writeVector(std::string fname,std::vector<double>* v){ std::fstream vOut(fname,std::ios::out | std::ios::trunc); for(auto d : *v) vOut<<d<<" "; vOut<<std::endl; }