Skip to content

Commit b8f28cc

Browse files
authored
fix deprecation warning for latest numpy (AtsushiSakai#480)
* fix deprication version for latest numpy * fix deprication version for latest numpy * fix deprication version for latest numpy * fix deprication version for latest numpy
1 parent f495ae8 commit b8f28cc

File tree

9 files changed

+69
-39
lines changed

9 files changed

+69
-39
lines changed

Mapping/lidar_to_grid_map/lidar_to_grid_map.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def generate_ray_casting_grid_map(ox, oy, xy_resolution, breshen=True):
193193
(x_w, y_w),
194194
(min_x, min_y), xy_resolution)
195195
flood_fill((center_x, center_y), occupancy_map)
196-
occupancy_map = np.array(occupancy_map, dtype=np.float)
196+
occupancy_map = np.array(occupancy_map, dtype=float)
197197
for (x, y) in zip(ox, oy):
198198
ix = int(round((x - min_x) / xy_resolution))
199199
iy = int(round((y - min_y) / xy_resolution))

PathPlanning/SpiralSpanningTreeCPP/spiral_spanning_tree_coverage_path_planner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def plan(self, start):
4242
"""
4343

4444
visit_times = np.zeros(
45-
(self.merged_map_height, self.merged_map_width), dtype=np.int)
45+
(self.merged_map_height, self.merged_map_width), dtype=int)
4646
visit_times[start[0]][start[1]] = 1
4747

4848
# generate route by

PathPlanning/WavefrontCPP/wavefront_coverage_path_planner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def transform(
4747
else:
4848
sys.exit('Unsupported distance type.')
4949

50-
transform_matrix = float('inf') * np.ones_like(grid_map, dtype=np.float)
50+
transform_matrix = float('inf') * np.ones_like(grid_map, dtype=float)
5151
transform_matrix[src[0], src[1]] = 0
5252
if transform_type == 'distance':
5353
eT = np.zeros_like(grid_map)

SLAM/EKFSLAM/ekf_slam.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ def jacob_motion(x, u):
115115
Fx = np.hstack((np.eye(STATE_SIZE), np.zeros(
116116
(STATE_SIZE, LM_SIZE * calc_n_lm(x)))))
117117

118-
jF = np.array([[0.0, 0.0, -DT * u[0] * math.sin(x[2, 0])],
119-
[0.0, 0.0, DT * u[0] * math.cos(x[2, 0])],
120-
[0.0, 0.0, 0.0]], dtype=np.float64)
118+
jF = np.array([[0.0, 0.0, -DT * u[0, 0] * math.sin(x[2, 0])],
119+
[0.0, 0.0, DT * u[0, 0] * math.cos(x[2, 0])],
120+
[0.0, 0.0, 0.0]], dtype=float)
121121

122122
G = np.eye(STATE_SIZE) + Fx.T @ jF @ Fx
123123

SLAM/GraphBasedSLAM/graphslam/graph.py

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@
88
99
"""
1010

11-
11+
import warnings
1212
from collections import defaultdict
1313
from functools import reduce
14-
import warnings
1514

15+
import matplotlib.pyplot as plt
1616
import numpy as np
1717
from scipy.sparse import SparseEfficiencyWarning, lil_matrix
1818
from scipy.sparse.linalg import spsolve
19-
import matplotlib.pyplot as plt
20-
2119

2220
warnings.simplefilter("ignore", SparseEfficiencyWarning)
2321
warnings.filterwarnings("ignore", category=SparseEfficiencyWarning)
@@ -44,6 +42,7 @@ class _Chi2GradientHessian:
4442
The contributions to the Hessian matrix
4543
4644
"""
45+
4746
def __init__(self, dim):
4847
self.chi2 = 0.
4948
self.dim = dim
@@ -59,7 +58,6 @@ def update(chi2_grad_hess, incoming):
5958
chi2_grad_hess : _Chi2GradientHessian
6059
The ``_Chi2GradientHessian`` that will be updated
6160
incoming : tuple
62-
TODO
6361
6462
"""
6563
chi2_grad_hess.chi2 += incoming[0]
@@ -100,6 +98,7 @@ class Graph(object):
10098
A list of the vertices in the graph
10199
102100
"""
101+
103102
def __init__(self, edges, vertices):
104103
# The vertices and edges lists
105104
self._edges = edges
@@ -117,14 +116,16 @@ def _link_edges(self):
117116
118117
"""
119118
index_id_dict = {i: v.id for i, v in enumerate(self._vertices)}
120-
id_index_dict = {v_id: v_index for v_index, v_id in index_id_dict.items()}
119+
id_index_dict = {v_id: v_index for v_index, v_id in
120+
index_id_dict.items()}
121121

