Exposing a function that returns an array of tuples fails to compile
Los mantenedores suelen responder en 1 día
Ya se ha fusionado un pull request relacionado.
- #1330 de @jgabry — fusionado
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 30/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Área
- build-system, compilers
Línea de trabajo
Start by reproducing the failure with the snippet in the issue, which calls $expose_functions() on a function that returns an array of tuples. The header inst/include/rcpp_tuple_interop.hpp defines the tuple wrap overload, and compile_functions() in R/expose.R sets the include order for the generated code. Done means the tuple-array return compiles and exposes, and the existing tuple-argument behaviour still works.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
A Stan function that returns an array of tuples can't be exposed with $expose_functions(), and because every function in the block is compiled together, that means no functions from the model can be exposed.
library(cmdstanr)
mod <- cmdstan_model(write_stan_file("
functions {
array[] tuple(real, real) f(array[] tuple(real, real) x) { return x; }
}
"))
mod$expose_functions()
The only message R shows is "Error 1 occurred building shared library". The compiler output is actually
Rcpp/internal/wrap.h:528:23: error: static assertion failed due to
requirement '!sizeof(std::tuple<double, double>)': cannot convert type
to SEXP
I did some investigating with Claude. Here's its diagnosis, although I haven't verified myself yet that this is correct:
The cause is in
inst/include/rcpp_tuple_interop.hpp. It definesRcpp::wrapforstd::tuple, which works when the tuple is the return type itself (and for nested tuples, where the overload calls itself).
Forstd::vector<std::tuple<...>>Rcpp's own container wrap takes over and calls::Rcpp::wrapper element from inside the Rcpp headers (wrap.h:200,range_wrap_dispatch___generic), where our overload isn't visible yet, so the generic fallback fires its static assertion. It's the same visibility problem that keepsRcpp::List::create(args...)from compiling for nested tuples (see the commit message of #1310).Taking a tuple array as an argument is fine, the
Exporterside handles it. Only returning one fails.Rcpp's documented way to extend
wrapfor a new type is to includeRcppCommon.h, declare the overload, then includeRcpp.h, so the declaration is visible to the templates in the Rcpp headers. The
generated code includesRcpp.hfirst through the other interop headers, so this would need the include order incompile_functions()(R/expose.R) rearranged. Untested.
Tested on macOS with CmdStan 2.40.0, Rcpp 1.1.2, on the v1.0 branch with the fix for #1001 (#1310) in. Pre-existing: the old tuple header failed the same way.
- Lenguaje dominante
- R
- Estrellas
- 162
- Forks
- 69
- Merge medio
- 1 d 9 h
- PR fusionados (30 d)
- 48
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de stan-dev/cmdstanr
-
internal-code
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
stan-dev/cmdstanr#506 · 7 comentarios · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Model methods fail on a reloaded fit when the data was passed in memoryPosiblemente ocupada @jgabry la tomó hoy. Abiertobug
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
Los mantenedores suelen responder en 1 día
-
internal-code
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
stan-dev/cmdstanr#1314 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
feature
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
stan-dev/cmdstanr#1175 · 1 comentario · 2 reacciones ·
Los mantenedores suelen responder en 1 día
Todos los issues de stan-dev/cmdstanr
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
mitchelloharawild/ggtime#39 ·
-
Add more snippets to R and JuliaAbiertoenhancement good first issue help wanted
Dificultad 2/5 Medio día Aptitud para principiantes 82/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
-
question
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
-
Breaking 🏴☠️ Consistency :green_apple: :apple:
Dificultad 1/5 Menos de una hora Aptitud para principiantes 70/100
easystats/bayestestR#789 ·
Los mantenedores suelen responder en 1 día