void LLVMState::compile_callframe(STATE, GCToken gct, CompiledCode* start, CallFrame* call_frame, int primitive) { // TODO: Fix compile policy checks if(!start->keywords()->nil_p()) { metrics().m.jit_metrics.methods_failed++; return; } if(debug_search) { std::cout << std::endl << "JIT: triggered: " << enclosure_name(start) << "#" << symbol_debug_str(start->name()) << std::endl; } CallFrame* candidate = find_candidate(state, start, call_frame); if(!candidate || candidate->jitted_p() || candidate->inline_method_p()) { if(config().jit_show_compiling) { llvm::outs() << "[[[ JIT error finding call frame " << enclosure_name(start) << "#" << symbol_debug_str(start->name()); if(!candidate) { llvm::outs() << " no candidate"; } else { if(candidate->jitted_p()) { llvm::outs() << " candidate is jitted"; } if(candidate->inline_method_p()) { llvm::outs() << " candidate is inlined"; } } llvm::outs() << " ]]]\n"; } return; } if(debug_search) { std::cout << "! "; candidate->print_backtrace(state, 1); } if(candidate->compiled_code->machine_code()->call_count <= 1) { if(!start || start->machine_code()->jitted_p()) return; // Ignore it. compile this one. candidate = call_frame; } if(candidate->block_p()) { compile_soon(state, gct, candidate->compiled_code, call_frame, candidate->self()->direct_class(state), candidate->block_env(), true); } else { if(candidate->compiled_code->can_specialize_p()) { compile_soon(state, gct, candidate->compiled_code, call_frame, candidate->self()->direct_class(state)); } else { compile_soon(state, gct, candidate->compiled_code, call_frame, NULL); } } }
void LLVMState::compile_callframe(STATE, VMMethod* start, CallFrame* call_frame, int primitive) { if(config().jit_inline_debug) { if(start) { llvm::errs() << "JIT: target search from " << symbol_cstr(start->original->scope()->module()->name()) << "#" << symbol_cstr(start->original->name()) << "\n"; } else { llvm::errs() << "JIT: target search from primitive\n"; } } VMMethod* candidate = find_candidate(start, call_frame); if(!candidate) { if(config().jit_inline_debug) { llvm::errs() << "JIT: unable to find candidate\n"; } return; } assert(!candidate->parent()); if(candidate->call_count < 0) { if(!start) return; // Ignore it. compile this one. candidate = start; } compile_soon(state, candidate); }
int main ( int argc , char * argv[] ) { int t , z , i; scanf("%d" , &t); for ( z = 1 ; z <= t ; z++ ) { int n; scanf("%d" , &n); for ( i = 0 ; i < n ; i++ ) { scanf("%d" , &array[i]); } int count = 0; int candidate = find_candidate(n); for ( i = 0 ; i < n ; i++ ) { if ( array[i] == candidate ) { count++; } } if ( count > n/2 ) { printf("YES %d\n" , candidate); } else { printf("NO\n"); } } return 0; }
void LLVMState::compile_callframe(STATE, CompiledMethod* start, CallFrame* call_frame, int primitive) { if(config().jit_inline_debug) { if(start) { log() << "JIT: target search from " << symbol_cstr(start->name()) << "\n"; } else { log() << "JIT: target search from primitive\n"; } } CallFrame* candidate = find_candidate(start, call_frame); if(!candidate || candidate->jitted_p() || candidate->inline_method_p()) { if(config().jit_inline_debug) { log() << "JIT: unable to find candidate\n"; } return; } if(candidate->cm->backend_method()->call_count <= 1) { if(!start || start->backend_method()->jitted()) return; // Ignore it. compile this one. candidate = call_frame; } if(candidate->block_p()) { compile_soon(state, candidate->cm, candidate->block_env()); } else { compile_soon(state, candidate->cm); } }
/* match_pairs() finds for each target in each source camera the candidate targets for correspondence on the other cameras by projecting epipolar lines. Arguments: correspond *list[4][4] - pairwise adjacency lists to be filled with the results. Each is a buffer long enough to contain data for all targets in the source camera of the pair. coord_2d **corrected - the flat-image metric coordinates of targets, by camera, x-sorted. Epipolar lines are projected in flat coordinates. frame *frm - frame data and reference target properties (similarity of size and brightness are used to determine correlation score). volume_par *vpar, control_par *cpar, Calibration **calib - scene parameters. */ void match_pairs(correspond *list[4][4], coord_2d **corrected, frame *frm, volume_par *vpar, control_par *cpar, Calibration **calib) { int i1, i2, i, j, pt1, count; double xa12, ya12, xb12, yb12; /* Epipolar line edges */ candidate cand[MAXCAND]; for (i1 = 0; i1 < cpar->num_cams - 1; i1++) { for (i2 = i1 + 1; i2 < cpar->num_cams; i2++) { for (i=0; i<frm->num_targets[i1]; i++) { if (corrected[i1][i].x == PT_UNUSED) continue; epi_mm (corrected[i1][i].x, corrected[i1][i].y, calib[i1], calib[i2], cpar->mm, vpar, &xa12, &ya12, &xb12, &yb12); /* origin point in the list */ list[i1][i2][i].p1 = i; pt1 = corrected[i1][i].pnr; /* search for a conjugate point in corrected[i2] */ count = find_candidate(corrected[i2], frm->targets[i2], frm->num_targets[i2], xa12, ya12, xb12, yb12, frm->targets[i1][pt1].n, frm->targets[i1][pt1].nx, frm->targets[i1][pt1].ny, frm->targets[i1][pt1].sumg, cand, vpar, cpar, calib[i2]); /* write all corresponding candidates to the preliminary list of correspondences */ if (count > MAXCAND) count = MAXCAND; for (j = 0; j < count; j++) { list[i1][i2][i].p2[j] = cand[j].pnr; list[i1][i2][i].corr[j] = cand[j].corr; list[i1][i2][i].dist[j] = cand[j].tol; } list[i1][i2][i].n = count; } } } }
END_TEST START_TEST(test_find_candidate) { int i; /* set of particles to choose from */ target test_pix[] = { {0, 0.0, -0.2, 5, 1, 2, 10, -999}, {6, 0.2, 0.0, 10, 8, 1, 20, -999}, {3, 0.2, 0.8, 10, 3, 3, 30, -999}, {4, 0.4, -1.1, 10, 3, 3, 40, -999}, {1, 0.7, -0.1, 10, 3, 3, 50, -999}, {7, 1.2, 0.3, 10, 3, 3, 60, -999}, {5, 10.4, 0.1, 10, 3, 3, 70, -999} }; int num_pix = 7; /* length of the test_pix */ /* coord_2d is int pnr, double x,y */ coord_2d test_crd[] = { {0, 0.0, 0.0}, {6, 0.1, 0.1}, /* best candidate, right on the diagonal */ {3, 0.2, 0.8}, {4, 0.4, -1.1}, {1, 0.7, -0.1}, {7, 1.2, 0.3}, {5, 10.4, 0.1} }; /* parameters of the particle for which we look for the candidates */ int n = 10; int nx = 3; int ny = 3; int sumg = 100; candidate test_cand[7]; int count; Exterior test_Ex = { 0.0, 0.0, 100.0, 0.0, 0.0, 0.0, {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}}; Interior test_I = {0.0, 0.0, 100.0}; Glass test_G = {0.0, 0.0, 50.0}; ap_52 test_addp = {0., 0., 0., 0., 0., 1., 0.}; Calibration test_cal = {test_Ex, test_I, test_G, test_addp}; mm_np test_mm = { 1, 1.0, {1.49, 0.0, 0.0}, {5.0, 0.0, 0.0}, 1.33, }; volume_par test_vpar = { {-250., 250.}, {-100., -100.}, {100., 100.}, 0.01, 0.3, 0.3, 0.01, 1.0, 33 }; /* prepare test control parameters, basically for pix_x */ int cam; char img_format[] = "cam%d"; char cal_format[] = "cal/cam%d.tif"; control_par *test_cpar, *cpar; test_cpar = new_control_par(4); for (cam = 0; cam < 4; cam++) { sprintf(test_cpar->img_base_name[cam], img_format, cam + 1); sprintf(test_cpar->cal_img_base_name[cam], cal_format, cam + 1); } test_cpar->hp_flag = 1; test_cpar->allCam_flag = 0; test_cpar->tiff_flag = 1; test_cpar->imx = 1280; test_cpar->imy = 1024; test_cpar->pix_x = 0.02; /* 20 micron pixel */ test_cpar->pix_y = 0.02; test_cpar->chfield = 0; test_cpar->mm->n1 = 1; test_cpar->mm->n2[0] = 1.49; test_cpar->mm->n3 = 1.33; test_cpar->mm->d[0] = 5; /* the result is that the sensor size is 12.8 mm x 10.24 mm */ /* epipolar line */ double xa = -10.; double ya = -10.; double xb = 10.; double yb = 10.; count = find_candidate (test_crd, test_pix, num_pix, xa, ya, xb, yb, n, nx, ny, sumg, test_cand, &test_vpar, test_cpar, &test_cal); free_control_par(test_cpar); /* expected results: */ fail_unless(test_cand[0].pnr = 1); fail_unless(test_cand[0].tol < EPS); /* regression guard */ double sum_corr = 0; for (i = 0; i < count; i++) { sum_corr += test_cand[i].corr; } ck_assert_msg( fabs(sum_corr - 2625.) < EPS && (count == 4) && fabs(test_cand[3].tol - 0.565685) < EPS, "\n Expected ... \n \ but found %f %d %9.6f \n", sum_corr, count, test_cand[3].tol); }
int main(int argc, char *argv[]) { int argi; char *envarea = NULL; char *hffile = "ghosts"; int bgcolor = COL_BLUE; char *ghosts = NULL; sendreturn_t *sres; for (argi = 1; (argi < argc); argi++) { if (argnmatch(argv[argi], "--env=")) { char *p = strchr(argv[argi], '='); loadenv(p+1, envarea); } else if (argnmatch(argv[argi], "--area=")) { char *p = strchr(argv[argi], '='); envarea = strdup(p+1); } else if (strcmp(argv[argi], "--debug") == 0) { debug = 1; } else if (argnmatch(argv[argi], "--hffile=")) { char *p = strchr(argv[argi], '='); hffile = strdup(p+1); } } load_hostnames(xgetenv("HOSTSCFG"), NULL, get_fqdn()); parse_query(); switch (outform) { case O_HTML: fprintf(stdout, "Content-type: %s\n\n", xgetenv("HTMLCONTENTTYPE")); headfoot(stdout, hffile, "", "header", bgcolor); break; case O_TXT: fprintf(stdout, "Content-type: text/plain\n\n"); break; } sres = newsendreturnbuf(1, NULL); if (sendmessage("ghostlist", NULL, XYMON_TIMEOUT, sres) == XYMONSEND_OK) { char *bol, *eoln, *name, *sender, *timestr; time_t tstamp, now; int count, idx; ghost_t *ghosttable; ghosts = getsendreturnstr(sres, 1); /* Count the number of lines */ for (bol = ghosts, count=0; (bol); bol = strchr(bol, '\n')) { if (*bol == '\n') bol++; count++; } ghosttable = (ghost_t *)calloc(count+1, sizeof(ghost_t)); idx = count = 0; tstamp = now = getcurrenttime(NULL); bol = ghosts; while (bol) { name = sender = timestr = NULL; eoln = strchr(bol, '\n'); if (eoln) *eoln = '\0'; name = strtok(bol, "|"); if (name) sender = strtok(NULL, "|"); if (sender) timestr = strtok(NULL, "|"); if (timestr) tstamp = atol(timestr); if (name && sender && timestr && (tstamp > (now - maxage))) { int i1, i2, i3, i4; sscanf(sender, "%d.%d.%d.%d", &i1, &i2, &i3, &i4); ghosttable[idx].sender = sender; ghosttable[idx].senderval = (i1 << 24) + (i2 << 16) + (i3 << 8) + i4; ghosttable[idx].name = name; ghosttable[idx].tstamp = tstamp; find_candidate(&ghosttable[idx]); idx++; count++; } if (eoln) eoln++; bol = eoln; } switch (sorttype) { case S_NAME: qsort(&ghosttable[0], count, sizeof(ghost_t), hostname_compare); break; case S_SENDER: qsort(&ghosttable[0], count, sizeof(ghost_t), sender_compare); break; case S_TIME: qsort(&ghosttable[0], count, sizeof(ghost_t), time_compare); break; } if (outform == O_HTML) { fprintf(stdout, "<table align=center>\n"); fprintf(stdout, "<tr>"); fprintf(stdout, "<th align=left><a href=\"ghostlist.sh?SORT=name&MAXAGE=%d\">Hostname</a></th>", maxage); fprintf(stdout, "<th align=left><a href=\"ghostlist.sh?SORT=sender&MAXAGE=%d\">Sent from</a></th>", maxage); fprintf(stdout, "<th align=left>Candidate</th>"); fprintf(stdout, "<th align=right><a href=\"ghostlist.sh?SORT=time&MAXAGE=%d\">Report age</a></th>", maxage); fprintf(stdout, "</tr>\n"); } for (idx = 0; (idx < count); idx++) { if (!ghosttable[idx].name) continue; if (!ghosttable[idx].sender) continue; switch (outform) { case O_HTML: fprintf(stdout, "<tr><td align=left>%s</td><td align=left>%s</td>", ghosttable[idx].name, ghosttable[idx].sender); if (ghosttable[idx].candidate) { fprintf(stdout, "<td align=left><a href=\"%s\">%s</a></td>", hostsvcurl(xmh_item(ghosttable[idx].candidate, XMH_HOSTNAME), xgetenv("INFOCOLUMN"), 1), xmh_item(ghosttable[idx].candidate, XMH_HOSTNAME)); } else { fprintf(stdout, "<td> </td>"); } fprintf(stdout, "<td align=right>%ld:%02ld</td></tr>\n", (now - ghosttable[idx].tstamp)/60, (now - ghosttable[idx].tstamp)%60); break; case O_TXT: fprintf(stdout, "%s\t\t%s\n", ghosttable[idx].sender, ghosttable[idx].name); break; } } if (outform == O_HTML) { fprintf(stdout, "</table>\n"); fprintf(stdout, "<br><br><center><a href=\"ghostlist.sh?SORT=%s&MAXAGE=%d&TEXT\">Text report</a></center>\n", htmlquoted(sortstring), maxage); } } else fprintf(stdout, "<h3><center>Failed to retrieve ghostlist from server</center></h3>\n"); freesendreturnbuf(sres); if (outform == O_HTML) { headfoot(stdout, hffile, "", "footer", bgcolor); } return 0; }