122122
# Fill in the vertices' `index` attribute
123123
for v in self._vertices:
124124
v.index = id_index_dict[v.id]
125125

126126
for e in self._edges:
127-
e.vertices = [self._vertices[id_index_dict[v_id]] for v_id in e.vertex_ids]
127+
e.vertices = [self._vertices[id_index_dict[v_id]] for v_id in
128+
e.vertex_ids]
128129

129130
def calc_chi2(self):
130131
r"""Calculate the :math:`\chi^2` error for the ``Graph``.
@@ -144,22 +145,34 @@ def _calc_chi2_gradient_hessian(self):
144145
"""
145146
n = len(self._vertices)
146147
dim = len(self._vertices[0].pose.to_compact())
147-
chi2_gradient_hessian = reduce(_Chi2GradientHessian.update, (e.calc_chi2_gradient_hessian() for e in self._edges), _Chi2GradientHessian(dim))
148+
chi2_gradient_hessian = reduce(_Chi2GradientHessian.update,
149+
(e.calc_chi2_gradient_hessian()
150+
for e in self._edges),
151+
_Chi2GradientHessian(dim))
148152

149153
self._chi2 = chi2_gradient_hessian.chi2
150154

151155
# Fill in the gradient vector
152-
self._gradient = np.zeros(n * dim, dtype=np.float64)
153-
for idx, contrib in chi2_gradient_hessian.gradient.items():
154-
self._gradient[idx * dim: (idx + 1) * dim] += contrib
156+
self._gradient = np.zeros(n * dim, dtype=float)
157+
for idx, cont in chi2_gradient_hessian.gradient.items():
158+
self._gradient[idx * dim: (idx + 1) * dim] += cont
155159

156160
# Fill in the Hessian matrix
157-
self._hessian = lil_matrix((n * dim, n * dim), dtype=np.float64)
158-
for (row_idx, col_idx), contrib in chi2_gradient_hessian.hessian.items():
159-
self._hessian[row_idx * dim: (row_idx + 1) * dim, col_idx * dim: (col_idx + 1) * dim] = contrib
161+
self._hessian = lil_matrix((n * dim, n * dim), dtype=float)
162+
for (row_idx, col_idx), cont in chi2_gradient_hessian.hessian.items():
163+
x_start = row_idx * dim
164+
x_end = (row_idx + 1) * dim
165+
y_start = col_idx * dim
166+
y_end = (col_idx + 1) * dim
167+
self._hessian[x_start:x_end, y_start:y_end] = cont
160168

161169
if row_idx != col_idx:
162-
self._hessian[col_idx * dim: (col_idx + 1) * dim, row_idx * dim: (row_idx + 1) * dim] = np.transpose(contrib)
170+
x_start = col_idx * dim
171+
x_end = (col_idx + 1) * dim
172+
y_start = row_idx * dim
173+
y_end = (row_idx + 1) * dim
174+
self._hessian[x_start:x_end, y_start:y_end] = \
175+
np.transpose(cont)
163176

