@@ -78,16 +78,15 @@ int _maxmin_divide(int m, const double* grid, int* idx) {
7878 double * n = A.data () + 6 ; // normal vector of the cut plane
7979
8080 // Rearrange the indices to put points in each subset together by
81- // examining the signed distances of the points to the cut plane (R^T*n).
81+ // examining the signed distances of points to the cut plane (R^T*n).
8282 std::vector<double > dist (m);
8383 dgemv_ (" T" , &i3, &m, &d1, R.data (), &i3, n, &i1, &d0, dist.data (), &i1);
8484
8585 int *head = idx;
8686 std::reverse_iterator<int *> tail (idx + m), rend (idx);
8787 auto is_negative = [&dist](int j) { return dist[j] < 0 ; };
88- auto is_nonnegative = [&dist](int j) { return dist[j] >= 0 ; };
89- while ( ( head = std::find (head, idx + m, is_negative) ) <
90- ( tail = std::find (tail, rend, is_nonnegative) ).base () ) {
88+ while ( ( head = std::find_if (head, idx + m, is_negative) ) <
89+ ( tail = std::find_if_not (tail, rend, is_negative) ).base () ) {
9190 std::swap (*head, *tail);
9291 std::swap (dist[head - idx], dist[tail.base () - idx]);
9392 ++head;
@@ -101,29 +100,24 @@ int _maxmin_divide(int m, const double* grid, int* idx) {
101100
102101
103102std::vector<int > Grid::Batch::maxmin (
104- int m_max,
105- int m,
106103 const double * grid,
107- int * idx
104+ int * idx,
105+ int m,
106+ int m_thr
108107) {
109- if (m <= m_max ) {
110- return std::vector<int >{};
108+ if (m <= m_thr ) {
109+ return std::vector<int >{0 };
111110 }
112111
113112 int m_left = _maxmin_divide (m, grid, idx);
114113
115- // recursively divide the subsets
116- std::vector<int > left = maxmin (m_max, m_left, grid, idx);
117- std::vector<int > right = maxmin (m_max, m - m_left, grid, idx + m_left);
114+ std::vector<int > left = maxmin (grid, idx, m_left, m_thr);
115+ std::vector<int > right = maxmin (grid, idx + m_left, m - m_left, m_thr);
118116 std::for_each (right.begin (), right.end (),
119117 [m_left](int & x) { x += m_left; }
120118 );
121119
122- // merge all delimiters
123- int sz_left = left.size ();
124- left.resize (sz_left + right.size () + 1 );
125- left[sz_left] = m_left;
126- std::copy (right.begin (), right.end (), left.begin () + sz_left + 1 );
120+ left.insert (left.end (), right.begin (), right.end ());
127121 return left;
128122}
129123
0 commit comments