Skip to main content

Cython and Python API for special functions.

Project description

licence docs

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

binder

Launch online interactive notebook with Binder.

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

Continuous Integration

3.9

3.10

3.11

3.12

3.8

3.9

3.10

Linux

X86-64

build-linux

AARCH-64

macOS

X86-64

build-macos

ARM-64

Windows

X86-64

build-windows

ARM-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.

* Wheels for Windows on ARM-64 architecture are exclusively available for installation through pip and cannot be installed using conda.

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

pypi format implementation pyversions

The recommended installation method is through the package available at PyPi using pip.

  1. 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
  2. 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

conda-version conda-platform

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

release

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.

  1. 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.

  2. 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

codecov-devel

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)

image06

Bessel function of the first kind

bessely(nu, z, n)

image07

Bessel function of the second kind (Weber function)

besseli(nu, z, n)

image08

Modified Bessel function of the first kind

besselk(nu, z, n)

image09

Modified Bessel function of the second kind

besselh(nu, k, z, n)

image10

Bessel function of the third kind (Hankel function)

lngamma(x)

image11

Natural logarithm of Gamma function

Typed Arguments:

Argument

Type

Symbol

Description

nu

double

image01

Parameter of Bessel functions.

k

int

image02

Can be 1 or 2 and sets the type of Hankel function.

z

double, double complex

image03

Real or complex argument of the Bessel functions.

x

double

image04

Real argument of the functions.

n

int

image05

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

image06

besselj(nu, x, n)

cbesselj(nu, z, n)

image07

bessely(nu, x, n)

cbessely(nu, z, n)

image08

besseli(nu, x, n)

cbesseli(nu, z, n)

image09

besselk(nu, x, n)

cbesselk(nu, z, n)

image10

besselh(nu, k, x, n)

cbesselh(nu, k, z, n)

image11

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

  • Ameli, S. (2022). ameli/special_functions: (v0.1.0). Zenodo. code-doi

Credit

This package uses the following libraries:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

special_functions-0.2.18.tar.gz (405.4 kB view details)

Uploaded Source

Built Distributions

special_functions-0.2.18-cp312-cp312-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.12 Windows x86-64

special_functions-0.2.18-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

special_functions-0.2.18-cp312-cp312-macosx_10_9_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.12 macOS 10.9+ x86-64

special_functions-0.2.18-cp311-cp311-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.11 Windows x86-64

special_functions-0.2.18-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

special_functions-0.2.18-cp311-cp311-macosx_10_9_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

special_functions-0.2.18-cp310-cp310-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.10 Windows x86-64

special_functions-0.2.18-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

special_functions-0.2.18-cp310-cp310-macosx_10_9_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

special_functions-0.2.18-cp39-cp39-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.9 Windows x86-64

special_functions-0.2.18-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

special_functions-0.2.18-cp39-cp39-macosx_10_9_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

File details

Details for the file special_functions-0.2.18.tar.gz.

File metadata

  • Download URL: special_functions-0.2.18.tar.gz
  • Upload date:
  • Size: 405.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for special_functions-0.2.18.tar.gz
Algorithm Hash digest
SHA256 f4e16cb8774630251f7826d6f7183c068f91b4d28771e7bb3af71a2338f4c074
MD5 0031062c00f07d6c0ebabd5869664435
BLAKE2b-256 282e921f01ddeb27fbe78b25c4bd95c1ca49258dcdf8c63b84f5432baf597b2b

See more details on using hashes here.

File details

Details for the file special_functions-0.2.18-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for special_functions-0.2.18-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 26820ac32b95f1089f331ddd440a2dcf0c977eb1d563b3ab8bf7886811abac28
MD5 83ef137503acef886de22237811f77f9
BLAKE2b-256 24bec73ddf280881c68253d744c8b867e11db18284ef6d4c7f0c36af75754a57

See more details on using hashes here.

File details

Details for the file special_functions-0.2.18-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for special_functions-0.2.18-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a74964244b12f358ecb4aa1d62ec00ecdaf116abba774a2c2f3acfa81d105c45
MD5 732ce1da8fd0715ae8c2bb16b110d9d9
BLAKE2b-256 1f6815eacc5d5613f3cfda72c2bbe706b8080711708fabd3fabb6c19644374b3

See more details on using hashes here.

File details

Details for the file special_functions-0.2.18-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for special_functions-0.2.18-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4f088f8b6e6fbb7fe7db7f12d9e92d36f8f3a0820f708e3742725d3a12d0a40c
MD5 bf67153a8372728ddbe0dc76d150040e
BLAKE2b-256 ec9f7c5565f2c04aa21b59291a44e30861e798d58f322c4b35db81545f0a4068

See more details on using hashes here.

File details

Details for the file special_functions-0.2.18-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for special_functions-0.2.18-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7f8f0a969a33ad19d42c5e648cf1a503766be3ffb4e1eb0c38b65ce73d87f979
MD5 cc585a61f4f58a25e6ac88eb94f5492d
BLAKE2b-256 bd3a9fe0f6d4c1d087d5dfec6ca04393e0d2a5da82db6eb4f20323f18ff9921d

See more details on using hashes here.

File details

Details for the file special_functions-0.2.18-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for special_functions-0.2.18-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 62bdd56aae550c6b9f2e238ad795b9d1fb701f3ecfde4d4e9c950efeaf345eaa
MD5 b36190d10cfdf96e2fc9a6c6ed4bfbf2
BLAKE2b-256 017f38724b5c5cd89afbb124f24f90fe674f25790520c46b052ddd947712e339

See more details on using hashes here.

File details

Details for the file special_functions-0.2.18-cp312-cp312-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for special_functions-0.2.18-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e919321ae0730c9665b84da6465bfd80612c700c076fc606f97db0575d9b94b2
MD5 8300612cd028bef367bc0ca47e1774c6
BLAKE2b-256 1a46f4036125195def467724ea8236ebb34106faeafb1c634e3f9affe5aa39ad

See more details on using hashes here.

File details

Details for the file special_functions-0.2.18-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for special_functions-0.2.18-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 69c8547469a3069a1f81f344772ca7feb49352bf1e7ec1091dc6fec36099dfbe
MD5 a0c941183bad32cf03c1fda514778270
BLAKE2b-256 3cb38c608cf2944110a4d5cc3764ea2720a09446f926d542ff8faa24177861d8

See more details on using hashes here.

File details

Details for the file special_functions-0.2.18-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for special_functions-0.2.18-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0185016ceeaa20fe5a776fe3710ea08acb52eb4c0f6fdbe2f2732b15a4322493
MD5 a58f500c039429fa6a35df01383f331c
BLAKE2b-256 fbdd18c1cd4a1cf57a3696472c96c682fecb46397259469b50fd1a3f7238ddf5

See more details on using hashes here.

File details

Details for the file special_functions-0.2.18-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for special_functions-0.2.18-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8bc3980481564353777d3be815dc0c06a3de5dd1abe76ea4aafc875507d93546
MD5 3bfe6b64758d4451704176657157b564
BLAKE2b-256 42be36f7c5b74ba398b6f4d7ce6c2176cb891f50c9e0cd439a4bad933d3f5e4f

See more details on using hashes here.

File details

Details for the file special_functions-0.2.18-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for special_functions-0.2.18-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8b226ee8412ae4d817d21fd4c304599c70dc76794d47ea707c971090f1d22531
MD5 bfeae6f80e1fa8827f96234b5a32c5e4
BLAKE2b-256 5a5b3cee81008850cbf0ab09c9fcb731b8060206b7290876ee435306623a9c7a

See more details on using hashes here.

File details

Details for the file special_functions-0.2.18-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for special_functions-0.2.18-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bc14afa40c5827c1cb6f9769fc906466fe933b69dc50d8b558af38eaca20800d
MD5 d59edc309e0ece9510a631bb020d0e89
BLAKE2b-256 8cba6e57b5bcf1524189aada114ebaf71609b35ed2e15f0cb1a51be4608f921f

See more details on using hashes here.

File details

Details for the file special_functions-0.2.18-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for special_functions-0.2.18-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 23d2d0fe0fdbc57fcc45a733d2a2ab48296d721fe3ef70d02f2d68a09c3bb003
MD5 5d78a84608da2015cad67b816258d1a8
BLAKE2b-256 e1ddad47dc57db3d21aa3e4a75e174f2ecd633d1d34f46173a2b5959b79ad953

See more details on using hashes here.

File details

Details for the file special_functions-0.2.18-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for special_functions-0.2.18-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 31313f9803569b77e75f7e49ccdd7434e4857efc9decd3cc36a3bec4aa0139a4
MD5 ed251511cb164b77ff75c0c7c0342f54
BLAKE2b-256 23930bafd12b00aa4bc5ac15e2eef0a2c2e3fa8f49fc3c7473702d4def49c742

See more details on using hashes here.

File details

Details for the file special_functions-0.2.18-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for special_functions-0.2.18-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dab3417666e09173954e42f1e3f86d320ff07e3c3c8f9b49536bb8b7d26d869c
MD5 589ec436517fcbc84e454baac20c5967
BLAKE2b-256 6356976728e830ee9f11e35ec2d28e9630adc627f5cd43cdb060e2f199269b09

See more details on using hashes here.

File details

Details for the file special_functions-0.2.18-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for special_functions-0.2.18-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6d41c04c2fa56a69dd2609dc6ba1f32366ad1f6fba95ff0252db3986326bd8ad
MD5 982926b2d3ec24438f0e6c3f7f179a49
BLAKE2b-256 51988a6ccda344b10c5bae29af3d8d06bbdd095da31a80a108cf3eb9222c70f9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page