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

[Stan 2.33] Expose functions with tuple return type or argument type #859

Closed
adamgorm opened this issue Sep 29, 2023 · 2 comments · Fixed by #860
Closed

[Stan 2.33] Expose functions with tuple return type or argument type #859

adamgorm opened this issue Sep 29, 2023 · 2 comments · Fixed by #860
Labels
feature New feature or request

Comments

@adamgorm
Copy link

Description

expose_functions fails for cmdstan models where at least one user-defined function either returns a tuple or takes a tuple as argument.

It would be perfect if we could for instance use R lists as the interface to Stan tuples, such that

  • functions that return a tuple return a list when called from R,
  • functions that take a tuple as argument take a list as argument when called from R.

If this is not possible, then it would also be very useful to be able to expose all other functions than those with tuple return/argument type (so that one can make utility functions returning tuples / taking tuples as arguments, while still being able to expose all other functions).

Reproducible examples

1: Fails

We can't expose a function that returns a tuple.

functions {
  tuple(int, vector)
  f(int a)
  {
    tuple(int, vector[5]) x;
    x.1 = a * 2;
    x.2 = rep_vector(a, 5);
    return x;
  }
}

2: Fails

We can't expose a function that takes a tuple as argument.

functions {
  vector
  f(tuple(int, vector) x)
  {
    return x.2;
  }
}

3: Works

However, note that we can expose a function with a tuple in the function body.

functions {
  vector
  f(int a)
  {
    tuple(int, vector[5]) x;
    x.1 = a * 2;
    x.2 = rep_vector(a, 5);
    return x.2;
  }
}
@adamgorm adamgorm added the feature New feature or request label Sep 29, 2023
@andrjohns
Copy link
Collaborator

Thanks for flagging!

It looks like Rcpp doesn't support tuples out-of-the box, I'll have a look at adding the wrappers that we need

@jgabry
Copy link
Member

jgabry commented Sep 29, 2023

This is fixed now by @andrjohns' PR #860 and I just checked that exposing the functions in the examples above works without error now. I'm going close this issue for now, but @adamgorm if you run into further trouble with this we can reopen the issue. Thanks for opening this.

@jgabry jgabry closed this as completed Sep 29, 2023
@jgabry jgabry linked a pull request Sep 29, 2023 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants