-
-
Notifications
You must be signed in to change notification settings - Fork 11
Review request -- Mathieu fcns #60
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
Open
brorson
wants to merge
15
commits into
scipy:main
Choose a base branch
from
brorson:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0adc5a6
Update mathieu.h with improved docstrings and comments.
brorson 9f62cf0
Add new directory of Mathieu fcn impls.
brorson 204e09d
Make sure we return nan when error is encountered.
brorson b09c280
Remove non-standard d in double constant literals.
brorson 41c1f28
Merge branch 'scipy:main' into main
brorson 93a41df
Remove license file and place code under whatever license xsf uses.
brorson b8911c1
Merge branch 'main' of https://github.com/brorson/xsf_mathieu
brorson 5cbf45c
I removed my Makefile since it's not used in the Scipy CI tool. I moved
brorson cdf598b
Run clang-format on test_mathieu.cpp so it passes CI.
brorson cec5ca1
Merge branch 'scipy:main' into main
brorson 9c850da
Replaced malloc/free with std::vector, updated some comments, added
brorson 72a5146
Merge branch 'main' of https://github.com/brorson/xsf_mathieu
brorson b25ba42
Merge branch 'scipy:main' into main
brorson e32d63c
Remove mathieu.h since it doesn't belong in this dir.
brorson 7614c4e
run clang-format on all .h files.
brorson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2025 Stuart Brorson | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
CC := g++ | ||
# CC := gcc | ||
CFLAGS := -O3 -std=c++17 -fno-fast-math -march=x86-64 -m128bit-long-double | ||
#CFLAGS := -O3 -std=c++17 -fno-fast-math -mfpmath=sse -march=x86-64 -m128bit-long-double | ||
|
||
SRCS := $(wildcard *.c) | ||
OBJS := $(SRCS:.c=.o) | ||
EXES := main | ||
TARGETS = main | ||
INCLUDES := -I. -I/usr/include -I/usr/local/include | ||
LDFLAGS := -L/usr/lib/x86_64-linux-gnu/lapack/ | ||
#LDFLAGS := -L/usr/lib/x86_64-linux-gnu/openblas-pthread/ -L/usr/lib -L/usr/local/lib | ||
#INCLUDES := -I. -I/usr/include/x86_64-linux-gnu/ | ||
#LDFLAGS := -L/usr/lib/x86_64-linux-gnu | ||
LIBS := -llapacke -llapack -lblas -lm | ||
|
||
|
||
#================================================= | ||
all: $(TARGETS) | ||
|
||
# Link all object files into the executable | ||
$(TARGETS): $(OBJS) | ||
$(CC) $(OBJS) -o $@ $(CFLAGS) $(LDFLAGS) $(LIBS) | ||
|
||
# Compile each .c into a .o | ||
%.o: %.c %.h | ||
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ | ||
|
||
# Also handle .c files without headers | ||
%.o: %.c | ||
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ | ||
|
||
#------------------------------- | ||
# Clean up directory -- remove executables and intermediate files. | ||
clean: | ||
-rm -f *~ *.o *.obj *.out *.map *.h.gch $(TARGETS) $(OBJS) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
This is an implementation of the Mathieu fcns in C/C++. The | ||
implementation follows the prototype algos created in Matlab and | ||
maintained on GitHub at | ||
https://github.com/brorson/MathieuFcnsFourier. This impl is a | ||
header-only library for compatability with Scipy's xsf library. | ||
|
||
The following Mathieu fcns are implemented: | ||
|
||
* Angular fcn ce(n,q,v) | ||
* Angular fcn se(n,q,v) | ||
* Radial (modified) fcn of first kind mc1(n,q,u) | ||
* Radial (modified) fcn of first kind ms1(n,q,u) | ||
* Radial (modified) fcn of second kind mc2(n,q,u) | ||
* Radial (modified) fcn of second kind ms2(n,q,u) | ||
|
||
Here, n = fcn order, q = frequency (geometry) parmeter, v = angular | ||
coord (radians), u = radial coord (au). | ||
|
||
I also provide the following utility fcns: | ||
|
||
* Eigenvalue a_n(q) | ||
* Eigenvalue b_n(q) | ||
* Fourier coeffs A_n^k(q) for ce fcns | ||
* Fourier coeffs B_n^k(q) for se fcns | ||
|
||
The goal is to provide a replacement of the Mathieu fcn suite used by | ||
Scipy. | ||
|
||
These programs may be built the usual way on a Linux system using the | ||
usual GNU build tools. The main() function runs some simple sanity | ||
checks on the functions. In particular, it verifies some output | ||
values against those computed by the Matlab programs. I did a lot of | ||
verification and accuracy testing on the Matlab implementations. | ||
Therefore, tests run here just make sure the C implementation's | ||
outputs match those from Matlab. The code in main() also shows how to | ||
invoke the various fcns. | ||
|
||
Summer 2025, SDB | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#ifndef BESSELJYD_H | ||
#define BESSELJYD_H | ||
|
||
#include "../config.h" | ||
#include "../bessel.h" | ||
|
||
|
||
/* | ||
* | ||
* This is part of the Mathieu function suite -- a reimplementation | ||
* of the Mathieu functions for Scipy. This file holds helpers | ||
* to the Bessel J and Y functions and also returns derivatives | ||
* of those fcns. | ||
* | ||
*/ | ||
|
||
namespace xsf { | ||
namespace mathieu { | ||
|
||
//================================================================== | ||
double besselj(int k, double z) { | ||
// This is just a thin wrapper around the Bessel impl in the | ||
// std library. | ||
double v = (double) k; | ||
return xsf::cyl_bessel_j(v, z); | ||
} | ||
|
||
//================================================================== | ||
double bessely(int k, double z) { | ||
// This is just a thin wrapper around the Bessel impl in the | ||
// std library. | ||
double v = (double) k; | ||
return xsf::cyl_bessel_y(v, z); | ||
} | ||
|
||
//================================================================== | ||
double besseljd(int k, double z) { | ||
// This returns the derivative of besselj. The deriv is | ||
// computed using common identities. | ||
double y; | ||
|
||
if (k == 0) { | ||
double v = 1.0; | ||
y = -besselj(v,z); | ||
} else { | ||
double kp1 = (double) (k+1); | ||
double km1 = (double) (k-1); | ||
y = (besselj(km1,z)-besselj(kp1,z))/2.0; | ||
} | ||
|
||
// Must flip sign for negative k and odd k. | ||
if (k<0 && ((k % 2) != 0)) { | ||
y = -y; | ||
} | ||
|
||
return y; | ||
} | ||
|
||
//================================================================== | ||
double besselyd(int k, double z) { | ||
// This returns the derivative of besselj. The deriv is | ||
// computed using common identities. | ||
double y; | ||
|
||
if (k == 0) { | ||
double v = 1.0; | ||
y = -bessely(v,z); | ||
} else { | ||
double kp1 = (double) (k+1); | ||
double km1 = (double) (k-1); | ||
y = (bessely(km1,z)-bessely(kp1,z))/2.0; | ||
} | ||
|
||
// Must flip sign for negative k and odd k. | ||
if (k<0 && ((k % 2) != 0)) { | ||
y = -y; | ||
} | ||
|
||
return y; | ||
} | ||
|
||
} // namespace xsf | ||
} // namespace mathieu | ||
|
||
#endif // #ifndef BESSELJYD_H |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.