stan-dev / stan-dev/cmdstanr

NA dimensions for complex and tuple types

Open
#925 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
R
Stars
160
Forks
69
Avg merge
1d 19h
Merged PRs (30d)
15

Description

Describe the bug

When calling $draws() on a fit object whose model has complex or tuple types in it I receive warning messages about NA's being made for the variable sizes.

To Reproduce

I made the stan program below to test this

parameters {
  real real_p;
  vector[2] vector_p;
  matrix[2, 2] matrix_p;
  array[2] matrix[2, 2] array_matrix_p;
  corr_matrix[2] corr_p;
  complex complex_p;
  complex_matrix[2, 2] complex_matrix_p;
  complex_vector[4] complex_vector_p;
  tuple(real, vector[3], array[2] matrix[2, 2], complex) tuple_int_vector_arraymatrix_complex_p;
  array[2] tuple(real, tuple(vector[2], array[2] tuple(real, complex, matrix[2, 2]))) arraytuple_big_p;
}

You can get the error with the following

# I put this in the tests/testthat/resources/stan folder
mod_params <- testing_model("parameter_types")
fit <- mod_params$pathfinder(data=data_list, seed=1234, refresh = 0)
foo = fit$draws(format = "df")
# Warning messages:
# 1: In variable_dims(metadata$variables) : NAs introduced by coercion
# 2: In variable_dims(metadata$variables) : NAs introduced by coercion
# 3: In variable_dims(metadata$variables) : NAs introduced by coercion
# 4: In variable_dims(metadata$variables) : NAs introduced by coercion
# 5: In variable_dims(metadata$variables) : NAs introduced by coercion
meta = fit$metadata()
meta$stan_variable_sizes
## Output
$lp_approx__
[1] 1

$lp__
[1] 1

$real_p
[1] 1

$vector_p
[1] 2

$matrix_p
[1] 2 2

$array_matrix_p
[1] 2 2 2

$corr_p
[1] 2 2

$complex_p
[1] NA

$complex_matrix_p
[1]  2  2 NA

$complex_vector_p
[1]  4 NA

$`tuple_int_vector_arraymatrix_complex_p:1`
[1] 1

$`tuple_int_vector_arraymatrix_complex_p:2`
[1] 3

$`tuple_int_vector_arraymatrix_complex_p:3`
[1] 2 2 2

$`tuple_int_vector_arraymatrix_complex_p:4`
[1] NA

$arraytuple_big_p
[1] NA NA  2  2

Expected behavior

Tuples and complex types would have the correct size

Operating system
Linux redhat

CmdStanR version number
master 28329d7

Additional context
I found this while working on the functions for adding pathfinder types

Contributor guide

Open the contributing guide

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

Start with the reproduction in tests/testthat/resources/stan/parameter_types and run the shown $draws(format = "df") and $metadata() calls. Trace variable_dims(metadata$variables) to see how complex and tuple variables are parsed; done means their reported sizes are correct and no NA coercion warnings appear.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.