Array bounds

Looking in the manual it sounds like I can’t do array values bounds. But the closed github issue says otherwise. Now, even with that closed issue, this is a bit different since it’s a 2d array and I want the array upper bound to pick up the first dimension and check the bound. Wondering if this is this something I can do @rok_cesnovar ? It’s not a big deal if I can’t but it would be nice to have the extra data check

  int<lower=1> N;              // total number training of observations
  int<lower=1> N_groups;       // number of groups
  int<lower=1> N_levels[N_groups];    // number of levels for each group
  int<lower=1> G[N_groups, N]; // 2d array containing the group
                               // indexes G[1] is equiv to
                               // G[1] = groupid[N], G[2] = category_name[N], etc
  // can I do instead
  int<lower=1, upper=N_levels> G[N_groups, N]; 

Please make an issue! Thank you. This has been available since CmdStan 2.24, was listed in release notes but we lagging behind in docs.

  int<lower=1> G[N_groups]; // 2d array containing the group
                               // indexes G[1] is equiv to
                               // G[1] = groupid[N], G[2] = category_name[N], etc
  // can I do instead
  int<lower=1, upper=N_levels> G1[N_groups, N]; 

is not valid as G and G1 have to be of the same type.
This is a valid model though:

transformed data {
  int<lower=1> N;              // total number training of observations
  int<lower=1> N_groups;       // number of groups
  int<lower=1> N_levels[N_groups, N];    // number of levels for each group
  int<lower=1> G[N_groups, N]; // 2d array containing the group
                               // indexes G[1] is equiv to
                               // G[1] = groupid[N], G[2] = category_name[N], etc
  // can I do instead
  int<lower=1, upper=N_levels> G1[N_groups, N]; 
}
parameters {
    real y;
}
model {
    y ~ std_normal();
}
1 Like

Will do, thanks for the quick response!

1 Like

Done. See Vectors with varying bounds is out of date and tells users that this can be a single type · Issue #338 · stan-dev/docs (github.com)

2 Likes