Julius 4.2
|
00001 00025 /* 00026 * Copyright (c) 1991-2011 Kawahara Lab., Kyoto University 00027 * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology 00028 * Copyright (c) 2005-2011 Julius project team, Nagoya Institute of Technology 00029 * All rights reserved 00030 */ 00031 00032 #include <sent/stddefs.h> 00033 #include <sent/htk_hmm.h> 00034 #include <sent/htk_param.h> 00035 #include <sent/hmm.h> 00036 #include <sent/hmm_calc.h> 00037 00047 static int 00048 find_insert_point(LOGPROB *calced_score, LOGPROB score, int len) 00049 { 00050 /* binary search on score */ 00051 int left = 0; 00052 int right = len - 1; 00053 int mid; 00054 00055 while (left < right) { 00056 mid = (left + right) / 2; 00057 if (calced_score[mid] > score) { 00058 left = mid + 1; 00059 } else { 00060 right = mid; 00061 } 00062 } 00063 return(left); 00064 } 00065 00087 int 00088 cache_push(HMMWork *wrk, int id, LOGPROB score, int len) 00089 { 00090 int insertp; 00091 LOGPROB *calced_score; 00092 int *calced_id; 00093 00094 calced_score = wrk->OP_calced_score; 00095 calced_id = wrk->OP_calced_id; 00096 00097 if (len == 0) { /* first one */ 00098 calced_score[0] = score; 00099 calced_id[0] = id; 00100 return(1); 00101 } 00102 if (calced_score[len-1] >= score) { /* bottom */ 00103 if (len < wrk->OP_gprune_num) { /* append to bottom */ 00104 calced_score[len] = score; 00105 calced_id[len] = id; 00106 len++; 00107 } 00108 return len; 00109 } 00110 if (calced_score[0] < score) { 00111 insertp = 0; 00112 } else { 00113 insertp = find_insert_point(calced_score, score, len); 00114 } 00115 if (len < wrk->OP_gprune_num) { 00116 memmove(&(calced_score[insertp+1]), &(calced_score[insertp]), sizeof(LOGPROB)*(len - insertp)); 00117 memmove(&(calced_id[insertp+1]), &(calced_id[insertp]), sizeof(int)*(len - insertp)); 00118 } else if (insertp < len - 1) { 00119 memmove(&(calced_score[insertp+1]), &(calced_score[insertp]), sizeof(LOGPROB)*(len - insertp - 1)); 00120 memmove(&(calced_id[insertp+1]), &(calced_id[insertp]), sizeof(int)*(len - insertp - 1)); 00121 } 00122 calced_score[insertp] = score; 00123 calced_id[insertp] = id; 00124 if (len < wrk->OP_gprune_num) len++; 00125 return(len); 00126 } 00127