164177
def optimize(self, tol=1e-4, max_iter=20, fix_first_pose=True):
165178
r"""Optimize the :math:`\chi^2` error for the ``Graph``.
@@ -189,8 +202,10 @@ def optimize(self, tol=1e-4, max_iter=20, fix_first_pose=True):
189202

190203
# Check for convergence (from the previous iteration); this avoids having to calculate chi^2 twice
191204
if i > 0:
192-
rel_diff = (chi2_prev - self._chi2) / (chi2_prev + np.finfo(float).eps)
193-
print("{:9d} {:20.4f} {:18.6f}".format(i, self._chi2, -rel_diff))
205+
rel_diff = (chi2_prev - self._chi2) / (
206+
chi2_prev + np.finfo(float).eps)
207+
print(
208+
"{:9d} {:20.4f} {:18.6f}".format(i, self._chi2, -rel_diff))
194209
if self._chi2 < chi2_prev and rel_diff < tol:
195210
return
196211
else:
@@ -207,7 +222,7 @@ def optimize(self, tol=1e-4, max_iter=20, fix_first_pose=True):
207222
self._gradient[:dim] = 0.
208223

209224
# Solve for the updates
210-
dx = spsolve(self._hessian, -self._gradient) # pylint: disable=invalid-unary-operand-type
225+
dx = spsolve(self._hessian, -self._gradient)
211226

212227
# Apply the updates
213228
for v, dx_i in zip(self._vertices, np.split(dx, n)):
@@ -216,7 +231,8 @@ def optimize(self, tol=1e-4, max_iter=20, fix_first_pose=True):
216231
# If we reached the maximum number of iterations, print out the final iteration's results
217232
self.calc_chi2()
218233
rel_diff = (chi2_prev - self._chi2) / (chi2_prev + np.finfo(float).eps)
219-
print("{:9d} {:20.4f} {:18.6f}".format(max_iter, self._chi2, -rel_diff))
234+
print("{:9d} {:20.4f} {:18.6f}".format(
235+
max_iter, self._chi2, -rel_diff))
220236

221237
def to_g2o(self, outfile):
222238
"""Save the graph in .g2o format.
@@ -234,7 +250,8 @@ def to_g2o(self, outfile):
234250
for e in self._edges:
235251
f.write(e.to_g2o())
236252

237-
def plot(self, vertex_color='r', vertex_marker='o', vertex_markersize=3, edge_color='b', title=None):
253+
def plot(self, vertex_color='r', vertex_marker='o', vertex_markersize=3,
254+
edge_color='b', title=None):
238255
"""Plot the graph.
239256
240257
Parameters

SLAM/GraphBasedSLAM/graphslam/load.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
99
"""
1010

11-
1211
import logging
1312

1413
import numpy as np
@@ -19,7 +18,6 @@
1918
from .util import upper_triangular_matrix_to_full_matrix
2019
from .vertex import Vertex
2120

22-
2321
_LOGGER = logging.getLogger(__name__)
2422

2523

@@ -44,15 +42,17 @@ def load_g2o_se2(infile):
4442
for line in f.readlines():
4543
if line.startswith("VERTEX_SE2"):
4644
numbers = line[10:].split()
47-
arr = np.array([float(number) for number in numbers[1:]], dtype=np.float64)
45+
arr = np.array([float(number) for number in numbers[1:]],
46+
dtype=float)
4847
p = PoseSE2(arr[:2], arr[2])
4948
v = Vertex(int(numbers[0]), p)
5049
vertices.append(v)
5150
continue
5251

5352
if line.startswith("EDGE_SE2"):
5453
numbers = line[9:].split()
55-
arr = np.array([float(number) for number in numbers[2:]], dtype=np.float64)
54+
arr = np.array([float(number) for number in numbers[2:]],
55+
dtype=float)
5656
vertex_ids = [int(numbers[0]), int(numbers[1])]
5757
estimate = PoseSE2(arr[:2], arr[2])
5858
information = upper_triangular_matrix_to_full_matrix(arr[3:], 3)

SLAM/GraphBasedSLAM/graphslam/pose/se2.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"""
1010

1111
import math
12-
1312
import numpy as np
1413

1514
from ..util import neg_pi_to_pi
@@ -26,8 +25,10 @@ class PoseSE2(np.ndarray):
2625
The angle of the pose (in radians)
2726
2827
"""
28+
2929
def __new__(cls, position, orientation):
30-
obj = np.array([position[0], position[1], neg_pi_to_pi(orientation)], dtype=np.float64).view(cls)
30+
obj = np.array([position[0], position[1], neg_pi_to_pi(orientation)],
31+
dtype=float).view(cls)
3132
return obj
3233

