| 92 | } |
| 93 | |
| 94 | static bool compareEuclidean(dim_t desc_len, dim_t ndesc, float* cpu, |
| 95 | float* gpu, float unit_thr = 1.f, |
| 96 | float euc_thr = 1.f) { |
| 97 | bool ret = true; |
| 98 | float sum = 0.0f; |
| 99 | |
| 100 | for (dim_t i = 0; i < ndesc; i++) { |
| 101 | sum = 0.0f; |
| 102 | for (dim_t l = 0; l < desc_len; l++) { |
| 103 | dim_t idx = i * desc_len + l; |
| 104 | float x = (cpu[idx] - gpu[idx]); |
| 105 | sum += x * x; |
| 106 | if (abs(x) > (float)unit_thr) { |
| 107 | ret = false; |
| 108 | cout << endl << "@compareEuclidean: unit mismatch." << endl; |
| 109 | cout << "(cpu,gpu,cpu-gpu)[" << i << "," << l << "] : {" |
| 110 | << cpu[idx] << "," << gpu[idx] << "," |
| 111 | << cpu[idx] - gpu[idx] << "}" << endl; |
| 112 | cout << endl; |
| 113 | break; |
| 114 | } |
| 115 | } |
| 116 | if (sqrt(sum) > euc_thr) { |
| 117 | ret = false; |
| 118 | cout << endl << "@compareEuclidean: distance mismatch." << endl; |
| 119 | cout << "Euclidean distance: " << sqrt(sum) << endl; |
| 120 | } |
| 121 | if (ret == false) return ret; |
| 122 | } |
| 123 | |
| 124 | return ret; |
| 125 | } |
| 126 | |
| 127 | template<typename T> |
| 128 | class GLOH : public ::testing::Test { |