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/0464 refactor seqview #486

Merged
merged 4 commits into from
Feb 12, 2017
Merged

Conversation

seantalts
Copy link
Member

@seantalts seantalts commented Feb 9, 2017

Submisison Checklist

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

Summary:

Refactor most common use case of VectorView (taking either a primitive or a sequence of primitives and treating it seamlessly as a sequence of primitives) into scalar_seq_view, which is much simpler.

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): Dual Space LLC

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

The result of a day's pair programming with Bob. Next commit will replace usage.
Eventually the goal is to rewrite and replace all uses of VectorView
with some form of seq_view.
@seantalts seantalts force-pushed the feature/0464-refactor-seqview branch from f85a20a to ff4dda5 Compare February 9, 2017 19:11
@bob-carpenter
Copy link
Contributor

Is that [WIP] supposed to mean this is work in progress? That makes sense if you are just using the test harness. But you'll need to let someone know when you want it reviewed.

@seantalts
Copy link
Member Author

Yeah, that was my intention; think someone told me to use [WIP] at one point.

@bob-carpenter
Copy link
Contributor

bob-carpenter commented Feb 9, 2017 via email

@syclik
Copy link
Member

syclik commented Feb 9, 2017 via email

@seantalts seantalts changed the title [WIP] Feature/0464 refactor seqview Feature/0464 refactor seqview Feb 10, 2017
@seantalts
Copy link
Member Author

@bob-carpenter Okay, tests pass and I'm marking this as non-WIP. I think it might be a good place to start with the refactor, keeping in mind your advice to keep pull requests as small as possible. Bob, since you and I paired on the design together do you think we should get a 3rd party to review it? And then whoever wants to can double check that I did the substitutions correctly... Actually maybe I should have just put up the design first and then done the replacements in a 2nd PR? What do you guys think?

Copy link
Member

@syclik syclik 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; just needs documentation.


namespace stan {

template <typename C, typename T = typename scalar_type<C>::type>
Copy link
Member

Choose a reason for hiding this comment

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

const C& c_;
};

template <typename T>
Copy link
Member

Choose a reason for hiding this comment

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

Add doc describing what this specialization is.

#include <stan/math/prim/scal/meta/scalar_seq_view.hpp>

namespace stan {
template <typename T>
Copy link
Member

Choose a reason for hiding this comment

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

Add doc about the template specialization.

}

TEST(MetaTraits, ScalarSeqViewMatrix) {
expect_scalar_seq_view_values(Eigen::VectorXd(4));
Copy link
Member

Choose a reason for hiding this comment

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

if you're bored, you can look at scoped traces in Google Test to give context when this fails. No need to take action, but it is a useful feature of Google Test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ooh, sounds cool! Will check it out, thanks.

bool b3 = is_same<double, scalar_type<Matrix<double, Dynamic, Dynamic> >::type>::value;
EXPECT_TRUE(b3);
// TODO(Sean): This behavior doesn't seem to make sense prima facie
// Likely change this so that we would expect `double` here instead.
Copy link
Member

Choose a reason for hiding this comment

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

Just commenting; I think scalar_type just unwraps one layer. I think there's a recursive version kicking around. But either way, this is improperly named.

Copy link
Member Author

Choose a reason for hiding this comment

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

It appears to be recursive on std::vector but not Matrix 🌝

* @param i index
* @return the element at the specified position in the container
*/
const T& operator[](int i) const {
Copy link
Member Author

Choose a reason for hiding this comment

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

What do you guys think about these operator[]s being inlined? I'm still getting a feel for where that's appropriate.

@seantalts
Copy link
Member Author

jenkins, retest this please

@bob-carpenter
Copy link
Contributor

bob-carpenter commented Feb 10, 2017 via email

@seantalts
Copy link
Member Author

Re: inline - I just looked into it a little more, and some stuff suggests that all member functions declared inside a class are implicitly inline and that marking it as inline does nothing? http://stackoverflow.com/questions/9370493/inline-function-members-inside-a-class

@betanalpha
Copy link
Contributor

betanalpha commented Feb 10, 2017 via email

@seantalts
Copy link
Member Author

Schwoops. Well, I'll leave them unmarked then.

@bob-carpenter
Copy link
Contributor

bob-carpenter commented Feb 10, 2017 via email

@seantalts
Copy link
Member Author

seantalts commented Feb 12, 2017

Bob, gotcha. I think from what I was reading on that SO link that literally nothing changes in the compiler if you mark a member function inline, though it's hard to imagine that being perfectly consistent across all compilers...

Daniel, I added doc if you want to take a quick look whenever you have a chance and see if it looks good now? Thanks!

@syclik
Copy link
Member

syclik commented Feb 12, 2017

Looks good to me. Just approved.

@syclik syclik merged commit d544624 into develop Feb 12, 2017
@syclik syclik deleted the feature/0464-refactor-seqview branch February 12, 2017 20:01
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

4 participants