From f3b24dde68f5dc13744db0782dd807712dbad369 Mon Sep 17 00:00:00 2001 From: Ryan Curtin Date: Fri, 30 Apr 2010 15:52:13 +0000 Subject: [PATCH] Add useful compat function which emulates Matrix::MakeColumnVector() functionality (albeit slowly) --- .../fastlib/base/arma_compat.cc | 18 ++++++++++++++++-- .../fastlib/base/arma_compat.h | 2 ++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/fastlib/branches/fastlib-armadillo/fastlib/base/arma_compat.cc b/fastlib/branches/fastlib-armadillo/fastlib/base/arma_compat.cc index 438b81d98a..59663e5854 100644 --- a/fastlib/branches/fastlib-armadillo/fastlib/base/arma_compat.cc +++ b/fastlib/branches/fastlib-armadillo/fastlib/base/arma_compat.cc @@ -12,7 +12,7 @@ * * This wasn't written to be fast or efficient. */ -void arma_compat::armaToMatrix(const arma::mat &mat, Matrix &mg) { +void arma_compat::armaToMatrix(const arma::mat& mat, Matrix& mg) { // initialize our matrix correctly mg.Init(mat.n_rows, mat.n_cols); @@ -29,7 +29,7 @@ void arma_compat::armaToMatrix(const arma::mat &mat, Matrix &mg) { * * This wasn't written to be fast or efficient. */ -void arma_compat::matrixToArma(const Matrix &gm, arma::mat &mat) { +void arma_compat::matrixToArma(const Matrix& gm, arma::mat& mat) { // initialize our matrix to the correct size mat.set_size(gm.n_rows(), gm.n_cols()); @@ -40,3 +40,17 @@ void arma_compat::matrixToArma(const Matrix &gm, arma::mat &mat) { } } } + +/*** + * Write the selected column of the matrix into the uninitialized Vector. + * + * This wasn't written to be fast or efficient. + */ +void arma_compat::armaColVector(const arma::mat& mat, int col, Vector& v) { + // initialize our vector to the correct size + v.Init(mat.n_rows); + + // copy elementwise. this is slow as hell + for(int r = 0; r < mat.n_rows; r++) + v[r] = mat(r, col); +} diff --git a/fastlib/branches/fastlib-armadillo/fastlib/base/arma_compat.h b/fastlib/branches/fastlib-armadillo/fastlib/base/arma_compat.h index 10f54e3e87..21c77d0e80 100644 --- a/fastlib/branches/fastlib-armadillo/fastlib/base/arma_compat.h +++ b/fastlib/branches/fastlib-armadillo/fastlib/base/arma_compat.h @@ -18,6 +18,8 @@ namespace arma_compat { void armaToMatrix(const arma::mat &mat, Matrix &mg); void matrixToArma(const Matrix &gm, arma::mat &mat); + // write a column into an uninitialized vector + void armaColVector(const arma::mat &mat, int col, Vector &v); } #endif /* ARMA_COMPAT_H */