| 201 | |
| 202 | template<typename T> |
| 203 | ::testing::AssertionResult imageEq(std::string aName, std::string bName, |
| 204 | const af::array &a, const af::array &b, |
| 205 | float maxAbsDiff) { |
| 206 | std::vector<T> avec(a.elements()); |
| 207 | a.host(avec.data()); |
| 208 | std::vector<T> bvec(b.elements()); |
| 209 | b.host(bvec.data()); |
| 210 | double NRMSD = computeArraysRMSD(a.elements(), avec.data(), bvec.data()); |
| 211 | |
| 212 | if (NRMSD < maxAbsDiff) { |
| 213 | return ::testing::AssertionSuccess(); |
| 214 | } else { |
| 215 | std::string test_name = |
| 216 | ::testing::UnitTest::GetInstance()->current_test_info()->name(); |
| 217 | |
| 218 | std::string valid_path = |
| 219 | std::string(TEST_RESULT_IMAGE_DIR) + test_name + "ValidImage.png"; |
| 220 | std::string result_path = |
| 221 | std::string(TEST_RESULT_IMAGE_DIR) + test_name + "ResultImage.png"; |
| 222 | std::string diff_path = |
| 223 | std::string(TEST_RESULT_IMAGE_DIR) + test_name + "DiffImage.png"; |
| 224 | |
| 225 | // af::array img = af::join(1, a, b); |
| 226 | // af::Window win; |
| 227 | // while (!win.close()) { win.image(img); } |
| 228 | af::saveImage(valid_path.c_str(), a.as(f32)); |
| 229 | af::saveImage(result_path.c_str(), b.as(f32)); |
| 230 | af::saveImage(diff_path.c_str(), abs(a.as(f32) - b.as(f32))); |
| 231 | |
| 232 | std::cout << "<DartMeasurementFile type=\"image/png\" " |
| 233 | "name=\"ValidImage\">" |
| 234 | << valid_path << "</DartMeasurementFile>\n"; |
| 235 | std::cout |
| 236 | << "<DartMeasurementFile type=\"image/png\" name=\"TestImage\">" |
| 237 | << result_path << "</DartMeasurementFile>\n"; |
| 238 | |
| 239 | std::cout << "<DartMeasurementFile " |
| 240 | << "type=\"image/png\" name=\"DifferenceImage2\">" |
| 241 | << diff_path << "</DartMeasurementFile>\n"; |
| 242 | |
| 243 | return ::testing::AssertionFailure() |
| 244 | << "RMSD Error(" << NRMSD << ") exceeds threshold(" << maxAbsDiff |
| 245 | << "): " << bName << "(" << b.type() << ") and " << aName << "(" |
| 246 | << a.type() << ")"; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | // Called by ASSERT_ARRAYS_EQ |
| 251 | ::testing::AssertionResult assertImageEq(std::string aName, std::string bName, |