Skip to content

Commit 22bb649

Browse files
committed
init project
0 parents  commit 22bb649

File tree

8 files changed

+317
-0
lines changed

8 files changed

+317
-0
lines changed

Diff for: .gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.ipynb_checkpoints/
2+
build/
3+
dist/
4+
pythonbasic.egg-info/
5+
*.pyc
6+
7+

Diff for: basic/__init__.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
fib = lambda n: 1 if n < 2 else fib(n-1) + fib(n-2)
3+
4+
5+
def gen_x(x0):
6+
x = lambda n: x0 if n < 2 else 1. + 1./(x(n-1)+1)
7+
return x
8+
9+
10+
def mem(f):
11+
res = {}
12+
def new_f(n):
13+
if n not in res:
14+
res[n] = f(n)
15+
return res[n]
16+
return new_f
17+

Diff for: bin/test.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import os
2+
from basic import gen_x, mem
3+
4+
X0 = float(os.environ.get("X0",1.))
5+
M = int(os.environ.get("M",20))
6+
7+
x = gen_x(X0)
8+
9+
for m in range(M):
10+
print "x("+str(m)+") = ", x(m)
11+
12+
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
13+
14+
15+
@mem
16+
def fib(n):
17+
return 1 if n < 2 else fib(n-1)+fib(n-2)
18+
19+
20+
for m in range(M):
21+
print "fib("+str(m)+") = ", fib(m)
22+
23+
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
24+
25+
26+
@mem
27+
def mfib(n):
28+
return 1 if n < 2 else mfib(n-1)+mfib(n-2)+mfib(n-3)
29+
30+
31+
for m in range(M):
32+
print "mfib("+str(m)+") = ", mfib(m)
33+
34+
35+
36+

Diff for: ipynbs/Untitled.ipynb

