diff options
Diffstat (limited to 'kaldi_io/tools/kaldi_to_nerv.cpp')
-rw-r--r-- | kaldi_io/tools/kaldi_to_nerv.cpp | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/kaldi_io/tools/kaldi_to_nerv.cpp b/kaldi_io/tools/kaldi_to_nerv.cpp index 0282b7c..f16de44 100644 --- a/kaldi_io/tools/kaldi_to_nerv.cpp +++ b/kaldi_io/tools/kaldi_to_nerv.cpp @@ -3,23 +3,40 @@ #include <string> #include <cstring> #include <cassert> +#include <cstdlib> char token[1024]; char output[1024]; -double mat[4096][4096]; + +double **new_matrix(int nrow, int ncol) { + double **mat = new double *[nrow]; + int i; + for (i = 0; i < nrow; i++) + mat[i] = new double[ncol]; + return mat; +} + +void free_matrix(double **mat, int nrow, int ncol) { + int i; + for (i = 0; i < nrow; i++) + delete [] mat[i]; + delete [] mat; +} + int main(int argc, char **argv) { FILE *fin; std::ofstream fout; - assert(argc == 3); + assert(argc >= 3); fin = fopen(argv[1], "r"); fout.open(argv[2]); assert(fin != NULL); - int cnt = 0; + int cnt = argc > 3 ? atoi(argv[3]) : 0; bool shift; while (fscanf(fin, "%s", token) != EOF) { int nrow, ncol; int i, j; + double **mat; if (strcmp(token, "<AffineTransform>") == 0) { double lrate, blrate, mnorm; @@ -29,6 +46,7 @@ int main(int argc, char **argv) { fscanf(fin, "%s", token); assert(*token == '['); printf("%d %d\n", nrow, ncol); + mat = new_matrix(nrow, ncol); for (j = 0; j < ncol; j++) for (i = 0; i < nrow; i++) fscanf(fin, "%lf", mat[i] + j); @@ -75,12 +93,14 @@ int main(int argc, char **argv) { fout.seekp(0, std::ios_base::end); cnt++; } + free_matrix(mat, nrow, ncol); } else if ((shift = (strcmp(token, "<AddShift>") == 0)) || strcmp(token, "<Rescale>") == 0) { double lrate, blrate, mnorm; fscanf(fin, "%d %d", &ncol, &ncol); + mat = new_matrix(1, ncol); fscanf(fin, "%s %lf", token, &lrate); fscanf(fin, "%s", token); @@ -107,6 +127,7 @@ int main(int argc, char **argv) { fout.seekp(0, std::ios_base::end); fscanf(fin, "%s", token); assert(*token == ']'); + free_matrix(mat, 1, ncol); } } return 0; |