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

Fixing some spacing issues #588

Merged
merged 11 commits into from
Aug 6, 2017
Merged

Conversation

syclik
Copy link
Member

@syclik syclik commented Jul 29, 2017

Submission Checklist

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

Summary:

Clean up part of the code base.

How to Verify:

Visually inspect.

Side Effects:

None.

Documentation:

None.

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

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

Copy link
Contributor

@bob-carpenter bob-carpenter left a comment

Choose a reason for hiding this comment

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

This all looks pretty much OK.

I didn't see the need to convert one liner conditionals to two lines, but we should set a standard for these if you're going to spend time correcting them.

So it'd be great if you could include the style you converted to as guidelines in our style guide.

There are some performance issues (duplicated subexpressions) and things like 1.0 vs. 1 that could be cleaned up elsewhere. If you don't want to do it as part of this, would you mind creating an issue?

@@ -78,8 +78,8 @@ namespace stan {
Eigen::Matrix<lp_ret, Eigen::Dynamic, 1> values(Km1);
for (int k = 0; k < Km1; k++)
values(k) = (Km1 - k - 1) * log_diagonals(k);
if ( (eta == 1.0) &&
stan::is_constant<typename stan::scalar_type<T_shape> >::value) {
if ((eta == 1.0) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't need the parens around the equality.

Copy link
Member Author

Choose a reason for hiding this comment

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

Created issue #593 for this.

if ( (eta == 1.0) &&
stan::is_constant<typename stan::scalar_type<T_shape> >::value )
if ((eta == 1.0) &&
stan::is_constant<typename stan::scalar_type<T_shape> >::value)
Copy link
Contributor

Choose a reason for hiding this comment

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

don't need the stan:: qualification within the stan namespace unless there's ambiguity with another namespace.

Copy link
Member Author

Choose a reason for hiding this comment

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

Created issue #594 for removing the stan:: qualification.

|| !stan::is_constant<typename scalar_type<T10>::type>::value
)
value = (!propto
|| !stan::is_constant<typename scalar_type<T1>::type>::value
Copy link
Contributor

Choose a reason for hiding this comment

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

don't need namespace qualification

@@ -43,8 +43,7 @@ namespace stan {
using stan::is_constant_struct;
using std::exp;

if (!(stan::length(n)
&& stan::length(theta)))
if (!(stan::length(n) && stan::length(theta)))
Copy link
Contributor

Choose a reason for hiding this comment

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

don't need stan:: namespace qual; I'm going to stop noting this now, but it should really be done everywhere

@@ -52,8 +52,7 @@ namespace stan {
T_scale_fail>::type
T_partials_return;

if (!(stan::length(y) && stan::length(alpha)
&& stan::length(beta)))
if (!(stan::length(y) && stan::length(alpha) && stan::length(beta)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Someone was just pointing out all the redundant code in our distributions (sorry, can't recall who). This is a case where we should have a function

template <typename T1, typename T2, typename T3>
bool non_empty(const T1& x1, const T2& x2, const T3& x3) {
  return !(length(x1) && length(x2) && length(x3));
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like you added #589 for this.

@@ -101,8 +101,8 @@ namespace stan {
const T_partials_return alpha_dbl = value_of(alpha_vec[i]);
const T_partials_return beta_dbl = value_of(beta_vec[i]);
const T_partials_return p_dbl = beta_dbl / (1.0 + beta_dbl);
const T_partials_return d_dbl = 1.0 / ( (1.0 + beta_dbl)
* (1.0 + beta_dbl) );
const T_partials_return d_dbl = 1.0 / ((1.0 + beta_dbl)
Copy link
Contributor

Choose a reason for hiding this comment

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

same expression duplication issue

@@ -121,7 +121,7 @@ namespace stan {
ops_partials.edge1_.partials_[i] += g1 / Pi;
}
if (!is_constant_struct<T_inv_scale>::value)
ops_partials.edge2_.partials_[i] += d_dbl * pow(1-p_dbl, n_dbl)
ops_partials.edge2_.partials_[i] += d_dbl * pow(1 - p_dbl, n_dbl)
* pow(p_dbl, alpha_dbl-1) / beta_func / Pi;
Copy link
Contributor

Choose a reason for hiding this comment

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

You missed the space around the operator in line 125. Also, efficiency of multiple division here.

@@ -45,9 +45,7 @@ namespace stan {

T_partials_return cdf(1.0);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a different order of return vs. all the other cases. Should we fix one? I don't think there's an efficiency concern either way, but I think having the return be a constant and the return defined afterwards is easier to understand (doesn't require you to go look back to find value of cdf being returned).

Copy link
Member Author

Choose a reason for hiding this comment

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

Created #597.

if (!(stan::length(y)
&& stan::length(alpha)
&& stan::length(beta)))
if (!(stan::length(y) && stan::length(alpha) && stan::length(beta)))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an example of the pattern I think we should be using.

const Eigen::Matrix<TB, CA, CB>& B)
: vari(0.0),
public:
int A_rows_, A_cols_, B_cols_, A_size_, B_size_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why double up some declarations and not others? It just looks inconsistent.

Copy link
Member Author

Choose a reason for hiding this comment

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

No idea. Created #598.

@bob-carpenter
Copy link
Contributor

I still can't figure out how you do these massive updates.

This kind of thing is dangerous as it has the potential to cause conflicts in lots of branches. I can cope, though, and would rather clean up our code. The jury's out on whether this is "best practices" or not.

@syclik
Copy link
Member Author

syclik commented Aug 1, 2017

I can get these massive updates done because I only focus on one small problem at a time! And I want to get the number of issues assigned to me down (this comment was on one of my assigned issues). And it bothers me when things aren't consistent.

I'll create new issues for all the other problems you spotted.

For this pull request, the conflicts across branches should be minimal. It's spacing within mostly if statements and git's diff mechanism works pretty well. I can see it messing with @sakrejda's branch on the derivatives of the gamma distribution, but otherwise, there aren't too many branches that touch these error checks.

Regarding the splitting of conditionals from one line to two, I did it for consistency with the rest of our code base. Those were the only places where they were on one line. Personally, I find it easier to follow the style of code in a code base when there aren't multiple styles in the code base. If there was a good rule to have it be on one line, we could change everything to that style and I'd be just as happy.

@sakrejda
Copy link
Contributor

sakrejda commented Aug 1, 2017 via email

@bob-carpenter
Copy link
Contributor

bob-carpenter commented Aug 1, 2017 via email

@syclik
Copy link
Member Author

syclik commented Aug 2, 2017

Btw, @bob-carpenter, thank you for being so thorough in the review! It's the only way our code base will get better.

@syclik
Copy link
Member Author

syclik commented Aug 6, 2017

@bob-carpenter, I've spawned new issues with the things you picked out. Want to approve this pull request so it can be merged?

If you ever wanted to ignore white-space changes, you can add ?w=1 to the diff url and it'll show it. Like this: https://github.com/stan-dev/math/pull/588/files?w=1
(It only looks at white-space differences within a single line; adding a newline shows up in that view.)

@bob-carpenter bob-carpenter merged commit 9465b2d into develop Aug 6, 2017
@bob-carpenter bob-carpenter deleted the feature/issue-587-fix-spacing branch August 6, 2017 12:27
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