Code Monkey home page Code Monkey logo

Comments (5)

BlackEdder avatar BlackEdder commented on July 29, 2024

This seems to be caused by the fact that you can't use a function to set vector size. Is this a "deliberate" design choice or a bug?

I was trying to use constants to set the size of my arrays instead of hard coded values (sirFunctions.stan is auto generated). The manual says the way to define constants in stan is:

Constants in Stan are nothing more than nullary (no-argument) functions. For in-
stance, the mathematical constants π and e are represented as nullary functions
named pi() and e(). See Section 41.2 for a list of built-in constants.

So I assumed this would mean you could use such constants when defining vector/array size.

from stanc3.

bob-carpenter avatar bob-carpenter commented on July 29, 2024

Thanks for reporting. Models shouldn't translate to C++ and then not compile, so that's a bug.

As far as the language design, the intention is that a function may be used to determine a size for a block variable or local variable as long as the function is constant---it can't change values based on parameters.

The situation that's failing here is using it to define a local variable in a function:

int get_state_dim() { return 13; }
...
real[] ode(real time, real[] state, real[] theta, real[] x_r, int[] x_i) {
    real dydt[get_state_dim()];
...

The problem is that it's not getting a print stream passed in.

In file included from <command-line>:0:0:
./sirStrain.hpp: In member function ‘void sirStrain_model_namespace::sirStrain_model::get_dims(std::vector<std::vector<long unsigned int> >&) const’:
./sirStrain.hpp:2822:40: error: ‘pstream__’ was not declared in this scope
         dims__.push_back(get_state_dim(pstream__));
                                        ^~~~~~~~~

We'll fix this.

from stanc3.

BlackEdder avatar BlackEdder commented on July 29, 2024

Thanks!

Just as a follow-up. This does work as expected in the transformed data section, but not in the transformed parameters section or within a function.

from stanc3.

bob-carpenter avatar bob-carpenter commented on July 29, 2024

Here's a smaller example of both where I get the same failure to compile:

functions {
  int sizer() {
    return 5;
  }
  real[] foo() {
    real x[sizer()];
    return x;
  }
}
transformed data {
  real x[sizer()] = foo();
}
transformed parameters {
  real z[sizer()];
  z = x;
}

from stanc3.

rok-cesnovar avatar rok-cesnovar commented on July 29, 2024

Still an issue in stanc3. Transferring.

from stanc3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.