-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
Cleanup some of the C++ #871
Cleanup some of the C++ #871
Conversation
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.
Looks great. One comment typo I think and then should be good to go.
src/stan_math_backend/Cpp_Json.ml
Outdated
}, | ||
"block": "parameters" | ||
} |}] | ||
|
||
(*Adds a backslash to all the inner quotes and then | ||
unblash the ones near a plus*) |
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.
Unslash? :)
pos__ = (pos__ + 1);}} | ||
pos__ = (pos__ + 1); | ||
} | ||
} |
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.
🤘 🤘 🤘
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.
That was bothering me for so long lol
Cool beans, fixed! thanks for the review! |
Summary
This PR has a few cleanups of the C++ I've been littering around several PRs and I thought it would be better to just put them all into one PR
Description
I always put the C++ through
clang-format
before reading it so that the end curly brace of for loop was on a new line. This fixes that so the for loop and body end curly braces go on new lines with proper indentation.to_vec()
to_vec()
was used when validating dimensions and all it did was make anstd::vector<size_t>
of the given dimensions. So instead we just do this inline usingstd::vector
s initializer list syntax.So this
becomes
.clear()
and push backs fromget_param_names()
For
get_param_names(std::vector<std::string>& names__)
we would callnames__.clear()
and then push strings into the vector, but we can just do this in one lineand we do the same thing for
get_dims()
Use
+
and strings instead of astringstream
and<<
for the json output methods likeget_constrained_sizedtypes()
Add all the
num_params_r__
in one line.Instead of accumulating the
num_params_r__
on each line we do it all on one line likeInstead of
idt this can ever throw since we are just adding up integer values.
In my evergoing quest to remove the fill's that we don't need I did figure out how to remove them from data. Though not really much of an optimization.
We are guranteed (and validate) that the size of data is correct, so we don't need to fill it with NA. However, we do need to fill transformed data with NA as users could potentially use inner assignments that could miss some cells.
Oddly, I noticed that we only fill NA's whenver we use Eigen matrices or containers of Eigen matrices, why is that? For instance an
std::vector<double>
will not have it's values fill with NA. Should we be doing it always? Should we never be doing it? The safer thing is to always do it for any container idt that's a bad idea.I removed those fills by adding a bool to the tuple that
pp_set_size
takes in. This feels like kind of a silly approach, I'd much rather have an optional parameter but I couldn't figure out how to do that.log_prob
andwrite_array
functions that only take in a vector of reals and not a vector of ints so they are a bit more efficient.Release notes
Cleanup readability of the C++
Copyright and Licensing
By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the BSD 3-clause license (https://opensource.org/licenses/BSD-3-Clause)
Steve Bronder