I am trying to just setup a simple script to make sure I understand how LAPACK++ expects matrix memory layout, and have encountered a frustrating and confusing bug:
As an example, I use the matrix given on the QR Factorization Wikipedia page:
#include <lapack.hh>
int main() {
// Row major
float a[] = { 12.0f, -51.0f, 4.0f, 6.0f, 167.0, -68.0f, -4.0f, 24.0f, -41.0f};
// Column major
// float a[] = { 12.0f, 6.0f, -4.0f, -51.0f, 167.0f, 24.0f, 4.0f, -68.0f, -41.0f };
float t[3];
int64_t return_code = lapack::gelq2(3, 3, a, 3, t);
std::cout << return_code << "\n";
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 3; ++j)
std::cout << "\t" << a[i * 3 + j] << " ";
std::cout << "\n";
}
return return_code;
}
Row major returns garbage, while column major shows the correct value _below_ the diagonal and differs by an overall minus sign:
-14 0.230769 -0.153846
-21 -175 0.0555556
14 70 -35
Could someone explain to me what I am doing incorrectly?