summaryrefslogtreecommitdiff
path: root/tools/matrixIO.h
diff options
context:
space:
mode:
authorJoe Zhao <ztuowen@gmail.com>2015-03-08 16:02:15 +0800
committerJoe Zhao <ztuowen@gmail.com>2015-03-08 16:02:15 +0800
commite500bb4cdb32b13cc022b6dc5d221de7ad97a73e (patch)
tree643bcf86336437ccee6182fc6d19c92f33b7201a /tools/matrixIO.h
parent457024eedfaf6e08146038c8cb3034e590a81df6 (diff)
downloadranksvm-e500bb4cdb32b13cc022b6dc5d221de7ad97a73e.tar.gz
ranksvm-e500bb4cdb32b13cc022b6dc5d221de7ad97a73e.tar.bz2
ranksvm-e500bb4cdb32b13cc022b6dc5d221de7ad97a73e.zip
added commandline parser
Diffstat (limited to 'tools/matrixIO.h')
-rw-r--r--tools/matrixIO.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/tools/matrixIO.h b/tools/matrixIO.h
new file mode 100644
index 0000000..88cd419
--- /dev/null
+++ b/tools/matrixIO.h
@@ -0,0 +1,30 @@
+#ifndef MATIO_H
+#define MATIO_H
+
+#include<iostream>
+
+namespace Eigen{
+ template<class Matrix>
+ void write_stream(std::ostream &ostr, const Matrix& matrix){
+ typename Matrix::Index rows=matrix.rows(), cols=matrix.cols();
+ ostr<<rows<<" "<<cols<<std::endl;
+ for (int r=0;r<rows;++r)
+ {
+ for (int c=0;c<cols;++c)
+ ostr<<matrix(r,c)<<" ";
+ ostr<<std::endl;
+ }
+ }
+ template<class Matrix>
+ void read_stream(std::istream &istr, Matrix& matrix){
+ typename Matrix::Index rows=0, cols=0;
+ istr>>rows>>cols;
+ matrix.resize(rows, cols);
+ for (int r=0;r<rows;++r)
+ for (int c=0;c<cols;++c)
+ istr>>matrix(r,c);
+ }
+} // Eigen::
+
+
+#endif \ No newline at end of file