Reply to topic

A.transpose() and A have different colPivHouseholder types

chrisjs
Registered Member
Posts
4
Karma
0
I'm using the QR decomposition to solve a non-least squares but similar looking problem. (Finding the minimum norm element of a plane.) To do this I'm computing the QR decomposition of A.transpose(), and for simplicity (since I use it several times) I had a typedef. So the following code
Code: Select all

typedef Eigen::MatrixXd Matrix;
typedef Eigen::ColPivHouseholderQR<Matrix> cph_qr;

const Matrix A;

//fill A in

const cph_qr qr_fact =  A.transpose().colPivHouseholderQr();

is failing with the error:
error: conversion from ‘const Eigen::ColPivHouseholderQR<Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001, 1, -0x00000000000000001, -0x00000000000000001> >’ to non-scalar type ‘cph_qr {aka const Eigen::ColPivHouseholderQR<Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001> >}’ requested


A similar problem happens when I attempt to assign qr_fact.matrixQR().triangularView<Eigen::Upper>() to a triangular view of type Eigen::TriangularView<const Matrix, Eigen::Upper>. (Which presumably is just a consequence of being constructed from a QR factorization of A.transpose().)

It looks like the Option, MaxRows, and MaxCols template parameters got set when I took the transpose. I'm wondering (1) Is there a reason for this, (2) Is there an easier way to solve my problem, and (3) failing that, what are my best options? I could use c++11 syntax and just declare the variable types with auto, or I could replace the typedef for cph_qr with
Code: Select all
typedef Eigen::ColPivHouseholderQR<Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor, Eigen::Dynamic, Eigen::Dynamic> > cph_qr;

I unsure which would be preferred. Thanks in advance for any responses.
User avatar ggael
Moderator
Posts
2195
Karma
15
OS
This is because A is a column major matrix, while A.transpose() is rowmajor. You should rather do:
Code: Select all
const cph_qr qr_fact(A.transpose());
// ...
qr_fact.compute(A);
//...
qr_fact.compute(A.transpose());
//...
chrisjs
Registered Member
Posts
4
Karma
0
Thanks! That fixed it. But I don't understand why I'd make the two calls to compute later. (Though it's good to know that function existed. It isn't in the online docs.)

 
Reply to topic

Bookmarks



Who is online

Registered users: Artmessiah, Baidu [Spider], Bing [Bot], Buddlespit, Exabot [Bot], garthecho, Google [Bot], Hans, koriun, La Ninje, valoriez, whatthefunk, Yahoo [Bot]