static void test_increment_stat_fails_if_key_is_NULL() { assert_true( init_stat() ); expect_assert_failure( increment_stat( NULL ) ); assert_true( finalize_stat() ); }
static void test_reset_stats_succeeds_with_multiple_entries() { assert_true( init_stat() ); const char *keys[] = { "key0", "key1" }; increment_stat( keys[ 0 ] ); increment_stat( keys[ 1 ] ); reset_stats(); hash_iterator iter; hash_entry *e = NULL; init_hash_iterator( stats, &iter ); int n_entries = 0; while ( ( e = iterate_hash_next( &iter ) ) != NULL ) { n_entries++; } assert_int_equal( n_entries, 0 ); assert_true( finalize_stat() ); }
static void test_dump_stats_succeeds() { assert_true( init_stat() ); const char *key = "key"; increment_stat( key ); expect_string( mock_info, message, "Statistics:" ); expect_string( mock_info, message, "key: 1" ); dump_stats(); assert_true( finalize_stat() ); }
static void test_foreach_stat_succeeds() { assert_true( init_stat() ); const char *keys[] = { "key0", "key1" }; increment_stat( keys[ 0 ] ); increment_stat( keys[ 1 ] ); increment_stat( keys[ 1 ] ); void *user_data = ( void * ) ( intptr_t ) 0x1; expect_string( mock_callback, key, keys[ 1 ] ); expect_value( mock_callback, value, 2 ); expect_value( mock_callback, user_data, user_data ); expect_string( mock_callback, key, keys[ 0 ] ); expect_value( mock_callback, value, 1 ); expect_value( mock_callback, user_data, user_data ); foreach_stat( mock_callback, user_data ); assert_true( finalize_stat() ); }
static void test_increment_stat_succeeds_with_undefined_key() { assert_true( init_stat() ); const char *key = "key"; increment_stat( key ); stat_entry *entry = lookup_hash_entry( stats, key ); assert_string_equal( entry->key, key ); uint64_t expected_value = 1; assert_memory_equal( &entry->value, &expected_value, sizeof( uint64_t ) ); assert_true( finalize_stat() ); }
static void test_increment_stat_fails_if_not_initialized() { const char *key = "key"; expect_assert_failure( increment_stat( key ) ); }
void gmm_compute(void *data, utt_res_t * ur, int32 sf, int32 ef, char *uttid) { kb_t *kb; kbcore_t *kbcore; mdef_t *mdef; dict_t *dict; dict2pid_t *d2p; mgau_model_t *mgau; subvq_t *svq; gs_t *gs; int32 ptranskip; int32 s, f, t; int32 single_el_list[2]; stats_t cur_ci_st; stats_t cur_cd_st; stats_t cur_cd_Nbest_st; stats_t *stptr; char str[100]; int32 *idx; int32 *cur_bstidx; int32 *last_bstidx; int32 *cur_scr; int32 *last_scr; int32 tmpint; s3senid_t *cd2cisen; int32 pheurtype; E_INFO("Processing: %s\n", uttid); kb = (kb_t *) data; kbcore = kb->kbcore; mdef = kbcore_mdef(kbcore); dict = kbcore_dict(kbcore); d2p = kbcore_dict2pid(kbcore); mgau = kbcore_mgau(kbcore); svq = kbcore_svq(kbcore); gs = kbcore_gs(kbcore); kb->uttid = uttid; ptranskip = kb->beam->ptranskip; pheurtype = kb->pl->pheurtype; single_el_list[0] = -1; single_el_list[1] = -1; /* Read mfc file and build feature vectors for entire utterance */ kb->stat->nfr = feat_s2mfc2feat(kbcore_fcb(kbcore), ur->uttfile, cmd_ln_str("-cepdir"), ".mfc", sf, ef, kb->feat, S3_MAX_FRAMES); cd2cisen = mdef_cd2cisen(mdef); /*This should be a procedure instead of just logic */ init_stat(&cur_cd_st, "Current CD Senone"); init_stat(&cur_ci_st, "Current CI Senone"); init_stat(&cur_cd_Nbest_st, "Current CD NBest Senone"); for (s = 0; s < mdef->n_ci_sen; s++) { sprintf(str, "Cur Senone %d", s); init_stat(&cur_sen_st[s], str); } for (t = 0; t < (int32) (mdef->n_sen - mdef->n_ci_sen) / NBEST_STEP; t++) { sprintf(str, " %d -Cur Best Senone", t * NBEST_STEP); init_stat(&cur_sen_Nbest_st[t], str); } idx = ckd_calloc(mdef->n_sen - mdef->n_ci_sen, sizeof(int32)); /* Allocate temporary array for CurScr and Curbst indx and Lat index */ cur_bstidx = ckd_calloc(mdef->n_sen, sizeof(int32)); last_bstidx = ckd_calloc(mdef->n_sen, sizeof(int32)); cur_scr = ckd_calloc(mdef->n_sen, sizeof(int32)); last_scr = ckd_calloc(mdef->n_sen, sizeof(int32)); for (f = 0; f < kb->stat->nfr; f++) { for (s = 0; s < mgau->n_mgau; s++) { /*1, Compute the approximate scores with the last best index. */ if (mgau->mgau[s].bstidx != NO_BSTIDX) { single_el_list[0] = mgau->mgau[s].bstidx; last_bstidx[s] = mgau->mgau[s].bstidx; last_scr[s] = mgau_eval(mgau, s, single_el_list, kb->feat[f][0], f, 0); } else { last_bstidx[s] = NO_BSTIDX; } /*2, Compute the exact scores and sort them and get the ranking. */ kb->ascr->senscr[s] = mgau_eval(mgau, s, NULL, kb->feat[f][0], f, 1); /*3, Compute the approximate scores with the current best index */ if (mgau->mgau[s].bstidx != NO_BSTIDX) { single_el_list[0] = mgau->mgau[s].bstidx; cur_bstidx[s] = mgau->mgau[s].bstidx; cur_scr[s] = mgau_eval(mgau, s, single_el_list, kb->feat[f][0], f, 0); } else { cur_bstidx[s] = NO_BSTIDX; } /* Only test for CD senones, test for best index hit */ /*Update either CI senone and CD senone) */ if (!mdef_is_cisenone(mdef, s)) stptr = &cur_cd_st; else stptr = &cur_ci_st; increment_stat(stptr, abs(last_scr[s] - kb->ascr->senscr[s]), abs(cur_scr[s] - kb->ascr->senscr[s]), abs(kb->ascr->senscr[cd2cisen[s]] - kb->ascr->senscr[s]), (cur_bstidx[s] == last_bstidx[s])); if (!mdef_is_cisenone(mdef, s)) { stptr = &cur_sen_st[cd2cisen[s]]; increment_stat(stptr, abs(last_scr[s] - kb->ascr->senscr[s]), abs(cur_scr[s] - kb->ascr->senscr[s]), abs(kb->ascr->senscr[cd2cisen[s]] - kb->ascr->senscr[s]), (cur_bstidx[s] == last_bstidx[s])); stptr->total_senone += 1; } } cur_cd_st.total_fr++; cur_cd_st.total_senone += mdef->n_sen - mdef->n_ci_sen; cur_ci_st.total_fr++; cur_ci_st.total_senone += mdef->n_ci_sen; for (s = 0; s < mdef->n_ci_sen; s++) { cur_sen_st[s].total_fr++; } /*This is the part we need to do sorting */ /*1, sort the scores in the current frames */ /*E_INFO("At frame %d\n",f); */ /*Pointer trick at here. */ for (s = 0; s < mdef->n_sen - mdef->n_ci_sen; s++) { idx[s] = s; } cd = &(kb->ascr->senscr[mdef->n_ci_sen]); qsort(idx, mdef->n_sen - mdef->n_ci_sen, sizeof(int32), intcmp_gmm_compute); /*This loop is stupid and it is just a hack. */ for (s = 0; s < mdef->n_sen - mdef->n_ci_sen; s++) { tmpint = idx[s] + mdef->n_ci_sen; for (t = 0; t < (int32) ((float) (mdef->n_sen - mdef->n_ci_sen) / (float) NBEST_STEP); t++) { if (s < t * NBEST_STEP) { increment_stat(&cur_sen_Nbest_st[t], abs(last_scr[tmpint] - kb->ascr->senscr[tmpint]), abs(cur_scr[tmpint] - kb->ascr->senscr[tmpint]), abs(kb->ascr->senscr[cd2cisen[tmpint]] - kb->ascr->senscr[tmpint]), (cur_bstidx[tmpint] == last_bstidx[tmpint])); cur_sen_Nbest_st[t].total_senone += 1; } } } for (t = 0; t < (int32) ((float) (mdef->n_sen - mdef->n_ci_sen) / (float) NBEST_STEP); t++) { cur_sen_Nbest_st[t].total_fr++; } } print_stat(&cur_cd_st); print_stat(&cur_ci_st); print_stat(&cur_sen_Nbest_st[1]); /*Only show the first NBEST_STEP best */ add_stat(&cd_st, &cur_cd_st); add_stat(&ci_st, &cur_ci_st); for (s = 0; s < mdef->n_ci_sen; s++) { add_stat(&sen_st[s], &cur_sen_st[s]); } for (s = 0; s < (int32) (mdef->n_sen - mdef->n_ci_sen) / NBEST_STEP; s++) { add_stat(&sen_Nbest_st[s], &cur_sen_Nbest_st[s]); } ckd_free(idx); ckd_free(cur_bstidx); ckd_free(last_bstidx); ckd_free(cur_scr); ckd_free(last_scr); }