Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Const correctness in C api #89

Merged
merged 1 commit into from
Mar 24, 2023
Merged

Fix: Const correctness in C api #89

merged 1 commit into from
Mar 24, 2023

Conversation

WardBrian
Copy link
Collaborator

As pointed out by @aseyboldt in #88, our C headers could have many more things marked as const than they currently did. This fixes that and cleans up some argument names, also per his suggestion.

@WardBrian
Copy link
Collaborator Author

Note: I didn't update the bridgestan_R header mainly because 1) it's only used by R and is redundant anywhere else and 2) I am not great at figuring out where to put the const in pointer-to-pointer types

@WardBrian
Copy link
Collaborator Author

I tested locally to confirm we cannot make param_constrain const, and with everything passing in CI I think this is good enough

@WardBrian WardBrian merged commit f07232a into main Mar 24, 2023
@WardBrian WardBrian deleted the fix/const-correctness branch March 24, 2023 18:07
@bob-carpenter
Copy link
Collaborator

We could get more extreme on this given that C++ lets you cast away const. The biggest problem is in our constructed model class. Despite being const, I don't believe the log_prob functions are not marked as const. What we can do in our interface is take in something that's marked const and then cast away the const modifier, which we know will be safe.

@WardBrian
Copy link
Collaborator Author

I think all of the truly const parts of the model class are marked as such. write_array requires a non-const RNG object, which is what prevents us from making it const in param_constrain

@bob-carpenter
Copy link
Collaborator

Nice. I hadn't realized that has been fixed. And it looks like we can't make the params arg to log_prob const because it'll be modified if it's an autodiff variable (though I'm wondering how we can declare all of our math library as const because those also get modified due to autodiff).

@WardBrian WardBrian mentioned this pull request Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants