void ASMs3DLag::generateThreadGroups (char lIndex, bool) { if (threadGroupsFace.find(lIndex) != threadGroupsFace.end()) return; const int p1 = svol->order(0); const int p2 = svol->order(1); const int p3 = svol->order(2); const int n1 = (nx-1)/(p1-1); const int n2 = (ny-1)/(p2-1); const int n3 = (nz-1)/(p3-1); // Find elements that are on the boundary face 'lIndex' IntVec map; map.reserve(this->getNoBoundaryElms(lIndex,2)); int d1, d2, iel = 0; for (int i3 = 1; i3 <= n3; i3++) for (int i2 = 1; i2 <= n2; i2++) for (int i1 = 1; i1 <= n1; i1++, iel++) switch (lIndex) { case 1: if (i1 == 1) map.push_back(iel); break; case 2: if (i1 == n1) map.push_back(iel); break; case 3: if (i2 == 1) map.push_back(iel); break; case 4: if (i2 == n2) map.push_back(iel); break; case 5: if (i3 == 1) map.push_back(iel); break; case 6: if (i3 == n3) map.push_back(iel); break; } switch (lIndex) { case 1: case 2: d1 = n2; d2 = n3; break; case 3: case 4: d1 = n1; d2 = n3; break; default: d1 = n1; d2 = n2; } threadGroupsFace[lIndex].calcGroups(d1,d2,1); threadGroupsFace[lIndex].applyMap(map); }
void add_train( string item, int label, MatVec & images, IntVec & labels ) { Mat img = load(item); if ( img.empty() ) return ; images.push_back(img); labels.push_back(label); }
long long minimalFatigue(vector <int> magicalGirlStrength, vector <int> enemyStrength, vector<long long> enemyCount) { g = magicalGirlStrength; sort(g.begin(), g.end()); e.clear(); for (int i = 0; i < (int)enemyStrength.size(); ++i) { e[enemyStrength[i]] += enemyCount[i]; } LL low = -1, high = 1LL<<62; while (low < high) { LL mid = (low + high) / 2; if (can(mid)) { high = mid; } else { low = mid + 1; } } return low < (1LL<<62) ? low : -1; }
void init(IntVec& iv, PtrVec& pv, size_t n) { iv.resize(n); pv.resize(n); std::mt19937 rg(0); for (size_t i = 0; i < n; i++) { iv[i] = rg(); pv[i] = &iv[i]; } }
bool loadKeywordFile(const std::string& keyFile) { std::ifstream ifs(keyFile.c_str(), std::ios::binary); if (!ifs) return false; std::string word; while (std::getline(ifs, word)) { size_t pos = word.find('\t'); if (pos == std::string::npos) break; word.resize(pos); std::pair<Str2Int::iterator, bool> ret = word2id_.insert(Str2Int::value_type(word, (int)id2word_.size())); if (ret.second) { id2word_.push_back(word); } else { fprintf(stderr, "ERR already set %s\n", word.c_str()); } } df_.resize(id2word_.size()); fprintf(stderr, "#word = %d\n", (int)df_.size()); return true; }
void put(int maxNum = 0x7fffffff) const { printf("docNum=%d, wordNum=%d\n", (int)tf_.size(), (int)df_.size()); for (int i = 0, n = std::min(maxNum, (int)sv_.size()); i < n; i++) { const DoubleSvec& v = sv_[i]; for (DoubleSvec::const_iterator j = v.begin(), je = v.end(); j != je; ++j) { printf("%d:%f ", (int)j->pos(), j->val()); } printf("\n"); } }
bool SIMoutput::writeGlvM (const Mode& mode, bool freq, int& nBlock) { if (mode.eigVec.empty()) return true; else if (!myVtf) return false; if (msgLevel > 1) IFEM::cout <<"Writing eigenvector for Mode "<< mode.eigNo << std::endl; Vector displ; Matrix field; IntVec vID; int geomID = myGeomID; for (size_t i = 0; i < myModel.size(); i++) { if (myModel[i]->empty()) continue; // skip empty patches if (myModel.size() > 1 && msgLevel > 1) IFEM::cout <<"."<< std::flush; geomID++; myModel[i]->extractNodeVec(mode.eigVec,displ); if (!myModel[i]->evalSolution(field,displ,opt.nViz)) return false; if (!myVtf->writeVres(field,++nBlock,geomID)) return false; else vID.push_back(nBlock); } if (myModel.size() > 1 && msgLevel > 1) IFEM::cout << std::endl; int idBlock = 10; if (!myVtf->writeDblk(vID,"Mode Shape",idBlock,mode.eigNo)) return false; return myVtf->writeState(mode.eigNo, freq ? "Frequency %g" : "Eigenvalue %g", mode.eigVal, 1); }
bool can(LL n) { int i = 0; LLVec t(g.size()); ILLMap::const_iterator it; for (it = e.begin(); it != e.end(); ++it) { LL r = it->second; while (r > 0) { LL c = min(r, n - t[i]); if (g[i] < it->first || c <= 0) { ++i; if (i >= (int)g.size()) { return false; } continue; } r -= c; t[i] += c; } } return true; }
SpeckleyNodes::SpeckleyNodes(SpeckleyNodes_ptr fullNodes, IntVec& requiredNodes, const string& meshName) : name(meshName) { numDims = fullNodes->numDims; nodeDist = fullNodes->nodeDist; globalNumNodes = fullNodes->globalNumNodes; // first: find the unique set of required nodes and their IDs while // updating the contents of requiredNodes at the same time // requiredNodes contains node indices (not IDs!) IntVec::iterator it; IndexMap indexMap; // maps old index to new index size_t newIndex = 0; for (it = requiredNodes.begin(); it != requiredNodes.end(); it++) { IndexMap::iterator res = indexMap.find(*it); if (res == indexMap.end()) { nodeID.push_back(fullNodes->nodeID[*it]); nodeTag.push_back(fullNodes->nodeTag[*it]); indexMap[*it] = newIndex; *it = newIndex++; } else { *it = res->second; } } // second: now that we know how many nodes we need use the map to fill // the coordinates numNodes = newIndex; for (int dim=0; dim<numDims; dim++) { const float* origC = fullNodes->coords[dim]; float* c = new float[numNodes]; coords.push_back(c); IndexMap::const_iterator mIt; for (mIt = indexMap.begin(); mIt != indexMap.end(); mIt++) { c[mIt->second] = origC[mIt->first]; } } }
// sort freq order void term(int lowerLimit = 3, double upperRateLimit = 0.98) { fprintf(stderr, "#doc=%d, #word=%d\n", docNum_, (int)df_.size()); for (size_t i = 0, n = id2word_.size(); i < n; i++) { const int freq = df_[i]; if (freq <= lowerLimit) continue; pv_.push_back(Pair(i, freq)); } int pvNum = (int)(pv_.size() * upperRateLimit); fprintf(stderr, "shrink %d -> %d\n", (int)pv_.size(), pvNum); std::partial_sort(pv_.begin(), pv_.begin() + pvNum, pv_.end()); pv_.resize(pvNum); }
void append(const std::string& word) { std::string lower; cybozu::ToLower(lower, word); std::pair<Str2Int::iterator, bool> ret = word2id_.insert(Str2Int::value_type(lower, (int)id2word_.size())); //printf("word=%s, id=%d, ret=%d\n", ret.first->first.c_str(), ret.first->second, ret.second); if (ret.second) { id2word_.push_back(lower); df_.resize(id2word_.size()); } if (set_.insert(word).second) { df_[ret.first->second]++; } }
bool ASMstruct::addXNodes (unsigned short int dim, size_t nXn, IntVec& nodes) { if (dim != ndim-1) { std::cerr <<" *** ASMstruct::addXNodes: Invalid boundary dimension "<< dim <<", only "<< (int)ndim-1 <<" is allowed."<< std::endl; return false; } else if (!geo || shareFE == 'F') return false; // logic error else if (MNPC.size() == nel && MLGE.size() == nel) { // Extend the element number and element topology arrays to double size, // to account for extra-ordinary elements associated with contact surfaces myMLGE.resize(2*nel,0); myMNPC.resize(2*nel); } else if (MLGE.size() != 2*nel || MNPC.size() != 2*nel) { // Already added interface elements, currently not allowed std::cerr <<" *** ASMstruct::addXNodes: Already have interface elements." << std::endl; return false; } // Add nXn extra-ordinary nodes to the list of global node numbers for (size_t i = 0; i < nXn; i++) { if (nodes.size() == i) nodes.push_back(++gNod); myMLGN.push_back(nodes[i]); } return true; }
bool SIMoutput::writeGlvF (const RealFunc& f, const char* fname, int iStep, int& nBlock, int idBlock, double time) { if (!myVtf) return false; IntVec sID; int geomID = myGeomID; for (size_t i = 0; i < myModel.size(); i++) { if (myModel[i]->empty()) continue; // skip empty patches if (msgLevel > 1) IFEM::cout <<"Writing function "<< fname <<" for patch "<< i+1 << std::endl; if (!myVtf->writeNfunc(f,time,++nBlock,++geomID)) return false; else sID.push_back(nBlock); } return myVtf->writeSblk(sID,fname,idBlock,iStep); }
static void pop_test() { IntVec* vec = new_int_vec(2); vec->push(vec, 7); vec->push(vec, 42); vec->push(vec, 8); assert_int_equal(8, vec->pop(vec)); assert_int_equal(42, vec->pop(vec)); assert_int_equal(7, vec->pop(vec)); destroy_int_vec(vec); }
static void assemSparse (const RealArray& V, SparseMatrix& SM, size_t col, const IntVec& mnen, const int* meqn, const int* mpmceq, const int* mmceq, const Real* ttcc) { for (size_t d = 0; d < mnen.size(); d++, col++) { Real vd = d < V.size() ? V[d] : V.back(); int ieq = mnen[d]; int ceq = -ieq; if (ieq > 0) SM(ieq,col) += vd; else if (ceq > 0) for (int ip = mpmceq[ceq-1]; ip < mpmceq[ceq]-1; ip++) { ieq = meqn[mmceq[ip]-1]; SM(ieq,col) += vd; } } }
long long minCost(vector <string> road, vector <int> altitude) { int sz = (int)road.size(); // generate alt table IntVec alt = altitude; sort(alt.begin(), alt.end()); unique(alt.begin(), alt.end()); LL mincost[64][64]; memset(mincost, 0x3f, sizeof(mincost)); LIIQueue q; int i, j; for (i = 0; i < (int)alt.size(); ++i) { LL cost = abs(alt[i] - altitude[0]); mincost[0][i] = cost; q.push(LII(-cost, II(0, alt[i]))); } // dijkstra while (q.size() > 0) { LII current = q.top(); q.pop(); int from = current.second.first; if (from == (sz-1)) { return -current.first; } for (i = 0; i < (int)alt.size(); ++i) { if (alt[i] > current.second.second) { break; } for (j = 0; j < sz; ++j) { if (road[from][j] == 'Y') { LL cost = -current.first + abs(alt[i] - altitude[j]); if (cost < mincost[j][i]) { mincost[j][i] = cost; q.push(LII(-cost, II(j, alt[i]))); } } } } } return -1; }
void read_test(const string & fn, int label, IntVec & labels, StrVec & items, int maxiter) { ifstream pos(fn.c_str()); int i = 0; while ( ! pos.eof() ) { string item; pos >> item; if ( item.empty() ) break; i++; if ( i % 2 == 0 ) continue; if ( i / 2 > maxiter ) break; labels.push_back(label); items.push_back(item); } }
LLPair eval(const IntVec &program, size_t pos) { int sz = (int)program.size(); size_t i; LLPairQueue q; for (i = 0; i <= sz*2; ++i) { q.push_front(LLPair(0, 0)); } for (i = 0; i < sz; ++i) { LLPair c(program[i], i == pos); if (program[i] == 0) { LLPair a = q.front(); q.pop_front(); LLPair b = q.front(); q.pop_front(); c.first = a.first + b.first; c.second = a.second + b.second; } q.push_front(c); } return q.front(); }
double rec(int i, int M) { if (memo[i][M] > 0) { return memo[i][M]; } double &res = memo[i][M]; int G = min(Max, M+_gain[i]); int d = G+1; if ((i+1) < (int)_day.size()) { d = _day[i+1] - _day[i]; } if (M > d) { res = rec(i+1, M-d); } else { res = _day[i]+M; } if (G > d) { res = max(res, (1.0-_win[i])*_day[i] + _win[i]*rec(i+1, G-d)); } else { res = max(res, (1.0-_win[i])*_day[i] + _win[i]*(_day[i]+G)); } return res; }
//prime factors, less than or equal to num. //check each prime number to square root void factor(i64 num, I64PairVec& ifac, const IntVec& prime) { //special case, not prime factor for 1 ifac.clear(); if(num==1){ ifac.push_back(IntPair(1,1)); return; } i64 n1 = num; int ubound = sqrt((double) num); for(unsigned int i = 0; i < prime.size(); ++i) { int nth = 0; if( n1 % prime[i] == 0){ while(n1% prime[i] ==0) { n1/=prime[i]; ++nth; } ifac.push_back(IntPair(prime[i], nth)); } if(n1 == 1 || prime[i] > ubound)break; } if(n1 > 1) ifac.push_back(I64Pair(n1, 1)); }
int main () { typedef vector <int> IntVec; IntVec v (10); for (int i = 0; i < v.size (); i++) v[i] = (i + 1) * (i + 1); IntVec::iterator iter; iter = find_if (v.begin (), v.end (), div_3); if (iter != v.end ()) cout << "Value " << *iter << " at offset " << (iter - v.begin ()) << " is divisible by 3" << endl; return 0; }
void SpeckleyElements::reorderArray(IntVec& v, const IntVec& idx, int elementsPerIndex) { IntVec newArray(v.size()); IntVec::iterator arrIt = newArray.begin(); IntVec::const_iterator idxIt; if (elementsPerIndex == 1) { for (idxIt=idx.begin(); idxIt!=idx.end(); idxIt++) { *arrIt++ = v[*idxIt]; } } else { for (idxIt=idx.begin(); idxIt!=idx.end(); idxIt++) { int i = *idxIt; copy(&v[i*elementsPerIndex], &v[(i+1)*elementsPerIndex], arrIt); arrIt += elementsPerIndex; } } v.swap(newArray); }
bool findNum(IntVec const& vec, int target) { RotatedIndex rotation(vec); cout << "Rotation shift: " << rotation.shift << endl; return binarySearch(vec, 0, vec.size()-1, target, rotation); }
RotatedIndex(IntVec const& vec) { size = vec.size(); shift = findRotatedIndex(vec); }
bool contains(IntVec& vec, uint32 value) { return std::find(vec.begin(), vec.end(), value) != vec.end(); }
//////////////////////////////////////////////////////////////////////////////////////// // GenerateStrips() // // in_indices: input index list, the indices you would use to render // in_numIndices: number of entries in in_indices // primGroups: array of optimized/stripified PrimitiveGroups // numGroups: number of groups returned // // Be sure to call delete[] on the returned primGroups to avoid leaking mem // bool GenerateStrips(const unsigned short* in_indices, const unsigned int in_numIndices, PrimitiveGroup** primGroups, unsigned short* numGroups, bool validateEnabled) { int i = 0; //put data in format that the stripifier likes WordVec tempIndices; tempIndices.resize(in_numIndices); unsigned short maxIndex = 0; unsigned short minIndex = 0xFFFF; for(i = 0; i < in_numIndices; i++) { tempIndices[i] = in_indices[i]; if (in_indices[i] > maxIndex) maxIndex = in_indices[i]; if (in_indices[i] < minIndex) minIndex = in_indices[i]; } NvStripInfoVec tempStrips; NvFaceInfoVec tempFaces; NvStripifier stripifier; //do actual stripification stripifier.Stripify(tempIndices, cacheSize, minStripSize, maxIndex, tempStrips, tempFaces); //stitch strips together IntVec stripIndices; unsigned int numSeparateStrips = 0; if(bListsOnly) { //if we're outputting only lists, we're done *numGroups = 1; (*primGroups) = new PrimitiveGroup[*numGroups]; PrimitiveGroup* primGroupArray = *primGroups; //count the total number of indices unsigned int numIndices = 0; for(i = 0; i < tempStrips.size(); i++) { numIndices += tempStrips[i]->m_faces.size() * 3; } //add in the list numIndices += tempFaces.size() * 3; primGroupArray[0].type = PT_LIST; primGroupArray[0].numIndices = numIndices; primGroupArray[0].indices = new unsigned short[numIndices]; //do strips unsigned int indexCtr = 0; for(i = 0; i < tempStrips.size(); i++) { for(int j = 0; j < tempStrips[i]->m_faces.size(); j++) { //degenerates are of no use with lists if(!NvStripifier::IsDegenerate(tempStrips[i]->m_faces[j])) { primGroupArray[0].indices[indexCtr++] = tempStrips[i]->m_faces[j]->m_v0; primGroupArray[0].indices[indexCtr++] = tempStrips[i]->m_faces[j]->m_v1; primGroupArray[0].indices[indexCtr++] = tempStrips[i]->m_faces[j]->m_v2; } else { //we've removed a tri, reduce the number of indices primGroupArray[0].numIndices -= 3; } } } //do lists for(i = 0; i < tempFaces.size(); i++) { primGroupArray[0].indices[indexCtr++] = tempFaces[i]->m_v0; primGroupArray[0].indices[indexCtr++] = tempFaces[i]->m_v1; primGroupArray[0].indices[indexCtr++] = tempFaces[i]->m_v2; } } else { stripifier.CreateStrips(tempStrips, stripIndices, bStitchStrips, numSeparateStrips, bRestart, restartVal); //if we're stitching strips together, we better get back only one strip from CreateStrips() assert( (bStitchStrips && (numSeparateStrips == 1)) || !bStitchStrips); //convert to output format *numGroups = numSeparateStrips; //for the strips if(tempFaces.size() != 0) (*numGroups)++; //we've got a list as well, increment (*primGroups) = new PrimitiveGroup[*numGroups]; PrimitiveGroup* primGroupArray = *primGroups; //first, the strips int startingLoc = 0; for(int stripCtr = 0; stripCtr < numSeparateStrips; stripCtr++) { int stripLength = 0; if(!bStitchStrips) { int i; //if we've got multiple strips, we need to figure out the correct length for(i = startingLoc; i < stripIndices.size(); i++) { if(stripIndices[i] == -1) break; } stripLength = i - startingLoc; } else stripLength = stripIndices.size(); primGroupArray[stripCtr].type = PT_STRIP; primGroupArray[stripCtr].indices = new unsigned short[stripLength]; primGroupArray[stripCtr].numIndices = stripLength; int indexCtr = 0; for(int i = startingLoc; i < stripLength + startingLoc; i++) primGroupArray[stripCtr].indices[indexCtr++] = stripIndices[i]; //we add 1 to account for the -1 separating strips //this doesn't break the stitched case since we'll exit the loop startingLoc += stripLength + 1; } //next, the list if(tempFaces.size() != 0) { int faceGroupLoc = (*numGroups) - 1; //the face group is the last one primGroupArray[faceGroupLoc].type = PT_LIST; primGroupArray[faceGroupLoc].indices = new unsigned short[tempFaces.size() * 3]; primGroupArray[faceGroupLoc].numIndices = tempFaces.size() * 3; int indexCtr = 0; for(int i = 0; i < tempFaces.size(); i++) { primGroupArray[faceGroupLoc].indices[indexCtr++] = tempFaces[i]->m_v0; primGroupArray[faceGroupLoc].indices[indexCtr++] = tempFaces[i]->m_v1; primGroupArray[faceGroupLoc].indices[indexCtr++] = tempFaces[i]->m_v2; } } } //validate generated data against input if (validateEnabled) { const int NUMBINS = 100; std::vector<NvFaceInfo> in_bins[NUMBINS]; //hash input indices on first index for (i = 0; i < in_numIndices; i += 3) { NvFaceInfo faceInfo(in_indices[i], in_indices[i + 1], in_indices[i + 2]); in_bins[in_indices[i] % NUMBINS].push_back(faceInfo); } for (i = 0; i < *numGroups; ++i) { switch ((*primGroups)[i].type) { case PT_LIST: { for (int j = 0; j < (*primGroups)[i].numIndices; j += 3) { unsigned short v0 = (*primGroups)[i].indices[j]; unsigned short v1 = (*primGroups)[i].indices[j + 1]; unsigned short v2 = (*primGroups)[i].indices[j + 2]; //ignore degenerates if (NvStripifier::IsDegenerate(v0, v1, v2)) continue; if (!TestTriangle(v0, v1, v2, in_bins, NUMBINS)) { Cleanup(tempStrips, tempFaces); return false; } } break; } case PT_STRIP: { //int brokenCtr = 0; bool flip = false; for (int j = 2; j < (*primGroups)[i].numIndices; ++j) { unsigned short v0 = (*primGroups)[i].indices[j - 2]; unsigned short v1 = (*primGroups)[i].indices[j - 1]; unsigned short v2 = (*primGroups)[i].indices[j]; if (flip) { //swap v1 and v2 unsigned short swap = v1; v1 = v2; v2 = swap; } //ignore degenerates if (NvStripifier::IsDegenerate(v0, v1, v2)) { flip = !flip; continue; } if (!TestTriangle(v0, v1, v2, in_bins, NUMBINS)) { Cleanup(tempStrips, tempFaces); return false; } flip = !flip; } break; } case PT_FAN: default: break; } } } //clean up everything Cleanup(tempStrips, tempFaces); return true; }
//////////////////////////////////////////////////////////////////////////////////////// // CreateStrips() // // Generates actual strips from the list-in-strip-order. // void NvStripifier::CreateStrips(const NvStripInfoVec& allStrips, IntVec& stripIndices, const bool bStitchStrips, unsigned int& numSeparateStrips, const bool bRestart, const unsigned int restartVal) { assert(numSeparateStrips == 0); NvFaceInfo tLastFace(0, 0, 0); NvFaceInfo tPrevStripLastFace(0, 0, 0); size_t nStripCount = allStrips.size(); //we infer the cw/ccw ordering depending on the number of indices //this is screwed up by the fact that we insert -1s to denote changing strips //this is to account for that int accountForNegatives = 0; for (size_t i = 0; i < nStripCount; i++) { NvStripInfo *strip = allStrips[i]; int nStripFaceCount = strip->m_faces.size(); assert(nStripFaceCount > 0); // Handle the first face in the strip { NvFaceInfo tFirstFace(strip->m_faces[0]->m_v0, strip->m_faces[0]->m_v1, strip->m_faces[0]->m_v2); // If there is a second face, reorder vertices such that the // unique vertex is first if (nStripFaceCount > 1) { int nUnique = NvStripifier::GetUniqueVertexInB(strip->m_faces[1], &tFirstFace); if (nUnique == tFirstFace.m_v1) { SWAP(tFirstFace.m_v0, tFirstFace.m_v1); } else if (nUnique == tFirstFace.m_v2) { SWAP(tFirstFace.m_v0, tFirstFace.m_v2); } // If there is a third face, reorder vertices such that the // shared vertex is last if (nStripFaceCount > 2) { if(IsDegenerate(strip->m_faces[1])) { int pivot = strip->m_faces[1]->m_v1; if(tFirstFace.m_v1 == pivot) { SWAP(tFirstFace.m_v1, tFirstFace.m_v2); } } else { int nShared0, nShared1; GetSharedVertices(strip->m_faces[2], &tFirstFace, &nShared0, &nShared1); if ( (nShared0 == tFirstFace.m_v1) && (nShared1 == -1) ) { SWAP(tFirstFace.m_v1, tFirstFace.m_v2); } } } } if( (i == 0) || !bStitchStrips || bRestart) { if(!IsCW(strip->m_faces[0], tFirstFace.m_v0, tFirstFace.m_v1)) stripIndices.push_back(tFirstFace.m_v0); } else { // Double tap the first in the new strip stripIndices.push_back(tFirstFace.m_v0); // Check CW/CCW ordering if (NextIsCW(stripIndices.size() - accountForNegatives) != IsCW(strip->m_faces[0], tFirstFace.m_v0, tFirstFace.m_v1)) { stripIndices.push_back(tFirstFace.m_v0); } } stripIndices.push_back(tFirstFace.m_v0); stripIndices.push_back(tFirstFace.m_v1); stripIndices.push_back(tFirstFace.m_v2); // Update last face info tLastFace = tFirstFace; } for (int j = 1; j < nStripFaceCount; j++) { int nUnique = GetUniqueVertexInB(&tLastFace, strip->m_faces[j]); if (nUnique != -1) { stripIndices.push_back(nUnique); // Update last face info tLastFace.m_v0 = tLastFace.m_v1; tLastFace.m_v1 = tLastFace.m_v2; tLastFace.m_v2 = nUnique; } else { //we've hit a degenerate stripIndices.push_back(strip->m_faces[j]->m_v2); tLastFace.m_v0 = strip->m_faces[j]->m_v0;//tLastFace.m_v1; tLastFace.m_v1 = strip->m_faces[j]->m_v1;//tLastFace.m_v2; tLastFace.m_v2 = strip->m_faces[j]->m_v2;//tLastFace.m_v1; } } // Double tap between strips. if (bStitchStrips && !bRestart) { if (i != nStripCount - 1) stripIndices.push_back(tLastFace.m_v2); } else if (bRestart) { stripIndices.push_back(restartVal); } else { //-1 index indicates next strip stripIndices.push_back(-1); accountForNegatives++; numSeparateStrips++; } // Update last face info tLastFace.m_v0 = tLastFace.m_v1; tLastFace.m_v1 = tLastFace.m_v2; tLastFace.m_v2 = tLastFace.m_v2; } if(bStitchStrips || bRestart) numSeparateStrips = 1; }
int main(int argc, char** argv) { int stat = 0; try { GlobalMPISession session(&argc, &argv); bool bad = false; for (int n=1; n<=4; n++) { Array<Array<Array<int> > > c = compositions(n); std::cout << "N=" << n << " compositions=" << c << std::endl; MultiSet<int> mu; for (int m=1; m<=n; m++) { mu.put(m); } for (int m=1; m<=n; m++) { Array<Array<Array<int> > > b = binnings(mu, m); std::cout << "binnings = " << b << std::endl; } std::cout << "--------- non-neg compositions" << std::endl; for (int m=1; m<=n; m++) { for (int k=1; k<=n; k++) { Array<Array<int> > a = nonNegCompositions(m, k); std::cout << m << " " << k << " " << std::endl; for (int l=0; l<a.size(); l++) { std::cout << " " << a[l] << std::endl; } } } std::cout << "-------- index combs ---- " << std::endl; Array<int> s = tuple(2,3,2); Array<Array<int> > C = indexCombinations(s); for (int m=0; m<C.size(); m++) { std::cout << C[m] << std::endl; } } std::cout << "--------- index tuples ----------------" << std::endl; Array<Array<int> > x = distinctIndexTuples(2, 6); std::cout << "num choices = " << x.size() << std::endl; for (int i=0; i<x.size(); i++) { if ((i % 5)==0) std::cout << std::endl; std::cout << x[i] << std::endl; } std::cout << "--------- int vec parts ----------------" << std::endl; IntVec iv = intVec(1,3,2); Array<Array<IntVec> > parts; iv.getPartitions(3, parts); std::cout << "----------- partitions of " << iv << " ---------" << std::endl; for (int i=0; i<parts.size(); i++) { std::cout << i << " -- " << std::endl; for (int j=0; j<parts[i].size(); j++) { std::cout << "\t\t" << parts[i][j] << std::endl; } } std::cout << "--------- weighted parts ----------------" << std::endl; Array<int> wgts = tuple(3,1); Array<Array<int> > wParts; int M = 3; weightedPartitions(M, wgts, wParts); std::cout << "----------- partitions of " << M << " ---------" << std::endl; for (int i=0; i<wParts.size(); i++) { std::cout << "\t" << wParts[i] << std::endl; } std::cout << "--------- weighted ordered parts ---------" << std::endl; IntVec iv2 = intVec(1,3,2,1); Array<Array<IntVec> > vParts; weightedOrderedPartitions(iv2, wgts, vParts); std::cout << "----------- partitions of " << iv2 << " ---------" << std::endl; for (int i=0; i<vParts.size(); i++) { std::cout << "\t" << vParts[i] << std::endl; } IntVec lam = intVec(1,2,1); IntVec nu = intVec(2,3); Array<Array<IntVec> > K; Array<Array<IntVec> > L; int S = 2; pSet(lam, nu, S, K, L); std::cout << "pSet(" << lam << ", " << nu << ", " << S << ")" << std::endl; for (int i=0; i<K.size(); i++) { std::cout << "i=" << i << std::endl; IntVec kSum(K[i][0].size()); IntVec lSum(L[i][0].size()); for (int j=0; j<K[i].size(); j++) { kSum = kSum + K[i][j]; lSum = lSum + K[i][j].abs() * L[i][j]; std::cout << "\t\t\t K=" << K[i][j] << ", L=" << L[i][j] << std::endl; } std::cout << "\t\tKSum=" << kSum << std::endl; std::cout << "\t\tLSum=" << lSum << std::endl; } #ifdef BLAH TEST_MS(makeMultiSet(1)); TEST_MS(makeMultiSet(1, 1)); TEST_MS(makeMultiSet(1, 2)); TEST_MS(makeMultiSet(1, 1, 2)); TEST_MS(makeMultiSet(1, 1, 2, 2)); TEST_MS(makeMultiSet(1, 2, 3)); TEST_MS(makeMultiSet(1, 2, 2, 3)); TEST_MS(makeMultiSet(1, 2, 2, 3, 3)); TEST_MS(makeMultiSet(1, 2, 2, 3, 3, 3)); #endif // BLAH if (!bad) { std::cerr << "all tests PASSED" << std::endl; } else { stat = -1; std::cerr << "a test has FAILED" << std::endl; } } catch(std::exception& e) { stat = -1; std::cerr << "detected exception " << e.what() << std::endl; } return stat; }
void test_intersect() { DoubleVec dv; IntVec iv; const struct { unsigned int pos; double val; } dTbl[] = { { 5, 3.14 }, { 10, 2 }, { 12, 1.4 }, { 100, 2.3 }, { 1000, 4 }, }; const struct { unsigned int pos; int val; } iTbl[] = { { 2, 4 }, { 5, 2 }, { 100, 4 }, { 101, 3}, { 999, 4 }, { 1000, 1 }, { 2000, 3 }, }; const struct { unsigned int pos; double d; int i; } interTbl[] = { { 5, 3.14, 2 }, { 100, 2.3, 4 }, { 1000, 4, 1 } }; for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(dTbl); i++) { dv.push_back(dTbl[i].pos, dTbl[i].val); } for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(iTbl); i++) { iv.push_back(iTbl[i].pos, iTbl[i].val); } int j = 0; for (typename DoubleVec::const_iterator i = dv.begin(), ie = dv.end(); i != ie; ++i) { CYBOZU_TEST_EQUAL(i->pos(), dTbl[j].pos); CYBOZU_TEST_EQUAL(i->val(), dTbl[j].val); j++; } j = 0; for (typename IntVec::const_iterator i = iv.begin(), ie = iv.end(); i != ie; ++i) { CYBOZU_TEST_EQUAL(i->pos(), iTbl[j].pos); CYBOZU_TEST_EQUAL(i->val(), iTbl[j].val); j++; } int sum = 0; for (typename IntVec::const_iterator i = iv.begin(), ie = iv.end(); i != ie; ++i) { sum += i->val() * i->val(); } CYBOZU_TEST_EQUAL(sum, 71); typedef cybozu::nlp::Intersection<DoubleVec, IntVec> InterSection; InterSection inter(dv, iv); j = 0; for (typename InterSection::const_iterator i = inter.begin(), ie = inter.end(); i != ie; ++i) { CYBOZU_TEST_EQUAL(i->pos(), interTbl[j].pos); CYBOZU_TEST_EQUAL(i->val1(), interTbl[j].d); CYBOZU_TEST_EQUAL(i->val2(), interTbl[j].i); j++; } }
void test_empty() { IntVec v; CYBOZU_TEST_EQUAL((int)v.size(), 0); CYBOZU_TEST_ASSERT(v.empty()); for (typename IntVec::const_iterator i = v.begin(); i != v.end(); ++i) { printf("%d\n", i->val()); } v.push_back(3, 1); CYBOZU_TEST_EQUAL((int)v.size(), 1); CYBOZU_TEST_ASSERT(!v.empty()); for (typename IntVec::const_iterator i = v.begin(); i != v.end(); ++i) { CYBOZU_TEST_EQUAL(i->pos(), (size_t)3); CYBOZU_TEST_EQUAL(i->val(), 1); } v.push_back(4, 2); CYBOZU_TEST_EQUAL((int)v.size(), 2); int j = 0; for (typename IntVec::const_iterator i = v.begin(); i != v.end(); ++i) { CYBOZU_TEST_EQUAL(i->pos(), size_t(j + 3)); CYBOZU_TEST_EQUAL(i->val(), j + 1); j++; } v.clear(); CYBOZU_TEST_EQUAL((int)v.size(), 0); CYBOZU_TEST_ASSERT(v.empty()); IntVec v1, v2; for (int i = 0; i < 3; i++) { v1.push_back(i, i); v2.push_back(i, i); } CYBOZU_TEST_ASSERT(v1 == v2); v2.push_back(10, 10); CYBOZU_TEST_ASSERT(v1 != v2); }