@@ -1847,6 +1847,7 @@ cdef cpath_from_dijkstra_field(np.float32_t[:,::1] costmap, np.int64_t[::1] firs
1847
1847
path = []
1848
1848
jump_log = []
1849
1849
path.append([first[0 ], first[1 ]])
1850
+ cdef int n
1850
1851
cdef np.int64_t n_offsets = len (offsets)
1851
1852
cdef np.int64_t maxi = costmap.shape[0 ]
1852
1853
cdef np.int64_t maxj = costmap.shape[1 ]
@@ -1860,7 +1861,7 @@ cdef cpath_from_dijkstra_field(np.float32_t[:,::1] costmap, np.int64_t[::1] firs
1860
1861
cdef np.float32_t olen
1861
1862
cdef np.float32_t[::1 ] offset_edge_costs = np.zeros((n_offsets,), dtype = np.float32)
1862
1863
cdef np.float32_t offset_edge_cost
1863
- cdef np.float32_t best_offset_edge_cost
1864
+ cdef int best_offset_edge_cost_id
1864
1865
cdef np.int64_t n_best_edges
1865
1866
cdef np.int64_t[::1 ] tied_firstplace_candidates = np.zeros((n_offsets,), dtype = np.int64)
1866
1867
cdef np.int64_t stochastic_candidate_pick
@@ -1869,7 +1870,7 @@ cdef cpath_from_dijkstra_field(np.float32_t[:,::1] costmap, np.int64_t[::1] firs
1869
1870
while True :
1870
1871
current_cost = costmap[current_idxi, current_idxj]
1871
1872
# lookup all edge costs and find lowest cost which is also < 0
1872
- best_offset_edge_cost = 0
1873
+ best_offset_edge_cost_id = 0
1873
1874
for n in range (n_offsets):
1874
1875
oi = offsets[n, 0 ]
1875
1876
oj = offsets[n, 1 ]
@@ -1904,18 +1905,21 @@ cdef cpath_from_dijkstra_field(np.float32_t[:,::1] costmap, np.int64_t[::1] firs
1904
1905
# in 8/16 connectedness some offsets are 'longer' and will be preferred unless normalized
1905
1906
olen = csqrt(oi* oi + oj* oj)
1906
1907
offset_edge_cost = offset_edge_cost / olen
1908
+ # fix nan values
1909
+ if np.isnan(offset_edge_cost):
1910
+ offset_edge_cost = np.inf
1907
1911
# store for later
1908
1912
offset_edge_costs[n] = offset_edge_cost
1909
- if offset_edge_cost < best_offset_edge_cost :
1910
- best_offset_edge_cost = offset_edge_cost
1913
+ if offset_edge_cost < offset_edge_costs[best_offset_edge_cost_id] :
1914
+ best_offset_edge_cost_id = n
1911
1915
# find how many choice are tied for best cost, if several, sample stochastically
1912
1916
n_best_edges = 0
1913
- if best_offset_edge_cost >= 0 :
1917
+ if offset_edge_costs[best_offset_edge_cost_id] >= 0 :
1914
1918
# local minima reached, terminate
1915
1919
jump_log.append(n_best_edges)
1916
1920
break
1917
1921
for n in range (n_offsets):
1918
- if offset_edge_costs[n] == best_offset_edge_cost :
1922
+ if offset_edge_costs[n] == offset_edge_costs[best_offset_edge_cost_id] :
1919
1923
tied_firstplace_candidates[n_best_edges] = n
1920
1924
n_best_edges += 1
1921
1925
if n_best_edges > 1 :
@@ -1925,8 +1929,9 @@ cdef cpath_from_dijkstra_field(np.float32_t[:,::1] costmap, np.int64_t[::1] firs
1925
1929
elif n_best_edges == 1 :
1926
1930
selected_offset_id = tied_firstplace_candidates[0 ]
1927
1931
else :
1928
- print (best_offset_edge_cost)
1929
- print (offset_edge_costs)
1932
+ print (best_offset_edge_cost_id)
1933
+ for n in range (n_offsets):
1934
+ print (offset_edge_costs[n])
1930
1935
print (" Warning: this code should be unreachable" )
1931
1936
break
1932
1937
jump_log.append(n_best_edges)
0 commit comments