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

Function hammingMatcherTest

test/hamming.cpp:46–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44
45template<typename T>
46void hammingMatcherTest(string pTestFile, int feat_dim) {
47 using af::dim4;
48
49 vector<dim4> numDims;
50 vector<vector<uint>> in32;
51 vector<vector<uint>> tests;
52
53 readTests<uint, uint, int>(pTestFile, numDims, in32, tests);
54
55 vector<vector<T>> in(in32.size());
56 for (size_t i = 0; i < in32[0].size(); i++) in[0].push_back((T)in32[0][i]);
57 for (size_t i = 0; i < in32[1].size(); i++) in[1].push_back((T)in32[1][i]);
58
59 dim4 qDims = numDims[0];
60 dim4 tDims = numDims[1];
61 af_array query = 0;
62 af_array train = 0;
63 af_array idx = 0;
64 af_array dist = 0;
65
66 ASSERT_SUCCESS(af_create_array(&query, &(in[0].front()), qDims.ndims(),
67 qDims.get(),
68 (af_dtype)dtype_traits<T>::af_type));
69 ASSERT_SUCCESS(af_create_array(&train, &(in[1].front()), tDims.ndims(),
70 tDims.get(),
71 (af_dtype)dtype_traits<T>::af_type));
72
73 ASSERT_SUCCESS(af_hamming_matcher(&idx, &dist, query, train, feat_dim, 1));
74
75 vector<uint> goldIdx = tests[0];
76 vector<uint> goldDist = tests[1];
77 size_t nElems = goldIdx.size();
78 uint *outIdx = new uint[nElems];
79 uint *outDist = new uint[nElems];
80
81 ASSERT_SUCCESS(af_get_data_ptr((void *)outIdx, idx));
82 ASSERT_SUCCESS(af_get_data_ptr((void *)outDist, dist));
83
84 for (size_t elIter = 0; elIter < nElems; ++elIter) {
85 ASSERT_EQ(goldDist[elIter], outDist[elIter])
86 << "at: " << elIter << endl;
87 }
88
89 delete[] outIdx;
90 delete[] outDist;
91 ASSERT_SUCCESS(af_release_array(query));
92 ASSERT_SUCCESS(af_release_array(train));
93 ASSERT_SUCCESS(af_release_array(idx));
94 ASSERT_SUCCESS(af_release_array(dist));
95}
96
97TYPED_TEST(HammingMatcher8, Hamming_500_5000_Dim0) {
98 UNSUPPORTED_BACKEND(AF_BACKEND_ONEAPI);

Callers

nothing calls this directly

Calls 6

af_create_arrayFunction · 0.50
af_hamming_matcherFunction · 0.50
af_get_data_ptrFunction · 0.50
af_release_arrayFunction · 0.50
ndimsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected