|
2 | 2 | - There is also a faster version (but more limited) implemented in c++ [diffeintC](https://github.com/iparsw/differintC) |
3 | 3 |
|
4 | 4 |
|
5 | | -## differint |
6 | | -This package is used for numerically calculating fractional derivatives and integrals (differintegrals). Options for varying definitions of the differintegral are available, including the Grunwald-Letnikov (GL), the 'improved' Grunwald-Letnikov (GLI), the Riemann-Liouville (RL), and the Caputo (L1, L2, and L2C). Through the API, you can compute differintegrals at a point or over an array of function values. |
| 5 | +# differintP |
7 | 6 |
|
8 | | -See below for an example of how to use this package, or check out the [wiki](https://github.com/differint/differint/wiki) for references, signatures, and examples for each function. |
| 7 | +**differintP** is a modern, pure Python library for **fractional calculus**—that is, for numerical differentiation and integration of arbitrary (non-integer) order. |
| 8 | +It is a high-performance fork and major modernization of the original [differint](https://github.com/differint/differint) library, with many optimizations, expanded features, and a strong emphasis on speed, completeness, and code clarity. |
9 | 9 |
|
10 | | -## Motivation |
11 | | -There is little in the way of readily available, easy-to-use code for numerical fractional calculus. What is currently available are functions that are generally either smart parts of a much larger package, or only offer one numerical algorithm. The *differint* package offers a variety of algorithms for computing differintegrals and several auxiliary functions relating to generalized binomial coefficients. |
| 10 | +> **Highlights** |
| 11 | +> - Orders of differentiation and integration: any real (fractional) value |
| 12 | +> - Fast, vectorized, and JIT-accelerated core routines (NumPy + Numba) |
| 13 | +> - GPU support (optional, via CuPy) |
| 14 | +> - Array and pointwise (endpoint) fractional derivative functions |
| 15 | +> - Covers Grünwald-Letnikov, Riemann-Liouville, Caputo, Weyl, Riesz, CRONE, and more |
| 16 | +> - Accurate for both smooth and non-smooth functions |
| 17 | +> - Extensive tests and clear, modern codebase |
| 18 | +> - MIT License |
12 | 19 |
|
13 | | -## Installation |
14 | | -This project requires Python 3+ and NumPy to run. |
| 20 | +--- |
15 | 21 |
|
16 | | -Installation from the Python Packaging index (https://pypi.python.org/pypi) is simple using pip. |
| 22 | +## 🚀 Quick Install |
17 | 23 |
|
18 | | -```python |
| 24 | +```bash |
19 | 25 | pip install differintP |
20 | | -``` |
| 26 | +```` |
| 27 | + |
| 28 | +* Optional: for GPU acceleration, also install [CuPy](https://docs.cupy.dev/en/stable/install.html): |
| 29 | + |
| 30 | + ```bash |
| 31 | + pip install cupy-cuda12x # or cupy-cuda11x, depending on your CUDA |
| 32 | + ``` |
| 33 | + |
| 34 | +--- |
| 35 | + |
| 36 | +## ✨ Features |
| 37 | + |
| 38 | +* **Fast Fractional Derivatives**: Grünwald-Letnikov (`GL`, `GLpoint`), Riemann-Liouville (`RL`, `RLpoint`), Caputo (`CaputoL1point`, etc.) |
| 39 | +* **Modern Implementations**: All methods rewritten for clarity, speed, and extensibility |
| 40 | +* **Advanced/Research Methods**: |
| 41 | + |
| 42 | + * **Weyl** (Fourier/spectral, periodic) |
| 43 | + * **Riesz** (symmetric, physical applications) |
| 44 | + * **CRONE** (for edge detection and signal processing) |
| 45 | +* **GPU-accelerated GL**: `GL_gpu` (if CuPy is installed) |
| 46 | +* **High test coverage**: Pytest, with analytical ground truths for common functions |
21 | 47 |
|
22 | | -## Included Files |
23 | | -Core File | Description |
24 | | ---------- | ----------- |
25 | | -differint/differint.py | Contains algorithms for fractional differentiation and integration. |
26 | | -tests/test.py | Testing suite containing all unit tests. |
27 | | - |
28 | | -Both of the above files have corresponding `__init__.py` files. |
29 | | - |
30 | | -Setup File | Description |
31 | | ----------- | ----------- |
32 | | -.gitignore | List of files to ignore during `git` push/pull requests. |
33 | | -CONTRIBUTING.md | Instructions for potential contributors to the *differint* project. |
34 | | -LICENSE | MIT license agreement. |
35 | | -MANIFEST.in | Selects the README file for uploading to PyPi. |
36 | | -README.md | This README file. |
37 | | -README.rst | This README file in ReStructuredText format. |
38 | | -__init__.py | `__init__` file for overall package. |
39 | | -changelog.txt | List of updates to package. |
40 | | -setup.py | Script for downloading package from `pip`. |
41 | | - |
42 | | -## Example Usage |
43 | | -Taking a fractional derivative is easy with the *differint* package. Let's take the 1/2 derivative of the square root function on the interval [0,1], using the Riemann-Liouville definition of the fractional derivative. |
| 48 | +--- |
| 49 | + |
| 50 | +## 📚 Usage Example |
44 | 51 |
|
45 | 52 | ```python |
46 | 53 | import numpy as np |
47 | | -import differint.differint as df |
| 54 | +from differintP import GL, GLpoint, Weyl, Riesz |
48 | 55 |
|
49 | | -def f(x): |
50 | | - return x**0.5 |
| 56 | +# Fractional derivative of order 0.5 of sqrt(x) on [0, 1] |
| 57 | +x = np.linspace(0, 1, 100) |
| 58 | +df_gl = GL(0.5, np.sqrt, 0, 1, 100) # Array version |
| 59 | +df_point = GLpoint(0.5, np.sqrt, 0, 1, 100) # Endpoint value |
51 | 60 |
|
52 | | -DF = df.RL(0.5, f) |
53 | | -print(DF) |
| 61 | +# Weyl and Riesz derivatives of sin(x) on [0, 2*pi] |
| 62 | +x2 = np.linspace(0, 2*np.pi, 256, endpoint=False) |
| 63 | +df_weyl = Weyl(0.5, np.sin, 0, 2*np.pi, 256) |
| 64 | +df_riesz = Riesz(0.5, np.sin, 0, 2*np.pi, 256) |
54 | 65 | ``` |
55 | 66 |
|
56 | | -You can also specify the endpoints of the domain and the number of points used as follows. |
| 67 | +See the [wiki](https://github.com/iparsw/differintP/wiki) for detailed documentation and advanced use. |
57 | 68 |
|
58 | | -```python |
59 | | -DF = df.RL(0.5, f, 0, 1, 128) |
60 | | -``` |
| 69 | +--- |
61 | 70 |
|
62 | | -For a description of all functions, their signatures, and more usage examples, see the project's [wiki](https://github.com/differint/differint/wiki). |
| 71 | +## 📑 Documentation |
63 | 72 |
|
64 | | -## Tests |
65 | | -All tests can be run with nose from the command line. Setup will automatically install nose if it is not present on your machine. |
| 73 | +* **Function Reference**: See the [Wiki](https://github.com/iparsw/differintP/wiki) for math, options, and examples for all supported methods. |
| 74 | +* **Benchmarks**: [BENCHMARK.md](https://github.com/iparsw/differintC/blob/main/BENCHMARK.md) for speed/performance notes. |
| 75 | +* **Importing**: Import main algorithms directly, See the [Wiki](https://github.com/iparsw/differintP/wiki/Namespaces). |
66 | 76 |
|
67 | | -```python |
68 | | -python setup.py tests |
69 | | -``` |
| 77 | +Of course! Here’s a suggested section for accuracy tests, following your README’s style: |
70 | 78 |
|
71 | | -Alternatively, you can run the test script directly. |
| 79 | +--- |
72 | 80 |
|
73 | | -```python |
74 | | -cd <file_path>/differint/tests/ |
75 | | -python test.py |
| 81 | +## ✅ Accuracy Tests |
| 82 | + |
| 83 | +To verify the correctness and numerical accuracy of all algorithms, see the interactive **accuracy test notebook**: |
| 84 | +[**accuracy\_test.ipynb**](https://github.com/iparsw/differintP/blob/master/accuracy_test.ipynb) |
| 85 | + |
| 86 | +This notebook compares numerical results to analytical ground truth for a variety of functions and methods, and serves as a practical demonstration and benchmark reference. |
| 87 | + |
| 88 | +--- |
| 89 | + |
| 90 | +## 🧑💻 Development and Testing |
| 91 | + |
| 92 | +* **Python ≥ 3.10** required |
| 93 | +* All code is in pure Python; C++ not required |
| 94 | +* **All tests use [pytest](https://pytest.org/)** for fast, expressive, and modern testing |
| 95 | + |
| 96 | +To run the full test suite: |
| 97 | + |
| 98 | +```bash |
| 99 | +pytest tests/ |
76 | 100 | ``` |
77 | 101 |
|
78 | | -## API Reference |
79 | | -In this section we cover the usage of the various functions within the *differint* package. |
80 | | - |
81 | | -Main Function | Usage |
82 | | -------------- | ----- |
83 | | -[GLpoint](https://github.com/differint/differint/wiki/GLpoint) | Computes the GL differintegral at a point |
84 | | -[GL](https://github.com/differint/differint/wiki/GL) | Computes the GL differintegral over an entire array of function values using the Fast Fourier Transform |
85 | | -[GLI](https://github.com/differint/differint/wiki/GLI) | Computes the improved GL differintegral over an entire array of function values |
86 | | -[CRONE](https://github.com/differint/differint/wiki/CRONE) | Calculates the GL derivative approximation using the CRONE operator. |
87 | | -[RLpoint](https://github.com/differint/differint/wiki/RLpoint) | Computes the RL differintegral at a point |
88 | | -[RL](https://github.com/differint/differint/wiki/RL) | Computes the RL differintegral over an entire array of function values using matrix methods |
89 | | -[CaputoL1point](https://github.com/differint/differint/wiki/CaputoL1point) | Computes the Caputo differintegral at a point using the L1 algorithm |
90 | | -[CaputoL2point](https://github.com/differint/differint/wiki/CaputoL2point) | Computes the Caputo differintegral at a point using the L2 algorithm |
91 | | -[CaputoL2Cpoint](https://github.com/differint/differint/wiki/CaputoL2Cpoint) | Computes the Caputo differintegral at a point using the L2C algorithm |
92 | | -[PCsolver](https://github.com/differint/differint/wiki/PCsolver) | Solves IVPs for fractional ODEs of the form ${}^CD^\alpha[y(x)]=f(x,y(x))$ using the predictor-corrector method |
93 | | - |
94 | | -Auxiliary Function | Usage |
95 | | ------------------- | ----- |
96 | | -[isInteger](https://github.com/differint/differint/wiki/isInteger) | Determine if a number is an integer |
97 | | -[isPositiveInteger](https://github.com/differint/differint/wiki/isPositiveInteger) | Determine if a number is an integer, and if it is greater than 0 |
98 | | -[checkValues](https://github.com/differint/differint/wiki/checkValues) | Used to check for valid algorithm input types |
99 | | -[GLIinterpolat](https://github.com/differint/differint/wiki/GLIinterpolat) | Define interpolating coefficients for the improved GL algorithm |
100 | | -[functionCheck](https://github.com/differint/differint/wiki/functionCheck) | Determines if algorithm function input is callable or an array of numbers |
101 | | -[poch](https://github.com/differint/differint/wiki/poch) | Computes the Pochhammer symbol |
102 | | -[Gamma](https://github.com/differint/differint/wiki/Gamma) | Computes the gamma function, an extension of the factorial to complex numbers |
103 | | -[Beta](https://github.com/differint/differint/wiki/Beta) | Computes the beta function, a function related to the binomial coefficient |
104 | | -[MittagLeffler](https://github.com/differint/differint/wiki/MittagLeffler) | Computes the two parameter Mittag-Leffler function, which is important in the solution of fractional ODEs |
105 | | -[GLcoeffs](https://github.com/differint/differint/wiki/GLcoeffs) | Determines the convolution filter composed of generalized binomial coefficients used in the GL algorithm |
106 | | -[RLcoeffs](https://github.com/differint/differint/wiki/RLcoeffs) | Calculates the coefficients used in the RLpoint and RL algorithms |
107 | | -[RLmatrix](https://github.com/differint/differint/wiki/RLmatrix) | Determines the matrix used in the RL algorithm |
108 | | -[PCcoeffs](https://github.com/differint/differint/wiki/PCcoeffs) | Determines the coefficients used in the PC algorithm |
109 | | - |
110 | | - |
111 | | -## Credits |
112 | | -Baleanu, D., Diethelm, K., Scalas, E., & Trujillo, J.J. (2012). Fractional Calculus: Models and Numerical Methods. World Scientific. |
113 | | - |
114 | | -Oldham, K.B. & Spanier, J. (1974). The Fractional Calculus: Theory and Applications of Differentiation and Integration to Arbitrary Order. Academic Press Inc. |
115 | | - |
116 | | -Karniadakis, G.E.. (2019). Handbook of Fractional Calculus with Applications Volume 3: Numerical Methods. De Gruyter. |
117 | | - |
118 | | -## License |
119 | | - |
120 | | -MIT © [Matthew Adams](2018) |
| 102 | +--- |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | +## 📝 License |
| 107 | + |
| 108 | +**MIT License** |
| 109 | +See [LICENSE](./LICENSE). |
| 110 | + |
| 111 | +--- |
| 112 | + |
| 113 | +## 🔗 Related Projects |
| 114 | + |
| 115 | +* [differint](https://github.com/differint/differint) (original library, now less maintained) |
| 116 | +* [differintC](https://github.com/iparsw/differintC) (C/C++ accelerated version by @iparsw) |
| 117 | +--- |
| 118 | + |
| 119 | +*For questions or help, open an [issue](https://github.com/iparsw/differintP/issues) or check the Discussions!* |
| 120 | + |
0 commit comments