Skip to content

Commit

Permalink
Upgrade to version 22.3.0 of the Black formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
omersahintas committed Mar 15, 2023
1 parent 41bba23 commit 31800c3
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def seg_arc_intersect(seg, origin, radius, arc):

D = D / t_max

coef = np.array([1, 2 * np.dot(D, (A - O)), norm(A - O) ** 2 - r ** 2])
coef = np.array([1, 2 * np.dot(D, (A - O)), norm(A - O) ** 2 - r**2])
coef = np.round(coef, decimals=8)

sol = np.roots(coef)
Expand Down
16 changes: 8 additions & 8 deletions p3iv_modules/src/p3iv_modules/perception/limited.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,29 +117,29 @@ def __init__(
# position covariance matrix for percepted objects
self.per_pos_cov = np.asarray(
[
[per_pos_sigma_x ** 2, per_pos_cross_corr * per_pos_sigma_x * per_pos_sigma_y],
[per_pos_cross_corr * per_pos_sigma_x * per_pos_sigma_y, per_pos_sigma_y ** 2],
[per_pos_sigma_x**2, per_pos_cross_corr * per_pos_sigma_x * per_pos_sigma_y],
[per_pos_cross_corr * per_pos_sigma_x * per_pos_sigma_y, per_pos_sigma_y**2],
]
)
# velocity covariance matrix for percepted objects
self.per_vel_cov = np.asarray(
[
[per_vel_sigma_x ** 2, per_vel_cross_corr * per_vel_sigma_x * per_vel_sigma_y],
[per_vel_cross_corr * per_vel_sigma_x * per_vel_sigma_y, per_vel_sigma_y ** 2],
[per_vel_sigma_x**2, per_vel_cross_corr * per_vel_sigma_x * per_vel_sigma_y],
[per_vel_cross_corr * per_vel_sigma_x * per_vel_sigma_y, per_vel_sigma_y**2],
]
)
# position covariance matrix for localization - ego vehicle
self.loc_pos_cov = np.asarray(
[
[loc_pos_sigma_x ** 2, loc_pos_cross_corr * loc_pos_sigma_x * loc_pos_sigma_y],
[loc_pos_cross_corr * loc_pos_sigma_x * loc_pos_sigma_y, loc_pos_sigma_y ** 2],
[loc_pos_sigma_x**2, loc_pos_cross_corr * loc_pos_sigma_x * loc_pos_sigma_y],
[loc_pos_cross_corr * loc_pos_sigma_x * loc_pos_sigma_y, loc_pos_sigma_y**2],
]
)
# velocity covariance matrix for localization - ego vehicle
self.loc_vel_cov = np.asarray(
[
[loc_vel_sigma_x ** 2, loc_vel_cross_corr * loc_vel_sigma_x * loc_vel_sigma_y],
[loc_vel_cross_corr * loc_vel_sigma_x * loc_vel_sigma_y, loc_vel_sigma_y ** 2],
[loc_vel_sigma_x**2, loc_vel_cross_corr * loc_vel_sigma_x * loc_vel_sigma_y],
[loc_vel_cross_corr * loc_vel_sigma_x * loc_vel_sigma_y, loc_vel_sigma_y**2],
]
)

Expand Down
16 changes: 8 additions & 8 deletions p3iv_modules/src/p3iv_modules/perception/perfect.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,29 @@ def __init__(
# position covariance matrix for percepted objects
self.per_pos_cov = np.asarray(
[
[per_pos_sigma_x ** 2, per_pos_cross_corr * per_pos_sigma_x * per_pos_sigma_y],
[per_pos_cross_corr * per_pos_sigma_x * per_pos_sigma_y, per_pos_sigma_y ** 2],
[per_pos_sigma_x**2, per_pos_cross_corr * per_pos_sigma_x * per_pos_sigma_y],
[per_pos_cross_corr * per_pos_sigma_x * per_pos_sigma_y, per_pos_sigma_y**2],
]
)
# velocity covariance matrix for percepted objects
self.per_vel_cov = np.asarray(
[
[per_vel_sigma_x ** 2, per_vel_cross_corr * per_vel_sigma_x * per_vel_sigma_y],
[per_vel_cross_corr * per_vel_sigma_x * per_vel_sigma_y, per_vel_sigma_y ** 2],
[per_vel_sigma_x**2, per_vel_cross_corr * per_vel_sigma_x * per_vel_sigma_y],
[per_vel_cross_corr * per_vel_sigma_x * per_vel_sigma_y, per_vel_sigma_y**2],
]
)
# position covariance matrix for localization - ego vehicle
self.loc_pos_cov = np.asarray(
[
[loc_pos_sigma_x ** 2, loc_pos_cross_corr * loc_pos_sigma_x * loc_pos_sigma_y],
[loc_pos_cross_corr * loc_pos_sigma_x * loc_pos_sigma_y, loc_pos_sigma_y ** 2],
[loc_pos_sigma_x**2, loc_pos_cross_corr * loc_pos_sigma_x * loc_pos_sigma_y],
[loc_pos_cross_corr * loc_pos_sigma_x * loc_pos_sigma_y, loc_pos_sigma_y**2],
]
)
# velocity covariance matrix for localization - ego vehicle
self.loc_vel_cov = np.asarray(
[
[loc_vel_sigma_x ** 2, loc_vel_cross_corr * loc_vel_sigma_x * loc_vel_sigma_y],
[loc_vel_cross_corr * loc_vel_sigma_x * loc_vel_sigma_y, loc_vel_sigma_y ** 2],
[loc_vel_sigma_x**2, loc_vel_cross_corr * loc_vel_sigma_x * loc_vel_sigma_y],
[loc_vel_cross_corr * loc_vel_sigma_x * loc_vel_sigma_y, loc_vel_sigma_y**2],
]
)

Expand Down
2 changes: 1 addition & 1 deletion p3iv_utils/src/p3iv_utils/driver_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def accs(self, l_ego, v_ego, l_front_array, v_front_array, N, dt):
if idm_acc < v_ego / dt:
idm_acc = v_ego / dt

displacement = v_ego * dt + 0.5 * idm_acc * (dt ** 2)
displacement = v_ego * dt + 0.5 * idm_acc * (dt**2)
l_ego = l_ego + displacement

idm_pos_array[i] = l_ego
Expand Down
8 changes: 4 additions & 4 deletions p3iv_utils/src/p3iv_utils/extrema_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ def get_braking_dist(v_curr, acceleration, **kwargs):
dist = v_curr * dt - 0.5 * acceleration * dt**2 - 1/6 * jerk * dt**3
"""

return np.abs(v_curr ** 2 / (2 * acceleration))
return np.abs(v_curr**2 / (2 * acceleration))


def accelerating_motion(v_curr, acceleration, **kwargs):
delta_time = kwargs["delta_time"]
return v_curr * delta_time + 0.5 * acceleration * delta_time ** 2
return v_curr * delta_time + 0.5 * acceleration * delta_time**2


def get_max_acc_displacements(vel_array, motion_func, acc, dt):
Expand Down Expand Up @@ -55,12 +55,12 @@ def saturation(param, threshold):


def get_delta_l(v, a, dt):
delta_l = v * dt + 0.5 * a * dt ** 2
delta_l = v * dt + 0.5 * a * dt**2
if delta_l > 0:
return delta_l
else:
t_stop = np.abs(v / a)
return v * t_stop + 0.5 * a * t_stop ** 2
return v * t_stop + 0.5 * a * t_stop**2


def get_delta_v(v, a, dt):
Expand Down
2 changes: 1 addition & 1 deletion p3iv_utils/src/p3iv_utils/integrate_acceleration.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def generate_position_velocity_acc_array(
# set initial values
x[:, 0] = np.array([s_0, v_0, 0])

half_dt_sim_square = 0.5 * dt_sim ** 2
half_dt_sim_square = 0.5 * dt_sim**2

for i in range(n_sim_timesteps):
x[0, i + 1] = x[0, i] + dt_sim * x[1, i] + half_dt_sim_square * acc[i]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def hypot(a, b):
# do not use np.hypot(a, b); may not work well with autodiff & jit
return (a ** 2 + b ** 2) ** 0.5
return (a**2 + b**2) ** 0.5


class InterpolatedPolylineSegment(object):
Expand Down
8 changes: 4 additions & 4 deletions p3iv_utils_polyline/test/test_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def test_straight_line_w_python_impl(self):
self.assertAlmostEqual(obs_ip.signed_distance(0, 2), 1)

# test the distance at the LAST-segment
self.assertAlmostEqual(obs_ip.signed_distance(4, 3), 2 * 2 ** 0.5)
self.assertAlmostEqual(obs_ip.signed_distance(4, 3), 2 * 2**0.5)

# test the distance at the FIRST-segment
self.assertAlmostEqual(obs_ip.signed_distance(-4, -1), -2 * 2 ** 0.5)
self.assertAlmostEqual(obs_ip.signed_distance(-4, -1), -2 * 2**0.5)

def test_straight_line_w_pybind_impl(self):
from p3iv_utils_polyline.py_interpolated_polyline import PyInterpolatedPolyline as InterpolatedPolyline
Expand All @@ -44,10 +44,10 @@ def test_straight_line_w_pybind_impl(self):
self.assertAlmostEqual(obs_ip.signed_distance(0, 2), 1)

# test the distance at the LAST-segment
self.assertAlmostEqual(obs_ip.signed_distance(4, 3), 2 * 2 ** 0.5)
self.assertAlmostEqual(obs_ip.signed_distance(4, 3), 2 * 2**0.5)

# test the distance at the FIRST-segment
self.assertAlmostEqual(obs_ip.signed_distance(-4, -1), -2 * 2 ** 0.5)
self.assertAlmostEqual(obs_ip.signed_distance(-4, -1), -2 * 2**0.5)


class InterpolatedPolylineRoundaboutOFCenterlineTest(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def generateFoVWedge(
radius = halfwidth + radiusFactor * (baserange - halfwidth)
# calculate center point of circle sector
# c_y = leftP_y - sqrt(radius²-leftP_x²)
center_y = leftP[1] - math.sqrt(radius ** 2 - leftP[0] ** 2)
center_y = leftP[1] - math.sqrt(radius**2 - leftP[0] ** 2)
center = np.array([0, center_y])
# calculate angle of circle sector
circleSectorAngle = 2 * math.asin(halfwidth / radius) # in radians
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ def uvn_product(uvn1, uvn2):


def _cal_par(mu1, sigma1, mu2, sigma2):
mu_12 = (mu1 * sigma2 ** 2 + mu2 * sigma1 ** 2) / (sigma1 ** 2 + sigma2 ** 2)
sigma_12 = np.sqrt((sigma1 ** 2 * sigma2 ** 2) / (sigma1 ** 2 + sigma2 ** 2))
mu_12 = (mu1 * sigma2**2 + mu2 * sigma1**2) / (sigma1**2 + sigma2**2)
sigma_12 = np.sqrt((sigma1**2 * sigma2**2) / (sigma1**2 + sigma2**2))
s = (
1
/ (np.sqrt(2 * np.pi * (sigma1 ** 2 + sigma2 ** 2)))
* np.exp(-((mu1 - mu2) ** 2 / (2 * (sigma1 ** 2 + sigma2 ** 2))))
/ (np.sqrt(2 * np.pi * (sigma1**2 + sigma2**2)))
* np.exp(-((mu1 - mu2) ** 2 / (2 * (sigma1**2 + sigma2**2))))
)
return s, mu_12, sigma_12


def cal_uncertainty_of_mul(mu1, cov1, mu2, cov2):
return mu2 ** 2 * cov1 + mu1 ** 2 * cov2
return mu2**2 * cov1 + mu1**2 * cov2


def get_diff_integral_list(uvn1, uvn2, n_std=4):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ def _pdf_jointly_normal(self, x, y):
rho = self.covariance[0, 1] / (sigma_1 * sigma_2)
f = (
1
/ (2 * np.pi * sigma_1 * sigma_2 * np.sqrt(1 - rho ** 2))
/ (2 * np.pi * sigma_1 * sigma_2 * np.sqrt(1 - rho**2))
* np.exp(
-((x - mu[0]) ** 2) / (2 * (1 - rho ** 2) * sigma_1 ** 2)
- (y - mu[1]) ** 2 / (2 * (1 - rho ** 2) * sigma_2 ** 2)
+ (rho * (x - mu[0]) * (y - mu[1])) / ((1 - rho ** 2) * sigma_1 * sigma_2)
-((x - mu[0]) ** 2) / (2 * (1 - rho**2) * sigma_1**2)
- (y - mu[1]) ** 2 / (2 * (1 - rho**2) * sigma_2**2)
+ (rho * (x - mu[0]) * (y - mu[1])) / ((1 - rho**2) * sigma_1 * sigma_2)
)
)
return f
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _intermediate_parameters(self):
@staticmethod
def _pdf_standard(x):
"""Probability distribution of standard normal distribution"""
return 1 / np.sqrt(2 * np.pi) * np.exp(-(x ** 2) / 2)
return 1 / np.sqrt(2 * np.pi) * np.exp(-(x**2) / 2)

@staticmethod
def _cdf_standard(x):
Expand All @@ -104,7 +104,7 @@ def within_n_std(self, x, y, n_std):
points = self.reform_points(x, y)

mean_x, mean_y, theta, a, b = super(TruncatedBivariateNormalDistribution, self).range(n_std)
c = np.sqrt(a ** 2 - b ** 2) # calculate linear eccentricity
c = np.sqrt(a**2 - b**2) # calculate linear eccentricity
F1 = np.array([mean_x, mean_y]) + c * np.array([np.cos(theta), np.sin(theta)]) # focal-point 1 coords
F2 = np.array([mean_x, mean_y]) - c * np.array([np.cos(theta), np.sin(theta)]) # focal-point 2 coords

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __div__(self, other):
def pdf(self, x, *args):
mu = self.mean
sigma = np.sqrt(self.covariance)
f_val = 1 / (np.sqrt(2 * np.pi) * sigma) * np.exp(-((x - mu) ** 2 / (2 * sigma ** 2)))
f_val = 1 / (np.sqrt(2 * np.pi) * sigma) * np.exp(-((x - mu) ** 2 / (2 * sigma**2)))
return f_val

def cdf(self, x, *args):
Expand Down

0 comments on commit 31800c3

Please sign in to comment.