-
-
Notifications
You must be signed in to change notification settings - Fork 189
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
fix assignment for nullptr var_value<matrix> and for assigning expressions #2978
Conversation
@SteveBronder this sounds kind of similar to #2895, which we 'fixed' in stan-dev/stanc3#1323. Do we think stan-dev/stanc3#1323 is still necessary, or does this also resolve the older issue? Also, does this resolve stan-dev/stan#3244? Edit: it does |
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.
A few small things but overall looks good. I've also plugged this branch into some downstream tests of models and confirmed it is working there now
x_ans_adj(i) = -(i + 0.1); | ||
} | ||
EXPECT_MATRIX_EQ(x.adj(), x_ans_adj); | ||
EXPECT_MATRIX_EQ(x_ans_adj, y.adj()); |
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.
Can you a comment just stating that this is intentionally different from the above test and why (e.g., that y did not exist before and therefore does not have its own memory which can be set to 0)
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.
Sure, I also wrote another test here to show that the assign_nan
test has the same behavior for both kinds of matrices
…x_cl, and add test for nan var matrix behaviors
…ix/hard-copy-var-assign
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 to me. Thanks!
Summary
Fixes #2977 by forcing
arena_matrix
to perform a hard copy when usingoperator=
from expressions made from other var matrices.Tests
Tests have been added to check assigning to a
var_value<Matrix>
when the innervari
isnullptr
and forvar_value<Matrix>
when the rhs is an expression and the lhs is just initialized toNaN
. Tests. can be run withSide Effects
Nope
Release notes
Bugfix for uninitialized
var_value<Matrix>
types and assignment when the rhs of the assignment is an expressionChecklist
Copyright holder: Simon's Foundation
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