File tree Expand file tree Collapse file tree 1 file changed +6
-8
lines changed Expand file tree Collapse file tree 1 file changed +6
-8
lines changed Original file line number Diff line number Diff line change @@ -86,16 +86,14 @@ void IndexLSH::train(idx_t n, const float* x) {
8686
8787 for (idx_t i = 0 ; i < nbits; i++) {
8888 float * xi = transposed_x.get () + i * n;
89- // Use nth_element (O(n)) instead of sort (O(n log n)) for median
90- if (n % 2 == 1 ) {
91- std::nth_element (xi, xi + n / 2 , xi + n);
92- thresholds[i] = xi[n / 2 ];
93- } else {
94- std::nth_element (xi, xi + n / 2 , xi + n);
95- float median_high = xi[n / 2 ];
89+ // Use nth_element (O(n)) instead of sort (O(n log n))
90+ std::nth_element (xi, xi + n / 2 , xi + n);
91+ float median = xi[n / 2 ];
92+ if (n % 2 == 0 ) {
9693 std::nth_element (xi, xi + n / 2 - 1 , xi + n);
97- thresholds[i] = (xi[n / 2 - 1 ] + median_high ) / 2 ;
94+ median = (median + xi[n / 2 - 1 ]) / 2 ;
9895 }
96+ thresholds[i] = median;
9997 }
10098 }
10199 is_trained = true ;
You can’t perform that action at this time.
0 commit comments