12 const unsigned long long m1 = 0x5555555555555555;
13 const unsigned long long m2 = 0x3333333333333333;
14 const unsigned long long m4 = 0x0f0f0f0f0f0f0f0f;
21 x = (x &
m2) + ((x >> 2) &
m2);
22 x = (x + (x >> 4)) &
m4;
35 DigitType diff = test_inst[i] ^ train_inst[i];
40 int max_dist_id = K_CONST+1;
43 FIND_MAX_DIST:
for (
int k = 0;
k <
K_CONST; ++
k )
53 if ( dist < max_dist )
55 dists[max_dist_id] = dist;
56 labels[max_dist_id] = label;
67 int votes[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
69 for (
int i = 0; i <
K_CONST; i ++ )
72 for (
int i = 0; i < 10; i ++ )
74 if (votes[i] > max_vote)
100 TEST_LOOP:
for (
int t = 0; t <
NTESTS ; ++t)
103 SET_KNN_SET:
for (
int i = 0; i <
K_CONST; ++i )
111 TRAINING_LOOP :
for (
int i = 0; i <
NUM_TRAINING; ++i )
112 update_knn(&global_training_set[i * DIGIT_WIDTH], &global_test_set[t * DIGIT_WIDTH], dists, labels, i /
CLASS_SIZE);
116 global_results[t] = max_vote;
void update_knn(const DigitType *train_inst, const DigitType *test_inst, int dists[K_CONST], int labels[K_CONST], int label)
int popcount(DigitType x)
LabelType knn_vote(int labels[K_CONST])
const unsigned long long m4
static const uint32_t k[]
const unsigned long long m2
void DigitRec_sw(const DigitType global_training_set[NUM_TRAINING *DIGIT_WIDTH], const DigitType global_test_set[NUM_TEST *DIGIT_WIDTH], LabelType global_results[NUM_TEST])
const unsigned long long m1
x
Return the smallest n such that 2^n >= _x.
unsigned long long DigitType