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

Compilation errors related with stan::math::arena_matrix #3085

Closed
crespofabian8012 opened this issue Nov 18, 2021 · 6 comments
Closed

Compilation errors related with stan::math::arena_matrix #3085

crespofabian8012 opened this issue Nov 18, 2021 · 6 comments

Comments

@crespofabian8012
Copy link

Hello

I translated a stan model using stanc3(CMDSTAN 2.28.1). I included the .hpp file in Xcode(MacOSX Mojave). I have Eigen 3.4 installed, Sundials, Boost , TBB 2020.3

I am getting compilation errors:

No member named 'adj' in 'stan::math::arena_matrix<Eigen::Matrix<stan::math::var_value<double, void>, -1, 1, 0, -1, 1> >'

No member named 'val' in 'stan::math::arena_matrix<Eigen::Matrix<stan::math::var_value<double, void>, -1, 1, 0, -1, 1> >'

@bob-carpenter
Copy link
Contributor

@crespofabian8012: Thanks for reporting. That's definitely a bug in Stan---you shouldn't ever see C++ compilation errors. Can you share the Stan program that led to this error (the shorter, the better)?

@rok-cesnovar
Copy link
Member

Hey Fabian,

I am guessing this a continuation of this discussion.

I have Eigen 3.4 installed, Sundials, Boost , TBB 2020.3

Based on the fact you are using Eigen 3.4, I am guessing you are using your own system-installed libraries? Is there a specific need to use Eigen 3.4? Stan currently uses 3.3.9 and that is also the version we test with in our CI.

You can see which libraries are bundled with Stan here: https://github.com/stan-dev/math/tree/develop/lib
If you need to use some other version of one of the dependencies, we cant guarantee that it will work.

No member named 'adj'

Errors like this typically mean that Eigen was included ahead of Stan headers. Stan Math is tightly coupled with Eigen in that we add code to the Eigen:: namespace. The adj() member function is one of those additions. The header file that must be included first is #include <stan/math/prim/fun/Eigen.hpp>. Which is also why the master header file is organized as it is: https://github.com/stan-dev/math/blob/develop/stan/math/rev.hpp

I would recommend you check out one of the top-level tests in Stan, for example https://github.com/stan-dev/stan/blob/develop/src/test/unit/services/sample/hmc_nuts_unit_e_adapt_test.cpp and try to run it and observe how the test is compiled. Then use that as a shim to compile your own C++ program (you can obviously then remove the GTest includes that are used for the test only).

I am moving this to the Stan repository, as that is where this issue should live, as its about using plain C++ Stan.

@crespofabian8012
Copy link
Author

Thanks @bob-carpenter and @rok-cesnovar. Yes, I am having the same issue with /examples/bernoulli.stan when translated with stanc. I am using Eigen 3.4, because I use some new features in Eigen 3.4 like Eigen::SeqN( for even and odd positions).

@rok-cesnovar
Copy link
Member

Probably the easiest workaround is to just include path_to_stan_math/stan/math/prim/fun/Eigen.hpp in the g++ compile call as the first include.
Something like: g++ -I path_to_stan_math/stan/math/prim/fun/Eigen.hpp ...

There is also a branch in Stan Math update/eigen-3.4 that has Eigen 3.4, but its failing in CI.

@SteveBronder
Copy link
Collaborator

Until we bump to 3.4 I would not use it. There's a lot that has changed internally in eigen and we have to update a good bit for that

@alecjacobson
Copy link

fwiw, I fixed this in my project by making sure #include <stan/math.hpp> cam before any #include <Eigen/ lines

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

No branches or pull requests

5 participants