1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
/*******************************************************
* Copyright (c) 2014, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include <gtest/gtest.h>
#include <arrayfire.h>
#include <af/dim4.hpp>
#include <af/traits.hpp>
#include <vector>
#include <iostream>
#include <string>
#include <testHelpers.hpp>
using std::vector;
using std::string;
using std::cout;
using std::endl;
using std::abs;
using af::cfloat;
using af::cdouble;
template<typename T>
class Translate : public ::testing::Test
{
public:
virtual void SetUp() {
}
};
template<typename T>
class TranslateInt : public ::testing::Test
{
public:
virtual void SetUp() {
}
};
// create a list of types to be tested
typedef ::testing::Types<float, double, cfloat, cdouble> TestTypes;
typedef ::testing::Types<int, intl, char, short> TestTypesInt;
// register the type list
TYPED_TEST_CASE(Translate, TestTypes);
TYPED_TEST_CASE(TranslateInt, TestTypesInt);
template<typename T>
void translateTest(string pTestFile, const unsigned resultIdx, af::dim4 odims, const float tx, const float ty, const af_interp_type method, const float max_fail_count = 0.0001)
{
if (noDoubleTests<T>()) return;
vector<af::dim4> numDims;
vector<vector<T> > in;
vector<vector<float> > tests;
readTests<T, float, float>(pTestFile,numDims,in,tests);
af_array inArray = 0;
af_array outArray = 0;
af::dim4 dims = numDims[0];
ASSERT_EQ(AF_SUCCESS, af_create_array(&inArray, &(in[0].front()), dims.ndims(), dims.get(), (af_dtype) af::dtype_traits<T>::af_type));
ASSERT_EQ(AF_SUCCESS, af_translate(&outArray, inArray, tx, ty, odims[0], odims[1], method));
// Get result
T* outData = new T[tests[resultIdx].size()];
ASSERT_EQ(AF_SUCCESS, af_get_data_ptr((void*)outData, outArray));
// Compare result
size_t nElems = tests[resultIdx].size();
size_t fail_count = 0;
for (size_t elIter = 0; elIter < nElems; ++elIter) {
if(abs((T)tests[resultIdx][elIter] - outData[elIter]) > 0.0001) {
fail_count++;
}
}
ASSERT_EQ(true, (((float)fail_count / (float)(nElems)) <= max_fail_count))
<< "Fail Count = " << fail_count << std::endl;
// Delete
delete[] outData;
if(inArray != 0) af_release_array(inArray);
if(outArray != 0) af_release_array(outArray);
}
TYPED_TEST(Translate, Small1)
{
translateTest<TypeParam>(string(TEST_DIR"/translate/translate_small_1.test"), 0,
af::dim4(10, 10, 1, 1), 3, 2, AF_INTERP_NEAREST);
}
TYPED_TEST(Translate, Small2)
{
translateTest<TypeParam>(string(TEST_DIR"/translate/translate_small_1.test"), 1,
af::dim4(10, 10, 1, 1), -3, -2, AF_INTERP_NEAREST);
}
TYPED_TEST(Translate, Small3)
{
translateTest<TypeParam>(string(TEST_DIR"/translate/translate_small_1.test"), 2,
af::dim4(15, 15, 1, 1), 1.5, 2.5, AF_INTERP_BILINEAR);
}
TYPED_TEST(Translate, Small4)
{
translateTest<TypeParam>(string(TEST_DIR"/translate/translate_small_1.test"), 3,
af::dim4(15, 15, 1, 1), -1.5, -2.5, AF_INTERP_BILINEAR);
}
TYPED_TEST(Translate, Large1)
{
translateTest<TypeParam>(string(TEST_DIR"/translate/translate_large_1.test"), 0,
af::dim4(250, 320, 1, 1), 10, 18, AF_INTERP_NEAREST);
}
TYPED_TEST(Translate, Large2)
{
translateTest<TypeParam>(string(TEST_DIR"/translate/translate_large_1.test"), 1,
af::dim4(250, 320, 1, 1), -20, 24, AF_INTERP_NEAREST);
}
TYPED_TEST(Translate, Large3)
{
translateTest<TypeParam>(string(TEST_DIR"/translate/translate_large_1.test"), 2,
af::dim4(300, 400, 1, 1), 10.23, 12.72, AF_INTERP_BILINEAR);
}
TYPED_TEST(Translate, Large4)
{
translateTest<TypeParam>(string(TEST_DIR"/translate/translate_large_1.test"), 3,
af::dim4(300, 400, 1, 1), -15.69, -10.13, AF_INTERP_BILINEAR);
}
TYPED_TEST(TranslateInt, Small1)
{
translateTest<TypeParam>(string(TEST_DIR"/translate/translate_small_1.test"), 0,
af::dim4(10, 10, 1, 1), 3, 2, AF_INTERP_NEAREST);
}
TYPED_TEST(TranslateInt, Small2)
{
translateTest<TypeParam>(string(TEST_DIR"/translate/translate_small_1.test"), 1,
af::dim4(10, 10, 1, 1), -3, -2, AF_INTERP_NEAREST);
}
TYPED_TEST(TranslateInt, Small3)
{
translateTest<TypeParam>(string(TEST_DIR"/translate/translate_small_1.test"), 2,
af::dim4(15, 15, 1, 1), 1.5, 2.5, AF_INTERP_BILINEAR);
}
TYPED_TEST(TranslateInt, Small4)
{
translateTest<TypeParam>(string(TEST_DIR"/translate/translate_small_1.test"), 3,
af::dim4(15, 15, 1, 1), -1.5, -2.5, AF_INTERP_BILINEAR);
}
TYPED_TEST(TranslateInt, Large1)
{
translateTest<TypeParam>(string(TEST_DIR"/translate/translate_large_1.test"), 0,
af::dim4(250, 320, 1, 1), 10, 18, AF_INTERP_NEAREST);
}
TYPED_TEST(TranslateInt, Large2)
{
translateTest<TypeParam>(string(TEST_DIR"/translate/translate_large_1.test"), 1,
af::dim4(250, 320, 1, 1), -20, 24, AF_INTERP_NEAREST);
}
TYPED_TEST(TranslateInt, Large3)
{
translateTest<TypeParam>(string(TEST_DIR"/translate/translate_large_1.test"), 2,
af::dim4(300, 400, 1, 1), 10.23, 12.72, AF_INTERP_BILINEAR, 0.001);
}
TYPED_TEST(TranslateInt, Large4)
{
translateTest<TypeParam>(string(TEST_DIR"/translate/translate_large_1.test"), 3,
af::dim4(300, 400, 1, 1), -15.69, -10.13, AF_INTERP_BILINEAR, 0.001);
}
|