- added char2vec and vec2char

- refactored

git-svn-id: http://moon:8086/svn/software/trunk/projects/Rbm@859 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2022-01-21 15:27:30 +00:00
parent a967f08874
commit 97c9dcce7c
2 changed files with 22 additions and 6 deletions
+18
View File
@@ -14,6 +14,8 @@
#ifndef MATUTILS_HPP
#define MATUTILS_HPP
#include "RnnTextHelper.hpp"
#include <math.h>
namespace Matutils
@@ -66,6 +68,22 @@ namespace Matutils
return x/stddev;
}
inline arma::mat char2vec(char c, size_t len)
{
arma::mat result = arma::zeros(1, len);
int idx = RnnTextHelper::ch2idx(c);
result[idx] = 1;
return result;
}
inline char vec2char(arma::mat const &vec)
{
char result = RnnTextHelper::idx2ch(vec.index_max());
return result;
}
}
#endif /* MATUTILS_HPP */