// Greedily compute a set of nonintersecting edges in a point cloud for testing purposes // Warning: Takes O(n^3) time. static Array<Vector<int,2>> greedy_nonintersecting_edges(RawArray<const Vector<real,2>> X, const int limit) { const auto E = amap(quantizer(bounding_box(X)),X).copy(); const int n = E.size(); Array<Vector<int,2>> edges; IntervalScope scope; for (const int i : range(n*n)) { const int pi = int(random_permute(n*n,key+14,i)); const int a = pi/n, b = pi-n*a; if (a < b) { const auto Ea = Perturbed2(a,E[a]), Eb = Perturbed2(b,E[b]); for (const auto e : edges) if (!e.contains(a) && !e.contains(b) && segments_intersect(Ea,Eb,Perturbed2(e.x,E[e.x]),Perturbed2(e.y,E[e.y]))) goto skip; edges.append(vec(a,b)); if (edges.size()==limit || edges.size()==3*n-6) break; skip:; } } return edges; }
void gettest() /* get next test annotation */ { static long tt; /* time of previous test beat annotation */ static struct WFDB_ann annot; tt = t; t = tprime; a = aprime; /* See comments on the similar code in getref(), above. */ if (tt == 0L || t == huge_time || (tt <= vfontest && vfontest < t) || (tt <= sdontest && sdontest < t) || (tt <= pvfontest && pvfontest < t) || (tt <= psdontest && psdontest < t)) rr = 0L; else rr = t - tt; if (oflag) test_annot = annot; while (getann(1, &annot) == 0) { if (isqrs(annot.anntyp) || Oflag) { tprime = annot.time; aprime = amap(annot.anntyp); return; } if (annot.anntyp == NOISE) { if ((annot.subtyp & 0x30) == 0x30) { psdontest = sdontest; psdofftest = sdofftest; sdontest = annot.time; if (getann(1, &annot) < 0) { tprime = huge_time; aprime = '*'; if (end_time > 0L) shut_down += end_time - sdontest; else { (void)fprintf(stderr, "%s: unterminated shutdown starting at %s in record %s, annotator %s\n", pname, timstr(sdontest), record, an[1].name); (void)fprintf(stderr, " (not included in shutdown duration measurement)\n"); } return; } if (annot.anntyp == NOISE && (annot.subtyp & 0x30) != 0x30) sdofftest = annot.time; else { if (vfofftest > t) sdontest = vfofftest + match_dt; else sdontest = t + match_dt; sdofftest = annot.time - match_dt; if (sdontest > sdofftest) sdontest = sdofftest; (void)ungetann(0, &annot); } /* update shutdown duration tally */ shut_down += sdofftest - sdontest; } } else if (annot.anntyp == VFON) { pvfontest = vfontest; pvfofftest = vfofftest; vfontest = annot.time; do { if (getann(1, &annot) < 0) { tprime = huge_time; aprime = '*'; return; } } while (annot.anntyp != VFOFF); vfofftest = annot.time; } } tprime = huge_time; aprime = '*'; }
void getref() /* get next reference beat annotation */ { static long TT; /* time of previous reference beat annotation */ static struct WFDB_ann annot; TT = T; T = Tprime; A = Aprime; /* T-TT is not a valid RR interval if T is the time of the first beat, if TT is the time of the last beat, or if a period of VF or shutdown occurs between TT and T. */ if (TT == 0L || T == huge_time || (TT <= vfonref && vfonref < T) || (TT <= sdonref && sdonref < T) || (TT <= pvfonref && pvfonref < T) || (TT <= psdonref && psdonref < T)) RR = 0L; else RR = T - TT; if (oflag) ref_annot = annot; /* Read reference annotations until a beat annotation is read, or EOF. If an expanded output annotation file is required, all annotations are treated as if they were beat annotations. */ while (getann(0, &annot) == 0) { if (isqrs(annot.anntyp) || Oflag) { /* beat annotation */ Tprime = annot.time; Aprime = amap(annot.anntyp); return; } /* Shutdown occurs when neither signal is readable; the beginning of shutdown is indicated by a NOISE annotation in which bits 4 and 5 of the subtyp field are set, and the end of shutdown is indicated by a NOISE annotation with any value of `subtyp' for which at least one of bits 4 and 5 is zero. In AHA DB reference annotation files, shutdown is indicated by a single shutdown annotation placed roughly in the middle of the shutdown interval; in this case, shutdown is assumed to begin match_dt samples after the previous beat annotation or VFOFF annotation, and is assumed to end match_dt samples before the next annotation. */ else if (annot.anntyp == NOISE) { if ((annot.subtyp & 0x30) == 0x30) { psdonref = sdonref; psdoffref = sdoffref; sdonref = annot.time; /* Read next annotation, which should mark end of shutdown. */ if (getann(0, &annot) < 0) { /* EOF before end of shutdown */ Tprime = sdoffref = huge_time; Aprime = '*'; return; } if (annot.anntyp == NOISE && (annot.subtyp & 0x30) != 0x30) sdoffref = annot.time; else { if (vfoffref > T) sdonref = vfoffref + match_dt; else sdonref = T + match_dt; sdoffref = annot.time - match_dt; if (sdonref > sdoffref) sdonref = sdoffref; (void)ungetann(0, &annot); } } } /* The beginning of ventricular fibrillation is indicated by a VFON annotation, and its end by a VFOFF annotation; any annotations between VFON and VFOFF are read and ignored. */ else if (annot.anntyp == VFON) { pvfonref = vfonref; pvfoffref = vfoffref; vfonref = annot.time; /* Read additional annotations, until end of VF or EOF. */ do { if (getann(0, &annot) < 0) { /* EOF before end of VF */ Tprime = huge_time; Aprime = '*'; return; } } while (annot.anntyp != VFOFF); vfoffref = annot.time; } } /* When this statement is reached, there are no more annotations in the reference annotation file. */ Tprime = huge_time; Aprime = '*'; }
Ref<TriangleTopology> delaunay_points(RawArray<const Vector<real,2>> X, RawArray<const Vector<int,2>> edges, const bool validate) { return exact_delaunay_points(amap(quantizer(bounding_box(X)),X).copy(),edges,validate); }
// caller owns the result, it must be deleted ExplicitBitVect *PatternFingerprintMol(const ROMol &mol, unsigned int fpSize, std::vector<unsigned int> *atomCounts, ExplicitBitVect *setOnlyBits) { PRECONDITION(fpSize != 0, "fpSize==0"); PRECONDITION(!atomCounts || atomCounts->size() >= mol.getNumAtoms(), "bad atomCounts size"); PRECONDITION(!setOnlyBits || setOnlyBits->getNumBits() == fpSize, "bad setOnlyBits size"); std::vector<const ROMol *> patts; patts.reserve(10); unsigned int idx = 0; while (1) { std::string pq = pqs[idx]; if (pq == "") break; ++idx; const ROMol *matcher = pattern_flyweight(pq).get().getMatcher(); CHECK_INVARIANT(matcher, "bad smarts"); patts.push_back(matcher); } if (!mol.getRingInfo()->isInitialized()) { MolOps::fastFindRings(mol); } boost::dynamic_bitset<> isQueryAtom(mol.getNumAtoms()), isQueryBond(mol.getNumBonds()); ROMol::VERTEX_ITER firstA, lastA; boost::tie(firstA, lastA) = mol.getVertices(); while (firstA != lastA) { const Atom *at = mol[*firstA].get(); if (isComplexQuery(at)) { isQueryAtom.set(at->getIdx()); // std::cerr<<" complex atom: "<<at->getIdx()<<std::endl; } ++firstA; } ROMol::EDGE_ITER firstB, lastB; boost::tie(firstB, lastB) = mol.getEdges(); while (firstB != lastB) { const Bond *bond = mol[*firstB].get(); // if( isComplexQuery(bond) ){ if (isPatternComplexQuery(bond)) { isQueryBond.set(bond->getIdx()); // std::cerr<<" complex bond: "<<bond->getIdx()<<std::endl; } ++firstB; } ExplicitBitVect *res = new ExplicitBitVect(fpSize); unsigned int pIdx = 0; BOOST_FOREACH (const ROMol *patt, patts) { ++pIdx; std::vector<MatchVectType> matches; // uniquify matches? // time for 10K molecules w/ uniquify: 5.24s // time for 10K molecules w/o uniquify: 4.87s SubstructMatch(mol, *patt, matches, false); boost::uint32_t mIdx = pIdx + patt->getNumAtoms() + patt->getNumBonds(); BOOST_FOREACH (MatchVectType &mv, matches) { #ifdef VERBOSE_FINGERPRINTING std::cerr << "\nPatt: " << pIdx << " | "; #endif // collect bits counting the number of occurances of the pattern: gboost::hash_combine(mIdx, 0xBEEF); res->setBit(mIdx % fpSize); #ifdef VERBOSE_FINGERPRINTING std::cerr << "count: " << mIdx % fpSize << " | "; #endif bool isQuery = false; boost::uint32_t bitId = pIdx; std::vector<unsigned int> amap(mv.size(), 0); BOOST_FOREACH (MatchVectType::value_type &p, mv) { #ifdef VERBOSE_FINGERPRINTING std::cerr << p.second << " "; #endif if (isQueryAtom[p.second]) { isQuery = true; #ifdef VERBOSE_FINGERPRINTING std::cerr << "atom query."; #endif break; } gboost::hash_combine(bitId, mol.getAtomWithIdx(p.second)->getAtomicNum()); amap[p.first] = p.second; }