@@ -158,6 +158,11 @@ function _split!_rtree(node::Node, tree::RTree)
158158 return n1, n2
159159end
160160
161+ # get low/high of a specific MBR dimension
162+ # accessor functions to speedup sortperm!()
163+ _mbr_low (node, dim:: Integer ) = @inbounds mbr (node). low[dim]
164+ _mbr_high (node, dim:: Integer ) = @inbounds mbr (node). high[dim]
165+
161166# R*-star node split
162167function _split!_rstar (node:: Node , tree:: RTree )
163168 nsplit = floor (Int, length (node) * tree. splitdistribution_factor)
@@ -173,17 +178,17 @@ function _split!_rstar(node::Node, tree::RTree)
173178 highorder = similar (loworder)
174179 use_low = false
175180 for dim in 1 : ndims (node)
176- sortperm! (loworder, children (node), by= child -> mbr (child) . low[ dim] )
177- sortperm! (highorder, children (node), by= child -> mbr (child) . high[ dim] )
181+ sortperm! (loworder, children (node), by= Base . Fix2 (_mbr_low, dim) )
182+ sortperm! (highorder, children (node), by= Base . Fix2 (_mbr_high, dim) )
178183
179184 # calculate the sum of perimiters for all splits
180185 low_perim = 0.0
181186 high_perim = 0.0
182187 for i in nsplit: (nsplit + nsplit_distr)
183- @inbounds br_low1 = mapreduce (i -> mbr (node[loworder[i]]) , combine, 1 : i)
184- @inbounds br_high1 = mapreduce (i -> mbr (node[highorder[i]]) , combine, 1 : i)
185- @inbounds br_low2 = mapreduce (i -> mbr (node[loworder[i]]) , combine, ( i+ 1 ): length (node))
186- @inbounds br_high2 = mapreduce (i -> mbr (node[highorder[i]]) , combine, ( i+ 1 ): length (node))
188+ @inbounds br_low1 = mapreduce (j -> @inbounds ( mbr (node[j])) , combine, view (loworder, 1 : i) )
189+ @inbounds br_high1 = mapreduce (j -> @inbounds ( mbr (node[j])) , combine, view (highorder, 1 : i) )
190+ @inbounds br_low2 = mapreduce (j -> @inbounds ( mbr (node[j])) , combine, view (loworder, ( i+ 1 ): length (node) ))
191+ @inbounds br_high2 = mapreduce (j -> @inbounds ( mbr (node[j])) , combine, view (highorder, ( i+ 1 ): length (node) ))
187192
188193 low_perim += perimeter (br_low1) + perimeter (br_low2)
189194 high_perim += perimeter (br_high1) + perimeter (br_high2)
@@ -199,8 +204,8 @@ function _split!_rstar(node::Node, tree::RTree)
199204
200205 # final sorting
201206 selorder = use_low ?
202- sortperm! (loworder, children (node), by = node -> mbr (node) . low[ split_dim] ) :
203- sortperm! (highorder, children (node), by = node -> mbr (node) . high[ split_dim] )
207+ sortperm! (loworder, children (node), by= Base . Fix2 (_mbr_low, split_dim) ) :
208+ sortperm! (highorder, children (node), by= Base . Fix2 (_mbr_high, split_dim) )
204209
205210 # find the best split point (minimizes split overlap and area)
206211 min_overlap = Inf
0 commit comments