-
-
Notifications
You must be signed in to change notification settings - Fork 183
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
operands_and_partials refactor #547
Conversation
We weren't getting expected behavior from some of these tests (e.g. return_type<std::vector<matrix_v>> should be var, not matrix_v). I think I made them simpler and they give me expected behavior for all the use-cases I'm aware of.
Let me fix the tests before anyone wastes time on this! |
…up/546-operands-partials
@seantalts, I'll take a look at this over this week. Quick question: can we come up with a better name? |
oh yeah... you think it's time for a review? |
So I sat with Bob today went over the design for a while and got some changes to make. I'll hopefully finish those up tomorrow - I'll post back here and tag you when I'm done? Or it might make sense to just have @bob-carpenter do the review since he's fairly steeped in the new design at this point. |
Great! Please ping me anyway. I'd like to see the changes and having an
extra set of eyes never hurt on something like this.
…On Mon, May 8, 2017 at 10:58 PM, seantalts ***@***.***> wrote:
So I sat with Bob today went over the design for a while and got some
changes to make. I'll hopefully finish those up tomorrow - I'll post back
here and tag you when I'm done? Or it might make sense to just have
@bob-carpenter <https://github.com/bob-carpenter> do the review since
he's fairly steeped in the new design at this point.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#547 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAZ_Fw0ZPFkpFe8v1AZJaDvthkyXoeEbks5r39ZFgaJpZM4NQAv4>
.
|
Will do! |
…ath into cleanup/546-operands-partials
Re: #547 (comment) I think you're right and it likely makes sense to expose the partials type on the edge classes. I'll give that a shot and work on hiding their implementation details. |
So I can do this kind of thing and use SFINAE to provide these methods only when appropriate (due to univariate o&p having
Thoughts on this? It also uses a C++11 feature, default function template parameters. Some alternatives:
I think 3 seems like the easiest for right now... |
This is terrible for threaded commenting as I can't tell what #547 (comment) is in response to. What is all this complicated template programming for? |
I was confused too at first but I think if you click the link it will bring the relevant comment to the top of your page. In any case, the higher level goal is to hide |
Please feel free to ignore a bulk of the code-level comments. I was reviewing the pull request with this conversation from Discourse in mind. My memory is pretty hazy, but I recalled a request (in person) for a deep review at the API boundary, which is what I provided. It was a discussion between documenting and testing internal pieces vs just what's visible as a consumer of the class. Once I started looking at what the probability distribution functions use, it turns out there's a lot more complexity there. The internal classes are exposed directly and not testing those pieces directly makes it really tough to test from the outside. @seantalts, as I mentioned in an earlier comment before, I'm happy with it going in as-is or possibly with a little work. I'm not expecting everything I mentioned to get fixed (ever). This does leave us in a better place than where we were. I guess the only change I'd want is for the thing I marked as a bug to be made safe. If there's discrepancy between what I suggest and @bob-carpenter suggests, I'd say go with @bob-carpenter's suggestion. To be helpful: @seantalts, what could I do to help? Should I put together a list of things that should be finished before merging? Should I add tests? Should I just sit back and let you finish it out? |
@seantalts, although the code is unsafe, it can't be instantiated with the way our probability distributions currently work. I'm going to change the comment to requesting doc instead of fixing the code. There are still ways to construct it so it'll break, but I don't think we can do that with our current use cases. |
I appreciate the thorough review, sorry for the push back - just didn't want to spend a ton more time on it. I figured out a way to use friendship to limit exposure of those internal methods so we don't have to consider them as part of the public API. I will figure out a solution for the BUG above if operands_ is size 0 and change the I also responded to the "var reuse" thing with more questions here, not sure if you saw it? I can try to do something about this as well if you think it's important. |
For the var reuse thing, I don't think you need to worry about the foo(a, a) case and consolidating the a variables. We'll just take the hit for the extra overhead. It'd be hugely complicated to try to reduce this and probably of very limited use (not many distros where you repeat parameters, except the Dirichlet or some symmetric multinomials).
I don't think you need to dream up possible instantiations here. If we have a sufficient set to implement our distributions, we can always add more specializations later for efficiency.
I haven't been too worried in reviews about carving out a public API because we haven't done it anywhere else. I am glad you're starting to think about it as I do think it's important.
When we're both back in the office, I'd like to talk about the general testing framework I have in mind that should allow us to blast through 4^10 possibilities. Whether we always want to do that is another question---if we could somehow set up tests with proofs by induction without having to repeat logic all the way up, that'd be great. But as is, we're trying to be defensive against downstream ad hoc optimizations.
|
Sounds good, looking forward to it. |
There's both a |
(I think this is ready for review again) |
Let's go over it tomorrow (Thursday) in person if that's OK. Then we should be able to resolve any last-minute things and get it merged.
|
Need to match the appropriate forward mode derivative adjustment types with the type present in partials_[i] even though they will never actually be added.
Okay, this is ready for another look. I think I addressed all of @bob-carpenter's comments on Thursday - some writing improvements and removing any inheritance from it, simplifying the conceptual burden at the expense of some additional code duplication. I'm pretty happy with it now. |
Great. I can take a pass through this Monday. |
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 good. Some forward-looking comments, but nothing to change here.
return value; | ||
} | ||
|
||
// These will always be 0 size base template instantiations (above). |
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.
If they're always zero size, why have them at all? It's not like they get get inherited by specializations or anything.
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.
They are needed to compile - even though the code will never run, the compiler needs to see that edge1_.partials_ exists and is the right type even for arithmetic primitives.
template <int R, int C> | ||
class ops_partials_edge<double, Eigen::Matrix<var, R, C> > { | ||
public: | ||
typedef Eigen::Matrix<var, R, C> Op; |
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.
Don't worry about fixing this, but going forward, I'd much rather see typedefs of the form op_t
rather than Op
. Using Op
makes it visually ambiguous with a template parameter (and if it were OP
, with a constant).
Approval from @syclik to go ahead after my final review.
Submission Checklist
./runTests.py test/unit
make cpplint
Summary:
Replace the existing OperandsAndPartials with a new one that attempts to be a little less confusing (YOU be the judge!). It also adds multivariate support.
Documentation:
Reviewer Suggestions:
I had a few questions and wasn't sure how to do some things throughout but tried to add comments in the code with a TODO or something similar to catch these situations. That said, the code seems to work on all the tests that I can run in a short amount of time (will use Jenkins to run the full distribution tests, etc).
I also haven't added any doc yet; I plan to doc the main
operands_and_partials
class while the tests are running on Jenkins (but probably not the stuff I've added in thedetail
namespace).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: