Exposing a function that returns an array of tuples fails to compile
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 30/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Ambito
- build-system, compilers
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- R
- Stelle
- 162
- Fork
- 69
- Merge medio
- 1g 9h
- PR unite (30g)
- 48
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di stan-dev/cmdstanr
-
internal-code
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
stan-dev/cmdstanr#506 · 7 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
I maintainer di solito rispondono entro 1 giorno
-
internal-code
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
stan-dev/cmdstanr#1314 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
feature
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
stan-dev/cmdstanr#1175 · 1 commento · 2 reazioni ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di stan-dev/cmdstanr
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
stan-dev/priorsense#150 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
bennettoxford/opencodecounts#170 ·
-
complexity::1-low effort::1-hours priority::3-could
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
jumpingrivers/audit.workbench#43 ·
I maintainer di solito rispondono entro 1 giorno
-
complexity::1-low effort::1-hours priority::3-could
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
jumpingrivers/audit.connect#71 ·
I maintainer di solito rispondono entro 1 giorno