differintC 0.0.1__cp313-cp313-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- differintc-0.0.1.dist-info/METADATA +98 -0
- differintc-0.0.1.dist-info/RECORD +6 -0
- differintc-0.0.1.dist-info/WHEEL +5 -0
- differintc-0.0.1.dist-info/licenses/LICENSE +21 -0
- python/CMakeLists.txt +17 -0
- python/module.cpp +110 -0
@@ -0,0 +1,98 @@
|
|
1
|
+
Metadata-Version: 2.2
|
2
|
+
Name: differintC
|
3
|
+
Version: 0.0.1
|
4
|
+
Summary: Fast C++ implementation of fractional calculus operators via pybind11
|
5
|
+
Author: Parsa Roshanak
|
6
|
+
License: MIT
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
9
|
+
Classifier: Programming Language :: Python
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
11
|
+
Classifier: Programming Language :: Python :: 3.8
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
16
|
+
Classifier: Programming Language :: C++
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
18
|
+
Classifier: Intended Audience :: Science/Research
|
19
|
+
Project-URL: Homepage, https://github.com/iparsw/differintC
|
20
|
+
Project-URL: Repository, https://github.com/iparsw/differintC
|
21
|
+
Project-URL: Issues, https://github.com/iparsw/differintC/issues
|
22
|
+
Requires-Python: >=3.8
|
23
|
+
Description-Content-Type: text/markdown
|
24
|
+
|
25
|
+
# differintC
|
26
|
+
|
27
|
+
`differintC` is a high-performance C++ library with Python bindings for computing fractional differintegrals (derivatives and integrals of arbitrary real order) using numerical methods.
|
28
|
+
|
29
|
+
This package implements optimized versions of the Riemann–Liouville and Grünwald–Letnikov (GL) fractional differintegral operators, inspired by the original [DifferInt project](https://placeholder-link-to-original-differint-project).
|
30
|
+
|
31
|
+
> ⚙️ Built with modern C++17 and exposed to Python via `pybind11`, this library is significantly faster than pure-Python equivalents, especially for large arrays and high-precision needs.
|
32
|
+
|
33
|
+
---
|
34
|
+
|
35
|
+
## 📦 Installation
|
36
|
+
|
37
|
+
```bash
|
38
|
+
pip install differintC
|
39
|
+
````
|
40
|
+
|
41
|
+
To build from source:
|
42
|
+
|
43
|
+
```bash
|
44
|
+
git clone https://github.com/your-username/differintC-project.git
|
45
|
+
cd differintC-project
|
46
|
+
pip install .
|
47
|
+
```
|
48
|
+
|
49
|
+
---
|
50
|
+
|
51
|
+
## 🚀 Usage
|
52
|
+
|
53
|
+
```python
|
54
|
+
from differintC import RLpoint, RL, GLpoint, GL
|
55
|
+
|
56
|
+
# Example 1: Riemann–Liouville at a single point
|
57
|
+
result = RLpoint(0.5, lambda x: x**2)
|
58
|
+
print("RLpoint(0.5, x^2) =", result)
|
59
|
+
|
60
|
+
# Example 2: RL on a whole domain
|
61
|
+
import numpy as np
|
62
|
+
x = np.linspace(0, 1, 100)
|
63
|
+
f = x**2
|
64
|
+
out = RL(0.5, f)
|
65
|
+
|
66
|
+
# Example 3: Grünwald–Letnikov pointwise
|
67
|
+
gl_res = GLpoint(0.5, lambda x: np.sqrt(x))
|
68
|
+
|
69
|
+
# Example 4: Full array version (fastest)
|
70
|
+
gl_array = GL(0.5, lambda x: np.sqrt(x))
|
71
|
+
```
|
72
|
+
|
73
|
+
All functions support either a NumPy array or a Python callable as the `f_name` argument.
|
74
|
+
|
75
|
+
---
|
76
|
+
|
77
|
+
## 📚 Implemented Functions
|
78
|
+
|
79
|
+
| Function | Description |
|
80
|
+
| --------- | ------------------------------------------- |
|
81
|
+
| `RLpoint` | Riemann–Liouville differintegral at a point |
|
82
|
+
| `RL` | RL differintegral over a uniform domain |
|
83
|
+
| `GLpoint` | Grünwald–Letnikov at a point (optimized) |
|
84
|
+
| `GL` | Vectorized GL differintegral with FFT |
|
85
|
+
|
86
|
+
---
|
87
|
+
|
88
|
+
## ⚖️ License and Credits
|
89
|
+
|
90
|
+
This package was inspired by and based on the original [`DifferInt`](https://placeholder-link-to-original-differint-project) project. We thank the authors for their foundational work in fractional calculus.
|
91
|
+
|
92
|
+
Licensed under MIT.
|
93
|
+
|
94
|
+
---
|
95
|
+
|
96
|
+
## 🛠 Development Notes
|
97
|
+
|
98
|
+
See the [todo list 1](https://github.com/your-username/differintC-project/issues/1) for the development roadmap and planned features. Contributions are welcome.
|
@@ -0,0 +1,6 @@
|
|
1
|
+
python/CMakeLists.txt,sha256=YH4PMGwp8NqUb5ZsKmOjtoRmwdjqAr9T8bcRf59sJcE,401
|
2
|
+
python/module.cpp,sha256=2ptoCWNYUXnhYlJfxMm_q6NM66goo1lB9WV6mbysTF0,5663
|
3
|
+
differintc-0.0.1.dist-info/METADATA,sha256=TPcJPxQPP4AAdefMQfHPLoj-i-IjFkDpx0ixQbe0rh8,3285
|
4
|
+
differintc-0.0.1.dist-info/WHEEL,sha256=_PdgJ-W7uMAsWwnGnEdiicDU_PKcobRdffEM23gmN6g,106
|
5
|
+
differintc-0.0.1.dist-info/licenses/LICENSE,sha256=jqB4xKqXwsqHxw3nhNfX51kOCtYhxNDQFqCIl5Qj8h4,1091
|
6
|
+
differintc-0.0.1.dist-info/RECORD,,
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 parsa roshanak
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
python/CMakeLists.txt
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
pybind11_add_module(differintC module.cpp ../src/differint.cpp)
|
2
|
+
|
3
|
+
target_include_directories(differintC
|
4
|
+
PRIVATE ${CMAKE_SOURCE_DIR}/include
|
5
|
+
)
|
6
|
+
|
7
|
+
target_link_libraries(differintC
|
8
|
+
PRIVATE differint_core
|
9
|
+
)
|
10
|
+
|
11
|
+
set_target_properties(differintC PROPERTIES
|
12
|
+
PREFIX ""
|
13
|
+
SUFFIX ".pyd"
|
14
|
+
)
|
15
|
+
|
16
|
+
install(TARGETS differintC
|
17
|
+
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/Lib/site-packages)
|
python/module.cpp
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
#include <pybind11/stl.h>
|
2
|
+
#include <pybind11/pybind11.h>
|
3
|
+
#include <pybind11/numpy.h>
|
4
|
+
#include <vector>
|
5
|
+
#include <stdexcept>
|
6
|
+
|
7
|
+
namespace py = pybind11;
|
8
|
+
|
9
|
+
namespace differint {
|
10
|
+
std::vector<double> RL(double, const std::vector<double>&, double, double, size_t);
|
11
|
+
double RLpoint(double, const std::vector<double>&, double, double, size_t);
|
12
|
+
std::vector<double> GL(double, const std::vector<double>&, double, double, size_t);
|
13
|
+
double GLpoint(double, const std::vector<double>&, double, double, size_t);
|
14
|
+
}
|
15
|
+
using namespace differint;
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
// Helper to sample a Python callable into a std::vector<double>
|
20
|
+
template <typename Func>
|
21
|
+
std::vector<double> call_and_sample(Func&& f, double a, double b, size_t n) {
|
22
|
+
std::vector<double> vals(n);
|
23
|
+
double step = (b - a) / (n - 1);
|
24
|
+
for (size_t i = 0; i < n; ++i)
|
25
|
+
vals[i] = f(a + step * i);
|
26
|
+
return vals;
|
27
|
+
}
|
28
|
+
|
29
|
+
// Overload 1: Input is a NumPy array or list (accept py::array_t<double>)
|
30
|
+
std::vector<double> prepare_fvals(py::array_t<double> arr, size_t expected_size) {
|
31
|
+
if (arr.size() != expected_size)
|
32
|
+
throw std::runtime_error("Input array length must equal num_points");
|
33
|
+
// Copy data from NumPy array (you could do zero-copy with caution, but copying is safer here)
|
34
|
+
std::vector<double> v(arr.size());
|
35
|
+
std::memcpy(v.data(), arr.data(), sizeof(double) * arr.size());
|
36
|
+
return v;
|
37
|
+
}
|
38
|
+
|
39
|
+
// Overload 2: Input is a Python callable (py::function)
|
40
|
+
std::vector<double> prepare_fvals(py::function func, double a, double b, size_t n) {
|
41
|
+
return call_and_sample([&func](double x) {
|
42
|
+
return func(x).cast<double>();
|
43
|
+
}, a, b, n);
|
44
|
+
}
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
PYBIND11_MODULE(differintC, m) {
|
51
|
+
m.doc() = "Fast fractional calculus operators in C++ with Python bindings";
|
52
|
+
|
53
|
+
// RL (whole array)
|
54
|
+
m.def("RL", [](double alpha, py::object f, double domain_start, double domain_end, size_t num_points) {
|
55
|
+
// Dispatch based on type
|
56
|
+
if (py::isinstance<py::array>(f)) {
|
57
|
+
return RL(alpha, prepare_fvals(f.cast<py::array_t<double>>(), num_points), domain_start, domain_end, num_points);
|
58
|
+
} else if (py::isinstance<py::function>(f)) {
|
59
|
+
return RL(alpha, prepare_fvals(f.cast<py::function>(), domain_start, domain_end, num_points), domain_start, domain_end, num_points);
|
60
|
+
} else if (py::isinstance<py::list>(f)) {
|
61
|
+
// treat list as array
|
62
|
+
return RL(alpha, prepare_fvals(f.cast<py::array_t<double>>(), num_points), domain_start, domain_end, num_points);
|
63
|
+
} else {
|
64
|
+
throw std::runtime_error("Unsupported input type for function f");
|
65
|
+
}
|
66
|
+
}, py::arg("alpha"), py::arg("f"), py::arg("domain_start") = 0.0, py::arg("domain_end") = 1.0, py::arg("num_points") = 100);
|
67
|
+
|
68
|
+
// RLpoint (single point)
|
69
|
+
m.def("RLpoint", [](double alpha, py::object f, double domain_start, double domain_end, size_t num_points) {
|
70
|
+
if (py::isinstance<py::array>(f)) {
|
71
|
+
return RLpoint(alpha, prepare_fvals(f.cast<py::array_t<double>>(), num_points), domain_start, domain_end, num_points);
|
72
|
+
} else if (py::isinstance<py::function>(f)) {
|
73
|
+
return RLpoint(alpha, prepare_fvals(f.cast<py::function>(), domain_start, domain_end, num_points), domain_start, domain_end, num_points);
|
74
|
+
} else if (py::isinstance<py::list>(f)) {
|
75
|
+
return RLpoint(alpha, prepare_fvals(f.cast<py::array_t<double>>(), num_points), domain_start, domain_end, num_points);
|
76
|
+
} else {
|
77
|
+
throw std::runtime_error("Unsupported input type for function f");
|
78
|
+
}
|
79
|
+
}, py::arg("alpha"), py::arg("f"), py::arg("domain_start") = 0.0, py::arg("domain_end") = 1.0, py::arg("num_points") = 100);
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
m.def("GL", [](double alpha, py::object f, double domain_start, double domain_end, size_t num_points) {
|
84
|
+
// Dispatch based on type
|
85
|
+
if (py::isinstance<py::array>(f)) {
|
86
|
+
return GL(alpha, prepare_fvals(f.cast<py::array_t<double>>(), num_points), domain_start, domain_end, num_points);
|
87
|
+
} else if (py::isinstance<py::function>(f)) {
|
88
|
+
return GL(alpha, prepare_fvals(f.cast<py::function>(), domain_start, domain_end, num_points), domain_start, domain_end, num_points);
|
89
|
+
} else if (py::isinstance<py::list>(f)) {
|
90
|
+
// treat list as array
|
91
|
+
return GL(alpha, prepare_fvals(f.cast<py::array_t<double>>(), num_points), domain_start, domain_end, num_points);
|
92
|
+
} else {
|
93
|
+
throw std::runtime_error("Unsupported input type for function f");
|
94
|
+
}
|
95
|
+
}, py::arg("alpha"), py::arg("f"), py::arg("domain_start") = 0.0, py::arg("domain_end") = 1.0, py::arg("num_points") = 100);
|
96
|
+
|
97
|
+
// GLpoint (single point)
|
98
|
+
m.def("GLpoint", [](double alpha, py::object f, double domain_start, double domain_end, size_t num_points) {
|
99
|
+
if (py::isinstance<py::array>(f)) {
|
100
|
+
return GLpoint(alpha, prepare_fvals(f.cast<py::array_t<double>>(), num_points), domain_start, domain_end, num_points);
|
101
|
+
} else if (py::isinstance<py::function>(f)) {
|
102
|
+
return GLpoint(alpha, prepare_fvals(f.cast<py::function>(), domain_start, domain_end, num_points), domain_start, domain_end, num_points);
|
103
|
+
} else if (py::isinstance<py::list>(f)) {
|
104
|
+
return GLpoint(alpha, prepare_fvals(f.cast<py::array_t<double>>(), num_points), domain_start, domain_end, num_points);
|
105
|
+
} else {
|
106
|
+
throw std::runtime_error("Unsupported input type for function f");
|
107
|
+
}
|
108
|
+
}, py::arg("alpha"), py::arg("f"), py::arg("domain_start") = 0.0, py::arg("domain_end") = 1.0, py::arg("num_points") = 100);
|
109
|
+
|
110
|
+
}
|