From 318dd96dfb483aa4c4f8ddf315dc26ad9a40408b Mon Sep 17 00:00:00 2001 From: Richard Roberts Date: Mon, 4 Jun 2012 13:44:21 +0000 Subject: [PATCH] Matrix stream input operator --- gtsam/base/Matrix.cpp | 23 +++++++++++++++++++++++ gtsam/base/Matrix.h | 7 +++++++ 2 files changed, 30 insertions(+) diff --git a/gtsam/base/Matrix.cpp b/gtsam/base/Matrix.cpp index 320dbe896..2d32ccc04 100644 --- a/gtsam/base/Matrix.cpp +++ b/gtsam/base/Matrix.cpp @@ -235,6 +235,29 @@ void save(const Matrix& A, const string &s, const string& filename) { stream.close(); } +/* ************************************************************************* */ +//istream& operator>>(istream& inputStream, Matrix& destinationMatrix) { +// destinationMatrix.resize(0,0); +// string line; +// bool first = true; +// while(getline(inputStream, line)) { +// // Read coefficients from file +// vector coeffs; +// std::copy(istream_iterator(stringstream(line)), istream_iterator(), coeffs.end()); +// if(first) { +// destinationMatrix.resize(1, +// } +// if(coeffs.size() != dimLatent()) { +// cout << "Error reading motion file, latent variable dimension does not match file" << endl; +// exit(1); +// } +// +// // Copy coefficients to alignment matrix +// alignment_.conservativeResize(alignment_.rows() + 1, dimLatent()); +// alignment_.row(alignment_.rows() - 1) = Eigen::Map(&coeffs[0], dimLatent()).transpose(); +// } +//} + /* ************************************************************************* */ void insertSub(Matrix& fullMatrix, const Matrix& subMatrix, size_t i, size_t j) { fullMatrix.block(i, j, subMatrix.rows(), subMatrix.cols()) = subMatrix; diff --git a/gtsam/base/Matrix.h b/gtsam/base/Matrix.h index 9093fb99d..553fb5b89 100644 --- a/gtsam/base/Matrix.h +++ b/gtsam/base/Matrix.h @@ -183,6 +183,13 @@ void print(const Matrix& A, const std::string& s = "", std::ostream& stream = st */ void save(const Matrix& A, const std::string &s, const std::string& filename); +/** + * Read a matrix from an input stream, such as a file. Entries can be either + * tab-, space-, or comma-separated, similar to the format read by the MATLAB + * dlmread command. + */ +//istream& operator>>(istream& inputStream, Matrix& destinationMatrix); + /** * extract submatrix, slice semantics, i.e. range = [i1,i2[ excluding i2 * @param A matrix