13 using namespace Eigen;
17 VectorXd Util.loadVector(
string file) {
20 cout <<
"Loading vector from file " << file << endl;
24 fs.open(file.c_str(), ios.in | ios.binary);
26 cerr <<
"Not able to read file " << file << endl;
31 bool le = little_endian();
40 copy(buf, buf +
INT_BYTES, reinterpret_cast<char*>(&n));
43 for (
int l = 0;
l < res.rows();
l++) {
48 copy(buf, buf +
DOUBLE_BYTES, reinterpret_cast<char*>(&tmp));
56 MatrixXd Util.loadMatrix(
string file) {
59 fs.open(file.c_str(), ios.in | ios.binary);
61 cerr <<
"Not able to read file " << file << endl;
66 bool le = little_endian();
75 copy(buf, buf +
INT_BYTES, reinterpret_cast<char*>(&n));
80 copy(buf, buf +
INT_BYTES, reinterpret_cast<char*>(&m));
85 cout <<
"Reading " << res.rows() <<
" x " << res.cols() <<
" matrix" << endl;
88 for (
int i = 0; i < res.rows(); i++) {
89 for (
int j = 0; j < res.cols(); j++) {
95 copy(buf, buf +
DOUBLE_BYTES, reinterpret_cast<char*>(&tmp));
105 inline bool Util.little_endian(
void) {
106 typedef unsigned char* pbyte;
107 static unsigned long word = 0x1;
108 static bool is_little_endian_machine = (*pbyte(&word) == 0x1);
109 return is_little_endian_machine;