stan-dev / stan-dev/stanc3

[BUG] SoA request is ignored with external c++

Open
#1,379 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

cpp-codegen optimization
Dominant language
OCaml
Stars
160
Forks
59
Avg merge
21h 45m
Merged PRs (30d)
26

Description

It looks like stanc ignores the -fsoa flag if any undefined functions are used in the likelihood. Given the following model:

functions {
  real undefined_fun(vector x);
}
data {
  int Npars;
}

parameters {
  vector[Npars] pars;
}

model {
  target += undefined_fun(pars);
}

I get the following generated c++:

...
Eigen::Matrix<local_scalar_t__,-1,1> pars =
  Eigen::Matrix<local_scalar_t__,-1,1>::Constant(Npars, DUMMY_VAR__);
...

If I remove the undefined_fun() call from the likelihood:

functions {
  real undefined_fun(vector x);
}
data {
  int Npars;
}

parameters {
  vector[Npars] pars;
}

model {
  target += sum(pars);
}

I instead get:

...
stan::math::var_value<Eigen::Matrix<double,-1,1>> pars =
  stan::math::var_value<Eigen::Matrix<double,-1,1>>(Eigen::Matrix<double,-1,1>::Constant(Npars,
                                                      std::numeric_limits<double>::quiet_NaN(
                                                        )));
...

Both models were called with ./mac-stanc ./soa_test.stan -fsoa --allow-undefined using the Oct 23 nightly (the latest release)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the supplied Stan models using ./mac-stanc ./soa_test.stan -fsoa --allow-undefined. Compare the generated C++ when undefined_fun is used with the output for sum(pars); done means the -fsoa request is honored even when external C++ functions are undefined.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, ocaml
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.