4

I'm calculating a SVD of a matrix using Eigen library.

Eigen::Matrix<double, Eigen::Dynamic, 6> A(points*2, 6);
Eigen::Matrix<double, Eigen::Dynamic, 1> b(points*2);
// fill the matrices
// ...
Eigen::Matrix<double, 6, 1> hVec;
hVec = A.bdcSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(b);

However, the following assertion fires:

SVDBase: thin U and V are only available when your matrix has a dynamic number of columns.

What is the reason of disallowing compile-time known parameters in this case? Am I not seeing something in the maths behind the SVD problem? Or is it a limitation / bug in Eigen?

Surely, I could convert the matrix to be have a run-time number of columns, but that would disallow possible optimizations achieved by specifying compile-time constants, when they are known.

maticus
  • 41
  • 3
  • Of course, forgot to add - Eigen version 3.3.2 – maticus May 15 '18 at 12:19
  • This is just my assumption, but when dealing with a singular value decomposition the matrix must be semi-positive definite. And it must be a symmetric matrix. – Sailanarmo May 15 '18 at 14:02
  • 1
    I'm confused; why positive semidefinite and symmetric? Don't all matrices have an SVD? – eozd May 15 '18 at 14:04
  • 1
    One problem with the current implementation is that this would make the return-type of `.matrixU()` and `.matrixV()` depend on a runtime parameter to `bdcSvd` -- of course that would be solvable by using a different API, which I guess nobody cared to suggest yet ... – chtz May 15 '18 at 18:38
  • 2
    Huh, the funny thing is that the code seems to work when compiled in release mode - i.e. without the assertion in question... – maticus May 16 '18 at 15:40
  • As for the return-type of `.matrixU()`, it is `Eigen::Dynamic` in my case, which covers all cases of runtime parameters to `bcdSvd` AFAIK. For sure that could be a compile-time-known 6x6 matrix if the ThinU request would be compile-time-known parameter, but isn't it just a performance improvement? – maticus May 16 '18 at 15:44
  • Just a side note: Using bdcSvd for small matrices does not make any sense. By default it will switch to JacobiSVD for blocks smaller than 16 anyway. So all you do is adding compilation time and binary size. – chtz May 18 '18 at 09:54

0 Answers0