Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions src/base/kaldi-utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#endif

#include <string>
#include <sstream>
#include "base/kaldi-utils.h"
#include "base/kaldi-common.h"


Expand All @@ -44,17 +42,6 @@ std::string CharToString(const char &c) {
return (std::string) buf;
}

std::string StringToReadable(const std::string& s) {
std::stringstream ss;
for (size_t i = 0; i < s.length(); ++i) {
if (std::isprint(s[i]))
ss << s[i];
else
ss << "[character " << static_cast<int>(s[i]) << "]";
}
return ss.str();
}

void Sleep(float seconds) {
#if defined(_MSC_VER) || defined(MINGW)
::Sleep(static_cast<int>(seconds * 1000.0));
Expand Down
2 changes: 0 additions & 2 deletions src/base/kaldi-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ namespace kaldi {
// CharToString prints the character in a human-readable form, for debugging.
std::string CharToString(const char &c);

// StringToReadable ensures the string can show up on console, for debugging.
std::string StringToReadable(const std::string& str);

inline int MachineIsLittleEndian() {
int check = 1;
Expand Down
13 changes: 6 additions & 7 deletions src/matrix/kaldi-matrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
// See the Apache 2 License for the specific language governing permissions and
// limitations under the License.

#include "base/kaldi-utils.h"
#include "matrix/kaldi-matrix.h"
#include "matrix/sp-matrix.h"
#include "matrix/jama-svd.h"
Expand Down Expand Up @@ -1488,8 +1487,8 @@ void Matrix<Real>::Read(std::istream & is, bool binary, bool add) {
std::string token;
ReadToken(is, binary, &token);
if (token != my_token) {
specific_error << ": Expected token " << my_token
<< ", got " << StringToReadable(token);
if (token.length() > 20) token = token.substr(0, 17) + "...";
specific_error << ": Expected token " << my_token << ", got " << token;
goto bad;
}
int32 rows, cols;
Expand Down Expand Up @@ -1522,8 +1521,8 @@ void Matrix<Real>::Read(std::istream & is, bool binary, bool add) {
// }
if (str == "[]") { Resize(0, 0); return; } // Be tolerant of variants.
else if (str != "[") {
specific_error << ": Expected \"[\", got \""
<< StringToReadable(str) << '"';
if (str.length() > 20) str = str.substr(0, 17) + "...";
specific_error << ": Expected \"[\", got \"" << str << '"';
goto bad;
}
// At this point, we have read "[".
Expand Down Expand Up @@ -1594,8 +1593,8 @@ void Matrix<Real>::Read(std::istream & is, bool binary, bool add) {
cur_row->push_back(std::numeric_limits<Real>::quiet_NaN());
KALDI_WARN << "Reading NaN value into matrix.";
} else {
specific_error << "Expecting numeric matrix data, got "
<< StringToReadable(str);
if (str.length() > 20) str = str.substr(0, 17) + "...";
specific_error << "Expecting numeric matrix data, got " << str;
goto cleanup;
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/matrix/kaldi-vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

#include <algorithm>
#include <string>

#include "base/kaldi-utils.h"
#include "matrix/cblas-wrappers.h"
#include "matrix/kaldi-vector.h"
#include "matrix/kaldi-matrix.h"
Expand Down Expand Up @@ -1124,8 +1122,8 @@ void Vector<Real>::Read(std::istream & is, bool binary, bool add) {
std::string token;
ReadToken(is, binary, &token);
if (token != my_token) {
specific_error << ": Expected token " << my_token
<< ", got " << StringToReadable(token);
if (token.length() > 20) token = token.substr(0, 17) + "...";
specific_error << ": Expected token " << my_token << ", got " << token;
goto bad;
}
int32 size;
Expand All @@ -1149,7 +1147,8 @@ void Vector<Real>::Read(std::istream & is, bool binary, bool add) {
if (is.fail()) { specific_error << "EOF while trying to read vector."; goto bad; }
if (s.compare("[]") == 0) { Resize(0); return; } // tolerate this variant.
if (s.compare("[")) {
specific_error << "Expected \"[\" but got " << StringToReadable(s);
if (s.length() > 20) s = s.substr(0, 17) + "...";
specific_error << "Expected \"[\" but got " << s;
goto bad;
}
std::vector<Real> data;
Expand Down Expand Up @@ -1198,8 +1197,8 @@ void Vector<Real>::Read(std::istream & is, bool binary, bool add) {
data.push_back(std::numeric_limits<Real>::quiet_NaN());
KALDI_WARN << "Reading NaN value into vector.";
} else {
specific_error << "Expecting numeric vector data, got "
<< StringToReadable(s);
if (s.length() > 20) s = s.substr(0, 17) + "...";
specific_error << "Expecting numeric vector data, got " << s;
goto bad;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/util/kaldi-holder-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ template<class BasicType> class BasicVectorHolder {
return true;
} catch(const std::exception &e) {
KALDI_WARN << "BasicVectorHolder::Read, could not interpret line: "
<< "'" << StringToReadable(line) << "'" << "\n" << e.what();
<< "'" << line << "'" << "\n" << e.what();
return false;
}
} else { // binary mode.
Expand Down Expand Up @@ -658,8 +658,8 @@ class TokenHolder {
while (isspace(c = is.peek()) && c!= '\n') is.get();
if (is.peek() != '\n') {
KALDI_WARN << "TokenHolder::Read, expected newline, got char "
<< CharToString(is.peek())
<< ", at stream pos " << is.tellg();
<< CharToString(is.peek())
<< ", at stream pos " << is.tellg();
return false;
}
is.get(); // get '\n'
Expand Down