3334
# pylint: disable=arguments-differ
@@ -73,7 +74,9 @@ def to_matrix(self):
7374
The pose as an :math:`SE(2)` matrix
7475
7576
"""
76-
return np.array([[np.cos(self[2]), -np.sin(self[2]), self[0]], [np.sin(self[2]), np.cos(self[2]), self[1]], [0., 0., 1.]], dtype=np.float64)
77+
return np.array([[np.cos(self[2]), -np.sin(self[2]), self[0]],
78+
[np.sin(self[2]), np.cos(self[2]), self[1]],
79+
[0., 0., 1.]], dtype=float)
7780

7881
@classmethod
7982
def from_matrix(cls, matrix):
@@ -90,7 +93,8 @@ def from_matrix(cls, matrix):
9093
The matrix as a `PoseSE2` object
9194
9295
"""
93-
return cls([matrix[0, 2], matrix[1, 2]], math.atan2(matrix[1, 0], matrix[0, 0]))
96+
return cls([matrix[0, 2], matrix[1, 2]],
97+
math.atan2(matrix[1, 0], matrix[0, 0]))
9498

9599
# ======================================================================= #
96100
# #
@@ -131,7 +135,9 @@ def inverse(self):
131135
The pose's inverse
132136
133137
"""
134-
return PoseSE2([-self[0] * np.cos(self[2]) - self[1] * np.sin(self[2]), self[0] * np.sin(self[2]) - self[1] * np.cos([self[2]])], -self[2])
138+
return PoseSE2([-self[0] * np.cos(self[2]) - self[1] * np.sin(self[2]),
139+
self[0] * np.sin(self[2]) - self[1] * np.cos(
140+
[self[2]])], -self[2])
135141

136142
# ======================================================================= #
137143
# #
@@ -152,7 +158,10 @@ def __add__(self, other):
152158
The result of pose composition
153159
154160
"""
155-
return PoseSE2([self[0] + other[0] * np.cos(self[2]) - other[1] * np.sin(self[2]), self[1] + other[0] * np.sin(self[2]) + other[1] * np.cos(self[2])], neg_pi_to_pi(self[2] + other[2]))
161+
return PoseSE2(
162+
[self[0] + other[0] * np.cos(self[2]) - other[1] * np.sin(self[2]),
163+
self[1] + other[0] * np.sin(self[2]) + other[1] * np.cos(self[2])
164+
], neg_pi_to_pi(self[2] + other[2]))
156165

157166
def __sub__(self, other):
158167
r"""Subtract poses (i.e., inverse pose composition): :math:`p_1 \ominus p_2`.
@@ -168,4 +177,8 @@ def __sub__(self, other):
168177
The result of inverse pose composition
169178
170179
"""
171-
return PoseSE2([(self[0] - other[0]) * np.cos(other[2]) + (self[1] - other[1]) * np.sin(other[2]), (other[0] - self[0]) * np.sin(other[2]) + (self[1] - other[1]) * np.cos(other[2])], neg_pi_to_pi(self[2] - other[2]))
180+
return PoseSE2([(self[0] - other[0]) * np.cos(other[2]) + (
181+
self[1] - other[1]) * np.sin(other[2]),
182+
(other[0] - self[0]) * np.sin(other[2]) + (
183+
self[1] - other[1]) * np.cos(other[2])],
184+
neg_pi_to_pi(self[2] - other[2]))

SLAM/GraphBasedSLAM/graphslam/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def upper_triangular_matrix_to_full_matrix(arr, n):
7171
triu1 = np.triu_indices(n, 1)
7272
tril1 = np.tril_indices(n, -1)
7373

74-
mat = np.zeros((n, n), dtype=np.float64)
74+
mat = np.zeros((n, n), dtype=float)
7575
mat[triu0] = arr
7676
mat[tril1] = mat[triu1]
7777

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
numpy == 1.19.5
1+
numpy == 1.20.1
22
scipy == 1.6.0
33
pandas == 1.2.1
44
matplotlib == 3.3.4

0 commit comments

Comments
 (0)