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

fixes #346, replace copy args with refs #539

Merged
merged 4 commits into from
Jun 26, 2017

Conversation

bob-carpenter
Copy link
Contributor

@bob-carpenter bob-carpenter commented Apr 28, 2017

Submission Checklist

  • Run unit tests: ./runTests.py test/unit
  • Run cpplint: make cpplint
  • Declare copyright holder and open-source license: see below

Summary:

Replaced arguments of form (T x) with (const T& x) to avoid copies. Also cleaned up a lot of doc. Removed const modifier on some local argumens.

Side Effects:

it should be faster :-)

Documentation:

cleaned it up where I saw it

Reviewer Suggestions:

anyone

Copyright and Licensing

Please list the copyright holder for the work you are submitting (this will be you or your assignee, such as a university or company):

Columbia University

By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses:

@bob-carpenter
Copy link
Contributor Author

Is there something wonky with Jenkins? The default build's been triggered for a while, but no details. Same for the next pull request. And there's nothing running from the stan-dev/stan repo.

@syclik
Copy link
Member

syclik commented Apr 29, 2017

Yes. It is wonky. It looks like there are two things going on: the Windows box is down and Jenkins is waiting to shutdown.

@sealtalts, it's probably in a condition where it can't shut down until the existing builds are finished.

@bob-carpenter
Copy link
Contributor Author

This has just been sitting for six days. Would someone mind reviewing? It should be relatively easy as it's just simple C++ updates.

Copy link
Member

@bbbales2 bbbales2 left a comment

Choose a reason for hiding this comment

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

Fixing the docs for as_bool is the important thing

*
* <p>See https://en.wikipedia.org/wiki/N-sphere#Generating_random_points
Copy link
Member

Choose a reason for hiding this comment

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

Missing closing <p>? Or should this even be here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

* @return 1 if argument is equal to zero (or NaN) and 0 otherwise.
* @tparam type of scalar
* @param x value
* @return true if value is equal to zero or NaN
Copy link
Member

Choose a reason for hiding this comment

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

This looks backwards. Returns true if value is not equal to zero. I don't think NaNs equal anything, so it should still return true there (should check me on this)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's backwards. I'll fix it.

Depends what you mean by equal. If you mean operator==, then that's right, NaN == NaN returns false, which is why we have is_nan(). I'll try to rephrase to make sure the "equal to" isn't confused as being == applied to NaN.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

*/
template <typename T, typename TL>
inline
T lb_constrain(const T x, const TL lb) {
inline T lb_constrain(const T& x, const TL lb) {
Copy link
Member

Choose a reason for hiding this comment

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

Seems like lb could be passed by reference too, but I suppose if it's a single number it won't matter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack no, I just missed that one. General drill is to pass primitives by value and everything else by reference. With templates, the idea is to use constant references, which works well in both situations (passing values by reference isn't such a big deal).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

*/
template <typename T>
inline int step(const T y) {
inline int step(const T& y) {
Copy link
Member

Choose a reason for hiding this comment

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

Should this exist with int_step?

Also, int_step and step handle zero differently. Not sure it matters for doubles but it would for ints.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, maybe there is a reason this is called int_step. Maybe it handles ints differently... Still seemed strange to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good catch. I think that's been wrong all along. The int_ should just be the return type. And we want the condition to be > 0 so that step(0) is zero.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

@bob-carpenter
Copy link
Contributor Author

@bbbales2 I addressed the comments. Thanks for reviewing. Let me know if it's OK now.

@bob-carpenter
Copy link
Contributor Author

@bbbales2 --- would you mind looking over the changes to see if this is OK to merge? I can't merge it until the original reviewer approves (or an admin overrides the review).

@bob-carpenter
Copy link
Contributor Author

That's very confusing---I just added a comment and it seems to have kicked off the tests again. @seantalts --- any idea what's going on with the testing starting again here?

@bbbales2
Copy link
Member

bbbales2 commented Jun 24, 2017

Sure thing (Edit: oh wow I see your comment from 13 days ago. I'll pay more attention next time. My mistake)

@bbbales2
Copy link
Member

I don't think the step behavior ever got changed Re: #539 (comment)

step(0) should be 0.0 to be consistent with the int_step function -- it still is how it was before.

I'll approve it if you meant to leave it like this though. Sorry for delay! (I'll be watching this closely so whenever it gets in I'll get on it)

@bob-carpenter
Copy link
Contributor Author

Thanks---hadn't realized I missed that. I'll fix it. It's not super urgent, I just every now and then try to clear out lingering pull requests, especially if they're mine.

@bob-carpenter
Copy link
Contributor Author

Not a bug on the step function.

But it is confusing, so I made a note to flag the difference in behavior in the integer and double step functions:

stan-dev/stan#2336 (comment)

I also pulled in the latest develop and am retesting. If it passes, I'll merge if you approve.

@bbbales2
Copy link
Member

Looks good!

@bob-carpenter bob-carpenter merged commit 4cb1c1a into develop Jun 26, 2017
@bob-carpenter bob-carpenter deleted the bugfix/0346-copy-to-reference-args branch June 26, 2017 16:55
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

3 participants