Skip to content

[feature request] Add ffi interface for logp-gradient function - #600

Closed
aseyboldt wants to merge 1 commit into
stan-dev:mainfrom
aseyboldt:export-logp-ffi
Closed

[feature request] Add ffi interface for logp-gradient function#600
aseyboldt wants to merge 1 commit into
stan-dev:mainfrom
aseyboldt:export-logp-ffi

Conversation

@aseyboldt

Copy link
Copy Markdown
Contributor

The current shared object build for each stan model includes a function for computing the logp gradient, but calling this function is relatively slow as it converts the dataset each time. This PR adds a couple of functions that make it possible to call the gradient function from a C or numba library without any python overhead:

model=import_services_extension_module(model_id)
ctx=model.new_logp_ctx(data)
function_address=model.logp_func(ctx)
# later, after we are done# model.free_logp_ctx(ctx)

function_address is now a pointer to a C function:

intlogp_gradient(size_tndim, constdouble*unconstrained_parameters, double*gradient, double*logp, void*ctx)

Which is way faster than the previously exported gradient function.

This is useful for implementing different samplers based on stan models (for example the sampler implemented in rust that I'm working on ;-) ).

@riddell-stan

Copy link
Copy Markdown
Contributor

Feature requests need to be proposed and discussed on the Stan Forums first. The issue tracker is for bugs and confirmed features only.

@aseyboldt

Copy link
Copy Markdown
ContributorAuthor

@stale

staleBot commented Sep 21, 2022

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stalestaleBot added the wontfix label Sep 21, 2022
@stalestaleBot closed this Nov 12, 2022
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@aseyboldt@riddell-stan