Skip to content

Conversation

@t4c1
Copy link
Collaborator

@t4c1 t4c1 commented Feb 22, 2021

Submission Checklist

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

Summary

This is a copy of #3010, just moved to original repo to make Jenkins formatting bot work.

Refactors indexing functions to simplify them including:

  • renames lvalue.hpp to assign.hpp and lvalue_varmat.hpp to assign_varmat.hpp to match functions implemented in them
  • deletes unused rvalue_return metaprogram
  • changes signatures of rvalue and assign functions:
  • deletes unused argument depth
  • removes default value from name argument to allow for the next change
  • replaces cons_index_list structure with (possibly variadic) argument list of indices. This makes cons_index_list and related functions redundant so they are removed.

Intended Effect

The generated code that uses indexing is more readable.

How to Verify

The changes are tested by changed tests.

Side Effects

This changes the interface of indexing functions. So it needs to be merged together with changes in stanc that will generate code according to the new interface.

Documentation

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): Tadej Ciglarič

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

@t4c1 t4c1 mentioned this pull request Feb 22, 2021
3 tasks
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.

Looks good. I left two notes but I think they were minor

@SteveBronder
Copy link
Collaborator

I skimmed over the code and I think everything looks okie dokie! I'll have another look tonight

Copy link
Collaborator

@SteveBronder SteveBronder left a comment

Choose a reason for hiding this comment

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

Looks so much nicer 🙏 couple comments but overall looks good!

Comment on lines -102 to +96
inline void assign(Vec1&& x,
const cons_index_list<index_multi, nil_index_list>& idxs,
const Vec2& y, const char* name = "ANON", int depth = 0) {
inline void assign(Vec1&& x, const Vec2& y, const char* name,
const index_multi& idx) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason to remove the default value of anon?

Copy link
Collaborator

Choose a reason for hiding this comment

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

[optional] I think with this change we could also change index_multi so it just holds a const& to the inner std vector

Copy link
Member

Choose a reason for hiding this comment

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

Once you go variadic, default value isnt really that useful I guess, the only use is assign(x,y) without indexing. The name is always set in code-gen.

inline void assign(Vec1&& x,
const cons_index_list<index_omni, nil_index_list>& idxs,
Vec2&& y, const char* name = "ANON", int depth = 0) {
inline void assign(Vec1&& x, Vec2&& y, const char* name, index_omni) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just because it's how we write other functions where we don't use a param

Suggested change
inline void assign(Vec1&& x, Vec2&& y, const char* name, index_omni) {
inline void assign(Vec1&& x, Vec2&& y, const char* name, index_omni /* idx */) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

inline void assign(Mat1&& x,
const cons_index_list<index_omni, nil_index_list>& idxs,
Mat2&& y, const char* name = "ANON", int depth = 0) {
inline void assign(Mat1&& x, Mat2&& y, const char* name, index_omni) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

same thing with /* idx */

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

* tail assignment.
*/
template <typename StdVec, typename Idx, typename U,
template <typename StdVec, typename U, typename... Idxes,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo?

Suggested change
template <typename StdVec, typename U, typename... Idxes,
template <typename StdVec, typename U, typename... Idxs,

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

require_all_std_vector_t<T, U>* = nullptr,
require_not_same_t<Idx1, index_uni>* = nullptr>
inline void assign(T&& x, U&& y, const char* name, const Idx1& idx1,
const Idxes&... idxes) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above idxs

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

stan::math::check_range("vector[multi] assign", name, x_size,
idxs.head_.ns_[i]);
x_idx[i] = idxs.head_.ns_[i] - 1;
if (likely(x_set.insert(idx.ns_[i]).second)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we should remove the likely here? I've been writing things lately that have a lot of repeated values so idk it's a judgement call

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No idea.

}
}
for (int i = assign_cols - 1; i >= 0; --i) {
if (likely(x_idx[i] != -1)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here for likely()

@rok-cesnovar rok-cesnovar mentioned this pull request Mar 7, 2021
@rok-cesnovar
Copy link
Member

The test error popping up now is legit: https://jenkins.mc-stan.org/blue/organizations/jenkins/Stan/detail/PR-3011/12/pipeline

Seems like a missing signature?

@stan-buildbot
Copy link
Contributor


Name Old Result New Result Ratio Performance change( 1 - new / old )
gp_pois_regr/gp_pois_regr.stan 3.4 3.43 0.99 -1.01% slower
low_dim_corr_gauss/low_dim_corr_gauss.stan 0.02 0.02 1.06 5.57% faster
eight_schools/eight_schools.stan 0.11 0.11 0.99 -1.26% slower
gp_regr/gp_regr.stan 0.16 0.16 0.98 -2.13% slower
irt_2pl/irt_2pl.stan 5.26 5.3 0.99 -0.82% slower
performance.compilation 90.05 88.69 1.02 1.51% faster
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan 9.05 9.23 0.98 -1.91% slower
pkpd/one_comp_mm_elim_abs.stan 29.57 29.77 0.99 -0.7% slower
sir/sir.stan 128.09 129.73 0.99 -1.28% slower
gp_regr/gen_gp_data.stan 0.03 0.04 0.95 -5.33% slower
low_dim_gauss_mix/low_dim_gauss_mix.stan 3.12 3.1 1.01 0.58% faster
pkpd/sim_one_comp_mm_elim_abs.stan 0.38 0.37 1.02 1.76% faster
arK/arK.stan 2.61 1.9 1.37 27.08% faster
arma/arma.stan 0.77 0.74 1.04 3.84% faster
garch/garch.stan 0.56 0.51 1.11 9.52% faster
Mean result: 1.03161378737

Jenkins Console Log
Blue Ocean
Commit hash: f30dc5d5ed8206dbf6e6f0197e5ffda98f7e0c5c


Machine information ProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010

CPU:
Intel(R) Xeon(R) CPU E5-1680 v2 @ 3.00GHz

G++:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

Clang:
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.6.0
Thread model: posix

@rok-cesnovar rok-cesnovar merged commit 6e58930 into develop Mar 13, 2021
@rok-cesnovar rok-cesnovar deleted the refactor_indexing branch March 13, 2021 12:37
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.

7 participants