-
-
Notifications
You must be signed in to change notification settings - Fork 193
use double loop for operator-/+ #2223
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
Conversation
Jenkins Console Log Machine informationProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010CPU: G++: Clang: |
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.
Is there a chance this could be a problem:
math/stan/math/rev/core/operator_addition.hpp
Line 228 in be3c985
inline auto add(const Var& a, const VarMat& b) { |
Will this work if the input is row major?
Will this work if the input is a block of another matrix?
@bbbales2 Blocks do not support linear indexing, so you can not traverse them using a single loop. So the linked file will not work with blocks. |
Jenkins Console Log Machine informationProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010CPU: G++: Clang: |
@SteveBronder I want to get this specific fix in so #2213 can move again, so I went to investigate the scalar + matrix comment here: #2223 (review) I added two tests to This is an easy way we can test that functions work with transposes: TEST(MathMixMatFun, add_transpose_test) {
auto f = [](const auto& x) {
return x + x.transpose();
};
Eigen::MatrixXd x(2, 2);
stan::test::expect_ad_matvar(f, x);
} Maybe that should be just the The other test I added was:
And I get compile errors. It seems like Anyway, I pushed that stuff up here. I would like to get the original fix you had in place for #2213 (just getting So feel free to remove whatever bits that I added that you don't want in this pull, and we can do that later (for instance, we don't have to fix block types for varmat here if they are messed up). The |
And if block types are messed up and there is no easy fix, then that also means the test for #2223 (review) won't work, which means that that issue can't be verified and fixed, so if we don't fix that here, make a note in #2245 |
Thanks for writing these! I think it's a good idea to fix them here so I'll update today |
I took a hard look at this and there were a couple underlying issues
I also made a specialization for |
@SteveBronder sounds good, I'll get a review for this tomorrow |
…4.1 (tags/RELEASE_600/final)
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.
Review!
Edit: There were a few minor/simple things I just fixed, but I left everything with questions.
using return_t = promote_var_matrix_t<T2, T1, T2>; | ||
arena_t<return_t> res = value_of(A) * value_of(arena_B).array(); | ||
reverse_pass_callback([A, arena_B, res]() mutable { | ||
arena_B.adj().array() += value_of(A) * res.adj().array(); |
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's a bug with A right? I wonder how this was passing. This should have segfaulted or given us a sanitizer error (unless A's destructor was called some other way or something).
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.
Well, it's not a bug if A is a scalar, but anyway not sure if something else is going on, cause if it's a scalar, then it may as well have stayed the way it was.
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.
It wasn't a bug, it just looked very must like a bug. I started fixing it because At first I thought it was a bug but then realized it's just a scalar type so it's fine. But then I was like well if it looks like a bug then at the very least it's probably bad code so I just kept the fix in here
@@ -135,31 +135,37 @@ template <typename T1, typename T2, require_not_matrix_t<T1>* = nullptr, | |||
require_not_row_and_col_vector_t<T1, T2>* = nullptr> | |||
inline auto multiply(const T1& A, const T2& B) { |
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.
The docs on this function say the first argument should be a scalar, but the code makes it look like it's been upgraded to handle vector/row vector arguments. Why the change?
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.
See above
@@ -66,7 +66,7 @@ inline plain_type_t<T> matrix_power(const T& M, const int n) { | |||
arena_M.adj() += adj_M + adj_C; | |||
}); | |||
|
|||
return res; | |||
return ret_type(res); |
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.
Good catch!
reverse_pass_callback([ret, b]() mutable { b.adj() -= ret.adj().sum(); }); | ||
return ret_type(ret); | ||
return plain_type_t<ret_type>(ret); |
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.
plain_type_t not necessary here or on line 235
@SteveBronder looks like the tests failed with some sort of RowMajor/Column Major problem:
|
…4.1 (tags/RELEASE_600/final)
@rok-cesnovar @serban-nicusor-toptal the build here is saying gelman-group-linux went offline. Is that something that can be worked around or do we need to reboot a computer somewhere? |
Needs a physical reboot I am afraid. We are working on enabling OpenCL tests on the Windows Columbia machine so we have two machines that can run this test. |
Oooo, and this one lives on campus? Is this a Goodrich thing or a G-man thing? |
I believe Nic usually writes to Ben G., other than that I have no idea where it resides. |
Okeedokee I will write the Newyorkerz |
Hey, linux machine is back online! Sorry for the trouble. ( It went through some maintenance and its IP changed ) |
@serban-nicusor-toptal what version of g++ are we using on jenkins? I'm seeing
|
Edit: I've updated aws to |
…ev/math into bugfix/linear-access-add-subtract
Jenkins Console Log Machine informationProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010CPU: G++: Clang: |
for (Eigen::Index i = 0; i < A_vm_f.size(); ++i) { | ||
for (Eigen::Index j = 0; j < A_mv_f.size(); ++j) { | ||
for (Eigen::Index j = 0; j < A_mv_f.cols(); ++j) { | ||
for (Eigen::Index i = 0; i < A_vm_f.rows(); ++i) { |
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.
Lol, two sets of indices and I screwed up two things. oof.
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.
Good!
Summary
Fixes the linear access bug found in #2213 by using a loop over the rows and columns
Tests
Adds tests that check
add/subtract(x, x.transpose())
has the correct adjointSide Effects
Nope
Release notes
Checklist
Math issue
var<mat>
implementation ofmdivide_left_spd
andmdivide_left_tri
#2213Copyright holder: Steve Bronder
The copyright holder is typically you or your assignee, such as a university or company. By submitting this pull request, the copyright holder is agreeing to the license the submitted work under the following licenses:
- Code: BSD 3-clause (https://opensource.org/licenses/BSD-3-Clause)
- Documentation: CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
the basic tests are passing
./runTests.py test/unit
)make test-headers
)make test-math-dependencies
)make doxygen
)make cpplint
)the code is written in idiomatic C++ and changes are documented in the doxygen
the new changes are tested