-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
Encapsulate std::complex functions #3122
Conversation
Also after this release I'm going to write a script that we can use in jenkins to check that includes are being done correctly |
Tagging #3006 just so this PR shows up in the history of that issue -- as you say, actually resolving it would require Eigen to make some changes first |
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 bunch of tiny questions/comments -- thanks for tackling this!
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 in the new fwd changes, plus the above comments on doc seem to be outstanding
stan/math/fwd/fun/tcrossprod.hpp
Outdated
#include <stan/math/prim/fun/to_ref.hpp> | ||
#include <stan/math/prim/fun/transpose.hpp> | ||
#include <stan/math/fwd/fun/multiply.hpp> | ||
#include <stan/math/prim/fun/multiply.hpp> |
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.
Was this meant to be a deletion?
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.
No sorry we are supposed to use multiply
in this function.
multiply returns a scalar for multiply(vector, row_vector)
. Should this function also return a scalar in the case of a vector?
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.
We’re including the fwd multiply higher up
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.
^yes. What about the second part of my Q. I think it should return the same thing as multiply?
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.
I think this should always return a Eigen::Matrix to match prim, rev, etc. so the latest looks correct?
Jenkins Console Log Machine informationNo LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focalCPU: G++: Clang: |
@SteveBronder I addressed all my own docstring comments, so it's just the ~6 things above that are unresolved, including ones from my original review which are unfortunately "hidden" by github and you need to click to expand |
Jenkins Console Log Machine informationNo LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focalCPU: G++: Clang: |
Jenkins Console Log Machine informationNo LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focalCPU: G++: Clang: |
@SteveBronder final check -- good to merge? |
Jenkins Console Log Machine informationNo LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focalCPU: G++: Clang: |
@SteveBronder awesome!!! |
Summary
For the last few releases Stan math has had to do quick fixes when clang would update their functions for 'std::complex' which can cause conflicts when looking for our own functions that work over complex. The main issue for function calls like the following where an unqualified name lookup is used to find the correct function to call.
In the above,
sin
is looked for in both thestan::math
namespace and thestd
namespace since unqualified name lookup also uses Argument Dependent Lookup (ADL). During ADL the compiler looks at the namespaces of the arguments as well as the local namespace to figure out all of the valid function signatures it should use when deciding which function is the best candidate. Since we overridestd::complex
thestd
namespace is then also included in the valid candidates. Sometimes this is fine because the clang standard library usesrequires
very similar to ours for only supporting floating point types inside of their complex functions.But some functions, like the one below (linked here), do not restrict themselves to only floating point types.
This causes issues because ADL then finds two valid candidates functions when trying to find the best candidate for
conj
(both thestan::math
version and thestd
version).There is no good solution to this issue, it's just how the language is defined. The only way to make
stan::math
functions a better candidate is to use templates to make the stan math function both more generic and have an extra template with ourrequires
which makes it slightly better so the compiler chooses it as the best candidate.So this PR does a few things.
std::complex
for their complex types.autodiff
so we can just use one requires instead of the several that were thererev
headers are always used first and if available. This stops issues with prim being brought in before their respectiverev
orfwd
functions are available and fixes soem header include order issues.Tests
No changes to tests
Side Effects
Hopefully not
Release notes
Template complex functions in the Stan math library to be better candidates than the standard library functions during ADL.
Checklist
Copyright holder: Simons 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