MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / TEST

Function TEST

test/transform.cpp:483–538  ·  view source on GitHub ↗

//////////////////////////////// CPP ////////////////////////////////

Source from the content-addressed store, hash-verified

481///////////////////////////////////// CPP ////////////////////////////////
482//
483TEST(Transform, CPP) {
484 IMAGEIO_ENABLED_CHECK();
485
486 vector<dim4> inDims;
487 vector<string> inFiles;
488 vector<dim_t> goldDim;
489 vector<string> goldFiles;
490
491 vector<dim4> HDims;
492 vector<vector<float>> HIn;
493 vector<vector<float>> HTests;
494 readTests<float, float, float>(TEST_DIR "/transform/tux_tmat.test", HDims,
495 HIn, HTests);
496
497 readImageTests(string(TEST_DIR "/transform/tux_nearest.test"), inDims,
498 inFiles, goldDim, goldFiles);
499
500 inFiles[0].insert(0, string(TEST_DIR "/transform/"));
501 inFiles[1].insert(0, string(TEST_DIR "/transform/"));
502
503 goldFiles[0].insert(0, string(TEST_DIR "/transform/"));
504
505 array H = array(HDims[0][0], HDims[0][1], &(HIn[0].front()));
506 array IH = array(HDims[0][0], HDims[0][1], &(HIn[0].front()));
507
508 array scene_img = loadImage(inFiles[1].c_str(), false);
509
510 array gold_img = loadImage(goldFiles[0].c_str(), false);
511
512 array out_img = transform(scene_img, IH, inDims[0][0], inDims[0][1],
513 AF_INTERP_NEAREST, false);
514
515 dim4 outDims = out_img.dims();
516 dim4 goldDims = gold_img.dims();
517
518 vector<float> h_out_img(outDims[0] * outDims[1]);
519 out_img.host(&h_out_img.front());
520 vector<float> h_gold_img(goldDims[0] * goldDims[1]);
521 gold_img.host(&h_gold_img.front());
522
523 const dim_t n = gold_img.elements();
524 const float thr = 1.0f;
525
526 // Maximum number of wrong pixels must be <= 0.01% of number of elements,
527 // this metric is necessary due to rounding errors between different
528 // backends for AF_INTERP_NEAREST and AF_INTERP_LOWER
529 const size_t maxErr = n * 0.0001f;
530 size_t err = 0;
531
532 for (dim_t elIter = 0; elIter < n; elIter++) {
533 err += fabs((int)h_out_img[elIter] - h_gold_img[elIter]) > thr;
534 if (err > maxErr) {
535 ASSERT_LE(err, maxErr) << "at: " << elIter << endl;
536 }
537 }
538}
539
540// This tests batching of different forms

Callers

nothing calls this directly

Calls 9

readImageTestsFunction · 0.85
loadImageFunction · 0.85
fabsFunction · 0.85
hostMethod · 0.80
arrayClass · 0.50
transformFunction · 0.50
dim4Class · 0.50
dimsMethod · 0.45
elementsMethod · 0.45

Tested by

no test coverage detected