23#ifndef VULPES_DATASTRUCTURE_CKDTREE_CKDTREE_DECL_HPP_
24#define VULPES_DATASTRUCTURE_CKDTREE_CKDTREE_DECL_HPP_
57#define tree_buffer_root(buf) (&(buf)[0][0])
58#define CKDTREE_LIKELY(x) __builtin_expect(!!(x), 1)
59#define CKDTREE_UNLIKELY(x) __builtin_expect(!!(x), 0)
60#ifdef HAVE___BUILTIN_PREFETCH
62#define CKDTREE_PREFETCH(x, rw, loc) __builtin_prefetch((x), (rw), (loc))
64#ifdef HAVE__MM_PREFETCH
66#define CKDTREE_PREFETCH(x, rw, loc) \
68 (x), loc == 0 ? _MM_HINT_NTA \
69 : (loc == 1 ? _MM_HINT_T2 \
70 : (loc == 2 ? _MM_HINT_T1 \
71 : (loc == 3 ? _MM_HINT_T0 : -1))))
73#define CKDTREE_PREFETCH(x, rw, loc)
76#define ckdtree_fmax(x, y) std::max(x, y)
77#define ckdtree_fmin(x, y) std::min(x, y)
78#define ckdtree_fabs(x) std::abs(x)
95 return (
i == other.
i) && (
j == other.
j);
100 std::vector<ordered_pair>* results,
105 results->push_back(p);
108 results->push_back(p);
122template <ckdtree_
intp_t Dim>
140template <ckdtree_
intp_t Dim>
148 const int _compact) {
150 const double* data = self->raw_data;
151 ckdtree_intp_t* indices =
reinterpret_cast<intptr_t*
>(self->raw_indices);
156 double size, split, minval, maxval;
159 self->tree_buffer->push_back(new_node);
160 node_index = self->tree_buffer->size() - 1;
162 n = root + node_index;
163 memset(n, 0,
sizeof(n[0]));
165 n->start_idx = start_idx;
166 n->end_idx = end_idx;
167 n->children = end_idx - start_idx;
169 if (end_idx - start_idx <= self->leafsize) {
180 const double* tmp_data_point;
181 tmp_data_point = data + indices[start_idx] * m;
182 for (i = 0; i < m; ++i) {
183 maxes[i] = tmp_data_point[i];
184 mins[i] = tmp_data_point[i];
186 for (j = start_idx + 1; j < end_idx; ++j) {
187 tmp_data_point = data + indices[j] * m;
188 for (i = 0; i < m; ++i) {
189 double tmp = tmp_data_point[i];
190 maxes[i] = maxes[i] > tmp ? maxes[i] : tmp;
191 mins[i] = mins[i] < tmp ? mins[i] : tmp;
199 for (i = 0; i < m; ++i) {
200 if (maxes[i] - mins[i] > size) {
202 size = maxes[i] - mins[i];
207 if (maxval == minval) {
217 const double point_a = data[a * m + d];
218 const double point_b = data[b * m + d];
219 return point_a < point_b;
224 const auto partition_ptr = std::partition(
227 return partition_ptr - indices;
234 const auto n_points = end_idx - start_idx;
235 auto* node_indices = indices + start_idx;
236 auto mid = node_indices + n_points / 2;
238 node_indices, mid, node_indices + n_points, index_compare);
240 split = data[*mid * m + d];
241 p = partition_pivot(node_indices, mid, split);
244 split = (maxval + minval) / 2;
246 p = partition_pivot(indices + start_idx, indices + end_idx, split);
250 if (p == start_idx) {
252 auto min_idx = *std::min_element(
253 indices + start_idx, indices + end_idx, index_compare);
254 split = std::nextafter(data[min_idx * m + d], HUGE_VAL);
255 p = partition_pivot(indices + start_idx, indices + end_idx, split);
256 }
else if (p == end_idx) {
258 auto max_idx = *std::max_element(
259 indices + start_idx, indices + end_idx, index_compare);
260 split = data[max_idx * m + d];
261 p = partition_pivot(indices + start_idx, indices + end_idx, split);
264 if (p == start_idx || p == end_idx) {
267 self->tree_buffer->pop_back();
268 std::array<double, 2 * m> tmp_bounds = {0};
269 double* tmp_mins = &tmp_bounds[0];
270 std::copy_n(mins, m, tmp_mins);
271 double* tmp_maxes = &tmp_bounds[m];
272 std::copy_n(maxes, m, tmp_maxes);
274 const auto fixed_val = data[indices[start_idx] * m + d];
275 tmp_mins[d] = fixed_val;
276 tmp_maxes[d] = fixed_val;
279 self, start_idx, end_idx, tmp_maxes, tmp_mins, _median, _compact);
283 less =
build_ckdtree(self, start_idx, p, maxes, mins, _median, _compact);
284 greater =
build_ckdtree(self, p, end_idx, maxes, mins, _median, _compact);
286 std::array<double, m> tmp = {0};
287 double* mids = &tmp[0];
289 for (i = 0; i < m; ++i) {
293 less =
build_ckdtree(self, start_idx, p, mids, mins, _median, _compact);
295 for (i = 0; i < m; ++i) {
299 greater =
build_ckdtree(self, p, end_idx, maxes, mids, _median, _compact);
306 n = root + node_index;
308 n->less =
reinterpret_cast<decltype(n-
>less)>(less);
309 n->greater =
reinterpret_cast<decltype(n-
>greater)>(greater);
321template <ckdtree_
intp_t m>
333 reinterpret_cast<void*
>(
mins()),
reinterpret_cast<const void*
>(_mins),
336 reinterpret_cast<void*
>(
maxes()),
reinterpret_cast<const void*
>(_maxes),
341 mutable std::array<double, 2 * m>
buf;
389template <
typename MinMaxDist, ckdtree_
intp_t Dim>
421 const double _upper_bound)
428 }
else if ((!std::isinf(
p)) && (!std::isinf(_upper_bound))) {
436 double tmp = 1. + eps;
437 epsfac = 1. / (tmp * tmp);
438 }
else if (eps == 0.) {
440 }
else if (std::isinf(
p)) {
443 epsfac = 1. / std::pow((1. + eps),
p);
451 MinMaxDist::rect_rect_p(
455 "Encountering floating point overflow. "
456 "The value of p too large for this dataset; "
457 "For such large p, consider using the special case p=np.inf . ";
458 throw std::invalid_argument(msg);
465 const intptr_t direction,
467 const double split_val) {
468 const double p = this->p;
501 MinMaxDist::interval_interval_p(
504 if (direction ==
LESS) {
505 rect->
maxes()[split_dim] = split_val;
507 rect->
mins()[split_dim] = split_val;
510 MinMaxDist::interval_interval_p(
524 MinMaxDist::rect_rect_p(
548 const char* msg =
"Bad stack size. This error should never occur.";
549 throw std::logic_error(msg);
556 if (item->
which == 1) {
566template <
typename Dist1D, ckdtree_
intp_t Dim>
583 Dist1D::interval_interval(tree, rect1, rect2, k, min, max);
584 *min = std::pow(*min, p);
585 *max = std::pow(*max, p);
600 Dist1D::interval_interval(tree, rect1, rect2, i, &min_, &max_);
602 *min += std::pow(min_, p);
603 *max += std::pow(max_, p);
613 const double upperbound) {
625 for (i = 0; i < k; ++i) {
626 r1 = Dist1D::point_point(tree, x, y, i);
627 r += std::pow(r1, p);
628 if (r > upperbound) {
635 static inline double distance_p(
const double s,
const double p) {
636 return std::pow(s, p);
640template <
typename Dist1D, ckdtree_
intp_t Dim>
653 Dist1D::interval_interval(tree, rect1, rect2, k, min, max);
668 Dist1D::interval_interval(tree, rect1, rect2, i, &min_, &max_);
681 const double upperbound) {
685 for (i = 0; i < k; ++i) {
686 r += Dist1D::point_point(tree, x, y, i);
687 if (r > upperbound) {
694 static inline double distance_p(
const double s,
const double) {
return s; }
697template <
typename Dist1D, ckdtree_
intp_t Dim>
707 return rect_rect_p(tree, rect1, rect2, p, min, max);
722 Dist1D::interval_interval(tree, rect1, rect2, i, &min_, &max_);
735 const double upperbound) {
739 for (i = 0; i < k; ++i) {
740 r =
ckdtree_fmax(r, Dist1D::point_point(tree, x, y, i));
741 if (r > upperbound) {
747 static inline double distance_p(
const double s,
const double) {
return s; }
750template <
typename Dist1D, ckdtree_
intp_t Dim>
763 Dist1D::interval_interval(tree, rect1, rect2, k, min, max);
780 Dist1D::interval_interval(tree, rect1, rect2, i, &min_, &max_);
796 const double upperbound) {
800 for (i = 0; i < k; ++i) {
801 double r1 = Dist1D::point_point(tree, x, y, i);
803 if (r > upperbound) {
809 static inline double distance_p(
const double s,
const double) {
814template <ckdtree_
intp_t Dim>
862template <ckdtree_
intp_t Dim>
864template <ckdtree_
intp_t Dim>
866template <ckdtree_
intp_t Dim>
868template <ckdtree_
intp_t Dim>
880 double acc[4] = {0., 0., 0., 0.};
881 for (; i + 4 <= n; i += 4) {
882 double _u[4] = {u[i], u[i + 1], u[i + 2], u[i + 3]};
883 double _v[4] = {v[i], v[i + 1], v[i + 2], v[i + 3]};
885 _u[0] - _v[0], _u[1] - _v[1], _u[2] - _v[2], _u[3] - _v[3]};
886 acc[0] += diff[0] * diff[0];
887 acc[1] += diff[1] * diff[1];
888 acc[2] += diff[2] * diff[2];
889 acc[3] += diff[3] * diff[3];
891 s = acc[0] + acc[1] + acc[2] + acc[3];
894 double d = u[i] - v[i];
901template <ckdtree_
intp_t Dim>
909 const double upperbound) {
914template <ckdtree_
intp_t Dim>
943 if (max <= 0 || min >= 0) {
963 if (max <= 0 || min >= 0) {
976 }
else if (min > half) {
978 *realmax = full - min;
979 *realmin = full - max;
1030 const double r = std::floor(x / boxsize);
1031 double x1 = x - r * boxsize;
1033 while (x1 >= boxsize) {
1048 double s, t, tmin, tmax;
1102 const double x,
const double hb,
const double fb) {
1136 space = initial_size;
1152 while ((i > 0) && (
_heap[i].priority <
_heap[(i - 1) / 2].priority)) {
1153 t =
_heap[(i - 1) / 2];
1177 while (((j < nn) && (
_heap[i].priority >
_heap[j].priority)) ||
1178 ((k < nn) && (
_heap[i].priority >
_heap[k].priority))) {
1179 if ((k < nn) && (
_heap[j].priority >
_heap[k].priority)) {
1205template <ckdtree_
intp_t m>
1220 std::memcpy(
buf, from->
buf,
sizeof(
double) * (3 * m));
1227 std::memcpy(
buf, from->
buf,
sizeof(
double) * m);
1232 const int d,
const double new_side_distance,
const double p) {
1247template <ckdtree_
intp_t m>
1250 64 * ((
sizeof(
nodeinfo<m>) + (3 * m - 1) *
sizeof(double)) / 64) + 64;
1270 typename MinMaxDist,
1273 bool Periodic =
false>
1276 double* result_distances,
1283 double distance_upper_bound) {
1303 heap neighbors(kmax);
1317 ni1->
node = self->ctree;
1322 for (i = 0; i < m; ++i) {
1323 ni1->
mins()[i] = self->raw_mins[i];
1324 ni1->
maxes()[i] = self->raw_maxes[i];
1326 double side_distance;
1329 self, x[i], self->raw_mins[i], self->raw_maxes[i], i);
1332 self, x[i], self->raw_mins[i], self->raw_maxes[i], i);
1334 side_distance = MinMaxDist::distance_p(side_distance, p);
1342 double tmp = 1. + eps;
1343 epsfac = 1. / (tmp * tmp);
1344 }
else if (eps == 0.) {
1346 }
else if constexpr (std::isinf(p)) {
1347 epsfac = 1. / (1. + eps);
1349 epsfac = 1. / std::pow((1. + eps), p);
1354 double tmp = distance_upper_bound;
1355 distance_upper_bound = tmp * tmp;
1356 }
else if ((!std::isinf(p)) && (!std::isinf(distance_upper_bound))) {
1357 distance_upper_bound = std::pow(distance_upper_bound, p);
1368 const double* data = self->raw_data;
1372 if (start_idx < end_idx - 1) {
1376 for (i = start_idx; i < end_idx; ++i) {
1377 if (i < end_idx - 2) {
1381 d = MinMaxDist::point_point_p(
1382 self, data + indices[i] * m, x, p, m, distance_upper_bound);
1383 if (d < distance_upper_bound) {
1385 if (neighbors.
n == kmax) {
1390 neighbors.
push(neighbor);
1393 if (neighbors.
n == kmax) {
1411 const double split = inode->
split;
1418 if (ni1->
min_distance > distance_upper_bound * epsfac) {
1427 if constexpr (!Periodic) {
1440 double side_distance;
1442 if (x[split_dim] < split) {
1445 side_distance = split - x[split_dim];
1449 side_distance = x[split_dim] - split;
1452 side_distance = MinMaxDist::distance_p(side_distance, p);
1464 double side_distance;
1466 ni1->
maxes()[split_dim] = split;
1470 self, x[split_dim], ni1->
mins()[split_dim], ni1->
maxes()[split_dim],
1472 side_distance = MinMaxDist::distance_p(side_distance, p);
1476 ni2->
mins()[split_dim] = split;
1480 self, x[split_dim], ni2->
mins()[split_dim], ni2->
maxes()[split_dim],
1482 side_distance = MinMaxDist::distance_p(side_distance, p);
1508 if (ni2->
min_distance <= distance_upper_bound * epsfac) {
1517 std::vector<heapitem> sorted_neighbors(kmax);
1519 for (i = neighbors.
n - 1; i >= 0; --i) {
1520 sorted_neighbors[i] = neighbors.
pop();
1524 for (i = 0; i < nk; ++i) {
1526 result_indices[i] = self->n;
1527 result_distances[i] = std::numeric_limits<double>::infinity();
1529 neighbor = sorted_neighbors[k[i] - 1];
1532 result_distances[i] = std::sqrt(-neighbor.
priority);
1533 }
else if constexpr ((p == 1.) || (std::isinf(p))) {
1534 result_distances[i] = -neighbor.
priority;
1536 result_distances[i] = std::pow((-neighbor.
priority), (1. / p));
1544template <ckdtree_
intp_t Dim,
double p,
bool Periodic = false>
1555 const double distance_upper_bound) {
1556#define HANDLE_KNN(cond, kls) \
1557 if constexpr (cond) { \
1558 query_single_point<kls, Dim, p, Periodic>( \
1559 self, dd_row, ii_row, xx_row, k, nk, kmax, eps, distance_upper_bound); \
1575 if constexpr (!Periodic) {
1576 for (i = 0; i < n; ++i) {
1577 double* dd_row = dd + (i * nk);
1579 const double* xx_row = xx + (i * m);
1586 std::array<double, m> row = {0};
1587 double* xx_row = &row[0];
1589 for (i = 0; i < n; ++i) {
1590 double* dd_row = dd + (i * nk);
1592 const double* old_xx_row = xx + (i * m);
1593 for (j = 0; j < m; ++j) {
1595 old_xx_row[j], self->raw_boxsize_data[j]);
1599 HANDLE_KNN(std::isinf(p), BoxMinkowskiDistPinf)
1608template <ckdtree_
intp_t Dim>
1611 const int return_length,
1612 std::vector<ckdtree_intp_t>& results,
1622 for (i = start; i < end; ++i) {
1623 if (return_length) {
1626 results.push_back(indices[i]);
1631 self, return_length, results, node->
less);
1633 self, return_length, results, node->
greater);
1637template <ckdtree_
intp_t Dim,
typename MinMaxDist>
1640 const int return_length,
1641 std::vector<ckdtree_intp_t>& results,
1655 const double p = tracker->
p;
1657 const double* tpt = tracker->
rect1.
mins();
1658 const double* data = self->raw_data;
1665 if (start < end - 1) {
1669 for (i = start; i < end; ++i) {
1674 d = MinMaxDist::point_point_p(
1675 self, data + indices[i] * m, tpt, p, m, tub);
1678 if (return_length) {
1688 self, return_length, results, node->
less, tracker);
1693 self, return_length, results, node->
greater, tracker);
1698template <ckdtree_
intp_t Dim,
double p,
bool Periodic = false>
1705 std::vector<ckdtree_intp_t>* results,
1706 const bool return_length,
1707 const bool sort_output) {
1708#define HANDLE_QBP(cond, kls) \
1709 if constexpr (cond) { \
1710 if (return_length) \
1711 results[i].push_back(0); \
1712 RectRectDistanceTracker<kls, Dim> tracker( \
1713 self, point, rect, p, eps, r[i]); \
1714 traverse_checking_query_ball_point( \
1715 self, return_length, results[i], self->ctree, &tracker); \
1731 if constexpr (!Periodic) {
1740 for (j = 0; j < m; ++j) {
1742 point.
mins()[j], self->raw_boxsize_data[j]);
1746 HANDLE_QBP(std::isinf(p), BoxMinkowskiDistPinf)
1750 if (!return_length && sort_output) {
1751 std::sort(results[i].begin(), results[i].end());
1759template <ckdtree_
intp_t Dim>
1762 std::vector<ordered_pair>* results,
1781 for (i = start1; i < end1; ++i) {
1783 if (node1 == node2) {
1789 for (j = min_j; j < end2; ++j) {
1798 if (node1 == node2) {
1817template <ckdtree_
intp_t Dim,
typename MinMaxDist>
1820 std::vector<ordered_pair>* results,
1840 const double p = tracker->
p;
1842 const double* data = self->raw_data;
1843 const double epsfac = tracker->
epsfac;
1852 if (start1 < end1 - 1) {
1856 for (i = start1; i < end1; ++i) {
1862 if (node1 == node2) {
1871 if (min_j < end2 - 1) {
1875 for (j = min_j; j < end2; ++j) {
1880 d = MinMaxDist::point_point_p(
1881 self, data + indices[i] * m, data + indices[j] * m, p, m, tub);
1883 if (d <= tub / epsfac) {
1895 self, results, node1, node2->
greater, tracker);
1906 self, results, node1->
greater, node2, tracker);
1912 self, results, node1->
less, node2->
less, tracker);
1917 self, results, node1->
less, node2->
greater, tracker);
1922 if (node1 != node2) {
1931 self, results, node1->
greater, node2->
less, tracker);
1943template <ckdtree_
intp_t Dim,
double p,
bool Periodic = false>
1948 std::vector<ordered_pair>* results) {
1949#define HANDLE_PAIRS(cond, kls) \
1950 if constexpr (cond) { \
1951 RectRectDistanceTracker<kls, Dim> tracker(self, r1, r2, p, eps, r); \
1952 traverse_checking_query_pairs( \
1953 self, results, self->ctree, self->ctree, &tracker); \
1969 if constexpr (!Periodic) {
1986template <ckdtree_
intp_t Dim>
1991 std::vector<ckdtree_intp_t>* results,
2011 for (i = start1; i < end1; ++i) {
2012 auto& results_i = results[sindices[i]];
2013 for (j = start2; j < end2; ++j) {
2014 results_i.push_back(oindices[j]);
2019 self, other, results, node1, node2->
less);
2021 self, other, results, node1, node2->
greater);
2025 self, other, results, node1->
less, node2);
2027 self, other, results, node1->
greater, node2);
2031template <ckdtree_
intp_t Dim,
typename MinMaxDist>
2035 std::vector<ckdtree_intp_t>* results,
2054 const double p = tracker->
p;
2057 const double* sdata = self->raw_data;
2059 const double* odata = other->
raw_data;
2069 if (start1 < end1 - 1) {
2073 for (i = start1; i < end1; ++i) {
2080 if (start2 < end2 - 1) {
2084 auto& results_i = results[sindices[i]];
2086 for (j = start2; j < end2; ++j) {
2091 d = MinMaxDist::point_point_p(
2092 self, sdata + sindices[i] * m, odata + oindices[j] * m, p, m,
2103 self, other, results, node1, node2->
less, tracker);
2108 self, other, results, node1, node2->
greater, tracker);
2115 self, other, results, node1->
less, node2, tracker);
2120 self, other, results, node1->
greater, node2, tracker);
2126 self, other, results, node1->
less, node2->
less, tracker);
2131 self, other, results, node1->
less, node2->
greater, tracker);
2138 self, other, results, node1->
greater, node2->
less, tracker);
2150template <ckdtree_
intp_t Dim,
double p,
bool Periodic = false>
2156 std::vector<ckdtree_intp_t>* results) {
2157#define HANDLE_TREE(cond, kls) \
2158 if constexpr (cond) { \
2159 RectRectDistanceTracker<kls, Dim> tracker(self, r1, r2, p, eps, r); \
2160 traverse_checking_query_ball_tree( \
2161 self, other, results, self->ctree, other->ctree, &tracker); \
2177 if constexpr (!Periodic) {
2190 std::sort(results[i].begin(), results[i].end());
#define ckdtree_fmax(x, y)
Definition ckdtree_decl.hpp:76
#define ckdtree_fmin(x, y)
Definition ckdtree_decl.hpp:77
#define CKDTREE_PREFETCH(x, rw, loc)
Definition ckdtree_decl.hpp:73
#define tree_buffer_root(buf)
Definition ckdtree_decl.hpp:57
#define HANDLE_PAIRS(cond, kls)
#define HANDLE_KNN(cond, kls)
#define HANDLE_QBP(cond, kls)
#define CKDTREE_LIKELY(x)
Definition ckdtree_decl.hpp:58
#define ckdtree_fabs(x)
Definition ckdtree_decl.hpp:78
#define CKDTREE_UNLIKELY(x)
Definition ckdtree_decl.hpp:59
#define HANDLE_TREE(cond, kls)
Definition ckdtree_decl.hpp:81
static ckdtree_intp_t build_ckdtree(ckdtree< Dim > *self, ckdtree_intp_t start_idx, intptr_t end_idx, double *maxes, double *mins, const int _median, const int _compact)
Definition ckdtree_decl.hpp:141
int query_ball_point(const ckdtree< Dim > *self, const double *x, const double *r, const double eps, const ckdtree_intp_t n_queries, std::vector< ckdtree_intp_t > *results, const bool return_length, const bool sort_output)
Definition ckdtree_decl.hpp:1699
int query_ball_tree(const ckdtree< Dim > *self, const ckdtree< Dim > *other, const double r, const double eps, std::vector< ckdtree_intp_t > *results)
Definition ckdtree_decl.hpp:2151
static void traverse_no_checking_query_pairs(const ckdtree< Dim > *self, std::vector< ordered_pair > *results, const ckdtreenode *node1, const ckdtreenode *node2)
Definition ckdtree_decl.hpp:1760
intptr_t ckdtree_intp_t
Definition ckdtree_decl.hpp:82
BaseMinkowskiDistPp< PlainDist1D< Dim >, Dim > MinkowskiDistPp
Definition ckdtree_decl.hpp:863
BaseMinkowskiDistP2< PlainDist1D< Dim >, Dim > NonOptimizedMinkowskiDistP2
Definition ckdtree_decl.hpp:869
int query_knn(const ckdtree< Dim > *self, double *dd, ckdtree_intp_t *ii, const double *xx, const ckdtree_intp_t n, const ckdtree_intp_t *k, const ckdtree_intp_t nk, const ckdtree_intp_t kmax, const double eps, const double distance_upper_bound)
Definition ckdtree_decl.hpp:1545
double sqeuclidean_distance_double(const double *u, const double *v, ckdtree_intp_t n)
Definition ckdtree_decl.hpp:875
const ckdtree_intp_t LESS
Definition ckdtree_decl.hpp:386
static void traverse_checking_query_ball_point(const ckdtree< Dim > *self, const int return_length, std::vector< ckdtree_intp_t > &results, const ckdtreenode *node, RectRectDistanceTracker< MinMaxDist, Dim > *tracker)
Definition ckdtree_decl.hpp:1638
BaseMinkowskiDistP1< PlainDist1D< Dim >, Dim > MinkowskiDistP1
Definition ckdtree_decl.hpp:867
static void traverse_checking_query_pairs(const ckdtree< Dim > *self, std::vector< ordered_pair > *results, const ckdtreenode *node1, const ckdtreenode *node2, RectRectDistanceTracker< MinMaxDist, Dim > *tracker)
Definition ckdtree_decl.hpp:1818
const ckdtree_intp_t GREATER
Definition ckdtree_decl.hpp:387
static void traverse_no_checking_query_ball_point(const ckdtree< Dim > *self, const int return_length, std::vector< ckdtree_intp_t > &results, const ckdtreenode *node)
Definition ckdtree_decl.hpp:1609
static void traverse_checking_query_ball_tree(const ckdtree< Dim > *self, const ckdtree< Dim > *other, std::vector< ckdtree_intp_t > *results, const ckdtreenode *node1, const ckdtreenode *node2, RectRectDistanceTracker< MinMaxDist, Dim > *tracker)
Definition ckdtree_decl.hpp:2032
static void traverse_no_checking_query_ball_tree(const ckdtree< Dim > *self, const ckdtree< Dim > *other, std::vector< ckdtree_intp_t > *results, const ckdtreenode *node1, const ckdtreenode *node2)
Definition ckdtree_decl.hpp:1988
static void query_single_point(const ckdtree< Dim > *self, double *result_distances, ckdtree_intp_t *result_indices, const double *x, const ckdtree_intp_t *k, const ckdtree_intp_t nk, const ckdtree_intp_t kmax, const double eps, double distance_upper_bound)
Definition ckdtree_decl.hpp:1274
void add_ordered_pair(std::vector< ordered_pair > *results, const ckdtree_intp_t i, const ckdtree_intp_t j)
Definition ckdtree_decl.hpp:99
BaseMinkowskiDistPinf< PlainDist1D< Dim >, Dim > MinkowskiDistPinf
Definition ckdtree_decl.hpp:865
int query_pairs(const ckdtree< Dim > *self, const double r, const double eps, std::vector< ordered_pair > *results)
Definition ckdtree_decl.hpp:1944
Definition cell_manager.hpp:38
Definition ckdtree_decl.hpp:641
static void rect_rect_p(const ckdtree< Dim > *tree, const Rectangle< Dim > &rect1, const Rectangle< Dim > &rect2, const double p, double *min, double *max)
Definition ckdtree_decl.hpp:656
static double point_point_p(const ckdtree< Dim > *tree, const double *x, const double *y, const double, const ckdtree_intp_t k, const double upperbound)
Definition ckdtree_decl.hpp:675
static void interval_interval_p(const ckdtree< Dim > *tree, const Rectangle< Dim > &rect1, const Rectangle< Dim > &rect2, const ckdtree_intp_t k, const double p, double *min, double *max)
Definition ckdtree_decl.hpp:642
static double distance_p(const double s, const double)
Definition ckdtree_decl.hpp:694
Definition ckdtree_decl.hpp:751
static double point_point_p(const ckdtree< Dim > *tree, const double *x, const double *y, const double, const ckdtree_intp_t k, const double upperbound)
Definition ckdtree_decl.hpp:790
static double distance_p(const double s, const double)
Definition ckdtree_decl.hpp:809
static void interval_interval_p(const ckdtree< Dim > *tree, const Rectangle< Dim > &rect1, const Rectangle< Dim > &rect2, const ckdtree_intp_t k, const double, double *min, double *max)
Definition ckdtree_decl.hpp:752
static void rect_rect_p(const ckdtree< Dim > *tree, const Rectangle< Dim > &rect1, const Rectangle< Dim > &rect2, const double, double *min, double *max)
Definition ckdtree_decl.hpp:768
Definition ckdtree_decl.hpp:698
static double distance_p(const double s, const double)
Definition ckdtree_decl.hpp:747
static double point_point_p(const ckdtree< Dim > *tree, const double *x, const double *y, const double, const ckdtree_intp_t k, const double upperbound)
Definition ckdtree_decl.hpp:729
static void interval_interval_p(const ckdtree< Dim > *tree, const Rectangle< Dim > &rect1, const Rectangle< Dim > &rect2, const ckdtree_intp_t k, double p, double *min, double *max)
Definition ckdtree_decl.hpp:699
static void rect_rect_p(const ckdtree< Dim > *tree, const Rectangle< Dim > &rect1, const Rectangle< Dim > &rect2, const double p, double *min, double *max)
Definition ckdtree_decl.hpp:710
Definition ckdtree_decl.hpp:567
static double point_point_p(const ckdtree< Dim > *tree, const double *x, const double *y, const double p, const ckdtree_intp_t k, const double upperbound)
Definition ckdtree_decl.hpp:607
static double distance_p(const double s, const double p)
Definition ckdtree_decl.hpp:635
static void interval_interval_p(const ckdtree< Dim > *tree, const Rectangle< Dim > &rect1, const Rectangle< Dim > &rect2, const ckdtree_intp_t k, const double p, double *min, double *max)
Definition ckdtree_decl.hpp:572
static void rect_rect_p(const ckdtree< Dim > *tree, const Rectangle< Dim > &rect1, const Rectangle< Dim > &rect2, const double p, double *min, double *max)
Definition ckdtree_decl.hpp:588
Definition ckdtree_decl.hpp:915
static double wrap_distance(const double x, const double hb, const double fb)
Definition ckdtree_decl.hpp:1101
static double wrap_position(const double x, const double boxsize)
Definition ckdtree_decl.hpp:1026
static double side_distance_from_min_max(const ckdtree< Dim > *tree, const double x, const double min, const double max, const ckdtree_intp_t k)
Definition ckdtree_decl.hpp:1042
static void _interval_interval_1d(double min, double max, double *realmin, double *realmax, const double full, const double half)
Definition ckdtree_decl.hpp:916
static double point_point(const ckdtree< Dim > *tree, const double *x, const double *y, const ckdtree_intp_t k)
Definition ckdtree_decl.hpp:1013
static void interval_interval(const ckdtree< Dim > *tree, const Rectangle< Dim > &rect1, const Rectangle< Dim > &rect2, const ckdtree_intp_t k, double *min, double *max)
Definition ckdtree_decl.hpp:998
Definition ckdtree_decl.hpp:902
static double point_point_p(const ckdtree< Dim > *tree, const double *x, const double *y, const double p, const ckdtree_intp_t k, const double upperbound)
Definition ckdtree_decl.hpp:903
Definition ckdtree_decl.hpp:815
static void interval_interval(const ckdtree< Dim > *, const Rectangle< Dim > &rect1, const Rectangle< Dim > &rect2, const ckdtree_intp_t k, double *min, double *max)
Definition ckdtree_decl.hpp:835
static double point_point(const ckdtree< Dim > *, const double *x, const double *y, const ckdtree_intp_t k)
Definition ckdtree_decl.hpp:853
static double side_distance_from_min_max(const ckdtree< Dim > *, const double x, const double min, const double max, const ckdtree_intp_t)
Definition ckdtree_decl.hpp:816
Definition ckdtree_decl.hpp:377
double max_distance
Definition ckdtree_decl.hpp:383
double max_along_dim
Definition ckdtree_decl.hpp:381
ckdtree_intp_t which
Definition ckdtree_decl.hpp:378
ckdtree_intp_t split_dim
Definition ckdtree_decl.hpp:379
double min_along_dim
Definition ckdtree_decl.hpp:380
double min_distance
Definition ckdtree_decl.hpp:382
Definition ckdtree_decl.hpp:390
ckdtree_intp_t stack_max_size
Definition ckdtree_decl.hpp:401
void _resize_stack(const ckdtree_intp_t new_max_size)
Definition ckdtree_decl.hpp:409
double p
Definition ckdtree_decl.hpp:394
Rectangle< Dim > rect1
Definition ckdtree_decl.hpp:392
double inaccurate_distance_limit
Definition ckdtree_decl.hpp:407
Rectangle< Dim > rect2
Definition ckdtree_decl.hpp:393
void push_less_of(const ckdtree_intp_t which, const ckdtreenode *node)
Definition ckdtree_decl.hpp:532
double min_distance
Definition ckdtree_decl.hpp:397
RR_stack_item * stack
Definition ckdtree_decl.hpp:403
ckdtree_intp_t stack_size
Definition ckdtree_decl.hpp:400
std::vector< RR_stack_item > stack_arr
Definition ckdtree_decl.hpp:402
void push_greater_of(const ckdtree_intp_t which, const ckdtreenode *node)
Definition ckdtree_decl.hpp:537
const ckdtree< Dim > * tree
Definition ckdtree_decl.hpp:391
void pop()
Definition ckdtree_decl.hpp:542
double upper_bound
Definition ckdtree_decl.hpp:396
double epsfac
Definition ckdtree_decl.hpp:395
RectRectDistanceTracker(const ckdtree< Dim > *_tree, const Rectangle< Dim > &_rect1, const Rectangle< Dim > &_rect2, const double _p, const double eps, const double _upper_bound)
Definition ckdtree_decl.hpp:415
double max_distance
Definition ckdtree_decl.hpp:398
void push(const ckdtree_intp_t which, const intptr_t direction, const ckdtree_intp_t split_dim, const double split_val)
Definition ckdtree_decl.hpp:463
Definition ckdtree_decl.hpp:322
Rectangle(const double *_mins, const double *_maxes)
Definition ckdtree_decl.hpp:329
double * maxes() const
Definition ckdtree_decl.hpp:326
double * mins() const
Definition ckdtree_decl.hpp:327
std::array< double, 2 *m > buf
Definition ckdtree_decl.hpp:341
Definition ckdtree_decl.hpp:123
static constexpr ckdtree_intp_t m
Definition ckdtree_decl.hpp:124
std::vector< ckdtreenode > * tree_buffer
Definition ckdtree_decl.hpp:126
ckdtree_intp_t n
Definition ckdtree_decl.hpp:130
ckdtree_intp_t leafsize
Definition ckdtree_decl.hpp:131
ckdtree_intp_t * raw_indices
Definition ckdtree_decl.hpp:134
const double * raw_data
Definition ckdtree_decl.hpp:129
double * raw_maxes
Definition ckdtree_decl.hpp:132
ckdtreenode * ctree
Definition ckdtree_decl.hpp:127
double * raw_boxsize_data
Definition ckdtree_decl.hpp:135
double * raw_mins
Definition ckdtree_decl.hpp:133
Definition ckdtree_decl.hpp:112
ckdtree_intp_t split_dim
Definition ckdtree_decl.hpp:113
ckdtree_intp_t end_idx
Definition ckdtree_decl.hpp:117
ckdtree_intp_t start_idx
Definition ckdtree_decl.hpp:116
ckdtreenode * greater
Definition ckdtree_decl.hpp:119
double split
Definition ckdtree_decl.hpp:115
ckdtree_intp_t children
Definition ckdtree_decl.hpp:114
ckdtreenode * less
Definition ckdtree_decl.hpp:118
Definition ckdtree_decl.hpp:84
ckdtree_intp_t i
Definition ckdtree_decl.hpp:85
double v
Definition ckdtree_decl.hpp:87
ckdtree_intp_t j
Definition ckdtree_decl.hpp:86
Definition ckdtree_decl.hpp:1130
void remove()
Definition ckdtree_decl.hpp:1162
heap(ckdtree_intp_t initial_size)
Definition ckdtree_decl.hpp:1135
ckdtree_intp_t space
Definition ckdtree_decl.hpp:1133
void push(heapitem &item)
Definition ckdtree_decl.hpp:1140
std::vector< heapitem > _heap
Definition ckdtree_decl.hpp:1131
heapitem pop()
Definition ckdtree_decl.hpp:1193
ckdtree_intp_t n
Definition ckdtree_decl.hpp:1132
heapitem peek()
Definition ckdtree_decl.hpp:1160
Definition ckdtree_decl.hpp:1125
double priority
Definition ckdtree_decl.hpp:1126
heapcontents contents
Definition ckdtree_decl.hpp:1127
Definition ckdtree_decl.hpp:1248
static constexpr ckdtree_intp_t arena_size
Definition ckdtree_decl.hpp:1251
nodeinfo_pool()
Definition ckdtree_decl.hpp:1256
size_t current_offset
Definition ckdtree_decl.hpp:1254
nodeinfo< m > * allocate()
Definition ckdtree_decl.hpp:1258
std::vector< char > arena
Definition ckdtree_decl.hpp:1253
static constexpr ckdtree_intp_t alloc_size
Definition ckdtree_decl.hpp:1249
Definition ckdtree_decl.hpp:1206
double * mins()
Definition ckdtree_decl.hpp:1217
double buf[1]
Definition ckdtree_decl.hpp:1209
double * side_distances()
Definition ckdtree_decl.hpp:1211
double * maxes()
Definition ckdtree_decl.hpp:1216
void update_side_distance(const int d, const double new_side_distance, const double p)
Definition ckdtree_decl.hpp:1231
void init_box(const struct nodeinfo *from)
Definition ckdtree_decl.hpp:1219
const ckdtreenode * node
Definition ckdtree_decl.hpp:1207
double min_distance
Definition ckdtree_decl.hpp:1208
void init_plain(const struct nodeinfo *from)
Definition ckdtree_decl.hpp:1224
Definition ckdtree_decl.hpp:90
ckdtree_intp_t j
Definition ckdtree_decl.hpp:92
ckdtree_intp_t i
Definition ckdtree_decl.hpp:91
bool operator==(const ordered_pair &other) const
Definition ckdtree_decl.hpp:94
Definition ckdtree_decl.hpp:1120
void * ptrdata
Definition ckdtree_decl.hpp:1122
ckdtree_intp_t intdata
Definition ckdtree_decl.hpp:1121