Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Improve speed in some modules#22678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1150,7 +1150,7 @@ def boxplot_stats(X, whis=1.5, bootstrap=None, labels=None, | ||
def _bootstrap_median(data, N=5000): | ||
# determine 95% confidence intervals of the median | ||
M = len(data) | ||
percentiles =(2.5, 97.5) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I don't think this matters wrt speed (does it?); also I prefer a list here as this matches "more" the return type of np.percentile below (a ndarray is closer to a list than to a tuple.) | ||
bs_index = np.random.randint(M, size=(N, M)) | ||
bsData = data[bs_index] | ||
@@ -1169,8 +1169,9 @@ def _compute_conf_interval(data, med, iqr, bootstrap): | ||
else: | ||
N = len(data) | ||
half_height = 1.57 * iqr / (N ** (1 / 2)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I guess you could inline len(data) into the computation here. | ||
notch_min = med - half_height | ||
notch_max = med + half_height | ||
return notch_min, notch_max | ||
@@ -1221,7 +1222,8 @@ def _compute_conf_interval(data, med, iqr, bootstrap): | ||
stats['mean'] = np.mean(x) | ||
# medians and quartiles | ||
percentiles = (25, 50, 75) | ||
q1, med, q3 = np.percentile(x, percentiles) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. ditto, leave as before. | ||
# interquartile range | ||
stats['iqr'] = q3 - q1 | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -677,7 +677,7 @@ def _set_pentagon(self): | ||
self._path = polypath | ||
else: | ||
verts = polypath.vertices | ||
y = (1 +5 ** (1 / 2)) / 4. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I'm not convinced of all these sqrt micro-optimizations. IMHO it makes the code less readable, and the performance gain is minimal. For example here The sqrt is less than 2% of the the time of the immediate surrounding code in the function:
and that function | ||
top = Path(verts[[0, 1, 4, 0]]) | ||
bottom = Path(verts[[1, 2, 3, 4, 1]]) | ||
left = Path([verts[0], verts[1], verts[2], [0, -y], verts[0]]) | ||
@@ -747,7 +747,7 @@ def _set_hexagon2(self): | ||
else: | ||
verts = polypath.vertices | ||
# not drawing inside lines | ||
x, y =3 ** (1 / 2) / 4, 3 / 4. | ||
top = Path(verts[[1, 0, 5, 4, 1]]) | ||
bottom = Path(verts[1:5]) | ||
left = Path(np.concatenate([ | ||
@@ -772,7 +772,7 @@ def _set_octagon(self): | ||
self._transform.rotate_deg(22.5) | ||
self._path = polypath | ||
else: | ||
x =2 ** (1 / 2) / 4. | ||
self._path = self._alt_path = Path( | ||
[[0, -1], [0, 1], [-x, 1], [-1, x], | ||
[-1, -x], [-x, -1], [0, -1]]) | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -822,45 +822,48 @@ def circle(cls, center=(0., 0.), radius=1., readonly=False): | ||
Bezier Cubic Splines <https://www.tinaja.com/glib/ellipse4.pdf>`_. | ||
""" | ||
MAGIC = 0.2652031 | ||
SQRTHALF =(1 / 2) ** (1 / 2) | ||
MAGIC45 = SQRTHALF * MAGIC | ||
MAGICSUM = SQRTHALF + MAGIC45 | ||
MAGICDIFF = SQRTHALF - MAGIC45 | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I guess I would just write this is as | ||
vertices =((0.0, -1.0), | ||
(MAGIC, -1.0), | ||
(MAGICDIFF, -MAGICSUM), | ||
(SQRTHALF, -SQRTHALF), | ||
(MAGICSUM, -MAGICDIFF), | ||
(1.0, -MAGIC), | ||
(1.0, 0.0), | ||
(1.0, MAGIC), | ||
(MAGICSUM, MAGICDIFF), | ||
(SQRTHALF, SQRTHALF), | ||
(MAGICDIFF, MAGICSUM), | ||
(MAGIC, 1.0), | ||
(0.0, 1.0), | ||
(-MAGIC, 1.0), | ||
(-MAGICDIFF, MAGICSUM), | ||
(-SQRTHALF, SQRTHALF), | ||
(-MAGICSUM, MAGICDIFF), | ||
(-1.0, MAGIC), | ||
(-1.0, 0.0), | ||
(-1.0, -MAGIC), | ||
(-MAGICSUM, -MAGICDIFF), | ||
(-SQRTHALF, -SQRTHALF), | ||
(-MAGICDIFF, -MAGICSUM), | ||
(-MAGIC, -1.0), | ||
(0.0, -1.0), | ||
(0.0, -1.0)) | ||
vertices = np.array(vertices, dtype=float) | ||
codes = [cls.CURVE4] * 26 | ||
codes[0] = cls.MOVETO | ||
@@ -878,31 +881,32 @@ def unit_circle_righthalf(cls): | ||
""" | ||
if cls._unit_circle_righthalf is None: | ||
MAGIC = 0.2652031 | ||
SQRTHALF =(1 / 2) ** (1 / 2) | ||
MAGIC45 = SQRTHALF * MAGIC | ||
MAGICSUM = SQRTHALF + MAGIC45 | ||
MAGICDIFF = SQRTHALF - MAGIC45 | ||
vertices = ((0.0, -1.0), | ||
(MAGIC, -1.0), | ||
(MAGICDIFF, -MAGICSUM), | ||
(SQRTHALF, -SQRTHALF), | ||
(MAGICSUM, -MAGICDIFF), | ||
(1.0, -MAGIC), | ||
(1.0, 0.0), | ||
(1.0, MAGIC), | ||
(MAGICSUM, MAGICDIFF), | ||
(SQRTHALF, SQRTHALF), | ||
(MAGICDIFF, MAGICSUM), | ||
(MAGIC, 1.0), | ||
(0.0, 1.0), | ||
(0.0, -1.0)) | ||
vertices = np.array(vertices, dtype=float) | ||
codes = np.full(14, cls.CURVE4, dtype=cls.code_type) | ||
codes[0] = cls.MOVETO | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -165,7 +165,7 @@ def transform_non_affine(self, xy): | ||
# docstring inherited | ||
x, y = xy.T | ||
r = np.hypot(x, y) | ||
QuLogic marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
theta = np.arctan2(y, x) % (2 * np.pi) | ||
# PolarAxes does not use the theta transforms here, but apply them for | ||
# backwards-compatibility if not being used by it. | ||
if self._apply_theta_transforms and self._axis is not None: | ||
@@ -1076,7 +1076,7 @@ def set_theta_zero_location(self, loc, offset=0.0): | ||
'SW': np.pi * 1.25, | ||
'S': np.pi * 1.5, | ||
'SE': np.pi * 1.75, | ||
'E': 0., | ||
'NE': np.pi * 0.25} | ||
return self.set_theta_offset(mapping[loc] + np.deg2rad(offset)) | ||