//////////////////////////// CPP ////////////////////////////////////
| 34 | |
| 35 | ///////////////////////////////// CPP //////////////////////////////////// |
| 36 | TEST(QRFactorized, CPP) { |
| 37 | LAPACK_ENABLED_CHECK(); |
| 38 | |
| 39 | int resultIdx = 0; |
| 40 | |
| 41 | vector<dim4> numDims; |
| 42 | vector<vector<float>> in; |
| 43 | vector<vector<float>> tests; |
| 44 | readTests<float, float, float>(string(TEST_DIR "/lapack/qrfactorized.test"), |
| 45 | numDims, in, tests); |
| 46 | |
| 47 | dim4 idims = numDims[0]; |
| 48 | array input(idims, &(in[0].front())); |
| 49 | |
| 50 | array q, r, tau; |
| 51 | qr(q, r, tau, input); |
| 52 | |
| 53 | dim4 qdims = q.dims(); |
| 54 | dim4 rdims = r.dims(); |
| 55 | |
| 56 | // Get result |
| 57 | float* qData = new float[qdims.elements()]; |
| 58 | q.host((void*)qData); |
| 59 | float* rData = new float[rdims.elements()]; |
| 60 | r.host((void*)rData); |
| 61 | |
| 62 | // Compare result |
| 63 | for (int y = 0; y < (int)qdims[1]; ++y) { |
| 64 | for (int x = 0; x < (int)qdims[0]; ++x) { |
| 65 | int elIter = y * qdims[0] + x; |
| 66 | ASSERT_NEAR(tests[resultIdx][elIter], qData[elIter], 0.001) |
| 67 | << "at: " << elIter << endl; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | resultIdx = 1; |
| 72 | |
| 73 | for (int y = 0; y < (int)rdims[1]; ++y) { |
| 74 | for (int x = 0; x < (int)rdims[0]; ++x) { |
| 75 | // Test only upper half |
| 76 | if (x <= y) { |
| 77 | int elIter = y * rdims[0] + x; |
| 78 | ASSERT_NEAR(tests[resultIdx][elIter], rData[elIter], 0.001) |
| 79 | << "at: " << elIter << endl; |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // Delete |
| 85 | delete[] qData; |
| 86 | delete[] rData; |
| 87 | } |
| 88 | |
| 89 | template<typename T> |
| 90 | void qrTester(const int m, const int n, double eps) { |
nothing calls this directly
no test coverage detected