diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index fa4f3e37..753cf61d 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -8,7 +8,7 @@ on: workflow_dispatch: {} env: - CACHE_VERSION: 0 + CACHE_VERSION: 1 # only run one copy per PR concurrency: @@ -270,12 +270,6 @@ jobs: path: ./test_models/ key: ${{ hashFiles('**/*.stan', 'src/*', 'stan/src/stan/version.hpp', 'Makefile') }}-${{ matrix.os }}-v${{ env.CACHE_VERSION }} - - name: Install LLVM and Clang - uses: KyleMayes/install-llvm-action@v2 - with: - version: "15.0" - directory: ${{ runner.temp }}/llvm - - name: Set up TBB if: matrix.os == 'windows-latest' run: | @@ -284,9 +278,6 @@ jobs: - name: Run rust tests working-directory: ./rust timeout-minutes: 60 - env: - LIBCLANG_PATH: ${{ runner.temp }}/llvm/lib - LLVM_CONFIG_PATH: ${{ runner.temp }}/llvm/bin/llvm-config run: | cargo clippy cargo fmt --check diff --git a/julia/src/model.jl b/julia/src/model.jl index 62cfa7c8..d8d12c7e 100644 --- a/julia/src/model.jl +++ b/julia/src/model.jl @@ -1,3 +1,4 @@ +using Base.Libc.Libdl: dlsym, dllist, dlopen struct StanModelStruct end @@ -54,7 +55,7 @@ mutable struct StanModel lib = compile_model(lib; stanc_args, make_args) end - if warn && in(abspath(lib), Libc.Libdl.dllist()) + if warn && in(abspath(lib), dllist()) @warn "Loading a shared object '" * lib * "' which is already loaded.\n" * @@ -72,18 +73,14 @@ mutable struct StanModel windows_dll_path_setup() - lib = Libc.Libdl.dlopen(lib) + lib = dlopen(lib) err = Ref{Cstring}() - - stanmodel = ccall( - Libc.Libdl.dlsym(lib, "bs_model_construct"), - Ptr{StanModelStruct}, - (Cstring, UInt32, Ref{Cstring}), - data, - seed, - err, - ) + stanmodel = @ccall $(dlsym(lib, :bs_model_construct))( + data::Cstring, + seed::UInt32, + err::Ref{Cstring}, + )::Ptr{StanModelStruct} if stanmodel == C_NULL error(handle_error(lib, err, "bs_model_construct")) end @@ -91,12 +88,9 @@ mutable struct StanModel sm = new(lib, stanmodel, data, seed) function f(sm) - ccall( - Libc.Libdl.dlsym(sm.lib, "bs_model_destruct"), - Cvoid, - (Ptr{StanModelStruct},), - sm.stanmodel, - ) + @ccall $(dlsym(sm.lib, :bs_model_destruct))( + sm.stanmodel::Ptr{StanModelStruct}, + )::Cvoid end finalizer(f, sm) @@ -122,13 +116,12 @@ mutable struct StanRNG seed = convert(UInt32, seed) err = Ref{Cstring}() - ptr = ccall( - Libc.Libdl.dlsym(sm.lib, "bs_rng_construct"), - Ptr{StanModelStruct}, - (UInt32, Ref{Cstring}), - seed, - err, - ) + + ptr = @ccall $(dlsym(sm.lib, :bs_rng_construct))( + seed::UInt32, + err::Ref{Cstring}, + )::Ptr{StanRNGStruct} + if ptr == C_NULL error(handle_error(sm.lib, err, "bs_rng_construct")) end @@ -136,12 +129,9 @@ mutable struct StanRNG stanrng = new(sm.lib, ptr, seed) function f(stanrng) - ccall( - Libc.Libdl.dlsym(stanrng.lib, "bs_rng_destruct"), - Cvoid, - (Ptr{StanModelStruct},), - stanrng.ptr, - ) + @ccall $(dlsym(stanrng.lib, :bs_rng_destruct))( + stanrng.ptr::Ptr{StanRNGStruct}, + )::Cvoid end finalizer(f, stanrng) @@ -167,12 +157,7 @@ new_rng(sm::StanModel, seed) = StanRNG(sm, seed) Return the name of the model `sm` """ function name(sm::StanModel) - cstr = ccall( - Libc.Libdl.dlsym(sm.lib, "bs_name"), - Cstring, - (Ptr{StanModelStruct},), - sm.stanmodel, - ) + cstr = @ccall $(dlsym(sm.lib, :bs_name))(sm.stanmodel::Ptr{StanModelStruct})::Cstring unsafe_string(cstr) end @@ -185,12 +170,8 @@ This includes the Stan version and important compiler flags. """ function model_info(sm::StanModel) - cstr = ccall( - Libc.Libdl.dlsym(sm.lib, "bs_model_info"), - Cstring, - (Ptr{StanModelStruct},), - sm.stanmodel, - ) + cstr = + @ccall $(dlsym(sm.lib, :bs_model_info))(sm.stanmodel::Ptr{StanModelStruct})::Cstring unsafe_string(cstr) end @@ -200,9 +181,9 @@ end Return the BridgeStan version of the compiled model `sm`. """ function model_version(sm::StanModel) - major = reinterpret(Ptr{Cint}, Libc.Libdl.dlsym(sm.lib, "bs_major_version")) - minor = reinterpret(Ptr{Cint}, Libc.Libdl.dlsym(sm.lib, "bs_minor_version")) - patch = reinterpret(Ptr{Cint}, Libc.Libdl.dlsym(sm.lib, "bs_patch_version")) + major = reinterpret(Ptr{Cint}, dlsym(sm.lib, "bs_major_version")) + minor = reinterpret(Ptr{Cint}, dlsym(sm.lib, "bs_minor_version")) + patch = reinterpret(Ptr{Cint}, dlsym(sm.lib, "bs_patch_version")) (unsafe_load(major), unsafe_load(minor), unsafe_load(patch)) end @@ -216,15 +197,12 @@ of the model. If `include_tp` or `include_gq` are true, items declared in the `transformed parameters` and `generate quantities` blocks are included, respectively. """ -function param_num(sm::StanModel; include_tp = false, include_gq = false) - ccall( - Libc.Libdl.dlsym(sm.lib, "bs_param_num"), - Cint, - (Ptr{StanModelStruct}, Cint, Cint), - sm.stanmodel, - include_tp, - include_gq, - ) +function param_num(sm::StanModel; include_tp::Bool = false, include_gq::Bool = false) + @ccall $(dlsym(sm.lib, :bs_param_num))( + sm.stanmodel::Ptr{StanModelStruct}, + include_tp::Bool, + include_gq::Bool, + )::Cint end @@ -238,12 +216,7 @@ when variables are declared with constraints. For example, `simplex[5]` has a constrained size of 5, but an unconstrained size of 4. """ function param_unc_num(sm::StanModel) - ccall( - Libc.Libdl.dlsym(sm.lib, "bs_param_unc_num"), - Cint, - (Ptr{StanModelStruct},), - sm.stanmodel, - ) + @ccall $(dlsym(sm.lib, :bs_param_unc_num))(sm.stanmodel::Ptr{StanModelStruct})::Cint end """ @@ -258,15 +231,12 @@ For example, the scalar `a` has indexed name `"a"`, the vector entry `a[1]` has indexed name `"a.1"` and the matrix entry `a[2, 3]` has indexed names `"a.2.3"`. Parameter order of the output is column major and more generally last-index major for containers. """ -function param_names(sm::StanModel; include_tp = false, include_gq = false) - cstr = ccall( - Libc.Libdl.dlsym(sm.lib, "bs_param_names"), - Cstring, - (Ptr{StanModelStruct}, Cint, Cint), - sm.stanmodel, - include_tp, - include_gq, - ) +function param_names(sm::StanModel; include_tp::Bool = false, include_gq::Bool = false) + cstr = @ccall $(dlsym(sm.lib, :bs_param_names))( + sm.stanmodel::Ptr{StanModelStruct}, + include_tp::Bool, + include_gq::Bool, + )::Cstring string.(split(unsafe_string(cstr), ',')) end @@ -279,12 +249,9 @@ For example, a scalar unconstrained parameter `b` has indexed name `b` and a vector entry `b[3]` has indexed name `b.3`. """ function param_unc_names(sm::StanModel) - cstr = ccall( - Libc.Libdl.dlsym(sm.lib, "bs_param_unc_names"), - Cstring, - (Ptr{StanModelStruct},), - sm.stanmodel, - ) + cstr = @ccall $(dlsym(sm.lib, :bs_param_unc_names))( + sm.stanmodel::Ptr{StanModelStruct}, + )::Cstring string.(split(unsafe_string(cstr), ',')) end @@ -307,8 +274,8 @@ function param_constrain!( sm::StanModel, theta_unc::Vector{Float64}, out::Vector{Float64}; - include_tp = false, - include_gq = false, + include_tp::Bool = false, + include_gq::Bool = false, rng::Union{StanRNG,Nothing} = nothing, ) dims = param_num(sm; include_tp = include_tp, include_gq = include_gq) @@ -328,27 +295,15 @@ function param_constrain!( end err = Ref{Cstring}() - - rc = ccall( - Libc.Libdl.dlsym(sm.lib, "bs_param_constrain"), - Cint, - ( - Ptr{StanModelStruct}, - Cint, - Cint, - Ref{Cdouble}, - Ref{Cdouble}, - Ptr{StanRNGStruct}, - Ref{Cstring}, - ), - sm.stanmodel, - include_tp, - include_gq, - theta_unc, - out, - rng_ptr, - err, - ) + rc = @ccall $(dlsym(sm.lib, :bs_param_constrain))( + sm.stanmodel::Ptr{StanModelStruct}, + include_tp::Bool, + include_gq::Bool, + theta_unc::Ref{Cdouble}, + out::Ref{Cdouble}, + rng_ptr::Ptr{StanRNGStruct}, + err::Ref{Cstring}, + )::Cint if rc != 0 error(handle_error(sm.lib, err, "param_constrain")) end @@ -374,8 +329,8 @@ This is the inverse of `param_unconstrain`. function param_constrain( sm::StanModel, theta_unc::Vector{Float64}; - include_tp = false, - include_gq = false, + include_tp::Bool = false, + include_gq::Bool = false, rng::Union{StanRNG,Nothing} = nothing, ) out = zeros(param_num(sm, include_tp = include_tp, include_gq = include_gq)) @@ -412,15 +367,12 @@ function param_unconstrain!(sm::StanModel, theta::Vector{Float64}, out::Vector{F ) end err = Ref{Cstring}() - rc = ccall( - Libc.Libdl.dlsym(sm.lib, "bs_param_unconstrain"), - Cint, - (Ptr{StanModelStruct}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cstring}), - sm.stanmodel, - theta, - out, - err, - ) + rc = @ccall $(dlsym(sm.lib, :bs_param_unconstrain))( + sm.stanmodel::Ptr{StanModelStruct}, + theta::Ref{Cdouble}, + out::Ref{Cdouble}, + err::Ref{Cstring}, + )::Cint if rc != 0 error(handle_error(sm.lib, err, "param_unconstrain")) end @@ -467,15 +419,12 @@ function param_unconstrain_json!(sm::StanModel, theta::String, out::Vector{Float end err = Ref{Cstring}() - rc = ccall( - Libc.Libdl.dlsym(sm.lib, "bs_param_unconstrain_json"), - Cint, - (Ptr{StanModelStruct}, Cstring, Ref{Cdouble}, Ref{Cstring}), - sm.stanmodel, - theta, - out, - err, - ) + rc = @ccall $(dlsym(sm.lib, :bs_param_unconstrain_json))( + sm.stanmodel::Ptr{StanModelStruct}, + theta::Cstring, + out::Ref{Cdouble}, + err::Ref{Cstring}, + )::Cint if rc != 0 error(handle_error(sm.lib, err, "param_unconstrain_json")) end @@ -506,20 +455,22 @@ Return the log density of the specified unconstrained parameters. This calculation drops constant terms that do not depend on the parameters if `propto` is `true` and includes change of variables terms for constrained parameters if `jacobian` is `true`. """ -function log_density(sm::StanModel, q::Vector{Float64}; propto = true, jacobian = true) +function log_density( + sm::StanModel, + q::Vector{Float64}; + propto::Bool = true, + jacobian::Bool = true, +) lp = Ref(0.0) err = Ref{Cstring}() - rc = ccall( - Libc.Libdl.dlsym(sm.lib, "bs_log_density"), - Cint, - (Ptr{StanModelStruct}, Cint, Cint, Ref{Cdouble}, Ref{Cdouble}, Ref{Cstring}), - sm.stanmodel, - propto, - jacobian, - q, - lp, - err, - ) + rc = @ccall $(dlsym(sm.lib, :bs_log_density))( + sm.stanmodel::Ptr{StanModelStruct}, + propto::Bool, + jacobian::Bool, + q::Ref{Cdouble}, + lp::Ref{Cdouble}, + err::Ref{Cstring}, + )::Cint if rc != 0 error(handle_error(sm.lib, err, "log_density")) end @@ -542,8 +493,8 @@ function log_density_gradient!( sm::StanModel, q::Vector{Float64}, out::Vector{Float64}; - propto = true, - jacobian = true, + propto::Bool = true, + jacobian::Bool = true, ) dims = param_unc_num(sm) if length(out) != dims @@ -555,26 +506,15 @@ function log_density_gradient!( end lp = Ref(0.0) err = Ref{Cstring}() - rc = ccall( - Libc.Libdl.dlsym(sm.lib, "bs_log_density_gradient"), - Cint, - ( - Ptr{StanModelStruct}, - Cint, - Cint, - Ref{Cdouble}, - Ref{Cdouble}, - Ref{Cdouble}, - Ref{Cstring}, - ), - sm.stanmodel, - propto, - jacobian, - q, - lp, - out, - err, - ) + rc = @ccall $(dlsym(sm.lib, :bs_log_density_gradient))( + sm.stanmodel::Ptr{StanModelStruct}, + propto::Bool, + jacobian::Bool, + q::Ref{Cdouble}, + lp::Ref{Cdouble}, + out::Ref{Cdouble}, + err::Ref{Cstring}, + )::Cint if rc != 0 error(handle_error(sm.lib, err, "log_density_gradient")) end @@ -597,8 +537,8 @@ re-using existing memory. function log_density_gradient( sm::StanModel, q::Vector{Float64}; - propto = true, - jacobian = true, + propto::Bool = true, + jacobian::Bool = true, ) grad = zeros(param_unc_num(sm)) log_density_gradient!(sm, q, grad; propto = propto, jacobian = jacobian) @@ -621,8 +561,8 @@ function log_density_hessian!( q::Vector{Float64}, out_grad::Vector{Float64}, out_hess::Vector{Float64}; - propto = true, - jacobian = true, + propto::Bool = true, + jacobian::Bool = true, ) dims = param_unc_num(sm) if length(out_grad) != dims @@ -640,28 +580,16 @@ function log_density_hessian!( end lp = Ref(0.0) err = Ref{Cstring}() - rc = ccall( - Libc.Libdl.dlsym(sm.lib, "bs_log_density_hessian"), - Cint, - ( - Ptr{StanModelStruct}, - Cint, - Cint, - Ref{Cdouble}, - Ref{Cdouble}, - Ref{Cdouble}, - Ref{Cdouble}, - Ref{Cstring}, - ), - sm.stanmodel, - propto, - jacobian, - q, - lp, - out_grad, - out_hess, - err, - ) + rc = @ccall $(dlsym(sm.lib, :bs_log_density_hessian))( + sm.stanmodel::Ptr{StanModelStruct}, + propto::Bool, + jacobian::Bool, + q::Ref{Cdouble}, + lp::Ref{Cdouble}, + out_grad::Ref{Cdouble}, + out_hess::Ref{Cdouble}, + err::Ref{Cstring}, + )::Cint if rc != 0 error(handle_error(sm.lib, err, "log_density_hessian")) end @@ -683,8 +611,8 @@ re-using existing memory. function log_density_hessian( sm::StanModel, q::Vector{Float64}; - propto = true, - jacobian = true, + propto::Bool = true, + jacobian::Bool = true, ) dims = param_unc_num(sm) grad = zeros(dims) @@ -709,8 +637,8 @@ function log_density_hessian_vector_product!( q::Vector{Float64}, v::Vector{Float64}, out::Vector{Float64}; - propto = true, - jacobian = true, + propto::Bool = true, + jacobian::Bool = true, ) dims = param_unc_num(sm) if length(out) != dims @@ -722,28 +650,16 @@ function log_density_hessian_vector_product!( end lp = Ref(0.0) err = Ref{Cstring}() - rc = ccall( - Libc.Libdl.dlsym(sm.lib, "bs_log_density_hessian_vector_product"), - Cint, - ( - Ptr{StanModelStruct}, - Cint, - Cint, - Ref{Cdouble}, - Ref{Cdouble}, - Ref{Cdouble}, - Ref{Cdouble}, - Ref{Cstring}, - ), - sm.stanmodel, - propto, - jacobian, - q, - v, - lp, - out, - err, - ) + rc = @ccall $(dlsym(sm.lib, :bs_log_density_hessian_vector_product))( + sm.stanmodel::Ptr{StanModelStruct}, + propto::Bool, + jacobian::Bool, + q::Ref{Cdouble}, + v::Ref{Cdouble}, + lp::Ref{Cdouble}, + out::Ref{Cdouble}, + err::Ref{Cstring}, + )::Cint if rc != 0 error(handle_error(sm.lib, err, "log_density_hessian_vector_product")) end @@ -766,8 +682,8 @@ function log_density_hessian_vector_product( sm::StanModel, q::Vector{Float64}, v::Vector{Float64}; - propto = true, - jacobian = true, + propto::Bool = true, + jacobian::Bool = true, ) out = zeros(param_unc_num(sm)) log_density_hessian_vector_product!(sm, q, v, out; propto = propto, jacobian = jacobian) @@ -788,7 +704,7 @@ function handle_error(lib::Ptr{Nothing}, err::Ref{Cstring}, method::String) return "Unknown error in $method." else s = string(unsafe_string(err[])) - ccall(Libc.Libdl.dlsym(lib, "bs_free_error_msg"), Cvoid, (Cstring,), err[]) + @ccall $(dlsym(lib, "bs_free_error_msg"))(err[]::Cstring)::Cvoid return s end end diff --git a/julia/test/model_tests.jl b/julia/test/model_tests.jl index 9bb9d09f..e923abc9 100644 --- a/julia/test/model_tests.jl +++ b/julia/test/model_tests.jl @@ -491,7 +491,8 @@ end for _ = 1:R x = rand(BridgeStan.param_num(model)) q = @. log(x / (1 - x)) # unconstrained scale - (log_density, gradient) = BridgeStan.log_density_gradient(model, q, jacobian = 0) + (log_density, gradient) = + BridgeStan.log_density_gradient(model, q, jacobian = false) p = x[1] @test isapprox(log_density, _bernoulli(y, p)) diff --git a/python/bridgestan/model.py b/python/bridgestan/model.py index 50611ee0..fa29560e 100644 --- a/python/bridgestan/model.py +++ b/python/bridgestan/model.py @@ -190,7 +190,7 @@ def __init__( self._param_num = self.stanlib.bs_param_num self._param_num.restype = ctypes.c_int - self._param_num.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int] + self._param_num.argtypes = [ctypes.c_void_p, ctypes.c_bool, ctypes.c_bool] self._param_unc_num = self.stanlib.bs_param_unc_num self._param_unc_num.restype = ctypes.c_int @@ -213,8 +213,8 @@ def __init__( self._param_names.restype = ctypes.c_char_p self._param_names.argtypes = [ ctypes.c_void_p, - ctypes.c_int, - ctypes.c_int, + ctypes.c_bool, + ctypes.c_bool, ] self._param_unc_names = self.stanlib.bs_param_unc_names @@ -225,8 +225,8 @@ def __init__( self._param_constrain.restype = ctypes.c_int self._param_constrain.argtypes = [ ctypes.c_void_p, - ctypes.c_int, - ctypes.c_int, + ctypes.c_bool, + ctypes.c_bool, double_array, writeable_double_array, ctypes.c_void_p, @@ -255,8 +255,8 @@ def __init__( self._log_density.restype = ctypes.c_int self._log_density.argtypes = [ ctypes.c_void_p, - ctypes.c_int, - ctypes.c_int, + ctypes.c_bool, + ctypes.c_bool, double_array, ctypes.POINTER(ctypes.c_double), star_star_char, @@ -266,8 +266,8 @@ def __init__( self._log_density_gradient.restype = ctypes.c_int self._log_density_gradient.argtypes = [ ctypes.c_void_p, - ctypes.c_int, - ctypes.c_int, + ctypes.c_bool, + ctypes.c_bool, double_array, ctypes.POINTER(ctypes.c_double), param_sized_out_array, @@ -278,8 +278,8 @@ def __init__( self._log_density_hessian.restype = ctypes.c_int self._log_density_hessian.argtypes = [ ctypes.c_void_p, - ctypes.c_int, - ctypes.c_int, + ctypes.c_bool, + ctypes.c_bool, double_array, ctypes.POINTER(ctypes.c_double), param_sized_out_array, @@ -291,8 +291,8 @@ def __init__( self._log_density_hvp.restype = ctypes.c_int self._log_density_hvp.argtypes = [ ctypes.c_void_p, - ctypes.c_int, - ctypes.c_int, + ctypes.c_bool, + ctypes.c_bool, double_array, double_array, ctypes.POINTER(ctypes.c_double), @@ -352,7 +352,7 @@ def param_num(self, *, include_tp: bool = False, include_gq: bool = False) -> in :param include_gq: ``True`` to include the generated quantities. :return: The number of parameters. """ - return self._param_num(self.model, int(include_tp), int(include_gq)) + return self._param_num(self.model, include_tp, include_gq) def param_unc_num(self) -> int: """ @@ -380,7 +380,7 @@ def param_names( :return: The indexed names of the parameters. """ return ( - self._param_names(self.model, int(include_tp), int(include_gq)) + self._param_names(self.model, include_tp, include_gq) .decode("utf-8") .split(",") ) @@ -448,8 +448,8 @@ def param_constrain( rc = self._param_constrain( self.model, - int(include_tp), - int(include_gq), + include_tp, + include_gq, theta_unc, out, rng_ptr, @@ -550,8 +550,8 @@ def log_density( err = ctypes.c_char_p() rc = self._log_density( self.model, - int(propto), - int(jacobian), + propto, + jacobian, theta_unc, ctypes.byref(lp), ctypes.byref(err), @@ -597,8 +597,8 @@ def log_density_gradient( rc = self._log_density_gradient( self.model, - int(propto), - int(jacobian), + propto, + jacobian, theta_unc, ctypes.byref(lp), out, @@ -654,8 +654,8 @@ def log_density_hessian( rc = self._log_density_hessian( self.model, - int(propto), - int(jacobian), + propto, + jacobian, theta_unc, ctypes.byref(lp), out_grad, @@ -701,8 +701,8 @@ def log_density_hessian_vector_product( rc = self._log_density_hvp( self.model, - int(propto), - int(jacobian), + propto, + jacobian, theta_unc, v, ctypes.byref(lp), diff --git a/src/bridgestanR.cpp b/src/bridgestanR.cpp index b5a5f19f..35c96784 100644 --- a/src/bridgestanR.cpp +++ b/src/bridgestanR.cpp @@ -23,14 +23,14 @@ void bs_model_info_R(bs_model** model, char const** info_out) { } void bs_param_names_R(bs_model** model, int* include_tp, int* include_gq, char const** names_out) { - *names_out = bs_param_names(*model, *include_tp, *include_gq); + *names_out = bs_param_names(*model, (*include_tp != 0), (*include_gq != 0)); } void bs_param_unc_names_R(bs_model** model, char const** names_out) { *names_out = bs_param_unc_names(*model); } void bs_param_num_R(bs_model** model, int* include_tp, int* include_gq, int* num_out) { - *num_out = bs_param_num(*model, *include_tp, *include_gq); + *num_out = bs_param_num(*model, (*include_tp != 0), (*include_gq != 0)); } void bs_param_unc_num_R(bs_model** model, int* num_out) { *num_out = bs_param_unc_num(*model); @@ -38,8 +38,9 @@ void bs_param_unc_num_R(bs_model** model, int* num_out) { void bs_param_constrain_R(bs_model** model, int* include_tp, int* include_gq, const double* theta_unc, double* theta, bs_rng** rng, int* return_code, char** err_msg, void** err_ptr) { - *return_code = bs_param_constrain(*model, *include_tp, *include_gq, theta_unc, - theta, *rng, err_msg); + *return_code + = bs_param_constrain(*model, (*include_tp != 0), (*include_gq != 0), + theta_unc, theta, *rng, err_msg); *err_ptr = static_cast(*err_msg); } void bs_param_unconstrain_R(bs_model** model, const double* theta, @@ -57,24 +58,25 @@ void bs_param_unconstrain_json_R(bs_model** model, char const** json, void bs_log_density_R(bs_model** model, int* propto, int* jacobian, const double* theta_unc, double* val, int* return_code, char** err_msg, void** err_ptr) { - *return_code - = bs_log_density(*model, *propto, *jacobian, theta_unc, val, err_msg); + *return_code = bs_log_density(*model, (*propto != 0), (*jacobian != 0), + theta_unc, val, err_msg); *err_ptr = static_cast(*err_msg); } void bs_log_density_gradient_R(bs_model** model, int* propto, int* jacobian, const double* theta_unc, double* val, double* grad, int* return_code, char** err_msg, void** err_ptr) { - *return_code = bs_log_density_gradient(*model, *propto, *jacobian, theta_unc, - val, grad, err_msg); + *return_code = bs_log_density_gradient( + *model, (*propto != 0), (*jacobian != 0), theta_unc, val, grad, err_msg); *err_ptr = static_cast(*err_msg); } void bs_log_density_hessian_R(bs_model** model, int* propto, int* jacobian, const double* theta_unc, double* val, double* grad, double* hess, int* return_code, char** err_msg, void** err_ptr) { - *return_code = bs_log_density_hessian(*model, *propto, *jacobian, theta_unc, - val, grad, hess, err_msg); + *return_code + = bs_log_density_hessian(*model, (*propto != 0), (*jacobian != 0), + theta_unc, val, grad, hess, err_msg); *err_ptr = static_cast(*err_msg); } void bs_log_density_hessian_vector_product_R(bs_model** model, int* propto, @@ -84,7 +86,8 @@ void bs_log_density_hessian_vector_product_R(bs_model** model, int* propto, double* Hvp, int* return_code, char** err_msg, void** err_ptr) { *return_code = bs_log_density_hessian_vector_product( - *model, *propto, *jacobian, theta_unc, vector, val, Hvp, err_msg); + *model, (*propto != 0), (*jacobian != 0), theta_unc, vector, val, Hvp, + err_msg); *err_ptr = static_cast(*err_msg); } void bs_rng_construct_R(int* seed, bs_rng** ptr_out, char** err_msg,