rapid-roots 0.1.0__tar.gz

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.
Files changed (35) hide show
  1. rapid_roots-0.1.0/LICENSE +21 -0
  2. rapid_roots-0.1.0/PKG-INFO +231 -0
  3. rapid_roots-0.1.0/README.md +180 -0
  4. rapid_roots-0.1.0/pyproject.toml +181 -0
  5. rapid_roots-0.1.0/setup.cfg +4 -0
  6. rapid_roots-0.1.0/src/rapid_roots/__init__.py +0 -0
  7. rapid_roots-0.1.0/src/rapid_roots/py.typed +0 -0
  8. rapid_roots-0.1.0/src/rapid_roots/shared/_enum_tools.py +40 -0
  9. rapid_roots-0.1.0/src/rapid_roots/solvers/__init__.py +21 -0
  10. rapid_roots-0.1.0/src/rapid_roots/solvers/_back_up_logic.py +1160 -0
  11. rapid_roots-0.1.0/src/rapid_roots/solvers/_codegen.py +159 -0
  12. rapid_roots-0.1.0/src/rapid_roots/solvers/_enums.py +85 -0
  13. rapid_roots-0.1.0/src/rapid_roots/solvers/_jit_solvers.py +743 -0
  14. rapid_roots-0.1.0/src/rapid_roots/solvers/_solvers.py +865 -0
  15. rapid_roots-0.1.0/src/rapid_roots/solvers/_types.py +18 -0
  16. rapid_roots-0.1.0/src/rapid_roots/solvers/core.py +748 -0
  17. rapid_roots-0.1.0/src/rapid_roots.egg-info/PKG-INFO +231 -0
  18. rapid_roots-0.1.0/src/rapid_roots.egg-info/SOURCES.txt +33 -0
  19. rapid_roots-0.1.0/src/rapid_roots.egg-info/dependency_links.txt +1 -0
  20. rapid_roots-0.1.0/src/rapid_roots.egg-info/requires.txt +20 -0
  21. rapid_roots-0.1.0/src/rapid_roots.egg-info/top_level.txt +1 -0
  22. rapid_roots-0.1.0/tests/test_back_up_bracket_vectorised.py +642 -0
  23. rapid_roots-0.1.0/tests/test_back_up_open_vectorised.py +606 -0
  24. rapid_roots-0.1.0/tests/test_back_up_scalar.py +586 -0
  25. rapid_roots-0.1.0/tests/test_bisection_vectorised.py +584 -0
  26. rapid_roots-0.1.0/tests/test_brent_vectorised.py +670 -0
  27. rapid_roots-0.1.0/tests/test_codegen.py +503 -0
  28. rapid_roots-0.1.0/tests/test_core_get_root.py +974 -0
  29. rapid_roots-0.1.0/tests/test_create_substitute.py +585 -0
  30. rapid_roots-0.1.0/tests/test_jit_solvers_scalar.py +541 -0
  31. rapid_roots-0.1.0/tests/test_newton_raphson_vectorised.py +500 -0
  32. rapid_roots-0.1.0/tests/test_params_validate.py +394 -0
  33. rapid_roots-0.1.0/tests/test_solvers.py +851 -0
  34. rapid_roots-0.1.0/tests/test_try_back_up_vectorised.py +1048 -0
  35. rapid_roots-0.1.0/tests/test_use_backup_solvers.py +1167 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Cian Quezon
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.
@@ -0,0 +1,231 @@
1
+ Metadata-Version: 2.4
2
+ Name: rapid-roots
3
+ Version: 0.1.0
4
+ Summary: Numba optimised numerical root-finding solvers for multiple data points
5
+ Author-email: Cian Quezon <cdsquezon@gmail.com>
6
+ Maintainer-email: Cian Quezon <cdsquezon@gmail.com>
7
+ License: MIT
8
+ Project-URL: Homepage, https://github.com/CianQuezon/rapid-roots
9
+ Project-URL: Repository, https://github.com/CianQuezon/rapid-roots
10
+ Project-URL: Documentation, https://github.com/CianQuezon/rapid-roots#readme
11
+ Project-URL: Issues, https://github.com/CianQuezon/rapid-roots/issues
12
+ Project-URL: Changelog, https://github.com/CianQuezon/rapid-roots/releases
13
+ Keywords: root-finder,root-solver,newton-raphson,numba,vectorised,scientific-computing,equation-solver,brent,bisection,optimisation
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Intended Audience :: Education
18
+ Classifier: License :: OSI Approved :: MIT License
19
+ Classifier: Operating System :: OS Independent
20
+ Classifier: Programming Language :: Python :: 3
21
+ Classifier: Programming Language :: Python :: 3.9
22
+ Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Programming Language :: Python :: 3.12
25
+ Classifier: Programming Language :: Python :: 3.13
26
+ Classifier: Topic :: Scientific/Engineering
27
+ Classifier: Topic :: Scientific/Engineering
28
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
29
+ Classifier: Typing :: Typed
30
+ Requires-Python: >=3.8
31
+ Description-Content-Type: text/markdown
32
+ License-File: LICENSE
33
+ Requires-Dist: numpy>=1.20.0
34
+ Requires-Dist: numba>=0.56.0
35
+ Provides-Extra: dev
36
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
37
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
38
+ Requires-Dist: pytest-xdist>=3.0.0; extra == "dev"
39
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
40
+ Requires-Dist: scipy>=1.9.0; extra == "dev"
41
+ Requires-Dist: build>=0.10.0; extra == "dev"
42
+ Requires-Dist: twine>=4.0.0; extra == "dev"
43
+ Provides-Extra: test
44
+ Requires-Dist: pytest>=7.0.0; extra == "test"
45
+ Requires-Dist: pytest-cov>=4.0.0; extra == "test"
46
+ Requires-Dist: scipy>=1.9.0; extra == "test"
47
+ Provides-Extra: docs
48
+ Requires-Dist: sphinx>=5.0.0; extra == "docs"
49
+ Requires-Dist: sphinx-rtd-theme>=1.0.0; extra == "docs"
50
+ Dynamic: license-file
51
+
52
+ # Rapid-Roots
53
+
54
+ [![PyPI version](https://badge.fury.io/py/rapid-roots.svg)](https://badge.fury.io/py/rapid-roots)
55
+ [![Python 3.9+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
56
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
57
+
58
+ General parallel vectorised root solver using Numba for large data volumes.
59
+
60
+ ## Problem
61
+
62
+ Open source root-finding libraries like Scipy requires users to processes problems sequentially.
63
+
64
+ ```python
65
+ # Sequential approach (Slow)
66
+ for i in range(1_000_000):
67
+ root = scipy.optimize.brentq(func, a[i], b[i], args=(params[i],))
68
+ ```
69
+
70
+ ## Solution
71
+
72
+ rapid-roots processes all problems at once using vectorisation and parallelisation.
73
+
74
+ ```python
75
+
76
+ # Vectorised rapid-roots approach
77
+ roots, iters, converged = RootSolvers.get_root(
78
+ func, a, b, func_params=func_params, main_solver='brent', use_backup=False
79
+ )
80
+
81
+ ```
82
+
83
+ ## Quick Start
84
+ ```bash
85
+ pip install rapid-roots
86
+ ```
87
+
88
+ ```python
89
+ from rapid_roots.solvers import RootSolvers
90
+ from numba import njit
91
+ import numpy as np
92
+
93
+ @njit
94
+ def f(x, a):
95
+ return x**2 - a
96
+
97
+ @njit
98
+ def f_prime(x, a):
99
+ return 2*x
100
+
101
+
102
+ # Creates function parameter a in the equation.
103
+ params = np.full((10000, 1), 4.0)
104
+
105
+
106
+ # Creates a and b bounds for backup bracketed solvers
107
+ a = np.zeros(10000)
108
+ b = np.full(10000, 10.0)
109
+
110
+ # Creates x0 initial guess for main Newton solver
111
+ x0 = (a + b) / 2
112
+
113
+ # Vectorised solver implementation solves 10,000 problems at once.
114
+ roots, iters, converged = RootSolvers.get_root(
115
+ func=f, a=a, b=b, x0=x0, func_prime=f_prime,
116
+ func_params=params, main_solver='newton',
117
+ use_backup=True
118
+ )
119
+
120
+ print(f"Solved {converged.sum()} problems") # Solved 10,000 problems
121
+ print(f"Mean root: {roots.mean()}") # Mean root: 2.0
122
+ ```
123
+
124
+ ## API Reference
125
+
126
+ ### `RootSolvers.get_root()`
127
+
128
+ Main interface for vectorized root finding.
129
+
130
+ ```python
131
+ roots, iterations, converged = RootSolvers.get_root(
132
+ func=func, # Numba JIT-compiled function
133
+ a=None, # Lowerbound brackets for bracketing methods
134
+ b=None, # Upperbound brackets for bracketing methods
135
+ x0=None, # Initial guess for open methods (Newton)
136
+ func_prime=None, # Derivatives for open method (Newton)
137
+ func_params=None, # Parameters Array (n_problems, n_params)
138
+ main_solver='brent', # 'brent', 'bisection', or 'newton'
139
+ tol=1e-12, # Convergence tolerance
140
+ max_iter=100, # Maximum iteration
141
+ use_backup=True, # Enables automatic fallback
142
+ backup_solvers=['newton', 'bisection'] # Fallback methods for unconverged problems
143
+ )
144
+ ```
145
+ **Returns:**
146
+ - `roots`: ndArray - Found roots for each problem
147
+ - `iterations`: ndArray - Number of iterations used
148
+ - `converged`: ndArray (bool) - Convergence status for each problem
149
+
150
+ ## Performance
151
+ ![Throughput Scaling](https://github.com/CianQuezon/rapid-roots/blob/main/benchmark/generated/plots/method_throughput_line_plot.png?raw=true)
152
+
153
+ <table width="100%" align="center">
154
+ <thead>
155
+ <tr>
156
+ <th align="center">Samples</th>
157
+ <th colspan="3" align="center">Throughput (Solves/sec)</th>
158
+ </tr>
159
+ <tr>
160
+ <th></th>
161
+ <th align="center">Newton</th>
162
+ <th align="center">Brent</th>
163
+ <th align="center">Bisection</th>
164
+ </tr>
165
+ </thead>
166
+ <tbody>
167
+ <tr>
168
+ <td align="center">10K</td>
169
+ <td align="center">22,951</td>
170
+ <td align="center">19,632</td>
171
+ <td align="center">23,219</td>
172
+ </tr>
173
+ <tr>
174
+ <td align="center">100K</td>
175
+ <td align="center">231,065</td>
176
+ <td align="center">194,212</td>
177
+ <td align="center">219,248</td>
178
+ </tr>
179
+ <tr>
180
+ <td align="center">1M</td>
181
+ <td align="center">2,187,503</td>
182
+ <td align="center">1,787,564</td>
183
+ <td align="center">1,566,471</td>
184
+ </tr>
185
+ <tr>
186
+ <td align="center">10M</td>
187
+ <td align="center">15,404,269</td>
188
+ <td align="center">9,486,609</td>
189
+ <td align="center">4,589,518</td>
190
+ </tr>
191
+ </tbody>
192
+ </table>
193
+
194
+ ## Accuracy
195
+ ![Error Distribution Boxplot](https://github.com/CianQuezon/rapid-roots/blob/main/benchmark/generated/plots/error_distribution_boxplot.png?raw=true)
196
+
197
+ Box plot compares the absolute error distributions against Scipy for Brent, Bisection and Newton implementation across different function categories.
198
+
199
+ Newton shows the lowest median error with occasional ouliers in challenging categories. Brent is slightly higher in median errors with a wider interquantile range. Meanwhile Bisection displays the largest spread and highest typical error.
200
+
201
+ Results show errors approach machine precision for all methods against scipy.
202
+
203
+ ## Installation
204
+
205
+ ### Requirements
206
+
207
+ - Python ≥ 3.8
208
+ - Numpy ≥ 1.20.0
209
+ - Numba ≥ 0.56.0
210
+
211
+ ### Install from PyPI
212
+ ```bash
213
+ pip install rapid-roots
214
+ ```
215
+
216
+ ### Install from source
217
+ ```bash
218
+ git clone https://github.com/CianQuezon/rapid-roots.git
219
+ cd rapid-roots
220
+ pip install -e .
221
+ ```
222
+
223
+
224
+ ## License
225
+
226
+ This project is licensed under the MIT License - see the LICENSE file for more details.
227
+
228
+ ## Acknowledgements
229
+
230
+ - Built with [Numba](https://numba.pydata.org/)
231
+ - Validated against [Scipy](https://scipy.org/) reference implementations
@@ -0,0 +1,180 @@
1
+ # Rapid-Roots
2
+
3
+ [![PyPI version](https://badge.fury.io/py/rapid-roots.svg)](https://badge.fury.io/py/rapid-roots)
4
+ [![Python 3.9+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
+
7
+ General parallel vectorised root solver using Numba for large data volumes.
8
+
9
+ ## Problem
10
+
11
+ Open source root-finding libraries like Scipy requires users to processes problems sequentially.
12
+
13
+ ```python
14
+ # Sequential approach (Slow)
15
+ for i in range(1_000_000):
16
+ root = scipy.optimize.brentq(func, a[i], b[i], args=(params[i],))
17
+ ```
18
+
19
+ ## Solution
20
+
21
+ rapid-roots processes all problems at once using vectorisation and parallelisation.
22
+
23
+ ```python
24
+
25
+ # Vectorised rapid-roots approach
26
+ roots, iters, converged = RootSolvers.get_root(
27
+ func, a, b, func_params=func_params, main_solver='brent', use_backup=False
28
+ )
29
+
30
+ ```
31
+
32
+ ## Quick Start
33
+ ```bash
34
+ pip install rapid-roots
35
+ ```
36
+
37
+ ```python
38
+ from rapid_roots.solvers import RootSolvers
39
+ from numba import njit
40
+ import numpy as np
41
+
42
+ @njit
43
+ def f(x, a):
44
+ return x**2 - a
45
+
46
+ @njit
47
+ def f_prime(x, a):
48
+ return 2*x
49
+
50
+
51
+ # Creates function parameter a in the equation.
52
+ params = np.full((10000, 1), 4.0)
53
+
54
+
55
+ # Creates a and b bounds for backup bracketed solvers
56
+ a = np.zeros(10000)
57
+ b = np.full(10000, 10.0)
58
+
59
+ # Creates x0 initial guess for main Newton solver
60
+ x0 = (a + b) / 2
61
+
62
+ # Vectorised solver implementation solves 10,000 problems at once.
63
+ roots, iters, converged = RootSolvers.get_root(
64
+ func=f, a=a, b=b, x0=x0, func_prime=f_prime,
65
+ func_params=params, main_solver='newton',
66
+ use_backup=True
67
+ )
68
+
69
+ print(f"Solved {converged.sum()} problems") # Solved 10,000 problems
70
+ print(f"Mean root: {roots.mean()}") # Mean root: 2.0
71
+ ```
72
+
73
+ ## API Reference
74
+
75
+ ### `RootSolvers.get_root()`
76
+
77
+ Main interface for vectorized root finding.
78
+
79
+ ```python
80
+ roots, iterations, converged = RootSolvers.get_root(
81
+ func=func, # Numba JIT-compiled function
82
+ a=None, # Lowerbound brackets for bracketing methods
83
+ b=None, # Upperbound brackets for bracketing methods
84
+ x0=None, # Initial guess for open methods (Newton)
85
+ func_prime=None, # Derivatives for open method (Newton)
86
+ func_params=None, # Parameters Array (n_problems, n_params)
87
+ main_solver='brent', # 'brent', 'bisection', or 'newton'
88
+ tol=1e-12, # Convergence tolerance
89
+ max_iter=100, # Maximum iteration
90
+ use_backup=True, # Enables automatic fallback
91
+ backup_solvers=['newton', 'bisection'] # Fallback methods for unconverged problems
92
+ )
93
+ ```
94
+ **Returns:**
95
+ - `roots`: ndArray - Found roots for each problem
96
+ - `iterations`: ndArray - Number of iterations used
97
+ - `converged`: ndArray (bool) - Convergence status for each problem
98
+
99
+ ## Performance
100
+ ![Throughput Scaling](https://github.com/CianQuezon/rapid-roots/blob/main/benchmark/generated/plots/method_throughput_line_plot.png?raw=true)
101
+
102
+ <table width="100%" align="center">
103
+ <thead>
104
+ <tr>
105
+ <th align="center">Samples</th>
106
+ <th colspan="3" align="center">Throughput (Solves/sec)</th>
107
+ </tr>
108
+ <tr>
109
+ <th></th>
110
+ <th align="center">Newton</th>
111
+ <th align="center">Brent</th>
112
+ <th align="center">Bisection</th>
113
+ </tr>
114
+ </thead>
115
+ <tbody>
116
+ <tr>
117
+ <td align="center">10K</td>
118
+ <td align="center">22,951</td>
119
+ <td align="center">19,632</td>
120
+ <td align="center">23,219</td>
121
+ </tr>
122
+ <tr>
123
+ <td align="center">100K</td>
124
+ <td align="center">231,065</td>
125
+ <td align="center">194,212</td>
126
+ <td align="center">219,248</td>
127
+ </tr>
128
+ <tr>
129
+ <td align="center">1M</td>
130
+ <td align="center">2,187,503</td>
131
+ <td align="center">1,787,564</td>
132
+ <td align="center">1,566,471</td>
133
+ </tr>
134
+ <tr>
135
+ <td align="center">10M</td>
136
+ <td align="center">15,404,269</td>
137
+ <td align="center">9,486,609</td>
138
+ <td align="center">4,589,518</td>
139
+ </tr>
140
+ </tbody>
141
+ </table>
142
+
143
+ ## Accuracy
144
+ ![Error Distribution Boxplot](https://github.com/CianQuezon/rapid-roots/blob/main/benchmark/generated/plots/error_distribution_boxplot.png?raw=true)
145
+
146
+ Box plot compares the absolute error distributions against Scipy for Brent, Bisection and Newton implementation across different function categories.
147
+
148
+ Newton shows the lowest median error with occasional ouliers in challenging categories. Brent is slightly higher in median errors with a wider interquantile range. Meanwhile Bisection displays the largest spread and highest typical error.
149
+
150
+ Results show errors approach machine precision for all methods against scipy.
151
+
152
+ ## Installation
153
+
154
+ ### Requirements
155
+
156
+ - Python ≥ 3.8
157
+ - Numpy ≥ 1.20.0
158
+ - Numba ≥ 0.56.0
159
+
160
+ ### Install from PyPI
161
+ ```bash
162
+ pip install rapid-roots
163
+ ```
164
+
165
+ ### Install from source
166
+ ```bash
167
+ git clone https://github.com/CianQuezon/rapid-roots.git
168
+ cd rapid-roots
169
+ pip install -e .
170
+ ```
171
+
172
+
173
+ ## License
174
+
175
+ This project is licensed under the MIT License - see the LICENSE file for more details.
176
+
177
+ ## Acknowledgements
178
+
179
+ - Built with [Numba](https://numba.pydata.org/)
180
+ - Validated against [Scipy](https://scipy.org/) reference implementations
@@ -0,0 +1,181 @@
1
+ [build-system]
2
+ requires = ["setuptools>=65.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "rapid-roots"
7
+ version = "0.1.0"
8
+ description = "Numba optimised numerical root-finding solvers for multiple data points"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = {text="MIT"}
12
+ authors = [
13
+ {name = "Cian Quezon", email = "cdsquezon@gmail.com"}
14
+ ]
15
+ maintainers = [
16
+ {name = "Cian Quezon", email = "cdsquezon@gmail.com"}
17
+ ]
18
+
19
+ keywords = [
20
+ "root-finder",
21
+ "root-solver",
22
+ "newton-raphson",
23
+ "numba",
24
+ "vectorised",
25
+ "scientific-computing",
26
+ "equation-solver",
27
+ "brent",
28
+ "bisection",
29
+ "optimisation",
30
+ ]
31
+
32
+ classifiers = [
33
+ "Development Status :: 4 - Beta",
34
+ "Intended Audience :: Science/Research",
35
+ "Intended Audience :: Developers",
36
+ "Intended Audience :: Education",
37
+ "License :: OSI Approved :: MIT License",
38
+ "Operating System :: OS Independent",
39
+ "Programming Language :: Python :: 3",
40
+ "Programming Language :: Python :: 3.9",
41
+ "Programming Language :: Python :: 3.10",
42
+ "Programming Language :: Python :: 3.11",
43
+ "Programming Language :: Python :: 3.12",
44
+ "Programming Language :: Python :: 3.13",
45
+ "Topic :: Scientific/Engineering",
46
+ "Topic :: Scientific/Engineering",
47
+ "Topic :: Software Development :: Libraries :: Python Modules",
48
+ "Typing :: Typed",
49
+ ]
50
+
51
+ dependencies = [
52
+ "numpy>=1.20.0",
53
+ "numba>=0.56.0",
54
+ ]
55
+
56
+
57
+ [project.optional-dependencies]
58
+
59
+ dev = [
60
+ "pytest>=7.0.0",
61
+ "pytest-cov>=4.0.0",
62
+ "pytest-xdist>=3.0.0",
63
+ "ruff>=0.1.0",
64
+ "scipy>=1.9.0",
65
+ "build>=0.10.0",
66
+ "twine>=4.0.0",
67
+ ]
68
+
69
+
70
+ test = [
71
+ "pytest>=7.0.0",
72
+ "pytest-cov>=4.0.0",
73
+ "scipy>=1.9.0"
74
+ ]
75
+
76
+ docs = [
77
+ "sphinx>=5.0.0",
78
+ "sphinx-rtd-theme>=1.0.0",
79
+ ]
80
+
81
+
82
+ [project.urls]
83
+ Homepage = "https://github.com/CianQuezon/rapid-roots"
84
+ Repository = "https://github.com/CianQuezon/rapid-roots"
85
+ Documentation = "https://github.com/CianQuezon/rapid-roots#readme"
86
+ Issues = "https://github.com/CianQuezon/rapid-roots/issues"
87
+ Changelog = "https://github.com/CianQuezon/rapid-roots/releases"
88
+
89
+ [tool.setuptools]
90
+ packages = ["rapid_roots", "rapid_roots.solvers", "rapid_roots.shared"]
91
+ package-dir = {"" = "src"}
92
+
93
+ [tool.setuptools.package-data]
94
+ rapid_roots = ["py.typed"]
95
+
96
+ [tool.pytest.ini_options]
97
+ testpaths = ["tests"]
98
+ python_files = ["*_test.py", "test_*.py"]
99
+ python_functions = ["test_*"]
100
+ addopts = [
101
+ "-v",
102
+ "--strict-markers",
103
+ "--strict-config",
104
+ "--tb=short"
105
+ ]
106
+
107
+ markers = [
108
+ "slow: marks tests as slow (deselect with '-m \"not slow\"')",
109
+ "unit: marks tests as unit tests",
110
+ "integration: marks tests as integration tests",
111
+ ]
112
+
113
+ [tool.coverage.report]
114
+ exclude_lines = [
115
+ "pragma: no cover",
116
+ "def __repr__",
117
+ "def __str__",
118
+ "raise AssertionError",
119
+ "raise NotImplementedError",
120
+ "if __name__ == .__main__.:",
121
+ "if TYPE_CHECKING:",
122
+ "if typing.TYPE_CHECKING:",
123
+ "@abstractmethod",
124
+ "@abc.abstractmethod",
125
+ ]
126
+
127
+ precision = 2
128
+ show_missing = true
129
+
130
+ [tool.coverage.html]
131
+ directory = "htmlcov"
132
+
133
+
134
+ [tool.ruff]
135
+ lint.select = [
136
+ "E", # pycodestyle errors
137
+ "W", # pycodestyle warnings
138
+ "F", # pyflakes
139
+ "I", # isort
140
+ "B", # flake8-bugbear
141
+ "C4", # flake8-comprehensions
142
+ "UP", # pyupgrade
143
+ "ARG", # flake8-unused-arguments
144
+ "SIM", # flake8-simplify
145
+ ]
146
+
147
+ lint.ignore = [
148
+ "E501", # line too long (handled by formatter)
149
+ "B008", # do not perform function calls in argument defaults
150
+ "C901", # too complex
151
+ "W191", # indentation contains tabs
152
+ ]
153
+
154
+ [tool.ruff.lint.per-file-ignores]
155
+ "tests/*" = ["ARG", "S101"] # Allow assert and unused arguments in tests
156
+
157
+ [tool.ruff.format]
158
+ quote-style = "double"
159
+ indent-style = "space"
160
+ skip-magic-trailing-comma = false
161
+ line-ending = "auto"
162
+
163
+ [tool.mypy]
164
+ python_version = "3.9"
165
+ warn_return_any = true
166
+ warn_unused_configs = true
167
+ disallow_untyped_defs = false
168
+ disallow_incomplete_defs = false
169
+ check_untyped_defs = true
170
+ disallow_untyped_decorators = false
171
+ no_implicit_optional = true
172
+ warn_redundant_casts = true
173
+ warn_unused_ignores = true
174
+ warn_no_return = true
175
+ follow_imports = "normal"
176
+ ignore_missing_imports = true
177
+
178
+ [[tool.mypy.overrides]]
179
+ module = "tests.*"
180
+ disallow_untyped_defs = false
181
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
File without changes
File without changes
@@ -0,0 +1,40 @@
1
+ """
2
+ reusable tools for validating and checking enums.
3
+
4
+ Author: Cian Quezon
5
+ """
6
+
7
+ from enum import Enum
8
+ from typing import TypeVar, Union
9
+
10
+ E = TypeVar("E", bound=Enum)
11
+
12
+
13
+ def parse_enum(value: Union[str, E], enum_class: type[E]) -> E:
14
+ """
15
+ returns the enum based on the string input or enum type input
16
+
17
+ Args:
18
+ - value(Union[str, E]) = enum string or type
19
+ - enum(Type[E]) = primary enum
20
+
21
+ Returns:
22
+ - Returns the enum selected
23
+ """
24
+ if isinstance(value, enum_class):
25
+ return value
26
+
27
+ if isinstance(value, str):
28
+ try:
29
+ final_enum = enum_class(value.lower())
30
+ return final_enum
31
+
32
+ except ValueError as err:
33
+ valid_enums = ", ".join([e.value for e in enum_class])
34
+ raise ValueError(
35
+ f"Invalid enum '{value}'. Available are the following: [{valid_enums}]"
36
+ ) from err
37
+
38
+ raise TypeError(
39
+ f"value must be str or {enum_class.__name__}, got {type(value).__name__}"
40
+ )
@@ -0,0 +1,21 @@
1
+ from rapid_roots.solvers._enums import MethodType, SolverName
2
+ from rapid_roots.solvers._solvers import (
3
+ BisectionSolver,
4
+ BrentSolver,
5
+ NewtonRaphsonSolver,
6
+ Solver,
7
+ )
8
+ from rapid_roots.solvers.core import RootSolvers
9
+
10
+ __all__ = [
11
+ "Solver",
12
+ "NewtonRaphsonSolver",
13
+ "BrentSolver",
14
+ "BisectionSolver",
15
+ "MethodType",
16
+ "SolverName",
17
+ "RootSolvers",
18
+ ]
19
+
20
+ __version__ = "0.1.0"
21
+ __author__ = "Cian Quezon"