38 typedef unsigned __int32 uint32_t;
39 typedef unsigned __int64 uint64_t;
81 template <
typename Iterator1,
typename Iterator2>
86 for(
size_t i = 0; i <
size; ++i ) {
93 template <
typename U,
typename V>
108 template <
typename Iterator1,
typename Iterator2>
122 template <
typename U,
typename V>
149 template <
typename Iterator1,
typename Iterator2>
154 Iterator1 last = a +
size;
155 Iterator1 lastgroup = last - 3;
158 while (a < lastgroup) {
163 result += diff0 * diff0 + diff1 * diff1 + diff2 * diff2 + diff3 * diff3;
167 if ((worst_dist>0)&&(
result>worst_dist)) {
185 template <
typename U,
typename V>
210 template <
typename Iterator1,
typename Iterator2>
215 Iterator1 last = a +
size;
216 Iterator1 lastgroup = last - 3;
219 while (a < lastgroup) {
224 result += diff0 + diff1 + diff2 + diff3;
228 if ((worst_dist>0)&&(
result>worst_dist)) {
243 template <
typename U,
typename V>
273 template <
typename Iterator1,
typename Iterator2>
278 Iterator1 last = a +
size;
279 Iterator1 lastgroup = last - 3;
282 while (a < lastgroup) {
291 if ((worst_dist>0)&&(
result>worst_dist)) {
306 template <
typename U,
typename V>
328 template <
typename Iterator1,
typename Iterator2>
333 Iterator1 last = a +
size;
334 Iterator1 lastgroup = last - 3;
337 while (a < lastgroup) {
349 if ((worst_dist>0)&&(
result>worst_dist)) {
382 for (
int i = 0; i <
size; i++) {
396 static const unsigned char table[256] = {
476 template<
typename Iterator1,
typename Iterator2>
481 #if ANDROID && HAVE_NEON
482 static uint64_t features = android_getCpuFeatures();
483 if ((features& ANDROID_CPU_ARM_FEATURE_NEON)) {
484 for (
size_t i = 0; i <
size; i += 16) {
485 uint8x16_t A_vec = vld1q_u8 (a + i);
486 uint8x16_t B_vec = vld1q_u8 (b + i);
488 uint8x16_t AxorB = veorq_u8 (A_vec, B_vec);
490 uint8x16_t bitsSet += vcntq_u8 (AxorB);
492 uint16x8_t bitSet8 = vpaddlq_u8 (bitsSet);
493 uint32x4_t bitSet4 = vpaddlq_u16 (bitSet8);
495 uint64x2_t bitSet2 = vpaddlq_u32 (bitSet4);
496 result += vgetq_lane_u64 (bitSet2,0);
497 result += vgetq_lane_u64 (bitSet2,1);
503 typedef unsigned long long pop_t;
504 const size_t modulo =
size %
sizeof(pop_t);
505 const pop_t* a2 =
reinterpret_cast<const pop_t*
> (a);
506 const pop_t* b2 =
reinterpret_cast<const pop_t*
> (b);
507 const pop_t* a2_end = a2 + (
size /
sizeof(pop_t));
509 for (; a2 != a2_end; ++a2, ++b2)
result += __builtin_popcountll((*a2) ^ (*b2));
514 pop_t a_final = 0, b_final = 0;
515 memcpy(&a_final, a2, modulo);
516 memcpy(&b_final, b2, modulo);
517 result += __builtin_popcountll(a_final ^ b_final);
521 result = lut(
reinterpret_cast<const unsigned char*
> (a),
522 reinterpret_cast<const unsigned char*
> (b),
size *
sizeof(pop_t));
538 n -= ((n >> 1) & 0x55555555);
539 n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
540 return (((n + (n >> 4))& 0xF0F0F0F)* 0x1010101) >> 24;
545 n -= ((n >> 1) & 0x5555555555555555LL);
546 n = (n & 0x3333333333333333LL) + ((n >> 2) & 0x3333333333333333LL);
547 return (((n + (n >> 4))& 0x0f0f0f0f0f0f0f0fLL)* 0x0101010101010101LL) >> 56;
550 template <
typename Iterator1,
typename Iterator2>
553 #ifdef FLANN_PLATFORM_64_BIT
554 const uint64_t* pa =
reinterpret_cast<const uint64_t*
>(a);
555 const uint64_t* pb =
reinterpret_cast<const uint64_t*
>(b);
557 size /= (
sizeof(uint64_t)/
sizeof(
unsigned char));
558 for(
size_t i = 0; i <
size; ++i ) {
564 const uint32_t* pa =
reinterpret_cast<const uint32_t*
>(a);
565 const uint32_t* pb =
reinterpret_cast<const uint32_t*
>(b);
567 size /= (
sizeof(uint32_t)/
sizeof(
unsigned char));
568 for(
size_t i = 0; i <
size; ++i ) {
593 template <
typename Iterator1,
typename Iterator2>
598 Iterator1 last = a +
size;
599 Iterator1 lastgroup = last - 3;
602 while (a < lastgroup) {
603 min0 = (
ResultType)(a[0] < b[0] ? a[0] : b[0]);
604 min1 = (
ResultType)(a[1] < b[1] ? a[1] : b[1]);
605 min2 = (
ResultType)(a[2] < b[2] ? a[2] : b[2]);
606 min3 = (
ResultType)(a[3] < b[3] ? a[3] : b[3]);
607 result += min0 + min1 + min2 + min3;
610 if ((worst_dist>0)&&(
result>worst_dist)) {
627 template <
typename U,
typename V>
647 template <
typename Iterator1,
typename Iterator2>
652 Iterator1 last = a +
size;
653 Iterator1 lastgroup = last - 3;
656 while (a < lastgroup) {
661 result += diff0 * diff0 + diff1 * diff1 + diff2 * diff2 + diff3 * diff3;
675 template <
typename U,
typename V>
695 template <
typename Iterator1,
typename Iterator2>
700 Iterator1 last = a +
size;
711 if ((worst_dist>0)&&(
result>worst_dist)) {
721 template <
typename U,
typename V>
748 template <
typename Iterator1,
typename Iterator2>
752 Iterator1 last = a +
size;
755 if ( *a != 0 && *b != 0 ) {
758 result += *a * log(ratio);
764 if ((worst_dist>0)&&(
result>worst_dist)) {
774 template <
typename U,
typename V>
778 if( a != 0 && b != 0 ) {
__host__ __device__ int2 abs(int2 v)
static double dist(double x1, double y1, double x2, double y2)
ResultType accum_dist(const U &a, const V &b, int) const
ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist=-1) const
Accumulator< T >::Type ResultType
unsigned char ElementType
static unsigned char byteBitsLookUp(unsigned char b)
given a byte, count the bits using a look up table
ResultType operator()(const unsigned char *a, const unsigned char *b, int size) const
ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType=-1) const
ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType=0) const
unsigned int popcnt64(uint64_t n) const
unsigned int popcnt32(uint32_t n) const
Accumulator< T >::Type ResultType
ResultType accum_dist(const U &a, const V &b, int) const
ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType=-1) const
Accumulator< T >::Type ResultType
ResultType accum_dist(const U &a, const V &b, int) const
ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist=-1) const
ResultType accum_dist(const U &a, const V &b, int) const
Accumulator< T >::Type ResultType
ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist=-1) const
ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist=-1) const
ResultType accum_dist(const U &a, const V &b, int) const
Accumulator< T >::Type ResultType
ResultType accum_dist(const U &a, const V &b, int) const
Accumulator< T >::Type ResultType
ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType=-1) const
Accumulator< T >::Type ResultType
ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType=-1) const
ResultType accum_dist(const U &a, const V &b, int) const
ResultType accum_dist(const U &a, const V &b, int) const
Accumulator< T >::Type ResultType
ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist=-1) const
ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist=-1) const
bool is_vector_space_distance
Accumulator< T >::Type ResultType
Accumulator< T >::Type ResultType
ResultType accum_dist(const U &a, const V &b, int) const
ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist=-1) const
MinkowskiDistance(int order_)