From 3f6c7b5b3e017bf74883e0b1c7eb238668faf421 Mon Sep 17 00:00:00 2001 From: zy424 Date: Tue, 15 Oct 2024 20:36:16 +0100 Subject: [PATCH] add pi caculation --- pyproject.toml | 13 +++++++++++++ simple_functions.egg-info/PKG-INFO | 3 +++ simple_functions.egg-info/SOURCES.txt | 12 ++++++++++++ .../dependency_links.txt | 1 + simple_functions.egg-info/top_level.txt | 1 + simple_functions/__init__.py | 3 ++- .../__pycache__/__init__.cpython-312.pyc | Bin 0 -> 608 bytes .../__pycache__/cacu_pi.cpython-312.pyc | Bin 0 -> 909 bytes .../__pycache__/functions1.cpython-312.pyc | Bin 0 -> 829 bytes simple_functions/cacu_pi.py | 18 ++++++++++++++++++ simple_functions/functions1.py | 15 ++++++++++++++- .../simple_functions.egg-info/PKG-INFO | 12 ++++++++++++ .../simple_functions.egg-info/SOURCES.txt | 10 ++++++++++ .../dependency_links.txt | 1 + .../simple_functions.egg-info/requires.txt | 2 ++ .../simple_functions.egg-info/top_level.txt | 1 + ...est_constants.cpython-312-pytest-8.3.3.pyc | Bin 0 -> 2059 bytes ...ple_functions.cpython-312-pytest-8.3.3.pyc | Bin 0 -> 1726 bytes tests/test_constants.py | 13 +++++++++++++ tests/test_simple_functions.py | 2 +- 20 files changed, 104 insertions(+), 3 deletions(-) create mode 100644 simple_functions.egg-info/PKG-INFO create mode 100644 simple_functions.egg-info/SOURCES.txt create mode 100644 simple_functions.egg-info/dependency_links.txt create mode 100644 simple_functions.egg-info/top_level.txt create mode 100644 simple_functions/__pycache__/__init__.cpython-312.pyc create mode 100644 simple_functions/__pycache__/cacu_pi.cpython-312.pyc create mode 100644 simple_functions/__pycache__/functions1.cpython-312.pyc create mode 100644 simple_functions/cacu_pi.py create mode 100644 simple_functions/simple_functions.egg-info/PKG-INFO create mode 100644 simple_functions/simple_functions.egg-info/SOURCES.txt create mode 100644 simple_functions/simple_functions.egg-info/dependency_links.txt create mode 100644 simple_functions/simple_functions.egg-info/requires.txt create mode 100644 simple_functions/simple_functions.egg-info/top_level.txt create mode 100644 tests/__pycache__/test_constants.cpython-312-pytest-8.3.3.pyc create mode 100644 tests/__pycache__/test_simple_functions.cpython-312-pytest-8.3.3.pyc create mode 100644 tests/test_constants.py 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 0000000000000000000000000000000000000000..7af9776156f58e4b44db1af634d4c2f2d5ef91b3 GIT binary patch literal 608 zcmZXRv2WBc6vm%p=i=OP3|EF$u$6%uxCj)fQiUiTKtkwB*UMss#2gXvC2|raIi zVgU(87R1QF1pfdNVj{~4F|kGMg37}4(E|i;u%Ey8d*8F=5B+`@F#LC?r!NS=S94ef zJ4ucnVe%AWh)D{H1VmYZMaB!z|bT$#3s@Xb7 z_dMv{qMxSSKlB71ukFD@I)Occ6i12@m_W^z>d^jXY=&0TQMD*4)i}84I*U=V@}yxJ zMa-QCQWr@!YtHP3(fx2Lce3(ER?Xt;T4#D^*l*4jiON$c?pCv?M6wwD&Ms++L$rB) zv-%$vg;6E)MB9ex7-oP@nJ&}h&Pd5JjKeb2j;V4}?cH2d7lZ#o#S(3}5VKH8A)1~L zC-)ZO6&ztV9B+E}G9|tJ+Q003<62CU(i`uNy(keXSKhzZ^MpudNh!oAuN!_vWpS0t zt9k{k%pVlDacLu3!et-2e-brF7TB@Ait^~5x}Nx r@}unnKX(WgalbI$+PEJVtLXUzf9pBlfR}xrz9Bw+Yj4r_WQ+a;BNC|W literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..4770ac84510961c198cf3dfdb89fa7fae1b26f53 GIT binary patch literal 909 zcmZuvO=uHA6n?Wm$)+(a1qnhGB5l=x?GmX6!Jnprx1`o0LM}_lY}19^B%R$HvPR6I zht&3vqR{jrk@h0J#9KXk^wQjPp&+P-+$yl8h^0Kq1gJvgO_B-fG7W6P z(I8DmsRZMpF8AWZlk5%V;2v7b=A0rkvL-rmE}L7|J)vaeu$c2DBNFlJEuq0e2o;=j zo(e|;>|z`h-7tW|qy1HdQI>P75SP;VK700P0ASGvwV5xAae?vEp2Y03#cOhOX4y8s zBlh>6x?Z$&)vYYtSx{3IEpIq#>S;>N8JbnHRNJshrmn4(3pvLq7Hk#!DQhKTzEoiW zOyHXk0(%-w4ZejVb@pzi!QS55dfB|&nTQ=;Zs`Y8or&9>@Z5b;T=5lDpUz- z8c25~^o(V+MikXFc2Ke|mkkx=6vNbrJyP(9WAn!qi!uKCe8M*o^z3CcHTb1WHm*04 zyVKj_O{w|3mDqo=f2pI)9#-0u2i5kxW{Dgk-o^szR(z2;PWKpDezxF(uGm#MT8=|KWJB6tq;feZB0t|hHYdPc literal 0 HcmV?d00001 diff --git a/simple_functions/__pycache__/functions1.cpython-312.pyc b/simple_functions/__pycache__/functions1.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7af18c6732e5bfdf515311e7487429eba91d9a34 GIT binary patch literal 829 zcmb7CF>ljA6nVkctpPx6o`%ymOrhMxJ!veedr1-S^(}=SrmnXzY`|{hk2) z;LhBHoXnmeIRYDO;(<>(gm5l+f-iPN_ewu%ZRcg+R8qh<_S7Vq#DIb z?inPN*e(rmFZ8;-9VeCj$YMi3Rd65B!0w@pg^9@cnyn+C1hPkBcm}T(fIT55u`sG2 zBL_tZV$udfXi={E1Pn1%-O!=kH=dJao^512h2(3%r70O>UL|Vixm8rvqUPv``=9SShkCNx0^Q&B7 zMNgjR0`A$`UJ>(}yXNGXRKxY!+p1ir7Wj~fTkarL>9(vAWdJ8YO wB=!hlDiT6|!pb+eeWBG3U!9d!6Xi;l$kJ6=BFob<2+A*kkb5(6&a$L`0Q{D&dH?_b literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..c45dde087c9ef7703407b26baf730f6fae9f8d6d GIT binary patch literal 2059 zcmdT_yN}#N7@zTL_k0f}7bQvx6oZ6_rLcQ@w+V@qLm-4wU33MaSRsvkw)f(bUzwRr z;$d>a>iAj8xR-L~cr*kr$tOGvz@Rkrd0hBv204vfzvMN) z4Dtl=MPGnV8@t3@lTg`?j9Ry4skQps9gSTA@6yoFOq=1EJ~O`4RV7MuW#j^M$@|t^CXYv1>SSXlk6y`}ad`gscfWjb@?aNkv*Gb9 zo=)LThLk&RU(1WZmdotVmF4VK!EF@-qX_}57coE1SZJ5mB!0(b*DLf*g$AQR4*{J= zc6r^A6Yfg*Etk1=DYP^fW>SzmayvrLi!CX(rPz^TD8)@FZV5xOyXV?ez5sLugy=LB z#M%dWK@KKS%%hYEE6#i`X2OQ3d}xSA#bv_oXOlP}G|VYEjI#qTCaIT%Vudho9LliR z_^_%36zpS4Gb%2SaYhr5lkjmKdudfl;AyZh9#i=kiB&mqUB5xwxzTpsYdg1Vvh~1& z0h2F@Q@6iw^zUa$*q;`|?O}hfAcqm}@9ppP{fH!a(wA#tl_ZO2vzHg5Q!O%&rWXgt65D-^L zeMEZo9>UJ|X!wXm9L~ieBsxuuUX(dzI!W@PK7m%9F3zzi$${~BlKS$(vFelxD?2!X z&sa_G9Y|hM7Tr7bD&MDD&>=rx>?(*qbd2#!$^Qqm`7>Jo4PE`yvheWfr+*<()d2qh DwyLx@ literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..eb8ab2ccf4763a50d1e0e5925ef613d8f3328549 GIT binary patch literal 1726 zcmb_cy^kA36rb5IukHKF9YG)hw-O4+kwcS;H#=URIi*OE(dx~6^M3o@oA)ul zEH5_@tUrEQ>3xF{`dbOrvS-ZnJz$OzMHI)VgUj7W%+SCnu{t)^8mHrc#)xZ)+i@{6 z(7TA5M~GUiJ~6eWP9w*@eWHZxK9)|B6ER9ct<-ex^J9>Y5i9+542nA@v-)MMi*SVc z%m0^^M2#N!{vK1SYxMBM&2D z5zLVgfko}_jKYB|+SH-7u^r)3a7hUN+ts=BhhMz~wm-260R{8}cwshR~XF3Djh76vbII5YmZLKnVE^5&P*VrX`g0 z;&d;F$skCWtP>G*nX({P-Ynh1B)rXe%H;;>raTEU0zt;XAW$;`lVb@Mccoi3JXcf5 zRR_qX@~vaPtOaf0)kWcoP`&8s_3&zIKTTMx$lKfP)^1LEQP$dhf43DzBpD_xbx~1L zq6d-82XSkd%VwDfcuOGd#ilC4nTg(70Mx;)_z1}7=)n?Nd;0eN@2i`)th?^!ohSEA z!9Kiju5?M6UqWPqkR+v}m;t{;$S0#9R+$H>MhHzqU>sdiX(a(akWDBg05TpGjBkRy z9}xFo<1Z+pUXqePGb3>Y$PxO}y7rgd{QAZhH}2RMezPz9`ut^CU%!3r*6KaeY&%nA zI<@<*X?xRp#c7MmnBSCc)i8Vm4&<{$$Frqt31#2n>?Vhb%liCC)@En?9Q?yCsvp0PlkWB5Nz|dkOSW(w>0Z^zd7ZaFp&mW)9FTh^#`vzf+gHo~pcfxF4eWjU(!U6{ HGV=cbaG{qT literal 0 HcmV?d00001 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