Skip to content

Commit bf35821

Browse files
committed
add nbpresent slide data
1 parent 448b10b commit bf35821

File tree

1 file changed

+180
-41
lines changed

1 file changed

+180
-41
lines changed

pycon2017_cffi.ipynb

Lines changed: 180 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
}
4242
},
4343
"source": [
44-
"### Why did you bother to show up? There is a lecture about Grumpy and PyPy next door\n",
44+
"### Thanks for coming, I too would rather be in the lecture about Grumpy and PyPy next door\n",
4545
"\n",
4646
"Here is what we will do\n",
4747
"\n",
@@ -88,7 +88,11 @@
8888
},
8989
{
9090
"cell_type": "markdown",
91-
"metadata": {},
91+
"metadata": {
92+
"nbpresent": {
93+
"id": "f0475485-ed91-4e5b-a3bd-7469b3b8947b"
94+
}
95+
},
9296
"source": [
9397
"Our mission: to create a fractal image. Hmm, what is an image? We decide to define a simple structure to hold the image: width, height, data-as-pointer"
9498
]
@@ -97,7 +101,10 @@
97101
"cell_type": "code",
98102
"execution_count": 2,
99103
"metadata": {
100-
"collapsed": true
104+
"collapsed": true,
105+
"nbpresent": {
106+
"id": "848e2511-04eb-46bf-9d63-633d999a87ee"
107+
}
101108
},
102109
"outputs": [],
103110
"source": [
@@ -114,7 +121,11 @@
114121
},
115122
{
116123
"cell_type": "markdown",
117-
"metadata": {},
124+
"metadata": {
125+
"nbpresent": {
126+
"id": "38c6569d-3e69-4e8e-9638-25fc31c455ec"
127+
}
128+
},
118129
"source": [
119130
"Now we design an API where we loop over the image, doing a calculation at each pixel location.\n",
120131
"For reasons known to only a select few, we normalize the horizontal values to be from -2 to 1 and the vertical values to -1 to 1, and then call a function with these normalized values. Also, our system architect is adamant that every function return a status, so our calculation function must accept a pointer to the value to be returned. This makes more sense in C, but can be done in python as well, although awkwardly.\n",
@@ -192,6 +203,9 @@
192203
"cell_type": "code",
193204
"execution_count": 8,
194205
"metadata": {
206+
"nbpresent": {
207+
"id": "e5336db1-ebd6-4ddf-93fe-1de2f67af19a"
208+
},
195209
"slideshow": {
196210
"slide_type": "slide"
197211
}
@@ -222,6 +236,9 @@
222236
"cell_type": "code",
223237
"execution_count": 11,
224238
"metadata": {
239+
"nbpresent": {
240+
"id": "2477301c-828f-4c7a-9276-1536e4518ab6"
241+
},
225242
"scrolled": false,
226243
"slideshow": {
227244
"slide_type": "slide"
@@ -1031,42 +1048,14 @@
10311048
"source": [
10321049
"fig, ax = subplots(1)\n",
10331050
"img = Image.open('python_numpy.png')\n",
1034-
"ax.imshow(img); ax.set_title('pure python, {:.2f} millisecs'.format(pure_python*1000))"
1051+
"ax.imshow(img); ax.set_title('pure python, {:.2f} millisecs'.format(pure_python*1000));"
10351052
]
10361053
},
10371054
{
1038-
"cell_type": "code",
1039-
"execution_count": 15,
1055+
"cell_type": "markdown",
10401056
"metadata": {},
1041-
"outputs": [
1042-
{
1043-
"name": "stdout",
1044-
"output_type": "stream",
1045-
"text": [
1046-
"#include <complex.h>\n",
1047-
"\n",
1048-
"int mandel(float x, float y, int max_iters, unsigned char * val)\n",
1049-
"{\n",
1050-
" int i = 0;\n",
1051-
" _Complex float c = CMPLX(x, y);\n",
1052-
" _Complex float z = CMPLX(0, 0);\n",
1053-
" for (i = 0; i < max_iters; i++)\n",
1054-
" {\n",
1055-
" z = z * z + c;\n",
1056-
" if ((crealf(z) * crealf(z) + cimagf(z) * cimagf(z)) >= 4)\n",
1057-
" {\n",
1058-
" *val = i;\n",
1059-
" return 0;\n",
1060-
" }\n",
1061-
" }\n",
1062-
" *val = max_iters;\n",
1063-
" return 1;\n",
1064-
"}\n"
1065-
]
1066-
}
1067-
],
10681057
"source": [
1069-
"%%bash\n",
1058+
"### %%bash\n",
10701059
"# EVERYONE KNOWS PYTHON IS TOO SLOW! So we outsource the whole thing to a contractor, keeping the format of\n",
10711060
"# two functions and their signatures. The contractor rewrites it in C, now the ``*val`` make sense\n",
10721061
"cat mandel.c"
@@ -1075,7 +1064,11 @@
10751064
{
10761065
"cell_type": "code",
10771066
"execution_count": 16,
1078-
"metadata": {},
1067+
"metadata": {
1068+
"nbpresent": {
1069+
"id": "05edfb6e-ca49-470a-a1fd-19e36c908a7e"
1070+
}
1071+
},
10791072
"outputs": [
10801073
{
10811074
"name": "stdout",
@@ -1115,7 +1108,11 @@
11151108
{
11161109
"cell_type": "code",
11171110
"execution_count": 18,
1118-
"metadata": {},
1111+
"metadata": {
1112+
"nbpresent": {
1113+
"id": "728b3e91-ccb1-4ce4-8da1-3005580df8c7"
1114+
}
1115+
},
11191116
"outputs": [
11201117
{
11211118
"name": "stdout",
@@ -1188,7 +1185,10 @@
11881185
"cell_type": "code",
11891186
"execution_count": 19,
11901187
"metadata": {
1191-
"collapsed": true
1188+
"collapsed": true,
1189+
"nbpresent": {
1190+
"id": "4546c856-db4f-4dce-95fc-7363a463a8d0"
1191+
}
11921192
},
11931193
"outputs": [],
11941194
"source": [
@@ -1201,6 +1201,9 @@
12011201
"cell_type": "code",
12021202
"execution_count": 20,
12031203
"metadata": {
1204+
"nbpresent": {
1205+
"id": "21a2f51d-22e3-4957-b953-1001eef24e17"
1206+
},
12041207
"scrolled": false
12051208
},
12061209
"outputs": [
@@ -2928,7 +2931,9 @@
29282931
{
29292932
"cell_type": "code",
29302933
"execution_count": 25,
2931-
"metadata": {},
2934+
"metadata": {
2935+
"collapsed": true
2936+
},
29322937
"outputs": [],
29332938
"source": [
29342939
"#cffi\n",
@@ -6295,7 +6300,7 @@
62956300
],
62966301
"metadata": {
62976302
"anaconda-cloud": {},
6298-
"celltoolbar": "Slideshow",
6303+
"celltoolbar": "Raw Cell Format",
62996304
"kernelspec": {
63006305
"display_name": "Python 3",
63016306
"language": "python",
@@ -6315,6 +6320,64 @@
63156320
},
63166321
"nbpresent": {
63176322
"slides": {
6323+
"186e3230-ca33-4009-9cb3-59f5152f3ed6": {
6324+
"id": "186e3230-ca33-4009-9cb3-59f5152f3ed6",
6325+
"prev": "47c7d149-648a-4d1f-b383-3cec9b152d86",
6326+
"regions": {
6327+
"f4f6215d-4165-43b4-9663-1fb98d51172d": {
6328+
"attrs": {
6329+
"height": 1,
6330+
"width": 1,
6331+
"x": 0,
6332+
"y": 0
6333+
},
6334+
"content": {
6335+
"cell": "e5336db1-ebd6-4ddf-93fe-1de2f67af19a",
6336+
"part": "whole"
6337+
},
6338+
"id": "f4f6215d-4165-43b4-9663-1fb98d51172d"
6339+
}
6340+
}
6341+
},
6342+
"3126aa1c-56f8-4a18-ab03-51830681c38f": {
6343+
"id": "3126aa1c-56f8-4a18-ab03-51830681c38f",
6344+
"prev": "dd4d838c-6cab-454b-92e0-deec09a65fe3",
6345+
"regions": {
6346+
"1510fa89-1d4a-416c-9bda-1c7e6e69062f": {
6347+
"attrs": {
6348+
"height": 1,
6349+
"width": 1,
6350+
"x": 0,
6351+
"y": 0
6352+
},
6353+
"content": {
6354+
"cell": "38c6569d-3e69-4e8e-9638-25fc31c455ec",
6355+
"part": "source"
6356+
},
6357+
"id": "1510fa89-1d4a-416c-9bda-1c7e6e69062f"
6358+
}
6359+
}
6360+
},
6361+
"3b180b7a-1548-4c41-98e1-00556dbc5bd7": {
6362+
"id": "3b180b7a-1548-4c41-98e1-00556dbc5bd7",
6363+
"prev": "cc4c502d-5c74-4ab6-a563-c7b2eb810f3d",
6364+
"regions": {
6365+
"cb144901-1093-45dd-9b9e-c77c79357a06": {
6366+
"attrs": {
6367+
"height": 1,
6368+
"width": 1,
6369+
"x": 0,
6370+
"y": 0
6371+
},
6372+
"content": {
6373+
"cell": "601820db-fdf7-4242-83fa-01868f04b3ac",
6374+
"part": "whole"
6375+
},
6376+
"id": "cb144901-1093-45dd-9b9e-c77c79357a06"
6377+
}
6378+
},
6379+
"theme": "d7885e3c-5b9e-4f88-86e4-94492910f1eb"
6380+
},
63186381
"3d7e0ae8-9433-41ca-9945-a70ab1cdc407": {
63196382
"id": "3d7e0ae8-9433-41ca-9945-a70ab1cdc407",
63206383
"prev": null,
@@ -6348,6 +6411,63 @@
63486411
},
63496412
"theme": null
63506413
},
6414+
"47c7d149-648a-4d1f-b383-3cec9b152d86": {
6415+
"id": "47c7d149-648a-4d1f-b383-3cec9b152d86",
6416+
"prev": "d5665980-b87c-498d-940b-9b7ec11b3762",
6417+
"regions": {
6418+
"866a7555-581f-4a92-99ef-b8f74af2da58": {
6419+
"attrs": {
6420+
"height": 1,
6421+
"width": 1,
6422+
"x": 0,
6423+
"y": 0
6424+
},
6425+
"content": {
6426+
"cell": "c687a4f1-bace-4d72-8fdf-d08ae4c34a19",
6427+
"part": "source"
6428+
},
6429+
"id": "866a7555-581f-4a92-99ef-b8f74af2da58"
6430+
}
6431+
}
6432+
},
6433+
"6095ed0a-275b-435d-b407-937c2f051503": {
6434+
"id": "6095ed0a-275b-435d-b407-937c2f051503",
6435+
"prev": "e236fbe4-5b06-4bfb-83a3-be512c56d697",
6436+
"regions": {
6437+
"1b9fe3eb-cddc-4005-80dd-8a7dd5eadd5c": {
6438+
"attrs": {
6439+
"height": 1,
6440+
"width": 1,
6441+
"x": 0,
6442+
"y": 0
6443+
},
6444+
"content": {
6445+
"cell": "21a2f51d-22e3-4957-b953-1001eef24e17",
6446+
"part": "whole"
6447+
},
6448+
"id": "1b9fe3eb-cddc-4005-80dd-8a7dd5eadd5c"
6449+
}
6450+
}
6451+
},
6452+
"66b6e285-73fa-452b-b783-a6ecdcc71f63": {
6453+
"id": "66b6e285-73fa-452b-b783-a6ecdcc71f63",
6454+
"prev": "3b180b7a-1548-4c41-98e1-00556dbc5bd7",
6455+
"regions": {
6456+
"8fe8f0a7-c631-486b-bf6d-cac82c8b7c85": {
6457+
"attrs": {
6458+
"height": 1,
6459+
"width": 1,
6460+
"x": 0,
6461+
"y": 0
6462+
},
6463+
"content": {
6464+
"cell": "728b3e91-ccb1-4ce4-8da1-3005580df8c7",
6465+
"part": "whole"
6466+
},
6467+
"id": "8fe8f0a7-c631-486b-bf6d-cac82c8b7c85"
6468+
}
6469+
}
6470+
},
63516471
"66d2e406-0d60-4c2f-8e26-f759144b0c42": {
63526472
"id": "66d2e406-0d60-4c2f-8e26-f759144b0c42",
63536473
"layout": "manual",
@@ -6384,13 +6504,32 @@
63846504
"y": 0
63856505
},
63866506
"content": {
6387-
"cell": "c687a4f1-bace-4d72-8fdf-d08ae4c34a19",
6507+
"cell": "f0475485-ed91-4e5b-a3bd-7469b3b8947b",
63886508
"part": "source"
63896509
},
63906510
"id": "6b8dc0c9-d025-456a-aa63-150ce1940bf5"
63916511
}
63926512
}
63936513
},
6514+
"d5665980-b87c-498d-940b-9b7ec11b3762": {
6515+
"id": "d5665980-b87c-498d-940b-9b7ec11b3762",
6516+
"prev": "3126aa1c-56f8-4a18-ab03-51830681c38f",
6517+
"regions": {
6518+
"bec62cd1-de89-4406-8096-1be054176369": {
6519+
"attrs": {
6520+
"height": 1,
6521+
"width": 1,
6522+
"x": 0,
6523+
"y": 0
6524+
},
6525+
"content": {
6526+
"cell": "ab8a8171-ccc1-40d7-88fb-e05d0ae3dd40",
6527+
"part": "source"
6528+
},
6529+
"id": "bec62cd1-de89-4406-8096-1be054176369"
6530+
}
6531+
}
6532+
},
63946533
"dd4d838c-6cab-454b-92e0-deec09a65fe3": {
63956534
"id": "dd4d838c-6cab-454b-92e0-deec09a65fe3",
63966535
"prev": "cdcb633d-b1c7-4fac-9f4f-983b7d9b79df",

0 commit comments

Comments
 (0)