void render_overlay(struct configuration *config, struct state *programState) { char msg[128]; int len; int rowSpacing = 4; int rowHeight = stats_font.pixel_height + rowSpacing; int bottom = 7; int left = 5; #define ROWS(n) (n * rowHeight) len = snprintf(msg, sizeof(msg), "%d/%d sample%s%s | radius %f | depth %d", programState->sampleNum, config->sampleRoot * config->sampleRoot, (config->sampleRoot == 1 ? "" : "s"), (config->paused ? "*" : ""), programState->lens_radius, config->traceDepth); renderText(text_config, &stats_font, msg, len, left, bottom, 1, overlay_text_color); char frameTimeMsg[64]; if (programState->last_frame_time != -1) { len = snprintf(frameTimeMsg, sizeof(frameTimeMsg), "Frame time: %.3f sec", programState->last_frame_time); renderText(text_config, &stats_font, frameTimeMsg, len, left, bottom + ROWS(1), 1, overlay_text_color); } else { len = snprintf(frameTimeMsg, sizeof(frameTimeMsg), "Frame time: ..."); renderText(text_config, &stats_font, frameTimeMsg, len, left, bottom + ROWS(1), 1, overlay_text_color); } }
int go() { int i; int *deck = XCALLOC(cards * sizeof(int)); int ret; pixel *image; /* init deck */ for (i = 0; i < cards; i++) { deck[i] = i * 360 / cards; } /* shuffle */ for (i = 0; i < reps; i++) { switch (mode) { case PILE: shuffle_pile (deck); break; case RIFFLE: shuffle_riffle(deck); break; case RANDOM: shuffle_random(deck); break; default: assert(0); } } image = flatten(deck); free(deck); ret = writeFile(file, ROWS(), COLS(), image); free(image); return ret; }
/* best_state_sequence - * Calculates the best state sequence of entire model given the feature data. */ int *best_state_sequence(Model *m, RMat data) { int u, uu = m->uu, *rv; RVec *logL; logL = (RVec *)safe_malloc(uu*sizeof(RVec)); for (u = 0; u<uu; u++) { assert(ROWS(data)==m->ffm[u]->ii); logL[u] = allocRVec(COLUMNS(data)); FFM_logL(m->ffm[u], logL[u], data);} rv = HMM_best_state_sequence(m->hmm, logL); for (u = 0; u<uu; u++) freeRVec(logL[u]); free(logL); return rv;}
/* HMM_initGlobals - * Given a number of states and a sequence length, allocates or reallocates * memory for internal variables. */ void HMM_initGlobals(int uu, int tt) { if (g_alpha==NULL||COLUMNS(g_alpha)<tt||ROWS(g_alpha)<uu) { if (g_alpha!=NULL) { freeRMat(g_alpha); freeRMat(g_delta); freeRMat(g_deltav); /* This could be int. */ freeRMat(g_beta); freeRMat3d(g_psi);} g_alpha = allocRMat(uu, tt); g_delta = allocRMat(uu, tt); g_deltav = allocRMat(uu, tt); /* This could be int. */ g_beta = allocRMat(uu, tt); g_psi = allocRMat3d(uu, uu, tt);}}
/* logLike - * Calculates log likelihood of entire model given the feature data. */ Real logLike(Model *m, RMat data) { int u, uu = m->uu; RVec *logL; Real rv; logL = (RVec *)safe_malloc(uu*sizeof(RVec)); for (u = 0; u<uu; u++) { assert(ROWS(data)==m->ffm[u]->ii); logL[u] = allocRVec(COLUMNS(data)); FFM_logL(m->ffm[u], logL[u], data);} rv = HMM_logL(m->hmm, logL); for (u = 0; u<uu; u++) freeRVec(logL[u]); free(logL); /* needs work: Why is rv divided by the number of features? */ return rv/model_ii(m);}
void DeliciousTest::testMusic1() { QUrl url = QUrl::fromLocalFile(QFINDTESTDATA("data/delicious1_music.xml")); Tellico::Import::DeliciousImporter importer(url); Tellico::Data::CollPtr coll = importer.collection(); QVERIFY(coll); QCOMPARE(coll->type(), Tellico::Data::Collection::Album); QCOMPARE(coll->entryCount(), 3); // first a movie Tellico::Data::EntryPtr entry = coll->entryById(1); QVERIFY(entry); QCOMPARE(entry->field("title"), QLatin1String("Are You Listening?")); QCOMPARE(entry->field("artist"), QLatin1String("Dolores O'Riordan")); QCOMPARE(entry->field("year"), QLatin1String("2007")); QCOMPARE(entry->field("medium"), QLatin1String("Compact Disc")); QCOMPARE(entry->field("label"), QLatin1String("Sanctuary Records")); QCOMPARE(ROWS(entry, "track").count(), 12); QCOMPARE(ROWS(entry, "track").first(), QLatin1String("Ordinary Day")); QCOMPARE(entry->field("pur_price"), QLatin1String("$15.98")); QCOMPARE(entry->field("pur_date"), QLatin1String("27-06-2008")); QCOMPARE(entry->field("rating"), QLatin1String("4.5")); }
/* ** Print the contents of the TermBuffer. */ static void _termBufferPrintBuffer ( const TermBuffer tb ) { short i; short j; short k; if (tb == NULL) { printf("TermBuffer has been freed.\n"); return; } printf("TermBuffer dimensions:\n"); printf(" rows: %d\n", ROWS(tb)); printf(" cols: %d\n", COLS(tb)); for (i = 0; i < ROWS(tb); i++) { _termBufferPrintLine(tb, i); } }
pixel *flatten(int *deck) { int rows = ROWS(); int cols = COLS(); pixel *flat = XCALLOC(rows * cols * sizeof(pixel)); int i, j; for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { pixel *pp = &flat[(i * cols) + j]; *pp = colorize(deck[j / CARD_WIDTH]); if (!(pp->red > 0 || pp->green > 0 || pp->blue > 0)) { printf("Pixel %d,%d (#%d) failed\n", i,j, j/CARD_WIDTH); } } } return flat; }
void load_input_with_image(IMAGE *img,BPNN *net) { double *units; int nr, nc, imgsize, i, j, k; nr = ROWS(img); nc = COLS(img); imgsize = nr * nc;; if (imgsize != net->input_n) { printf("LOAD_INPUT_WITH_IMAGE: This image has %d pixels,\n", imgsize); printf(" but your net has %d input units. I give up.\n", net->input_n); exit (-1); } units = net->input_units; k = 1; for (i = 0; i < nr; i++) { for (j = 0; j < nc; j++) { units[k] = ((double) img_getpixel(img, i, j)) / 255.0; k++; } } }
TETRIS_API void tetris_remove_full_rows(Tetris *object) { zuint8 row_count = object->full_row_count; if (row_count) { zuint delta = 0, size; zuint x_size = object->size.x; zuint8 index = row_count; TetrisCell *matrix = object->matrix, *row, *row_above, *row_below, cell; while (row_count) { row = ROWS(FULL_ROW_INDICES(--row_count)); row_above = row - x_size; row_below = row + x_size; for (index = x_size; index;) { if (!(cell = row[--index]).fields.top_edge) row_above[index].fields.bottom_edge = TRUE; if (!cell.fields.bottom_edge) row_below[index].fields.top_edge = TRUE; } } for (index = row_count = object->full_row_count; --index;) { delta++; if ((size = FULL_ROW_INDICES(index) - FULL_ROW_INDICES(index - 1) - 1)) z_move (ROWS(FULL_ROW_INDICES(index - 1) + 1), x_size * size, ROWS(FULL_ROW_INDICES(index - 1) + 1 + delta)); } z_move (ROWS(object->top), x_size * (FULL_ROW_INDICES(0) - object->top), ROWS(object->top + row_count)); z_block_int8_set(ROWS(object->top), x_size * row_count, 0); object->full_row_count = 0; object->top += row_count; } }
struct gui_t *gui_init(int angle) { struct gui_t *gui; FB *fb; gui = malloc(sizeof(*gui)); if (NULL == gui) { DPRINTF("Can't allocate memory for GUI structure"); return NULL; } /* init framebuffer */ fb = fb_new(angle); if (NULL == fb) { log_msg(lg, "Can't initialize framebuffer"); free(gui); return NULL; } gui->fb = fb; /* Tune GUI size */ #ifdef USE_FBUI_WIDTH if (fb->width > USE_FBUI_WIDTH) gui->width = USE_FBUI_WIDTH; else #endif gui->width = fb->width; #ifdef USE_FBUI_HEIGHT if (fb->height > USE_FBUI_HEIGHT) gui->height = USE_FBUI_HEIGHT; else #endif gui->height = fb->height; gui->x = (fb->width - gui->width)/2; gui->y = (fb->height - gui->height)/2; #ifdef USE_ICONS /* Parse compiled images. * We don't care about result because drawing code is aware */ int bpp; bpp = fb->bpp; gui->icons = malloc(sizeof(*(gui->icons)) * ICON_ARRAY_SIZE); gui->icons[ICON_LOGO] = xpm_parse_image(logo_xpm, ROWS(logo_xpm), bpp); gui->icons[ICON_STORAGE] = xpm_parse_image(storage_xpm, ROWS(storage_xpm), bpp); gui->icons[ICON_MMC] = xpm_parse_image(mmc_xpm, ROWS(mmc_xpm), bpp); gui->icons[ICON_MEMORY] = xpm_parse_image(memory_xpm, ROWS(memory_xpm), bpp); gui->icons[ICON_SYSTEM] = xpm_parse_image(system_xpm, ROWS(system_xpm), bpp); gui->icons[ICON_BACK] = xpm_parse_image(back_xpm, ROWS(back_xpm), bpp); gui->icons[ICON_RESCAN] = xpm_parse_image(rescan_xpm, ROWS(rescan_xpm), bpp); gui->icons[ICON_DEBUG] = xpm_parse_image(debug_xpm, ROWS(debug_xpm), bpp); gui->icons[ICON_REBOOT] = xpm_parse_image(reboot_xpm, ROWS(reboot_xpm), bpp); gui->icons[ICON_SHUTDOWN] = xpm_parse_image(shutdown_xpm, ROWS(shutdown_xpm), bpp); gui->icons[ICON_EXIT] = xpm_parse_image(exit_xpm, ROWS(exit_xpm), bpp); #endif #ifdef USE_BG_BUFFER /* Pre-draw background and store it in special buffer */ draw_background_low(gui); gui->bg_buffer = fb_dump(fb); #endif return gui; }
/** * Computes the Levenshtein distance of two strings. * Adapted from Stephen Toub's C# implementation. * http://blogs.msdn.com/b/toub/archive/2006/05/05/590814.aspx * @param x first string * @param y second string * @return Levenshtein distance */ static float dist_levenshtein_compare_toub(hstring_t x, hstring_t y) { int i, j, a, b; if (x.len == 0 && y.len == 0) return 0; /* * Rather than maintain an entire matrix (which would require O(n*m) * space), just store the current row and the next row, each of which * has a length m+1, so just O(m) space. Initialize the curr row. */ int curr = 0, next = 1; int *rows = malloc(sizeof(int) * (y.len + 1) * 2); if (!rows) { error("Failed to allocate memory for Levenshtein distance"); return 0; } for (j = 0; j <= y.len; j++) ROWS(curr,j) = j; /* For each virtual row (we only have physical storage for two) */ for (i = 1; i <= x.len; i++) { /* Fill in the values in the row */ ROWS(next,0) = i; for (j = 1; j <= y.len; j++) { /* Insertion and deletion */ a = ROWS(curr,j) + cost_ins; b = ROWS(next, j - 1) + cost_del; if (a > b) a = b; /* Substitution */ b = ROWS(curr, j - 1) + (hstring_compare(x, i - 1, y, j - 1) ? cost_sub : 0); if (a > b) a = b; /* * Transpositions (Damerau-Levenshtein) are not supported by * this implementation, as only two rows of the distance matrix * are available. Potential fix: provide three rows. */ ROWS(next, j) = a; } /* Swap the current and next rows */ if (curr == 0) { curr = 1; next = 0; } else { curr = 0; next = 1; } } double d = ROWS(curr, y.len); /* Free memory */ free(rows); return d; }
struct TypeUint8 { public: static const TText* const KType; static const TUint KValues[]; static const TSelectTest KTests[]; }; const TText* const TypeUint8::KType=_S("UNSIGNED TINYINT"); const TUint TypeUint8::KValues[]={0,1,127,128,254,255}; const TSelectTest TypeUint8::KTests[]= { {_S("IS NULL"),ROW(0)}, {_S("IS NOT NULL"),ALL_ROWS}, {_S("=0"),ROW(1)}, {_S("=3"),NO_ROWS}, {_S("<2"),ROWS(1,2)}, {_S(">=0"),ALL_ROWS}, {_S("<128"),ROWS(1,3)}, {_S("<>1"),ALL_ROWS-ROW(2)}, {_S(">255"),NO_ROWS} }; struct TypeUint16 { public: static const TText* const KType; static const TUint KValues[]; static const TSelectTest KTests[]; }; const TText* const TypeUint16::KType=_S("UNSIGNED SMALLINT"); const TUint TypeUint16::KValues[]={0,1,5000,32767,32768,65534,65535};