+234
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {
7+
"collapsed": true
8+
},
9+
"outputs": [],
10+
"source": [
11+
"import a"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": 2,
17+
"metadata": {
18+
"collapsed": false
19+
},
20+
"outputs": [
21+
{
22+
"data": {
23+
"text/plain": [
24+
"123"
25+
]
26+
},
27+
"execution_count": 2,
28+
"metadata": {},
29+
"output_type": "execute_result"
30+
}
31+
],
32+
"source": [
33+
"a.x"
34+
]
35+
},
36+
{
37+
"cell_type": "code",
38+
"execution_count": 4,
39+
"metadata": {
40+
"collapsed": false
41+
},
42+
"outputs": [
43+
{
44+
"data": {
45+
"text/plain": [
46+
"['__builtins__',\n",
47+
" '__doc__',\n",
48+
" '__file__',\n",
49+
" '__name__',\n",
50+
" '__package__',\n",
51+
" 'x',\n",
52+
" 'y',\n",
53+
" 'z']"
54+
]
55+
},
56+
"execution_count": 4,
57+
"metadata": {},
58+
"output_type": "execute_result"
59+
}
60+
],
61+
"source": [
62+
"dir(a)"
63+
]
64+
},
65+
{
66+
"cell_type": "code",
67+
"execution_count": 5,
68+
"metadata": {
69+
"collapsed": true
70+
},
71+
"outputs": [],
72+
"source": [
73+
"import b"
74+
]
75+
},
76+
{
77+
"cell_type": "code",
78+
"execution_count": 6,
79+
"metadata": {
80+
"collapsed": false
81+
},
82+
"outputs": [
83+
{
84+
"data": {
85+
"text/plain": [
86+
"['__builtins__',\n",
87+
" '__doc__',\n",
88+
" '__file__',\n",
89+
" '__name__',\n",
90+
" '__package__',\n",
91+
" '__path__',\n",
92+
" 's',\n",
93+
" 't',\n",
94+
" 'z']"
95+
]
96+
},
97+
"execution_count": 6,
98+
"metadata": {},
99+
"output_type": "execute_result"
100+
}
101+
],
102+
"source": [
103+
"dir(b)"
104+
]
105+
},
106+
{
107+
"cell_type": "code",
108+
"execution_count": 7,
109+
"metadata": {
110+
"collapsed": true
111+
},
112+
"outputs": [],
113+
"source": [
114+
"import b.m"
115+
]
116+
},
117+
{
118+
"cell_type": "code",
119+
"execution_count": 9,
120+
"metadata": {
121+
"collapsed": false
122+
},
123+
"outputs": [
124+
{
125+
"data": {
126+
"text/plain": [
127+
"['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'p', 'r']"
128+
]
129+
},
130+
"execution_count": 9,
131+
"metadata": {},
132+
"output_type": "execute_result"
133+
}
134+
],
135+
"source": [
136+
"dir(b.m)"
137+
]
138+
},
139+
{
140+
"cell_type": "code",
141+
"execution_count": 10,
142+
"metadata": {
143+
"collapsed": false
144+
},
145+
"outputs": [
146+
{
147+
"ename": "ImportError",
148+
"evalue": "No module named c",
149+
"output_type": "error",
150+
"traceback": [
151+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
152+
"\u001b[1;31mImportError\u001b[0m Traceback (most recent call last)",
153+
"\u001b[1;32m<ipython-input-10-600d7d3e28bb>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[1;32mimport\u001b[0m \u001b[0mc\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
154+
"\u001b[1;31mImportError\u001b[0m: No module named c"
155+
]
156+
}
157+
],
158+
"source": [
159+
"import c"
160+
]
161+
},
162+
{
163+
"cell_type": "code",
164+
"execution_count": 1,
165+
"metadata": {
166+
"collapsed": false
167+
},
168+
"outputs": [],
169+
"source": [
170+
"from basic import fib"
171+
]
172+
},
173+
{
174+
"cell_type": "code",
175+
"execution_count": 2,
176+
"metadata": {
177+
"collapsed": false
178+
},
179+
"outputs": [
180+
{
181+
"name": "stdout",
182+
"output_type": "stream",
183+
"text": [
184+
"CPU times: user 3.42 s, sys: 10 ms, total: 3.43 s\n",
185+
"Wall time: 3.45 s\n"
186+
]
187+
},
188+
{
189+
"data": {
190+
"text/plain": [
191+
"14930352"
192+
]
193+
},
194+
"execution_count": 2,
195+
"metadata": {},
196+
"output_type": "execute_result"
197+
}
198+
],
199+
"source": [
200+
"%time fib(35)"
201+
]
202+
},
203+
{
204+
"cell_type": "code",
205+
"execution_count": null,
206+
"metadata": {
207+
"collapsed": true
208+
},
209+
"outputs": [],
210+
"source": []
211+
}
212+
],
213+
"metadata": {
214+
"kernelspec": {
215+
"display_name": "Python 2",
216+
"language": "python",
217+
"name": "python2"
218+
},
219+
"language_info": {
220+
"codemirror_mode": {
221+
"name": "ipython",
222+
"version": 2
223+
},
224+
"file_extension": ".py",
225+
"mimetype": "text/x-python",
226+
"name": "python",
227+
"nbconvert_exporter": "python",
228+
"pygments_lexer": "ipython2",
229+
"version": "2.7.11"
230+
}
231+
},
232+
"nbformat": 4,
233+
"nbformat_minor": 0
234+
}

Diff for: ipynbs/a.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
x = 123
2+
y= 234
3+
z =[]

Diff for: ipynbs/b/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
t = 123
2+
s = 321
3+
z = []
4+
5+

Diff for: ipynbs/b/m.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
r = 123
2+
p = 321

Diff for: setup.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from setuptools import setup, find_packages
2+
3+
setup(
4+
name='pythonbasic',
5+
version='0.0.1dev0',
6+
author='Chia-Chi Chang',
7+
author_email='[email protected]',
8+
packages=find_packages(),
9+
install_requires=[],
10+
)
11+
12+
13+

0 commit comments

Comments
 (0)