This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Concatenated matrix as a reference

Tags: None
(comma "," separated)
pratikr
Registered Member
Posts
1
Karma
0

Concatenated matrix as a reference

Sat Nov 19, 2016 12:42 am
The following code concatenates a vector of ones to a matrix:

Code: Select all
  using Eigen::VectorXd;
  using Eigen::MatrixXd;

MatrixXd cbind1(const Eigen::Ref<const MatrixXd> X) {
  const unsigned int n = X.rows();
  MatrixXd Y(n, 1 + X.cols());
  Y << VectorXd::Ones(n), X;
  return Y;
}

The function copies the contents of X to Y. How do I define the function so that it avoids doing the copy and returns a reference to a matrix containing VectorXd::Ones(n), X?

Thanks.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]