Registered Member
|
I have a matrix X and a vector of its column indices. I want to multiply another vector with a matrix composed of only those columns of X listed in the vector of indices. Currently I am using
to do this. Is there a faster way? |
Moderator
|
if res is quite large, then better copy the set of X.col(indices(i)) columns to a temporary matrix and then perform a matrix-matrix product. (Sorry, the handling of indexed columns/rows is still missing)
|
Registered Member
|
Thanks for the reply! Unfortunately X can be quite large so copying the columns to a temporary matrix would be slower. Is there no other way? |
Moderator
|
Internally, Eigen's matrix-vector product works per block of 4 columns, so you can write a little helper function working per block of 4:
int b=4; MatrixXd tmp(X.rows(),b); for(int j=0;j<(X.cols()+b-1)/b; ++j) { int c = std::max(b,X.cols()-j); // copy the c columns into tmp res += q.transpose() * tmp.leftCols(c); } |
Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]