From 23dafa2617a78cb6b9e68b7a3c3d9b35527a503d Mon Sep 17 00:00:00 2001 From: Nikolas Siccha Date: Wed, 25 Mar 2026 09:55:58 +0100 Subject: [PATCH 1/9] Add tuple support to apply_scalar_unary for autodiff Add tuple specialization to apply_scalar_unary so that vectorized math functions (exp, sin, cos, etc.) automatically work on tuples. Also extend require_ad_container_t to accept tuples containing autodiff types, and add is_autodiff support for tuples. Fixes #3041 Co-Authored-By: Claude Opus 4.6 (1M context) --- stan/math/prim/functor/apply_scalar_unary.hpp | 32 +++++++++++++++++++ stan/math/prim/meta/is_autodiff.hpp | 13 ++++++++ stan/math/prim/meta/is_container.hpp | 9 ++++-- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/stan/math/prim/functor/apply_scalar_unary.hpp b/stan/math/prim/functor/apply_scalar_unary.hpp index f37a57f8740..16e660bb879 100644 --- a/stan/math/prim/functor/apply_scalar_unary.hpp +++ b/stan/math/prim/functor/apply_scalar_unary.hpp @@ -4,11 +4,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include @@ -206,6 +208,36 @@ struct apply_scalar_unary> { } }; +/** + * Template specialization for vectorized functions applying to + * tuple arguments. Each element of the tuple is processed + * recursively through apply_scalar_unary, allowing heterogeneous + * element types. + * + * @tparam F Type of function defining static apply function. + * @tparam T Tuple type. + */ +template +struct apply_scalar_unary> { + template + static inline auto apply_impl(TT&& x, std::index_sequence) { + return std::make_tuple( + apply_scalar_unary< + F, std::tuple_element_t>>:: + apply(std::get(std::forward(x)))...); + } + + template + static inline auto apply(TT&& x) { + return apply_impl( + std::forward(x), + std::make_index_sequence>>()); + } + + using return_t = std::decay_t::apply(std::declval()))>; +}; + } // namespace math } // namespace stan #endif diff --git a/stan/math/prim/meta/is_autodiff.hpp b/stan/math/prim/meta/is_autodiff.hpp index a5eec9f62e3..056176cb77c 100644 --- a/stan/math/prim/meta/is_autodiff.hpp +++ b/stan/math/prim/meta/is_autodiff.hpp @@ -8,10 +8,12 @@ #include #include #include +#include #include #include #include #include +#include #include namespace stan { @@ -46,6 +48,17 @@ template struct is_autodiff> : bool_constant::Scalar>::value> {}; +template +struct is_tuple_autodiff : std::false_type {}; + +template +struct is_tuple_autodiff, void> + : bool_constant<(is_autodiff::value || ...)> {}; + +template +struct is_autodiff> + : is_tuple_autodiff> {}; + } // namespace internal /** diff --git a/stan/math/prim/meta/is_container.hpp b/stan/math/prim/meta/is_container.hpp index 9928a154c9b..c2469424cb7 100644 --- a/stan/math/prim/meta/is_container.hpp +++ b/stan/math/prim/meta/is_container.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -99,9 +100,11 @@ using require_not_container_st /*! and holds a base type that satisfies @ref is_autodiff_scalar */ /*! @tparam T the type to check */ template -using require_ad_container_t - = require_all_t, is_std_vector>, - is_autodiff_scalar>>; +using require_ad_container_t = require_t, is_std_vector>, + is_autodiff_scalar>>, + math::conjunction, + internal::is_autodiff>>>>; /*! @} */ } // namespace stan From 85b5472d35aed4565e8c28cef36cb7ab592525dd Mon Sep 17 00:00:00 2001 From: Nikolas Siccha Date: Wed, 25 Mar 2026 11:19:18 +0100 Subject: [PATCH 2/9] Add tuple overloads for deep_copy_vars, save_varis, accumulate_adjoints These three functions handle var, vector, Eigen, and arithmetic types but not tuples. With STAN_THREADS=true, reduce_sum passes tuple arguments through these functions, causing compilation failures. Add tuple overloads that unpack the tuple via stan::math::apply and recursively process each element. Fixes #3041 Co-Authored-By: Claude Opus 4.6 (1M context) --- stan/math/rev/core/accumulate_adjoints.hpp | 19 +++++++++++++++++++ stan/math/rev/core/deep_copy_vars.hpp | 20 ++++++++++++++++++++ stan/math/rev/core/save_varis.hpp | 18 ++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/stan/math/rev/core/accumulate_adjoints.hpp b/stan/math/rev/core/accumulate_adjoints.hpp index e5b27354ebd..87d669f7aac 100644 --- a/stan/math/rev/core/accumulate_adjoints.hpp +++ b/stan/math/rev/core/accumulate_adjoints.hpp @@ -2,9 +2,11 @@ #define STAN_MATH_REV_CORE_ACCUMULATE_ADJOINTS_HPP #include +#include #include #include +#include #include #include @@ -35,6 +37,9 @@ inline double* accumulate_adjoints(double* dest, Arith&& x, Pargs&&... args); inline double* accumulate_adjoints(double* dest); +template * = nullptr, typename... Pargs> +inline double* accumulate_adjoints(double* dest, Tuple&& x, Pargs&&... args); + /** * Accumulate adjoints from x into storage pointed to by dest, * increment the adjoint storage pointer, @@ -147,6 +152,20 @@ inline double* accumulate_adjoints(double* dest, Arith&& x, Pargs&&... args) { */ inline double* accumulate_adjoints(double* dest) { return dest; } +/** + * Unpack a tuple and accumulate adjoints from each element. + */ +template * = nullptr, typename... Pargs> +inline double* accumulate_adjoints(double* dest, Tuple&& x, Pargs&&... args) { + dest = stan::math::apply( + [dest](auto&&... inner_args) { + return accumulate_adjoints( + dest, std::forward(inner_args)...); + }, + std::forward(x)); + return accumulate_adjoints(dest, std::forward(args)...); +} + } // namespace math } // namespace stan diff --git a/stan/math/rev/core/deep_copy_vars.hpp b/stan/math/rev/core/deep_copy_vars.hpp index 06561d1a9e0..38ce91532e8 100644 --- a/stan/math/rev/core/deep_copy_vars.hpp +++ b/stan/math/rev/core/deep_copy_vars.hpp @@ -2,9 +2,11 @@ #define STAN_MATH_REV_CORE_DEEP_COPY_VARS_HPP #include +#include #include #include +#include #include #include @@ -81,6 +83,24 @@ inline auto deep_copy_vars(EigT&& arg) { .eval(); } +/** + * Copy the vars in a tuple but reallocate new varis for them. + * Non-var elements are forwarded unchanged. + * + * @tparam Tuple A std::tuple type + * @param arg A tuple potentially containing vars + * @return A new tuple with deep-copied vars + */ +template * = nullptr> +inline auto deep_copy_vars(Tuple&& arg) { + return stan::math::apply( + [](auto&&... args) { + return std::make_tuple(deep_copy_vars( + std::forward(args))...); + }, + std::forward(arg)); +} + } // namespace math } // namespace stan diff --git a/stan/math/rev/core/save_varis.hpp b/stan/math/rev/core/save_varis.hpp index c53a5390539..3c46c435be9 100644 --- a/stan/math/rev/core/save_varis.hpp +++ b/stan/math/rev/core/save_varis.hpp @@ -3,9 +3,11 @@ #include #include +#include #include #include +#include #include #include @@ -35,6 +37,9 @@ inline vari** save_varis(vari** dest, Arith&& x, Pargs&&... args); inline vari** save_varis(vari** dest); +template * = nullptr, typename... Pargs> +inline vari** save_varis(vari** dest, Tuple&& x, Pargs&&... args); + /** * Save the vari pointer in x into the memory pointed to by dest, * increment the dest storage pointer, @@ -143,6 +148,19 @@ inline vari** save_varis(vari** dest, Arith&& x, Pargs&&... args) { */ inline vari** save_varis(vari** dest) { return dest; } +/** + * Unpack a tuple and save the varis of each element. + */ +template * = nullptr, typename... Pargs> +inline vari** save_varis(vari** dest, Tuple&& x, Pargs&&... args) { + dest = stan::math::apply( + [dest](auto&&... inner_args) { + return save_varis(dest, std::forward(inner_args)...); + }, + std::forward(x)); + return save_varis(dest, std::forward(args)...); +} + } // namespace math } // namespace stan From ca376aab1c83152ed25a2e1cd9bb27c0cad24cfd Mon Sep 17 00:00:00 2001 From: Nikolas Siccha Date: Wed, 25 Mar 2026 11:19:24 +0100 Subject: [PATCH 3/9] Add MWE: reduce_sum with tuple(param, data) and STAN_THREADS Co-Authored-By: Claude Opus 4.6 (1M context) --- mwe/.env-main/Manifest.toml | 97 ++++++++++++++++ mwe/.env-main/Project.toml | 2 + mwe/.env-worktree/Manifest.toml | 97 ++++++++++++++++ mwe/.env-worktree/Project.toml | 2 + mwe/Project.toml | 2 + mwe/mwe.jl | 54 +++++++++ mwe/mwe.main.out | 193 ++++++++++++++++++++++++++++++++ mwe/mwe.worktree.out | 193 ++++++++++++++++++++++++++++++++ 8 files changed, 640 insertions(+) create mode 100644 mwe/.env-main/Manifest.toml create mode 100644 mwe/.env-main/Project.toml create mode 100644 mwe/.env-worktree/Manifest.toml create mode 100644 mwe/.env-worktree/Project.toml create mode 100644 mwe/Project.toml create mode 100644 mwe/mwe.jl create mode 100644 mwe/mwe.main.out create mode 100644 mwe/mwe.worktree.out diff --git a/mwe/.env-main/Manifest.toml b/mwe/.env-main/Manifest.toml new file mode 100644 index 00000000000..bb76e196de7 --- /dev/null +++ b/mwe/.env-main/Manifest.toml @@ -0,0 +1,97 @@ +# This file is machine-generated - editing it directly is not advised + +julia_version = "1.10.11" +manifest_format = "2.0" +project_hash = "5578dd2aac58cda5d4cf32fe876f733701deb830" + +[[deps.ArgTools]] +uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" +version = "1.1.1" + +[[deps.Artifacts]] +uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" + +[[deps.BridgeStan]] +deps = ["Downloads", "Inflate", "TOML", "Tar"] +git-tree-sha1 = "f8689ac4ce3245df7a436889988762a6c4a9da12" +uuid = "c88b6f0a-829e-4b0b-94b7-f06ab5908f5a" +version = "2.7.0" + +[[deps.Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[deps.Downloads]] +deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"] +uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6" +version = "1.6.0" + +[[deps.FileWatching]] +uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee" + +[[deps.Inflate]] +git-tree-sha1 = "d1b1b796e47d94588b3757fe84fbf65a5ec4a80d" +uuid = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9" +version = "0.1.5" + +[[deps.LibCURL]] +deps = ["LibCURL_jll", "MozillaCACerts_jll"] +uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" +version = "0.6.4" + +[[deps.LibCURL_jll]] +deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"] +uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0" +version = "8.4.0+0" + +[[deps.LibSSH2_jll]] +deps = ["Artifacts", "Libdl", "MbedTLS_jll"] +uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8" +version = "1.11.0+1" + +[[deps.Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[deps.MbedTLS_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" +version = "2.28.1010+0" + +[[deps.MozillaCACerts_jll]] +uuid = "14a3606d-f60d-562e-9121-12d972cd8159" +version = "2025.12.2" + +[[deps.NetworkOptions]] +uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" +version = "1.2.0" + +[[deps.Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[deps.SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" +version = "0.7.0" + +[[deps.TOML]] +deps = ["Dates"] +uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" +version = "1.0.3" + +[[deps.Tar]] +deps = ["ArgTools", "SHA"] +uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" +version = "1.10.0" + +[[deps.Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[deps.Zlib_jll]] +deps = ["Libdl"] +uuid = "83775a58-1f1d-513f-b197-d71354ab007a" +version = "1.2.13+1" + +[[deps.nghttp2_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d" +version = "1.52.0+1" diff --git a/mwe/.env-main/Project.toml b/mwe/.env-main/Project.toml new file mode 100644 index 00000000000..bdf49f9a5ef --- /dev/null +++ b/mwe/.env-main/Project.toml @@ -0,0 +1,2 @@ +[deps] +BridgeStan = "c88b6f0a-829e-4b0b-94b7-f06ab5908f5a" diff --git a/mwe/.env-worktree/Manifest.toml b/mwe/.env-worktree/Manifest.toml new file mode 100644 index 00000000000..bb76e196de7 --- /dev/null +++ b/mwe/.env-worktree/Manifest.toml @@ -0,0 +1,97 @@ +# This file is machine-generated - editing it directly is not advised + +julia_version = "1.10.11" +manifest_format = "2.0" +project_hash = "5578dd2aac58cda5d4cf32fe876f733701deb830" + +[[deps.ArgTools]] +uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" +version = "1.1.1" + +[[deps.Artifacts]] +uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" + +[[deps.BridgeStan]] +deps = ["Downloads", "Inflate", "TOML", "Tar"] +git-tree-sha1 = "f8689ac4ce3245df7a436889988762a6c4a9da12" +uuid = "c88b6f0a-829e-4b0b-94b7-f06ab5908f5a" +version = "2.7.0" + +[[deps.Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[deps.Downloads]] +deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"] +uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6" +version = "1.6.0" + +[[deps.FileWatching]] +uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee" + +[[deps.Inflate]] +git-tree-sha1 = "d1b1b796e47d94588b3757fe84fbf65a5ec4a80d" +uuid = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9" +version = "0.1.5" + +[[deps.LibCURL]] +deps = ["LibCURL_jll", "MozillaCACerts_jll"] +uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" +version = "0.6.4" + +[[deps.LibCURL_jll]] +deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"] +uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0" +version = "8.4.0+0" + +[[deps.LibSSH2_jll]] +deps = ["Artifacts", "Libdl", "MbedTLS_jll"] +uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8" +version = "1.11.0+1" + +[[deps.Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[deps.MbedTLS_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" +version = "2.28.1010+0" + +[[deps.MozillaCACerts_jll]] +uuid = "14a3606d-f60d-562e-9121-12d972cd8159" +version = "2025.12.2" + +[[deps.NetworkOptions]] +uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" +version = "1.2.0" + +[[deps.Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[deps.SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" +version = "0.7.0" + +[[deps.TOML]] +deps = ["Dates"] +uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" +version = "1.0.3" + +[[deps.Tar]] +deps = ["ArgTools", "SHA"] +uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" +version = "1.10.0" + +[[deps.Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[deps.Zlib_jll]] +deps = ["Libdl"] +uuid = "83775a58-1f1d-513f-b197-d71354ab007a" +version = "1.2.13+1" + +[[deps.nghttp2_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d" +version = "1.52.0+1" diff --git a/mwe/.env-worktree/Project.toml b/mwe/.env-worktree/Project.toml new file mode 100644 index 00000000000..bdf49f9a5ef --- /dev/null +++ b/mwe/.env-worktree/Project.toml @@ -0,0 +1,2 @@ +[deps] +BridgeStan = "c88b6f0a-829e-4b0b-94b7-f06ab5908f5a" diff --git a/mwe/Project.toml b/mwe/Project.toml new file mode 100644 index 00000000000..bdf49f9a5ef --- /dev/null +++ b/mwe/Project.toml @@ -0,0 +1,2 @@ +[deps] +BridgeStan = "c88b6f0a-829e-4b0b-94b7-f06ab5908f5a" diff --git a/mwe/mwe.jl b/mwe/mwe.jl new file mode 100644 index 00000000000..599ff64ce95 --- /dev/null +++ b/mwe/mwe.jl @@ -0,0 +1,54 @@ +using BridgeStan + +stan_code = """ +functions { + real partial_sum(array[] real slice, int start, int end, + tuple(real, int) params) { + real mu = params.1; + int K = params.2; + real lp = 0; + for (i in 1:size(slice)) { + lp += normal_lpdf(slice[i] | mu, K); + } + return lp; + } +} +data { + int N; + int K; + array[N] real y; +} +parameters { + real mu; +} +model { + mu ~ normal(0, 10); + target += reduce_sum(partial_sum, y, 1, (mu, K)); +} +""" + +stan_math = ENV["MWE_RUN_DIR"] +label = ENV["MWE_LABEL"] + +workdir = mktempdir() +stan_file = joinpath(workdir, "mwe.stan") +write(stan_file, stan_code) + +lib = compile_model(stan_file; make_args=["STAN_MATH=$stan_math", "STAN_THREADS=true"]) + +data = """{"N": 5, "K": 2, "y": [1.0, 2.0, 3.0, 4.0, 5.0]}""" +sm = StanModel(lib, data) + +params = [3.0] # mu (unconstrained) +lp = log_density(sm, params) +lp_grad, grad = log_density_gradient(sm, params) + +println("[$label] log_density = $lp") +println("[$label] gradient = $grad") + +@assert isfinite(lp) "log_density should be finite" +@assert all(isfinite, grad) "gradient should be finite" +@assert lp ≈ lp_grad "log_density values should match" +@assert length(grad) == 1 "gradient should have 1 element" + +println("[$label] All checks passed!") diff --git a/mwe/mwe.main.out b/mwe/mwe.main.out new file mode 100644 index 00000000000..31cdfa652f9 --- /dev/null +++ b/mwe/mwe.main.out @@ -0,0 +1,193 @@ +# MWE: mwe.jl on main +# started: 2026-03-25 11:14:04 +# dir: /home/niko/github/stan-dev/math +# project: /home/niko/github/issues/stan-dev-math/worktrees/3041-map-tuple/mwe/.env-main +--- +==> Pkg.instantiate() +==> Running mwe.jl +ERROR: LoadError: Compilation failed! +Command: setenv(`make STAN_MATH=/home/niko/github/stan-dev/math STAN_THREADS=true /tmp/jl_aYanbD/mwe_model.so`; dir="/home/niko/.bridgestan/bridgestan-2.7.0") +stdout: +--- Translating Stan model to C++ code --- +./bin/stanc --o=/tmp/jl_aYanbD/mwe.hpp /tmp/jl_aYanbD/mwe.stan + +--- Compiling C++ code --- +g++ -std=c++17 -pthread -D_REENTRANT -Wno-sign-compare -Wno-ignored-attributes -Wno-class-memaccess -DSTAN_THREADS -I ./stan/lib/stan_math/lib/tbb_2020.3/include -O3 -I ./stan/src -I ./stan/lib/rapidjson_1.1.0/ -I ./stan/lib/stan_math/ -I ./stan/lib/stan_math/lib/eigen_3.4.0 -I ./stan/lib/stan_math/lib/boost_1.87.0 -I ./stan/lib/stan_math/lib/sundials_6.1.1/include -I ./stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -DBOOST_DISABLE_ASSERTS -DBRIDGESTAN_EXPORT -DSTAN_OVERRIDE_EIGEN_ASSERT -c -x c++ -o /tmp/jl_aYanbD/mwe.o /tmp/jl_aYanbD/mwe.hpp +rm /tmp/jl_aYanbD/mwe.hpp + +stderr: In file included from ./stan/lib/stan_math/stan/math/rev/functor.hpp:30, + from ./stan/lib/stan_math/stan/math/rev.hpp:15, + from ./stan/lib/stan_math/stan/math.hpp:19, + from ./stan/src/stan/model/model_header.hpp:6, + from /tmp/jl_aYanbD/mwe.hpp:2: +./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp: In instantiation of ‘stan::math::var stan::math::internal::reduce_sum_impl::type>::value, void>::type, ReturnType, Vec, Args ...>::operator()(Vec&&, bool, int, std::ostream*, Args&& ...) const [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; ReturnType = stan::math::var_value; Vec = const std::vector&; Args = {std::tuple&, const int&>}; typename std::enable_if::type>::value, void>::type = void; typename std::decay<_Tp2>::type = std::decay >::type; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’: +./stan/lib/stan_math/stan/math/prim/functor/reduce_sum.hpp:208:60: required from ‘auto stan::math::reduce_sum(Vec&&, int, std::ostream*, Args&& ...) [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; Vec = const std::vector&; = void; Args = {std::tuple&, const int&>}; std::ostream = std::basic_ostream]’ +/tmp/jl_aYanbD/mwe.hpp:252:71: required from ‘stan::scalar_type_t mwe_model_namespace::mwe_model::log_prob_impl(VecR&, VecI&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; VecR = Eigen::Matrix, -1, 1>; VecI = Eigen::Matrix; stan::require_vector_like_t* = 0; stan::require_vector_like_vt* = 0; stan::require_st_var* = 0; stan::scalar_type_t = stan::math::var_value; std::ostream = std::basic_ostream]’ +/tmp/jl_aYanbD/mwe.hpp:434:47: required from ‘T_ mwe_model_namespace::mwe_model::log_prob(Eigen::Matrix&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; T_ = stan::math::var_value; std::ostream = std::basic_ostream]’ +./stan/src/stan/model/model_base_crtp.hpp:98:72: required from ‘stan::math::var stan::model::model_base_crtp::log_prob(Eigen::Matrix, -1, 1>&, std::ostream*) const [with M = mwe_model_namespace::mwe_model; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ +./stan/src/stan/model/model_base_crtp.hpp:96:20: required from here +./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:241:15: error: no matching function for call to ‘save_varis(stan::math::vari**, std::tuple&, const int&>&)’ + 241 | save_varis(varis + num_vars_sliced_terms, args...); + | ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +In file included from ./stan/lib/stan_math/stan/math/rev/core.hpp:76, + from ./stan/src/stan/model/model_base.hpp:8, + from ./stan/src/stan/model/model_header.hpp:4, + from /tmp/jl_aYanbD/mwe.hpp:2: +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:51:15: note: candidate: ‘template stan::math::vari** stan::math::save_varis(stan::math::vari**, const var&, Pargs&& ...)’ + 51 | inline vari** save_varis(vari** dest, const var& x, Pargs&&... args) { + | ^~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:51:15: note: template argument deduction/substitution failed: +In file included from ./stan/lib/stan_math/stan/math/rev/functor.hpp:30, + from ./stan/lib/stan_math/stan/math/rev.hpp:15, + from ./stan/lib/stan_math/stan/math.hpp:19, + from ./stan/src/stan/model/model_header.hpp:6, + from /tmp/jl_aYanbD/mwe.hpp:2: +./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:241:15: note: cannot convert ‘args#0’ (type ‘std::tuple&, const int&>’) to type ‘const var&’ {aka ‘const stan::math::var_value&’} + 241 | save_varis(varis + num_vars_sliced_terms, args...); + | ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +In file included from ./stan/lib/stan_math/stan/math/rev/core.hpp:76, + from ./stan/src/stan/model/model_base.hpp:8, + from ./stan/src/stan/model/model_header.hpp:4, + from /tmp/jl_aYanbD/mwe.hpp:2: +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:71:15: note: candidate: ‘template* , class ... Pargs> stan::math::vari** stan::math::save_varis(stan::math::vari**, VarVec&&, Pargs&& ...)’ + 71 | inline vari** save_varis(vari** dest, VarVec&& x, Pargs&&... args) { + | ^~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:71:15: note: template argument deduction/substitution failed: +In file included from /usr/include/c++/11/bits/move.h:57, + from /usr/include/c++/11/bits/exception_ptr.h:43, + from /usr/include/c++/11/exception:153, + from /usr/include/c++/11/ios:39, + from /usr/include/c++/11/istream:38, + from /usr/include/c++/11/sstream:38, + from ./stan/src/stan/io/var_context.hpp:4, + from ./stan/src/stan/model/model_base.hpp:7, + from ./stan/src/stan/model/model_header.hpp:4, + from /tmp/jl_aYanbD/mwe.hpp:2: +/usr/include/c++/11/type_traits: In substitution of ‘template using enable_if_t = typename std::enable_if::type [with bool _Cond = false; _Tp = void]’: +./stan/lib/stan_math/stan/math/prim/meta/require_helpers.hpp:19:7: required by substitution of ‘template using require_t = std::enable_if_t [with Check = std::integral_constant]’ +./stan/lib/stan_math/stan/math/prim/meta/is_vector.hpp:677:7: required by substitution of ‘template class TypeCheck, class ... Check> using require_std_vector_vt = stan::require_t > [with TypeCheck = stan::is_var; Check = {std::tuple&, const int&>&}]’ +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:18:69: required from ‘stan::math::var stan::math::internal::reduce_sum_impl::type>::value, void>::type, ReturnType, Vec, Args ...>::operator()(Vec&&, bool, int, std::ostream*, Args&& ...) const [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; ReturnType = stan::math::var_value; Vec = const std::vector&; Args = {std::tuple&, const int&>}; typename std::enable_if::type>::value, void>::type = void; typename std::decay<_Tp2>::type = std::decay >::type; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ +./stan/lib/stan_math/stan/math/prim/functor/reduce_sum.hpp:208:60: required from ‘auto stan::math::reduce_sum(Vec&&, int, std::ostream*, Args&& ...) [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; Vec = const std::vector&; = void; Args = {std::tuple&, const int&>}; std::ostream = std::basic_ostream]’ +/tmp/jl_aYanbD/mwe.hpp:252:71: required from ‘stan::scalar_type_t mwe_model_namespace::mwe_model::log_prob_impl(VecR&, VecI&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; VecR = Eigen::Matrix, -1, 1>; VecI = Eigen::Matrix; stan::require_vector_like_t* = 0; stan::require_vector_like_vt* = 0; stan::require_st_var* = 0; stan::scalar_type_t = stan::math::var_value; std::ostream = std::basic_ostream]’ +/tmp/jl_aYanbD/mwe.hpp:434:47: required from ‘T_ mwe_model_namespace::mwe_model::log_prob(Eigen::Matrix&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; T_ = stan::math::var_value; std::ostream = std::basic_ostream]’ +./stan/src/stan/model/model_base_crtp.hpp:98:72: required from ‘stan::math::var stan::model::model_base_crtp::log_prob(Eigen::Matrix, -1, 1>&, std::ostream*) const [with M = mwe_model_namespace::mwe_model; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ +./stan/src/stan/model/model_base_crtp.hpp:96:20: required from here +/usr/include/c++/11/type_traits:2579:11: error: no type named ‘type’ in ‘struct std::enable_if’ + 2579 | using enable_if_t = typename enable_if<_Cond, _Tp>::type; + | ^~~~~~~~~~~ +In file included from ./stan/lib/stan_math/stan/math/rev/core.hpp:76, + from ./stan/src/stan/model/model_base.hpp:8, + from ./stan/src/stan/model/model_header.hpp:4, + from /tmp/jl_aYanbD/mwe.hpp:2: +./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp: In instantiation of ‘stan::math::var stan::math::internal::reduce_sum_impl::type>::value, void>::type, ReturnType, Vec, Args ...>::operator()(Vec&&, bool, int, std::ostream*, Args&& ...) const [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; ReturnType = stan::math::var_value; Vec = const std::vector&; Args = {std::tuple&, const int&>}; typename std::enable_if::type>::value, void>::type = void; typename std::decay<_Tp2>::type = std::decay >::type; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’: +./stan/lib/stan_math/stan/math/prim/functor/reduce_sum.hpp:208:60: required from ‘auto stan::math::reduce_sum(Vec&&, int, std::ostream*, Args&& ...) [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; Vec = const std::vector&; = void; Args = {std::tuple&, const int&>}; std::ostream = std::basic_ostream]’ +/tmp/jl_aYanbD/mwe.hpp:252:71: required from ‘stan::scalar_type_t mwe_model_namespace::mwe_model::log_prob_impl(VecR&, VecI&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; VecR = Eigen::Matrix, -1, 1>; VecI = Eigen::Matrix; stan::require_vector_like_t* = 0; stan::require_vector_like_vt* = 0; stan::require_st_var* = 0; stan::scalar_type_t = stan::math::var_value; std::ostream = std::basic_ostream]’ +/tmp/jl_aYanbD/mwe.hpp:434:47: required from ‘T_ mwe_model_namespace::mwe_model::log_prob(Eigen::Matrix&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; T_ = stan::math::var_value; std::ostream = std::basic_ostream]’ +./stan/src/stan/model/model_base_crtp.hpp:98:72: required from ‘stan::math::var stan::model::model_base_crtp::log_prob(Eigen::Matrix, -1, 1>&, std::ostream*) const [with M = mwe_model_namespace::mwe_model; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ +./stan/src/stan/model/model_base_crtp.hpp:96:20: required from here +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:93:15: note: candidate: ‘template* , stan::require_std_vector_vt* , class ... Pargs> stan::math::vari** stan::math::save_varis(stan::math::vari**, VecContainer&&, Pargs&& ...)’ + 93 | inline vari** save_varis(vari** dest, VecContainer&& x, Pargs&&... args) { + | ^~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:93:15: note: template argument deduction/substitution failed: +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:114:15: note: candidate: ‘template* , class ... Pargs> stan::math::vari** stan::math::save_varis(stan::math::vari**, EigT&&, Pargs&& ...)’ + 114 | inline vari** save_varis(vari** dest, EigT&& x, Pargs&&... args) { + | ^~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:114:15: note: template argument deduction/substitution failed: +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:135:15: note: candidate: ‘template* , class ... Pargs> stan::math::vari** stan::math::save_varis(stan::math::vari**, Arith&&, Pargs&& ...)’ + 135 | inline vari** save_varis(vari** dest, Arith&& x, Pargs&&... args) { + | ^~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:135:15: note: template argument deduction/substitution failed: +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:144:15: note: candidate: ‘stan::math::vari** stan::math::save_varis(stan::math::vari**)’ + 144 | inline vari** save_varis(vari** dest) { return dest; } + | ^~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:144:15: note: candidate expects 1 argument, 2 provided +In file included from ./stan/lib/stan_math/stan/math/rev/functor.hpp:30, + from ./stan/lib/stan_math/stan/math/rev.hpp:15, + from ./stan/lib/stan_math/stan/math.hpp:19, + from ./stan/src/stan/model/model_header.hpp:6, + from /tmp/jl_aYanbD/mwe.hpp:2: +./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp: In instantiation of ‘struct stan::math::internal::reduce_sum_impl, const std::vector&, std::tuple&, const int&> >::scoped_args_tuple’: +./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:58:23: required from ‘struct stan::math::internal::reduce_sum_impl, const std::vector&, std::tuple&, const int&> >::recursive_reducer’ +./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:247:23: required from ‘stan::math::var stan::math::internal::reduce_sum_impl::type>::value, void>::type, ReturnType, Vec, Args ...>::operator()(Vec&&, bool, int, std::ostream*, Args&& ...) const [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; ReturnType = stan::math::var_value; Vec = const std::vector&; Args = {std::tuple&, const int&>}; typename std::enable_if::type>::value, void>::type = void; typename std::decay<_Tp2>::type = std::decay >::type; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ +./stan/lib/stan_math/stan/math/prim/functor/reduce_sum.hpp:208:60: required from ‘auto stan::math::reduce_sum(Vec&&, int, std::ostream*, Args&& ...) [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; Vec = const std::vector&; = void; Args = {std::tuple&, const int&>}; std::ostream = std::basic_ostream]’ +/tmp/jl_aYanbD/mwe.hpp:252:71: required from ‘stan::scalar_type_t mwe_model_namespace::mwe_model::log_prob_impl(VecR&, VecI&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; VecR = Eigen::Matrix, -1, 1>; VecI = Eigen::Matrix; stan::require_vector_like_t* = 0; stan::require_vector_like_vt* = 0; stan::require_st_var* = 0; stan::scalar_type_t = stan::math::var_value; std::ostream = std::basic_ostream]’ +/tmp/jl_aYanbD/mwe.hpp:434:47: required from ‘T_ mwe_model_namespace::mwe_model::log_prob(Eigen::Matrix&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; T_ = stan::math::var_value; std::ostream = std::basic_ostream]’ +./stan/src/stan/model/model_base_crtp.hpp:98:72: required from ‘stan::math::var stan::model::model_base_crtp::log_prob(Eigen::Matrix, -1, 1>&, std::ostream*) const [with M = mwe_model_namespace::mwe_model; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ +./stan/src/stan/model/model_base_crtp.hpp:96:20: required from here +./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:36:45: error: no matching function for call to ‘deep_copy_vars(std::tuple&, const int&>)’ + 36 | = std::tuple()))...>; + | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ +In file included from ./stan/lib/stan_math/stan/math/rev/core.hpp:17, + from ./stan/src/stan/model/model_base.hpp:8, + from ./stan/src/stan/model/model_header.hpp:4, + from /tmp/jl_aYanbD/mwe.hpp:2: +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:23:14: note: candidate: ‘template Arith stan::math::deep_copy_vars(Arith&&)’ + 23 | inline Arith deep_copy_vars(Arith&& arg) { + | ^~~~~~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:23:14: note: template argument deduction/substitution failed: +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:45:13: note: candidate: ‘template* > auto stan::math::deep_copy_vars(VarVec&&)’ + 45 | inline auto deep_copy_vars(VarVec&& arg) { + | ^~~~~~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:45:13: note: template argument deduction/substitution failed: +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:63:13: note: candidate: ‘template* , stan::require_std_vector_vt* > auto stan::math::deep_copy_vars(VecContainer&&)’ + 63 | inline auto deep_copy_vars(VecContainer&& arg) { + | ^~~~~~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:63:13: note: template argument deduction/substitution failed: +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:79:13: note: candidate: ‘template* > auto stan::math::deep_copy_vars(EigT&&)’ + 79 | inline auto deep_copy_vars(EigT&& arg) { + | ^~~~~~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:79:13: note: template argument deduction/substitution failed: +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:33:13: note: candidate: ‘auto stan::math::deep_copy_vars(const var&)’ + 33 | inline auto deep_copy_vars(const var& arg) { + | ^~~~~~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:33:39: note: no known conversion for argument 1 from ‘std::tuple&, const int&>’ to ‘const var&’ {aka ‘const stan::math::var_value&’} + 33 | inline auto deep_copy_vars(const var& arg) { + | ~~~~~~~~~~~^~~ +In file included from ./stan/lib/stan_math/stan/math/rev/functor.hpp:30, + from ./stan/lib/stan_math/stan/math/rev.hpp:15, + from ./stan/lib/stan_math/stan/math.hpp:19, + from ./stan/src/stan/model/model_header.hpp:6, + from /tmp/jl_aYanbD/mwe.hpp:2: +./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:36:45: error: no matching function for call to ‘deep_copy_vars(std::tuple&, const int&>)’ + 36 | = std::tuple()))...>; + | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ +In file included from ./stan/lib/stan_math/stan/math/rev/core.hpp:17, + from ./stan/src/stan/model/model_base.hpp:8, + from ./stan/src/stan/model/model_header.hpp:4, + from /tmp/jl_aYanbD/mwe.hpp:2: +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:23:14: note: candidate: ‘template Arith stan::math::deep_copy_vars(Arith&&)’ + 23 | inline Arith deep_copy_vars(Arith&& arg) { + | ^~~~~~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:23:14: note: template argument deduction/substitution failed: +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:45:13: note: candidate: ‘template* > auto stan::math::deep_copy_vars(VarVec&&)’ + 45 | inline auto deep_copy_vars(VarVec&& arg) { + | ^~~~~~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:45:13: note: template argument deduction/substitution failed: +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:63:13: note: candidate: ‘template* , stan::require_std_vector_vt* > auto stan::math::deep_copy_vars(VecContainer&&)’ + 63 | inline auto deep_copy_vars(VecContainer&& arg) { + | ^~~~~~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:63:13: note: template argument deduction/substitution failed: +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:79:13: note: candidate: ‘template* > auto stan::math::deep_copy_vars(EigT&&)’ + 79 | inline auto deep_copy_vars(EigT&& arg) { + | ^~~~~~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:79:13: note: template argument deduction/substitution failed: +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:33:13: note: candidate: ‘auto stan::math::deep_copy_vars(const var&)’ + 33 | inline auto deep_copy_vars(const var& arg) { + | ^~~~~~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:33:39: note: no known conversion for argument 1 from ‘std::tuple&, const int&>’ to ‘const var&’ {aka ‘const stan::math::var_value&’} + 33 | inline auto deep_copy_vars(const var& arg) { + | ~~~~~~~~~~~^~~ +make: *** [Makefile:77: /tmp/jl_aYanbD/mwe.o] Error 1 + +Stacktrace: + [1] error(s::String) + @ Base ./error.jl:35 + [2] compile_model(stan_file::String; stanc_args::Vector{String}, make_args::Vector{String}) + @ BridgeStan ~/.julia/packages/BridgeStan/Bodre/src/compile.jl:114 + [3] top-level scope + @ ~/github/issues/stan-dev-math/worktrees/3041-map-tuple/mwe/mwe.jl:37 +in expression starting at /home/niko/github/issues/stan-dev-math/worktrees/3041-map-tuple/mwe/mwe.jl:37 + +# exit_code: 1 +# status: FAIL +# finished: 2026-03-25 11:14:22 diff --git a/mwe/mwe.worktree.out b/mwe/mwe.worktree.out new file mode 100644 index 00000000000..a969001e1a5 --- /dev/null +++ b/mwe/mwe.worktree.out @@ -0,0 +1,193 @@ +# MWE: mwe.jl on worktree +# started: 2026-03-25 11:14:04 +# dir: /home/niko/github/issues/stan-dev-math/worktrees/3041-map-tuple +# project: /home/niko/github/issues/stan-dev-math/worktrees/3041-map-tuple/mwe/.env-worktree +--- +==> Pkg.instantiate() +==> Running mwe.jl +ERROR: LoadError: Compilation failed! +Command: setenv(`make STAN_MATH=/home/niko/github/issues/stan-dev-math/worktrees/3041-map-tuple STAN_THREADS=true /tmp/jl_QQmvi1/mwe_model.so`; dir="/home/niko/.bridgestan/bridgestan-2.7.0") +stdout: +--- Translating Stan model to C++ code --- +./bin/stanc --o=/tmp/jl_QQmvi1/mwe.hpp /tmp/jl_QQmvi1/mwe.stan + +--- Compiling C++ code --- +g++ -std=c++17 -pthread -D_REENTRANT -Wno-sign-compare -Wno-ignored-attributes -Wno-class-memaccess -DSTAN_THREADS -I ./stan/lib/stan_math/lib/tbb_2020.3/include -O3 -I ./stan/src -I ./stan/lib/rapidjson_1.1.0/ -I ./stan/lib/stan_math/ -I ./stan/lib/stan_math/lib/eigen_3.4.0 -I ./stan/lib/stan_math/lib/boost_1.87.0 -I ./stan/lib/stan_math/lib/sundials_6.1.1/include -I ./stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -DBOOST_DISABLE_ASSERTS -DBRIDGESTAN_EXPORT -DSTAN_OVERRIDE_EIGEN_ASSERT -c -x c++ -o /tmp/jl_QQmvi1/mwe.o /tmp/jl_QQmvi1/mwe.hpp +rm /tmp/jl_QQmvi1/mwe.hpp + +stderr: In file included from ./stan/lib/stan_math/stan/math/rev/functor.hpp:30, + from ./stan/lib/stan_math/stan/math/rev.hpp:15, + from ./stan/lib/stan_math/stan/math.hpp:19, + from ./stan/src/stan/model/model_header.hpp:6, + from /tmp/jl_QQmvi1/mwe.hpp:2: +./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp: In instantiation of ‘stan::math::var stan::math::internal::reduce_sum_impl::type>::value, void>::type, ReturnType, Vec, Args ...>::operator()(Vec&&, bool, int, std::ostream*, Args&& ...) const [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; ReturnType = stan::math::var_value; Vec = const std::vector&; Args = {std::tuple&, const int&>}; typename std::enable_if::type>::value, void>::type = void; typename std::decay<_Tp2>::type = std::decay >::type; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’: +./stan/lib/stan_math/stan/math/prim/functor/reduce_sum.hpp:208:60: required from ‘auto stan::math::reduce_sum(Vec&&, int, std::ostream*, Args&& ...) [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; Vec = const std::vector&; = void; Args = {std::tuple&, const int&>}; std::ostream = std::basic_ostream]’ +/tmp/jl_QQmvi1/mwe.hpp:252:71: required from ‘stan::scalar_type_t mwe_model_namespace::mwe_model::log_prob_impl(VecR&, VecI&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; VecR = Eigen::Matrix, -1, 1>; VecI = Eigen::Matrix; stan::require_vector_like_t* = 0; stan::require_vector_like_vt* = 0; stan::require_st_var* = 0; stan::scalar_type_t = stan::math::var_value; std::ostream = std::basic_ostream]’ +/tmp/jl_QQmvi1/mwe.hpp:434:47: required from ‘T_ mwe_model_namespace::mwe_model::log_prob(Eigen::Matrix&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; T_ = stan::math::var_value; std::ostream = std::basic_ostream]’ +./stan/src/stan/model/model_base_crtp.hpp:98:72: required from ‘stan::math::var stan::model::model_base_crtp::log_prob(Eigen::Matrix, -1, 1>&, std::ostream*) const [with M = mwe_model_namespace::mwe_model; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ +./stan/src/stan/model/model_base_crtp.hpp:96:20: required from here +./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:241:15: error: no matching function for call to ‘save_varis(stan::math::vari**, std::tuple&, const int&>&)’ + 241 | save_varis(varis + num_vars_sliced_terms, args...); + | ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +In file included from ./stan/lib/stan_math/stan/math/rev/core.hpp:76, + from ./stan/src/stan/model/model_base.hpp:8, + from ./stan/src/stan/model/model_header.hpp:4, + from /tmp/jl_QQmvi1/mwe.hpp:2: +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:51:15: note: candidate: ‘template stan::math::vari** stan::math::save_varis(stan::math::vari**, const var&, Pargs&& ...)’ + 51 | inline vari** save_varis(vari** dest, const var& x, Pargs&&... args) { + | ^~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:51:15: note: template argument deduction/substitution failed: +In file included from ./stan/lib/stan_math/stan/math/rev/functor.hpp:30, + from ./stan/lib/stan_math/stan/math/rev.hpp:15, + from ./stan/lib/stan_math/stan/math.hpp:19, + from ./stan/src/stan/model/model_header.hpp:6, + from /tmp/jl_QQmvi1/mwe.hpp:2: +./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:241:15: note: cannot convert ‘args#0’ (type ‘std::tuple&, const int&>’) to type ‘const var&’ {aka ‘const stan::math::var_value&’} + 241 | save_varis(varis + num_vars_sliced_terms, args...); + | ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +In file included from ./stan/lib/stan_math/stan/math/rev/core.hpp:76, + from ./stan/src/stan/model/model_base.hpp:8, + from ./stan/src/stan/model/model_header.hpp:4, + from /tmp/jl_QQmvi1/mwe.hpp:2: +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:71:15: note: candidate: ‘template* , class ... Pargs> stan::math::vari** stan::math::save_varis(stan::math::vari**, VarVec&&, Pargs&& ...)’ + 71 | inline vari** save_varis(vari** dest, VarVec&& x, Pargs&&... args) { + | ^~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:71:15: note: template argument deduction/substitution failed: +In file included from /usr/include/c++/11/bits/move.h:57, + from /usr/include/c++/11/bits/exception_ptr.h:43, + from /usr/include/c++/11/exception:153, + from /usr/include/c++/11/ios:39, + from /usr/include/c++/11/istream:38, + from /usr/include/c++/11/sstream:38, + from ./stan/src/stan/io/var_context.hpp:4, + from ./stan/src/stan/model/model_base.hpp:7, + from ./stan/src/stan/model/model_header.hpp:4, + from /tmp/jl_QQmvi1/mwe.hpp:2: +/usr/include/c++/11/type_traits: In substitution of ‘template using enable_if_t = typename std::enable_if::type [with bool _Cond = false; _Tp = void]’: +./stan/lib/stan_math/stan/math/prim/meta/require_helpers.hpp:19:7: required by substitution of ‘template using require_t = std::enable_if_t [with Check = std::integral_constant]’ +./stan/lib/stan_math/stan/math/prim/meta/is_vector.hpp:677:7: required by substitution of ‘template class TypeCheck, class ... Check> using require_std_vector_vt = stan::require_t > [with TypeCheck = stan::is_var; Check = {std::tuple&, const int&>&}]’ +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:18:69: required from ‘stan::math::var stan::math::internal::reduce_sum_impl::type>::value, void>::type, ReturnType, Vec, Args ...>::operator()(Vec&&, bool, int, std::ostream*, Args&& ...) const [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; ReturnType = stan::math::var_value; Vec = const std::vector&; Args = {std::tuple&, const int&>}; typename std::enable_if::type>::value, void>::type = void; typename std::decay<_Tp2>::type = std::decay >::type; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ +./stan/lib/stan_math/stan/math/prim/functor/reduce_sum.hpp:208:60: required from ‘auto stan::math::reduce_sum(Vec&&, int, std::ostream*, Args&& ...) [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; Vec = const std::vector&; = void; Args = {std::tuple&, const int&>}; std::ostream = std::basic_ostream]’ +/tmp/jl_QQmvi1/mwe.hpp:252:71: required from ‘stan::scalar_type_t mwe_model_namespace::mwe_model::log_prob_impl(VecR&, VecI&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; VecR = Eigen::Matrix, -1, 1>; VecI = Eigen::Matrix; stan::require_vector_like_t* = 0; stan::require_vector_like_vt* = 0; stan::require_st_var* = 0; stan::scalar_type_t = stan::math::var_value; std::ostream = std::basic_ostream]’ +/tmp/jl_QQmvi1/mwe.hpp:434:47: required from ‘T_ mwe_model_namespace::mwe_model::log_prob(Eigen::Matrix&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; T_ = stan::math::var_value; std::ostream = std::basic_ostream]’ +./stan/src/stan/model/model_base_crtp.hpp:98:72: required from ‘stan::math::var stan::model::model_base_crtp::log_prob(Eigen::Matrix, -1, 1>&, std::ostream*) const [with M = mwe_model_namespace::mwe_model; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ +./stan/src/stan/model/model_base_crtp.hpp:96:20: required from here +/usr/include/c++/11/type_traits:2579:11: error: no type named ‘type’ in ‘struct std::enable_if’ + 2579 | using enable_if_t = typename enable_if<_Cond, _Tp>::type; + | ^~~~~~~~~~~ +In file included from ./stan/lib/stan_math/stan/math/rev/core.hpp:76, + from ./stan/src/stan/model/model_base.hpp:8, + from ./stan/src/stan/model/model_header.hpp:4, + from /tmp/jl_QQmvi1/mwe.hpp:2: +./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp: In instantiation of ‘stan::math::var stan::math::internal::reduce_sum_impl::type>::value, void>::type, ReturnType, Vec, Args ...>::operator()(Vec&&, bool, int, std::ostream*, Args&& ...) const [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; ReturnType = stan::math::var_value; Vec = const std::vector&; Args = {std::tuple&, const int&>}; typename std::enable_if::type>::value, void>::type = void; typename std::decay<_Tp2>::type = std::decay >::type; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’: +./stan/lib/stan_math/stan/math/prim/functor/reduce_sum.hpp:208:60: required from ‘auto stan::math::reduce_sum(Vec&&, int, std::ostream*, Args&& ...) [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; Vec = const std::vector&; = void; Args = {std::tuple&, const int&>}; std::ostream = std::basic_ostream]’ +/tmp/jl_QQmvi1/mwe.hpp:252:71: required from ‘stan::scalar_type_t mwe_model_namespace::mwe_model::log_prob_impl(VecR&, VecI&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; VecR = Eigen::Matrix, -1, 1>; VecI = Eigen::Matrix; stan::require_vector_like_t* = 0; stan::require_vector_like_vt* = 0; stan::require_st_var* = 0; stan::scalar_type_t = stan::math::var_value; std::ostream = std::basic_ostream]’ +/tmp/jl_QQmvi1/mwe.hpp:434:47: required from ‘T_ mwe_model_namespace::mwe_model::log_prob(Eigen::Matrix&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; T_ = stan::math::var_value; std::ostream = std::basic_ostream]’ +./stan/src/stan/model/model_base_crtp.hpp:98:72: required from ‘stan::math::var stan::model::model_base_crtp::log_prob(Eigen::Matrix, -1, 1>&, std::ostream*) const [with M = mwe_model_namespace::mwe_model; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ +./stan/src/stan/model/model_base_crtp.hpp:96:20: required from here +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:93:15: note: candidate: ‘template* , stan::require_std_vector_vt* , class ... Pargs> stan::math::vari** stan::math::save_varis(stan::math::vari**, VecContainer&&, Pargs&& ...)’ + 93 | inline vari** save_varis(vari** dest, VecContainer&& x, Pargs&&... args) { + | ^~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:93:15: note: template argument deduction/substitution failed: +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:114:15: note: candidate: ‘template* , class ... Pargs> stan::math::vari** stan::math::save_varis(stan::math::vari**, EigT&&, Pargs&& ...)’ + 114 | inline vari** save_varis(vari** dest, EigT&& x, Pargs&&... args) { + | ^~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:114:15: note: template argument deduction/substitution failed: +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:135:15: note: candidate: ‘template* , class ... Pargs> stan::math::vari** stan::math::save_varis(stan::math::vari**, Arith&&, Pargs&& ...)’ + 135 | inline vari** save_varis(vari** dest, Arith&& x, Pargs&&... args) { + | ^~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:135:15: note: template argument deduction/substitution failed: +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:144:15: note: candidate: ‘stan::math::vari** stan::math::save_varis(stan::math::vari**)’ + 144 | inline vari** save_varis(vari** dest) { return dest; } + | ^~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:144:15: note: candidate expects 1 argument, 2 provided +In file included from ./stan/lib/stan_math/stan/math/rev/functor.hpp:30, + from ./stan/lib/stan_math/stan/math/rev.hpp:15, + from ./stan/lib/stan_math/stan/math.hpp:19, + from ./stan/src/stan/model/model_header.hpp:6, + from /tmp/jl_QQmvi1/mwe.hpp:2: +./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp: In instantiation of ‘struct stan::math::internal::reduce_sum_impl, const std::vector&, std::tuple&, const int&> >::scoped_args_tuple’: +./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:58:23: required from ‘struct stan::math::internal::reduce_sum_impl, const std::vector&, std::tuple&, const int&> >::recursive_reducer’ +./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:247:23: required from ‘stan::math::var stan::math::internal::reduce_sum_impl::type>::value, void>::type, ReturnType, Vec, Args ...>::operator()(Vec&&, bool, int, std::ostream*, Args&& ...) const [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; ReturnType = stan::math::var_value; Vec = const std::vector&; Args = {std::tuple&, const int&>}; typename std::enable_if::type>::value, void>::type = void; typename std::decay<_Tp2>::type = std::decay >::type; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ +./stan/lib/stan_math/stan/math/prim/functor/reduce_sum.hpp:208:60: required from ‘auto stan::math::reduce_sum(Vec&&, int, std::ostream*, Args&& ...) [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; Vec = const std::vector&; = void; Args = {std::tuple&, const int&>}; std::ostream = std::basic_ostream]’ +/tmp/jl_QQmvi1/mwe.hpp:252:71: required from ‘stan::scalar_type_t mwe_model_namespace::mwe_model::log_prob_impl(VecR&, VecI&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; VecR = Eigen::Matrix, -1, 1>; VecI = Eigen::Matrix; stan::require_vector_like_t* = 0; stan::require_vector_like_vt* = 0; stan::require_st_var* = 0; stan::scalar_type_t = stan::math::var_value; std::ostream = std::basic_ostream]’ +/tmp/jl_QQmvi1/mwe.hpp:434:47: required from ‘T_ mwe_model_namespace::mwe_model::log_prob(Eigen::Matrix&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; T_ = stan::math::var_value; std::ostream = std::basic_ostream]’ +./stan/src/stan/model/model_base_crtp.hpp:98:72: required from ‘stan::math::var stan::model::model_base_crtp::log_prob(Eigen::Matrix, -1, 1>&, std::ostream*) const [with M = mwe_model_namespace::mwe_model; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ +./stan/src/stan/model/model_base_crtp.hpp:96:20: required from here +./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:36:45: error: no matching function for call to ‘deep_copy_vars(std::tuple&, const int&>)’ + 36 | = std::tuple()))...>; + | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ +In file included from ./stan/lib/stan_math/stan/math/rev/core.hpp:17, + from ./stan/src/stan/model/model_base.hpp:8, + from ./stan/src/stan/model/model_header.hpp:4, + from /tmp/jl_QQmvi1/mwe.hpp:2: +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:23:14: note: candidate: ‘template Arith stan::math::deep_copy_vars(Arith&&)’ + 23 | inline Arith deep_copy_vars(Arith&& arg) { + | ^~~~~~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:23:14: note: template argument deduction/substitution failed: +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:45:13: note: candidate: ‘template* > auto stan::math::deep_copy_vars(VarVec&&)’ + 45 | inline auto deep_copy_vars(VarVec&& arg) { + | ^~~~~~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:45:13: note: template argument deduction/substitution failed: +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:63:13: note: candidate: ‘template* , stan::require_std_vector_vt* > auto stan::math::deep_copy_vars(VecContainer&&)’ + 63 | inline auto deep_copy_vars(VecContainer&& arg) { + | ^~~~~~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:63:13: note: template argument deduction/substitution failed: +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:79:13: note: candidate: ‘template* > auto stan::math::deep_copy_vars(EigT&&)’ + 79 | inline auto deep_copy_vars(EigT&& arg) { + | ^~~~~~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:79:13: note: template argument deduction/substitution failed: +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:33:13: note: candidate: ‘auto stan::math::deep_copy_vars(const var&)’ + 33 | inline auto deep_copy_vars(const var& arg) { + | ^~~~~~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:33:39: note: no known conversion for argument 1 from ‘std::tuple&, const int&>’ to ‘const var&’ {aka ‘const stan::math::var_value&’} + 33 | inline auto deep_copy_vars(const var& arg) { + | ~~~~~~~~~~~^~~ +In file included from ./stan/lib/stan_math/stan/math/rev/functor.hpp:30, + from ./stan/lib/stan_math/stan/math/rev.hpp:15, + from ./stan/lib/stan_math/stan/math.hpp:19, + from ./stan/src/stan/model/model_header.hpp:6, + from /tmp/jl_QQmvi1/mwe.hpp:2: +./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:36:45: error: no matching function for call to ‘deep_copy_vars(std::tuple&, const int&>)’ + 36 | = std::tuple()))...>; + | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ +In file included from ./stan/lib/stan_math/stan/math/rev/core.hpp:17, + from ./stan/src/stan/model/model_base.hpp:8, + from ./stan/src/stan/model/model_header.hpp:4, + from /tmp/jl_QQmvi1/mwe.hpp:2: +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:23:14: note: candidate: ‘template Arith stan::math::deep_copy_vars(Arith&&)’ + 23 | inline Arith deep_copy_vars(Arith&& arg) { + | ^~~~~~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:23:14: note: template argument deduction/substitution failed: +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:45:13: note: candidate: ‘template* > auto stan::math::deep_copy_vars(VarVec&&)’ + 45 | inline auto deep_copy_vars(VarVec&& arg) { + | ^~~~~~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:45:13: note: template argument deduction/substitution failed: +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:63:13: note: candidate: ‘template* , stan::require_std_vector_vt* > auto stan::math::deep_copy_vars(VecContainer&&)’ + 63 | inline auto deep_copy_vars(VecContainer&& arg) { + | ^~~~~~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:63:13: note: template argument deduction/substitution failed: +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:79:13: note: candidate: ‘template* > auto stan::math::deep_copy_vars(EigT&&)’ + 79 | inline auto deep_copy_vars(EigT&& arg) { + | ^~~~~~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:79:13: note: template argument deduction/substitution failed: +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:33:13: note: candidate: ‘auto stan::math::deep_copy_vars(const var&)’ + 33 | inline auto deep_copy_vars(const var& arg) { + | ^~~~~~~~~~~~~~ +./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:33:39: note: no known conversion for argument 1 from ‘std::tuple&, const int&>’ to ‘const var&’ {aka ‘const stan::math::var_value&’} + 33 | inline auto deep_copy_vars(const var& arg) { + | ~~~~~~~~~~~^~~ +make: *** [Makefile:77: /tmp/jl_QQmvi1/mwe.o] Error 1 + +Stacktrace: + [1] error(s::String) + @ Base ./error.jl:35 + [2] compile_model(stan_file::String; stanc_args::Vector{String}, make_args::Vector{String}) + @ BridgeStan ~/.julia/packages/BridgeStan/Bodre/src/compile.jl:114 + [3] top-level scope + @ ~/github/issues/stan-dev-math/worktrees/3041-map-tuple/mwe/mwe.jl:37 +in expression starting at /home/niko/github/issues/stan-dev-math/worktrees/3041-map-tuple/mwe/mwe.jl:37 + +# exit_code: 1 +# status: FAIL +# finished: 2026-03-25 11:14:22 From 78e67ac2f4b9f9f10f702c5d370dd86b535ebb0e Mon Sep 17 00:00:00 2001 From: Nikolas Siccha Date: Wed, 25 Mar 2026 11:24:08 +0100 Subject: [PATCH 4/9] Fix: use MATH= instead of STAN_MATH= for BridgeStan make override Co-Authored-By: Claude Opus 4.6 (1M context) --- mwe/mwe.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mwe/mwe.jl b/mwe/mwe.jl index 599ff64ce95..b2ab7ea189d 100644 --- a/mwe/mwe.jl +++ b/mwe/mwe.jl @@ -34,7 +34,7 @@ workdir = mktempdir() stan_file = joinpath(workdir, "mwe.stan") write(stan_file, stan_code) -lib = compile_model(stan_file; make_args=["STAN_MATH=$stan_math", "STAN_THREADS=true"]) +lib = compile_model(stan_file; make_args=["MATH=$stan_math/", "STAN_THREADS=true"]) data = """{"N": 5, "K": 2, "y": [1.0, 2.0, 3.0, 4.0, 5.0]}""" sm = StanModel(lib, data) From 46eae9c68ac152f927b7d25e6274181ab3e73ede Mon Sep 17 00:00:00 2001 From: Nikolas Siccha Date: Wed, 25 Mar 2026 11:29:17 +0100 Subject: [PATCH 5/9] Revert "Add tuple support to apply_scalar_unary for autodiff" This reverts commit 23dafa2617a78cb6b9e68b7a3c3d9b35527a503d. --- stan/math/prim/functor/apply_scalar_unary.hpp | 32 ------------------- stan/math/prim/meta/is_autodiff.hpp | 13 -------- stan/math/prim/meta/is_container.hpp | 9 ++---- 3 files changed, 3 insertions(+), 51 deletions(-) diff --git a/stan/math/prim/functor/apply_scalar_unary.hpp b/stan/math/prim/functor/apply_scalar_unary.hpp index 16e660bb879..f37a57f8740 100644 --- a/stan/math/prim/functor/apply_scalar_unary.hpp +++ b/stan/math/prim/functor/apply_scalar_unary.hpp @@ -4,13 +4,11 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include @@ -208,36 +206,6 @@ struct apply_scalar_unary> { } }; -/** - * Template specialization for vectorized functions applying to - * tuple arguments. Each element of the tuple is processed - * recursively through apply_scalar_unary, allowing heterogeneous - * element types. - * - * @tparam F Type of function defining static apply function. - * @tparam T Tuple type. - */ -template -struct apply_scalar_unary> { - template - static inline auto apply_impl(TT&& x, std::index_sequence) { - return std::make_tuple( - apply_scalar_unary< - F, std::tuple_element_t>>:: - apply(std::get(std::forward(x)))...); - } - - template - static inline auto apply(TT&& x) { - return apply_impl( - std::forward(x), - std::make_index_sequence>>()); - } - - using return_t = std::decay_t::apply(std::declval()))>; -}; - } // namespace math } // namespace stan #endif diff --git a/stan/math/prim/meta/is_autodiff.hpp b/stan/math/prim/meta/is_autodiff.hpp index 056176cb77c..a5eec9f62e3 100644 --- a/stan/math/prim/meta/is_autodiff.hpp +++ b/stan/math/prim/meta/is_autodiff.hpp @@ -8,12 +8,10 @@ #include #include #include -#include #include #include #include #include -#include #include namespace stan { @@ -48,17 +46,6 @@ template struct is_autodiff> : bool_constant::Scalar>::value> {}; -template -struct is_tuple_autodiff : std::false_type {}; - -template -struct is_tuple_autodiff, void> - : bool_constant<(is_autodiff::value || ...)> {}; - -template -struct is_autodiff> - : is_tuple_autodiff> {}; - } // namespace internal /** diff --git a/stan/math/prim/meta/is_container.hpp b/stan/math/prim/meta/is_container.hpp index c2469424cb7..9928a154c9b 100644 --- a/stan/math/prim/meta/is_container.hpp +++ b/stan/math/prim/meta/is_container.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -100,11 +99,9 @@ using require_not_container_st /*! and holds a base type that satisfies @ref is_autodiff_scalar */ /*! @tparam T the type to check */ template -using require_ad_container_t = require_t, is_std_vector>, - is_autodiff_scalar>>, - math::conjunction, - internal::is_autodiff>>>>; +using require_ad_container_t + = require_all_t, is_std_vector>, + is_autodiff_scalar>>; /*! @} */ } // namespace stan From ac2068217a89bab216cee24815795217744027f9 Mon Sep 17 00:00:00 2001 From: Nikolas Siccha Date: Wed, 25 Mar 2026 11:35:35 +0100 Subject: [PATCH 6/9] Trim includes, add docs and tests for tuple overloads Remove unnecessary includes (already available via prim/meta.hpp). Add doxygen comments matching existing style. Add unit tests for tuple overloads of deep_copy_vars, save_varis, and accumulate_adjoints covering tuple, tuple, and tuple. Co-Authored-By: Claude Opus 4.6 (1M context) --- stan/math/rev/core/accumulate_adjoints.hpp | 13 +++++-- stan/math/rev/core/deep_copy_vars.hpp | 9 ++--- stan/math/rev/core/save_varis.hpp | 16 ++++++-- .../rev/core/accumulate_adjoints_test.cpp | 38 +++++++++++++++++++ .../math/rev/core/deep_copy_vars_test.cpp | 37 ++++++++++++++++++ test/unit/math/rev/core/save_varis_test.cpp | 33 ++++++++++++++++ 6 files changed, 134 insertions(+), 12 deletions(-) diff --git a/stan/math/rev/core/accumulate_adjoints.hpp b/stan/math/rev/core/accumulate_adjoints.hpp index 87d669f7aac..f046bc66941 100644 --- a/stan/math/rev/core/accumulate_adjoints.hpp +++ b/stan/math/rev/core/accumulate_adjoints.hpp @@ -6,7 +6,6 @@ #include #include -#include #include #include @@ -153,9 +152,17 @@ inline double* accumulate_adjoints(double* dest, Arith&& x, Pargs&&... args) { inline double* accumulate_adjoints(double* dest) { return dest; } /** - * Unpack a tuple and accumulate adjoints from each element. + * Accumulate adjoints from a tuple into storage pointed to by dest + * by unpacking the tuple and recursively processing each element. + * + * @tparam Tuple A std::tuple type + * @tparam Pargs Types of remaining arguments + * @param dest Pointer to where adjoints are to be accumulated + * @param x A tuple potentially containing vars + * @param args Further args to accumulate over + * @return Final position of adjoint storage pointer */ -template * = nullptr, typename... Pargs> +template *, typename... Pargs> inline double* accumulate_adjoints(double* dest, Tuple&& x, Pargs&&... args) { dest = stan::math::apply( [dest](auto&&... inner_args) { diff --git a/stan/math/rev/core/deep_copy_vars.hpp b/stan/math/rev/core/deep_copy_vars.hpp index 38ce91532e8..50e8c11f642 100644 --- a/stan/math/rev/core/deep_copy_vars.hpp +++ b/stan/math/rev/core/deep_copy_vars.hpp @@ -6,7 +6,6 @@ #include #include -#include #include #include @@ -84,8 +83,8 @@ inline auto deep_copy_vars(EigT&& arg) { } /** - * Copy the vars in a tuple but reallocate new varis for them. - * Non-var elements are forwarded unchanged. + * Deep copy vars in a tuple, reallocating new varis for var elements + * and forwarding non-var elements unchanged. * * @tparam Tuple A std::tuple type * @param arg A tuple potentially containing vars @@ -95,8 +94,8 @@ template * = nullptr> inline auto deep_copy_vars(Tuple&& arg) { return stan::math::apply( [](auto&&... args) { - return std::make_tuple(deep_copy_vars( - std::forward(args))...); + return std::make_tuple( + deep_copy_vars(std::forward(args))...); }, std::forward(arg)); } diff --git a/stan/math/rev/core/save_varis.hpp b/stan/math/rev/core/save_varis.hpp index 3c46c435be9..e0286639a53 100644 --- a/stan/math/rev/core/save_varis.hpp +++ b/stan/math/rev/core/save_varis.hpp @@ -7,7 +7,6 @@ #include #include -#include #include #include @@ -149,13 +148,22 @@ inline vari** save_varis(vari** dest, Arith&& x, Pargs&&... args) { inline vari** save_varis(vari** dest) { return dest; } /** - * Unpack a tuple and save the varis of each element. + * Save the vari pointers in a tuple into the memory pointed to by dest + * by unpacking the tuple and recursively processing each element. + * + * @tparam Tuple A std::tuple type + * @tparam Pargs Types of remaining arguments + * @param[in, out] dest Pointer to where vari pointers are saved + * @param[in] x A tuple potentially containing vars + * @param[in] args Additional arguments to have their varis saved + * @return Final position of dest pointer */ -template * = nullptr, typename... Pargs> +template *, typename... Pargs> inline vari** save_varis(vari** dest, Tuple&& x, Pargs&&... args) { dest = stan::math::apply( [dest](auto&&... inner_args) { - return save_varis(dest, std::forward(inner_args)...); + return save_varis( + dest, std::forward(inner_args)...); }, std::forward(x)); return save_varis(dest, std::forward(args)...); diff --git a/test/unit/math/rev/core/accumulate_adjoints_test.cpp b/test/unit/math/rev/core/accumulate_adjoints_test.cpp index e8017993f73..52faea0d7d7 100644 --- a/test/unit/math/rev/core/accumulate_adjoints_test.cpp +++ b/test/unit/math/rev/core/accumulate_adjoints_test.cpp @@ -381,6 +381,44 @@ TEST_F(AgradRev, Rev_accumulate_adjoints_std_vector_eigen_matrix_var_arg) { stan::math::recover_memory(); } +TEST_F(AgradRev, Rev_accumulate_adjoints_tuple_var_int_arg) { + using stan::math::var; + using stan::math::vari; + var a(5.0); + a.vi_->adj_ = 3.0; + int b = 7; + auto arg = std::make_tuple(a, b); + + Eigen::VectorXd storage = Eigen::VectorXd::Zero(1000); + double* ptr = stan::math::accumulate_adjoints(storage.data(), arg); + + EXPECT_FLOAT_EQ(storage(0), 3.0); + for (int i = 1; i < storage.size(); ++i) + EXPECT_FLOAT_EQ(storage(i), 0.0); + EXPECT_EQ(ptr, storage.data() + 1); + stan::math::recover_memory(); +} + +TEST_F(AgradRev, Rev_accumulate_adjoints_tuple_var_var_arg) { + using stan::math::var; + using stan::math::vari; + var a(5.0); + a.vi_->adj_ = 3.0; + var b(7.0); + b.vi_->adj_ = 4.0; + auto arg = std::make_tuple(a, b); + + Eigen::VectorXd storage = Eigen::VectorXd::Zero(1000); + double* ptr = stan::math::accumulate_adjoints(storage.data(), arg); + + EXPECT_FLOAT_EQ(storage(0), 3.0); + EXPECT_FLOAT_EQ(storage(1), 4.0); + for (int i = 2; i < storage.size(); ++i) + EXPECT_FLOAT_EQ(storage(i), 0.0); + EXPECT_EQ(ptr, storage.data() + 2); + stan::math::recover_memory(); +} + TEST_F(AgradRev, Rev_accumulate_adjoints_sum) { using stan::math::var; using stan::math::vari; diff --git a/test/unit/math/rev/core/deep_copy_vars_test.cpp b/test/unit/math/rev/core/deep_copy_vars_test.cpp index 99f78c9fb9c..6cba3a8134b 100644 --- a/test/unit/math/rev/core/deep_copy_vars_test.cpp +++ b/test/unit/math/rev/core/deep_copy_vars_test.cpp @@ -283,6 +283,43 @@ TEST_F(AgradRev, Rev_deep_copy_vars_std_vector_eigen_row_vector_var_arg) { } } +TEST_F(AgradRev, Rev_deep_copy_vars_tuple_var_int_arg) { + var a(3.0); + int b = 5; + auto arg = std::make_tuple(a, b); + + auto out = stan::math::deep_copy_vars(arg); + + EXPECT_EQ(std::get<0>(out).val(), a.val()); + EXPECT_NE(std::get<0>(out).vi_, a.vi_); + EXPECT_EQ(std::get<1>(out), b); +} + +TEST_F(AgradRev, Rev_deep_copy_vars_tuple_var_double_arg) { + var a(3.0); + double b = 5.0; + auto arg = std::make_tuple(a, b); + + auto out = stan::math::deep_copy_vars(arg); + + EXPECT_EQ(std::get<0>(out).val(), a.val()); + EXPECT_NE(std::get<0>(out).vi_, a.vi_); + EXPECT_EQ(std::get<1>(out), b); +} + +TEST_F(AgradRev, Rev_deep_copy_vars_tuple_var_var_arg) { + var a(3.0); + var b(7.0); + auto arg = std::make_tuple(a, b); + + auto out = stan::math::deep_copy_vars(arg); + + EXPECT_EQ(std::get<0>(out).val(), a.val()); + EXPECT_NE(std::get<0>(out).vi_, a.vi_); + EXPECT_EQ(std::get<1>(out).val(), b.val()); + EXPECT_NE(std::get<1>(out).vi_, b.vi_); +} + TEST_F(AgradRev, Rev_deep_copy_vars_std_vector_eigen_matrix_var_arg) { Eigen::Matrix arg_(5, 3); std::vector> arg(2, arg_); diff --git a/test/unit/math/rev/core/save_varis_test.cpp b/test/unit/math/rev/core/save_varis_test.cpp index 5f8a69ce0d9..110cc7d7d3d 100644 --- a/test/unit/math/rev/core/save_varis_test.cpp +++ b/test/unit/math/rev/core/save_varis_test.cpp @@ -332,6 +332,39 @@ TEST_F(AgradRev, Rev_save_varis_std_vector_eigen_matrix_var_arg) { EXPECT_EQ(ptr, storage.data() + num_vars); } +TEST_F(AgradRev, Rev_save_varis_tuple_var_int_arg) { + var a(5.0); + int b = 3; + auto arg = std::make_tuple(a, b); + + std::vector storage(1000, nullptr); + vari** ptr = stan::math::save_varis(storage.data(), arg); + + size_t num_vars = stan::math::count_vars(arg); + EXPECT_EQ(num_vars, 1); + EXPECT_EQ(storage[0], a.vi_); + for (int i = num_vars; i < storage.size(); ++i) + EXPECT_EQ(storage[i], nullptr); + EXPECT_EQ(ptr, storage.data() + num_vars); +} + +TEST_F(AgradRev, Rev_save_varis_tuple_var_var_arg) { + var a(5.0); + var b(7.0); + auto arg = std::make_tuple(a, b); + + std::vector storage(1000, nullptr); + vari** ptr = stan::math::save_varis(storage.data(), arg); + + size_t num_vars = stan::math::count_vars(arg); + EXPECT_EQ(num_vars, 2); + EXPECT_EQ(storage[0], a.vi_); + EXPECT_EQ(storage[1], b.vi_); + for (int i = num_vars; i < storage.size(); ++i) + EXPECT_EQ(storage[i], nullptr); + EXPECT_EQ(ptr, storage.data() + num_vars); +} + TEST_F(AgradRev, Rev_save_varis_sum) { int arg1 = 1; double arg2 = 1.0; From 55484370849226e7703274588cb5eaf9a6716baa Mon Sep 17 00:00:00 2001 From: Nikolas Siccha Date: Wed, 25 Mar 2026 12:08:18 +0100 Subject: [PATCH 7/9] Clean up MWE --- mwe/.env-main/Manifest.toml | 97 ---------------- mwe/.env-main/Project.toml | 2 - mwe/.env-worktree/Manifest.toml | 97 ---------------- mwe/.env-worktree/Project.toml | 2 - mwe/Project.toml | 2 - mwe/mwe.jl | 54 --------- mwe/mwe.main.out | 193 -------------------------------- mwe/mwe.worktree.out | 193 -------------------------------- 8 files changed, 640 deletions(-) delete mode 100644 mwe/.env-main/Manifest.toml delete mode 100644 mwe/.env-main/Project.toml delete mode 100644 mwe/.env-worktree/Manifest.toml delete mode 100644 mwe/.env-worktree/Project.toml delete mode 100644 mwe/Project.toml delete mode 100644 mwe/mwe.jl delete mode 100644 mwe/mwe.main.out delete mode 100644 mwe/mwe.worktree.out diff --git a/mwe/.env-main/Manifest.toml b/mwe/.env-main/Manifest.toml deleted file mode 100644 index bb76e196de7..00000000000 --- a/mwe/.env-main/Manifest.toml +++ /dev/null @@ -1,97 +0,0 @@ -# This file is machine-generated - editing it directly is not advised - -julia_version = "1.10.11" -manifest_format = "2.0" -project_hash = "5578dd2aac58cda5d4cf32fe876f733701deb830" - -[[deps.ArgTools]] -uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" -version = "1.1.1" - -[[deps.Artifacts]] -uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" - -[[deps.BridgeStan]] -deps = ["Downloads", "Inflate", "TOML", "Tar"] -git-tree-sha1 = "f8689ac4ce3245df7a436889988762a6c4a9da12" -uuid = "c88b6f0a-829e-4b0b-94b7-f06ab5908f5a" -version = "2.7.0" - -[[deps.Dates]] -deps = ["Printf"] -uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" - -[[deps.Downloads]] -deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"] -uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6" -version = "1.6.0" - -[[deps.FileWatching]] -uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee" - -[[deps.Inflate]] -git-tree-sha1 = "d1b1b796e47d94588b3757fe84fbf65a5ec4a80d" -uuid = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9" -version = "0.1.5" - -[[deps.LibCURL]] -deps = ["LibCURL_jll", "MozillaCACerts_jll"] -uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" -version = "0.6.4" - -[[deps.LibCURL_jll]] -deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"] -uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0" -version = "8.4.0+0" - -[[deps.LibSSH2_jll]] -deps = ["Artifacts", "Libdl", "MbedTLS_jll"] -uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8" -version = "1.11.0+1" - -[[deps.Libdl]] -uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" - -[[deps.MbedTLS_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" -version = "2.28.1010+0" - -[[deps.MozillaCACerts_jll]] -uuid = "14a3606d-f60d-562e-9121-12d972cd8159" -version = "2025.12.2" - -[[deps.NetworkOptions]] -uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" -version = "1.2.0" - -[[deps.Printf]] -deps = ["Unicode"] -uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" - -[[deps.SHA]] -uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" -version = "0.7.0" - -[[deps.TOML]] -deps = ["Dates"] -uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" -version = "1.0.3" - -[[deps.Tar]] -deps = ["ArgTools", "SHA"] -uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" -version = "1.10.0" - -[[deps.Unicode]] -uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" - -[[deps.Zlib_jll]] -deps = ["Libdl"] -uuid = "83775a58-1f1d-513f-b197-d71354ab007a" -version = "1.2.13+1" - -[[deps.nghttp2_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d" -version = "1.52.0+1" diff --git a/mwe/.env-main/Project.toml b/mwe/.env-main/Project.toml deleted file mode 100644 index bdf49f9a5ef..00000000000 --- a/mwe/.env-main/Project.toml +++ /dev/null @@ -1,2 +0,0 @@ -[deps] -BridgeStan = "c88b6f0a-829e-4b0b-94b7-f06ab5908f5a" diff --git a/mwe/.env-worktree/Manifest.toml b/mwe/.env-worktree/Manifest.toml deleted file mode 100644 index bb76e196de7..00000000000 --- a/mwe/.env-worktree/Manifest.toml +++ /dev/null @@ -1,97 +0,0 @@ -# This file is machine-generated - editing it directly is not advised - -julia_version = "1.10.11" -manifest_format = "2.0" -project_hash = "5578dd2aac58cda5d4cf32fe876f733701deb830" - -[[deps.ArgTools]] -uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" -version = "1.1.1" - -[[deps.Artifacts]] -uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" - -[[deps.BridgeStan]] -deps = ["Downloads", "Inflate", "TOML", "Tar"] -git-tree-sha1 = "f8689ac4ce3245df7a436889988762a6c4a9da12" -uuid = "c88b6f0a-829e-4b0b-94b7-f06ab5908f5a" -version = "2.7.0" - -[[deps.Dates]] -deps = ["Printf"] -uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" - -[[deps.Downloads]] -deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"] -uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6" -version = "1.6.0" - -[[deps.FileWatching]] -uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee" - -[[deps.Inflate]] -git-tree-sha1 = "d1b1b796e47d94588b3757fe84fbf65a5ec4a80d" -uuid = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9" -version = "0.1.5" - -[[deps.LibCURL]] -deps = ["LibCURL_jll", "MozillaCACerts_jll"] -uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" -version = "0.6.4" - -[[deps.LibCURL_jll]] -deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"] -uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0" -version = "8.4.0+0" - -[[deps.LibSSH2_jll]] -deps = ["Artifacts", "Libdl", "MbedTLS_jll"] -uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8" -version = "1.11.0+1" - -[[deps.Libdl]] -uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" - -[[deps.MbedTLS_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" -version = "2.28.1010+0" - -[[deps.MozillaCACerts_jll]] -uuid = "14a3606d-f60d-562e-9121-12d972cd8159" -version = "2025.12.2" - -[[deps.NetworkOptions]] -uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" -version = "1.2.0" - -[[deps.Printf]] -deps = ["Unicode"] -uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" - -[[deps.SHA]] -uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" -version = "0.7.0" - -[[deps.TOML]] -deps = ["Dates"] -uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" -version = "1.0.3" - -[[deps.Tar]] -deps = ["ArgTools", "SHA"] -uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" -version = "1.10.0" - -[[deps.Unicode]] -uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" - -[[deps.Zlib_jll]] -deps = ["Libdl"] -uuid = "83775a58-1f1d-513f-b197-d71354ab007a" -version = "1.2.13+1" - -[[deps.nghttp2_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d" -version = "1.52.0+1" diff --git a/mwe/.env-worktree/Project.toml b/mwe/.env-worktree/Project.toml deleted file mode 100644 index bdf49f9a5ef..00000000000 --- a/mwe/.env-worktree/Project.toml +++ /dev/null @@ -1,2 +0,0 @@ -[deps] -BridgeStan = "c88b6f0a-829e-4b0b-94b7-f06ab5908f5a" diff --git a/mwe/Project.toml b/mwe/Project.toml deleted file mode 100644 index bdf49f9a5ef..00000000000 --- a/mwe/Project.toml +++ /dev/null @@ -1,2 +0,0 @@ -[deps] -BridgeStan = "c88b6f0a-829e-4b0b-94b7-f06ab5908f5a" diff --git a/mwe/mwe.jl b/mwe/mwe.jl deleted file mode 100644 index b2ab7ea189d..00000000000 --- a/mwe/mwe.jl +++ /dev/null @@ -1,54 +0,0 @@ -using BridgeStan - -stan_code = """ -functions { - real partial_sum(array[] real slice, int start, int end, - tuple(real, int) params) { - real mu = params.1; - int K = params.2; - real lp = 0; - for (i in 1:size(slice)) { - lp += normal_lpdf(slice[i] | mu, K); - } - return lp; - } -} -data { - int N; - int K; - array[N] real y; -} -parameters { - real mu; -} -model { - mu ~ normal(0, 10); - target += reduce_sum(partial_sum, y, 1, (mu, K)); -} -""" - -stan_math = ENV["MWE_RUN_DIR"] -label = ENV["MWE_LABEL"] - -workdir = mktempdir() -stan_file = joinpath(workdir, "mwe.stan") -write(stan_file, stan_code) - -lib = compile_model(stan_file; make_args=["MATH=$stan_math/", "STAN_THREADS=true"]) - -data = """{"N": 5, "K": 2, "y": [1.0, 2.0, 3.0, 4.0, 5.0]}""" -sm = StanModel(lib, data) - -params = [3.0] # mu (unconstrained) -lp = log_density(sm, params) -lp_grad, grad = log_density_gradient(sm, params) - -println("[$label] log_density = $lp") -println("[$label] gradient = $grad") - -@assert isfinite(lp) "log_density should be finite" -@assert all(isfinite, grad) "gradient should be finite" -@assert lp ≈ lp_grad "log_density values should match" -@assert length(grad) == 1 "gradient should have 1 element" - -println("[$label] All checks passed!") diff --git a/mwe/mwe.main.out b/mwe/mwe.main.out deleted file mode 100644 index 31cdfa652f9..00000000000 --- a/mwe/mwe.main.out +++ /dev/null @@ -1,193 +0,0 @@ -# MWE: mwe.jl on main -# started: 2026-03-25 11:14:04 -# dir: /home/niko/github/stan-dev/math -# project: /home/niko/github/issues/stan-dev-math/worktrees/3041-map-tuple/mwe/.env-main ---- -==> Pkg.instantiate() -==> Running mwe.jl -ERROR: LoadError: Compilation failed! -Command: setenv(`make STAN_MATH=/home/niko/github/stan-dev/math STAN_THREADS=true /tmp/jl_aYanbD/mwe_model.so`; dir="/home/niko/.bridgestan/bridgestan-2.7.0") -stdout: ---- Translating Stan model to C++ code --- -./bin/stanc --o=/tmp/jl_aYanbD/mwe.hpp /tmp/jl_aYanbD/mwe.stan - ---- Compiling C++ code --- -g++ -std=c++17 -pthread -D_REENTRANT -Wno-sign-compare -Wno-ignored-attributes -Wno-class-memaccess -DSTAN_THREADS -I ./stan/lib/stan_math/lib/tbb_2020.3/include -O3 -I ./stan/src -I ./stan/lib/rapidjson_1.1.0/ -I ./stan/lib/stan_math/ -I ./stan/lib/stan_math/lib/eigen_3.4.0 -I ./stan/lib/stan_math/lib/boost_1.87.0 -I ./stan/lib/stan_math/lib/sundials_6.1.1/include -I ./stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -DBOOST_DISABLE_ASSERTS -DBRIDGESTAN_EXPORT -DSTAN_OVERRIDE_EIGEN_ASSERT -c -x c++ -o /tmp/jl_aYanbD/mwe.o /tmp/jl_aYanbD/mwe.hpp -rm /tmp/jl_aYanbD/mwe.hpp - -stderr: In file included from ./stan/lib/stan_math/stan/math/rev/functor.hpp:30, - from ./stan/lib/stan_math/stan/math/rev.hpp:15, - from ./stan/lib/stan_math/stan/math.hpp:19, - from ./stan/src/stan/model/model_header.hpp:6, - from /tmp/jl_aYanbD/mwe.hpp:2: -./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp: In instantiation of ‘stan::math::var stan::math::internal::reduce_sum_impl::type>::value, void>::type, ReturnType, Vec, Args ...>::operator()(Vec&&, bool, int, std::ostream*, Args&& ...) const [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; ReturnType = stan::math::var_value; Vec = const std::vector&; Args = {std::tuple&, const int&>}; typename std::enable_if::type>::value, void>::type = void; typename std::decay<_Tp2>::type = std::decay >::type; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’: -./stan/lib/stan_math/stan/math/prim/functor/reduce_sum.hpp:208:60: required from ‘auto stan::math::reduce_sum(Vec&&, int, std::ostream*, Args&& ...) [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; Vec = const std::vector&; = void; Args = {std::tuple&, const int&>}; std::ostream = std::basic_ostream]’ -/tmp/jl_aYanbD/mwe.hpp:252:71: required from ‘stan::scalar_type_t mwe_model_namespace::mwe_model::log_prob_impl(VecR&, VecI&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; VecR = Eigen::Matrix, -1, 1>; VecI = Eigen::Matrix; stan::require_vector_like_t* = 0; stan::require_vector_like_vt* = 0; stan::require_st_var* = 0; stan::scalar_type_t = stan::math::var_value; std::ostream = std::basic_ostream]’ -/tmp/jl_aYanbD/mwe.hpp:434:47: required from ‘T_ mwe_model_namespace::mwe_model::log_prob(Eigen::Matrix&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; T_ = stan::math::var_value; std::ostream = std::basic_ostream]’ -./stan/src/stan/model/model_base_crtp.hpp:98:72: required from ‘stan::math::var stan::model::model_base_crtp::log_prob(Eigen::Matrix, -1, 1>&, std::ostream*) const [with M = mwe_model_namespace::mwe_model; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ -./stan/src/stan/model/model_base_crtp.hpp:96:20: required from here -./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:241:15: error: no matching function for call to ‘save_varis(stan::math::vari**, std::tuple&, const int&>&)’ - 241 | save_varis(varis + num_vars_sliced_terms, args...); - | ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -In file included from ./stan/lib/stan_math/stan/math/rev/core.hpp:76, - from ./stan/src/stan/model/model_base.hpp:8, - from ./stan/src/stan/model/model_header.hpp:4, - from /tmp/jl_aYanbD/mwe.hpp:2: -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:51:15: note: candidate: ‘template stan::math::vari** stan::math::save_varis(stan::math::vari**, const var&, Pargs&& ...)’ - 51 | inline vari** save_varis(vari** dest, const var& x, Pargs&&... args) { - | ^~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:51:15: note: template argument deduction/substitution failed: -In file included from ./stan/lib/stan_math/stan/math/rev/functor.hpp:30, - from ./stan/lib/stan_math/stan/math/rev.hpp:15, - from ./stan/lib/stan_math/stan/math.hpp:19, - from ./stan/src/stan/model/model_header.hpp:6, - from /tmp/jl_aYanbD/mwe.hpp:2: -./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:241:15: note: cannot convert ‘args#0’ (type ‘std::tuple&, const int&>’) to type ‘const var&’ {aka ‘const stan::math::var_value&’} - 241 | save_varis(varis + num_vars_sliced_terms, args...); - | ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -In file included from ./stan/lib/stan_math/stan/math/rev/core.hpp:76, - from ./stan/src/stan/model/model_base.hpp:8, - from ./stan/src/stan/model/model_header.hpp:4, - from /tmp/jl_aYanbD/mwe.hpp:2: -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:71:15: note: candidate: ‘template* , class ... Pargs> stan::math::vari** stan::math::save_varis(stan::math::vari**, VarVec&&, Pargs&& ...)’ - 71 | inline vari** save_varis(vari** dest, VarVec&& x, Pargs&&... args) { - | ^~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:71:15: note: template argument deduction/substitution failed: -In file included from /usr/include/c++/11/bits/move.h:57, - from /usr/include/c++/11/bits/exception_ptr.h:43, - from /usr/include/c++/11/exception:153, - from /usr/include/c++/11/ios:39, - from /usr/include/c++/11/istream:38, - from /usr/include/c++/11/sstream:38, - from ./stan/src/stan/io/var_context.hpp:4, - from ./stan/src/stan/model/model_base.hpp:7, - from ./stan/src/stan/model/model_header.hpp:4, - from /tmp/jl_aYanbD/mwe.hpp:2: -/usr/include/c++/11/type_traits: In substitution of ‘template using enable_if_t = typename std::enable_if::type [with bool _Cond = false; _Tp = void]’: -./stan/lib/stan_math/stan/math/prim/meta/require_helpers.hpp:19:7: required by substitution of ‘template using require_t = std::enable_if_t [with Check = std::integral_constant]’ -./stan/lib/stan_math/stan/math/prim/meta/is_vector.hpp:677:7: required by substitution of ‘template class TypeCheck, class ... Check> using require_std_vector_vt = stan::require_t > [with TypeCheck = stan::is_var; Check = {std::tuple&, const int&>&}]’ -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:18:69: required from ‘stan::math::var stan::math::internal::reduce_sum_impl::type>::value, void>::type, ReturnType, Vec, Args ...>::operator()(Vec&&, bool, int, std::ostream*, Args&& ...) const [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; ReturnType = stan::math::var_value; Vec = const std::vector&; Args = {std::tuple&, const int&>}; typename std::enable_if::type>::value, void>::type = void; typename std::decay<_Tp2>::type = std::decay >::type; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ -./stan/lib/stan_math/stan/math/prim/functor/reduce_sum.hpp:208:60: required from ‘auto stan::math::reduce_sum(Vec&&, int, std::ostream*, Args&& ...) [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; Vec = const std::vector&; = void; Args = {std::tuple&, const int&>}; std::ostream = std::basic_ostream]’ -/tmp/jl_aYanbD/mwe.hpp:252:71: required from ‘stan::scalar_type_t mwe_model_namespace::mwe_model::log_prob_impl(VecR&, VecI&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; VecR = Eigen::Matrix, -1, 1>; VecI = Eigen::Matrix; stan::require_vector_like_t* = 0; stan::require_vector_like_vt* = 0; stan::require_st_var* = 0; stan::scalar_type_t = stan::math::var_value; std::ostream = std::basic_ostream]’ -/tmp/jl_aYanbD/mwe.hpp:434:47: required from ‘T_ mwe_model_namespace::mwe_model::log_prob(Eigen::Matrix&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; T_ = stan::math::var_value; std::ostream = std::basic_ostream]’ -./stan/src/stan/model/model_base_crtp.hpp:98:72: required from ‘stan::math::var stan::model::model_base_crtp::log_prob(Eigen::Matrix, -1, 1>&, std::ostream*) const [with M = mwe_model_namespace::mwe_model; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ -./stan/src/stan/model/model_base_crtp.hpp:96:20: required from here -/usr/include/c++/11/type_traits:2579:11: error: no type named ‘type’ in ‘struct std::enable_if’ - 2579 | using enable_if_t = typename enable_if<_Cond, _Tp>::type; - | ^~~~~~~~~~~ -In file included from ./stan/lib/stan_math/stan/math/rev/core.hpp:76, - from ./stan/src/stan/model/model_base.hpp:8, - from ./stan/src/stan/model/model_header.hpp:4, - from /tmp/jl_aYanbD/mwe.hpp:2: -./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp: In instantiation of ‘stan::math::var stan::math::internal::reduce_sum_impl::type>::value, void>::type, ReturnType, Vec, Args ...>::operator()(Vec&&, bool, int, std::ostream*, Args&& ...) const [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; ReturnType = stan::math::var_value; Vec = const std::vector&; Args = {std::tuple&, const int&>}; typename std::enable_if::type>::value, void>::type = void; typename std::decay<_Tp2>::type = std::decay >::type; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’: -./stan/lib/stan_math/stan/math/prim/functor/reduce_sum.hpp:208:60: required from ‘auto stan::math::reduce_sum(Vec&&, int, std::ostream*, Args&& ...) [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; Vec = const std::vector&; = void; Args = {std::tuple&, const int&>}; std::ostream = std::basic_ostream]’ -/tmp/jl_aYanbD/mwe.hpp:252:71: required from ‘stan::scalar_type_t mwe_model_namespace::mwe_model::log_prob_impl(VecR&, VecI&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; VecR = Eigen::Matrix, -1, 1>; VecI = Eigen::Matrix; stan::require_vector_like_t* = 0; stan::require_vector_like_vt* = 0; stan::require_st_var* = 0; stan::scalar_type_t = stan::math::var_value; std::ostream = std::basic_ostream]’ -/tmp/jl_aYanbD/mwe.hpp:434:47: required from ‘T_ mwe_model_namespace::mwe_model::log_prob(Eigen::Matrix&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; T_ = stan::math::var_value; std::ostream = std::basic_ostream]’ -./stan/src/stan/model/model_base_crtp.hpp:98:72: required from ‘stan::math::var stan::model::model_base_crtp::log_prob(Eigen::Matrix, -1, 1>&, std::ostream*) const [with M = mwe_model_namespace::mwe_model; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ -./stan/src/stan/model/model_base_crtp.hpp:96:20: required from here -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:93:15: note: candidate: ‘template* , stan::require_std_vector_vt* , class ... Pargs> stan::math::vari** stan::math::save_varis(stan::math::vari**, VecContainer&&, Pargs&& ...)’ - 93 | inline vari** save_varis(vari** dest, VecContainer&& x, Pargs&&... args) { - | ^~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:93:15: note: template argument deduction/substitution failed: -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:114:15: note: candidate: ‘template* , class ... Pargs> stan::math::vari** stan::math::save_varis(stan::math::vari**, EigT&&, Pargs&& ...)’ - 114 | inline vari** save_varis(vari** dest, EigT&& x, Pargs&&... args) { - | ^~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:114:15: note: template argument deduction/substitution failed: -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:135:15: note: candidate: ‘template* , class ... Pargs> stan::math::vari** stan::math::save_varis(stan::math::vari**, Arith&&, Pargs&& ...)’ - 135 | inline vari** save_varis(vari** dest, Arith&& x, Pargs&&... args) { - | ^~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:135:15: note: template argument deduction/substitution failed: -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:144:15: note: candidate: ‘stan::math::vari** stan::math::save_varis(stan::math::vari**)’ - 144 | inline vari** save_varis(vari** dest) { return dest; } - | ^~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:144:15: note: candidate expects 1 argument, 2 provided -In file included from ./stan/lib/stan_math/stan/math/rev/functor.hpp:30, - from ./stan/lib/stan_math/stan/math/rev.hpp:15, - from ./stan/lib/stan_math/stan/math.hpp:19, - from ./stan/src/stan/model/model_header.hpp:6, - from /tmp/jl_aYanbD/mwe.hpp:2: -./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp: In instantiation of ‘struct stan::math::internal::reduce_sum_impl, const std::vector&, std::tuple&, const int&> >::scoped_args_tuple’: -./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:58:23: required from ‘struct stan::math::internal::reduce_sum_impl, const std::vector&, std::tuple&, const int&> >::recursive_reducer’ -./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:247:23: required from ‘stan::math::var stan::math::internal::reduce_sum_impl::type>::value, void>::type, ReturnType, Vec, Args ...>::operator()(Vec&&, bool, int, std::ostream*, Args&& ...) const [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; ReturnType = stan::math::var_value; Vec = const std::vector&; Args = {std::tuple&, const int&>}; typename std::enable_if::type>::value, void>::type = void; typename std::decay<_Tp2>::type = std::decay >::type; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ -./stan/lib/stan_math/stan/math/prim/functor/reduce_sum.hpp:208:60: required from ‘auto stan::math::reduce_sum(Vec&&, int, std::ostream*, Args&& ...) [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; Vec = const std::vector&; = void; Args = {std::tuple&, const int&>}; std::ostream = std::basic_ostream]’ -/tmp/jl_aYanbD/mwe.hpp:252:71: required from ‘stan::scalar_type_t mwe_model_namespace::mwe_model::log_prob_impl(VecR&, VecI&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; VecR = Eigen::Matrix, -1, 1>; VecI = Eigen::Matrix; stan::require_vector_like_t* = 0; stan::require_vector_like_vt* = 0; stan::require_st_var* = 0; stan::scalar_type_t = stan::math::var_value; std::ostream = std::basic_ostream]’ -/tmp/jl_aYanbD/mwe.hpp:434:47: required from ‘T_ mwe_model_namespace::mwe_model::log_prob(Eigen::Matrix&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; T_ = stan::math::var_value; std::ostream = std::basic_ostream]’ -./stan/src/stan/model/model_base_crtp.hpp:98:72: required from ‘stan::math::var stan::model::model_base_crtp::log_prob(Eigen::Matrix, -1, 1>&, std::ostream*) const [with M = mwe_model_namespace::mwe_model; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ -./stan/src/stan/model/model_base_crtp.hpp:96:20: required from here -./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:36:45: error: no matching function for call to ‘deep_copy_vars(std::tuple&, const int&>)’ - 36 | = std::tuple()))...>; - | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ -In file included from ./stan/lib/stan_math/stan/math/rev/core.hpp:17, - from ./stan/src/stan/model/model_base.hpp:8, - from ./stan/src/stan/model/model_header.hpp:4, - from /tmp/jl_aYanbD/mwe.hpp:2: -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:23:14: note: candidate: ‘template Arith stan::math::deep_copy_vars(Arith&&)’ - 23 | inline Arith deep_copy_vars(Arith&& arg) { - | ^~~~~~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:23:14: note: template argument deduction/substitution failed: -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:45:13: note: candidate: ‘template* > auto stan::math::deep_copy_vars(VarVec&&)’ - 45 | inline auto deep_copy_vars(VarVec&& arg) { - | ^~~~~~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:45:13: note: template argument deduction/substitution failed: -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:63:13: note: candidate: ‘template* , stan::require_std_vector_vt* > auto stan::math::deep_copy_vars(VecContainer&&)’ - 63 | inline auto deep_copy_vars(VecContainer&& arg) { - | ^~~~~~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:63:13: note: template argument deduction/substitution failed: -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:79:13: note: candidate: ‘template* > auto stan::math::deep_copy_vars(EigT&&)’ - 79 | inline auto deep_copy_vars(EigT&& arg) { - | ^~~~~~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:79:13: note: template argument deduction/substitution failed: -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:33:13: note: candidate: ‘auto stan::math::deep_copy_vars(const var&)’ - 33 | inline auto deep_copy_vars(const var& arg) { - | ^~~~~~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:33:39: note: no known conversion for argument 1 from ‘std::tuple&, const int&>’ to ‘const var&’ {aka ‘const stan::math::var_value&’} - 33 | inline auto deep_copy_vars(const var& arg) { - | ~~~~~~~~~~~^~~ -In file included from ./stan/lib/stan_math/stan/math/rev/functor.hpp:30, - from ./stan/lib/stan_math/stan/math/rev.hpp:15, - from ./stan/lib/stan_math/stan/math.hpp:19, - from ./stan/src/stan/model/model_header.hpp:6, - from /tmp/jl_aYanbD/mwe.hpp:2: -./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:36:45: error: no matching function for call to ‘deep_copy_vars(std::tuple&, const int&>)’ - 36 | = std::tuple()))...>; - | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ -In file included from ./stan/lib/stan_math/stan/math/rev/core.hpp:17, - from ./stan/src/stan/model/model_base.hpp:8, - from ./stan/src/stan/model/model_header.hpp:4, - from /tmp/jl_aYanbD/mwe.hpp:2: -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:23:14: note: candidate: ‘template Arith stan::math::deep_copy_vars(Arith&&)’ - 23 | inline Arith deep_copy_vars(Arith&& arg) { - | ^~~~~~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:23:14: note: template argument deduction/substitution failed: -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:45:13: note: candidate: ‘template* > auto stan::math::deep_copy_vars(VarVec&&)’ - 45 | inline auto deep_copy_vars(VarVec&& arg) { - | ^~~~~~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:45:13: note: template argument deduction/substitution failed: -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:63:13: note: candidate: ‘template* , stan::require_std_vector_vt* > auto stan::math::deep_copy_vars(VecContainer&&)’ - 63 | inline auto deep_copy_vars(VecContainer&& arg) { - | ^~~~~~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:63:13: note: template argument deduction/substitution failed: -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:79:13: note: candidate: ‘template* > auto stan::math::deep_copy_vars(EigT&&)’ - 79 | inline auto deep_copy_vars(EigT&& arg) { - | ^~~~~~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:79:13: note: template argument deduction/substitution failed: -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:33:13: note: candidate: ‘auto stan::math::deep_copy_vars(const var&)’ - 33 | inline auto deep_copy_vars(const var& arg) { - | ^~~~~~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:33:39: note: no known conversion for argument 1 from ‘std::tuple&, const int&>’ to ‘const var&’ {aka ‘const stan::math::var_value&’} - 33 | inline auto deep_copy_vars(const var& arg) { - | ~~~~~~~~~~~^~~ -make: *** [Makefile:77: /tmp/jl_aYanbD/mwe.o] Error 1 - -Stacktrace: - [1] error(s::String) - @ Base ./error.jl:35 - [2] compile_model(stan_file::String; stanc_args::Vector{String}, make_args::Vector{String}) - @ BridgeStan ~/.julia/packages/BridgeStan/Bodre/src/compile.jl:114 - [3] top-level scope - @ ~/github/issues/stan-dev-math/worktrees/3041-map-tuple/mwe/mwe.jl:37 -in expression starting at /home/niko/github/issues/stan-dev-math/worktrees/3041-map-tuple/mwe/mwe.jl:37 - -# exit_code: 1 -# status: FAIL -# finished: 2026-03-25 11:14:22 diff --git a/mwe/mwe.worktree.out b/mwe/mwe.worktree.out deleted file mode 100644 index a969001e1a5..00000000000 --- a/mwe/mwe.worktree.out +++ /dev/null @@ -1,193 +0,0 @@ -# MWE: mwe.jl on worktree -# started: 2026-03-25 11:14:04 -# dir: /home/niko/github/issues/stan-dev-math/worktrees/3041-map-tuple -# project: /home/niko/github/issues/stan-dev-math/worktrees/3041-map-tuple/mwe/.env-worktree ---- -==> Pkg.instantiate() -==> Running mwe.jl -ERROR: LoadError: Compilation failed! -Command: setenv(`make STAN_MATH=/home/niko/github/issues/stan-dev-math/worktrees/3041-map-tuple STAN_THREADS=true /tmp/jl_QQmvi1/mwe_model.so`; dir="/home/niko/.bridgestan/bridgestan-2.7.0") -stdout: ---- Translating Stan model to C++ code --- -./bin/stanc --o=/tmp/jl_QQmvi1/mwe.hpp /tmp/jl_QQmvi1/mwe.stan - ---- Compiling C++ code --- -g++ -std=c++17 -pthread -D_REENTRANT -Wno-sign-compare -Wno-ignored-attributes -Wno-class-memaccess -DSTAN_THREADS -I ./stan/lib/stan_math/lib/tbb_2020.3/include -O3 -I ./stan/src -I ./stan/lib/rapidjson_1.1.0/ -I ./stan/lib/stan_math/ -I ./stan/lib/stan_math/lib/eigen_3.4.0 -I ./stan/lib/stan_math/lib/boost_1.87.0 -I ./stan/lib/stan_math/lib/sundials_6.1.1/include -I ./stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -DBOOST_DISABLE_ASSERTS -DBRIDGESTAN_EXPORT -DSTAN_OVERRIDE_EIGEN_ASSERT -c -x c++ -o /tmp/jl_QQmvi1/mwe.o /tmp/jl_QQmvi1/mwe.hpp -rm /tmp/jl_QQmvi1/mwe.hpp - -stderr: In file included from ./stan/lib/stan_math/stan/math/rev/functor.hpp:30, - from ./stan/lib/stan_math/stan/math/rev.hpp:15, - from ./stan/lib/stan_math/stan/math.hpp:19, - from ./stan/src/stan/model/model_header.hpp:6, - from /tmp/jl_QQmvi1/mwe.hpp:2: -./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp: In instantiation of ‘stan::math::var stan::math::internal::reduce_sum_impl::type>::value, void>::type, ReturnType, Vec, Args ...>::operator()(Vec&&, bool, int, std::ostream*, Args&& ...) const [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; ReturnType = stan::math::var_value; Vec = const std::vector&; Args = {std::tuple&, const int&>}; typename std::enable_if::type>::value, void>::type = void; typename std::decay<_Tp2>::type = std::decay >::type; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’: -./stan/lib/stan_math/stan/math/prim/functor/reduce_sum.hpp:208:60: required from ‘auto stan::math::reduce_sum(Vec&&, int, std::ostream*, Args&& ...) [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; Vec = const std::vector&; = void; Args = {std::tuple&, const int&>}; std::ostream = std::basic_ostream]’ -/tmp/jl_QQmvi1/mwe.hpp:252:71: required from ‘stan::scalar_type_t mwe_model_namespace::mwe_model::log_prob_impl(VecR&, VecI&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; VecR = Eigen::Matrix, -1, 1>; VecI = Eigen::Matrix; stan::require_vector_like_t* = 0; stan::require_vector_like_vt* = 0; stan::require_st_var* = 0; stan::scalar_type_t = stan::math::var_value; std::ostream = std::basic_ostream]’ -/tmp/jl_QQmvi1/mwe.hpp:434:47: required from ‘T_ mwe_model_namespace::mwe_model::log_prob(Eigen::Matrix&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; T_ = stan::math::var_value; std::ostream = std::basic_ostream]’ -./stan/src/stan/model/model_base_crtp.hpp:98:72: required from ‘stan::math::var stan::model::model_base_crtp::log_prob(Eigen::Matrix, -1, 1>&, std::ostream*) const [with M = mwe_model_namespace::mwe_model; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ -./stan/src/stan/model/model_base_crtp.hpp:96:20: required from here -./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:241:15: error: no matching function for call to ‘save_varis(stan::math::vari**, std::tuple&, const int&>&)’ - 241 | save_varis(varis + num_vars_sliced_terms, args...); - | ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -In file included from ./stan/lib/stan_math/stan/math/rev/core.hpp:76, - from ./stan/src/stan/model/model_base.hpp:8, - from ./stan/src/stan/model/model_header.hpp:4, - from /tmp/jl_QQmvi1/mwe.hpp:2: -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:51:15: note: candidate: ‘template stan::math::vari** stan::math::save_varis(stan::math::vari**, const var&, Pargs&& ...)’ - 51 | inline vari** save_varis(vari** dest, const var& x, Pargs&&... args) { - | ^~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:51:15: note: template argument deduction/substitution failed: -In file included from ./stan/lib/stan_math/stan/math/rev/functor.hpp:30, - from ./stan/lib/stan_math/stan/math/rev.hpp:15, - from ./stan/lib/stan_math/stan/math.hpp:19, - from ./stan/src/stan/model/model_header.hpp:6, - from /tmp/jl_QQmvi1/mwe.hpp:2: -./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:241:15: note: cannot convert ‘args#0’ (type ‘std::tuple&, const int&>’) to type ‘const var&’ {aka ‘const stan::math::var_value&’} - 241 | save_varis(varis + num_vars_sliced_terms, args...); - | ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -In file included from ./stan/lib/stan_math/stan/math/rev/core.hpp:76, - from ./stan/src/stan/model/model_base.hpp:8, - from ./stan/src/stan/model/model_header.hpp:4, - from /tmp/jl_QQmvi1/mwe.hpp:2: -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:71:15: note: candidate: ‘template* , class ... Pargs> stan::math::vari** stan::math::save_varis(stan::math::vari**, VarVec&&, Pargs&& ...)’ - 71 | inline vari** save_varis(vari** dest, VarVec&& x, Pargs&&... args) { - | ^~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:71:15: note: template argument deduction/substitution failed: -In file included from /usr/include/c++/11/bits/move.h:57, - from /usr/include/c++/11/bits/exception_ptr.h:43, - from /usr/include/c++/11/exception:153, - from /usr/include/c++/11/ios:39, - from /usr/include/c++/11/istream:38, - from /usr/include/c++/11/sstream:38, - from ./stan/src/stan/io/var_context.hpp:4, - from ./stan/src/stan/model/model_base.hpp:7, - from ./stan/src/stan/model/model_header.hpp:4, - from /tmp/jl_QQmvi1/mwe.hpp:2: -/usr/include/c++/11/type_traits: In substitution of ‘template using enable_if_t = typename std::enable_if::type [with bool _Cond = false; _Tp = void]’: -./stan/lib/stan_math/stan/math/prim/meta/require_helpers.hpp:19:7: required by substitution of ‘template using require_t = std::enable_if_t [with Check = std::integral_constant]’ -./stan/lib/stan_math/stan/math/prim/meta/is_vector.hpp:677:7: required by substitution of ‘template class TypeCheck, class ... Check> using require_std_vector_vt = stan::require_t > [with TypeCheck = stan::is_var; Check = {std::tuple&, const int&>&}]’ -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:18:69: required from ‘stan::math::var stan::math::internal::reduce_sum_impl::type>::value, void>::type, ReturnType, Vec, Args ...>::operator()(Vec&&, bool, int, std::ostream*, Args&& ...) const [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; ReturnType = stan::math::var_value; Vec = const std::vector&; Args = {std::tuple&, const int&>}; typename std::enable_if::type>::value, void>::type = void; typename std::decay<_Tp2>::type = std::decay >::type; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ -./stan/lib/stan_math/stan/math/prim/functor/reduce_sum.hpp:208:60: required from ‘auto stan::math::reduce_sum(Vec&&, int, std::ostream*, Args&& ...) [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; Vec = const std::vector&; = void; Args = {std::tuple&, const int&>}; std::ostream = std::basic_ostream]’ -/tmp/jl_QQmvi1/mwe.hpp:252:71: required from ‘stan::scalar_type_t mwe_model_namespace::mwe_model::log_prob_impl(VecR&, VecI&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; VecR = Eigen::Matrix, -1, 1>; VecI = Eigen::Matrix; stan::require_vector_like_t* = 0; stan::require_vector_like_vt* = 0; stan::require_st_var* = 0; stan::scalar_type_t = stan::math::var_value; std::ostream = std::basic_ostream]’ -/tmp/jl_QQmvi1/mwe.hpp:434:47: required from ‘T_ mwe_model_namespace::mwe_model::log_prob(Eigen::Matrix&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; T_ = stan::math::var_value; std::ostream = std::basic_ostream]’ -./stan/src/stan/model/model_base_crtp.hpp:98:72: required from ‘stan::math::var stan::model::model_base_crtp::log_prob(Eigen::Matrix, -1, 1>&, std::ostream*) const [with M = mwe_model_namespace::mwe_model; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ -./stan/src/stan/model/model_base_crtp.hpp:96:20: required from here -/usr/include/c++/11/type_traits:2579:11: error: no type named ‘type’ in ‘struct std::enable_if’ - 2579 | using enable_if_t = typename enable_if<_Cond, _Tp>::type; - | ^~~~~~~~~~~ -In file included from ./stan/lib/stan_math/stan/math/rev/core.hpp:76, - from ./stan/src/stan/model/model_base.hpp:8, - from ./stan/src/stan/model/model_header.hpp:4, - from /tmp/jl_QQmvi1/mwe.hpp:2: -./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp: In instantiation of ‘stan::math::var stan::math::internal::reduce_sum_impl::type>::value, void>::type, ReturnType, Vec, Args ...>::operator()(Vec&&, bool, int, std::ostream*, Args&& ...) const [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; ReturnType = stan::math::var_value; Vec = const std::vector&; Args = {std::tuple&, const int&>}; typename std::enable_if::type>::value, void>::type = void; typename std::decay<_Tp2>::type = std::decay >::type; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’: -./stan/lib/stan_math/stan/math/prim/functor/reduce_sum.hpp:208:60: required from ‘auto stan::math::reduce_sum(Vec&&, int, std::ostream*, Args&& ...) [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; Vec = const std::vector&; = void; Args = {std::tuple&, const int&>}; std::ostream = std::basic_ostream]’ -/tmp/jl_QQmvi1/mwe.hpp:252:71: required from ‘stan::scalar_type_t mwe_model_namespace::mwe_model::log_prob_impl(VecR&, VecI&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; VecR = Eigen::Matrix, -1, 1>; VecI = Eigen::Matrix; stan::require_vector_like_t* = 0; stan::require_vector_like_vt* = 0; stan::require_st_var* = 0; stan::scalar_type_t = stan::math::var_value; std::ostream = std::basic_ostream]’ -/tmp/jl_QQmvi1/mwe.hpp:434:47: required from ‘T_ mwe_model_namespace::mwe_model::log_prob(Eigen::Matrix&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; T_ = stan::math::var_value; std::ostream = std::basic_ostream]’ -./stan/src/stan/model/model_base_crtp.hpp:98:72: required from ‘stan::math::var stan::model::model_base_crtp::log_prob(Eigen::Matrix, -1, 1>&, std::ostream*) const [with M = mwe_model_namespace::mwe_model; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ -./stan/src/stan/model/model_base_crtp.hpp:96:20: required from here -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:93:15: note: candidate: ‘template* , stan::require_std_vector_vt* , class ... Pargs> stan::math::vari** stan::math::save_varis(stan::math::vari**, VecContainer&&, Pargs&& ...)’ - 93 | inline vari** save_varis(vari** dest, VecContainer&& x, Pargs&&... args) { - | ^~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:93:15: note: template argument deduction/substitution failed: -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:114:15: note: candidate: ‘template* , class ... Pargs> stan::math::vari** stan::math::save_varis(stan::math::vari**, EigT&&, Pargs&& ...)’ - 114 | inline vari** save_varis(vari** dest, EigT&& x, Pargs&&... args) { - | ^~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:114:15: note: template argument deduction/substitution failed: -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:135:15: note: candidate: ‘template* , class ... Pargs> stan::math::vari** stan::math::save_varis(stan::math::vari**, Arith&&, Pargs&& ...)’ - 135 | inline vari** save_varis(vari** dest, Arith&& x, Pargs&&... args) { - | ^~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:135:15: note: template argument deduction/substitution failed: -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:144:15: note: candidate: ‘stan::math::vari** stan::math::save_varis(stan::math::vari**)’ - 144 | inline vari** save_varis(vari** dest) { return dest; } - | ^~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/save_varis.hpp:144:15: note: candidate expects 1 argument, 2 provided -In file included from ./stan/lib/stan_math/stan/math/rev/functor.hpp:30, - from ./stan/lib/stan_math/stan/math/rev.hpp:15, - from ./stan/lib/stan_math/stan/math.hpp:19, - from ./stan/src/stan/model/model_header.hpp:6, - from /tmp/jl_QQmvi1/mwe.hpp:2: -./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp: In instantiation of ‘struct stan::math::internal::reduce_sum_impl, const std::vector&, std::tuple&, const int&> >::scoped_args_tuple’: -./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:58:23: required from ‘struct stan::math::internal::reduce_sum_impl, const std::vector&, std::tuple&, const int&> >::recursive_reducer’ -./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:247:23: required from ‘stan::math::var stan::math::internal::reduce_sum_impl::type>::value, void>::type, ReturnType, Vec, Args ...>::operator()(Vec&&, bool, int, std::ostream*, Args&& ...) const [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; ReturnType = stan::math::var_value; Vec = const std::vector&; Args = {std::tuple&, const int&>}; typename std::enable_if::type>::value, void>::type = void; typename std::decay<_Tp2>::type = std::decay >::type; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ -./stan/lib/stan_math/stan/math/prim/functor/reduce_sum.hpp:208:60: required from ‘auto stan::math::reduce_sum(Vec&&, int, std::ostream*, Args&& ...) [with ReduceFunction = mwe_model_namespace::partial_sum_rsfunctor__; Vec = const std::vector&; = void; Args = {std::tuple&, const int&>}; std::ostream = std::basic_ostream]’ -/tmp/jl_QQmvi1/mwe.hpp:252:71: required from ‘stan::scalar_type_t mwe_model_namespace::mwe_model::log_prob_impl(VecR&, VecI&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; VecR = Eigen::Matrix, -1, 1>; VecI = Eigen::Matrix; stan::require_vector_like_t* = 0; stan::require_vector_like_vt* = 0; stan::require_st_var* = 0; stan::scalar_type_t = stan::math::var_value; std::ostream = std::basic_ostream]’ -/tmp/jl_QQmvi1/mwe.hpp:434:47: required from ‘T_ mwe_model_namespace::mwe_model::log_prob(Eigen::Matrix&, std::ostream*) const [with bool propto__ = false; bool jacobian__ = false; T_ = stan::math::var_value; std::ostream = std::basic_ostream]’ -./stan/src/stan/model/model_base_crtp.hpp:98:72: required from ‘stan::math::var stan::model::model_base_crtp::log_prob(Eigen::Matrix, -1, 1>&, std::ostream*) const [with M = mwe_model_namespace::mwe_model; stan::math::var = stan::math::var_value; std::ostream = std::basic_ostream]’ -./stan/src/stan/model/model_base_crtp.hpp:96:20: required from here -./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:36:45: error: no matching function for call to ‘deep_copy_vars(std::tuple&, const int&>)’ - 36 | = std::tuple()))...>; - | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ -In file included from ./stan/lib/stan_math/stan/math/rev/core.hpp:17, - from ./stan/src/stan/model/model_base.hpp:8, - from ./stan/src/stan/model/model_header.hpp:4, - from /tmp/jl_QQmvi1/mwe.hpp:2: -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:23:14: note: candidate: ‘template Arith stan::math::deep_copy_vars(Arith&&)’ - 23 | inline Arith deep_copy_vars(Arith&& arg) { - | ^~~~~~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:23:14: note: template argument deduction/substitution failed: -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:45:13: note: candidate: ‘template* > auto stan::math::deep_copy_vars(VarVec&&)’ - 45 | inline auto deep_copy_vars(VarVec&& arg) { - | ^~~~~~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:45:13: note: template argument deduction/substitution failed: -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:63:13: note: candidate: ‘template* , stan::require_std_vector_vt* > auto stan::math::deep_copy_vars(VecContainer&&)’ - 63 | inline auto deep_copy_vars(VecContainer&& arg) { - | ^~~~~~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:63:13: note: template argument deduction/substitution failed: -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:79:13: note: candidate: ‘template* > auto stan::math::deep_copy_vars(EigT&&)’ - 79 | inline auto deep_copy_vars(EigT&& arg) { - | ^~~~~~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:79:13: note: template argument deduction/substitution failed: -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:33:13: note: candidate: ‘auto stan::math::deep_copy_vars(const var&)’ - 33 | inline auto deep_copy_vars(const var& arg) { - | ^~~~~~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:33:39: note: no known conversion for argument 1 from ‘std::tuple&, const int&>’ to ‘const var&’ {aka ‘const stan::math::var_value&’} - 33 | inline auto deep_copy_vars(const var& arg) { - | ~~~~~~~~~~~^~~ -In file included from ./stan/lib/stan_math/stan/math/rev/functor.hpp:30, - from ./stan/lib/stan_math/stan/math/rev.hpp:15, - from ./stan/lib/stan_math/stan/math.hpp:19, - from ./stan/src/stan/model/model_header.hpp:6, - from /tmp/jl_QQmvi1/mwe.hpp:2: -./stan/lib/stan_math/stan/math/rev/functor/reduce_sum.hpp:36:45: error: no matching function for call to ‘deep_copy_vars(std::tuple&, const int&>)’ - 36 | = std::tuple()))...>; - | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ -In file included from ./stan/lib/stan_math/stan/math/rev/core.hpp:17, - from ./stan/src/stan/model/model_base.hpp:8, - from ./stan/src/stan/model/model_header.hpp:4, - from /tmp/jl_QQmvi1/mwe.hpp:2: -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:23:14: note: candidate: ‘template Arith stan::math::deep_copy_vars(Arith&&)’ - 23 | inline Arith deep_copy_vars(Arith&& arg) { - | ^~~~~~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:23:14: note: template argument deduction/substitution failed: -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:45:13: note: candidate: ‘template* > auto stan::math::deep_copy_vars(VarVec&&)’ - 45 | inline auto deep_copy_vars(VarVec&& arg) { - | ^~~~~~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:45:13: note: template argument deduction/substitution failed: -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:63:13: note: candidate: ‘template* , stan::require_std_vector_vt* > auto stan::math::deep_copy_vars(VecContainer&&)’ - 63 | inline auto deep_copy_vars(VecContainer&& arg) { - | ^~~~~~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:63:13: note: template argument deduction/substitution failed: -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:79:13: note: candidate: ‘template* > auto stan::math::deep_copy_vars(EigT&&)’ - 79 | inline auto deep_copy_vars(EigT&& arg) { - | ^~~~~~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:79:13: note: template argument deduction/substitution failed: -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:33:13: note: candidate: ‘auto stan::math::deep_copy_vars(const var&)’ - 33 | inline auto deep_copy_vars(const var& arg) { - | ^~~~~~~~~~~~~~ -./stan/lib/stan_math/stan/math/rev/core/deep_copy_vars.hpp:33:39: note: no known conversion for argument 1 from ‘std::tuple&, const int&>’ to ‘const var&’ {aka ‘const stan::math::var_value&’} - 33 | inline auto deep_copy_vars(const var& arg) { - | ~~~~~~~~~~~^~~ -make: *** [Makefile:77: /tmp/jl_QQmvi1/mwe.o] Error 1 - -Stacktrace: - [1] error(s::String) - @ Base ./error.jl:35 - [2] compile_model(stan_file::String; stanc_args::Vector{String}, make_args::Vector{String}) - @ BridgeStan ~/.julia/packages/BridgeStan/Bodre/src/compile.jl:114 - [3] top-level scope - @ ~/github/issues/stan-dev-math/worktrees/3041-map-tuple/mwe/mwe.jl:37 -in expression starting at /home/niko/github/issues/stan-dev-math/worktrees/3041-map-tuple/mwe/mwe.jl:37 - -# exit_code: 1 -# status: FAIL -# finished: 2026-03-25 11:14:22 From 3f05beaf760361f8dfc6285ac9bda316a7e29e19 Mon Sep 17 00:00:00 2001 From: Nikolas Siccha Date: Wed, 25 Mar 2026 13:31:51 +0100 Subject: [PATCH 8/9] Add MWE --- mwe/Project.toml | 2 ++ mwe/mwe.jl | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 mwe/Project.toml create mode 100644 mwe/mwe.jl diff --git a/mwe/Project.toml b/mwe/Project.toml new file mode 100644 index 00000000000..bdf49f9a5ef --- /dev/null +++ b/mwe/Project.toml @@ -0,0 +1,2 @@ +[deps] +BridgeStan = "c88b6f0a-829e-4b0b-94b7-f06ab5908f5a" diff --git a/mwe/mwe.jl b/mwe/mwe.jl new file mode 100644 index 00000000000..b2ab7ea189d --- /dev/null +++ b/mwe/mwe.jl @@ -0,0 +1,54 @@ +using BridgeStan + +stan_code = """ +functions { + real partial_sum(array[] real slice, int start, int end, + tuple(real, int) params) { + real mu = params.1; + int K = params.2; + real lp = 0; + for (i in 1:size(slice)) { + lp += normal_lpdf(slice[i] | mu, K); + } + return lp; + } +} +data { + int N; + int K; + array[N] real y; +} +parameters { + real mu; +} +model { + mu ~ normal(0, 10); + target += reduce_sum(partial_sum, y, 1, (mu, K)); +} +""" + +stan_math = ENV["MWE_RUN_DIR"] +label = ENV["MWE_LABEL"] + +workdir = mktempdir() +stan_file = joinpath(workdir, "mwe.stan") +write(stan_file, stan_code) + +lib = compile_model(stan_file; make_args=["MATH=$stan_math/", "STAN_THREADS=true"]) + +data = """{"N": 5, "K": 2, "y": [1.0, 2.0, 3.0, 4.0, 5.0]}""" +sm = StanModel(lib, data) + +params = [3.0] # mu (unconstrained) +lp = log_density(sm, params) +lp_grad, grad = log_density_gradient(sm, params) + +println("[$label] log_density = $lp") +println("[$label] gradient = $grad") + +@assert isfinite(lp) "log_density should be finite" +@assert all(isfinite, grad) "gradient should be finite" +@assert lp ≈ lp_grad "log_density values should match" +@assert length(grad) == 1 "gradient should have 1 element" + +println("[$label] All checks passed!") From 3a685117873c60915ddd7f99bda09239ea9efbb0 Mon Sep 17 00:00:00 2001 From: Stan Jenkins Date: Wed, 25 Mar 2026 08:33:56 -0400 Subject: [PATCH 9/9] [Jenkins] auto-formatting by clang-format version 10.0.0-4ubuntu1 --- stan/math/rev/core/save_varis.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stan/math/rev/core/save_varis.hpp b/stan/math/rev/core/save_varis.hpp index e0286639a53..3293fe4d73a 100644 --- a/stan/math/rev/core/save_varis.hpp +++ b/stan/math/rev/core/save_varis.hpp @@ -162,8 +162,8 @@ template *, typename... Pargs> inline vari** save_varis(vari** dest, Tuple&& x, Pargs&&... args) { dest = stan::math::apply( [dest](auto&&... inner_args) { - return save_varis( - dest, std::forward(inner_args)...); + return save_varis(dest, + std::forward(inner_args)...); }, std::forward(x)); return save_varis(dest, std::forward(args)...);