-
Notifications
You must be signed in to change notification settings - Fork 1
/
slides.html
587 lines (562 loc) · 155 KB
/
slides.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
<!DOCTYPE html><html lang="en-US"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0"><meta name="apple-mobile-web-app-capable" content="yes"><meta http-equiv="X-UA-Compatible" content="ie=edge"><meta property="og:type" content="website"><meta name="twitter:card" content="summary"><style>@media screen{body,html{background:#000;height:100%;margin:0;overflow:hidden}[data-bespoke-marp-fragment=inactive]{visibility:hidden}.bespoke-marp-osc{display:none;opacity:0}.bespoke-marp-parent{bottom:0;left:0;position:absolute;right:0;top:0}.bespoke-marp-parent>.bespoke-marp-osc{background:rgba(0,0,0,.65);border-radius:7px;bottom:50px;color:#fff;display:block;font-family:Helvetica,Arial,sans-serif;font-size:16px;left:50%;line-height:0;opacity:1;padding:12px;position:absolute;touch-action:manipulation;transform:translateX(-50%);transition:opacity .2s linear;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;white-space:nowrap;z-index:1}.bespoke-marp-parent>.bespoke-marp-osc>*{margin-left:6px}.bespoke-marp-parent>.bespoke-marp-osc>:first-child{margin-left:0}.bespoke-marp-parent>.bespoke-marp-osc>span{opacity:.8}.bespoke-marp-parent>.bespoke-marp-osc>span[data-bespoke-marp-osc=page]{display:inline-block;min-width:140px;text-align:center}.bespoke-marp-parent>.bespoke-marp-osc>button{-webkit-appearance:none;-moz-appearance:none;appearance:none;background-color:transparent;border:0;color:inherit;cursor:pointer;font-size:inherit;opacity:.8;outline:none;padding:0;transition:opacity .2s linear;-webkit-tap-highlight-color:transparent}.bespoke-marp-parent>.bespoke-marp-osc>button:disabled{cursor:not-allowed;opacity:.15!important}.bespoke-marp-parent>.bespoke-marp-osc>button:hover{opacity:1}.bespoke-marp-parent>.bespoke-marp-osc>button:hover:active{opacity:.6}.bespoke-marp-parent>.bespoke-marp-osc>button:hover:not(:disabled){transition:none}.bespoke-marp-parent>.bespoke-marp-osc>button[data-bespoke-marp-osc=prev]{background:transparent url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj48cGF0aCBmaWxsPSJub25lIiBzdHJva2U9IiNmZmYiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLXdpZHRoPSI1IiBkPSJNNjggOTBMMjggNTBsNDAtNDAiLz48L3N2Zz4=") no-repeat 50%;background-size:contain;height:32px;overflow:hidden;text-indent:100%;white-space:nowrap;width:32px}.bespoke-marp-parent>.bespoke-marp-osc>button[data-bespoke-marp-osc=next]{background:transparent url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj48cGF0aCBmaWxsPSJub25lIiBzdHJva2U9IiNmZmYiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgc3Ryb2tlLXdpZHRoPSI1IiBkPSJNMzIgOTBsNDAtNDAtNDAtNDAiLz48L3N2Zz4=") no-repeat 50%;background-size:contain;height:32px;overflow:hidden;text-indent:100%;white-space:nowrap;width:32px}.bespoke-marp-parent>.bespoke-marp-osc>button[data-bespoke-marp-osc=fullscreen]{background:transparent url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj48ZGVmcz48c3R5bGU+LmF7ZmlsbDpub25lO3N0cm9rZTojZmZmO3N0cm9rZS1saW5lY2FwOnJvdW5kO3N0cm9rZS1saW5lam9pbjpyb3VuZDtzdHJva2Utd2lkdGg6NXB4fTwvc3R5bGU+PC9kZWZzPjxyZWN0IGNsYXNzPSJhIiB4PSIxMCIgeT0iMjAiIHdpZHRoPSI4MCIgaGVpZ2h0PSI2MCIgcng9IjUuNjciLz48cGF0aCBjbGFzcz0iYSIgZD0iTTQwIDcwSDIwVjUwbTIwIDBMMjAgNzBtNDAtNDBoMjB2MjBtLTIwIDBsMjAtMjAiLz48L3N2Zz4=") no-repeat 50%;background-size:contain;height:32px;overflow:hidden;text-indent:100%;white-space:nowrap;width:32px}.bespoke-marp-parent>.bespoke-marp-osc>button[data-bespoke-marp-osc=fullscreen].exit{background-image:url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj48ZGVmcz48c3R5bGU+LmF7ZmlsbDpub25lO3N0cm9rZTojZmZmO3N0cm9rZS1saW5lY2FwOnJvdW5kO3N0cm9rZS1saW5lam9pbjpyb3VuZDtzdHJva2Utd2lkdGg6NXB4fTwvc3R5bGU+PC9kZWZzPjxyZWN0IGNsYXNzPSJhIiB4PSIxMCIgeT0iMjAiIHdpZHRoPSI4MCIgaGVpZ2h0PSI2MCIgcng9IjUuNjciLz48cGF0aCBjbGFzcz0iYSIgZD0iTTIwIDUwaDIwdjIwbS0yMCAwbDIwLTIwbTQwIDBINjBWMzBtMjAgMEw2MCA1MCIvPjwvc3ZnPg==")}.bespoke-marp-parent.bespoke-marp-inactive{cursor:none}.bespoke-marp-parent.bespoke-marp-inactive>.bespoke-marp-osc{opacity:0;pointer-events:none}svg.bespoke-marp-slide{height:100%;left:0;pointer-events:none;position:absolute;top:0;width:100%;z-index:-1}svg.bespoke-marp-slide.bespoke-marp-active{pointer-events:auto;z-index:0}.bespoke-progress-parent{background:#222;display:flex;height:5px;width:100%}.bespoke-progress-parent+.bespoke-marp-parent{top:5px}.bespoke-progress-parent .bespoke-progress-bar{flex:0 0 0;background:#0288d1;transition:flex-basis .2s cubic-bezier(0,1,1,1)}}@media print{.bespoke-marp-osc,.bespoke-progress-parent{display:none!important;transition:none!important}.bespoke-marp-parent{top:0}}</style><style>@charset "UTF-8";@import url("https://fonts.googleapis.com/css?family=Lato:400,900|Roboto+Mono:400,700");article#presentation > svg > foreignObject > section {
width: 1280px;
height: 720px;
box-sizing: border-box;
overflow: hidden;
position: relative;
scroll-snap-align: center center;
}article#presentation > svg > foreignObject > section::after {
bottom: 0;
content: attr(data-marpit-pagination);
padding: inherit;
pointer-events: none;
position: absolute;
right: 0;
}article#presentation > svg > foreignObject > section:not([data-marpit-pagination])::after {
display: none;
}/* Normalization */article#presentation > svg > foreignObject > section h1 {
font-size: 2em;
margin: 0.67em 0;
}@page {
size: 1280px 720px;
margin: 0;
}@media print {html, body {
background-color: #fff;
margin: 0;
page-break-inside: avoid;
break-inside: avoid-page;
}
article#presentation > svg > foreignObject > section {
page-break-before: always;
break-before: page;
}
article#presentation > svg > foreignObject > section, article#presentation > svg > foreignObject > section * {
-webkit-print-color-adjust: exact !important;
color-adjust: exact !important;
}
article#presentation > svg[data-marpit-svg] {
display: block;
height: 100vh;
width: 100vw;
}
}@font-face{font-family:KaTeX_AMS;src:url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_AMS-Regular.woff2') format("woff2"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_AMS-Regular.woff') format("woff"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_AMS-Regular.ttf') format("truetype");font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Caligraphic;src:url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Caligraphic-Bold.woff2') format("woff2"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Caligraphic-Bold.woff') format("woff"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Caligraphic-Bold.ttf') format("truetype");font-weight:700;font-style:normal}@font-face{font-family:KaTeX_Caligraphic;src:url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Caligraphic-Regular.woff2') format("woff2"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Caligraphic-Regular.woff') format("woff"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Caligraphic-Regular.ttf') format("truetype");font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Fraktur;src:url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Fraktur-Bold.woff2') format("woff2"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Fraktur-Bold.woff') format("woff"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Fraktur-Bold.ttf') format("truetype");font-weight:700;font-style:normal}@font-face{font-family:KaTeX_Fraktur;src:url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Fraktur-Regular.woff2') format("woff2"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Fraktur-Regular.woff') format("woff"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Fraktur-Regular.ttf') format("truetype");font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Main;src:url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Main-Bold.woff2') format("woff2"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Main-Bold.woff') format("woff"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Main-Bold.ttf') format("truetype");font-weight:700;font-style:normal}@font-face{font-family:KaTeX_Main;src:url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Main-BoldItalic.woff2') format("woff2"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Main-BoldItalic.woff') format("woff"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Main-BoldItalic.ttf') format("truetype");font-weight:700;font-style:italic}@font-face{font-family:KaTeX_Main;src:url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Main-Italic.woff2') format("woff2"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Main-Italic.woff') format("woff"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Main-Italic.ttf') format("truetype");font-weight:400;font-style:italic}@font-face{font-family:KaTeX_Main;src:url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Main-Regular.woff2') format("woff2"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Main-Regular.woff') format("woff"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Main-Regular.ttf') format("truetype");font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Math;src:url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Math-BoldItalic.woff2') format("woff2"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Math-BoldItalic.woff') format("woff"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Math-BoldItalic.ttf') format("truetype");font-weight:700;font-style:italic}@font-face{font-family:KaTeX_Math;src:url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Math-Italic.woff2') format("woff2"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Math-Italic.woff') format("woff"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Math-Italic.ttf') format("truetype");font-weight:400;font-style:italic}@font-face{font-family:"KaTeX_SansSerif";src:url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_SansSerif-Bold.woff2') format("woff2"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_SansSerif-Bold.woff') format("woff"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_SansSerif-Bold.ttf') format("truetype");font-weight:700;font-style:normal}@font-face{font-family:"KaTeX_SansSerif";src:url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_SansSerif-Italic.woff2') format("woff2"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_SansSerif-Italic.woff') format("woff"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_SansSerif-Italic.ttf') format("truetype");font-weight:400;font-style:italic}@font-face{font-family:"KaTeX_SansSerif";src:url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_SansSerif-Regular.woff2') format("woff2"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_SansSerif-Regular.woff') format("woff"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_SansSerif-Regular.ttf') format("truetype");font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Script;src:url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Script-Regular.woff2') format("woff2"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Script-Regular.woff') format("woff"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Script-Regular.ttf') format("truetype");font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Size1;src:url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size1-Regular.woff2') format("woff2"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size1-Regular.woff') format("woff"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size1-Regular.ttf') format("truetype");font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Size2;src:url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size2-Regular.woff2') format("woff2"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size2-Regular.woff') format("woff"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size2-Regular.ttf') format("truetype");font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Size3;src:url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size3-Regular.woff2') format("woff2"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size3-Regular.woff') format("woff"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size3-Regular.ttf') format("truetype");font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Size4;src:url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size4-Regular.woff2') format("woff2"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size4-Regular.woff') format("woff"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size4-Regular.ttf') format("truetype");font-weight:400;font-style:normal}@font-face{font-family:KaTeX_Typewriter;src:url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Typewriter-Regular.woff2') format("woff2"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Typewriter-Regular.woff') format("woff"),url('https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Typewriter-Regular.ttf') format("truetype");font-weight:400;font-style:normal}article#presentation > svg > foreignObject > section .katex{font:normal 1.21em KaTeX_Main,Times New Roman,serif;line-height:1.2;text-indent:0;text-rendering:auto}article#presentation > svg > foreignObject > section .katex *{-ms-high-contrast-adjust:none!important}article#presentation > svg > foreignObject > section .katex .katex-version:after{content:"0.10.2"}article#presentation > svg > foreignObject > section .katex .katex-mathml{position:absolute;clip:rect(1px,1px,1px,1px);padding:0;border:0;height:1px;width:1px;overflow:hidden}article#presentation > svg > foreignObject > section .katex .katex-html>.newline{display:block}article#presentation > svg > foreignObject > section .katex .base{position:relative;white-space:nowrap;width:-webkit-min-content;width:-moz-min-content;width:min-content}article#presentation > svg > foreignObject > section .katex .base,article#presentation > svg > foreignObject > section .katex .strut{display:inline-block}article#presentation > svg > foreignObject > section .katex .textbf{font-weight:700}article#presentation > svg > foreignObject > section .katex .textit{font-style:italic}article#presentation > svg > foreignObject > section .katex .textrm{font-family:KaTeX_Main}article#presentation > svg > foreignObject > section .katex .textsf{font-family:KaTeX_SansSerif}article#presentation > svg > foreignObject > section .katex .texttt{font-family:KaTeX_Typewriter}article#presentation > svg > foreignObject > section .katex .mathdefault{font-family:KaTeX_Math;font-style:italic}article#presentation > svg > foreignObject > section .katex .mathit{font-family:KaTeX_Main;font-style:italic}article#presentation > svg > foreignObject > section .katex .mathrm{font-style:normal}article#presentation > svg > foreignObject > section .katex .mathbf{font-family:KaTeX_Main;font-weight:700}article#presentation > svg > foreignObject > section .katex .boldsymbol{font-family:KaTeX_Math;font-weight:700;font-style:italic}article#presentation > svg > foreignObject > section .katex .amsrm,article#presentation > svg > foreignObject > section .katex .mathbb,article#presentation > svg > foreignObject > section .katex .textbb{font-family:KaTeX_AMS}article#presentation > svg > foreignObject > section .katex .mathcal{font-family:KaTeX_Caligraphic}article#presentation > svg > foreignObject > section .katex .mathfrak,article#presentation > svg > foreignObject > section .katex .textfrak{font-family:KaTeX_Fraktur}article#presentation > svg > foreignObject > section .katex .mathtt{font-family:KaTeX_Typewriter}article#presentation > svg > foreignObject > section .katex .mathscr,article#presentation > svg > foreignObject > section .katex .textscr{font-family:KaTeX_Script}article#presentation > svg > foreignObject > section .katex .mathsf,article#presentation > svg > foreignObject > section .katex .textsf{font-family:KaTeX_SansSerif}article#presentation > svg > foreignObject > section .katex .mathboldsf,article#presentation > svg > foreignObject > section .katex .textboldsf{font-family:KaTeX_SansSerif;font-weight:700}article#presentation > svg > foreignObject > section .katex .mathitsf,article#presentation > svg > foreignObject > section .katex .textitsf{font-family:KaTeX_SansSerif;font-style:italic}article#presentation > svg > foreignObject > section .katex .mainrm{font-family:KaTeX_Main;font-style:normal}article#presentation > svg > foreignObject > section .katex .vlist-t{display:inline-table;table-layout:fixed}article#presentation > svg > foreignObject > section .katex .vlist-r{display:table-row}article#presentation > svg > foreignObject > section .katex .vlist{display:table-cell;vertical-align:bottom;position:relative}article#presentation > svg > foreignObject > section .katex .vlist>span{display:block;height:0;position:relative}article#presentation > svg > foreignObject > section .katex .vlist>span>span{display:inline-block}article#presentation > svg > foreignObject > section .katex .vlist>span>.pstrut{overflow:hidden;width:0}article#presentation > svg > foreignObject > section .katex .vlist-t2{margin-right:-2px}article#presentation > svg > foreignObject > section .katex .vlist-s{display:table-cell;vertical-align:bottom;font-size:1px;width:2px;min-width:2px}article#presentation > svg > foreignObject > section .katex .msupsub{text-align:left}article#presentation > svg > foreignObject > section .katex .mfrac>span>span{text-align:center}article#presentation > svg > foreignObject > section .katex .mfrac .frac-line{display:inline-block;width:100%;border-bottom-style:solid}article#presentation > svg > foreignObject > section .katex .hdashline,article#presentation > svg > foreignObject > section .katex .hline,article#presentation > svg > foreignObject > section .katex .mfrac .frac-line,article#presentation > svg > foreignObject > section .katex .overline .overline-line,article#presentation > svg > foreignObject > section .katex .rule,article#presentation > svg > foreignObject > section .katex .underline .underline-line{min-height:1px}article#presentation > svg > foreignObject > section .katex .mspace{display:inline-block}article#presentation > svg > foreignObject > section .katex .clap,article#presentation > svg > foreignObject > section .katex .llap,article#presentation > svg > foreignObject > section .katex .rlap{width:0;position:relative}article#presentation > svg > foreignObject > section .katex .clap>.inner,article#presentation > svg > foreignObject > section .katex .llap>.inner,article#presentation > svg > foreignObject > section .katex .rlap>.inner{position:absolute}article#presentation > svg > foreignObject > section .katex .clap>.fix,article#presentation > svg > foreignObject > section .katex .llap>.fix,article#presentation > svg > foreignObject > section .katex .rlap>.fix{display:inline-block}article#presentation > svg > foreignObject > section .katex .llap>.inner{right:0}article#presentation > svg > foreignObject > section .katex .clap>.inner,article#presentation > svg > foreignObject > section .katex .rlap>.inner{left:0}article#presentation > svg > foreignObject > section .katex .clap>.inner>span{margin-left:-50%;margin-right:50%}article#presentation > svg > foreignObject > section .katex .rule{display:inline-block;border:0 solid;position:relative}article#presentation > svg > foreignObject > section .katex .hline,article#presentation > svg > foreignObject > section .katex .overline .overline-line,article#presentation > svg > foreignObject > section .katex .underline .underline-line{display:inline-block;width:100%;border-bottom-style:solid}article#presentation > svg > foreignObject > section .katex .hdashline{display:inline-block;width:100%;border-bottom-style:dashed}article#presentation > svg > foreignObject > section .katex .sqrt>.root{margin-left:.27777778em;margin-right:-.55555556em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer,article#presentation > svg > foreignObject > section .katex .sizing{display:inline-block}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size1.size1,article#presentation > svg > foreignObject > section .katex .sizing.reset-size1.size1{font-size:1em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size1.size2,article#presentation > svg > foreignObject > section .katex .sizing.reset-size1.size2{font-size:1.2em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size1.size3,article#presentation > svg > foreignObject > section .katex .sizing.reset-size1.size3{font-size:1.4em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size1.size4,article#presentation > svg > foreignObject > section .katex .sizing.reset-size1.size4{font-size:1.6em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size1.size5,article#presentation > svg > foreignObject > section .katex .sizing.reset-size1.size5{font-size:1.8em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size1.size6,article#presentation > svg > foreignObject > section .katex .sizing.reset-size1.size6{font-size:2em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size1.size7,article#presentation > svg > foreignObject > section .katex .sizing.reset-size1.size7{font-size:2.4em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size1.size8,article#presentation > svg > foreignObject > section .katex .sizing.reset-size1.size8{font-size:2.88em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size1.size9,article#presentation > svg > foreignObject > section .katex .sizing.reset-size1.size9{font-size:3.456em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size1.size10,article#presentation > svg > foreignObject > section .katex .sizing.reset-size1.size10{font-size:4.148em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size1.size11,article#presentation > svg > foreignObject > section .katex .sizing.reset-size1.size11{font-size:4.976em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size2.size1,article#presentation > svg > foreignObject > section .katex .sizing.reset-size2.size1{font-size:.83333333em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size2.size2,article#presentation > svg > foreignObject > section .katex .sizing.reset-size2.size2{font-size:1em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size2.size3,article#presentation > svg > foreignObject > section .katex .sizing.reset-size2.size3{font-size:1.16666667em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size2.size4,article#presentation > svg > foreignObject > section .katex .sizing.reset-size2.size4{font-size:1.33333333em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size2.size5,article#presentation > svg > foreignObject > section .katex .sizing.reset-size2.size5{font-size:1.5em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size2.size6,article#presentation > svg > foreignObject > section .katex .sizing.reset-size2.size6{font-size:1.66666667em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size2.size7,article#presentation > svg > foreignObject > section .katex .sizing.reset-size2.size7{font-size:2em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size2.size8,article#presentation > svg > foreignObject > section .katex .sizing.reset-size2.size8{font-size:2.4em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size2.size9,article#presentation > svg > foreignObject > section .katex .sizing.reset-size2.size9{font-size:2.88em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size2.size10,article#presentation > svg > foreignObject > section .katex .sizing.reset-size2.size10{font-size:3.45666667em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size2.size11,article#presentation > svg > foreignObject > section .katex .sizing.reset-size2.size11{font-size:4.14666667em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size3.size1,article#presentation > svg > foreignObject > section .katex .sizing.reset-size3.size1{font-size:.71428571em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size3.size2,article#presentation > svg > foreignObject > section .katex .sizing.reset-size3.size2{font-size:.85714286em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size3.size3,article#presentation > svg > foreignObject > section .katex .sizing.reset-size3.size3{font-size:1em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size3.size4,article#presentation > svg > foreignObject > section .katex .sizing.reset-size3.size4{font-size:1.14285714em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size3.size5,article#presentation > svg > foreignObject > section .katex .sizing.reset-size3.size5{font-size:1.28571429em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size3.size6,article#presentation > svg > foreignObject > section .katex .sizing.reset-size3.size6{font-size:1.42857143em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size3.size7,article#presentation > svg > foreignObject > section .katex .sizing.reset-size3.size7{font-size:1.71428571em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size3.size8,article#presentation > svg > foreignObject > section .katex .sizing.reset-size3.size8{font-size:2.05714286em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size3.size9,article#presentation > svg > foreignObject > section .katex .sizing.reset-size3.size9{font-size:2.46857143em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size3.size10,article#presentation > svg > foreignObject > section .katex .sizing.reset-size3.size10{font-size:2.96285714em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size3.size11,article#presentation > svg > foreignObject > section .katex .sizing.reset-size3.size11{font-size:3.55428571em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size4.size1,article#presentation > svg > foreignObject > section .katex .sizing.reset-size4.size1{font-size:.625em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size4.size2,article#presentation > svg > foreignObject > section .katex .sizing.reset-size4.size2{font-size:.75em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size4.size3,article#presentation > svg > foreignObject > section .katex .sizing.reset-size4.size3{font-size:.875em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size4.size4,article#presentation > svg > foreignObject > section .katex .sizing.reset-size4.size4{font-size:1em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size4.size5,article#presentation > svg > foreignObject > section .katex .sizing.reset-size4.size5{font-size:1.125em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size4.size6,article#presentation > svg > foreignObject > section .katex .sizing.reset-size4.size6{font-size:1.25em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size4.size7,article#presentation > svg > foreignObject > section .katex .sizing.reset-size4.size7{font-size:1.5em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size4.size8,article#presentation > svg > foreignObject > section .katex .sizing.reset-size4.size8{font-size:1.8em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size4.size9,article#presentation > svg > foreignObject > section .katex .sizing.reset-size4.size9{font-size:2.16em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size4.size10,article#presentation > svg > foreignObject > section .katex .sizing.reset-size4.size10{font-size:2.5925em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size4.size11,article#presentation > svg > foreignObject > section .katex .sizing.reset-size4.size11{font-size:3.11em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size5.size1,article#presentation > svg > foreignObject > section .katex .sizing.reset-size5.size1{font-size:.55555556em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size5.size2,article#presentation > svg > foreignObject > section .katex .sizing.reset-size5.size2{font-size:.66666667em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size5.size3,article#presentation > svg > foreignObject > section .katex .sizing.reset-size5.size3{font-size:.77777778em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size5.size4,article#presentation > svg > foreignObject > section .katex .sizing.reset-size5.size4{font-size:.88888889em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size5.size5,article#presentation > svg > foreignObject > section .katex .sizing.reset-size5.size5{font-size:1em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size5.size6,article#presentation > svg > foreignObject > section .katex .sizing.reset-size5.size6{font-size:1.11111111em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size5.size7,article#presentation > svg > foreignObject > section .katex .sizing.reset-size5.size7{font-size:1.33333333em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size5.size8,article#presentation > svg > foreignObject > section .katex .sizing.reset-size5.size8{font-size:1.6em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size5.size9,article#presentation > svg > foreignObject > section .katex .sizing.reset-size5.size9{font-size:1.92em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size5.size10,article#presentation > svg > foreignObject > section .katex .sizing.reset-size5.size10{font-size:2.30444444em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size5.size11,article#presentation > svg > foreignObject > section .katex .sizing.reset-size5.size11{font-size:2.76444444em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size6.size1,article#presentation > svg > foreignObject > section .katex .sizing.reset-size6.size1{font-size:.5em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size6.size2,article#presentation > svg > foreignObject > section .katex .sizing.reset-size6.size2{font-size:.6em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size6.size3,article#presentation > svg > foreignObject > section .katex .sizing.reset-size6.size3{font-size:.7em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size6.size4,article#presentation > svg > foreignObject > section .katex .sizing.reset-size6.size4{font-size:.8em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size6.size5,article#presentation > svg > foreignObject > section .katex .sizing.reset-size6.size5{font-size:.9em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size6.size6,article#presentation > svg > foreignObject > section .katex .sizing.reset-size6.size6{font-size:1em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size6.size7,article#presentation > svg > foreignObject > section .katex .sizing.reset-size6.size7{font-size:1.2em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size6.size8,article#presentation > svg > foreignObject > section .katex .sizing.reset-size6.size8{font-size:1.44em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size6.size9,article#presentation > svg > foreignObject > section .katex .sizing.reset-size6.size9{font-size:1.728em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size6.size10,article#presentation > svg > foreignObject > section .katex .sizing.reset-size6.size10{font-size:2.074em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size6.size11,article#presentation > svg > foreignObject > section .katex .sizing.reset-size6.size11{font-size:2.488em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size7.size1,article#presentation > svg > foreignObject > section .katex .sizing.reset-size7.size1{font-size:.41666667em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size7.size2,article#presentation > svg > foreignObject > section .katex .sizing.reset-size7.size2{font-size:.5em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size7.size3,article#presentation > svg > foreignObject > section .katex .sizing.reset-size7.size3{font-size:.58333333em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size7.size4,article#presentation > svg > foreignObject > section .katex .sizing.reset-size7.size4{font-size:.66666667em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size7.size5,article#presentation > svg > foreignObject > section .katex .sizing.reset-size7.size5{font-size:.75em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size7.size6,article#presentation > svg > foreignObject > section .katex .sizing.reset-size7.size6{font-size:.83333333em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size7.size7,article#presentation > svg > foreignObject > section .katex .sizing.reset-size7.size7{font-size:1em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size7.size8,article#presentation > svg > foreignObject > section .katex .sizing.reset-size7.size8{font-size:1.2em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size7.size9,article#presentation > svg > foreignObject > section .katex .sizing.reset-size7.size9{font-size:1.44em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size7.size10,article#presentation > svg > foreignObject > section .katex .sizing.reset-size7.size10{font-size:1.72833333em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size7.size11,article#presentation > svg > foreignObject > section .katex .sizing.reset-size7.size11{font-size:2.07333333em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size8.size1,article#presentation > svg > foreignObject > section .katex .sizing.reset-size8.size1{font-size:.34722222em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size8.size2,article#presentation > svg > foreignObject > section .katex .sizing.reset-size8.size2{font-size:.41666667em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size8.size3,article#presentation > svg > foreignObject > section .katex .sizing.reset-size8.size3{font-size:.48611111em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size8.size4,article#presentation > svg > foreignObject > section .katex .sizing.reset-size8.size4{font-size:.55555556em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size8.size5,article#presentation > svg > foreignObject > section .katex .sizing.reset-size8.size5{font-size:.625em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size8.size6,article#presentation > svg > foreignObject > section .katex .sizing.reset-size8.size6{font-size:.69444444em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size8.size7,article#presentation > svg > foreignObject > section .katex .sizing.reset-size8.size7{font-size:.83333333em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size8.size8,article#presentation > svg > foreignObject > section .katex .sizing.reset-size8.size8{font-size:1em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size8.size9,article#presentation > svg > foreignObject > section .katex .sizing.reset-size8.size9{font-size:1.2em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size8.size10,article#presentation > svg > foreignObject > section .katex .sizing.reset-size8.size10{font-size:1.44027778em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size8.size11,article#presentation > svg > foreignObject > section .katex .sizing.reset-size8.size11{font-size:1.72777778em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size9.size1,article#presentation > svg > foreignObject > section .katex .sizing.reset-size9.size1{font-size:.28935185em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size9.size2,article#presentation > svg > foreignObject > section .katex .sizing.reset-size9.size2{font-size:.34722222em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size9.size3,article#presentation > svg > foreignObject > section .katex .sizing.reset-size9.size3{font-size:.40509259em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size9.size4,article#presentation > svg > foreignObject > section .katex .sizing.reset-size9.size4{font-size:.46296296em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size9.size5,article#presentation > svg > foreignObject > section .katex .sizing.reset-size9.size5{font-size:.52083333em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size9.size6,article#presentation > svg > foreignObject > section .katex .sizing.reset-size9.size6{font-size:.5787037em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size9.size7,article#presentation > svg > foreignObject > section .katex .sizing.reset-size9.size7{font-size:.69444444em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size9.size8,article#presentation > svg > foreignObject > section .katex .sizing.reset-size9.size8{font-size:.83333333em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size9.size9,article#presentation > svg > foreignObject > section .katex .sizing.reset-size9.size9{font-size:1em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size9.size10,article#presentation > svg > foreignObject > section .katex .sizing.reset-size9.size10{font-size:1.20023148em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size9.size11,article#presentation > svg > foreignObject > section .katex .sizing.reset-size9.size11{font-size:1.43981481em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size10.size1,article#presentation > svg > foreignObject > section .katex .sizing.reset-size10.size1{font-size:.24108004em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size10.size2,article#presentation > svg > foreignObject > section .katex .sizing.reset-size10.size2{font-size:.28929605em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size10.size3,article#presentation > svg > foreignObject > section .katex .sizing.reset-size10.size3{font-size:.33751205em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size10.size4,article#presentation > svg > foreignObject > section .katex .sizing.reset-size10.size4{font-size:.38572806em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size10.size5,article#presentation > svg > foreignObject > section .katex .sizing.reset-size10.size5{font-size:.43394407em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size10.size6,article#presentation > svg > foreignObject > section .katex .sizing.reset-size10.size6{font-size:.48216008em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size10.size7,article#presentation > svg > foreignObject > section .katex .sizing.reset-size10.size7{font-size:.57859209em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size10.size8,article#presentation > svg > foreignObject > section .katex .sizing.reset-size10.size8{font-size:.69431051em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size10.size9,article#presentation > svg > foreignObject > section .katex .sizing.reset-size10.size9{font-size:.83317261em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size10.size10,article#presentation > svg > foreignObject > section .katex .sizing.reset-size10.size10{font-size:1em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size10.size11,article#presentation > svg > foreignObject > section .katex .sizing.reset-size10.size11{font-size:1.19961427em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size11.size1,article#presentation > svg > foreignObject > section .katex .sizing.reset-size11.size1{font-size:.20096463em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size11.size2,article#presentation > svg > foreignObject > section .katex .sizing.reset-size11.size2{font-size:.24115756em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size11.size3,article#presentation > svg > foreignObject > section .katex .sizing.reset-size11.size3{font-size:.28135048em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size11.size4,article#presentation > svg > foreignObject > section .katex .sizing.reset-size11.size4{font-size:.32154341em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size11.size5,article#presentation > svg > foreignObject > section .katex .sizing.reset-size11.size5{font-size:.36173633em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size11.size6,article#presentation > svg > foreignObject > section .katex .sizing.reset-size11.size6{font-size:.40192926em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size11.size7,article#presentation > svg > foreignObject > section .katex .sizing.reset-size11.size7{font-size:.48231511em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size11.size8,article#presentation > svg > foreignObject > section .katex .sizing.reset-size11.size8{font-size:.57877814em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size11.size9,article#presentation > svg > foreignObject > section .katex .sizing.reset-size11.size9{font-size:.69453376em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size11.size10,article#presentation > svg > foreignObject > section .katex .sizing.reset-size11.size10{font-size:.83360129em}article#presentation > svg > foreignObject > section .katex .fontsize-ensurer.reset-size11.size11,article#presentation > svg > foreignObject > section .katex .sizing.reset-size11.size11{font-size:1em}article#presentation > svg > foreignObject > section .katex .delimsizing.size1{font-family:KaTeX_Size1}article#presentation > svg > foreignObject > section .katex .delimsizing.size2{font-family:KaTeX_Size2}article#presentation > svg > foreignObject > section .katex .delimsizing.size3{font-family:KaTeX_Size3}article#presentation > svg > foreignObject > section .katex .delimsizing.size4{font-family:KaTeX_Size4}article#presentation > svg > foreignObject > section .katex .delimsizing.mult .delim-size1>span{font-family:KaTeX_Size1}article#presentation > svg > foreignObject > section .katex .delimsizing.mult .delim-size4>span{font-family:KaTeX_Size4}article#presentation > svg > foreignObject > section .katex .nulldelimiter{display:inline-block;width:.12em}article#presentation > svg > foreignObject > section .katex .delimcenter,article#presentation > svg > foreignObject > section .katex .op-symbol{position:relative}article#presentation > svg > foreignObject > section .katex .op-symbol.small-op{font-family:KaTeX_Size1}article#presentation > svg > foreignObject > section .katex .op-symbol.large-op{font-family:KaTeX_Size2}article#presentation > svg > foreignObject > section .katex .accent>.vlist-t,article#presentation > svg > foreignObject > section .katex .op-limits>.vlist-t{text-align:center}article#presentation > svg > foreignObject > section .katex .accent .accent-body{position:relative}article#presentation > svg > foreignObject > section .katex .accent .accent-body:not(.accent-full){width:0}article#presentation > svg > foreignObject > section .katex .overlay{display:block}article#presentation > svg > foreignObject > section .katex .mtable .vertical-separator{display:inline-block;margin:0 -.025em;border-right:.05em solid;min-width:1px}article#presentation > svg > foreignObject > section .katex .mtable .vs-dashed{border-right:.05em dashed}article#presentation > svg > foreignObject > section .katex .mtable .arraycolsep{display:inline-block}article#presentation > svg > foreignObject > section .katex .mtable .col-align-c>.vlist-t{text-align:center}article#presentation > svg > foreignObject > section .katex .mtable .col-align-l>.vlist-t{text-align:left}article#presentation > svg > foreignObject > section .katex .mtable .col-align-r>.vlist-t{text-align:right}article#presentation > svg > foreignObject > section .katex .svg-align{text-align:left}article#presentation > svg > foreignObject > section .katex svg{display:block;position:absolute;width:100%;height:inherit;fill:currentColor;stroke:currentColor;fill-rule:nonzero;fill-opacity:1;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1}article#presentation > svg > foreignObject > section .katex svg path{stroke:none}article#presentation > svg > foreignObject > section .katex img{border-style:none;min-width:0;min-height:0;max-width:none;max-height:none}article#presentation > svg > foreignObject > section .katex .stretchy{width:100%;display:block;position:relative;overflow:hidden}article#presentation > svg > foreignObject > section .katex .stretchy:after,article#presentation > svg > foreignObject > section .katex .stretchy:before{content:""}article#presentation > svg > foreignObject > section .katex .hide-tail{width:100%;position:relative;overflow:hidden}article#presentation > svg > foreignObject > section .katex .halfarrow-left{position:absolute;left:0;width:50.2%;overflow:hidden}article#presentation > svg > foreignObject > section .katex .halfarrow-right{position:absolute;right:0;width:50.2%;overflow:hidden}article#presentation > svg > foreignObject > section .katex .brace-left{position:absolute;left:0;width:25.1%;overflow:hidden}article#presentation > svg > foreignObject > section .katex .brace-center{position:absolute;left:25%;width:50%;overflow:hidden}article#presentation > svg > foreignObject > section .katex .brace-right{position:absolute;right:0;width:25.1%;overflow:hidden}article#presentation > svg > foreignObject > section .katex .x-arrow-pad{padding:0 .5em}article#presentation > svg > foreignObject > section .katex .mover,article#presentation > svg > foreignObject > section .katex .munder,article#presentation > svg > foreignObject > section .katex .x-arrow{text-align:center}article#presentation > svg > foreignObject > section .katex .boxpad{padding:0 .3em}article#presentation > svg > foreignObject > section .katex .fbox,article#presentation > svg > foreignObject > section .katex .fcolorbox{box-sizing:border-box;border:.04em solid}article#presentation > svg > foreignObject > section .katex .cancel-pad{padding:0 .2em}article#presentation > svg > foreignObject > section .katex .cancel-lap{margin-left:-.2em;margin-right:-.2em}article#presentation > svg > foreignObject > section .katex .sout{border-bottom-style:solid;border-bottom-width:.08em}article#presentation > svg > foreignObject > section .katex-display{display:block;margin:1em 0;text-align:center}article#presentation > svg > foreignObject > section .katex-display>.katex{display:block;text-align:center;white-space:nowrap}article#presentation > svg > foreignObject > section .katex-display>.katex>.katex-html{display:block;position:relative}article#presentation > svg > foreignObject > section .katex-display>.katex>.katex-html>.tag{position:absolute;right:0}article#presentation > svg > foreignObject > section .katex-display.leqno>.katex>.katex-html>.tag{left:0;right:auto}article#presentation > svg > foreignObject > section .katex-display.fleqn>.katex{text-align:left}article#presentation > svg > foreignObject > section .katex-display{margin:0}article#presentation > svg > foreignObject > section svg[data-marp-fitting-math]{--preserve-aspect-ratio:xMidYMid meet}article#presentation > svg > foreignObject > section svg[data-marp-fitting-math] [data-marp-fitting-svg-content]{margin:0 auto}article#presentation > svg > foreignObject > section svg[data-marp-fitting=svg]{display:block;height:auto;width:100%}@supports (-ms-ime-align:auto){article#presentation > svg > foreignObject > section svg[data-marp-fitting=svg]{position:static}}article#presentation > svg > foreignObject > section svg[data-marp-fitting=svg].__reflow__{content:""}@supports (-ms-ime-align:auto){article#presentation > svg > foreignObject > section svg[data-marp-fitting=svg].__reflow__{position:relative}}article#presentation > svg > foreignObject > section [data-marp-fitting-svg-content]{display:table;white-space:nowrap}article#presentation > svg > foreignObject > section [data-marp-fitting-svg-content-wrap]{white-space:pre}article#presentation > svg > foreignObject > section img[data-marp-twemoji]{background:transparent;height:1em;margin:0 .05em 0 .1em;vertical-align:-.1em;width:1em}
/*!
* Marp / Marpit Gaia theme.
*
* @theme gaia
* @author Yuki Hattori
*
* @auto-scaling true
* @size 4:3 960px 720px
*/article#presentation > svg > foreignObject > section .hljs{display:block;overflow-x:auto;padding:.5em;background:#000;color:#f8f8f8}article#presentation > svg > foreignObject > section .hljs-comment,article#presentation > svg > foreignObject > section .hljs-quote{color:#aeaeae;font-style:italic}article#presentation > svg > foreignObject > section .hljs-keyword,article#presentation > svg > foreignObject > section .hljs-selector-tag,article#presentation > svg > foreignObject > section .hljs-type{color:#e28964}article#presentation > svg > foreignObject > section .hljs-string{color:#65b042}article#presentation > svg > foreignObject > section .hljs-subst{color:#daefa3}article#presentation > svg > foreignObject > section .hljs-link,article#presentation > svg > foreignObject > section .hljs-regexp{color:#e9c062}article#presentation > svg > foreignObject > section .hljs-name,article#presentation > svg > foreignObject > section .hljs-section,article#presentation > svg > foreignObject > section .hljs-tag,article#presentation > svg > foreignObject > section .hljs-title{color:#89bdff}article#presentation > svg > foreignObject > section .hljs-class .hljs-title,article#presentation > svg > foreignObject > section .hljs-doctag{text-decoration:underline}article#presentation > svg > foreignObject > section .hljs-bullet,article#presentation > svg > foreignObject > section .hljs-number,article#presentation > svg > foreignObject > section .hljs-symbol{color:#3387cc}article#presentation > svg > foreignObject > section .hljs-params,article#presentation > svg > foreignObject > section .hljs-template-variable,article#presentation > svg > foreignObject > section .hljs-variable{color:#3e87e3}article#presentation > svg > foreignObject > section .hljs-attribute{color:#cda869}article#presentation > svg > foreignObject > section .hljs-meta{color:#8996a8}article#presentation > svg > foreignObject > section .hljs-formula{background-color:#0e2231;color:#f8f8f8;font-style:italic}article#presentation > svg > foreignObject > section .hljs-addition{background-color:#253b22;color:#f8f8f8}article#presentation > svg > foreignObject > section .hljs-deletion{background-color:#420e09;color:#f8f8f8}article#presentation > svg > foreignObject > section .hljs-selector-class{color:#9b703f}article#presentation > svg > foreignObject > section .hljs-selector-id{color:#8b98ab}article#presentation > svg > foreignObject > section .hljs-emphasis{font-style:italic}article#presentation > svg > foreignObject > section .hljs-strong{font-weight:700}article#presentation > svg > foreignObject > section svg[data-marp-fitting=svg]{max-height:580px}article#presentation > svg > foreignObject > section h1,article#presentation > svg > foreignObject > section h2,article#presentation > svg > foreignObject > section h3,article#presentation > svg > foreignObject > section h4,article#presentation > svg > foreignObject > section h5,article#presentation > svg > foreignObject > section h6{margin:.5em 0 0}article#presentation > svg > foreignObject > section h1 strong,article#presentation > svg > foreignObject > section h2 strong,article#presentation > svg > foreignObject > section h3 strong,article#presentation > svg > foreignObject > section h4 strong,article#presentation > svg > foreignObject > section h5 strong,article#presentation > svg > foreignObject > section h6 strong{font-weight:inherit}article#presentation > svg > foreignObject > section h1{font-size:1.8em}article#presentation > svg > foreignObject > section h2{font-size:1.5em}article#presentation > svg > foreignObject > section h3{font-size:1.3em}article#presentation > svg > foreignObject > section h4{font-size:1.1em}article#presentation > svg > foreignObject > section h5{font-size:1em}article#presentation > svg > foreignObject > section h6{font-size:.9em}article#presentation > svg > foreignObject > section blockquote,article#presentation > svg > foreignObject > section p{margin:1em 0 0}article#presentation > svg > foreignObject > section ol>li,article#presentation > svg > foreignObject > section ul>li{margin:.3em 0 0}article#presentation > svg > foreignObject > section ol>li>p,article#presentation > svg > foreignObject > section ul>li>p{margin:.6em 0 0}article#presentation > svg > foreignObject > section code{display:inline-block;font-family:Roboto Mono,monospace;font-size:.8em;letter-spacing:0;margin:-.1em .15em;padding:.1em .2em;vertical-align:baseline}article#presentation > svg > foreignObject > section pre{display:block;margin:1em 0 0;min-height:1em;overflow:visible}article#presentation > svg > foreignObject > section pre code{box-sizing:border-box;margin:0;min-width:100%;padding:.5em;font-size:.7em}article#presentation > svg > foreignObject > section pre code svg[data-marp-fitting=svg]{max-height:calc(580px - 1em)}article#presentation > svg > foreignObject > section blockquote{margin:1em 0 0;padding:0 1em;position:relative}article#presentation > svg > foreignObject > section blockquote:after,article#presentation > svg > foreignObject > section blockquote:before{content:"“";display:block;font-family:Times New Roman,serif;font-weight:700;position:absolute}article#presentation > svg > foreignObject > section blockquote:before{top:0;left:0}article#presentation > svg > foreignObject > section blockquote:after{right:0;bottom:0;transform:rotate(180deg)}article#presentation > svg > foreignObject > section blockquote>:first-child{margin-top:0}article#presentation > svg > foreignObject > section mark{background:transparent}article#presentation > svg > foreignObject > section table{border-spacing:0;border-collapse:collapse;margin:1em 0 0}article#presentation > svg > foreignObject > section table td,article#presentation > svg > foreignObject > section table th{padding:.2em .4em;border-width:1px;border-style:solid}article#presentation > svg > foreignObject > section{background-image:linear-gradient(135deg,hsla(0,0%,53.3%,0),hsla(0,0%,53.3%,.02) 50%,hsla(0,0%,100%,0) 0,hsla(0,0%,100%,.05));font-size:35px;font-family:Lato,Avenir Next,Avenir,Trebuchet MS,Segoe UI,sans-serif;height:720px;line-height:1.35;letter-spacing:1.25px;padding:70px;width:1280px;color:#455a64;background-color:#fff8e1}article#presentation > svg > foreignObject > section>:first-child,article#presentation > svg > foreignObject > section>header:first-child+*{margin-top:0}article#presentation > svg > foreignObject > section a,article#presentation > svg > foreignObject > section mark{color:#0288d1}article#presentation > svg > foreignObject > section code{background:#6a7a7d;color:#fff8e1}article#presentation > svg > foreignObject > section h1 strong,article#presentation > svg > foreignObject > section h2 strong,article#presentation > svg > foreignObject > section h3 strong,article#presentation > svg > foreignObject > section h4 strong,article#presentation > svg > foreignObject > section h5 strong,article#presentation > svg > foreignObject > section h6 strong{color:#0288d1}article#presentation > svg > foreignObject > section pre>code{background:#455a64}article#presentation > svg > foreignObject > section blockquote:after,article#presentation > svg > foreignObject > section blockquote:before,article#presentation > svg > foreignObject > section footer,article#presentation > svg > foreignObject > section header,article#presentation > svg > foreignObject > section section:after{color:#6a7a7d}article#presentation > svg > foreignObject > section table td,article#presentation > svg > foreignObject > section table th{border-color:#455a64}article#presentation > svg > foreignObject > section table thead th{background:#455a64;color:#fff8e1}article#presentation > svg > foreignObject > section table tbody>tr:nth-child(odd) td,article#presentation > svg > foreignObject > section table tbody>tr:nth-child(odd) th{background:rgba(69,90,100,.1)}article#presentation > svg > foreignObject > section.invert{color:#fff8e1;background-color:#455a64}article#presentation > svg > foreignObject > section.invert a,article#presentation > svg > foreignObject > section.invert mark{color:#81d4fa}article#presentation > svg > foreignObject > section.invert code{background:#dad8c8;color:#455a64}article#presentation > svg > foreignObject > section.invert h1 strong,article#presentation > svg > foreignObject > section.invert h2 strong,article#presentation > svg > foreignObject > section.invert h3 strong,article#presentation > svg > foreignObject > section.invert h4 strong,article#presentation > svg > foreignObject > section.invert h5 strong,article#presentation > svg > foreignObject > section.invert h6 strong{color:#81d4fa}article#presentation > svg > foreignObject > section.invert pre>code{background:#fff8e1}article#presentation > svg > foreignObject > section.invert blockquote:after,article#presentation > svg > foreignObject > section.invert blockquote:before,article#presentation > svg > foreignObject > section.invert footer,article#presentation > svg > foreignObject > section.invert header,article#presentation > svg > foreignObject > section.invert section:after{color:#dad8c8}article#presentation > svg > foreignObject > section.invert table td,article#presentation > svg > foreignObject > section.invert table th{border-color:#fff8e1}article#presentation > svg > foreignObject > section.invert table thead th{background:#fff8e1;color:#455a64}article#presentation > svg > foreignObject > section.invert table tbody>tr:nth-child(odd) td,article#presentation > svg > foreignObject > section.invert table tbody>tr:nth-child(odd) th{background:rgba(255,248,225,.1)}article#presentation > svg > foreignObject > section.gaia{color:#fff8e1;background-color:#0288d1}article#presentation > svg > foreignObject > section.gaia a,article#presentation > svg > foreignObject > section.gaia mark{color:#81d4fa}article#presentation > svg > foreignObject > section.gaia code{background:#cce2de;color:#0288d1}article#presentation > svg > foreignObject > section.gaia h1 strong,article#presentation > svg > foreignObject > section.gaia h2 strong,article#presentation > svg > foreignObject > section.gaia h3 strong,article#presentation > svg > foreignObject > section.gaia h4 strong,article#presentation > svg > foreignObject > section.gaia h5 strong,article#presentation > svg > foreignObject > section.gaia h6 strong{color:#81d4fa}article#presentation > svg > foreignObject > section.gaia pre>code{background:#fff8e1}article#presentation > svg > foreignObject > section.gaia blockquote:after,article#presentation > svg > foreignObject > section.gaia blockquote:before,article#presentation > svg > foreignObject > section.gaia footer,article#presentation > svg > foreignObject > section.gaia header,article#presentation > svg > foreignObject > section.gaia section:after{color:#cce2de}article#presentation > svg > foreignObject > section.gaia table td,article#presentation > svg > foreignObject > section.gaia table th{border-color:#fff8e1}article#presentation > svg > foreignObject > section.gaia table thead th{background:#fff8e1;color:#0288d1}article#presentation > svg > foreignObject > section.gaia table tbody>tr:nth-child(odd) td,article#presentation > svg > foreignObject > section.gaia table tbody>tr:nth-child(odd) th{background:rgba(255,248,225,.1)}article#presentation > svg > foreignObject > section.lead{display:flex;flex-direction:column;flex-wrap:nowrap;justify-content:center}article#presentation > svg > foreignObject > section.lead h1,article#presentation > svg > foreignObject > section.lead h2,article#presentation > svg > foreignObject > section.lead h3,article#presentation > svg > foreignObject > section.lead h4,article#presentation > svg > foreignObject > section.lead h5,article#presentation > svg > foreignObject > section.lead h6{text-align:center}article#presentation > svg > foreignObject > section.lead h1 svg[data-marp-fitting=svg],article#presentation > svg > foreignObject > section.lead h2 svg[data-marp-fitting=svg],article#presentation > svg > foreignObject > section.lead h3 svg[data-marp-fitting=svg],article#presentation > svg > foreignObject > section.lead h4 svg[data-marp-fitting=svg],article#presentation > svg > foreignObject > section.lead h5 svg[data-marp-fitting=svg],article#presentation > svg > foreignObject > section.lead h6 svg[data-marp-fitting=svg]{--preserve-aspect-ratio:xMidYMid meet}article#presentation > svg > foreignObject > section.lead p{text-align:center}article#presentation > svg > foreignObject > section.lead blockquote>h1,article#presentation > svg > foreignObject > section.lead blockquote>h2,article#presentation > svg > foreignObject > section.lead blockquote>h3,article#presentation > svg > foreignObject > section.lead blockquote>h4,article#presentation > svg > foreignObject > section.lead blockquote>h5,article#presentation > svg > foreignObject > section.lead blockquote>h6,article#presentation > svg > foreignObject > section.lead blockquote>p{text-align:left}article#presentation > svg > foreignObject > section.lead blockquote svg[data-marp-fitting=svg]:not([data-marp-fitting-math]){--preserve-aspect-ratio:xMinYMin meet}article#presentation > svg > foreignObject > section.lead ol>li>p,article#presentation > svg > foreignObject > section.lead ul>li>p{text-align:left}article#presentation > svg > foreignObject > section.lead table{margin-left:auto;margin-right:auto}article#presentation > svg > foreignObject > section footer,article#presentation > svg > foreignObject > section header,article#presentation > svg > foreignObject > section:after{box-sizing:border-box;font-size:66%;height:70px;line-height:50px;overflow:hidden;padding:10px 25px;position:absolute}article#presentation > svg > foreignObject > section header{top:0}article#presentation > svg > foreignObject > section footer,article#presentation > svg > foreignObject > section header{left:0;right:0}article#presentation > svg > foreignObject > section footer{bottom:0}article#presentation > svg > foreignObject > section:after{right:0;bottom:0;font-size:80%}article#presentation > svg > foreignObject > section[data-marpit-advanced-background="background"] {
padding: 0 !important;
}article#presentation > svg > foreignObject > section[data-marpit-advanced-background="background"]::before,
article#presentation > svg > foreignObject > section[data-marpit-advanced-background="background"]::after,
article#presentation > svg > foreignObject > section[data-marpit-advanced-background="content"]::before,
article#presentation > svg > foreignObject > section[data-marpit-advanced-background="content"]::after {
display: none !important;
}article#presentation > svg > foreignObject > section[data-marpit-advanced-background="background"] > div[data-marpit-advanced-background-container] {
all: initial;
display: flex;
flex-direction: row;
height: 100%;
overflow: hidden;
width: 100%;
}article#presentation > svg > foreignObject > section[data-marpit-advanced-background="background"] > div[data-marpit-advanced-background-container][data-marpit-advanced-background-direction="vertical"] {
flex-direction: column;
}article#presentation > svg > foreignObject > section[data-marpit-advanced-background="background"][data-marpit-advanced-background-split] > div[data-marpit-advanced-background-container] {
width: var(--marpit-advanced-background-split, 50%);
}article#presentation > svg > foreignObject > section[data-marpit-advanced-background="background"][data-marpit-advanced-background-split="right"] > div[data-marpit-advanced-background-container] {
margin-left: calc(100% - var(--marpit-advanced-background-split, 50%));
}article#presentation > svg > foreignObject > section[data-marpit-advanced-background="background"] > div[data-marpit-advanced-background-container] > figure {
all: initial;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
flex: auto;
margin: 0;
}article#presentation > svg > foreignObject > section[data-marpit-advanced-background="content"],
article#presentation > svg > foreignObject > section[data-marpit-advanced-background="pseudo"] {
background: transparent !important;
}article#presentation > svg > foreignObject > section[data-marpit-advanced-background="pseudo"],
article#presentation > svg[data-marpit-svg] > foreignObject[data-marpit-advanced-background="pseudo"] {
pointer-events: none !important;
}article#presentation > svg > foreignObject > section[data-marpit-advanced-background-split] {
width: 100%;
height: 100%;
}</style></head><body><div class="bespoke-marp-osc"><button data-bespoke-marp-osc="prev" tabindex="-1" title="Previous slide">Previous slide</button><span data-bespoke-marp-osc="page"></span><button data-bespoke-marp-osc="next" tabindex="-1" title="Next slide">Next slide</button><button data-bespoke-marp-osc="fullscreen" tabindex="-1" title="Toggle fullscreen (f)">Toggle fullscreen</button></div><article id="presentation"><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="1" data-class="lead invert" data-theme="gaia" class="lead invert" style="--class:lead invert;--theme:gaia;">
<h1>A simple project mixing parallel Python and C++ codes</h1>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="2" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>We will show...</h1>
<ul>
<li>how to configure a platform-independent project mixing Python and C++ with <a href="https://cmake.org">cmake</a> and <a href="https://github.com/pybind/pybind11">pybind11</a></li>
<li>how to call Python from C++ and vice versa</li>
<li>how to write efficient parallel code mixing C++ and Python by circumventing Python's GIL</li>
<li>how to unit-test C++ code</li>
<li>how to produce meaningful stack traces in case of segfaults (like stack trace exceptions in Java or Python)</li>
<li>how to setup a cmake-based mixed C++/Python library with setuptools (e.g. for installation with pip)</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="3" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Requirements</h1>
<ul>
<li>good C++ compiler with C++-17 standard support: e.g. <a href="https://gcc.gnu.org">GCC</a> or <a href="https://clang.llvm.org">Clang</a></li>
<li><a href="https://cmake.org">CMake</a>: platform-independent configuration tool for C++</li>
<li><a href="https://github.com/pybind/pybind11">pybind11</a>: high-level C++ directives to call Python from C++ and vice versa; built upon cython</li>
<li><a href="https://github.com/bombela/backward-cpp">backward</a>: magically adds stack trace capabilities for C++ without additional code (only if project compiled in debug mode)</li>
<li><a href="https://github.com/catchorg/Catch2">Catch2</a>: beautiful unit tests in C++</li>
</ul>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="4" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Project architecture</h1>
<pre><code class="language-bash"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap>simple-cpp-python
|-- CMakeLists.txt <span class="hljs-comment"># project configuration</span>
|-- code.hh <span class="hljs-comment"># C++ functions code</span>
|-- package.cc <span class="hljs-comment"># export C++ functions to python</span>
|-- tests.cc <span class="hljs-comment"># C++ unit tests</span>
|-- script.py <span class="hljs-comment"># python code calling C++ code</span>
|-- setup.py <span class="hljs-comment"># setuptools installation script</span>
|-- __init__.py <span class="hljs-comment"># init script loading the compiled library</span>
|-- build <span class="hljs-comment"># created after project configuration (see next slide)</span>
|-- __simple_cpp_python.cpython-37m-darwin.so <span class="hljs-comment"># C++ python extension</span>
</span></span></foreignObject></svg></code></pre>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="5" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Project configuration: CMakeLists.txt</h1>
<pre><code class="language-cmake"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap><span class="hljs-keyword">CMAKE_MINIMUM_REQUIRED</span>(VERSION <span class="hljs-number">3.10</span>.<span class="hljs-number">2</span>)
<span class="hljs-keyword">PROJECT</span>(simple_cpp_python)
<span class="hljs-keyword">ENABLE_LANGUAGE</span>(CXX)
<span class="hljs-keyword">SET</span>(CMAKE_CXX_STANDARD <span class="hljs-number">17</span>) <span class="hljs-comment"># C++-17 required for high-level code parallelization</span>
<span class="hljs-keyword">SET</span>(CMAKE_CXX_STANDARD_REQUIRED <span class="hljs-keyword">ON</span>)
<span class="hljs-keyword">FIND_PACKAGE</span>(TBB REQUIRED) <span class="hljs-comment"># TBB required by GCC's implementation of C++-17</span>
<span class="hljs-keyword">FIND_PACKAGE</span>(pybind11 REQUIRED)
<span class="hljs-keyword">FIND_PACKAGE</span>(Catch2 REQUIRED)
<span class="hljs-keyword">FIND_PACKAGE</span>(Backward) <span class="hljs-comment"># optional package</span>
PYBIND11_ADD_MODULE(__simple_cpp_python package.cc)
<span class="hljs-keyword">TARGET_LINK_LIBRARIES</span>(__simple_cpp_python PRIVATE <span class="hljs-variable">${TBB_IMPORTED_TARGETS}</span>)
</span></span></foreignObject></svg></code></pre>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="6" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Configuring the project</h1>
<ol>
<li>Go to the directory where you installed <code>simple-cpp-python</code></li>
<li>Create a <code>build</code> directory there</li>
<li>Run the following commands (or use an IDE like visual studio code):<pre><code class="language-bash"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap><span class="hljs-built_in">cd</span> build
cmake .. <span class="hljs-comment"># configure the project for your platform (creates a Makefile)</span>
make <span class="hljs-comment"># compile the python extension library</span>
</span></span></foreignObject></svg></code></pre>
</li>
</ol>
<p>You should now have a file under <code>build</code> called<br />
<code>__simple_cpp_python.cpython-37m-darwin.so</code> that you can import in Python.</p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="7" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Selecting different python interpreters</h1>
<p>In the previous slide, cmake via the pybind11 package (line<br />
<code>FIND_PACKAGE(pybind11 REQUIRED)</code> in <em>CMakeLists.txt</em>) automatically selects the default python interpreter of my shell.</p>
<p>To select a different python interpreter you need to configure with the following command:<br />
<code>cmake -DPYTHON_EXECUTABLE="/path/to/my/python/interpreter" ..</code></p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="8" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Computing Lagrange's trigonometric identities</h1>
<p>See the <a href="https://en.wikipedia.org/wiki/List_of_trigonometric_identities#Lagrange's_trigonometric_identities">Wikipedia</a> page. We gonna compute:</p>
<p><svg data-marp-fitting="svg" data-marp-fitting-math><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap><span class="katex-display"><span class="katex"><span class="katex-mathml"><math><semantics><mtable rowspacing="0.24999999999999992em" columnalign="right left" columnspacing="0em"><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>θ</mi><mo separator="true">,</mo><mi>N</mi><mo stretchy="false">)</mo></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>=</mo><munderover><mo>∑</mo><mrow><mi>n</mi><mo>=</mo><mn>1</mn></mrow><mi>N</mi></munderover><mi>sin</mi><mo></mo><mo stretchy="false">(</mo><mi>n</mi><mi>θ</mi><mo stretchy="false">)</mo><mo>+</mo><mi>cos</mi><mo></mo><mo stretchy="false">(</mo><mi>n</mi><mi>θ</mi><mo stretchy="false">)</mo></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="true"><mrow><mrow></mrow><mo>=</mo><mfrac><mn>1</mn><mn>2</mn></mfrac><mrow><mo fence="true">(</mo><mi>cot</mi><mo></mo><mrow><mo fence="true">(</mo><mfrac><mi>θ</mi><mn>2</mn></mfrac><mo fence="true">)</mo></mrow><mo>−</mo><mn>1</mn><mo>+</mo><mfrac><mrow><mi>sin</mi><mo></mo><mrow><mo fence="true">(</mo><mrow><mo fence="true">(</mo><mi>N</mi><mo>+</mo><mfrac><mn>1</mn><mn>2</mn></mfrac><mo fence="true">)</mo></mrow><mi>θ</mi><mo fence="true">)</mo></mrow><mo>−</mo><mi>cos</mi><mo></mo><mrow><mo fence="true">(</mo><mrow><mo fence="true">(</mo><mi>N</mi><mo>+</mo><mfrac><mn>1</mn><mn>2</mn></mfrac><mo fence="true">)</mo></mrow><mi>θ</mi><mo fence="true">)</mo></mrow></mrow><mrow><mi>sin</mi><mo></mo><mrow><mo fence="true">(</mo><mfrac><mi>θ</mi><mn>2</mn></mfrac><mo fence="true">)</mo></mrow></mrow></mfrac><mo fence="true">)</mo></mrow></mrow></mstyle></mtd></mtr></mtable><annotation encoding="application/x-tex"> \begin{aligned}
f(\theta, N) &= \sum_{n=1}^N \sin(n \theta) + \cos(n \theta) \\
& = \frac{1}{2} \left( \cot \left(\frac{\theta}{2}\right) - 1 + \frac{\sin \left( \left(N+\frac{1}{2}\right) \theta \right) - \cos \left( \left(N+\frac{1}{2}\right) \theta \right)}{\sin \left(\frac{\theta}{2}\right)} \right)
\end{aligned} </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:6.695479000000001em;vertical-align:-3.0977395000000003em;"></span><span class="mord"><span class="mtable"><span class="col-align-r"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:3.5977395000000003em;"><span style="top:-5.5977395em;"><span class="pstrut" style="height:3.828336em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.10764em;">f</span><span class="mopen">(</span><span class="mord mathdefault" style="margin-right:0.02778em;">θ</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathdefault" style="margin-right:0.10903em;">N</span><span class="mclose">)</span></span></span><span style="top:-2.2806265em;"><span class="pstrut" style="height:3.828336em;"></span><span class="mord"></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:3.0977395000000003em;"><span></span></span></span></span></span><span class="col-align-l"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:3.5977395000000003em;"><span style="top:-5.5977395em;"><span class="pstrut" style="height:3.828336em;"></span><span class="mord"><span class="mord"></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mop op-limits"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.8283360000000002em;"><span style="top:-1.882887em;margin-left:0em;"><span class="pstrut" style="height:3.05em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight">n</span><span class="mrel mtight">=</span><span class="mord mtight">1</span></span></span></span><span style="top:-3.050005em;"><span class="pstrut" style="height:3.05em;"></span><span><span class="mop op-symbol large-op">∑</span></span></span><span style="top:-4.3000050000000005em;margin-left:0em;"><span class="pstrut" style="height:3.05em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathdefault mtight" style="margin-right:0.10903em;">N</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:1.267113em;"><span></span></span></span></span></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mop">sin</span><span class="mopen">(</span><span class="mord mathdefault">n</span><span class="mord mathdefault" style="margin-right:0.02778em;">θ</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mop">cos</span><span class="mopen">(</span><span class="mord mathdefault">n</span><span class="mord mathdefault" style="margin-right:0.02778em;">θ</span><span class="mclose">)</span></span></span><span style="top:-2.2806265em;"><span class="pstrut" style="height:3.828336em;"></span><span class="mord"><span class="mord"></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.32144em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">2</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">1</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.686em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="minner"><span class="mopen delimcenter" style="top:0em;"><span class="delimsizing size4">(</span></span><span class="mop">cot</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="minner"><span class="mopen delimcenter" style="top:0em;"><span class="delimsizing size3">(</span></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.37144em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">2</span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord mathdefault" style="margin-right:0.02778em;">θ</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.686em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mclose delimcenter" style="top:0em;"><span class="delimsizing size3">)</span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord">1</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.59001em;"><span style="top:-2.229892em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mop">sin</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="minner"><span class="mopen delimcenter" style="top:0em;"><span class="delimsizing size1">(</span></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8801079999999999em;"><span style="top:-2.6550000000000002em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">2</span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.394em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.02778em;">θ</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.345em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mclose delimcenter" style="top:0em;"><span class="delimsizing size1">)</span></span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.7400100000000003em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mop">sin</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="minner"><span class="mopen delimcenter" style="top:0em;"><span class="delimsizing size1">(</span></span><span class="minner"><span class="mopen delimcenter" style="top:0em;"><span class="delimsizing size1">(</span></span><span class="mord mathdefault" style="margin-right:0.10903em;">N</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.845108em;"><span style="top:-2.6550000000000002em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">2</span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.394em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.345em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mclose delimcenter" style="top:0em;"><span class="delimsizing size1">)</span></span></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathdefault" style="margin-right:0.02778em;">θ</span><span class="mclose delimcenter" style="top:0em;"><span class="delimsizing size1">)</span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mop">cos</span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="minner"><span class="mopen delimcenter" style="top:0em;"><span class="delimsizing size1">(</span></span><span class="minner"><span class="mopen delimcenter" style="top:0em;"><span class="delimsizing size1">(</span></span><span class="mord mathdefault" style="margin-right:0.10903em;">N</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.845108em;"><span style="top:-2.6550000000000002em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">2</span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.394em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.345em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mclose delimcenter" style="top:0em;"><span class="delimsizing size1">)</span></span></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord mathdefault" style="margin-right:0.02778em;">θ</span><span class="mclose delimcenter" style="top:0em;"><span class="delimsizing size1">)</span></span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:1.120118em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mclose delimcenter" style="top:0em;"><span class="delimsizing size4">)</span></span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:3.0977395000000003em;"><span></span></span></span></span></span></span></span></span></span></span></span></span></span></foreignObject></svg></p><p>with <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>θ</mi><mo>=</mo><mfrac><mi>π</mi><mn>8</mn></mfrac><mo>=</mo><msubsup><mo>∑</mo><mrow><mi>k</mi><mo>=</mo><mn>0</mn></mrow><mrow><mo>+</mo><mi mathvariant="normal">∞</mi></mrow></msubsup><mfrac><mn>1</mn><mrow><mo stretchy="false">(</mo><mn>4</mn><mi>k</mi><mo>+</mo><mn>1</mn><mo stretchy="false">)</mo><mo stretchy="false">(</mo><mn>4</mn><mi>k</mi><mo>+</mo><mn>3</mn><mo stretchy="false">)</mo></mrow></mfrac></mrow><annotation encoding="application/x-tex">\theta = \frac{\pi}{8} = \sum_{k=0}^{+\infty} \frac{1}{(4k+1)(4k+3)}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.69444em;vertical-align:0em;"></span><span class="mord mathdefault" style="margin-right:0.02778em;">θ</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.040392em;vertical-align:-0.345em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.695392em;"><span style="top:-2.6550000000000002em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">8</span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.394em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.03588em;">π</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.345em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.431231em;vertical-align:-0.52em;"></span><span class="mop"><span class="mop op-symbol small-op" style="position:relative;top:-0.0000050000000000050004em;">∑</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.911231em;"><span style="top:-2.40029em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.03148em;">k</span><span class="mrel mtight">=</span><span class="mord mtight">0</span></span></span></span><span style="top:-3.2029em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">+</span><span class="mord mtight">∞</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.29971000000000003em;"><span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.16666666666666666em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.845108em;"><span style="top:-2.655em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mopen mtight">(</span><span class="mord mtight">4</span><span class="mord mathdefault mtight" style="margin-right:0.03148em;">k</span><span class="mbin mtight">+</span><span class="mord mtight">1</span><span class="mclose mtight">)</span><span class="mopen mtight">(</span><span class="mord mtight">4</span><span class="mord mathdefault mtight" style="margin-right:0.03148em;">k</span><span class="mbin mtight">+</span><span class="mord mtight">3</span><span class="mclose mtight">)</span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.394em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.52em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="9" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Why such a dummy useless nested loops computation?</h1>
<br />
<span style="font-size:95%">
Only to show:
(1) the benefit of parallezing code mixing Python and C++
(2) how to call python (inner loop) from C++ (outer loop)
<p>Outer loop (i.e. sum from <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>n</mi><mo>=</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">n=1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.43056em;vertical-align:0em;"></span><span class="mord mathdefault">n</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">1</span></span></span></span> to <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>N</mi></mrow><annotation encoding="application/x-tex">N</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.68333em;vertical-align:0em;"></span><span class="mord mathdefault" style="margin-right:0.10903em;">N</span></span></span></span>) used to demonstrate parallelization (compute each element of the sum in parallel)</p>
<p>Overhead of parallel for loops mitigated if computation of each element of the loop takes a lot of CPU cycles --> compute <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>sin</mi><mo></mo><mo stretchy="false">(</mo><mi>n</mi><mi>θ</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">\sin(n\theta)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mop">sin</span><span class="mopen">(</span><span class="mord mathdefault">n</span><span class="mord mathdefault" style="margin-right:0.02778em;">θ</span><span class="mclose">)</span></span></span></span> and <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>cos</mi><mo></mo><mo stretchy="false">(</mo><mi>n</mi><mi>θ</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">\cos(n\theta)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mop">cos</span><span class="mopen">(</span><span class="mord mathdefault">n</span><span class="mord mathdefault" style="margin-right:0.02778em;">θ</span><span class="mclose">)</span></span></span></span> with <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>θ</mi><mo>=</mo><mfrac><mi>π</mi><mn>8</mn></mfrac></mrow><annotation encoding="application/x-tex">\theta=\frac{\pi}{8}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.69444em;vertical-align:0em;"></span><span class="mord mathdefault" style="margin-right:0.02778em;">θ</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2777777777777778em;"></span></span><span class="base"><span class="strut" style="height:1.040392em;vertical-align:-0.345em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.695392em;"><span style="top:-2.6550000000000002em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">8</span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.394em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathdefault mtight" style="margin-right:0.03588em;">π</span></span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.345em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span> as a series (inner loop).<br />
</span></p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="10" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Full python code</h1>
<pre><code class="language-python"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap><span class="hljs-keyword">import</span> math, operator, time, sys
<span class="hljs-keyword">from</span> pathos <span class="hljs-keyword">import</span> multiprocessing
<span class="hljs-keyword">from</span> functools <span class="hljs-keyword">import</span> reduce
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">python_inner_loop</span><span class="hljs-params">(M)</span>:</span> <span class="hljs-comment"># computes pi/8 as a sequential series</span>
<span class="hljs-keyword">return</span> reduce(operator.add, [<span class="hljs-number">1</span> / ((<span class="hljs-number">4</span>*k + <span class="hljs-number">1</span>) * (<span class="hljs-number">4</span>*k + <span class="hljs-number">3</span>)) <span class="hljs-keyword">for</span> k <span class="hljs-keyword">in</span> range(M)], <span class="hljs-number">0</span>)
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">python_outer_loop</span><span class="hljs-params">(xf, N, M)</span>:</span> <span class="hljs-comment"># computes the parallel series of cos(n * theta) + sin(n * theta)</span>
pool = multiprocessing.Pool()
v = pool.map(<span class="hljs-keyword">lambda</span> n: math.cos((n+<span class="hljs-number">1</span>) * xf(M)) + math.sin((n+<span class="hljs-number">1</span>) * xf(M)), [n <span class="hljs-keyword">for</span> n <span class="hljs-keyword">in</span> range(N)])
<span class="hljs-keyword">return</span> reduce(operator.add, v, <span class="hljs-number">0</span>)
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">full_python</span><span class="hljs-params">(N, M)</span>:</span>
<span class="hljs-keyword">return</span> python_outer_loop(python_inner_loop, N, M)
<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">"__main__"</span>:
start = time.time()
r = full_python(<span class="hljs-number">1000</span>, <span class="hljs-number">10000</span>)
end = time.time()
print(<span class="hljs-string">'full python result: '</span> + str(r) + <span class="hljs-string">' in '</span> + str(end-start) + <span class="hljs-string">' seconds'</span>)
x = math.pi / <span class="hljs-number">8</span>
r = <span class="hljs-number">0.5</span> * ((<span class="hljs-number">1.0</span> / math.tan(x / <span class="hljs-number">2</span>)) - <span class="hljs-number">1</span> + (math.sin(x * (N + <span class="hljs-number">0.5</span>)) - math.cos(x * (N + <span class="hljs-number">0.5</span>))) / math.sin(x / <span class="hljs-number">2</span>))
print(<span class="hljs-string">'exact result: '</span> + str(r))
</span></span></foreignObject></svg></code></pre>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="11" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Full python code (cont.)</h1>
<p>Result:</p>
<pre><code class="language-bash"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap>$ python script.py
full python result: 4.046217839811811 <span class="hljs-keyword">in</span> 1.1689767837524414 seconds
exact result: 4.027339492125908
</span></span></foreignObject></svg></code></pre>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="12" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Full C++ version</h1>
<pre><code class="language-cpp"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap><span class="hljs-function"><span class="hljs-keyword">double</span> <span class="hljs-title">cpp_inner_loop</span><span class="hljs-params">(<span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>& M)</span> </span>{
<span class="hljs-built_in">std</span>::<span class="hljs-built_in">vector</span><<span class="hljs-keyword">double</span>> v(M);
<span class="hljs-built_in">std</span>::iota(v.begin(), v.end(), <span class="hljs-number">0</span>); <span class="hljs-comment">// fills the vector v with [0, 1, 2, ..., M-1]</span>
<span class="hljs-built_in">std</span>::transform(<span class="hljs-built_in">std</span>::execution::seq, v.begin(), v.end(), v.begin(), [](<span class="hljs-keyword">const</span> <span class="hljs-keyword">double</span>& k){ <span class="hljs-comment">// sequential loop</span>
<span class="hljs-keyword">return</span> <span class="hljs-number">1.0</span> / ((<span class="hljs-number">4</span>*k + <span class="hljs-number">1</span>) * (<span class="hljs-number">4</span>*k + <span class="hljs-number">3</span>));
});
<span class="hljs-keyword">return</span> <span class="hljs-built_in">std</span>::reduce(<span class="hljs-built_in">std</span>::execution::seq, v.begin(), v.end(), <span class="hljs-number">0.0</span>, <span class="hljs-built_in">std</span>::plus<>());
}
<span class="hljs-function"><span class="hljs-keyword">double</span> <span class="hljs-title">cpp_outer_loop</span><span class="hljs-params">(<span class="hljs-keyword">const</span> <span class="hljs-built_in">std</span>::function<<span class="hljs-keyword">double</span> (<span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>&)>& xf, <span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>& N, <span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>& M)</span> </span>{
<span class="hljs-built_in">std</span>::<span class="hljs-built_in">vector</span><<span class="hljs-keyword">double</span>> v(N);
<span class="hljs-built_in">std</span>::iota(v.begin(), v.end(), <span class="hljs-number">0</span>); <span class="hljs-comment">// fills the vector v with [0, 1, 2, ..., N-1]</span>
<span class="hljs-built_in">std</span>::transform(<span class="hljs-built_in">std</span>::execution::par, v.begin(), v.end(), v.begin(), [&xf, &M](<span class="hljs-keyword">const</span> <span class="hljs-keyword">auto</span>& n){ <span class="hljs-comment">// parallel loop</span>
<span class="hljs-keyword">return</span> <span class="hljs-built_in">std</span>::<span class="hljs-built_in">cos</span>((n+<span class="hljs-number">1</span>) * xf(M)) + <span class="hljs-built_in">std</span>::<span class="hljs-built_in">sin</span>((n+<span class="hljs-number">1</span>) * xf(M));
});
<span class="hljs-keyword">return</span> <span class="hljs-built_in">std</span>::reduce(<span class="hljs-built_in">std</span>::execution::par, v.begin(), v.end(), <span class="hljs-number">0.0</span>, <span class="hljs-built_in">std</span>::plus<>());
}
<span class="hljs-function"><span class="hljs-keyword">double</span> <span class="hljs-title">full_cpp</span><span class="hljs-params">(<span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>& N, <span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>& M)</span> </span>{
<span class="hljs-keyword">return</span> cpp_outer_loop(cpp_inner_loop, N, M);
}
</span></span></foreignObject></svg></code></pre>
<span style="font-size:75%">
Note how std::transform() is called with std::execution::seq or std::execution::par.
</span>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="13" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Exporting the C++ code to python</h1>
<p>In <em><a href="http://package.cc">package.cc</a></em>:</p>
<pre><code class="language-cpp"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">"code.hh"</span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string"><pybind11/pybind11.h></span></span>
<span class="hljs-keyword">namespace</span> py = pybind11;
PYBIND11_MODULE(__simple_cpp_python, m) {
m.doc() = <span class="hljs-string">"pybind11 example plugin"</span>; <span class="hljs-comment">// optional module docstring</span>
m.def(<span class="hljs-string">"full_cpp"</span>, &full_cpp, <span class="hljs-string">"A function which computes the sum of
Lagrangian's trigonometric identities - full c++"</span>);
}
</span></span></foreignObject></svg></code></pre>
<span style="font-size:75%">
It will compile a python extension library called __simple_cpp_python.cpython-37m-darwin.so (on MacOS) containing the full_cpp() python function.
</span>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="14" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Calling the C++ code from python</h1>
<p>In <em><a href="http://script.py">script.py</a></em>:</p>
<pre><code class="language-python"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap><span class="hljs-keyword">import</span> build.__simple_cpp_python <span class="hljs-keyword">as</span> wow
<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">"__main__"</span>:
start = time.time()
r = wow.full_cpp(<span class="hljs-number">1000</span>, <span class="hljs-number">10000</span>)
end = time.time()
print(<span class="hljs-string">'full c++ result: '</span> + str(r) + <span class="hljs-string">' in '</span> + str(end-start) + <span class="hljs-string">' seconds'</span>)
</span></span></foreignObject></svg></code></pre>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="15" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Running the script and comparing full Python vs full C++</h1>
<p>Result:</p>
<pre><code class="language-bash"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap>$ python script.py
full python result: 4.046217839811811 <span class="hljs-keyword">in</span> 1.1679670810699463 seconds
full c++ result: 4.046217839811809 <span class="hljs-keyword">in</span> 0.008682012557983398 seconds
exact result: 4.027339492125908
</span></span></foreignObject></svg></code></pre>
<p>On this example <strong>pure C++ is 134.53x faster than pure Python</strong>; both using a sequential inner loop and a parallel outer loop.</p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="16" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Mixing C++ (outer loop) and Python (inner loop)</h1>
<p>In <em>code.hh</em> (<code>xf</code> will be a Python lambda function when calling <code>cpp_outer_loop_gil</code> from Python):</p>
<pre><code><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap><span class="hljs-function"><span class="hljs-keyword">double</span> <span class="hljs-title">cpp_outer_loop_gil</span><span class="hljs-params">(<span class="hljs-keyword">const</span> <span class="hljs-built_in">std</span>::function<<span class="hljs-keyword">double</span> (<span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>&)>& xf,
<span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>& N, <span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>& M)</span> </span>{
py::gil_scoped_release release; <span class="hljs-comment">// Release Python's GIL to enable OS multithreading</span>
<span class="hljs-built_in">std</span>::<span class="hljs-built_in">vector</span><<span class="hljs-keyword">double</span>> v(N);
<span class="hljs-built_in">std</span>::iota(v.begin(), v.end(), <span class="hljs-number">0</span>);
<span class="hljs-built_in">std</span>::transform(<span class="hljs-built_in">std</span>::execution::par, v.begin(), v.end(), v.begin(), [&xf, &M](<span class="hljs-keyword">const</span> <span class="hljs-keyword">auto</span>& n){
py::gil_scoped_acquire acquire; <span class="hljs-comment">// Acquire the GIL to prevent Python race conditions</span>
<span class="hljs-keyword">return</span> <span class="hljs-built_in">std</span>::<span class="hljs-built_in">cos</span>((n+<span class="hljs-number">1</span>) * xf(M)) + <span class="hljs-built_in">std</span>::<span class="hljs-built_in">sin</span>((n+<span class="hljs-number">1</span>) * xf(M)); <span class="hljs-comment">// xf() calls a Python lambda</span>
});
<span class="hljs-keyword">return</span> <span class="hljs-built_in">std</span>::reduce(<span class="hljs-built_in">std</span>::execution::par, v.begin(), v.end(), <span class="hljs-number">0.0</span>, <span class="hljs-built_in">std</span>::plus<>());
}
</span></span></foreignObject></svg></code></pre>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="17" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Calling the C++ function from Python</h1>
<p>In <em><a href="http://script.py">script.py</a></em>:</p>
<pre><code class="language-python"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap><span class="hljs-keyword">import</span> build.__simple_cpp_python <span class="hljs-keyword">as</span> wow
<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">"__main__"</span>:
start = time.time()
r = wow.cpp_outer_loop_gil(<span class="hljs-keyword">lambda</span> M: python_inner_loop(M), <span class="hljs-number">1000</span>, <span class="hljs-number">10000</span>)
end = time.time()
print(<span class="hljs-string">'mixed result: '</span> + str(r) + <span class="hljs-string">' in '</span> + str(end-start) + <span class="hljs-string">' seconds'</span>)
</span></span></foreignObject></svg></code></pre>
<p>In short: Python calls a C++ function that calls a long-running Python function in a parallel loop.</p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="18" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Running the script</h1>
<p>Result:</p>
<pre><code class="language-bash"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap>$ python script.py
full python result: 4.046217839811811 <span class="hljs-keyword">in</span> 1.239090919494629 seconds
full c++ result: 4.046217839811811 <span class="hljs-keyword">in</span> 0.009485006332397461 seconds
mixed result: 4.046217839811811 <span class="hljs-keyword">in</span> 4.09197211265564 seconds
exact result: 4.027339492125908
</span></span></foreignObject></svg></code></pre>
<p>The mixed C++/Python code is <strong>3.3x slower</strong> than the pure Python code! (and 431x slower than the pure C++ code)<br />
That's because of <strong>Python's GIL</strong> that acts like a mutex that forces to sequentialize the C++ parallel loop...</p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="19" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Analysis</h1>
<ul>
<li>Python's GIL forces the outer C++ parallel loop to call each inner element in sequence</li>
<li>Not happening in pure Python because full python code parallelism is implemented using <em>multiprocessing</em> instead of <em>multithreading</em> (thus circumventing the GIL)</li>
<li>Solution: <strong>call each inner Python function from a different Python process!</strong> (but each Python inner loop running in sequence as previously)</li>
</ul>
<p>Idea: <strong>1 C++ thread <=> 1 Python process</strong></p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="20" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>C++ code calling concurrent python processes in parallel</h1>
<pre><code class="language-cpp"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap><span class="hljs-function"><span class="hljs-keyword">double</span> <span class="hljs-title">cpp_outer_loop_process</span><span class="hljs-params">(<span class="hljs-keyword">const</span> <span class="hljs-built_in">std</span>::function<<span class="hljs-keyword">void</span> (<span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>&, <span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>&)>& xg,
<span class="hljs-keyword">const</span> <span class="hljs-built_in">std</span>::function<<span class="hljs-keyword">double</span> (<span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>&)>& xf,
<span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>& N, <span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>& M)</span> </span>{
py::gil_scoped_release release;
<span class="hljs-built_in">std</span>::<span class="hljs-built_in">vector</span><<span class="hljs-keyword">double</span>> v(N);
<span class="hljs-built_in">std</span>::iota(v.begin(), v.end(), <span class="hljs-number">0</span>);
<span class="hljs-built_in">std</span>::for_each(<span class="hljs-built_in">std</span>::execution::par, v.begin(), v.end(), [&xg, &M](<span class="hljs-keyword">const</span> <span class="hljs-keyword">auto</span>& n){
py::gil_scoped_acquire acquire;
xg(n, M); <span class="hljs-comment">// Call to Python function that launches a detached process computing the inner loop</span>
});
<span class="hljs-built_in">std</span>::transform(<span class="hljs-built_in">std</span>::execution::par, v.begin(), v.end(), v.begin(), [&xf](<span class="hljs-keyword">const</span> <span class="hljs-keyword">auto</span>& n){
py::gil_scoped_acquire acquire;
<span class="hljs-keyword">return</span> <span class="hljs-built_in">std</span>::<span class="hljs-built_in">cos</span>((n+<span class="hljs-number">1</span>) * xf(n)) + <span class="hljs-built_in">std</span>::<span class="hljs-built_in">sin</span>((n+<span class="hljs-number">1</span>) * xf(n)); <span class="hljs-comment">// xf(n) gets the result of xg(n, M)</span>
});
<span class="hljs-keyword">return</span> <span class="hljs-built_in">std</span>::reduce(<span class="hljs-built_in">std</span>::execution::par, v.begin(), v.end(), <span class="hljs-number">0.0</span>, <span class="hljs-built_in">std</span>::plus<>());
}
</span></span></foreignObject></svg></code></pre>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="21" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Calling the C++ function from Python</h1>
<pre><code class="language-python"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">mixed_op</span><span class="hljs-params">(pool, lr, n, M)</span>:</span> <span class="hljs-comment"># this our xg() viewed from C++</span>
lr[n] = pool.apply_async(<span class="hljs-keyword">lambda</span> : python_inner_loop(M)) <span class="hljs-comment"># GIL freed after launch</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">mixed_get</span><span class="hljs-params">(lr, n)</span>:</span> <span class="hljs-comment"># this our xf() viewed from C++</span>
<span class="hljs-keyword">return</span> lr[n].get() <span class="hljs-comment"># blocks the process until the result is ready</span>
<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">"__main__"</span>:
start = time.time()
pool = multiprocessing.Pool()
lr = [<span class="hljs-literal">None</span>]*N <span class="hljs-comment"># lr[] saves the result of each detached process</span>
r = wow.cpp_outer_loop_process(<span class="hljs-keyword">lambda</span> n, M : mixed_op(pool, lr, n, M),
<span class="hljs-keyword">lambda</span> n : mixed_get(lr, n), <span class="hljs-number">1000</span>, <span class="hljs-number">10000</span>)
end = time.time()
print(<span class="hljs-string">'mixed result (process): '</span> + str(r) + <span class="hljs-string">' in '</span> + str(end-start) + <span class="hljs-string">' seconds'</span>)
</span></span></foreignObject></svg></code></pre>
<span style="font-size:70%">
The GIL blocks the (only) main Python thread just to launch processes and to get their results.
</span>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="22" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Running the script</h1>
<pre><code class="language-bash"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap>$ python script.py
full python result: 4.046217839811811 <span class="hljs-keyword">in</span> 1.1558029651641846 seconds
full c++ result: 4.046217839811814 <span class="hljs-keyword">in</span> 0.00848531723022461 seconds
mixed result (GIL): 4.046217839811811 <span class="hljs-keyword">in</span> 4.034562110900879 seconds
mixed result (process): 4.046217839811811 <span class="hljs-keyword">in</span> 0.6684191226959229 seconds
exact result: 4.027339492125908
</span></span></foreignObject></svg></code></pre>
<p>The mixed C++/Python process-based implementation is now <strong>1.73x faster than the full parallel python</strong> one (but still 78.77x slower than the full parallel C++ one...). Improvements expected to increase as inner Python code takes more CPU time.</p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="23" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Performance analysis (with 4 cores)</h1>
<p>Speedup vs full (parallel) Python: the higher the better (log scale)</p>
<table>
<thead>
<tr>
<th><img src="comparison_M.png" alt="width:550px" style="width:550px;" /></th>
<th><img src="comparison_N.png" alt="width:550px" style="width:550px;" /></th>
</tr>
</thead>
<tbody></tbody>
</table>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="24" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Using native python objects</h1>
<pre><code class="language-cpp"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap><span class="hljs-function"><span class="hljs-keyword">double</span> <span class="hljs-title">cpp_outer_loop_process</span><span class="hljs-params">(<span class="hljs-keyword">const</span> <span class="hljs-built_in">std</span>::function<<span class="hljs-keyword">void</span> (<span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>&, <span class="hljs-keyword">const</span> py::dict&)>& xg,
<span class="hljs-keyword">const</span> <span class="hljs-built_in">std</span>::function<<span class="hljs-keyword">double</span> (<span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>&)>& xf,
<span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>& N, <span class="hljs-keyword">const</span> py::dict& d)</span> </span>{
py::gil_scoped_release release;
<span class="hljs-built_in">std</span>::<span class="hljs-built_in">vector</span><<span class="hljs-keyword">double</span>> v(N);
<span class="hljs-built_in">std</span>::iota(v.begin(), v.end(), <span class="hljs-number">0</span>);
<span class="hljs-built_in">std</span>::for_each(<span class="hljs-built_in">std</span>::execution::par, v.begin(), v.end(), [&xg, &M](<span class="hljs-keyword">const</span> <span class="hljs-keyword">auto</span>& n){
py::gil_scoped_acquire acquire;
xg(n, d); <span class="hljs-comment">// Work with a native python dictionary d (no copy)</span>
});
<span class="hljs-built_in">std</span>::transform(<span class="hljs-built_in">std</span>::execution::par, v.begin(), v.end(), v.begin(), [&xf](<span class="hljs-keyword">const</span> <span class="hljs-keyword">auto</span>& n){
py::gil_scoped_acquire acquire;
<span class="hljs-keyword">return</span> <span class="hljs-built_in">std</span>::<span class="hljs-built_in">cos</span>((n+<span class="hljs-number">1</span>) * xf(n)) + <span class="hljs-built_in">std</span>::<span class="hljs-built_in">sin</span>((n+<span class="hljs-number">1</span>) * xf(n)); <span class="hljs-comment">// xf(n) gets the result of xg(n, M)</span>
});
<span class="hljs-keyword">return</span> <span class="hljs-built_in">std</span>::reduce(<span class="hljs-built_in">std</span>::execution::par, v.begin(), v.end(), <span class="hljs-number">0.0</span>, <span class="hljs-built_in">std</span>::plus<>());
}
</span></span></foreignObject></svg></code></pre>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="25" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>C++ templates: one generic outer loop for either Python or C++ inner loop</h1>
<pre><code class="language-cpp"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap><span class="hljs-keyword">template</span> <<span class="hljs-keyword">typename</span> ExecutionModel, <span class="hljs-keyword">typename</span> InnerType> <span class="hljs-comment">// declare generic types</span>
<span class="hljs-function"><span class="hljs-keyword">double</span> <span class="hljs-title">cpp_outer_loop_process</span><span class="hljs-params">(<span class="hljs-keyword">const</span> <span class="hljs-built_in">std</span>::function<<span class="hljs-keyword">void</span> (<span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>&, <span class="hljs-keyword">const</span> InnerType&)>& xg,
<span class="hljs-keyword">const</span> <span class="hljs-built_in">std</span>::function<<span class="hljs-keyword">double</span> (<span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>&)>& xf,
<span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>& N, <span class="hljs-keyword">const</span> InnerType& d, <span class="hljs-keyword">const</span> ExecutionModel& em)</span> </span>{
<span class="hljs-keyword">typename</span> ExecutionModel::Release release; <span class="hljs-comment">// py::gil_scoped_release if xg() is a Python lambda otherwise empty class</span>
<span class="hljs-built_in">std</span>::<span class="hljs-built_in">vector</span><<span class="hljs-keyword">double</span>> v(N);
<span class="hljs-built_in">std</span>::iota(v.begin(), v.end(), <span class="hljs-number">0</span>);
<span class="hljs-built_in">std</span>::for_each(<span class="hljs-built_in">std</span>::execution::par, v.begin(), v.end(), [&xg, &M](<span class="hljs-keyword">const</span> <span class="hljs-keyword">auto</span>& n){
<span class="hljs-keyword">typename</span> ExecutionModel::Acquire acquire; <span class="hljs-comment">// py::gil_scoped_acquire if xg() is a Python lambda otherwise empty class</span>
xg(n, d); <span class="hljs-comment">// d is a generic type (C++ type or e.g. python native type via pybind11)</span>
});
<span class="hljs-built_in">std</span>::transform(<span class="hljs-built_in">std</span>::execution::par, v.begin(), v.end(), v.begin(), [&xf](<span class="hljs-keyword">const</span> <span class="hljs-keyword">auto</span>& n){
<span class="hljs-keyword">typename</span> ExecutionModel::Acquire acquire; <span class="hljs-comment">// py::gil_scoped_acquire if xg() is a Python lambda otherwise empty class</span>
<span class="hljs-keyword">return</span> <span class="hljs-built_in">std</span>::<span class="hljs-built_in">cos</span>((n+<span class="hljs-number">1</span>) * xf(n)) + <span class="hljs-built_in">std</span>::<span class="hljs-built_in">sin</span>((n+<span class="hljs-number">1</span>) * xf(n)); <span class="hljs-comment">// xf(n) gets the result of xg(n, M)</span>
});
<span class="hljs-keyword">return</span> <span class="hljs-built_in">std</span>::reduce(<span class="hljs-built_in">std</span>::execution::par, v.begin(), v.end(), <span class="hljs-number">0.0</span>, <span class="hljs-built_in">std</span>::plus<>());
}
</span></span></foreignObject></svg></code></pre>
<span style="font-size:60%">
ExecutionModel is a generic type that must define Release and Acquire classes (empty in case of pure C++).
</span>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="26" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Using the generic C++ outer loop with C++ inner function (from C++)</h1>
<pre><code class="language-cpp"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap><span class="hljs-class"><span class="hljs-keyword">struct</span> <span class="hljs-title">CPPExecutionModel</span> {</span>
<span class="hljs-class"><span class="hljs-keyword">struct</span> <span class="hljs-title">Acquire</span> {</span>};
<span class="hljs-class"><span class="hljs-keyword">struct</span> <span class="hljs-title">Release</span> {</span>};
};
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">cpp_xg</span><span class="hljs-params">(<span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>& n, <span class="hljs-keyword">const</span> <span class="hljs-built_in">std</span>::<span class="hljs-built_in">map</span><<span class="hljs-built_in">std</span>::<span class="hljs-built_in">string</span>, <span class="hljs-keyword">double</span>>& m)</span> </span>{...};
<span class="hljs-function"><span class="hljs-keyword">double</span> <span class="hljs-title">cpp_xf</span><span class="hljs-params">(<span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>& n)</span> </span>{...};
<span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span> N = ...;
<span class="hljs-built_in">std</span>::<span class="hljs-built_in">map</span><<span class="hljs-built_in">std</span>::<span class="hljs-built_in">string</span>, <span class="hljs-keyword">double</span>> m = ...;
<span class="hljs-keyword">double</span> r = cpp_outer_loop_process(cpp_xg, cpp_xf, N, m, CPPExecutionModel());
</span></span></foreignObject></svg></code></pre>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="27" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Using the generic C++ outer loop with Python inner function (from Python)</h1>
<pre><code class="language-cpp"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap><span class="hljs-class"><span class="hljs-keyword">struct</span> <span class="hljs-title">PYExecutionModel</span> {</span>
<span class="hljs-keyword">typedef</span> py::gil_scoped_acquire Acquire;
<span class="hljs-keyword">typedef</span> py::gil_scoped_release Release;
};
<span class="hljs-function"><span class="hljs-keyword">double</span> <span class="hljs-title">export_cpp_outer_loop_process</span><span class="hljs-params">(<span class="hljs-keyword">const</span> <span class="hljs-built_in">std</span>::function<<span class="hljs-keyword">void</span> (<span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>&, <span class="hljs-keyword">const</span> py::dict&)>& xg,
<span class="hljs-keyword">const</span> <span class="hljs-built_in">std</span>::function<<span class="hljs-keyword">double</span> (<span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>&)>& xf,
<span class="hljs-keyword">const</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span>& N, <span class="hljs-keyword">const</span> py::dict& d)</span> </span>{
<span class="hljs-keyword">return</span> cpp_outer_loop_process(xg, xf, N, d, PYExecutionModel()); <span class="hljs-comment">// instantiate generic C++ outer loop function for Python</span>
}
PYBIND11_MODULE(__simple_cpp_python, m) {
m.def(<span class="hljs-string">"cpp_outer_loop_process"</span>, &export_cpp_outer_loop_process); <span class="hljs-comment">// Export the specialized function to Python</span>
}
</span></span></foreignObject></svg></code></pre>
<pre><code class="language-python"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap>r = export_cpp_outer_loop_process(<span class="hljs-keyword">lambda</span> n, d: ..., <span class="hljs-keyword">lambda</span> n: ..., N, my_dict) <span class="hljs-comment"># use with native python dict</span>
</span></span></foreignObject></svg></code></pre>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="28" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Unit-testing the C++ code</h1>
<p>Append the following lines to your <em>CMakeLists.txt</em>:</p>
<pre><code class="language-cmake"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap><span class="hljs-keyword">INCLUDE</span>(CTest)
<span class="hljs-keyword">INCLUDE</span>(Catch)
<span class="hljs-keyword">ADD_EXECUTABLE</span>(<span class="hljs-keyword">test</span>-cpp-inner-loop tests.cc)
<span class="hljs-keyword">TARGET_INCLUDE_DIRECTORIES</span>(<span class="hljs-keyword">test</span>-cpp-inner-loop PRIVATE <span class="hljs-variable">${PYTHON_INCLUDE_DIRS}</span>)
<span class="hljs-keyword">TARGET_LINK_LIBRARIES</span>(<span class="hljs-keyword">test</span>-cpp-inner-loop PRIVATE
Catch2::Catch2 <span class="hljs-variable">${TBB_IMPORTED_TARGETS}</span> <span class="hljs-variable">${PYTHON_LIBRARIES}</span>)
CATCH_DISCOVER_TESTS(<span class="hljs-keyword">test</span>-cpp-inner-loop)
</span></span></foreignObject></svg></code></pre>
<p>It will add a unit test program called test-cpp-inner-loop.<br />
Catch2 takes care of automatically finding your unit tests in <em><a href="http://tests.cc">tests.cc</a></em></p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="29" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Unit-testing the C++ code (cont.)</h1>
<p>Contents of <em><a href="http://tests.cc">tests.cc</a></em>:</p>
<pre><code class="language-cpp"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap><span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> CATCH_CONFIG_MAIN</span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string"><catch2/catch.hpp></span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string"><cmath></span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">"code.hh"</span></span>
TEST_CASE(<span class="hljs-string">"Test the approximate computation of PI/8.0"</span>, <span class="hljs-string">"[PI computation]"</span>) { <span class="hljs-comment">// declare a new unit test</span>
<span class="hljs-keyword">double</span> r1 = cpp_inner_loop(<span class="hljs-number">10</span>);
<span class="hljs-keyword">double</span> r2 = cpp_inner_loop(<span class="hljs-number">100</span>);
<span class="hljs-keyword">double</span> r3 = cpp_inner_loop(<span class="hljs-number">1000</span>);
<span class="hljs-keyword">double</span> v = <span class="hljs-built_in">std</span>::<span class="hljs-built_in">acos</span>(<span class="hljs-number">-1.0</span>) / <span class="hljs-number">8.0</span>;
REQUIRE( <span class="hljs-built_in">std</span>::<span class="hljs-built_in">fabs</span>(v - r1) < <span class="hljs-number">1e-1</span> );
REQUIRE( <span class="hljs-built_in">std</span>::<span class="hljs-built_in">fabs</span>(v - r2) < <span class="hljs-number">1e-3</span> );
REQUIRE( <span class="hljs-built_in">std</span>::<span class="hljs-built_in">fabs</span>(v - r3) < <span class="hljs-number">1e-5</span> );
}
</span></span></foreignObject></svg></code></pre>
<span style="font-size:65%">
You can write scenario tests, check values or exceptions, write conditonal tests, and much more...
</span>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="30" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Unit test result</h1>
<pre><code class="language-bash"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap>$ build/<span class="hljs-built_in">test</span>-cpp-inner-loop
<span class="hljs-built_in">test</span>-cpp-inner-loop is a Catch v2.9.2 host application.
Run with -? <span class="hljs-keyword">for</span> options
-------------------------------------------------------------------------------
Test the approximate computation of PI/8.0
-------------------------------------------------------------------------------
/Users/teichteil_fl/Projects/simple-cpp-python/tests.cc:6
...............................................................................
/Users/teichteil_fl/Projects/simple-cpp-python/tests.cc:13: FAILED:
REQUIRE( std::fabs(v - r3) < 1e-5 )
with expansion:
0.0000625 < 0.00001
===============================================================================
<span class="hljs-built_in">test</span> cases: 1 | 1 failed
assertions: 3 | 2 passed | 1 failed
</span></span></foreignObject></svg></code></pre>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="31" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Finally: replace segfault message by useful stack trace message</h1>
<p>Link your target against Backward libraries in <em>CMakeLists.txt</em>, e.g.:</p>
<pre><code class="language-cmake"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap><span class="hljs-keyword">TARGET_LINK_LIBRARIES</span>(<span class="hljs-keyword">test</span>-cpp-inner-loop PRIVATE Backward::Backward
Catch2::Catch2 <span class="hljs-variable">${TBB_IMPORTED_TARGETS}</span> <span class="hljs-variable">${PYTHON_LIBRARIES}</span>)
</span></span></foreignObject></svg></code></pre>
<p>Add the following line at the top of your source file, e.g. in <em><a href="http://tests.cc">tests.cc</a></em>:</p>
<pre><code class="language-cpp"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap>include <span class="hljs-string">"backward.hpp"</span>
<span class="hljs-keyword">namespace</span> backward { backward::SignalHandling sh; }
</span></span></foreignObject></svg></code></pre>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="32" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Replace segfault message by useful stack trace message</h1>
<p>Add a silly test that should produce a segfault (<img class="emoji" draggable="false" alt="⚠️" src="https://twemoji.maxcdn.com/2/svg/26a0.svg" data-marp-twemoji=""/> bad old school C++ coding style from the 90s on top of a silly bug!), e.g.:</p>
<pre><code class="language-cpp"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap>TEST_CASE(<span class="hljs-string">"Stupid test to demonstrate Backward"</span>, <span class="hljs-string">"[backward]"</span>) {
<span class="hljs-keyword">int</span>* v = <span class="hljs-literal">nullptr</span>; <span class="hljs-comment">// v is a null pointer</span>
REQUIRE( v[<span class="hljs-number">0</span>] == <span class="hljs-number">0</span> ); <span class="hljs-comment">// crash: Backward provides a stack trace </span>
}
</span></span></foreignObject></svg></code></pre>
<p><em>Note: we put this intentional crash test in a unit test for simplicity but Backward can trace any C++ code of your project</em></p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="33" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Backward stack trace result</h1>
<p>Instead of an ungentle <em>sefgault</em> message we get a more informative trace (well, depend on the context) that helps debug your program:</p>
<pre><code class="language-bash"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap>Stack trace (most recent call last):
<span class="hljs-comment">#2 Object "libsystem_platform.dylib", at 0x7fff5932fb3c, in _sigtramp + 28</span>
<span class="hljs-comment">#1 Object "test-cpp-inner-loop", at 0x10ae52478, in backward::SignalHandling::sig_handler(int, __siginfo*, void*) + 8</span>
<span class="hljs-comment">#0 Object "test-cpp-inner-loop", at 0x10ae5207d, in backward::SignalHandling::handleSignal(int, __siginfo*, void*) + 77</span>
</span></span></foreignObject></svg></code></pre>
<p>Without Backward we would simply get a message like:</p>
<pre><code class="language-bash"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap>[1] 46461 segmentation fault build/<span class="hljs-built_in">test</span>-cpp-inner-loop
</span></span></foreignObject></svg></code></pre>
<p>Note that Backward is nearly non-intrusive in your code.</p>
</section>
</foreignObject></svg><svg data-marpit-svg="" viewBox="0 0 1280 720"><foreignObject width="1280" height="720"><section id="34" data-class="invert" data-theme="gaia" class="invert" style="--class:invert;--theme:gaia;">
<h1>Setting-up an installation script with cmake and setuptools</h1>
<p>Look at <em><a href="http://setup.py">setup.py</a></em> (too large to be copied here) -> provides <em>CMakeExtension</em> and <em>CMakeBuild</em> classes<br />
In <code>__init__.py</code>:</p>
<pre><code class="language-python"><svg data-marp-fitting="svg" data-marp-fitting-code><foreignObject><span data-marp-fitting-svg-content><span data-marp-fitting-svg-content-wrap><span class="hljs-keyword">import</span> sys
<span class="hljs-keyword">import</span> os
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
<span class="hljs-keyword">import</span> __simple_cpp_python <span class="hljs-keyword">as</span> simple_cpp_python
</span></span></foreignObject></svg></code></pre>
<p>That's it! Now you can <code>pip install -e .</code> and load <code>simple_cpp_python</code></p>
</section>
</foreignObject></svg></article><script>!function(){"use strict";const t=()=>"Apple Computer, Inc."===navigator.vendor?[e]:[];function e(t){Array.from(document.getElementsByTagName("svg"),e=>{if(e.hasAttribute("data-marpit-svg")){const{clientHeight:r,clientWidth:a}=e;e.style.transform||(e.style.transform="translateZ(0)");const i=t||e.currentScale||1,n=e.viewBox.baseVal.width/i,s=e.viewBox.baseVal.height/i,o=Math.min(r/s,a/n);Array.from(e.querySelectorAll(":scope > foreignObject"),t=>{const e=t.x.baseVal.value,i=t.y.baseVal.value;Array.from(t.querySelectorAll(":scope > section"),t=>{t.style.transformOrigin||(t.style.transformOrigin="0 0");const l=(a-o*n)/2-e,c=(r-o*s)/2-i;t.style.transform=`translate3d(${l}px,${c}px,0) scale(${o}) translate(${e}px,${i}px)`})})}})}const r="data-marp-fitting",a="data-marp-fitting-code",i="data-marp-fitting-math",n=(t,e,r)=>{if(t.getAttribute(e)!==r)return t.setAttribute(e,r),!0};!function(e=!0){const s=()=>{for(const e of t())e();Array.from(document.querySelectorAll(`svg[${r}="svg"]`),t=>{const e=t.firstChild,r=e.firstChild,{scrollWidth:s,scrollHeight:o}=r;let l,c=1;if(t.hasAttribute(a)&&(l=t.parentElement.parentElement),t.hasAttribute(i)&&(l=t.parentElement),l){const t=getComputedStyle(l),e=Math.ceil(l.clientWidth-parseFloat(t.paddingLeft)-parseFloat(t.paddingRight));e&&(c=e)}const m=Math.max(s,c),p=Math.max(o,1),g=`0 0 ${m} ${p}`;n(e,"width",`${m}`),n(e,"height",`${p}`),n(t,"preserveAspectRatio",getComputedStyle(t).getPropertyValue("--preserve-aspect-ratio")||"xMinYMin meet"),n(t,"viewBox",g)&&t.classList.toggle("__reflow__")}),e&&window.requestAnimationFrame(s)};s()}()}();
</script><script>!function(){"use strict";var e={from:function(e,t){var n=1===(e.parent||e).nodeType?e.parent||e:document.querySelector(e.parent||e),r=[].filter.call("string"==typeof e.slides?n.querySelectorAll(e.slides):e.slides||n.children,function(e){return"SCRIPT"!==e.nodeName}),i=r[0],l={},o=function(e,t){r[e]&&(c("deactivate",u(i,t)),i=r[e],c("activate",u(i,t)))},s=function(e,t){var n=r.indexOf(i)+e;c(e>0?"next":"prev",u(i,t))&&o(n,t)},a=function(e,t){l[e]=(l[e]||[]).filter(function(e){return e!==t})},c=function(e,t){return(l[e]||[]).reduce(function(e,n){return e&&!1!==n(t)},!0)},u=function(e,t){return(t=t||{}).index=r.indexOf(e),t.slide=e,t},d={on:function(e,t){return(l[e]||(l[e]=[])).push(t),a.bind(null,e,t)},off:a,fire:c,slide:function(e,t){if(!arguments.length)return r.indexOf(i);c("slide",u(r[e],t))&&o(e,t)},next:s.bind(null,1),prev:s.bind(null,-1),parent:n,slides:r};return(t||[]).forEach(function(e){e(d)}),o(0),d}},t=function(){return function(e){e.slides.forEach(function(e){e.addEventListener("keydown",function(e){(/INPUT|TEXTAREA|SELECT/.test(e.target.nodeName)||"true"===e.target.contentEditable)&&e.stopPropagation()})})}};function n(e){e.parent.classList.add("bespoke-marp-parent"),e.slides.map(e=>e.classList.add("bespoke-marp-slide")),e.on("activate",t=>{e.slides.map(e=>e.classList.remove("bespoke-marp-active")),t.slide.classList.add("bespoke-marp-active")})}function r(e=2e3){return t=>{let n;function r(){n&&clearTimeout(n),n=setTimeout(()=>{t.parent.classList.add("bespoke-marp-inactive")},e),t.parent.classList.remove("bespoke-marp-inactive")}document.addEventListener("mousedown",r),document.addEventListener("mousemove",r),document.addEventListener("touchend",r),setTimeout(r,0)}}function i(e){let t=0,n=0;const r=e.slides.map(e=>[null,...e.querySelectorAll("[data-marpit-fragment]")]),i=e=>void 0!==r[t][n+e],l=(i,l)=>{t=i,n=l,r.forEach((e,t)=>{e.forEach((e,n)=>{if(null==e)return;const r=t<i||t===i&&n<=l;e.setAttribute("data-bespoke-marp-fragment",r?"active":"inactive"),t===i&&n===l?e.setAttribute("data-bespoke-marp-current-fragment","current"):e.removeAttribute("data-bespoke-marp-current-fragment")})}),e.fire("fragment",{slide:e.slides[i],index:i,fragments:r[i],fragmentIndex:l})};e.on("next",()=>{if(i(1))return l(t,n+1),!1;const e=t+1;r[e]&&l(e,0)}),e.on("prev",()=>{if(i(-1))return l(t,n-1),!1;const e=t-1;r[e]&&l(e,r[e].length-1)}),e.on("slide",({index:e,fragment:t})=>{let n=0;if(void 0!==t){const i=r[e];if(i){const{length:e}=i;n=-1===t?e-1:Math.min(Math.max(t,0),e-1)}}l(e,n)}),l(0,0)}var l,o=function(e,t){return e(t={exports:{}},t.exports),t.exports}(function(e){!function(){var t="undefined"!=typeof window&&void 0!==window.document?window.document:{},n=e.exports,r="undefined"!=typeof Element&&"ALLOW_KEYBOARD_INPUT"in Element,i=function(){for(var e,n=[["requestFullscreen","exitFullscreen","fullscreenElement","fullscreenEnabled","fullscreenchange","fullscreenerror"],["webkitRequestFullscreen","webkitExitFullscreen","webkitFullscreenElement","webkitFullscreenEnabled","webkitfullscreenchange","webkitfullscreenerror"],["webkitRequestFullScreen","webkitCancelFullScreen","webkitCurrentFullScreenElement","webkitCancelFullScreen","webkitfullscreenchange","webkitfullscreenerror"],["mozRequestFullScreen","mozCancelFullScreen","mozFullScreenElement","mozFullScreenEnabled","mozfullscreenchange","mozfullscreenerror"],["msRequestFullscreen","msExitFullscreen","msFullscreenElement","msFullscreenEnabled","MSFullscreenChange","MSFullscreenError"]],r=0,i=n.length,l={};r<i;r++)if((e=n[r])&&e[1]in t){for(r=0;r<e.length;r++)l[n[0][r]]=e[r];return l}return!1}(),l={change:i.fullscreenchange,error:i.fullscreenerror},o={request:function(e){return new Promise(function(n){var l=i.requestFullscreen,o=function(){this.off("change",o),n()}.bind(this);e=e||t.documentElement,/ Version\/5\.1(?:\.\d+)? Safari\//.test(navigator.userAgent)?e[l]():e[l](r?Element.ALLOW_KEYBOARD_INPUT:{}),this.on("change",o)}.bind(this))},exit:function(){return new Promise(function(e){if(this.isFullscreen){var n=function(){this.off("change",n),e()}.bind(this);t[i.exitFullscreen](),this.on("change",n)}else e()}.bind(this))},toggle:function(e){return this.isFullscreen?this.exit():this.request(e)},onchange:function(e){this.on("change",e)},onerror:function(e){this.on("error",e)},on:function(e,n){var r=l[e];r&&t.addEventListener(r,n,!1)},off:function(e,n){var r=l[e];r&&t.removeEventListener(r,n,!1)},raw:i};i?(Object.defineProperties(o,{isFullscreen:{get:function(){return Boolean(t[i.fullscreenElement])}},element:{enumerable:!0,get:function(){return t[i.fullscreenElement]}},enabled:{enumerable:!0,get:function(){return Boolean(t[i.fullscreenEnabled])}}}),n?(e.exports=o,e.exports.default=o):window.screenfull=o):n?e.exports=!1:window.screenfull=!1}()});function s(e){e.fullscreen=()=>o&&o.toggle(document.body),document.addEventListener("keydown",t=>{70!==t.which&&122!==t.which||t.altKey||t.ctrlKey||t.metaKey||!o||!o.enabled||(e.fullscreen(),t.preventDefault())})}function a(e={}){const t=Object.assign({history:!0},e);return e=>{function n(){const t=parseInt(window.location.hash.slice(1),10);Number.isNaN(t)||function(t){const n=Math.max(0,Math.min(t,e.slides.length-1));n!==e.slide()&&e.slide(n)}(t-1)}setTimeout(()=>{n(),e.on("activate",e=>{t.history?window.location.hash=e.index+1:window.location.replace(`#${e.index+1}`)}),window.addEventListener("hashchange",n)},0)}}function c(e={}){const t=Object.assign({interval:200},e);return e=>{document.addEventListener("keydown",t=>{(32===t.which&&t.shiftKey||33===t.which||37===t.which||38===t.which)&&e.prev(),(32===t.which&&!t.shiftKey||34===t.which||39===t.which||40===t.which)&&e.next(),35===t.which&&e.slide(e.slides.length-1,{fragment:-1}),36===t.which&&e.slide(0)});let n,r,i=0;e.parent.addEventListener("wheel",o=>{let s=!1;const a=(e,t)=>{e&&(s=s||function(e,t){return function(e,t){const n=t===l.X?"Width":"Height";return e[`client${n}`]<e[`scroll${n}`]}(e,t)&&function(e,t){const{overflow:n}=e,r=e[`overflow${t}`];return"auto"===n||"scroll"===n||"auto"===r||"scroll"===r}(getComputedStyle(e),t)}(e,t)),e&&e.parentElement&&a(e.parentElement,t)};if(0!==o.deltaX&&a(o.target,l.X),0!==o.deltaY&&a(o.target,l.Y),s)return;o.preventDefault(),r&&clearTimeout(r),r=setTimeout(()=>{n=0},t.interval);const c=Date.now()-i<t.interval,u=Math.sqrt(Math.pow(o.deltaX,2)+Math.pow(o.deltaY,2)),d=u<=n;if(n=u,c||d)return;let f;(o.deltaX>0||o.deltaY>0)&&(f="next"),(o.deltaX<0||o.deltaY<0)&&(f="prev"),f&&(e[f](),i=Date.now())})}}function u(e=".bespoke-marp-osc"){const t=document.querySelector(e);if(!t)return()=>{};const n=(e,n)=>{t.querySelectorAll(`[data-bespoke-marp-osc=${JSON.stringify(e)}]`).forEach(n)};return o&&!o.enabled&&n("fullscreen",e=>e.style.display="none"),e=>{t.addEventListener("click",t=>{if(t.target instanceof HTMLElement)switch(t.target.dataset.bespokeMarpOsc){case"next":e.next();break;case"prev":e.prev();break;case"fullscreen":"function"==typeof e.fullscreen&&o&&o.enabled&&e.fullscreen()}}),e.parent.appendChild(t),e.on("activate",({index:t})=>{n("page",n=>n.textContent=`Page ${t+1} of ${e.slides.length}`)}),e.on("fragment",({index:t,fragments:r,fragmentIndex:i})=>{n("prev",e=>e.disabled=0===t&&0===i),n("next",n=>n.disabled=t===e.slides.length-1&&i===r.length-1)}),o&&o.onchange(()=>n("fullscreen",e=>e.classList.toggle("exit",o&&o.isFullscreen)))}}!function(e){e.X="X",e.Y="Y"}(l||(l={}));const d=".bespoke-progress-bar";function f(e){e.on("activate",t=>{document.querySelectorAll(d).forEach(n=>{n.style.flexBasis=`${100*t.index/(e.slides.length-1)}%`})})}function h(e={}){const t=Object.assign({slope:Math.tan(-35*Math.PI/180),swipeThreshold:30},e);return e=>{let n;const r=e.parent,i=e=>{const t=r.getBoundingClientRect();return{x:e.pageX-(t.left+t.right)/2,y:e.pageY-(t.top+t.bottom)/2}};r.addEventListener("touchstart",e=>{n=1===e.touches.length?i(e.touches[0]):void 0}),r.addEventListener("touchmove",e=>{if(n)if(1===e.touches.length){e.preventDefault();const t=i(e.touches[0]),r=t.x-n.x,l=t.y-n.y;n.delta=Math.sqrt(Math.pow(Math.abs(r),2)+Math.pow(Math.abs(l),2)),n.radian=Math.atan2(r,l)}else n=void 0}),r.addEventListener("touchend",r=>{if(n){if(n.delta&&n.delta>=t.swipeThreshold){let i=n.radian-t.slope;i=(i+Math.PI)%(2*Math.PI)-Math.PI,e[i<0?"next":"prev"](),r.stopPropagation()}n=void 0}})}}e.from(document.getElementById("presentation"),[t(),n,r(),a({history:!1}),c(),s,f,h(),u(),i])}();
</script></body></html>