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

hack stan::io::var_context for container variables with dimension of size 0 #2867

Closed
mitzimorris opened this issue Dec 21, 2019 · 0 comments
Closed
Assignees
Milestone

Comments

@mitzimorris
Copy link
Member

Summary:

Currently validate_dims is a non-virtual function on class stan::io::var_context. Make this class virtural and move implementation to classes stan::io::dump and cmdstan::io::json.

Description:

In JSON notation, multi-dim arrays with leading dim 0 are indistinguishable from single-dim arrays of size 0, e.g., 3d array 0 x 0 x 0 is represented in JSON as '[ ]'. Therefore, for JSON notation, we need to hack the function validate_dims.

Rdump notation allows this - e.g.

d_m_ar <- structure(c(), .Dim = c(0, 0, 0))

defines a 3d array, dims 0 x 0 x 0

in JSON, this is represented as

    "d_m_ar" : [ ]

while [ [ [ ] ] ] describes a 1 x 1 x 0 array.

Reproducible Steps:

Please report steps to reproduce the issue. If it's not possible to reproduce, please include a description of how you discovered the issue.

If you have a reproducible example, please include it.

Current Output:

Currently, CmdStan and by extension CmdStanPy and CmdStanR cannot accept JSON inputs is there are any 0-size multi-dim container objects.

Expected Output:

Stan program:

data { 
  int d;
  vector[d] d_v1;
  vector[d] d_v2;
  row_vector[d] d_rv1;
  row_vector[d] d_rv2;
  vector[d] d_v_ar[d];
  row_vector[d] d_rv_ar[d];
  matrix[d, d] d_m;
} 

should run (and do nothing) for following JSON data file:

{
    "flag" : 0,
    "d" : 0,
    "d_v1" : [],
    "d_v2" : [],
    "d_rv1" : [],
    "d_rv2" : [],
    "d_v_ar" : [],
    "d_rv_ar" : [],
    "d_m" : [],
    "d_m_ar" : []
}

Additional Information:

see stan-dev/cmdstan#775

Current Version:

v2.21.0

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

4 participants