[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/arrayfire/arrayfire/feature/optional-graphics/test/hamming.cpp [Back]  [Original]

/*******************************************************
 * 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 
#include 
#include 
#include 
#include 
#include 
#include 

using af::cdouble;
using af::cfloat;
using af::dtype_traits;
using std::endl;
using std::string;
using std::vector;

template
class HammingMatcher8 : public ::testing::Test {
   public:
    virtual void SetUp() {}
};

template
class HammingMatcher32 : public ::testing::Test {
   public:
    virtual void SetUp() {}
};

// create lists of types to be tested
typedef ::testing::Types TestTypes8;
typedef ::testing::Types TestTypes32;

// register the type list
TYPED_TEST_SUITE(HammingMatcher8, TestTypes8);
TYPED_TEST_SUITE(HammingMatcher32, TestTypes32);

template
void hammingMatcherTest(string pTestFile, int feat_dim) {
    using af::dim4;

    vector numDims;
    vector in32;
    vector tests;

    readTests(pTestFile, numDims, in32, tests);

    vector in(in32.size());
    for (size_t i = 0; i < in32[0].size(); i++) in[0].push_back((T)in32[0][i]);
    for (size_t i = 0; i < in32[1].size(); i++) in[1].push_back((T)in32[1][i]);

    dim4 qDims     = numDims[0];
    dim4 tDims     = numDims[1];
    af_array query = 0;
    af_array train = 0;
    af_array idx   = 0;
    af_array dist  = 0;

    ASSERT_SUCCESS(af_create_array(&query, &(in[0].front()), qDims.ndims(),
                                   qDims.get(),
                                   (af_dtype)dtype_traits::af_type));
    ASSERT_SUCCESS(af_create_array(&train, &(in[1].front()), tDims.ndims(),
                                   tDims.get(),
                                   (af_dtype)dtype_traits::af_type));

    ASSERT_SUCCESS(af_hamming_matcher(&idx, &dist, query, train, feat_dim, 1));

    vector goldIdx  = tests[0];
    vector goldDist = tests[1];
    size_t nElems         = goldIdx.size();
    uint *outIdx          = new uint[nElems];
    uint *outDist         = new uint[nElems];

    ASSERT_SUCCESS(af_get_data_ptr((void *)outIdx, idx));
    ASSERT_SUCCESS(af_get_data_ptr((void *)outDist, dist));

    for (size_t elIter = 0; elIter < nElems; ++elIter) {
        ASSERT_EQ(goldDist[elIter], outDist[elIter])
            

Web Proxy Viewer  |  New URL  |  Original Page