Skip to content
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

Merged
merged 9 commits into from Jan 27, 2013
Merged

Conversation

dmcdougall
Copy link
Member

New version of #1517 with a test, typos fixed, and a CHANGELOG.

@dmcdougall
Copy link
Member Author

@Tillsten Are you happy with the CHANGELOG and the whats_new?

@dmcdougall
Copy link
Member Author

@Tillsten Instead of embedding an image to the whats_new file, I'll write an example and just refer to that. I think that's cleaner.

@dmcdougall
Copy link
Member Author

Ok, I think this is good to go now. Tests pass locally except for tight_bbox (which has nothing to do with the stackplot baseline test, it's a weird font thing I occasionally get):

Expected:

bbox_inches_tight-expected

Computed:

bbox_inches_tight

Difference:

bbox_inches_tight-failed-diff

@tacaswell
Copy link
Member

I have also been intermittently getting this failure. (python2.7)

@dmcdougall
Copy link
Member Author

@tacaswell Specifically on this branch, or in general?

@tacaswell
Copy link
Member

@dmcdougall in general (typically with in a few commits of master).

Sorry I wasn't clear.

@Tillsten
Copy link
Contributor

@dmcdougall Just thanks for doing the final touches!

@dmcdougall
Copy link
Member Author

@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'])
Copy link
Member

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)

Copy link
Member Author

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.

@pelson
Copy link
Member

pelson commented Jan 17, 2013

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])
Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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.

@dmcdougall
Copy link
Member Author

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?

@Tillsten
Copy link
Contributor

@dmcdougall I checked both versions, both are getting excat the same result on my machine. I prefer mine, because
your diag generates an n-n-matrix, which could be quite big.

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.

@Tillsten
Copy link
Contributor

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

@Tillsten
Copy link
Contributor

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 :)

@dmcdougall
Copy link
Member Author

@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.

Also note that this just probably premature optimizing, but vetorizing stuff is surprisingly fun :)

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.

@dmcdougall
Copy link
Member Author

@Tillsten Out of interest, would you be able to add a timing test comparing against the origin double for loop too? Not for any reason other than I am curious.

@dmcdougall
Copy link
Member Author

@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:

stackplot_test_baseline-expected

Computed:

stackplot_test_baseline

Diff:

stackplot_test_baseline-failed-diff

@Tillsten
Copy link
Contributor

@dmcdougall After including the orginal loop, i am very happy that we verctorize it. There is a factor of 10 000 of differnce.

@dmcdougall
Copy link
Member Author

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.

@dmcdougall
Copy link
Member Author

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.

@Tillsten
Copy link
Contributor

I have not too experience with the workflow, but why not squash everything together?

@dmcdougall
Copy link
Member Author

@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 git bisect easier to use should something go wrong.

Perhaps this is better thrown out for a consensus. @pelson and @mdboom What do you guys think?

@WeatherGod
Copy link
Member

My personal feelings about squashing commits is to be conservative with
it. Squashing everything together makes for very big diffs, but not
squashing can lead to many confusing commit messages and clutter
histories. Squashing the vectorization commits makes sense here.

@dmcdougall
Copy link
Member Author

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):
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing :)

Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in bd204e1.

@pelson
Copy link
Member

pelson commented Jan 21, 2013

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,

@Tillsten
Copy link
Contributor

merge it?

@dmcdougall
Copy link
Member Author

@Tillsten I would rather wait until @pelson confirms his concerns have been addressed before merging.

In general I like to wait for at least one of the other developers to give it a once-over, but I realise that's not always possible with people being busy.

@dmcdougall
Copy link
Member Author

Also, the tests that were added here are now failing. Curious.

@dmcdougall
Copy link
Member Author

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.

@dmcdougall
Copy link
Member Author

Rebasing addresses the error_bar failures locally. Now all tests pass locally with py2.7. Travis will probably have a different story.

dmcdougall added a commit that referenced this pull request Jan 27, 2013
@dmcdougall dmcdougall merged commit daf551d into matplotlib:master Jan 27, 2013
@dmcdougall dmcdougall deleted the feature_stack_base branch January 27, 2013 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants