Cython and Python API for special functions.
Project description
This package provides both Python and Cython interfaces for Bessel functions and a few other special functions.
Features
Lightweight: This package requires no python dependency at runtime.
Cython interface: Both Python and Cython interfaces are available.
Releasing GIL: Most importantly, the functions can be used in with nogil: environment, which is essential in parallel OpenMP applications with Cython.
Tutorial
Launch online interactive notebook with Binder.
Links
Install
Supported Platforms
Successful installation and tests have been performed on the following platforms and Python/PyPy versions shown in the table below.
Platform |
Arch |
Python Version |
PyPy Version 1 |
Continuous Integration |
|||||
---|---|---|---|---|---|---|---|---|---|
3.9 |
3.10 |
3.11 |
3.12 |
3.8 |
3.9 |
3.10 |
|||
Linux |
X86-64 |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
|
AARCH-64 |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
||
macOS |
X86-64 |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
|
ARM-64 |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
||
Windows |
X86-64 |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
✔ |
Python wheels for special_functions for all supported platforms and versions in the above are available through PyPI and Anaconda Cloud. If you need special_functions on other platforms, architectures, and Python or PyPy versions, raise an issue on GitHub and we build its Python Wheel for you.
Dependencies
At runtime: This package does not have any dependencies at runtime.
For tests: To run Test, scipy package is required and can be installed by
python -m pip install -r tests/requirements.txt
Install Package
Either Install from PyPi, Install from Anaconda Cloud, or Build and Install from Source Code.
Install from PyPi
The recommended installation method is through the package available at PyPi using pip.
Ensure pip is installed within Python and upgrade the existing pip by
python -m ensurepip python -m pip install --upgrade pip
If you are using PyPy instead of Python, ensure pip is installed and upgrade the existing pip by
pypy -m ensurepip pypy -m pip install --upgrade pip
Install this package in Python by
python -m pip install special_functions
or, in PyPy by
pypy -m pip install special_functions
Install from Anaconda Cloud
Alternatively, the package can be installed through Anaconda could.
In Linux and Windows:
conda install -c s-ameli special_functions
In macOS:
conda install -c s-ameli -c conda-forge special_functions
Build and Install from Source Code
Build dependencies: To build the package from the source code, numpy and cython are required. These dependencies are installed automatically during the build process and no action is needed.
Install both C and Fortran compilers as follows.
Linux: Install gcc, for instance, by apt (or any other package manager on your Linux distro)
sudo apt install gcc gfortran
macOS: Install gcc via Homebrew:
sudo brew install gcc
Note: If gcc is already installed, but Fortran compiler is yet not available on macOS, you may resolve this issue by reinstalling:
sudo brew reinstall gcc
Windows: Install both Microsoft Visual C++ compiler and Intel Fortran compiler (Intel oneAPI). Open the command prompt (where you will enter the installation commands in the next step) and load the Intel compiler variables by
C:\Program Files (x86)\Intel\oneAPI\setvars.bat
Here, we assumed the Intel Fortran compiler is installed in C:\Program Files (x86)\Intel\oneAPI. You may set this directory accordingly to the directory of your Intel compiler.
Clone the source code and install this package by
git clone https://github.com/ameli/special_functions.git cd special_functions python -m pip install .
Warning: After the package is built and installed from the source code, the package cannot be imported properly if the current working directory is the same as the source code directory. To properly import the package, change the current working directory to a directory anywhere else outside of the source code directory. For instance:
cd ..
python
>>> import special_functions
Test
To test package, install tox:
python -m pip install tox
and test the package with
tox
List of Functions
Python API
Syntax |
Symbol |
User guide |
---|---|---|
besselj(nu, z, n) |
||
bessely(nu, z, n) |
Bessel function of the second kind (Weber function) |
|
besseli(nu, z, n) |
||
besselk(nu, z, n) |
||
besselh(nu, k, z, n) |
Bessel function of the third kind (Hankel function) |
|
lngamma(x) |
Typed Arguments:
Argument |
Type |
Symbol |
Description |
---|---|---|---|
nu |
double |
Parameter of Bessel functions. |
|
k |
int |
Can be 1 or 2 and sets the type of Hankel function. |
|
z |
double, double complex |
Real or complex argument of the Bessel functions. |
|
x |
double |
Real argument of the functions. |
|
n |
int |
Order of derivative of function. Zero indicates no derivative. |
Cython API
In Cython interface, the syntax of the real functions are similar to the Python interface. However, the syntax of complex functions start with the letter c in the beginning of each function as shown in the table below.
Symbol |
Real Function |
Complex Function |
---|---|---|
besselj(nu, x, n) |
cbesselj(nu, z, n) |
|
bessely(nu, x, n) |
cbessely(nu, z, n) |
|
besseli(nu, x, n) |
cbesseli(nu, z, n) |
|
besselk(nu, x, n) |
cbesselk(nu, z, n) |
|
besselh(nu, k, x, n) |
cbesselh(nu, k, z, n) |
|
lngamma(x) |
N/A |
Examples
Using in Cython Code
The codes below should be used in a .pyx file and compiled with Cython.
As shown in the codes below, the python’s global lock interpreter, or gil, can be optionally released inside the scope of with nogil: statement. This is especially useful in parallel OpenMP environments.
Real Function
This example shows the real function besselk to compute the modified Bessel function of the second kind for a real argument z. The output variables d0k, d1k, and d2k represent the values of modified Bessel function and its first and second derivatives, respectively.
>>> # cimport module in a *.pyx file
>>> from special_functions cimport besselk
>>> # Declare typed variables
>>> cdef double nu = 2.5
>>> cdef double z = 2.0
>>> cdef double d0k, d1k, d2k
>>> # Releasing gil to secure maximum cythonic speedup
>>> with nogil:
... d0k = besselk(nu, z, 0) # no derivative
... d1k = besselk(nu, z, 1) # 1st derivative
... d2k = besselk(nu, z, 2) # 2nd derivative
Complex Function
The example below is similar to the above, except, the complex function cbesselk with complex argument z is used. The output variables d0k, d1k, and d2k are also complex.
>>> # cimport module in a *.pyx file
>>> from special_functions cimport cbesselk
>>> # Declare typed variables
>>> cdef double nu = 2.5
>>> cdef double complex z = 2.0 + 1.0j
>>> cdef double complex d0k, d1k, d2k
>>> # Releasing gil to secure maximum cythonic speedup
>>> with nogil:
... d0k = cbesselk(nu, z, 0) # no derivative
... d1k = cbesselk(nu, z, 1) # 1st derivative
... d2k = cbesselk(nu, z, 2) # 2nd derivative
Using in Python Code
The codes below should be used in a .py file and no compilation is required. The python’s global lock interpreter, or gil, cannot be released.
Real Function
The example below uses the function besselk with the real argument z to compute the modified Bessel function of the second kind and its first and second derivatives.
>>> # import module in a *.py file
>>> from special_functions import besselk
>>> nu = 2.5
>>> z = 2.0
>>> d0k = besselk(nu, z) # no derivative
>>> d1k = besselk(nu, z, 1) # 1st derivative
>>> d2k = besselk(nu, z, 2) # 2nd derivative
Complex Function
To use a complex input argument z in the Python interface, the same function besselk as the previous example can be used. This is unlike the Cython interface in which cbesselk should be used.
>>> # import module in a *.py file
>>> from special_functions import besselk
>>> nu = 2.5
>>> z = 2.0 + 1.0j
>>> d0k = besselk(nu, z) # no derivative
>>> d1k = besselk(nu, z, 1) # 1st derivative
>>> d2k = besselk(nu, z, 2) # 2nd derivative
Acknowledgements
National Science Foundation #1520825
American Heart Association #18EIA33900046
Citation
Credit
This package uses the following libraries:
Amos, D. E. (1986). Algorithm 644: A portable package for Bessel functions of a complex argument and nonnegative order. ACM Trans. Math. Softw. 12, 3 (Sept. 1986), 265-273. DOI: https://doi.org/10.1145/7921.214331. Available at http://netlib.org/amos/.
Moshier, S. L. (1989). C language library with special functions for mathematical physics. Available at http://www.netlib.org/cephes/index.html.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for special_functions-0.3.7-pp310-pypy310_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb3af66e5ee2b8455d5e7978c6adcb3f5b00253a19654e84b7b41ff6f95c2d94 |
|
MD5 | d8018fa37ff88d08780ed091ac7a6e8e |
|
BLAKE2b-256 | 7109e05976318c38cf315100b20a1933f49768734e0f714795b0e6752b975754 |
Hashes for special_functions-0.3.7-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 063ab80aef6551b74e4adefe8aadf42f030ad47505fb3a058959416b99878d02 |
|
MD5 | 97ae15d862b642ec222a476beb6635e3 |
|
BLAKE2b-256 | 8e8c060d84c07d8c4d853005fe1d389ed2da8dee3f321e23232550485feadd9a |
Hashes for special_functions-0.3.7-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00d8dc6d96f5a78973e4c8f2f3e0b34701e87f467432bec6b6e79cdcfb1c6efe |
|
MD5 | b15cf4fe801fb199d2012a0ddfbd5d41 |
|
BLAKE2b-256 | 03ebc26f06980d4eeee728ec0862247b1b395693cb7d600301a644bf5f3fbfcd |
Hashes for special_functions-0.3.7-pp310-pypy310_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb2e4b56d1726afb4ca54b5631ef844996370dfcea69feb98f90d2cf3bdc5f90 |
|
MD5 | 1d8b60ba93014e9710b53a8ce0288d4f |
|
BLAKE2b-256 | fc26e7dde9ef45494b372af4d5c8f65d7527733d4dd7fdfeb1e09694407d5864 |
Hashes for special_functions-0.3.7-pp39-pypy39_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17e40e871fdf2ca583fead55bcea0d8989bf183e724ae23837df6cbeec561286 |
|
MD5 | f4c1ff458461a077f6a3a15f736005f1 |
|
BLAKE2b-256 | 796a9f870720b61bf191214535c11ac4fa4f270c55ba6a02d6e3da329e3e9c66 |
Hashes for special_functions-0.3.7-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1088e213eb17988bad753e4e98928a45eaa5303f22a59076cb6bf6f0de195f8 |
|
MD5 | ee90fe8c9e0b62d78fd64c02c8899003 |
|
BLAKE2b-256 | 82c7a3173e9a9db0c06c2caaeecce3dc46a6e92be0c7213d4a45a84374e5439e |
Hashes for special_functions-0.3.7-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88b666f22a8029cf4c69556a5910559a5f4d403fcd748757c0c6a31de832a2af |
|
MD5 | 22de41cfffb5b12c127dc54fd484ab7e |
|
BLAKE2b-256 | 5218a1fdcdd6398aedf29dcc34aa525aad7d75efdcb3f57a71a4a9798321b45c |
Hashes for special_functions-0.3.7-pp39-pypy39_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 855533f90ca8dc106c676b00ca6f278ef8e7f2a2332ed2aae52209fd50625ad8 |
|
MD5 | 37490e4eb6f1c6c582b35a3c08183ed3 |
|
BLAKE2b-256 | 4ffefb2a289dd970a158bf90ee80f23139dd97cb8261144e72fe7185b5632ef4 |
Hashes for special_functions-0.3.7-pp38-pypy38_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c75cfbdadcc5952d832ee1b04ce5fa5035cc83cfdad21a25d33a6b2a786efc0 |
|
MD5 | f4ea4508e6ff52af656bd21698b44387 |
|
BLAKE2b-256 | 873cd792623ebe01af1fbe56ead9a14f48fc8950bfa41dfff59244004c028295 |
Hashes for special_functions-0.3.7-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92eeb82d42a3ef75913e1bf8d93258c8254d0fe727070229c81e516a23cd1756 |
|
MD5 | 79a39efef6a6e5d581cb03dee21cc490 |
|
BLAKE2b-256 | 0ad085ec03cc2bb4da5e0909a073d4e92ad8a9dbc87ee24b2b34e69b32995fb0 |
Hashes for special_functions-0.3.7-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a2f97c02b7fc41d4f597645d66c4069b4e5487628874c9e1191c39b40b4aaae |
|
MD5 | f4ad2059512b2fa810cba5c2e3fbc83c |
|
BLAKE2b-256 | fac368277f7eb04071c14bd0c329baec8d6c37f949ab741da1e6024fd13804e5 |
Hashes for special_functions-0.3.7-pp38-pypy38_pp73-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a385b19d6589dc0ae391b297b5fa636a5446f9f210ca057585525980eef2c75e |
|
MD5 | eb05309b83f5f0ca7bafd07030597978 |
|
BLAKE2b-256 | b10e398e2cfc6cc9d9af057737934699a6c4a8b45e41ae9974a196f2084b72e6 |
Hashes for special_functions-0.3.7-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b46c6bf7fda0add57b5b3082a423cfb7171020e4943aa912efa2cfe9ff41e6f0 |
|
MD5 | bf16a6056b698da8f4e277f434ae9d00 |
|
BLAKE2b-256 | 028753647a854231b72524849470f32b7c1bc6f9b45eac78fbe1204ea2b8a399 |
Hashes for special_functions-0.3.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7212571851d30d20cd31b8fc3ac6b66f9d3fad7de9ee807f7699b2b3b014e683 |
|
MD5 | 3d01574ab5bb35d7d07b75f5e0428c50 |
|
BLAKE2b-256 | 27aca6feff58cac5e9035f9140b4ca06e69c25cc4cacd32f0dca5ddb9650ba06 |
Hashes for special_functions-0.3.7-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11cf7108966dbc9fd66eb15489e24e77fc529226407f8cc8fe9913be3e0ee84f |
|
MD5 | 97e6e030de346a6916669965a0289358 |
|
BLAKE2b-256 | c12f7544d21b907ca222e914f42b093405a93fd842b607512d787f9d9e827f3a |
Hashes for special_functions-0.3.7-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2963cec90a2ff53819f3a55e93f3796d377a13d932380fab1aef309bc9e86d2 |
|
MD5 | 690c674853cdc270888ebb9b705f91b4 |
|
BLAKE2b-256 | c61d9d30ba9171898583b829eb0b791b9280b3fefcb072ffa9211c4f30d3a462 |
Hashes for special_functions-0.3.7-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c00ac0011db67064a3f9fde1a33f28fbc11a1b34315d68e9f2383169862b38b2 |
|
MD5 | 5679c3a0862dddfd5fd13589cb598d4f |
|
BLAKE2b-256 | 3e9da9eca758c2185b798a0c4559cd21919b2d5b1646ff4c714837beac0c7f48 |
Hashes for special_functions-0.3.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c384bedf18464af7b7b985010cc20c45c60a5702c5dd493e726be35aec2a339c |
|
MD5 | 73625c92be75f811c42c4a7b84b9ae5a |
|
BLAKE2b-256 | acb667dde6d382dbdeef569686e0113d8406f5f8d37bc55f9d45957976b07f13 |
Hashes for special_functions-0.3.7-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6415ccba0e1132cccf4046fd718646480e0e7cbbcdd44b7af108664424889063 |
|
MD5 | f33756f63e830d10a1fcf3cb226876c0 |
|
BLAKE2b-256 | cc219db9160a479227303a2ce416c1d97d94241cd4b6eff1126daed1e329fcc6 |
Hashes for special_functions-0.3.7-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c2f83f6d8f94eb7022280c580e3636d5111a599e5cc381b74851f4461634415 |
|
MD5 | 115ac79ada575239fd8e1fb9d6591989 |
|
BLAKE2b-256 | 498333d654d61bcf214b2c21698701fba6c8ec8fd11189569bd518241be3a4ae |
Hashes for special_functions-0.3.7-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebae65259bbf695c3806349bd750217707c814460a32d01af12c2c1f516d5bbe |
|
MD5 | 42f8d7285749620cc730e58d101aa86f |
|
BLAKE2b-256 | ca417e27eaf16da67dfbd795a88270e4f6ad76a1b8f160cc8a6b38bd8b139524 |
Hashes for special_functions-0.3.7-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | beeda39143c6e57aebeb16ea1f07d777cd1255165e7713184241cd58643821e2 |
|
MD5 | 7d95d989beec30938b1d16dfa4bbf700 |
|
BLAKE2b-256 | 256664a72841732d788cc1f480b2aa943d382665b9f06b1cca27714655a5e619 |
Hashes for special_functions-0.3.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 824a2b593d7747fbd511e5852f204ab68e9fd074699555faf494c21f7a5d5a12 |
|
MD5 | 3abecce4b0f262079ffb53b74909f625 |
|
BLAKE2b-256 | 1211b7d412f837fbfe77b3a768061c7bac31b4af2d37a456df259dc79b459d57 |
Hashes for special_functions-0.3.7-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e40d39ffa805608b98a7ae9eb7766cd4f88aaf5b2bc60127abc7d6434a7bb42f |
|
MD5 | 661be8f2b56455967e3de2e4c3a5abd0 |
|
BLAKE2b-256 | c00a3ce949956b140220af139facfd730e8520e2a23a3f4abf167d5f2758f9c1 |
Hashes for special_functions-0.3.7-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32921e8eb7373f5ed9a97f54cf09433e077eeda3d1e96378ba1e306f53ed2e7c |
|
MD5 | aa7435a896cae7fdd673c5c37aca4edf |
|
BLAKE2b-256 | 0c6b8473073418b134ae7a726c35b9a9fc431d57cdbacde2b2a5a8ed41271b06 |
Hashes for special_functions-0.3.7-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0472cab3fa84380fed0b22b6298f7d319bfb2c71bbb66db2a6cee67587c43a59 |
|
MD5 | be4a642dfa118c9f9dad2cc5afdf311b |
|
BLAKE2b-256 | 32021b20bf15fb4a411b46042a777c023af750302b99f36de35e6e806d7c95ac |
Hashes for special_functions-0.3.7-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9926324690650862dbce81ff35f0868136d082253a33516b0b705a36c766d394 |
|
MD5 | fffb8e33551920cbdd2ad50dcdf5cc70 |
|
BLAKE2b-256 | 3c1f68c1b26933cece00bec6dc9500b0d3062752011278b7d1b9e5e3ddd3b93a |
Hashes for special_functions-0.3.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ef6522d290007df8043e4b0be16a3f6d321bb6e7df4966257c261eb8b8bc44c |
|
MD5 | faf026fc19407987cd3256f362ca257b |
|
BLAKE2b-256 | 645c5b82869619c89d771aad6634527c04c6ddcbfa34c0ecbd1af04e6ef1295a |
Hashes for special_functions-0.3.7-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21b733a48ad35ab681787375bd9a382d490dd760774a83d576e29b4346f51d55 |
|
MD5 | 4677fa9137fb5b5fe44f047499cc085e |
|
BLAKE2b-256 | 87c0d3afcca14d250b8ceaf61d13d453302e81c77dfd033c22ffbb01dda22e0d |
Hashes for special_functions-0.3.7-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b29cfcbee2947542cfa53546fc775aacdf8821e808ec3163a0457a7f1516a0a6 |
|
MD5 | f3e7f7894504731892c081f6c4566cd2 |
|
BLAKE2b-256 | 8e0b7935b03050d61201cb744a99a9ad747f1beedd06d4746b2edfa4472be68c |