computils 0.0.2__tar.gz → 0.0.3__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 (27) hide show
  1. {computils-0.0.2 → computils-0.0.3}/PKG-INFO +10 -3
  2. {computils-0.0.2 → computils-0.0.3}/pyproject.toml +16 -10
  3. {computils-0.0.2 → computils-0.0.3}/src/computils/globals.py +2 -2
  4. {computils-0.0.2 → computils-0.0.3}/src/computils.egg-info/PKG-INFO +10 -3
  5. {computils-0.0.2 → computils-0.0.3}/src/computils.egg-info/SOURCES.txt +2 -5
  6. computils-0.0.3/src/computils.egg-info/requires.txt +5 -0
  7. {computils-0.0.2 → computils-0.0.3}/src/computils.egg-info/top_level.txt +0 -1
  8. computils-0.0.2/src/tests/matrix_computations_tests.py +0 -25
  9. computils-0.0.2/src/tests/numerical_derivatives_tests.py +0 -129
  10. computils-0.0.2/src/tests/parameter_transformation_tests.py +0 -122
  11. computils-0.0.2/src/tests/test_utils.py +0 -12
  12. {computils-0.0.2 → computils-0.0.3}/LICENSE +0 -0
  13. {computils-0.0.2 → computils-0.0.3}/README.md +0 -0
  14. {computils-0.0.2 → computils-0.0.3}/setup.cfg +0 -0
  15. {computils-0.0.2 → computils-0.0.3}/src/computils/__init__.py +0 -0
  16. {computils-0.0.2 → computils-0.0.3}/src/computils/factory.py +0 -0
  17. {computils-0.0.2 → computils-0.0.3}/src/computils/fast_eval.py +0 -0
  18. {computils-0.0.2 → computils-0.0.3}/src/computils/finite_difference.py +0 -0
  19. {computils-0.0.2 → computils-0.0.3}/src/computils/gaussian_elim_spp.py +0 -0
  20. {computils-0.0.2 → computils-0.0.3}/src/computils/interpolation.py +0 -0
  21. {computils-0.0.2 → computils-0.0.3}/src/computils/matrix_computations.py +0 -0
  22. {computils-0.0.2 → computils-0.0.3}/src/computils/parallelization.py +0 -0
  23. {computils-0.0.2 → computils-0.0.3}/src/computils/parameter_transformations.py +0 -0
  24. {computils-0.0.2 → computils-0.0.3}/src/computils/performance_checking.py +0 -0
  25. {computils-0.0.2 → computils-0.0.3}/src/computils/sorting_algorithms.py +0 -0
  26. {computils-0.0.2 → computils-0.0.3}/src/computils/type_utils.py +0 -0
  27. {computils-0.0.2 → computils-0.0.3}/src/computils.egg-info/dependency_links.txt +0 -0
@@ -1,15 +1,22 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: computils
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: A package collecting functionality for various numerical computations (numerical differentiation, interpolation, optimization, sorting, parallelization).
5
- Author-email: Karim Moussa <research@k-moussa.com>
5
+ Author-email: Karim Moussa <k.moussa.science@proton.me>
6
6
  Project-URL: Homepage, https://github.com/k-moussa/computils
7
+ Project-URL: Repository, https://github.com/k-moussa/computils
7
8
  Classifier: Programming Language :: Python :: 3
8
9
  Classifier: License :: OSI Approved :: MIT License
9
10
  Classifier: Operating System :: OS Independent
10
11
  Requires-Python: >=3.7
11
12
  Description-Content-Type: text/markdown
12
13
  License-File: LICENSE
14
+ Requires-Dist: numpy>=1.26.4
15
+ Requires-Dist: scipy>=1.13.0
16
+ Requires-Dist: numba>=0.59.1
17
+ Requires-Dist: splines>=0.3.1
18
+ Requires-Dist: psutil>=5.9.0
19
+ Dynamic: license-file
13
20
 
14
21
  # computils
15
22
  A package collecting utilities and other convenient functionality for various numerical computations:
@@ -1,24 +1,25 @@
1
1
  [build-system]
2
- requires = [
3
- "setuptools>=61.0",
4
- "numpy >= 1.26.4",
5
- "scipy >= 1.13.0",
6
- "numba >= 0.59.1",
7
- "splines >= 0.3.1",
8
- "psutil>=5.9.0",
9
- ]
2
+ requires = ["setuptools>=61.0"]
10
3
  build-backend = "setuptools.build_meta"
11
4
 
12
5
  [project]
13
6
  name = "computils"
14
- version = "0.0.2"
7
+ version = "0.0.3"
15
8
  authors = [
16
- { name="Karim Moussa", email="research@k-moussa.com" },
9
+ { name="Karim Moussa", email="k.moussa.science@proton.me" },
17
10
  ]
18
11
  description = "A package collecting functionality for various numerical computations (numerical differentiation, interpolation, optimization, sorting, parallelization)."
19
12
  readme = "README.md"
20
13
  requires-python = ">=3.7"
21
14
 
15
+ dependencies = [
16
+ "numpy >= 1.26.4",
17
+ "scipy >= 1.13.0",
18
+ "numba >= 0.59.1",
19
+ "splines >= 0.3.1",
20
+ "psutil>=5.9.0",
21
+ ]
22
+
22
23
  classifiers = [
23
24
  "Programming Language :: Python :: 3",
24
25
  "License :: OSI Approved :: MIT License",
@@ -27,4 +28,9 @@ classifiers = [
27
28
 
28
29
  [project.urls]
29
30
  Homepage = "https://github.com/k-moussa/computils"
31
+ Repository = "https://github.com/k-moussa/computils"
30
32
  # Issues = "https://github.com/pypa/sampleproject/issues"
33
+
34
+ [tool.setuptools.packages.find]
35
+ where = ["src"]
36
+ include = ["computils*"]
@@ -11,8 +11,8 @@ CUBE_ROOT_MACHINE_EPS: final = np.cbrt(MACHINE_EPS) #:
11
11
  FOURTH_ROOT_MACHINE_EPS: final = np.power(MACHINE_EPS, 1/4) #:
12
12
 
13
13
  Integer: final = Union[int, np.int8, np.int16, np.int32, np.int64, np.uint8, np.uint16, np.uint32, np.uint64] #:
14
- Float: final = Union[float, np.float16, np.float32, np.float64, np.float128] #:
15
- Complex: final = Union[complex, np.complex64, np.complex128, np.complex256] #:
14
+ Float: final = Union[float, np.float16, np.float32, np.float64] #:
15
+ Complex: final = Union[complex, np.complex64, np.complex128] #:
16
16
  Scalar: final = Union[Integer, Float, Complex] #:
17
17
  Bool: final = Union[bool, np.bool_]
18
18
 
@@ -1,15 +1,22 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: computils
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: A package collecting functionality for various numerical computations (numerical differentiation, interpolation, optimization, sorting, parallelization).
5
- Author-email: Karim Moussa <research@k-moussa.com>
5
+ Author-email: Karim Moussa <k.moussa.science@proton.me>
6
6
  Project-URL: Homepage, https://github.com/k-moussa/computils
7
+ Project-URL: Repository, https://github.com/k-moussa/computils
7
8
  Classifier: Programming Language :: Python :: 3
8
9
  Classifier: License :: OSI Approved :: MIT License
9
10
  Classifier: Operating System :: OS Independent
10
11
  Requires-Python: >=3.7
11
12
  Description-Content-Type: text/markdown
12
13
  License-File: LICENSE
14
+ Requires-Dist: numpy>=1.26.4
15
+ Requires-Dist: scipy>=1.13.0
16
+ Requires-Dist: numba>=0.59.1
17
+ Requires-Dist: splines>=0.3.1
18
+ Requires-Dist: psutil>=5.9.0
19
+ Dynamic: license-file
13
20
 
14
21
  # computils
15
22
  A package collecting utilities and other convenient functionality for various numerical computations:
@@ -17,8 +17,5 @@ src/computils/type_utils.py
17
17
  src/computils.egg-info/PKG-INFO
18
18
  src/computils.egg-info/SOURCES.txt
19
19
  src/computils.egg-info/dependency_links.txt
20
- src/computils.egg-info/top_level.txt
21
- src/tests/matrix_computations_tests.py
22
- src/tests/numerical_derivatives_tests.py
23
- src/tests/parameter_transformation_tests.py
24
- src/tests/test_utils.py
20
+ src/computils.egg-info/requires.txt
21
+ src/computils.egg-info/top_level.txt
@@ -0,0 +1,5 @@
1
+ numpy>=1.26.4
2
+ scipy>=1.13.0
3
+ numba>=0.59.1
4
+ splines>=0.3.1
5
+ psutil>=5.9.0
@@ -1,25 +0,0 @@
1
- """ This module tests functionality related to matrix computations. """
2
-
3
- import unittest
4
- import numpy as np
5
- from numpy.linalg import inv
6
- from scipy.stats import wishart
7
- from test_utils import compute_max_abs_diff
8
- from computils import SEED128_1
9
- from computils.gaussian_elim_spp import compute_inverse_using_gauss_elim_spp
10
-
11
-
12
- class MatrixComputationsTests(unittest.TestCase):
13
-
14
- def test_inverse_gauss_elim_spp(self):
15
- rng = np.random.default_rng(SEED128_1)
16
- n = 50
17
- df = n + 1.0
18
- scale_matrix = np.eye(n)
19
-
20
- for i in range(100):
21
- matrix = wishart.rvs(df=df, scale=scale_matrix, random_state=rng)
22
- inverse_matrix = inv(matrix)
23
- inverse_matrix_gespp = compute_inverse_using_gauss_elim_spp(matrix)
24
- max_diff = compute_max_abs_diff(inverse_matrix, inverse_matrix_gespp)
25
- self.assertAlmostEqual(0.0, max_diff, delta=10**-8)
@@ -1,129 +0,0 @@
1
- """ This module tests the computation of numerical derivatives. """
2
-
3
- import unittest
4
- import numpy as np
5
- from computils.finite_difference import compute_gradient, compute_jacobian, compute_hessian
6
-
7
-
8
- def func_r2_to_r3(x: np.ndarray, scaling_factor: float = 1.0) -> np.ndarray:
9
- """ A test function f: R^2 -> R^3
10
-
11
- :param x: a (2,) np array of argument values.
12
- :param scaling_factor: real number (nonzero).
13
- :return: a (3,) array containing the function values
14
- """
15
-
16
- function_values = np.zeros((3,))
17
- function_values[0] = 2.0 * x[0]
18
- function_values[1] = func_r2_to_r(x)
19
- function_values[2] = -3.0 * x[1]
20
-
21
- return scaling_factor * function_values
22
-
23
-
24
- def analytical_jacobian_test_func_r2_to_r3(x: np.ndarray) -> np.ndarray:
25
- """ Analytical Jacobian of the test function f: R^2 -> R^3
26
-
27
- :param x: a (2,) np array of argument values.
28
- :return: jacobian: a (3, 2) array of first-order derivatives.
29
- """
30
-
31
- jacobian = np.zeros((3, 2))
32
- jacobian[0, 0] = 2.0
33
- jacobian[1, :] = analytical_gradient_test_func_r2_to_r(x).flatten()
34
- jacobian[2, 1] = -3.0
35
- return jacobian
36
-
37
-
38
- def func_r2_to_r(x: np.ndarray, scaling_factor: float = 1.0) -> float:
39
- """ A test function f: R^2 -> R
40
-
41
- :param x: a (2,) array of argument values.
42
- :param scaling_factor: real number (nonzero).
43
- :return: the function value (scalar).
44
- """
45
-
46
- return scaling_factor * (2.0 * x[0] ** 2 + 4.0 * x[1] ** 3 + 6.0 * x[0] * x[1])
47
-
48
-
49
- def analytical_gradient_test_func_r2_to_r(x: np.ndarray) -> np.ndarray:
50
- """ Analytical gradient of the test function f: R^2 -> R
51
-
52
- :param x: a (2,) array of argument values.
53
- :return: gradient: a (2, 1) np array of first-order derivatives.
54
- """
55
-
56
- gradient = np.zeros((2, 1))
57
- gradient[0, 0] = 4.0 * x[0] + 6.0 * x[1]
58
- gradient[1, 0] = 12.0 * x[1] ** 2 + 6.0 * x[0]
59
- return gradient
60
-
61
-
62
- def analytical_hessian_test_func_r2_to_r(x: np.ndarray) -> np.ndarray:
63
- """ Analytical hessian of the test function f: R^2 -> R
64
-
65
- :param x: a (2,) array of argument values.
66
- :return: hessian: a (2, 1) np array of first-order derivatives.
67
- """
68
-
69
- hessian = np.zeros((2, 2))
70
- hessian[0, 0] = 4.0
71
- hessian[0, 1] = hessian[1, 0] = 6.0
72
- hessian[1, 1] = 24.0 * x[1]
73
- return hessian
74
-
75
-
76
- class FiniteDifferenceTests(unittest.TestCase):
77
- @classmethod
78
- def setUpClass(cls):
79
- cls.x_values = [n * np.array([0.5, 1.0]) for n in range(-1, 10)]
80
- cls.scaling_factor = 0.9
81
-
82
- def test_gradient(self):
83
- for x in self.x_values:
84
- for include_args in (True, False):
85
- analytical_gradient = analytical_gradient_test_func_r2_to_r(x)
86
-
87
- if include_args:
88
- analytical_gradient *= self.scaling_factor
89
- numerical_gradient = compute_gradient(func_r2_to_r, x, args=(self.scaling_factor,))
90
- else:
91
- numerical_gradient = compute_gradient(func_r2_to_r, x)
92
-
93
- diffs = numerical_gradient - analytical_gradient
94
- max_diff = np.amax(np.abs(diffs))
95
- self.assertAlmostEqual(0.0, max_diff, delta=10**-8)
96
-
97
- def test_jacobian(self):
98
- for x in self.x_values:
99
- for include_args in (True, False):
100
- analytical_jacobian = analytical_jacobian_test_func_r2_to_r3(x)
101
-
102
- if include_args:
103
- analytical_jacobian *= self.scaling_factor
104
- numerical_jacobian = compute_jacobian(func_r2_to_r3, x, args=(self.scaling_factor,))
105
- else:
106
- numerical_jacobian = compute_jacobian(func_r2_to_r3, x)
107
-
108
- diffs = numerical_jacobian - analytical_jacobian
109
- max_diff = np.amax(np.abs(diffs))
110
- self.assertAlmostEqual(0.0, max_diff, delta=10**-8)
111
-
112
- def test_hessian(self):
113
- for x in self.x_values:
114
- for include_args in (True, False):
115
- analytical_hessian = analytical_hessian_test_func_r2_to_r(x)
116
-
117
- if include_args:
118
- analytical_hessian *= self.scaling_factor
119
- numerical_hessian = compute_hessian(func_r2_to_r, x, args=(self.scaling_factor,))
120
- else:
121
- numerical_hessian = compute_hessian(func_r2_to_r, x)
122
-
123
- diffs = numerical_hessian - analytical_hessian
124
- max_diff = np.amax(np.abs(diffs))
125
- self.assertAlmostEqual(0.0, max_diff, delta=10**-6)
126
-
127
-
128
- if __name__ == '__main__':
129
- unittest.main()
@@ -1,122 +0,0 @@
1
- """ This module implements tests for the parameter transformation functions. """
2
-
3
- import unittest
4
- import numpy as np
5
- import computils.parameter_transformations as pt
6
-
7
-
8
- class ParameterTransformationTests(unittest.TestCase):
9
- def test_impose_lower_bound(self):
10
- n_values = 100
11
- lower_bounds = np.linspace(start=-10.0, stop=10.0, num=n_values)
12
-
13
- for lower_bound in lower_bounds:
14
- expected_value = 1.0 + lower_bound
15
- actual_value = pt.impose_lower_bound(transformed_parameter=0.0, lower_bound=lower_bound)
16
-
17
- self.assertAlmostEqual(expected_value, actual_value, delta=10 ** (-10))
18
-
19
- def test_consistency_lower_bound_transformations(self):
20
- """ Tests consistency of the lower bound transformations by checking whether their
21
- composition yields the identity function. """
22
-
23
- n_values = 100
24
- lower_bounds = np.linspace(start=-10.0, stop=10.0, num=n_values)
25
- transformed_values = np.linspace(start=-10.0, stop=10.0, num=n_values)
26
-
27
- for lower_bound in lower_bounds:
28
- for value in transformed_values:
29
- actual_value = pt.inverse_impose_lower_bound(
30
- pt.impose_lower_bound(value, lower_bound), lower_bound)
31
-
32
- self.assertAlmostEqual(value, actual_value, delta=10 ** (-10))
33
-
34
- def test_impose_upper_bound(self):
35
- n_values = 100
36
- upper_bounds = np.linspace(start=-10.0, stop=10.0, num=n_values)
37
-
38
- for upper_bound in upper_bounds:
39
- expected_value = -1.0 + upper_bound
40
- actual_value = pt.impose_upper_bound(transformed_parameter=0.0, upper_bound=upper_bound)
41
-
42
- self.assertAlmostEqual(expected_value, actual_value, delta=10 ** (-10))
43
-
44
- def test_consistency_upper_bound_transformations(self):
45
- """ Tests consistency of the upper bound transformations by checking whether their
46
- composition yields the identity function. """
47
-
48
- n_values = 100
49
- upper_bounds = np.linspace(start=-10.0, stop=10.0, num=n_values)
50
- transformed_values = np.linspace(start=-10.0, stop=10.0, num=n_values)
51
-
52
- for upper_bound in upper_bounds:
53
- for value in transformed_values:
54
- actual_value = pt.inverse_impose_upper_bound(
55
- pt.impose_upper_bound(value, upper_bound), upper_bound)
56
-
57
- self.assertAlmostEqual(value, actual_value, delta=10 ** (-10))
58
-
59
- def test_impose_bounds(self):
60
- n_values = 100
61
- lower_bounds = np.linspace(start=-10.0, stop=10.0, num=n_values)
62
- upper_bounds = np.linspace(start=-10.0, stop=10.0, num=n_values)
63
-
64
- for lower_bound in lower_bounds:
65
- for upper_bound in upper_bounds:
66
- expected_value = (lower_bound + upper_bound) / 2.0
67
- actual_value = pt.impose_bounds(
68
- transformed_parameter=0.0, lower_bound=lower_bound, upper_bound=upper_bound)
69
-
70
- self.assertAlmostEqual(expected_value, actual_value, delta=10 ** (-10))
71
-
72
- def test_consistency_bounds_transformations(self):
73
- """ Tests consistency of the double bound transformations by checking whether their
74
- composition yields the identity function. """
75
-
76
- n_values = 100
77
- lower_bounds = np.linspace(start=-10.0, stop=10.0, num=n_values)
78
- transformed_values = np.linspace(start=-10.0, stop=10.0, num=n_values)
79
-
80
- for lower_bound in lower_bounds:
81
- upper_bound = lower_bound + 1.0
82
-
83
- for value in transformed_values:
84
- actual_value = pt.inverse_impose_bounds(
85
- pt.impose_bounds(value, lower_bound, upper_bound), lower_bound, upper_bound)
86
-
87
- self.assertAlmostEqual(value, actual_value, delta=10 ** (-10))
88
-
89
- def test_impose_upper_bound_sum(self):
90
- n_params = 3
91
- transformed_params = np.zeros((n_params,))
92
- n_values = 100
93
- upper_bounds = np.linspace(start=-10.0, stop=10.0, num=n_values)
94
-
95
- for upper_bound in upper_bounds:
96
- expected_param_value = upper_bound / (n_params + 1.0)
97
- actual_params = pt.impose_upper_bound_sum(transformed_params=transformed_params, upper_bound=upper_bound)
98
-
99
- for param in actual_params:
100
- self.assertAlmostEqual(expected_param_value, param, delta=10 ** (-10))
101
-
102
- def test_consistency_upper_bound_sum_transformations(self):
103
- """ Tests consistency of the upper bound sum transformations by checking whether their
104
- composition yields the identity function. """
105
-
106
- n_values = 100
107
- upper_bounds = np.linspace(start=-10.0, stop=10.0, num=n_values)
108
- transformed_values = np.random.normal(size=(n_values, 2))
109
-
110
- for upper_bound in upper_bounds:
111
- for i in range(n_values):
112
- transformed_params = transformed_values[i]
113
- result = pt.inverse_impose_upper_bound_sum(
114
- pt.impose_upper_bound_sum(transformed_params, upper_bound), upper_bound)
115
-
116
- diffs = result - transformed_params
117
- max_abs_diff = np.amax(np.abs(diffs))
118
- self.assertAlmostEqual(0.0, max_abs_diff, delta=10 ** (-10))
119
-
120
-
121
- if __name__ == '__main__':
122
- unittest.main()
@@ -1,12 +0,0 @@
1
- "This module collects functionality for testing. "
2
-
3
- import numpy as np
4
- from computils import FloatOrArray
5
-
6
-
7
- def compute_max_abs_diff(expected: np.ndarray, actual: np.ndarray) -> float:
8
- return float(np.amax(compute_abs_diff(expected, actual)))
9
-
10
-
11
- def compute_abs_diff(expected: FloatOrArray, actual: FloatOrArray) -> FloatOrArray:
12
- return np.abs(actual - expected)
File without changes
File without changes
File without changes