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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature stack base #1671
Feature stack base #1671
Conversation
@Tillsten Are you happy with the |
@Tillsten Instead of embedding an image to the |
I have also been intermittently getting this failure. (python2.7) |
@tacaswell Specifically on this branch, or in general? |
@dmcdougall in general (typically with in a few commits of master). Sorry I wasn't clear. |
@dmcdougall Just thanks for doing the final touches! |
@Tillsten No problem. Feedback permitting, someone else should push the big green button! |
@@ -863,6 +863,41 @@ def test_stackplot(): | |||
ax.set_xlim((0, 10)) | |||
ax.set_ylim((0, 70)) | |||
|
|||
|
|||
@image_comparison(baseline_images=['stackplot_test_baseline']) |
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.
Think we need to "remove_text" from the test results (to avoid freetype version differences across architectures)
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.
Yes! I think I meant to do this and forgot. Thanks.
Excellent feature. Only a few minor comments, but I think it looks great! |
|
||
for i in range(1, n): | ||
center[i] = center[i - 1] | ||
center[i] += np.dot(move_up[:, i], increase[:, i]) |
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.
@Tillsten I used your idea to construct below_size and it works nicely! But now I'm stuck here. Any ideas on how to move out the center
with that inter-dependence inside the loop? I tried modifying your approach but it didn't work.
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.
Are you sure my code dient work? I also fester the code and the max difff was 1e-17 maybe enough to let it fail. I am at my phone at the moment but I think using multiply, sum and than cumsum should do the trick.
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.
I copied and pasted verbatim into the else
block, replacing all I had there already. Maybe I fluffed it up. You could try it independently and run the test for feedback. That would actually be helpful.
Wooooo vectorised! Thanks for you help and advice @Tillsten. Do you like the proposed solution? Is there anything you'd like to add/change before it is rebased and merged? |
@dmcdougall I checked both versions, both are getting excat the same result on my machine. I prefer mine, because edit: I am wrong, it just extract the diagonal (the dot product is (m, m)). But still, some unnecessary terms are calculated. Some simple timing shows a 2.5 increase for my method. |
Also i was able to simplify below_size. stack = np.cumsum(y, axis=0)
m, n = y.shape
center = np.zeros(n)
total = np.sum(y, 0)
increase = np.hstack((y[:, 0:1], np.diff(y)))
below_size = total - nstack
below_size += 0.5*y
move_up = below_size / total
move_up[:, 0] = 0.5
center = (move_up - 0.5) * increase
center = np.cumsum(center.sum(0))
first_line = center - 0..5 * total
stack += first_line |
Test is here: https://www.wakari.io/usermgmt/nb/tillsten/Vectorizing_the_loop Also note that this just probably premature optimizing, but vetorizing stuff is surprisingly fun :) |
@Tillsten Ok. Your method is faster, so let's use that! I must've fluffed something up in the copy-paste. Thanks for collaborating with me. I'll update the PR with your approach.
Yes it is! What's more fun is to work with somebody on it. Thanks for all your hard work and guidance, I really appreciate it. |
@Tillsten Out of interest, would you be able to add a timing test comparing against the origin double |
@Tillsten I get a local test failure with your patch (implemented in c356f44). Could you perhaps take a look? Here's the diff from the test output. Expected: Computed: Diff: |
@dmcdougall After including the orginal loop, i am very happy that we verctorize it. There is a factor of 10 000 of differnce. |
Down comes the house! That's what I like to see. Good work. Tests are now passing locally, too. |
I'm going to rebase this pull request so it will merge cleanly. During that process, I will squash down the vectorisation commits into a single vectorisation commit. I'll then check for PEP8 compliancy. After that I'll run the tests locally and report back. After that, this should be good to go. |
I have not too experience with the workflow, but why not squash everything together? |
@Tillsten I can do that, too. The reason I did it this way is because then each commit adds something logical and complete in bite-size chunks. This makes tools like Perhaps this is better thrown out for a consensus. @pelson and @mdboom What do you guys think? |
My personal feelings about squashing commits is to be conservative with |
This seems reasonably stable now, so I'll merge it if there's no more feedback by, say, tomorrow. It'd be good to get this into master so people can play with it. |
import matplotlib.pyplot as plt | ||
|
||
np.random.seed(0) | ||
def layers(n, m): |
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.
I know its only an example, but a docstring would be nice here - something which focuses on the purpose of the function, rather than its args/kwargs.
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.
Actually, this is not uncommon to do in the examples. IIRC, the sphinx
doc-builder will take the docstring portion of the example, and render it
as ReST text above the source code portion. If one feels like having a
docstring there, feel free. The more the better.
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.
Sure thing :)
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.
Explanation of the code:
This is just a direct copy of the original code. All it does is calculating random Gaussians.
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.
Done in bd204e1.
This is an excellent PR, and from my point of view, is on the cusp of being merged. I've added two questions/actions - one of which I would appreciate others either agreeing, or throwing it out of the park. Cheers, |
merge it? |
Also, the tests that were added here are now failing. Curious. |
Locally I don't get the stack_base errors with python 2.7. The error bar and tight_bbox failures have nothing to do with these changes. |
This boasts an O(10^4) speed up
Also made a minor PEP8 change
Rebasing addresses the error_bar failures locally. Now all tests pass locally with py2.7. Travis will probably have a different story. |
New version of #1517 with a test, typos fixed, and a CHANGELOG.