| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -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] | ||
| percentiles = (2.5, 97.5) | ||
|
|
||
| bs_index = np.random.randint(M, size=(N, M)) | ||
| bsData = data[bs_index] | ||
| Expand All | @@ -1169,8 +1169,9 @@ def _compute_conf_interval(data, med, iqr, bootstrap): | |
| else: | ||
|
|
||
| N = len(data) | ||
| notch_min = med - 1.57 * iqr / np.sqrt(N) | ||
| notch_max = med + 1.57 * iqr / np.sqrt(N) | ||
| half_height = 1.57 * iqr / (N ** (1 / 2)) | ||
|
Comment thread
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI guess you could inline len(data) into the computation here.
Sorry, something went wrong.
All reactions
|
||
| notch_min = med - half_height | ||
| notch_max = med + half_height | ||
|
|
||
| return notch_min, notch_max | ||
|
|
||
| Expand Down Expand Up | @@ -1221,7 +1222,8 @@ def _compute_conf_interval(data, med, iqr, bootstrap): | |
| stats['mean'] = np.mean(x) | ||
|
|
||
| # medians and quartiles | ||
| q1, med, q3 = np.percentile(x, [25, 50, 75]) | ||
| percentiles = (25, 50, 75) | ||
| q1, med, q3 = np.percentile(x, percentiles) | ||
|
Comment thread
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Qualityditto, leave as before.
Sorry, something went wrong.
All reactions
|
||
|
|
||
| # interquartile range | ||
| stats['iqr'] = q3 - q1 | ||
| Expand Down | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -677,7 +677,7 @@ def _set_pentagon(self): | |
| self._path = polypath | ||
| else: | ||
| verts = polypath.vertices | ||
| y = (1 + np.sqrt(5)) / 4. | ||
| y = (1 + 5 ** (1 / 2)) / 4. | ||
|
Comment thread
Copy link
Copy Markdown
Member
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI'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: In [21]: %%timeit
...: Affine2D().scale(0.5)
...: polypath = Path.unit_regular_polygon(5)
...: verts = polypath.vertices
...: 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]])
...: right = Path([verts[0], verts[4], verts[3], [0, -y], verts[0]])
...:
61.1 µs ± 228 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
In [22]: %timeit np.sqrt(5)
2.36 µs ± 35 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
and that function _set_pentagon() again is only used to create a new marker object, which in itself is quite rare. So I bet the performance gain is not measurable in any real example.
Sorry, something went wrong.
All reactions
|
||
| 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]]) | ||
| Expand Down Expand Up | @@ -747,7 +747,7 @@ def _set_hexagon2(self): | |
| else: | ||
| verts = polypath.vertices | ||
| # not drawing inside lines | ||
| x, y = np.sqrt(3) / 4, 3 / 4. | ||
| 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([ | ||
| Expand All | @@ -772,7 +772,7 @@ def _set_octagon(self): | |
| self._transform.rotate_deg(22.5) | ||
| self._path = polypath | ||
| else: | ||
| x = np.sqrt(2.) / 4. | ||
| 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]]) | ||
| Expand Down | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -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 = np.sqrt(0.5) | ||
| SQRTHALF = (1 / 2) ** (1 / 2) | ||
| MAGIC45 = SQRTHALF * MAGIC | ||
| MAGICSUM = SQRTHALF + MAGIC45 | ||
| MAGICDIFF = SQRTHALF - MAGIC45 | ||
|
|
||
| vertices = np.array([[0.0, -1.0], | ||
|
Comment thread
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI guess I would just write this is as vertices = np.array([...]) without even bothering with the dtype=float which is unneeded; this also avoids a temporary variable (mostly avoids having to keep track of it mentally). Ditto below.
Sorry, something went wrong.
All reactions
|
||
| vertices = ((0.0, -1.0), | ||
|
|
||
| [MAGIC, -1.0], | ||
| [SQRTHALF-MAGIC45, -SQRTHALF-MAGIC45], | ||
| [SQRTHALF, -SQRTHALF], | ||
| (MAGIC, -1.0), | ||
| (MAGICDIFF, -MAGICSUM), | ||
| (SQRTHALF, -SQRTHALF), | ||
|
|
||
| [SQRTHALF+MAGIC45, -SQRTHALF+MAGIC45], | ||
| [1.0, -MAGIC], | ||
| [1.0, 0.0], | ||
| (MAGICSUM, -MAGICDIFF), | ||
| (1.0, -MAGIC), | ||
| (1.0, 0.0), | ||
|
|
||
| [1.0, MAGIC], | ||
| [SQRTHALF+MAGIC45, SQRTHALF-MAGIC45], | ||
| [SQRTHALF, SQRTHALF], | ||
| (1.0, MAGIC), | ||
| (MAGICSUM, MAGICDIFF), | ||
| (SQRTHALF, SQRTHALF), | ||
|
|
||
| [SQRTHALF-MAGIC45, SQRTHALF+MAGIC45], | ||
| [MAGIC, 1.0], | ||
| [0.0, 1.0], | ||
| (MAGICDIFF, MAGICSUM), | ||
| (MAGIC, 1.0), | ||
| (0.0, 1.0), | ||
|
|
||
| [-MAGIC, 1.0], | ||
| [-SQRTHALF+MAGIC45, SQRTHALF+MAGIC45], | ||
| [-SQRTHALF, SQRTHALF], | ||
| (-MAGIC, 1.0), | ||
| (-MAGICDIFF, MAGICSUM), | ||
| (-SQRTHALF, SQRTHALF), | ||
|
|
||
| [-SQRTHALF-MAGIC45, SQRTHALF-MAGIC45], | ||
| [-1.0, MAGIC], | ||
| [-1.0, 0.0], | ||
| (-MAGICSUM, MAGICDIFF), | ||
| (-1.0, MAGIC), | ||
| (-1.0, 0.0), | ||
|
|
||
| [-1.0, -MAGIC], | ||
| [-SQRTHALF-MAGIC45, -SQRTHALF+MAGIC45], | ||
| [-SQRTHALF, -SQRTHALF], | ||
| (-1.0, -MAGIC), | ||
| (-MAGICSUM, -MAGICDIFF), | ||
| (-SQRTHALF, -SQRTHALF), | ||
|
|
||
| [-SQRTHALF+MAGIC45, -SQRTHALF-MAGIC45], | ||
| [-MAGIC, -1.0], | ||
| [0.0, -1.0], | ||
| (-MAGICDIFF, -MAGICSUM), | ||
| (-MAGIC, -1.0), | ||
| (0.0, -1.0), | ||
|
|
||
| [0.0, -1.0]], | ||
| dtype=float) | ||
| (0.0, -1.0)) | ||
|
|
||
| vertices = np.array(vertices, dtype=float) | ||
|
|
||
| codes = [cls.CURVE4] * 26 | ||
| codes[0] = cls.MOVETO | ||
| Expand All | @@ -878,31 +881,32 @@ def unit_circle_righthalf(cls): | |
| """ | ||
| if cls._unit_circle_righthalf is None: | ||
| MAGIC = 0.2652031 | ||
| SQRTHALF = np.sqrt(0.5) | ||
| SQRTHALF = (1 / 2) ** (1 / 2) | ||
| MAGIC45 = SQRTHALF * MAGIC | ||
| MAGICSUM = SQRTHALF + MAGIC45 | ||
| MAGICDIFF = SQRTHALF - MAGIC45 | ||
|
|
||
| vertices = np.array( | ||
| [[0.0, -1.0], | ||
| vertices = ((0.0, -1.0), | ||
|
|
||
| [MAGIC, -1.0], | ||
| [SQRTHALF-MAGIC45, -SQRTHALF-MAGIC45], | ||
| [SQRTHALF, -SQRTHALF], | ||
| (MAGIC, -1.0), | ||
| (MAGICDIFF, -MAGICSUM), | ||
| (SQRTHALF, -SQRTHALF), | ||
|
|
||
| [SQRTHALF+MAGIC45, -SQRTHALF+MAGIC45], | ||
| [1.0, -MAGIC], | ||
| [1.0, 0.0], | ||
| (MAGICSUM, -MAGICDIFF), | ||
| (1.0, -MAGIC), | ||
| (1.0, 0.0), | ||
|
|
||
| [1.0, MAGIC], | ||
| [SQRTHALF+MAGIC45, SQRTHALF-MAGIC45], | ||
| [SQRTHALF, SQRTHALF], | ||
| (1.0, MAGIC), | ||
| (MAGICSUM, MAGICDIFF), | ||
| (SQRTHALF, SQRTHALF), | ||
|
|
||
| [SQRTHALF-MAGIC45, SQRTHALF+MAGIC45], | ||
| [MAGIC, 1.0], | ||
| [0.0, 1.0], | ||
| (MAGICDIFF, MAGICSUM), | ||
| (MAGIC, 1.0), | ||
| (0.0, 1.0), | ||
|
|
||
| [0.0, -1.0]], | ||
| (0.0, -1.0)) | ||
|
|
||
| float) | ||
| vertices = np.array(vertices, dtype=float) | ||
|
|
||
| codes = np.full(14, cls.CURVE4, dtype=cls.code_type) | ||
| codes[0] = cls.MOVETO | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI 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.)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.