use numpy tobytes() and frombuffer() instead of pickling only
This commit is contained in:
parent
3602f24980
commit
ef94932f65
1 changed files with 8 additions and 4 deletions
|
@ -350,7 +350,9 @@ class Router:
|
||||||
options_key)
|
options_key)
|
||||||
result = cache.get(cache_key)
|
result = cache.get(cache_key)
|
||||||
if result:
|
if result:
|
||||||
return result
|
distances, predecessors = result
|
||||||
|
return (np.frombuffer(distances, dtype=np.float64).reshape(self.graph.shape),
|
||||||
|
np.frombuffer(predecessors, dtype=np.int32).reshape(self.graph.shape))
|
||||||
|
|
||||||
graph = self.graph.copy()
|
graph = self.graph.copy()
|
||||||
|
|
||||||
|
@ -389,9 +391,11 @@ class Router:
|
||||||
graph[:, tuple(restrictions.spaces)] = np.inf
|
graph[:, tuple(restrictions.spaces)] = np.inf
|
||||||
graph[restrictions.edges.transpose().tolist()] = np.inf
|
graph[restrictions.edges.transpose().tolist()] = np.inf
|
||||||
|
|
||||||
result = shortest_path(graph, directed=True, return_predecessors=True)
|
distances, predecessors = shortest_path(graph, directed=True, return_predecessors=True)
|
||||||
cache.set(cache_key, result, 600)
|
print(distances.dtype, predecessors.dtype)
|
||||||
return result
|
cache.set(cache_key, (distances.astype(np.float64).tobytes(),
|
||||||
|
predecessors.astype(np.int32).tobytes()), 600)
|
||||||
|
return distances, predecessors
|
||||||
|
|
||||||
def get_restrictions(self, permissions):
|
def get_restrictions(self, permissions):
|
||||||
return RouterRestrictionSet({
|
return RouterRestrictionSet({
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue