/* * Return the `loop's preExit block if it was already created or if a * suitable block already exists. Otherwise, return nullptr. */ Block* findLoopPreExit(LoopInfo& loop) { if (loop.preExit) return loop.preExit; const auto preHeader = loop.preHeader; if (!preHeader) return nullptr; if (preHeader->preds().size() != 1) return nullptr; const auto& pred = preHeader->preds().front().from(); if (pred->back().op() == ExitPlaceholder) loop.preExit = pred->taken(); return loop.preExit; }
/* * Splits the critical edges in `unit', if any. * Returns true iff the unit was modified. */ bool splitCriticalEdges(Vunit& unit) { jit::vector<unsigned> preds(unit.blocks.size()); jit::flat_set<size_t> catch_blocks; for (size_t b = 0; b < unit.blocks.size(); b++) { auto succlist = succs(unit.blocks[b]); for (auto succ : succlist) { preds[succ]++; } } auto changed = false; for (size_t pred = 0; pred < unit.blocks.size(); pred++) { auto succlist = succs(unit.blocks[pred]); if (succlist.size() <= 1) continue; for (auto& succ : succlist) { if (preds[succ] <= 1) continue; // split the critical edge. auto middle = unit.makeBlock(unit.blocks[succ].area); forwardJmp(unit, catch_blocks, middle, succ); succ = middle; changed = true; } } // Remove any landingpad{} instructions that were hoisted to split edges. for (auto block : catch_blocks) { auto& code = unit.blocks[block].code; assertx(code.front().op == Vinstr::landingpad); code.front() = nop{}; } return changed; }
void DepCompCopyArrayToBuffer:: EnforceCopyRoot( DepCompCopyArrayCollect::CopyArrayUnit& curunit, const DepCompAstRefGraphCreate& refDep, const DepCompAstRefGraphNode* outnode, DepCompCopyArrayCollect::CopyArrayUnit::NodeSet& cuts) { int copylevel = curunit.copylevel(); DepCompCopyArrayCollect::CopyArrayUnit::CrossGraphOut crossout(&refDep, curunit); GraphNodePredecessorIterator<DepCompCopyArrayCollect::CopyArrayUnit::CrossGraphOut> preds(&crossout, outnode); bool complete = EnforceCopyRootRemove(preds, outnode, copylevel, cuts); DepCompCopyArrayCollect::CopyArrayUnit tmp = curunit; tmp.refs -= cuts; DepCompCopyArrayCollect::CopyArrayUnit::CrossGraphIn crossin(&refDep, tmp); GraphNodeSuccessorIterator<DepCompCopyArrayCollect::CopyArrayUnit::CrossGraphIn> succ(&crossin, outnode); if (!EnforceCopyRootRemove( succ, outnode, copylevel, cuts)) complete = false; if (complete) return; tmp.refs -= cuts; EnforceCopyRootRemove(tmp.refs.begin(), outnode, copylevel, cuts); }
std::vector<float> SupportVectorMachine::predict(const FeatureCollection &fset) const { std::vector<float> preds(fset.size()); for(int i = 0; i < fset.size(); i++) { preds[i] = predict(fset[i]); } return preds; }
PredVector computePreds(const Vunit& unit) { PredVector preds(unit.blocks.size()); PostorderWalker walker(unit); walker.dfs([&](Vlabel b) { for (auto s: succs(unit.blocks[b])) { preds[s].push_back(b); } }); return preds; }
void mk_array_instantiation::instantiate_rule(const rule& r, rule_set & dest) { //Reset everything selects.reset(); eq_classes.reset(); cnt = src_manager->get_counter().get_max_rule_var(r)+1; done_selects.reset(); ownership.reset(); expr_ref_vector phi(m); expr_ref_vector preds(m); expr_ref new_head = create_head(to_app(r.get_head())); unsigned nb_predicates = r.get_uninterpreted_tail_size(); unsigned tail_size = r.get_tail_size(); for(unsigned i=0;i<nb_predicates;i++) { preds.push_back(r.get_tail(i)); } for(unsigned i=nb_predicates;i<tail_size;i++) { phi.push_back(r.get_tail(i)); } //Retrieve selects for(unsigned i=0;i<phi.size();i++) retrieve_selects(phi[i].get()); //Rewrite the predicates expr_ref_vector new_tail(m); for(unsigned i=0;i<preds.size();i++) { new_tail.append(instantiate_pred(to_app(preds[i].get()))); } new_tail.append(phi); for(obj_map<expr, var*>::iterator it = done_selects.begin(); it!=done_selects.end(); ++it) { expr_ref tmp(m); tmp = &it->get_key(); new_tail.push_back(m.mk_eq(it->get_value(), tmp)); } proof_ref pr(m); src_manager->mk_rule(m.mk_implies(m.mk_and(new_tail.size(), new_tail.c_ptr()), new_head), pr, dest, r.name()); }
RegionDesc::BlockVec::iterator RegionDesc::deleteBlock(RegionDesc::BlockVec::iterator it) { const auto bid = (*it)->id(); for (auto pid : preds(bid)) removeArc(pid, bid); for (auto sid : succs(bid)) removeArc(bid, sid); if (auto nextR = nextRetrans(bid)) { auto prevR = prevRetrans(bid); clearPrevRetrans(nextR.value()); if (prevR) { clearNextRetrans(prevR.value()); setNextRetrans(prevR.value(), nextR.value()); } else { clearPrevRetrans(nextR.value()); } } else if (auto prevR = prevRetrans(bid)) { clearNextRetrans(prevR.value()); } m_data.erase(bid); return m_blocks.erase(it); }
Block* findDefiningBlock(const SSATmp* t, const IdomVector& idoms) { assertx(!t->inst()->is(DefConst)); auto const srcInst = t->inst(); if (srcInst->hasEdges()) { auto const next = srcInst->next(); UNUSED auto const taken = srcInst->taken(); always_assert_flog( next && taken, "hasEdges instruction defining a dst had no edges:\n {}\n", srcInst->toString() ); for (const auto& arc : next->preds()) { auto pred = arc.from(); if (pred != srcInst->block() && !dominates(next, pred, idoms)) { return nullptr; } } return next; } return srcInst->block(); }
/* * Splits the critical edges in `unit', if any. * Returns true iff the unit was modified. */ bool splitCriticalEdges(Vunit& unit) { jit::vector<unsigned> preds(unit.blocks.size()); for (size_t b = 0; b < unit.blocks.size(); b++) { auto succlist = succs(unit.blocks[b]); for (auto succ : succlist) { preds[succ]++; } } auto changed = false; for (size_t pred = 0; pred < unit.blocks.size(); pred++) { auto succlist = succs(unit.blocks[pred]); if (succlist.size() <= 1) continue; for (auto& succ : succlist) { if (preds[succ] <= 1) continue; // split the critical edge. auto middle = unit.makeBlock(unit.blocks[succ].area); forwardJmp(unit, middle, succ); succ = middle; changed = true; } } return changed; }
bool ValuePropagate:: known_value( const AstNodePtr& exp, HasValueDescriptor* result, bool *change) { std::map<AstNodePtr, ValuePropagateNode*>::const_iterator p = nodemap.find(exp); if (p == nodemap.end()) { bool r = valmap.has_value( exp, result); if (change != 0) *change = true; return r; } ValuePropagateNode* node = (*p).second; if (result != 0) *result = node->get_desc(); if (change != 0) { if (!node->is_definition()) *change = false; else { *change = false; for (GraphNodePredecessorIterator<ValuePropagate> preds(this,node); !preds.ReachEnd(); ++preds) { ValuePropagateNode* cur = *preds; HasValueDescriptor tmp = cur->get_desc(); if (tmp.merge(node->get_desc())) { *change = true; if (DebugValuePropogate()) { std::cerr << "HasValue descriptors differ : " << cur->toString() << " : " << node->toString() << std::endl; } break; } } } } return true; }
static bool expandCyclic(NGHolder &h, NFAVertex v) { DEBUG_PRINTF("inspecting %zu\n", h[v].index); bool changes = false; auto v_preds = preds(v, h); auto v_succs = succs(v, h); set<NFAVertex> start_siblings; set<NFAVertex> end_siblings; CharReach &v_cr = h[v].char_reach; /* We need to find start vertices which have all of our preds. * As we have a self loop, it must be one of our succs. */ for (auto a : adjacent_vertices_range(v, h)) { auto a_preds = preds(a, h); if (a_preds == v_preds && isutf8start(h[a].char_reach)) { DEBUG_PRINTF("%zu is a start v\n", h[a].index); start_siblings.insert(a); } } /* We also need to find full cont vertices which have all our own succs; * As we have a self loop, it must be one of our preds. */ for (auto a : inv_adjacent_vertices_range(v, h)) { auto a_succs = succs(a, h); if (a_succs == v_succs && h[a].char_reach == UTF_CONT_CR) { DEBUG_PRINTF("%zu is a full tail cont\n", h[a].index); end_siblings.insert(a); } } for (auto s : start_siblings) { if (out_degree(s, h) != 1) { continue; } const CharReach &cr = h[s].char_reach; if (cr.isSubsetOf(UTF_TWO_START_CR)) { if (end_siblings.find(*adjacent_vertices(s, h).first) == end_siblings.end()) { DEBUG_PRINTF("%zu is odd\n", h[s].index); continue; } } else if (cr.isSubsetOf(UTF_THREE_START_CR)) { NFAVertex m = *adjacent_vertices(s, h).first; if (h[m].char_reach != UTF_CONT_CR || out_degree(m, h) != 1) { continue; } if (end_siblings.find(*adjacent_vertices(m, h).first) == end_siblings.end()) { DEBUG_PRINTF("%zu is odd\n", h[s].index); continue; } } else if (cr.isSubsetOf(UTF_FOUR_START_CR)) { NFAVertex m1 = *adjacent_vertices(s, h).first; if (h[m1].char_reach != UTF_CONT_CR || out_degree(m1, h) != 1) { continue; } NFAVertex m2 = *adjacent_vertices(m1, h).first; if (h[m2].char_reach != UTF_CONT_CR || out_degree(m2, h) != 1) { continue; } if (end_siblings.find(*adjacent_vertices(m2, h).first) == end_siblings.end()) { DEBUG_PRINTF("%zu is odd\n", h[s].index); continue; } } else { DEBUG_PRINTF("%zu is bad\n", h[s].index); continue; } v_cr |= cr; clear_vertex(s, h); changes = true; } if (changes) { v_cr |= UTF_CONT_CR; /* we need to add in cont reach */ v_cr.set(0xc0); /* we can also add in the forbidden bytes as we require * valid unicode data */ v_cr.set(0xc1); v_cr |= CharReach(0xf5, 0xff); } return changes; }
int main(int argc, char* argv[]) { bool draw_sample = false; bool load_pipeline = false; char c; opterr = 0; while ((c = getopt(argc, argv, "dl")) != -1) { switch (c) { case 'd': draw_sample = true; break; case 'l': load_pipeline = true; break; default: abort(); } } // Setup Pipeline // TODO(benzh) Convert this to user code loading GRT::GestureRecognitionPipeline pipeline; pipeline.addFeatureExtractionModule( GRT::FFT(kFFT_WindowSize, kFFT_HopSize, DIM, GRT::FFT::HAMMING_WINDOW, true, false)); GRT::MFCC::Options options; options.sample_rate = sample_rate; options.fft_size = kFFT_WindowSize / 2; options.start_freq = 300; options.end_freq = 8000; options.num_tri_filter = 26; options.num_cepstral_coeff = 12; options.lifter_param = 22; options.use_vad = true; options.noise_level = 5; pipeline.addFeatureExtractionModule(GRT::MFCC(options)); pipeline.setClassifier(GRT::GMM(16, true, false, 1, 100, 0.001)); pipeline.addPostProcessingModule(GRT::ClassLabelFilter(25, 40)); TrainingDataManager training_data_manager(kNumMaxLabels); if (!load_pipeline) { // We load the training data and train the model if (training_data_manager.load(kTrainingDataFilename)) { auto d = training_data_manager.getSample(1, 2); if (draw_sample) { plt::plot(training_data_manager.getSample(1, 2).getColVector(0)); plt::save("./sample.png"); } if (pipeline.train(training_data_manager.getAllData())) { std::cout << "Training Successful" << std::endl;; pipeline.save(kPipelineFilename); } else { std::cout << "Failed to train the model" << std::endl; return -1; } } } else { pipeline.load(kPipelineFilename); } GRT::MatrixDouble test_data; if (!test_data.load(kTestDataFilename)) { std::cout << "Failed to load test data from " << kTestDataFilename << std::endl; return -1; } size_t vec_size = test_data.getNumRows(); std::vector<double> x(vec_size, 0); std::vector<double> preds(vec_size, 0); std::vector<double> audio(vec_size, 0); std::vector<double> distances1(vec_size, 0); std::vector<double> distances2(vec_size, 0); std::cout << "Running testing" << std::endl; // Run test data through for (uint32_t i = 0; i < test_data.getNumRows(); i++) { auto td = test_data.getRowVector(i); pipeline.predict(td); uint32_t predicted_label = pipeline.getPredictedClassLabel(); auto ds = pipeline.getClassDistances(); audio[i] = td[0]; x[i] = i; preds[i] = static_cast<double>(predicted_label); distances1[i] = ds[0]; distances2[i] = ds[1]; } // std::cout << "Test finished, plotting ... "; // plt::plot(x, audio, "b-"); // plt::save("./audio.png"); plt::plot(x, distances1, "r.", x, distances2, "g."); plt::save("./prediction.png"); std::cout << "Done" << std::endl; return 0; }