summaryrefslogtreecommitdiff
path: root/kaldi_seq/src/init.c
diff options
context:
space:
mode:
authorYimmon Zhuang <[email protected]>2015-09-18 22:18:47 +0800
committerYimmon Zhuang <[email protected]>2015-09-18 22:18:47 +0800
commit74809198a31cb7d902de23c217ca7492b5f8a29b (patch)
treef14bf7081491f4b40b2a9fcccc17228b0142181f /kaldi_seq/src/init.c
parent84a91188a4c6e660c1c3d5df2f450c177f4e2fe8 (diff)
mpe implement
Diffstat (limited to 'kaldi_seq/src/init.c')
-rw-r--r--kaldi_seq/src/init.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/kaldi_seq/src/init.c b/kaldi_seq/src/init.c
new file mode 100644
index 0000000..88d0a80
--- /dev/null
+++ b/kaldi_seq/src/init.c
@@ -0,0 +1,73 @@
+#include "nerv/common.h"
+#include "kaldi_mpe.h"
+#include <stdio.h>
+
+const char *nerv_kaldi_mpe_tname = "nerv.KaldiMPE";
+const char *nerv_matrix_cuda_float_tname = "nerv.CuMatrixFloat";
+const char *nerv_matrix_host_float_tname = "nerv.MMatrixFloat";
+
+static int mpe_new(lua_State *L) {
+ const char *arg = luaL_checkstring(L, 1);
+ const char *mdl = luaL_checkstring(L, 2);
+ const char *lat = luaL_checkstring(L, 3);
+ const char *ali = luaL_checkstring(L, 4);
+ KaldiMPE *mpe = new_KaldiMPE(arg, mdl, lat, ali);
+ luaT_pushudata(L, mpe, nerv_kaldi_mpe_tname);
+ return 1;
+}
+
+static int mpe_destroy(lua_State *L) {
+ KaldiMPE *mpe = luaT_checkudata(L, 1, nerv_kaldi_mpe_tname);
+ destroy_KaldiMPE(mpe);
+ return 0;
+}
+
+static int mpe_check(lua_State *L) {
+ KaldiMPE *mpe = luaT_checkudata(L, 1, nerv_kaldi_mpe_tname);
+ const Matrix *cumat = luaT_checkudata(L, 2, nerv_matrix_cuda_float_tname);
+ const char *utt = luaL_checkstring(L, 3);
+
+ lua_pushboolean(L, check_mpe(mpe, cumat, utt));
+ return 1;
+}
+
+static int mpe_calc_diff(lua_State *L) {
+ KaldiMPE *mpe = luaT_checkudata(L, 1, nerv_kaldi_mpe_tname);
+ Matrix *mat = luaT_checkudata(L, 2, nerv_matrix_host_float_tname);
+ const char *utt = luaL_checkstring(L, 3);
+
+ Matrix *diff = calc_diff_mpe(mpe, mat, utt);
+ luaT_pushudata(L, diff, nerv_matrix_host_float_tname);
+ return 1;
+}
+
+static int mpe_get_num_frames(lua_State *L) {
+ KaldiMPE *mpe = luaT_checkudata(L, 1, nerv_kaldi_mpe_tname);
+ lua_pushnumber(L, get_num_frames_mpe(mpe));
+ return 1;
+}
+
+static int mpe_get_utt_frame_acc(lua_State *L) {
+ KaldiMPE *mpe = luaT_checkudata(L, 1, nerv_kaldi_mpe_tname);
+ lua_pushnumber(L, get_utt_frame_acc_mpe(mpe));
+ return 1;
+}
+
+static const luaL_Reg mpe_methods[] = {
+ {"check", mpe_check},
+ {"calc_diff", mpe_calc_diff},
+ {"get_num_frames", mpe_get_num_frames},
+ {"get_utt_frame_acc", mpe_get_utt_frame_acc},
+ {NULL, NULL}
+};
+
+static void mpe_init(lua_State *L) {
+ luaT_newmetatable(L, nerv_kaldi_mpe_tname, NULL,
+ mpe_new, mpe_destroy, NULL);
+ luaL_register(L, NULL, mpe_methods);
+ lua_pop(L, 1);
+}
+
+void kaldi_seq_init(lua_State *L) {
+ mpe_init(L);
+}