|
41 | 41 | } |
42 | 42 | }, |
43 | 43 | "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", |
45 | 45 | "\n", |
46 | 46 | "Here is what we will do\n", |
47 | 47 | "\n", |
|
88 | 88 | }, |
89 | 89 | { |
90 | 90 | "cell_type": "markdown", |
91 | | - "metadata": {}, |
| 91 | + "metadata": { |
| 92 | + "nbpresent": { |
| 93 | + "id": "f0475485-ed91-4e5b-a3bd-7469b3b8947b" |
| 94 | + } |
| 95 | + }, |
92 | 96 | "source": [ |
93 | 97 | "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" |
94 | 98 | ] |
|
97 | 101 | "cell_type": "code", |
98 | 102 | "execution_count": 2, |
99 | 103 | "metadata": { |
100 | | - "collapsed": true |
| 104 | + "collapsed": true, |
| 105 | + "nbpresent": { |
| 106 | + "id": "848e2511-04eb-46bf-9d63-633d999a87ee" |
| 107 | + } |
101 | 108 | }, |
102 | 109 | "outputs": [], |
103 | 110 | "source": [ |
|
114 | 121 | }, |
115 | 122 | { |
116 | 123 | "cell_type": "markdown", |
117 | | - "metadata": {}, |
| 124 | + "metadata": { |
| 125 | + "nbpresent": { |
| 126 | + "id": "38c6569d-3e69-4e8e-9638-25fc31c455ec" |
| 127 | + } |
| 128 | + }, |
118 | 129 | "source": [ |
119 | 130 | "Now we design an API where we loop over the image, doing a calculation at each pixel location.\n", |
120 | 131 | "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 | 203 | "cell_type": "code", |
193 | 204 | "execution_count": 8, |
194 | 205 | "metadata": { |
| 206 | + "nbpresent": { |
| 207 | + "id": "e5336db1-ebd6-4ddf-93fe-1de2f67af19a" |
| 208 | + }, |
195 | 209 | "slideshow": { |
196 | 210 | "slide_type": "slide" |
197 | 211 | } |
|
222 | 236 | "cell_type": "code", |
223 | 237 | "execution_count": 11, |
224 | 238 | "metadata": { |
| 239 | + "nbpresent": { |
| 240 | + "id": "2477301c-828f-4c7a-9276-1536e4518ab6" |
| 241 | + }, |
225 | 242 | "scrolled": false, |
226 | 243 | "slideshow": { |
227 | 244 | "slide_type": "slide" |
|
1031 | 1048 | "source": [ |
1032 | 1049 | "fig, ax = subplots(1)\n", |
1033 | 1050 | "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));" |
1035 | 1052 | ] |
1036 | 1053 | }, |
1037 | 1054 | { |
1038 | | - "cell_type": "code", |
1039 | | - "execution_count": 15, |
| 1055 | + "cell_type": "markdown", |
1040 | 1056 | "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 | | - ], |
1068 | 1057 | "source": [ |
1069 | | - "%%bash\n", |
| 1058 | + "### %%bash\n", |
1070 | 1059 | "# EVERYONE KNOWS PYTHON IS TOO SLOW! So we outsource the whole thing to a contractor, keeping the format of\n", |
1071 | 1060 | "# two functions and their signatures. The contractor rewrites it in C, now the ``*val`` make sense\n", |
1072 | 1061 | "cat mandel.c" |
|
1075 | 1064 | { |
1076 | 1065 | "cell_type": "code", |
1077 | 1066 | "execution_count": 16, |
1078 | | - "metadata": {}, |
| 1067 | + "metadata": { |
| 1068 | + "nbpresent": { |
| 1069 | + "id": "05edfb6e-ca49-470a-a1fd-19e36c908a7e" |
| 1070 | + } |
| 1071 | + }, |
1079 | 1072 | "outputs": [ |
1080 | 1073 | { |
1081 | 1074 | "name": "stdout", |
|
1115 | 1108 | { |
1116 | 1109 | "cell_type": "code", |
1117 | 1110 | "execution_count": 18, |
1118 | | - "metadata": {}, |
| 1111 | + "metadata": { |
| 1112 | + "nbpresent": { |
| 1113 | + "id": "728b3e91-ccb1-4ce4-8da1-3005580df8c7" |
| 1114 | + } |
| 1115 | + }, |
1119 | 1116 | "outputs": [ |
1120 | 1117 | { |
1121 | 1118 | "name": "stdout", |
|
1188 | 1185 | "cell_type": "code", |
1189 | 1186 | "execution_count": 19, |
1190 | 1187 | "metadata": { |
1191 | | - "collapsed": true |
| 1188 | + "collapsed": true, |
| 1189 | + "nbpresent": { |
| 1190 | + "id": "4546c856-db4f-4dce-95fc-7363a463a8d0" |
| 1191 | + } |
1192 | 1192 | }, |
1193 | 1193 | "outputs": [], |
1194 | 1194 | "source": [ |
|
1201 | 1201 | "cell_type": "code", |
1202 | 1202 | "execution_count": 20, |
1203 | 1203 | "metadata": { |
| 1204 | + "nbpresent": { |
| 1205 | + "id": "21a2f51d-22e3-4957-b953-1001eef24e17" |
| 1206 | + }, |
1204 | 1207 | "scrolled": false |
1205 | 1208 | }, |
1206 | 1209 | "outputs": [ |
|
2928 | 2931 | { |
2929 | 2932 | "cell_type": "code", |
2930 | 2933 | "execution_count": 25, |
2931 | | - "metadata": {}, |
| 2934 | + "metadata": { |
| 2935 | + "collapsed": true |
| 2936 | + }, |
2932 | 2937 | "outputs": [], |
2933 | 2938 | "source": [ |
2934 | 2939 | "#cffi\n", |
|
6295 | 6300 | ], |
6296 | 6301 | "metadata": { |
6297 | 6302 | "anaconda-cloud": {}, |
6298 | | - "celltoolbar": "Slideshow", |
| 6303 | + "celltoolbar": "Raw Cell Format", |
6299 | 6304 | "kernelspec": { |
6300 | 6305 | "display_name": "Python 3", |
6301 | 6306 | "language": "python", |
|
6315 | 6320 | }, |
6316 | 6321 | "nbpresent": { |
6317 | 6322 | "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 | + }, |
6318 | 6381 | "3d7e0ae8-9433-41ca-9945-a70ab1cdc407": { |
6319 | 6382 | "id": "3d7e0ae8-9433-41ca-9945-a70ab1cdc407", |
6320 | 6383 | "prev": null, |
|
6348 | 6411 | }, |
6349 | 6412 | "theme": null |
6350 | 6413 | }, |
| 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 | + }, |
6351 | 6471 | "66d2e406-0d60-4c2f-8e26-f759144b0c42": { |
6352 | 6472 | "id": "66d2e406-0d60-4c2f-8e26-f759144b0c42", |
6353 | 6473 | "layout": "manual", |
|
6384 | 6504 | "y": 0 |
6385 | 6505 | }, |
6386 | 6506 | "content": { |
6387 | | - "cell": "c687a4f1-bace-4d72-8fdf-d08ae4c34a19", |
| 6507 | + "cell": "f0475485-ed91-4e5b-a3bd-7469b3b8947b", |
6388 | 6508 | "part": "source" |
6389 | 6509 | }, |
6390 | 6510 | "id": "6b8dc0c9-d025-456a-aa63-150ce1940bf5" |
6391 | 6511 | } |
6392 | 6512 | } |
6393 | 6513 | }, |
| 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 | + }, |
6394 | 6533 | "dd4d838c-6cab-454b-92e0-deec09a65fe3": { |
6395 | 6534 | "id": "dd4d838c-6cab-454b-92e0-deec09a65fe3", |
6396 | 6535 | "prev": "cdcb633d-b1c7-4fac-9f4f-983b7d9b79df", |
|
0 commit comments