diff --git a/pyproject.toml b/pyproject.toml index 9787c3b..1e3e926 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,16 @@ [build-system] requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta" + +[project] +name = "simple_functions" # 你的包名称 +version = "0.1.0" # 包的版本 +description = "A package for simple math functions" +authors = [{name = "Your Name", email = "your.email@example.com"}] +license = {text = "MIT"} # 包的许可证类型 +dependencies = ["numpy", "functools"] # 运行时依赖 +readme = "README.md" # 包含的 README 文件 + +[tool.setuptools.packages.find] +where = ["simple_functions"] + diff --git a/simple_functions.egg-info/PKG-INFO b/simple_functions.egg-info/PKG-INFO new file mode 100644 index 0000000..1a97094 --- /dev/null +++ b/simple_functions.egg-info/PKG-INFO @@ -0,0 +1,3 @@ +Metadata-Version: 2.1 +Name: simple_functions +Version: 0.1.0 diff --git a/simple_functions.egg-info/SOURCES.txt b/simple_functions.egg-info/SOURCES.txt new file mode 100644 index 0000000..e3f4a65 --- /dev/null +++ b/simple_functions.egg-info/SOURCES.txt @@ -0,0 +1,12 @@ +README.md +pyproject.toml +setup.py +simple_functions/__init__.py +simple_functions/cacu_pi.py +simple_functions/functions1.py +simple_functions.egg-info/PKG-INFO +simple_functions.egg-info/SOURCES.txt +simple_functions.egg-info/dependency_links.txt +simple_functions.egg-info/top_level.txt +tests/test_constants.py +tests/test_simple_functions.py \ No newline at end of file diff --git a/simple_functions.egg-info/dependency_links.txt b/simple_functions.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/simple_functions.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/simple_functions.egg-info/top_level.txt b/simple_functions.egg-info/top_level.txt new file mode 100644 index 0000000..a4ba85f --- /dev/null +++ b/simple_functions.egg-info/top_level.txt @@ -0,0 +1 @@ +simple_functions diff --git a/simple_functions/__init__.py b/simple_functions/__init__.py index d613bea..ca0d3bd 100644 --- a/simple_functions/__init__.py +++ b/simple_functions/__init__.py @@ -1,4 +1,5 @@ -from .functions1 import * # noqa +from simple_functions.functions1 import my_sum, my_prod # noqa +from simple_functions.cacu_pi import pi, rsum try: from importlib.metadata import version, PackageNotFoundError # Python 3.8+ diff --git a/simple_functions/__pycache__/__init__.cpython-312.pyc b/simple_functions/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000..7af9776 Binary files /dev/null and b/simple_functions/__pycache__/__init__.cpython-312.pyc differ diff --git a/simple_functions/__pycache__/cacu_pi.cpython-312.pyc b/simple_functions/__pycache__/cacu_pi.cpython-312.pyc new file mode 100644 index 0000000..4770ac8 Binary files /dev/null and b/simple_functions/__pycache__/cacu_pi.cpython-312.pyc differ diff --git a/simple_functions/__pycache__/functions1.cpython-312.pyc b/simple_functions/__pycache__/functions1.cpython-312.pyc new file mode 100644 index 0000000..7af18c6 Binary files /dev/null and b/simple_functions/__pycache__/functions1.cpython-312.pyc differ diff --git a/simple_functions/cacu_pi.py b/simple_functions/cacu_pi.py new file mode 100644 index 0000000..d440fc8 --- /dev/null +++ b/simple_functions/cacu_pi.py @@ -0,0 +1,18 @@ + +from numpy import sqrt +from functions1 import factorial +from functools import cache + +__all__ = ['pi'] + + +def pi(terms=1): + return 1./(2.*sqrt(2.)/9801.*rsum(terms)) + + +@cache # 递归/重复调用时记得使用 @cache +def rsum(n): + t = factorial(4*n)*(1103+26390*n)/(factorial(n)**4*396**(4*n)) + return t + rsum(n-1) if n else t + +print(pi(100)) \ No newline at end of file diff --git a/simple_functions/functions1.py b/simple_functions/functions1.py index 8c63a4d..6e3363e 100644 --- a/simple_functions/functions1.py +++ b/simple_functions/functions1.py @@ -1,5 +1,8 @@ -__all__ = ['my_sum'] +from numpy import sqrt +from functools import cache + +__all__ = ['my_sum', 'my_prod'] # module rsum 只是服务于计算pi,因此不需要导入 def my_sum(iterable): @@ -7,3 +10,13 @@ def my_sum(iterable): for i in iterable: tot += i return tot + +def my_prod(iterable): + result = 1 + for i in iterable: + result *= i + return result + +@cache +def factorial(n): + return n * factorial(n-1) if n else 1 \ No newline at end of file diff --git a/simple_functions/simple_functions.egg-info/PKG-INFO b/simple_functions/simple_functions.egg-info/PKG-INFO new file mode 100644 index 0000000..4e5e4fb --- /dev/null +++ b/simple_functions/simple_functions.egg-info/PKG-INFO @@ -0,0 +1,12 @@ +Metadata-Version: 2.1 +Name: simple_functions +Version: 0.1.0 +Summary: A package for simple math functions +Author-email: Your Name +License: MIT +Description-Content-Type: text/markdown +Requires-Dist: numpy +Requires-Dist: pandas + +# CI MPM +Toy repo with some simple functions for the CI lecture diff --git a/simple_functions/simple_functions.egg-info/SOURCES.txt b/simple_functions/simple_functions.egg-info/SOURCES.txt new file mode 100644 index 0000000..0ce1f9a --- /dev/null +++ b/simple_functions/simple_functions.egg-info/SOURCES.txt @@ -0,0 +1,10 @@ +README.md +pyproject.toml +setup.py +simple_functions/simple_functions.egg-info/PKG-INFO +simple_functions/simple_functions.egg-info/SOURCES.txt +simple_functions/simple_functions.egg-info/dependency_links.txt +simple_functions/simple_functions.egg-info/requires.txt +simple_functions/simple_functions.egg-info/top_level.txt +tests/test_constants.py +tests/test_simple_functions.py \ No newline at end of file diff --git a/simple_functions/simple_functions.egg-info/dependency_links.txt b/simple_functions/simple_functions.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/simple_functions/simple_functions.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/simple_functions/simple_functions.egg-info/requires.txt b/simple_functions/simple_functions.egg-info/requires.txt new file mode 100644 index 0000000..5da331c --- /dev/null +++ b/simple_functions/simple_functions.egg-info/requires.txt @@ -0,0 +1,2 @@ +numpy +pandas diff --git a/simple_functions/simple_functions.egg-info/top_level.txt b/simple_functions/simple_functions.egg-info/top_level.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/simple_functions/simple_functions.egg-info/top_level.txt @@ -0,0 +1 @@ + diff --git a/tests/__pycache__/test_constants.cpython-312-pytest-8.3.3.pyc b/tests/__pycache__/test_constants.cpython-312-pytest-8.3.3.pyc new file mode 100644 index 0000000..c45dde0 Binary files /dev/null and b/tests/__pycache__/test_constants.cpython-312-pytest-8.3.3.pyc differ diff --git a/tests/__pycache__/test_simple_functions.cpython-312-pytest-8.3.3.pyc b/tests/__pycache__/test_simple_functions.cpython-312-pytest-8.3.3.pyc new file mode 100644 index 0000000..eb8ab2c Binary files /dev/null and b/tests/__pycache__/test_simple_functions.cpython-312-pytest-8.3.3.pyc differ diff --git a/tests/test_constants.py b/tests/test_constants.py new file mode 100644 index 0000000..0652916 --- /dev/null +++ b/tests/test_constants.py @@ -0,0 +1,13 @@ +import numpy as np +import pytest + +from simple_functions import pi + + +class TestPi(object): + '''Class to test our constants are computed correctly''' + + def test_pi(self): + '''Test computation of pi''' + my_pi = pi(2) + assert np.isclose(my_pi, np.pi, atol=1e-12) \ No newline at end of file diff --git a/tests/test_simple_functions.py b/tests/test_simple_functions.py index 5a03b52..1b201f5 100644 --- a/tests/test_simple_functions.py +++ b/tests/test_simple_functions.py @@ -13,4 +13,4 @@ class TestSimpleFunctions(object): def test_my_add(self, iterable, expected): '''Test our add function''' isum = my_sum(iterable) - assert isum == expected + assert isum == expected \ No newline at end of file