Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH: Implement CDF of the von Mises distribution#111

Merged
dschmitz89 merged 14 commits into
scipy:mainfrom
fbourgey:von_mises_cdf
May 15, 2026
Merged

ENH: Implement CDF of the von Mises distribution#111
dschmitz89 merged 14 commits into
scipy:mainfrom
fbourgey:von_mises_cdf

Conversation

@fbourgey
Copy link
Copy Markdown
Member

Reference issue

Toward #98

What does this implement/fix?

Implement the CDF of the von Mises distribution and related helper functions from von_mises_cdf

@fbourgey
Copy link
Copy Markdown
Member Author

The inputs and outputs for the CDF are std::vector<double> as in the original Cython code. It was not clear if we wanted double instead.

@dschmitz89
Copy link
Copy Markdown
Contributor

The math looks sound here. Input and output should be a simple scalar here so we can turn this into a regular ufunc. I do not understand why this was taking arrays as input before. Could you chime in @WarrenWeckesser ?

@WarrenWeckesser
Copy link
Copy Markdown
Member

Input and output should be a simple scalar here so we can turn this into a regular ufunc. I do not understand why this was taking arrays as input before.

I agree; I would expect the C++ implementation of von_mises_cdf(k, x) in xsf to be a scalar kernel. In SciPy, that kernel would be wrapped using the standard ufunc machinery so that the Python function implements broadcasting and the rest of the ufunc API (including, for example, the out parameter).

The existing Cython code accepts input arrays with arbitrary dimensions, but it uses NumPy functions and loops to create an ad hoc implementation of broadcasting of k and x.

@steppi
Copy link
Copy Markdown
Member

steppi commented May 8, 2026

@fbourgey, to help you keep on track, I recommend pairing each xsf PR adding a new function to an associated SciPy PR adding a new ufunc/gufunc (temporarily checking out and pinning the xsf subproject to your xsf PR branch). This is the workflow I use.

@fbourgey
Copy link
Copy Markdown
Member Author

fbourgey commented May 8, 2026

Thanks all. I will make this a scalar kernel ASAP.

@steppi regarding your comment, should I go ahead and submit a PR on SciPy for #130?

@steppi
Copy link
Copy Markdown
Member

steppi commented May 8, 2026

Thanks all. I will make this a scalar kernel ASAP.

@steppi regarding your comment, should I go ahead and submit a PR on SciPy for #130?

Yeah, when it's ready. Usually what I try to do is work on SciPy and xsf feature branches in parallel and PR them at the same time when they are ready for review. Then we can merge the xsf PR first, make an xsf release, and then change the xsf submodule in the SciPy from your associated xsf feature branch to the new release.

@fbourgey
Copy link
Copy Markdown
Member Author

fbourgey commented May 8, 2026

Sounds good. #130 has been merged already but maybe we can merge #112 and #111 before making a new xsf release?

@fbourgey
Copy link
Copy Markdown
Member Author

fbourgey commented May 8, 2026

@dschmitz89 I've tried to make this a scalar kernel and added a few tests with some SciPy reference values.

Copy link
Copy Markdown
Contributor

@dschmitz89 dschmitz89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can get this into the next xsf release once the merge conflicts are resolved.

My main blocker is adding references: does the current SciPy code or the PR that added this include some useful ones?

Comment thread include/xsf/stats.h Outdated
Comment on lines +311 to +312
R = 0;
V = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you just followed the code in SciPy but let's use typical C++ style and use lower letters for variables.

@fbourgey
Copy link
Copy Markdown
Member Author

fbourgey commented May 9, 2026

I think we can get this into the next xsf release once the merge conflicts are resolved.

My main blocker is adding references: does the current SciPy code or the PR that added this include some useful ones?

@dschmitz89 I've used lower case letters, strengthen test coverage. I've added the same tests as those in scipy/stats/tests/test_distributions.py::TestVonMises. Let me know what you think.

@dschmitz89
Copy link
Copy Markdown
Contributor

Thanks @fbourgey , tests and implementation look good! I would still like to add a reference to the code comments.

@fbourgey
Copy link
Copy Markdown
Member Author

Thanks @fbourgey , tests and implementation look good! I would still like to add a reference to the code comments.

Sorry, I missed that. I've just added a ref.

Comment thread include/xsf/stats.h Outdated
}

XSF_HOST_DEVICE inline double von_mises_cdf_normalapprox(double k, double x) {
double b = xsf::cephes::detail::SQRT2OPI / cephes::i0e(k); // Check for negative k
Copy link
Copy Markdown
Member

@j-bowhay j-bowhay May 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its not entirely clear what the "check for negative k" comment means?

Comment thread tests/xsf_tests/test_von_mises_cdf.cpp Outdated
#include <xsf/stats.h>

TEST_CASE("von Mises CDF test", "[von_mises_cdf][xsf_tests]") {
// Reference values from scipy.stats._stats
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to include the permalink since presumably von_mises_cdf will be removed at some point if it is replaced by this

…rresponding test case + remove stale comment
@fbourgey
Copy link
Copy Markdown
Member Author

@dschmitz89 @j-bowhay do you think this can be merged now?

@dschmitz89 dschmitz89 merged commit 5e064af into scipy:main May 15, 2026
4 of 6 checks passed
@fbourgey fbourgey deleted the von_mises_cdf branch May 15, 2026 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants