py-num-math 1.0.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.
- py_num_math-1.0.0/LICENCE.txt +22 -0
- py_num_math-1.0.0/PKG-INFO +28 -0
- py_num_math-1.0.0/README.md +90 -0
- py_num_math-1.0.0/py_num_math.egg-info/PKG-INFO +28 -0
- py_num_math-1.0.0/py_num_math.egg-info/SOURCES.txt +25 -0
- py_num_math-1.0.0/py_num_math.egg-info/dependency_links.txt +1 -0
- py_num_math-1.0.0/py_num_math.egg-info/requires.txt +2 -0
- py_num_math-1.0.0/py_num_math.egg-info/top_level.txt +1 -0
- py_num_math-1.0.0/pymath/__init__.py +0 -0
- py_num_math-1.0.0/pymath/src/dot_prod/dot_prod.py +13 -0
- py_num_math-1.0.0/pymath/src/fibonacci/fibonacci.py +37 -0
- py_num_math-1.0.0/pymath/src/finite_diff/finite_diff.py +46 -0
- py_num_math-1.0.0/pymath/src/matrices/rectangular_matrices.py +37 -0
- py_num_math-1.0.0/pymath/src/matrices/square_matrices.py +75 -0
- py_num_math-1.0.0/pymath/src/norms/norm_lp.py +20 -0
- py_num_math-1.0.0/pymath/src/num_seq/num_seq.py +74 -0
- py_num_math-1.0.0/pymath/src/vectors/vectors.py +51 -0
- py_num_math-1.0.0/pymath/tests/dot_prod/test_dot_prod.py +27 -0
- py_num_math-1.0.0/pymath/tests/fibonacci/test_fibonacci.py +46 -0
- py_num_math-1.0.0/pymath/tests/finite_diff/test_finite_diff.py +116 -0
- py_num_math-1.0.0/pymath/tests/matrices/test_rectangular_matrices.py +72 -0
- py_num_math-1.0.0/pymath/tests/matrices/test_square_matrices.py +63 -0
- py_num_math-1.0.0/pymath/tests/norms/test_norm_lp.py +26 -0
- py_num_math-1.0.0/pymath/tests/num_seq/test_num_seq.py +71 -0
- py_num_math-1.0.0/pymath/tests/vectors/test_vectors.py +65 -0
- py_num_math-1.0.0/setup.cfg +4 -0
- py_num_math-1.0.0/setup.py +29 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2026 Diouf Tech
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
Quote Diouf Tech in any of your work using this package, or PayPal us :
|
|
14
|
+
https://www.paypal.com/paypalme/mathgamepy
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: py_num_math
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Python package for mathematical numerical tools.
|
|
5
|
+
Home-page: https://www.paypal.com/paypalme/mathgamepy
|
|
6
|
+
Author: Aliou Diouf
|
|
7
|
+
Author-email: aliou.diouf5@gmail.com
|
|
8
|
+
License: Diouf Tech
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: License :: Free To Use But Restricted
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
12
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENCE.txt
|
|
15
|
+
Requires-Dist: flake8
|
|
16
|
+
Requires-Dist: pytest
|
|
17
|
+
Dynamic: author
|
|
18
|
+
Dynamic: author-email
|
|
19
|
+
Dynamic: classifier
|
|
20
|
+
Dynamic: description
|
|
21
|
+
Dynamic: description-content-type
|
|
22
|
+
Dynamic: home-page
|
|
23
|
+
Dynamic: license
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
Dynamic: requires-dist
|
|
26
|
+
Dynamic: summary
|
|
27
|
+
|
|
28
|
+
Python package for mathematical numerical tools.
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# pymath
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
## Python Mathematics
|
|
5
|
+
|
|
6
|
+
Math utilities in Python
|
|
7
|
+
|
|
8
|
+
A package for numerical Mathematics in Python
|
|
9
|
+
|
|
10
|
+
## Author
|
|
11
|
+
* Aliou Diouf,
|
|
12
|
+
* Graduated from University, Paul Sabatier Toulouse 3, in
|
|
13
|
+
* Applied Mathematics, speciality Scientific Computing:
|
|
14
|
+
* Numerical Analysis, PDE, Software Engineering, Images processing, Signal processing,
|
|
15
|
+
Aerospace, HR, English...
|
|
16
|
+
|
|
17
|
+
* CEO and Founder of Diouf Tech, a STEM company headquartered in Paris
|
|
18
|
+
|
|
19
|
+
* E-mail: aliou.diouf5@gmail.com
|
|
20
|
+
* My LinkedIn: https://www.linkedin.com/in/aliou-diouf-7b980441b/
|
|
21
|
+
* My personal Facebook: https://www.facebook.com/aliou.diouf.587/
|
|
22
|
+
|
|
23
|
+
## Our product
|
|
24
|
+
|
|
25
|
+
* https://www.mathgame-py.com
|
|
26
|
+
|
|
27
|
+
## Company: Diouf Tech
|
|
28
|
+
|
|
29
|
+
* PayPal: https://www.paypal.com/paypalme/mathgamepy
|
|
30
|
+
* Facebook page: https://www.facebook.com/profile.php?id=100086476192955
|
|
31
|
+
* address: 149, Avenue du Maine, 75014 Paris, France
|
|
32
|
+
* Location: France
|
|
33
|
+
* Target: Worldwide
|
|
34
|
+
|
|
35
|
+
## Test and Deploy
|
|
36
|
+
|
|
37
|
+
* Tests: pymath/tests
|
|
38
|
+
* All tests must pass. However, some tests may be environment (computer, OS, Python...) precision dependant.
|
|
39
|
+
|
|
40
|
+
* If you need consultant, feel free to e-mail: aliou.diouf5@gmail.com
|
|
41
|
+
* For deployment, we are AWS-oriented
|
|
42
|
+
* We prefer empty EC2 server. We can scale it over the time according to usage
|
|
43
|
+
|
|
44
|
+
***
|
|
45
|
+
|
|
46
|
+
# This README
|
|
47
|
+
|
|
48
|
+
Describes pymath idea, goal, context, usages ...
|
|
49
|
+
|
|
50
|
+
## Suggestions
|
|
51
|
+
|
|
52
|
+
Read it entirely.
|
|
53
|
+
|
|
54
|
+
## pymath
|
|
55
|
+
pymath stands for Python Mathematics.
|
|
56
|
+
|
|
57
|
+
## Description
|
|
58
|
+
A package for numerical Mathematics in Python, can be used in numerical simulations.
|
|
59
|
+
|
|
60
|
+
## Visuals
|
|
61
|
+
Diouf Tech logo.
|
|
62
|
+
|
|
63
|
+
## Installation
|
|
64
|
+
* pip install pymath
|
|
65
|
+
* Locally: pip install .
|
|
66
|
+
|
|
67
|
+
## Usages
|
|
68
|
+
* import pymath
|
|
69
|
+
* from pymath.src.dir_name.file_name import the_function_you_want
|
|
70
|
+
* For tests: pytest
|
|
71
|
+
|
|
72
|
+
## Support
|
|
73
|
+
E-mail to: aliou.diouf5@gmail.com
|
|
74
|
+
|
|
75
|
+
## Roadmap
|
|
76
|
+
Under development
|
|
77
|
+
|
|
78
|
+
## Contributing
|
|
79
|
+
* We cannot invite people without financial support.
|
|
80
|
+
* We prefer financial support:
|
|
81
|
+
* PayPal: https://www.paypal.com/paypalme/mathgamepy
|
|
82
|
+
|
|
83
|
+
## Authors and acknowledgment
|
|
84
|
+
Aliou Diouf (aliou.diouf5@gmail.com)
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
Diouf Tech License.
|
|
88
|
+
|
|
89
|
+
## Project status
|
|
90
|
+
Ongoing
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: py_num_math
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Python package for mathematical numerical tools.
|
|
5
|
+
Home-page: https://www.paypal.com/paypalme/mathgamepy
|
|
6
|
+
Author: Aliou Diouf
|
|
7
|
+
Author-email: aliou.diouf5@gmail.com
|
|
8
|
+
License: Diouf Tech
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: License :: Free To Use But Restricted
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
12
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENCE.txt
|
|
15
|
+
Requires-Dist: flake8
|
|
16
|
+
Requires-Dist: pytest
|
|
17
|
+
Dynamic: author
|
|
18
|
+
Dynamic: author-email
|
|
19
|
+
Dynamic: classifier
|
|
20
|
+
Dynamic: description
|
|
21
|
+
Dynamic: description-content-type
|
|
22
|
+
Dynamic: home-page
|
|
23
|
+
Dynamic: license
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
Dynamic: requires-dist
|
|
26
|
+
Dynamic: summary
|
|
27
|
+
|
|
28
|
+
Python package for mathematical numerical tools.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
LICENCE.txt
|
|
2
|
+
README.md
|
|
3
|
+
setup.py
|
|
4
|
+
py_num_math.egg-info/PKG-INFO
|
|
5
|
+
py_num_math.egg-info/SOURCES.txt
|
|
6
|
+
py_num_math.egg-info/dependency_links.txt
|
|
7
|
+
py_num_math.egg-info/requires.txt
|
|
8
|
+
py_num_math.egg-info/top_level.txt
|
|
9
|
+
pymath/__init__.py
|
|
10
|
+
pymath/src/dot_prod/dot_prod.py
|
|
11
|
+
pymath/src/fibonacci/fibonacci.py
|
|
12
|
+
pymath/src/finite_diff/finite_diff.py
|
|
13
|
+
pymath/src/matrices/rectangular_matrices.py
|
|
14
|
+
pymath/src/matrices/square_matrices.py
|
|
15
|
+
pymath/src/norms/norm_lp.py
|
|
16
|
+
pymath/src/num_seq/num_seq.py
|
|
17
|
+
pymath/src/vectors/vectors.py
|
|
18
|
+
pymath/tests/dot_prod/test_dot_prod.py
|
|
19
|
+
pymath/tests/fibonacci/test_fibonacci.py
|
|
20
|
+
pymath/tests/finite_diff/test_finite_diff.py
|
|
21
|
+
pymath/tests/matrices/test_rectangular_matrices.py
|
|
22
|
+
pymath/tests/matrices/test_square_matrices.py
|
|
23
|
+
pymath/tests/norms/test_norm_lp.py
|
|
24
|
+
pymath/tests/num_seq/test_num_seq.py
|
|
25
|
+
pymath/tests/vectors/test_vectors.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pymath
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Dot product without external library
|
|
3
|
+
Aliou Diouf, graduated from Toulouse University, in Applied Mathematics,
|
|
4
|
+
President and Founder of Diouf Tech, A STEM company headquartered in Paris
|
|
5
|
+
Our product: www.mathgame-py.com
|
|
6
|
+
https://www.paypal.com/paypalme/mathgamepy
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def dot_prod(x, y):
|
|
11
|
+
"""Dot product between x and y, where x and y are vectors"""
|
|
12
|
+
|
|
13
|
+
return sum([x_i * y_i for x_i, y_i in zip(x, y)])
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Fibonacci without library
|
|
3
|
+
Author: Aliou Diouf - Master degree from University, Paul Sabatier Toulouse 3,
|
|
4
|
+
in Applied Mathematics, speciality Scientific Computing (Numerical Analysis,
|
|
5
|
+
PDE, Software Engineering, Images&Signal processing, Aerospace, HR, English...)
|
|
6
|
+
CEO and Founder of Diouf Tech, a STEM company headquartered in Paris (75014)
|
|
7
|
+
Products: www.mathgame-py.com, https://www.paypal.com/paypalme/mathgamepy
|
|
8
|
+
Facebook page: https://www.facebook.com/profile.php?id=100086476192955
|
|
9
|
+
My personal Facebook: https://www.facebook.com/aliou.diouf.587/
|
|
10
|
+
My LinkedIn: https://www.linkedin.com/in/aliou-diouf-7b980441b/
|
|
11
|
+
My PyPI packages: https://pypi.org/project/py-ci-cd,
|
|
12
|
+
https://pypi.org/project/pymeshing
|
|
13
|
+
https://pypi.org/project/passwordworld
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def fib(p):
|
|
18
|
+
"""
|
|
19
|
+
Yields the p terms of Fibonacci sequence, from F1.
|
|
20
|
+
Note:
|
|
21
|
+
F0 = 0
|
|
22
|
+
F1 = 1
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
# Initialization (F0 = 0, F1 = 1, first terms of the sequence)
|
|
26
|
+
fnm2 = 0
|
|
27
|
+
fnm1 = 1
|
|
28
|
+
|
|
29
|
+
# Yield F1. F0 is 0, it is not useful to yield it.
|
|
30
|
+
yield fnm1
|
|
31
|
+
|
|
32
|
+
# F2, F3, ..., Fn
|
|
33
|
+
for i in range(2, p+1):
|
|
34
|
+
fn = fnm1 + fnm2
|
|
35
|
+
fnm2, fnm1 = fnm1, fn
|
|
36
|
+
|
|
37
|
+
yield fn
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Finite differences
|
|
3
|
+
Source: https://en.wikipedia.org/wiki/Finite_difference_method
|
|
4
|
+
Author: Aliou Diouf - Master degree from University, Paul Sabatier Toulouse 3,
|
|
5
|
+
in Applied Mathematics, speciality Scientific Computing (Numerical Analysis,
|
|
6
|
+
PDE, Software Engineering, Images&Signal processing, Aerospace, HR, English...)
|
|
7
|
+
CEO and Founder of Diouf Tech, a STEM company headquartered in Paris (75014)
|
|
8
|
+
Products: www.mathgame-py.com, https://www.paypal.com/paypalme/mathgamepy
|
|
9
|
+
Facebook page: https://www.facebook.com/profile.php?id=100086476192955
|
|
10
|
+
My personal Facebook: https://www.facebook.com/aliou.diouf.587/
|
|
11
|
+
My LinkedIn: https://www.linkedin.com/in/aliou-diouf-7b980441b/
|
|
12
|
+
My PyPI packages: https://pypi.org/project/py-ci-cd,
|
|
13
|
+
https://pypi.org/project/pymeshing
|
|
14
|
+
https://pypi.org/project/passwordworld
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def first_der_finite_difference_backwarded(f, x0, h):
|
|
19
|
+
"""
|
|
20
|
+
Approximation of first derivative of f in x0 using
|
|
21
|
+
finite difference method backwarded (or left)
|
|
22
|
+
"""
|
|
23
|
+
return (f(x0) - f(x0 - h)) / h
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def first_der_finite_difference_centred(f, x0, h):
|
|
27
|
+
"""
|
|
28
|
+
Approximation of first derivative of f in x0 using
|
|
29
|
+
finite difference method centred
|
|
30
|
+
"""
|
|
31
|
+
return (f(x0 + h) - f(x0 - h)) / (2 * h)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def first_der_finite_difference_forwarded(f, x0, h):
|
|
35
|
+
"""
|
|
36
|
+
Approximation of first derivative of f in x0 using
|
|
37
|
+
finite difference method forwarded (or right)
|
|
38
|
+
"""
|
|
39
|
+
return (f(x0 + h) - f(x0)) / h
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def sec_der_finite_difference(f, x0, h):
|
|
43
|
+
"""
|
|
44
|
+
Approximation of second derivative of f in x0 with finite difference method
|
|
45
|
+
"""
|
|
46
|
+
return (f(x0 + h) - 2 * f(x0) + f(x0 - h)) / h ** 2
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Rectangular matrices
|
|
3
|
+
A rectangular matrix is a list of m list(s) of n element(s)
|
|
4
|
+
m > 0, n > 0
|
|
5
|
+
You can use numpy. However, the goal here is to do not use external library
|
|
6
|
+
Author: Aliou Diouf - Master degree from University, Paul Sabatier Toulouse 3,
|
|
7
|
+
in Applied Mathematics, speciality Scientific Computing (Numerical Analysis,
|
|
8
|
+
PDE, Software Engineering, Images&Signal processing, Aerospace, HR, English...)
|
|
9
|
+
CEO and Founder of Diouf Tech, a STEM company headquartered in Paris (75014)
|
|
10
|
+
Products: www.mathgame-py.com, https://www.paypal.com/paypalme/mathgamepy
|
|
11
|
+
Facebook page: https://www.facebook.com/profile.php?id=100086476192955
|
|
12
|
+
My personal Facebook: https://www.facebook.com/aliou.diouf.587/
|
|
13
|
+
My LinkedIn: https://www.linkedin.com/in/aliou-diouf-7b980441b/
|
|
14
|
+
My PyPI packages: https://pypi.org/project/py-ci-cd,
|
|
15
|
+
https://pypi.org/project/pymeshing
|
|
16
|
+
https://pypi.org/project/passwordworld
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def zero_matrix(m, n):
|
|
21
|
+
"""Zero matrix"""
|
|
22
|
+
|
|
23
|
+
return [[0] * n for _ in range(m)]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def sum_matrices(m1, m2):
|
|
27
|
+
"""Sum of matrices"""
|
|
28
|
+
|
|
29
|
+
# c1, c2: respectively coeff for m1, m2; l1: line of m1, l2: line of m2
|
|
30
|
+
return [[c1 + c2 for c1, c2 in zip(l1, l2)] for l1, l2 in zip(m1, m2)]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def substraction_matrices(m1, m2):
|
|
34
|
+
"""Substraction matrices: m1 - m2"""
|
|
35
|
+
|
|
36
|
+
# c1, c2: respectively coeff for m1, m2; l1: line of m1, l2: line of m2
|
|
37
|
+
return [[c1 - c2 for c1, c2 in zip(l1, l2)] for l1, l2 in zip(m1, m2)]
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Square matrices - A list of n list(s) of n element(s), n > 0
|
|
3
|
+
You can use numpy. However, the goal here is to do not use external library
|
|
4
|
+
Author: Aliou Diouf - Master degree from University, Paul Sabatier Toulouse 3,
|
|
5
|
+
in Applied Mathematics, speciality Scientific Computing (Numerical Analysis,
|
|
6
|
+
PDE, Software Engineering, Images&Signal processing, Aerospace, HR, English...)
|
|
7
|
+
CEO and Founder of Diouf Tech, a STEM company headquartered in Paris (75014)
|
|
8
|
+
Products: www.mathgame-py.com, https://www.paypal.com/paypalme/mathgamepy
|
|
9
|
+
Facebook page: https://www.facebook.com/profile.php?id=100086476192955
|
|
10
|
+
My personal Facebook: https://www.facebook.com/aliou.diouf.587/
|
|
11
|
+
My LinkedIn: https://www.linkedin.com/in/aliou-diouf-7b980441b/
|
|
12
|
+
My PyPI packages: https://pypi.org/project/py-ci-cd,
|
|
13
|
+
https://pypi.org/project/pymeshing
|
|
14
|
+
https://pypi.org/project/passwordworld
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def print_matrix(matrix):
|
|
19
|
+
"""
|
|
20
|
+
Prints a matrix in an human-readable way.
|
|
21
|
+
Here matrix is square of size n
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
n = len(matrix)
|
|
25
|
+
|
|
26
|
+
for i in range(n):
|
|
27
|
+
for j in range(n-1):
|
|
28
|
+
print(matrix[i][j], end=' ')
|
|
29
|
+
print(matrix[i][-1], end='\n')
|
|
30
|
+
|
|
31
|
+
return 'ok'
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def zero_matrix(n):
|
|
35
|
+
"""n x n zero matrix"""
|
|
36
|
+
|
|
37
|
+
return [[0] * n for _ in range(n)]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def identity_matrix(n):
|
|
41
|
+
"""Identity matrix"""
|
|
42
|
+
|
|
43
|
+
return [[1 if j == i else 0 for j in range(n)] for i in range(n)]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def diagonal_matrix(coeff):
|
|
47
|
+
"""Diagonal matrix. Coeff is the vector of coefficients in the diagonal"""
|
|
48
|
+
|
|
49
|
+
n = len(coeff)
|
|
50
|
+
|
|
51
|
+
return [[coeff[i] if j == i else 0.00 for j in range(n)] for i in range(n)]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def tridiagonal_matrix(lower, diag, upper):
|
|
55
|
+
r"""
|
|
56
|
+
Tridiagonal matrix. lower, diag and upper are respectively the vectors
|
|
57
|
+
of coefficients under the diagonal, on the diagonal, upper the diagonal
|
|
58
|
+
/!\ In industrial application you do not fill tridiagonaal matrix.
|
|
59
|
+
Search for Thomas algorithm
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
n = len(diag)
|
|
63
|
+
tridiag = zero_matrix(n)
|
|
64
|
+
|
|
65
|
+
tridiag[0][0] = diag[0]
|
|
66
|
+
tridiag[0][1] = upper[0]
|
|
67
|
+
tridiag[n-1][n-2] = lower[-1]
|
|
68
|
+
tridiag[n-1][n-1] = diag[n-1]
|
|
69
|
+
|
|
70
|
+
for i in range(1, n-1):
|
|
71
|
+
tridiag[i][i-1] = lower[i-1]
|
|
72
|
+
tridiag[i][i] = diag[i]
|
|
73
|
+
tridiag[i][i+1] = upper[i]
|
|
74
|
+
|
|
75
|
+
return tridiag
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Norm Lp
|
|
3
|
+
Author: Aliou Diouf - Master degree from University, Paul Sabatier Toulouse 3,
|
|
4
|
+
in Applied Mathematics, speciality Scientific Computing (Numerical Analysis,
|
|
5
|
+
PDE, Software Engineering, Images&Signal processing, Aerospace, HR, English...)
|
|
6
|
+
CEO and Founder of Diouf Tech, a STEM company headquartered in Paris (75014)
|
|
7
|
+
Products: www.mathgame-py.com, https://www.paypal.com/paypalme/mathgamepy
|
|
8
|
+
Facebook page: https://www.facebook.com/profile.php?id=100086476192955
|
|
9
|
+
My personal Facebook: https://www.facebook.com/aliou.diouf.587/
|
|
10
|
+
My LinkedIn: https://www.linkedin.com/in/aliou-diouf-7b980441b/
|
|
11
|
+
My PyPI packages: https://pypi.org/project/py-ci-cd,
|
|
12
|
+
https://pypi.org/project/pymeshing
|
|
13
|
+
https://pypi.org/project/passwordworld
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def norm_lp(vect, p):
|
|
18
|
+
"""Norm Lp of a vect, where vect is a vector of length n"""
|
|
19
|
+
|
|
20
|
+
return sum([abs(v_i) ** p for v_i in vect]) ** 1/p
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Numerical sequences
|
|
3
|
+
Author: Aliou Diouf - Master degree from University, Paul Sabatier Toulouse 3,
|
|
4
|
+
in Applied Mathematics, speciality Scientific Computing (Numerical Analysis,
|
|
5
|
+
PDE, Software Engineering, Images&Signal processing, Aerospace, HR, English...)
|
|
6
|
+
CEO and Founder of Diouf Tech, a STEM company headquartered in Paris (75014)
|
|
7
|
+
Products: www.mathgame-py.com, https://www.paypal.com/paypalme/mathgamepy
|
|
8
|
+
Facebook page: https://www.facebook.com/profile.php?id=100086476192955
|
|
9
|
+
My personal Facebook: https://www.facebook.com/aliou.diouf.587/
|
|
10
|
+
My LinkedIn: https://www.linkedin.com/in/aliou-diouf-7b980441b/
|
|
11
|
+
My PyPI packages: https://pypi.org/project/py-ci-cd,
|
|
12
|
+
https://pypi.org/project/pymeshing
|
|
13
|
+
https://pypi.org/project/passwordworld
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def arithmetic_seq_gen(ap, p, d, n):
|
|
18
|
+
"""
|
|
19
|
+
Arithmetic sequence (or progression) in general, with common difference d
|
|
20
|
+
n is the number of the term to compute
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
return ap + (n - p) * d
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def arithmetic_seq_a0(a0, d, n):
|
|
27
|
+
"""
|
|
28
|
+
Arithmetic sequence in the special case "ap = a0", with common difference d
|
|
29
|
+
n is the number of the term to compute
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
return a0 + n * d
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def arithmetic_seq_a1(a1, d, n):
|
|
36
|
+
"""
|
|
37
|
+
Arithmetic sequence in the special case "ap = a1", with common difference d
|
|
38
|
+
n is the number of the term to compute
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
return a1 + (n - 1) * d
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def sum_arithmetic_seq(first_term, last_term, nb_term):
|
|
45
|
+
"""Sum of rithmetic sequence"""
|
|
46
|
+
|
|
47
|
+
return (first_term + last_term) * nb_term / 2
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def geometric_seq_gen(ap, p, r, n):
|
|
51
|
+
"""
|
|
52
|
+
Geometric sequence (or progression) in general, with common ratio r
|
|
53
|
+
n is the number of the term to compute
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
return ap * r ** (n - p)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def geometric_seq_a0(a0, r, n):
|
|
60
|
+
"""
|
|
61
|
+
Geometric sequence in the special case "ap = a0", with common ratio r
|
|
62
|
+
n is the number of the term to compute
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
return a0 * r ** n
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def geometric_seq_a1(a1, r, n):
|
|
69
|
+
"""
|
|
70
|
+
Geometric sequence in the special case "ap = a1", with common ratio r
|
|
71
|
+
n is the number of the term to compute
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
return a1 * r ** (n - 1)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Vector
|
|
3
|
+
A rectangular matrix is a list of m list(s) of n element(s)
|
|
4
|
+
m > 0, n > 0
|
|
5
|
+
You can use numpy. However, the goal here is to do not use external library
|
|
6
|
+
Author: Aliou Diouf - Master degree from University, Paul Sabatier Toulouse 3,
|
|
7
|
+
in Applied Mathematics, speciality Scientific Computing (Numerical Analysis,
|
|
8
|
+
PDE, Software Engineering, Images&Signal processing, Aerospace, HR, English...)
|
|
9
|
+
CEO and Founder of Diouf Tech, a STEM company headquartered in Paris (75014)
|
|
10
|
+
Products: www.mathgame-py.com, https://www.paypal.com/paypalme/mathgamepy
|
|
11
|
+
Facebook page: https://www.facebook.com/profile.php?id=100086476192955
|
|
12
|
+
My personal Facebook: https://www.facebook.com/aliou.diouf.587/
|
|
13
|
+
My LinkedIn: https://www.linkedin.com/in/aliou-diouf-7b980441b/
|
|
14
|
+
My PyPI packages: https://pypi.org/project/py-ci-cd,
|
|
15
|
+
https://pypi.org/project/pymeshing
|
|
16
|
+
https://pypi.org/project/passwordworld
|
|
17
|
+
"""
|
|
18
|
+
from random import uniform
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def zero_vector(n):
|
|
22
|
+
"""Vector on n zeros"""
|
|
23
|
+
|
|
24
|
+
return [0] * n
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def sum_vectors(vector1, vector2):
|
|
28
|
+
"""Sum of two vectors of length n"""
|
|
29
|
+
|
|
30
|
+
return [v1 + v2 for v1, v2 in zip(vector1, vector2)]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def substraction_vectors(vector1, vector2):
|
|
34
|
+
"""Substraction vectors: vector1 - vector2, of length n"""
|
|
35
|
+
|
|
36
|
+
return [v1 - v2 for v1, v2 in zip(vector1, vector2)]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def unit_vector(n, i):
|
|
40
|
+
"""Unit vector where 1 is at position i <= n"""
|
|
41
|
+
|
|
42
|
+
vect = zero_vector(n)
|
|
43
|
+
vect[i] = 1
|
|
44
|
+
|
|
45
|
+
return vect
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def random_vector(n, min_val, max_val):
|
|
49
|
+
"""Random vector of length n"""
|
|
50
|
+
|
|
51
|
+
return [uniform(min_val, max_val) for _ in range(n)]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Test dot_prod module
|
|
3
|
+
Aliou Diouf, graduated from Toulouse University, in Applied Mathematics,
|
|
4
|
+
President and Founder of Diouf Tech, A STEM company headquartered in Paris
|
|
5
|
+
Our product: www.mathgame-py.com
|
|
6
|
+
https://www.paypal.com/paypalme/mathgamepy
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from pymath.src.dot_prod.dot_prod import dot_prod
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_dot_prod():
|
|
13
|
+
"""Tests dot_prod function from dot_prod module"""
|
|
14
|
+
|
|
15
|
+
n = 3
|
|
16
|
+
|
|
17
|
+
x = [0] * n
|
|
18
|
+
y = [1] * n
|
|
19
|
+
assert dot_prod(x, y) == 0
|
|
20
|
+
|
|
21
|
+
x = [1, 0, 0]
|
|
22
|
+
y = [0, 1, 0]
|
|
23
|
+
assert dot_prod(x, y) == 0
|
|
24
|
+
|
|
25
|
+
x = [1] * n
|
|
26
|
+
y = [1] * n
|
|
27
|
+
assert dot_prod(x, y) == n
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
"""
|
|
3
|
+
Fibonacci without library
|
|
4
|
+
Author: Aliou Diouf - Master degree from University, Paul Sabatier Toulouse 3,
|
|
5
|
+
in Applied Mathematics, speciality Scientific Computing (Numerical Analysis,
|
|
6
|
+
PDE, Software Engineering, Images&Signal processing, Aerospace, HR, English...)
|
|
7
|
+
CEO and Founder of Diouf Tech, a STEM company headquartered in Paris (75014)
|
|
8
|
+
Products: www.mathgame-py.com, https://www.paypal.com/paypalme/mathgamepy
|
|
9
|
+
Facebook page: https://www.facebook.com/profile.php?id=100086476192955
|
|
10
|
+
My personal Facebook: https://www.facebook.com/aliou.diouf.587/
|
|
11
|
+
My LinkedIn: https://www.linkedin.com/in/aliou-diouf-7b980441b/
|
|
12
|
+
My PyPI packages: https://pypi.org/project/py-ci-cd,
|
|
13
|
+
https://pypi.org/project/pymeshing
|
|
14
|
+
https://pypi.org/project/passwordworld
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from pymath.src.fibonacci.fibonacci import fib
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# Just an example
|
|
21
|
+
p = 17
|
|
22
|
+
|
|
23
|
+
# Just printing the Fibonacci terms
|
|
24
|
+
for f in fib(p):
|
|
25
|
+
print(f)
|
|
26
|
+
print('fn = ', f)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# Now we aim to compute the mean of phi, Where phi = Fn / F_{n-1}, n > 1.
|
|
30
|
+
# Let denote this mean of phi phi_mean.
|
|
31
|
+
|
|
32
|
+
# Let p a big number.
|
|
33
|
+
# The bigger is p, the closer to golden ratio is the mean of phi.
|
|
34
|
+
# This corresponds also to "Law of large numbers".
|
|
35
|
+
p = 100000
|
|
36
|
+
|
|
37
|
+
# Initialization in order to sum to get the mean of phi
|
|
38
|
+
s = 0
|
|
39
|
+
fnm1 = 1
|
|
40
|
+
|
|
41
|
+
for f in fib(p):
|
|
42
|
+
phi = f / fnm1
|
|
43
|
+
s += phi
|
|
44
|
+
fnm1 = f
|
|
45
|
+
|
|
46
|
+
print('phi_mean = ', s / p)
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Tests finite_diff module
|
|
3
|
+
Source: https://en.wikipedia.org/wiki/Finite_difference_method
|
|
4
|
+
Author: Aliou Diouf - Master degree from University, Paul Sabatier Toulouse 3,
|
|
5
|
+
in Applied Mathematics, speciality Scientific Computing (Numerical Analysis,
|
|
6
|
+
PDE, Software Engineering, Images&Signal processing, Aerospace, HR, English...)
|
|
7
|
+
CEO and Founder of Diouf Tech, a STEM company headquartered in Paris (75014)
|
|
8
|
+
Products: www.mathgame-py.com, https://www.paypal.com/paypalme/mathgamepy
|
|
9
|
+
Facebook page: https://www.facebook.com/profile.php?id=100086476192955
|
|
10
|
+
My personal Facebook: https://www.facebook.com/aliou.diouf.587/
|
|
11
|
+
My LinkedIn: https://www.linkedin.com/in/aliou-diouf-7b980441b/
|
|
12
|
+
My PyPI packages: https://pypi.org/project/py-ci-cd,
|
|
13
|
+
https://pypi.org/project/pymeshing
|
|
14
|
+
https://pypi.org/project/passwordworld
|
|
15
|
+
"""
|
|
16
|
+
from pymath.src.finite_diff.finite_diff import (
|
|
17
|
+
first_der_finite_difference_backwarded,
|
|
18
|
+
first_der_finite_difference_centred,
|
|
19
|
+
first_der_finite_difference_forwarded,
|
|
20
|
+
sec_der_finite_difference
|
|
21
|
+
)
|
|
22
|
+
from math import cos, sin
|
|
23
|
+
from random import uniform
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# If epsilon is too low, your criterion to validate a test would be too strict.
|
|
27
|
+
# So, tests would not pass
|
|
28
|
+
epsilon = 0.1 # If too low tests will fail, approximation has limit
|
|
29
|
+
|
|
30
|
+
# If h is too high, you would get good time computing but not good accuracy
|
|
31
|
+
# If h is too low, you woulg get good accuracy, but high computing time
|
|
32
|
+
h = 1.e-3
|
|
33
|
+
|
|
34
|
+
maxi = 1000
|
|
35
|
+
mini = - maxi
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def for_first_der(num_method):
|
|
39
|
+
"""The test process called inside all tests"""
|
|
40
|
+
|
|
41
|
+
f = cos
|
|
42
|
+
x0 = uniform(mini, maxi)
|
|
43
|
+
|
|
44
|
+
fprime = num_method(f, x0, h)
|
|
45
|
+
|
|
46
|
+
# fprime(cos) = -sin
|
|
47
|
+
if sin(x0) == 0.0:
|
|
48
|
+
assert abs(fprime + sin(x0)) < epsilon
|
|
49
|
+
else:
|
|
50
|
+
assert abs(fprime + sin(x0)) / abs(sin(x0)) < epsilon
|
|
51
|
+
|
|
52
|
+
f = sin
|
|
53
|
+
x0 = uniform(mini, maxi)
|
|
54
|
+
|
|
55
|
+
fprime = num_method(f, x0, h)
|
|
56
|
+
|
|
57
|
+
# fprime(sin) = cos
|
|
58
|
+
print(fprime, cos(x0))
|
|
59
|
+
if cos(x0) == 0.0:
|
|
60
|
+
assert abs(fprime - cos(x0)) < epsilon
|
|
61
|
+
else:
|
|
62
|
+
assert abs(fprime - cos(x0)) / abs(cos(x0)) < epsilon
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_first_der_finite_difference_backwarded():
|
|
66
|
+
"""
|
|
67
|
+
It tests: Approximation of first derivative of f in x0 using
|
|
68
|
+
finite difference method backwarded (or left)
|
|
69
|
+
"""
|
|
70
|
+
for_first_der(first_der_finite_difference_backwarded)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def test_first_der_finite_difference_centred():
|
|
74
|
+
"""
|
|
75
|
+
It tests: Approximation of first derivative of f in x0 using
|
|
76
|
+
finite difference method centred
|
|
77
|
+
"""
|
|
78
|
+
for_first_der(first_der_finite_difference_centred)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_first_der_finite_difference_forwarded():
|
|
82
|
+
"""
|
|
83
|
+
It tests: Approximation of first derivative of f in x0 using
|
|
84
|
+
finite difference method forwarded (or right)
|
|
85
|
+
"""
|
|
86
|
+
for_first_der(first_der_finite_difference_forwarded)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def test_sec_der_finite_difference():
|
|
90
|
+
"""
|
|
91
|
+
It tests:
|
|
92
|
+
Approximation of second derivative of f in x0 with finite difference method
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
f = cos
|
|
96
|
+
x0 = uniform(mini, maxi)
|
|
97
|
+
|
|
98
|
+
fsec = sec_der_finite_difference(f, x0, h)
|
|
99
|
+
print(fsec, -cos(x0))
|
|
100
|
+
|
|
101
|
+
# Second derivative of cos is -cos
|
|
102
|
+
if cos(x0) == 0.0:
|
|
103
|
+
assert abs(fsec + cos(x0)) < epsilon
|
|
104
|
+
else:
|
|
105
|
+
assert abs(fsec + cos(x0)) / abs(cos(x0)) < epsilon
|
|
106
|
+
|
|
107
|
+
f = sin
|
|
108
|
+
x0 = uniform(mini, maxi)
|
|
109
|
+
|
|
110
|
+
fsec = sec_der_finite_difference(f, x0, h)
|
|
111
|
+
|
|
112
|
+
# Second derivative of sin is -sin
|
|
113
|
+
if sin(x0) == 0.0:
|
|
114
|
+
assert abs(fsec + sin(x0)) < epsilon
|
|
115
|
+
else:
|
|
116
|
+
assert abs(fsec + sin(x0)) / abs(sin(x0)) < epsilon
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Tests rectangular matrices
|
|
3
|
+
A rectangular matrix is a list of m list(s) of n element(s)
|
|
4
|
+
m > 0, n > 0
|
|
5
|
+
You can use numpy. However, the goal here is to do not use external library
|
|
6
|
+
Author: Aliou Diouf - Master degree from University, Paul Sabatier Toulouse 3,
|
|
7
|
+
in Applied Mathematics, speciality Scientific Computing (Numerical Analysis,
|
|
8
|
+
PDE, Software Engineering, Images&Signal processing, Aerospace, HR, English...)
|
|
9
|
+
CEO and Founder of Diouf Tech, a STEM company headquartered in Paris (75014)
|
|
10
|
+
Products: www.mathgame-py.com, https://www.paypal.com/paypalme/mathgamepy
|
|
11
|
+
Facebook page: https://www.facebook.com/profile.php?id=100086476192955
|
|
12
|
+
My personal Facebook: https://www.facebook.com/aliou.diouf.587/
|
|
13
|
+
My LinkedIn: https://www.linkedin.com/in/aliou-diouf-7b980441b/
|
|
14
|
+
My PyPI packages: https://pypi.org/project/py-ci-cd,
|
|
15
|
+
https://pypi.org/project/pymeshing
|
|
16
|
+
https://pypi.org/project/passwordworld
|
|
17
|
+
"""
|
|
18
|
+
from pymath.src.matrices.rectangular_matrices import zero_matrix, \
|
|
19
|
+
sum_matrices, substraction_matrices
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_zero_matrix():
|
|
23
|
+
"""Tests zero_matrix"""
|
|
24
|
+
|
|
25
|
+
assert zero_matrix(1, 2) == [[0, 0]]
|
|
26
|
+
assert zero_matrix(2, 1) == [[0], [0]]
|
|
27
|
+
assert zero_matrix(2, 3) == [[0, 0, 0], [0, 0, 0]]
|
|
28
|
+
assert zero_matrix(3, 2) == [[0, 0], [0, 0], [0, 0]]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_sum_matrices():
|
|
32
|
+
"""Tests sum_matrices"""
|
|
33
|
+
|
|
34
|
+
m1 = [[1, 1]]
|
|
35
|
+
m2 = [[2, 2]]
|
|
36
|
+
assert sum_matrices(m1, m2) == [[3, 3]]
|
|
37
|
+
|
|
38
|
+
m1 = [[1], [1]]
|
|
39
|
+
m2 = [[2], [2]]
|
|
40
|
+
assert sum_matrices(m1, m2) == [[3], [3]]
|
|
41
|
+
|
|
42
|
+
m1 = [[1, 1, 1], [1, 1, 1]]
|
|
43
|
+
m2 = [[2, 2, 2], [2, 2, 2]]
|
|
44
|
+
assert sum_matrices(m1, m2) == [[3, 3, 3], [3, 3, 3]]
|
|
45
|
+
|
|
46
|
+
m1 = [[1, 1], [1, 1], [1, 1]]
|
|
47
|
+
m2 = [[2, 2], [2, 2], [2, 2]]
|
|
48
|
+
assert sum_matrices(m1, m2) == [[3, 3], [3, 3], [3, 3]]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_substraction_matrices():
|
|
52
|
+
"""Tests substraction_matrices"""
|
|
53
|
+
|
|
54
|
+
m1 = [[1, 1]]
|
|
55
|
+
m2 = [[2, 2]]
|
|
56
|
+
assert substraction_matrices(m1, m2) == [[-1, -1]]
|
|
57
|
+
assert substraction_matrices(m2, m1) == [[1, 1]]
|
|
58
|
+
|
|
59
|
+
m1 = [[1], [1]]
|
|
60
|
+
m2 = [[2], [2]]
|
|
61
|
+
assert substraction_matrices(m1, m2) == [[-1], [-1]]
|
|
62
|
+
assert substraction_matrices(m2, m1) == [[1], [1]]
|
|
63
|
+
|
|
64
|
+
m1 = [[1, 1, 1], [1, 1, 1]]
|
|
65
|
+
m2 = [[2, 2, 2], [2, 2, 2]]
|
|
66
|
+
assert substraction_matrices(m1, m2) == [[-1, -1, -1], [-1, -1, -1]]
|
|
67
|
+
assert substraction_matrices(m2, m1) == [[1, 1, 1], [1, 1, 1]]
|
|
68
|
+
|
|
69
|
+
m1 = [[1, 1], [1, 1], [1, 1]]
|
|
70
|
+
m2 = [[2, 2], [2, 2], [2, 2]]
|
|
71
|
+
assert substraction_matrices(m1, m2) == [[-1, -1], [-1, -1], [-1, -1]]
|
|
72
|
+
assert substraction_matrices(m2, m1) == [[1, 1], [1, 1], [1, 1]]
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""
|
|
2
|
+
A test of square_matrices module
|
|
3
|
+
You can use numpy. However, the goal here is to do not use external library
|
|
4
|
+
Author: Aliou Diouf - Master degree from University, Paul Sabatier Toulouse 3,
|
|
5
|
+
in Applied Mathematics, speciality Scientific Computing (Numerical Analysis,
|
|
6
|
+
PDE, Software Engineering, Images&Signal processing, Aerospace, HR, English...)
|
|
7
|
+
CEO and Founder of Diouf Tech, a STEM company headquartered in Paris (75014)
|
|
8
|
+
Products: www.mathgame-py.com, https://www.paypal.com/paypalme/mathgamepy
|
|
9
|
+
Facebook page: https://www.facebook.com/profile.php?id=100086476192955
|
|
10
|
+
My personal Facebook: https://www.facebook.com/aliou.diouf.587/
|
|
11
|
+
My LinkedIn: https://www.linkedin.com/in/aliou-diouf-7b980441b/
|
|
12
|
+
My PyPI packages: https://pypi.org/project/py-ci-cd,
|
|
13
|
+
https://pypi.org/project/pymeshing
|
|
14
|
+
https://pypi.org/project/passwordworld
|
|
15
|
+
"""
|
|
16
|
+
from pymath.src.matrices.square_matrices import print_matrix, \
|
|
17
|
+
zero_matrix, identity_matrix, diagonal_matrix, tridiagonal_matrix
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_print_matrix():
|
|
21
|
+
"""Test print_matrix"""
|
|
22
|
+
|
|
23
|
+
matrix = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]
|
|
24
|
+
assert print_matrix(matrix) == 'ok'
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_zero_matrix():
|
|
28
|
+
"""n x n zero matrix"""
|
|
29
|
+
|
|
30
|
+
assert zero_matrix(1) == [[0]]
|
|
31
|
+
assert zero_matrix(2) == [[0, 0], [0, 0]]
|
|
32
|
+
assert zero_matrix(3) == [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
|
|
33
|
+
assert zero_matrix(4) == [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0],
|
|
34
|
+
[0, 0, 0, 0]]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_identity_matrix():
|
|
38
|
+
"""Identity matrix"""
|
|
39
|
+
|
|
40
|
+
assert identity_matrix(1) == [[1]]
|
|
41
|
+
assert identity_matrix(2) == [[1, 0], [0, 1]]
|
|
42
|
+
assert identity_matrix(3) == [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
|
|
43
|
+
assert identity_matrix(4) == [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0],
|
|
44
|
+
[0, 0, 0, 1]]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_diagonal_matrix():
|
|
48
|
+
"""Tests diagonal_matrix"""
|
|
49
|
+
|
|
50
|
+
assert diagonal_matrix(range(1, 2)) == [[1]]
|
|
51
|
+
assert diagonal_matrix(range(1, 3)) == [[1, 0], [0, 2]]
|
|
52
|
+
assert diagonal_matrix(range(1, 4)) == [[1, 0, 0], [0, 2, 0], [0, 0, 3]]
|
|
53
|
+
assert diagonal_matrix(range(1, 5)) == [[1, 0, 0, 0], [0, 2, 0, 0],
|
|
54
|
+
[0, 0, 3, 0], [0, 0, 0, 4]]
|
|
55
|
+
|
|
56
|
+
def test_tridiagonal_matrix():
|
|
57
|
+
"""Tests tridiagonal_matrix"""
|
|
58
|
+
|
|
59
|
+
td = tridiagonal_matrix([1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [1, 1, 1, 1, 1])
|
|
60
|
+
expected = [[2, 1, 0, 0, 0], [1, 2, 1, 0, 0], [0, 1, 2, 1, 0],
|
|
61
|
+
[0, 0, 1, 2, 1], [0, 0, 0, 1, 2]]
|
|
62
|
+
|
|
63
|
+
assert td == expected
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Norm Lp
|
|
3
|
+
Author: Aliou Diouf - Master degree from University, Paul Sabatier Toulouse 3,
|
|
4
|
+
in Applied Mathematics, speciality Scientific Computing (Numerical Analysis,
|
|
5
|
+
PDE, Software Engineering, Images&Signal processing, Aerospace, HR, English...)
|
|
6
|
+
CEO and Founder of Diouf Tech, a STEM company headquartered in Paris (75014)
|
|
7
|
+
Products: www.mathgame-py.com, https://www.paypal.com/paypalme/mathgamepy
|
|
8
|
+
Facebook page: https://www.facebook.com/profile.php?id=100086476192955
|
|
9
|
+
My personal Facebook: https://www.facebook.com/aliou.diouf.587/
|
|
10
|
+
My LinkedIn: https://www.linkedin.com/in/aliou-diouf-7b980441b/
|
|
11
|
+
My PyPI packages: https://pypi.org/project/py-ci-cd,
|
|
12
|
+
https://pypi.org/project/pymeshing
|
|
13
|
+
https://pypi.org/project/passwordworld
|
|
14
|
+
"""
|
|
15
|
+
from pymath.src.norms.norm_lp import norm_lp
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def test_norm_lp():
|
|
19
|
+
"""Tests norm_lp"""
|
|
20
|
+
|
|
21
|
+
len_vect = 4 # Arbitrary
|
|
22
|
+
vect = [1] * len_vect
|
|
23
|
+
print(vect)
|
|
24
|
+
|
|
25
|
+
for p, expected in zip([1, 2], [4, 2]):
|
|
26
|
+
assert norm_lp(vect, p) == expected
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Tests num_seq module
|
|
3
|
+
Author: Aliou Diouf - Master degree from University, Paul Sabatier Toulouse 3,
|
|
4
|
+
in Applied Mathematics, speciality Scientific Computing (Numerical Analysis,
|
|
5
|
+
PDE, Software Engineering, Images&Signal processing, Aerospace, HR, English...)
|
|
6
|
+
CEO and Founder of Diouf Tech, a STEM company headquartered in Paris (75014)
|
|
7
|
+
Products: www.mathgame-py.com, https://www.paypal.com/paypalme/mathgamepy
|
|
8
|
+
Facebook page: https://www.facebook.com/profile.php?id=100086476192955
|
|
9
|
+
My personal Facebook: https://www.facebook.com/aliou.diouf.587/
|
|
10
|
+
My LinkedIn: https://www.linkedin.com/in/aliou-diouf-7b980441b/
|
|
11
|
+
My PyPI packages: https://pypi.org/project/py-ci-cd,
|
|
12
|
+
https://pypi.org/project/pymeshing
|
|
13
|
+
https://pypi.org/project/passwordworld
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from pymath.src.num_seq.num_seq import arithmetic_seq_gen, arithmetic_seq_a0, \
|
|
17
|
+
arithmetic_seq_a1, geometric_seq_gen, geometric_seq_a0, geometric_seq_a1
|
|
18
|
+
from random import randint
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
n_max = 10
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_arithmetic_seq_gen():
|
|
25
|
+
"""Tests arithmetic_seq_gen"""
|
|
26
|
+
|
|
27
|
+
n = randint(0, n_max)
|
|
28
|
+
p = randint(0, n)
|
|
29
|
+
|
|
30
|
+
assert arithmetic_seq_gen(p, p, 1, n) == n
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_arithmetic_seq_a0():
|
|
34
|
+
"""Tests arithmetic_seq_a0"""
|
|
35
|
+
|
|
36
|
+
n = randint(0, n_max)
|
|
37
|
+
|
|
38
|
+
assert arithmetic_seq_a0(0, 1, n) == n
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_arithmetic_seq_a1():
|
|
42
|
+
"""Tests arithmetic_seq_a1"""
|
|
43
|
+
|
|
44
|
+
n = randint(1, n_max)
|
|
45
|
+
|
|
46
|
+
assert arithmetic_seq_a1(1, 1, n) == n
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_geometric_seq_gen():
|
|
50
|
+
"""Tests geometric_seq_gen"""
|
|
51
|
+
|
|
52
|
+
n = randint(1, n_max)
|
|
53
|
+
p = randint(0, n)
|
|
54
|
+
|
|
55
|
+
assert geometric_seq_gen(2**p, p, 2, n) == 2 ** n
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_geometric_seq_a0():
|
|
59
|
+
"""Tests geometric_seq_a0"""
|
|
60
|
+
|
|
61
|
+
n = randint(1, n_max)
|
|
62
|
+
|
|
63
|
+
assert geometric_seq_a0(1, 2, n) == 2 ** n
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def test_geometric_seq_a1():
|
|
67
|
+
"""Tests geometric_seq_a1"""
|
|
68
|
+
|
|
69
|
+
n = randint(1, n_max)
|
|
70
|
+
|
|
71
|
+
assert geometric_seq_a1(2, 2, n) == 2 ** n
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Vector
|
|
3
|
+
A rectangular matrix is a list of m list(s) of n element(s)
|
|
4
|
+
m > 0, n > 0
|
|
5
|
+
You can use numpy. However, the goal here is to do not use external library
|
|
6
|
+
Author: Aliou Diouf - Master degree from University, Paul Sabatier Toulouse 3,
|
|
7
|
+
in Applied Mathematics, speciality Scientific Computing (Numerical Analysis,
|
|
8
|
+
PDE, Software Engineering, Images&Signal processing, Aerospace, HR, English...)
|
|
9
|
+
CEO and Founder of Diouf Tech, a STEM company headquartered in Paris (75014)
|
|
10
|
+
Products: www.mathgame-py.com, https://www.paypal.com/paypalme/mathgamepy
|
|
11
|
+
Facebook page: https://www.facebook.com/profile.php?id=100086476192955
|
|
12
|
+
My personal Facebook: https://www.facebook.com/aliou.diouf.587/
|
|
13
|
+
My LinkedIn: https://www.linkedin.com/in/aliou-diouf-7b980441b/
|
|
14
|
+
My PyPI packages: https://pypi.org/project/py-ci-cd,
|
|
15
|
+
https://pypi.org/project/pymeshing
|
|
16
|
+
https://pypi.org/project/passwordworld
|
|
17
|
+
"""
|
|
18
|
+
from pymath.src.vectors.vectors import zero_vector, sum_vectors, \
|
|
19
|
+
substraction_vectors, unit_vector, random_vector
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_zero_vector():
|
|
23
|
+
"""Tests zero_vector"""
|
|
24
|
+
|
|
25
|
+
assert zero_vector(1) == [0]
|
|
26
|
+
assert zero_vector(5) == [0, 0, 0, 0, 0]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_sum_vectors():
|
|
30
|
+
"""Tests sum_vectors"""
|
|
31
|
+
|
|
32
|
+
v1 = [1, 1, 1]
|
|
33
|
+
v2 = [2, 2, 2]
|
|
34
|
+
|
|
35
|
+
assert sum_vectors(v1, v2) == [3, 3, 3]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_substraction_vectors():
|
|
39
|
+
"""Tests substraction_vectors"""
|
|
40
|
+
|
|
41
|
+
v1 = [1, 1, 1]
|
|
42
|
+
v2 = [2, 2, 2]
|
|
43
|
+
|
|
44
|
+
assert substraction_vectors(v1, v2) == [-1, -1, -1]
|
|
45
|
+
assert substraction_vectors(v2, v1) == [1, 1, 1]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_unit_vector():
|
|
49
|
+
"""Tests unit_vector"""
|
|
50
|
+
|
|
51
|
+
assert unit_vector(3, 0) == [1, 0, 0]
|
|
52
|
+
assert unit_vector(3, 1) == [0, 1, 0]
|
|
53
|
+
assert unit_vector(3, 2) == [0, 0, 1]
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_random_vector():
|
|
57
|
+
"""Tests random_vector"""
|
|
58
|
+
|
|
59
|
+
n, min_val, max_val = 4, -10, 10
|
|
60
|
+
rand_vect = random_vector(n, min_val, max_val)
|
|
61
|
+
|
|
62
|
+
assert len(rand_vect) == n
|
|
63
|
+
|
|
64
|
+
for _ in range(n):
|
|
65
|
+
assert rand_vect
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from setuptools import setup
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
setup(
|
|
5
|
+
name='py_num_math',
|
|
6
|
+
version='1.0.0',
|
|
7
|
+
description='Python package for mathematical numerical tools.',
|
|
8
|
+
long_description='Python package for mathematical numerical tools.',
|
|
9
|
+
long_description_content_type="text/markdown",
|
|
10
|
+
url='https://www.paypal.com/paypalme/mathgamepy',
|
|
11
|
+
author='Aliou Diouf',
|
|
12
|
+
author_email='aliou.diouf5@gmail.com',
|
|
13
|
+
license='Diouf Tech',
|
|
14
|
+
packages=[
|
|
15
|
+
'pymath', 'pymath.src', 'pymath.src.dot_prod', 'pymath.src.fibonacci',
|
|
16
|
+
'pymath.src.finite_diff', 'pymath.src.matrices', 'pymath.src.norms',
|
|
17
|
+
'pymath.src.num_seq', 'pymath.src.vectors',
|
|
18
|
+
'pymath.tests', 'pymath.tests.dot_prod', 'pymath.tests.fibonacci',
|
|
19
|
+
'pymath.tests.finite_diff', 'pymath.tests.matrices',
|
|
20
|
+
'pymath.tests.norms', 'pymath.tests.num_seq', 'pymath.tests.vectors',
|
|
21
|
+
],
|
|
22
|
+
install_requires=['flake8', 'pytest'],
|
|
23
|
+
classifiers=[
|
|
24
|
+
'Development Status :: 5 - Production/Stable',
|
|
25
|
+
'License :: Free To Use But Restricted',
|
|
26
|
+
'Programming Language :: Python :: 3.14',
|
|
27
|
+
'Operating System :: POSIX :: Linux'
|
|
28
|
+
]
|
|
29
|
+
)
|