summaryrefslogtreecommitdiff
path: root/kaldi_io/src
diff options
context:
space:
mode:
Diffstat (limited to 'kaldi_io/src')
-rw-r--r--kaldi_io/src/cwrapper_kaldi.cpp29
-rw-r--r--kaldi_io/src/cwrapper_kaldi.h15
-rw-r--r--kaldi_io/src/init.c17
-rw-r--r--kaldi_io/src/test.c7
4 files changed, 45 insertions, 23 deletions
diff --git a/kaldi_io/src/cwrapper_kaldi.cpp b/kaldi_io/src/cwrapper_kaldi.cpp
index d16f316..83331ce 100644
--- a/kaldi_io/src/cwrapper_kaldi.cpp
+++ b/kaldi_io/src/cwrapper_kaldi.cpp
@@ -10,10 +10,11 @@ extern "C" {
#include "cwrapper_kaldi.h"
#include "string.h"
#include "assert.h"
-#include "nerv/common.h"
+#include "nerv/lib/common.h"
+#include "nerv/lib/matrix/mmatrix.h"
- extern Matrix *nerv_matrix_host_float_create(long nrow, long ncol, Status *status);
- extern Matrix *nerv_matrix_host_double_create(long nrow, long ncol, Status *status);
+ extern Matrix *nerv_matrix_host_float_create(long nrow, long ncol, MContext *context, Status *status);
+ extern Matrix *nerv_matrix_host_double_create(long nrow, long ncol, MContext *context, Status *status);
struct KaldiFeatureRepo {
kaldi::SequentialBaseFloatMatrixReader* feature_reader;
@@ -26,7 +27,8 @@ extern "C" {
return repo;
}
- Matrix *kaldi_feature_repo_read_utterance(KaldiFeatureRepo *repo, lua_State *L, int debug) {
+ Matrix *kaldi_feature_repo_read_utterance(KaldiFeatureRepo *repo, lua_State *L,
+ int debug, MContext *context) {
Matrix *mat; /* nerv implementation */
repo->utt = repo->feature_reader->Key();
@@ -37,9 +39,9 @@ extern "C" {
Status status;
assert(sizeof(BaseFloat) == sizeof(float));
if(sizeof(BaseFloat) == sizeof(float))
- mat = nerv_matrix_host_float_create(n, m, &status);
+ mat = nerv_matrix_host_float_create(n, m, context, &status);
else if(sizeof(BaseFloat) == sizeof(double))
- mat = nerv_matrix_host_double_create(n, m, &status);
+ mat = nerv_matrix_host_double_create(n, m, context, &status);
NERV_LUA_CHECK_STATUS(L, status);
size_t stride = mat->stride;
if (debug)
@@ -99,7 +101,10 @@ extern "C" {
return repo;
}
- Matrix *kaldi_lookup_feature_repo_read_utterance(KaldiLookupFeatureRepo *repo, KaldiFeatureRepo *frepo, int nframes, lua_State *L, int debug) {
+ Matrix *kaldi_lookup_feature_repo_read_utterance(KaldiLookupFeatureRepo *repo,
+ KaldiFeatureRepo *frepo,
+ int nframes, lua_State *L,
+ int debug, MContext *context) {
Matrix *mat; /* nerv implementation */
StringToString_t::iterator mit = repo->map.find(frepo->utt);
if (mit == repo->map.end())
@@ -115,9 +120,9 @@ extern "C" {
Status status;
assert(sizeof(BaseFloat) == sizeof(float));
if(sizeof(BaseFloat) == sizeof(float))
- mat = nerv_matrix_host_float_create(n, m, &status);
+ mat = nerv_matrix_host_float_create(n, m, context, &status);
else if(sizeof(BaseFloat) == sizeof(double))
- mat = nerv_matrix_host_double_create(n, m, &status);
+ mat = nerv_matrix_host_double_create(n, m, context, &status);
NERV_LUA_CHECK_STATUS(L, status);
size_t stride = mat->stride;
if (debug)
@@ -149,7 +154,7 @@ extern "C" {
Matrix *kaldi_label_repo_read_utterance(KaldiLabelRepo *repo, KaldiFeatureRepo *frepo, int nframes,
lua_State *L,
- int debug) {
+ int debug, MContext *context) {
Matrix *mat;
kaldi::Posterior targets = repo->targets_reader->Value(frepo->utt);
@@ -159,9 +164,9 @@ extern "C" {
Status status;
assert(sizeof(BaseFloat) == sizeof(float));
if(sizeof(BaseFloat) == sizeof(float))
- mat = nerv_matrix_host_float_create(n, m, &status);
+ mat = nerv_matrix_host_float_create(n, m, context, &status);
else if(sizeof(BaseFloat) == sizeof(double))
- mat = nerv_matrix_host_double_create(n, m, &status);
+ mat = nerv_matrix_host_double_create(n, m, context, &status);
NERV_LUA_CHECK_STATUS(L, status);
size_t stride = mat->stride;
if (debug)
diff --git a/kaldi_io/src/cwrapper_kaldi.h b/kaldi_io/src/cwrapper_kaldi.h
index c8a7a25..db20087 100644
--- a/kaldi_io/src/cwrapper_kaldi.h
+++ b/kaldi_io/src/cwrapper_kaldi.h
@@ -1,7 +1,7 @@
#ifndef NERV_kaldi_KALDI_IO_CWRAPPER
#define NERV_kaldi_KALDI_IO_CWRAPPER
-#include "nerv/matrix/matrix.h"
-#include "nerv/common.h"
+#include "nerv/lib/matrix/mmatrix.h"
+#include "nerv/lib/common.h"
#ifdef __cplusplus
extern "C" {
#endif
@@ -9,7 +9,8 @@ extern "C" {
typedef struct KaldiFeatureRepo KaldiFeatureRepo;
KaldiFeatureRepo *kaldi_feature_repo_new(const char *);
- Matrix *kaldi_feature_repo_read_utterance(KaldiFeatureRepo *repo, lua_State *L, int debug);
+ Matrix *kaldi_feature_repo_read_utterance(KaldiFeatureRepo *repo, lua_State *L,
+ int debug, MContext *context);
void kaldi_feature_repo_next(KaldiFeatureRepo *repo);
int kaldi_feature_repo_is_end(KaldiFeatureRepo *repo);
const char *kaldi_feature_repo_key(KaldiFeatureRepo *repo);
@@ -21,14 +22,18 @@ extern "C" {
Matrix *kaldi_label_repo_read_utterance(KaldiLabelRepo *repo, KaldiFeatureRepo *, int,
lua_State *L,
- int debug);
+ int debug,
+ MContext *context);
void kaldi_label_repo_destroy(KaldiLabelRepo *repo);
typedef struct KaldiLookupFeatureRepo KaldiLookupFeatureRepo;
KaldiLookupFeatureRepo *kaldi_lookup_feature_repo_new(const char *, const char *);
- Matrix *kaldi_lookup_feature_repo_read_utterance(KaldiLookupFeatureRepo *repo, KaldiFeatureRepo *frepo, int nframes, lua_State *L, int debug);
+ Matrix *kaldi_lookup_feature_repo_read_utterance(KaldiLookupFeatureRepo *repo,
+ KaldiFeatureRepo *frepo,
+ int nframes, lua_State *L,
+ int debug, MContext *context);
void kaldi_lookup_feature_repo_destroy(KaldiLookupFeatureRepo *repo);
#ifdef __cplusplus
diff --git a/kaldi_io/src/init.c b/kaldi_io/src/init.c
index 529895b..e8b4ea6 100644
--- a/kaldi_io/src/init.c
+++ b/kaldi_io/src/init.c
@@ -1,4 +1,5 @@
-#include "nerv/common.h"
+#include "nerv/lib/common.h"
+#include "nerv/matrix/matrix.h"
#include "cwrapper_kaldi.h"
#include <stdio.h>
@@ -21,12 +22,14 @@ static int feat_repo_destroy(lua_State *L) {
}
static int feat_repo_current_utterance(lua_State *L) {
+ MContext *context;
+ MMATRIX_GET_CONTEXT(L, 3);
KaldiFeatureRepo *repo = luaT_checkudata(L, 1, nerv_kaldi_feat_repo_tname);
int debug;
if (!lua_isboolean(L, 2))
nerv_error(L, "debug flag should be a boolean");
debug = lua_toboolean(L, 2);
- Matrix *utter = kaldi_feature_repo_read_utterance(repo, L, debug);
+ Matrix *utter = kaldi_feature_repo_read_utterance(repo, L, debug, context);
luaT_pushudata(L, utter, nerv_matrix_host_float_tname);
return 1;
}
@@ -72,6 +75,8 @@ static int lookup_feat_repo_destroy(lua_State *L) {
}
static int lookup_feat_repo_read_utterance(lua_State *L) {
+ MContext *context;
+ MMATRIX_GET_CONTEXT(L, 5);
KaldiLookupFeatureRepo *repo = luaT_checkudata(L, 1, nerv_kaldi_lookup_feat_repo_tname);
KaldiFeatureRepo *feat_repo = luaT_checkudata(L, 2, nerv_kaldi_feat_repo_tname);
int nframes, debug;
@@ -81,7 +86,8 @@ static int lookup_feat_repo_read_utterance(lua_State *L) {
if (!lua_isboolean(L, 4))
nerv_error(L, "debug flag should be a boolean");
debug = lua_toboolean(L, 4);
- Matrix *utter = kaldi_lookup_feature_repo_read_utterance(repo, feat_repo, nframes, L, debug);
+ Matrix *utter = kaldi_lookup_feature_repo_read_utterance(repo, feat_repo,
+ nframes, L, debug, context);
luaT_pushudata(L, utter, nerv_matrix_host_float_tname);
return 1;
}
@@ -100,6 +106,8 @@ static int label_repo_new(lua_State *L) {
}
static int label_repo_read_utterance(lua_State *L) {
+ MContext *context;
+ MMATRIX_GET_CONTEXT(L, 5);
KaldiLabelRepo *repo = luaT_checkudata(L, 1, nerv_kaldi_label_repo_tname);
KaldiFeatureRepo *feat_repo = luaT_checkudata(L, 2, nerv_kaldi_feat_repo_tname);
int nframes, debug;
@@ -109,7 +117,8 @@ static int label_repo_read_utterance(lua_State *L) {
if (!lua_isboolean(L, 4))
nerv_error(L, "debug flag should be a boolean");
debug = lua_toboolean(L, 4);
- Matrix *utter = kaldi_label_repo_read_utterance(repo, feat_repo, nframes, L, debug);
+ Matrix *utter = kaldi_label_repo_read_utterance(repo, feat_repo, nframes,
+ L, debug, context);
luaT_pushudata(L, utter, nerv_matrix_host_float_tname);
return 1;
}
diff --git a/kaldi_io/src/test.c b/kaldi_io/src/test.c
index e92b4c9..e3368df 100644
--- a/kaldi_io/src/test.c
+++ b/kaldi_io/src/test.c
@@ -7,8 +7,11 @@
**********************************************************************************/
#include "cwrapper_kaldi.h"
+#include "nerv/lib/matrix/mmatrix.h"
#include <stdio.h>
+MContext context;
+
char feature_rspecifier[] = {"ark:/slfs6/users/ymz09/kaldi/src/featbin/copy-feats scp:/slfs6/users/ymz09/swb_ivec/train_bp.scp ark:- |"};
void print_nerv_matrix(Matrix *mat) {
@@ -30,13 +33,13 @@ int main(int argc, char *argv[])
Matrix *mat;
KaldiFeatureRepo *repo = kaldi_feature_repo_new(feature_rspecifier);
- mat = kaldi_feature_repo_read_utterance(repo, NULL, 1);
+ mat = kaldi_feature_repo_read_utterance(repo, NULL, 1, &context);
printf("1st uttrance\n");
print_nerv_matrix(mat);
kaldi_feature_repo_next(repo);
- mat = kaldi_feature_repo_read_utterance(repo, NULL, 1);
+ mat = kaldi_feature_repo_read_utterance(repo, NULL, 1, &context);
printf("2nd uttrance\n");
print_nerv_matrix(mat);