Skip to content

Commit da9d59b

Browse files
authored
Merge pull request #4 from anutosh491/improve_demo_notebook
Update notebook to add more features
2 parents b38003f + bb09b16 commit da9d59b

File tree

1 file changed

+183
-21
lines changed

1 file changed

+183
-21
lines changed

content/3rd-party-libs.ipynb

Lines changed: 183 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
"source": "## Scientific Computation (Symbolic & Numeric)\n\nLet’s begin with powerful C++ libraries for symbolic math, high-precision arithmetic, and efficient numerical computation using BLAS and LAPACK routines.",
2929
"metadata": {}
3030
},
31+
{
32+
"id": "0c0e79fc-65ce-4efa-8bf9-a20125d347a1",
33+
"cell_type": "markdown",
34+
"source": "1. [boost-cpp](https://github.com/boostorg/boost): Collection of peer-reviewed portable C++ libraries for tasks like linear algebra, multithreading, networking, parsing, and more.\n2. [symengine](https://github.com/symengine/symengine): Fast C++ symbolic mathematics library supporting algebraic manipulation, calculus, equation solving, and more, with optional Python bindings.",
35+
"metadata": {}
36+
},
3137
{
3238
"id": "7ef2ba09-bcc8-41e2-b503-3b21e60fdd3e",
3339
"cell_type": "code",
@@ -92,6 +98,18 @@
9298
],
9399
"execution_count": 4
94100
},
101+
{
102+
"id": "6b7e64a2-546c-47a7-b4ed-95e98febd785",
103+
"cell_type": "markdown",
104+
"source": "## Array based Computation through Xtensor-stack\n\nExplore NumPy-style array computing in C++ with Xtensor, Xtensor-BLAS, and Xsimd — enabling high-performance numerical and SIMD-accelerated workflows.",
105+
"metadata": {}
106+
},
107+
{
108+
"id": "d640a780-ead3-4f8f-a2d9-f21c38990456",
109+
"cell_type": "markdown",
110+
"source": "1. [openblas](https://github.com/xianyi/OpenBLAS): Optimized BLAS and LAPACK implementation providing efficient linear algebra routines such as matrix multiplication, factorization, and solvers.\n2. [xtensor](https://github.com/xtensor-stack/xtensor): C++ multidimensional array library with NumPy-like syntax, enabling numerical computing, broadcasting, and integration with C++ scientific libraries.\n3. [xtensor-blas](https://github.com/xtensor-stack/xtensor-blas): BLAS and LAPACK bindings for xtensor, adding high-performance linear algebra operations like dot products, decompositions, and solvers.\n4. [xsimd](https://github.com/xtensor-stack/xsimd): C++ library providing a high-level SIMD API that abstracts platform-specific vectorization instructions, simplifying portable and efficient numerical code.\n",
111+
"metadata": {}
112+
},
95113
{
96114
"id": "f25ec9b7-951e-4494-b932-64d71a601127",
97115
"cell_type": "code",
@@ -109,10 +127,23 @@
109127
"execution_count": 5
110128
},
111129
{
112-
"id": "6b7e64a2-546c-47a7-b4ed-95e98febd785",
113-
"cell_type": "markdown",
114-
"source": "## Array based Computation through Xtensor-stack\n\nExplore NumPy-style array computing in C++ with Xtensor, Xtensor-BLAS, and Xsimd — enabling high-performance numerical and SIMD-accelerated workflows.",
115-
"metadata": {}
130+
"id": "c5275c44-c5a8-4ae4-9221-7149f37a545a",
131+
"cell_type": "code",
132+
"source": "?xt::xtensor",
133+
"metadata": {
134+
"trusted": true
135+
},
136+
"outputs": [
137+
{
138+
"output_type": "display_data",
139+
"data": {
140+
"text/html": "<style>\n #pager-container {\n padding: 0;\n margin: 0;\n width: 100%;\n height: 100%;\n }\n .xcpp-iframe-pager {\n padding: 0;\n margin: 0;\n width: 100%;\n height: 100%;\n border: none;\n }\n </style>\n <iframe class=\"xcpp-iframe-pager\" src=\"https://xtensor.readthedocs.io/en/latest/api/xtensor.html#_CPPv2N2xt7xtensorE?action=purge\"></iframe>",
141+
"text/plain": "https://xtensor.readthedocs.io/en/latest/api/xtensor.html#_CPPv2N2xt7xtensorE"
142+
},
143+
"metadata": {}
144+
}
145+
],
146+
"execution_count": 6
116147
},
117148
{
118149
"id": "6496d5e7-d1e5-4437-be87-bb26b48ce735",
@@ -130,7 +161,7 @@
130161
"metadata": {}
131162
}
132163
],
133-
"execution_count": 6
164+
"execution_count": 7
134165
},
135166
{
136167
"id": "c748227d-4083-4c19-8f07-a449d41e67fe",
@@ -148,7 +179,7 @@
148179
"metadata": {}
149180
}
150181
],
151-
"execution_count": 7
182+
"execution_count": 8
152183
},
153184
{
154185
"id": "74298554-9964-4633-bff3-e67d03a1797d",
@@ -158,7 +189,7 @@
158189
"trusted": true
159190
},
160191
"outputs": [],
161-
"execution_count": 8
192+
"execution_count": 9
162193
},
163194
{
164195
"id": "22dadb84-d39e-4028-a919-febd64f4a60d",
@@ -193,7 +224,7 @@
193224
"metadata": {}
194225
}
195226
],
196-
"execution_count": 9
227+
"execution_count": 10
197228
},
198229
{
199230
"id": "d8e9e9e7-5def-4d77-b459-afb8002282ae",
@@ -209,14 +240,20 @@
209240
"text": "(3.300000, 7.700000, 12.100000, 16.500000)\n"
210241
}
211242
],
212-
"execution_count": 10
243+
"execution_count": 11
213244
},
214245
{
215246
"id": "0f0978c4-7ec4-4615-894a-c6558503d851",
216247
"cell_type": "markdown",
217248
"source": "## Interactive Widgets\n\nBuild rich, interactive UI components in C++ using xwidgets and xcanvas, seamlessly integrated with the Jupyter frontend.",
218249
"metadata": {}
219250
},
251+
{
252+
"id": "8965d8ed-5704-47a2-806a-c047f542782d",
253+
"cell_type": "markdown",
254+
"source": "1. [xwidgets](https://github.com/jupyter-xeus/xwidgets): C++ implementation of the Jupyter widget protocol, providing core interactive widgets and serving as the foundation for libraries like xleaflet and xcanvas.\n2. [xcanvas](https://github.com/jupyter-xeus/xcanvas): C++ library bringing the HTML5 canvas API to Jupyter via the widget protocol, enabling interactive 2D graphics and visualizations in notebooks.",
255+
"metadata": {}
256+
},
220257
{
221258
"id": "2ce27d4d-43f7-464c-a611-5400c3cdb735",
222259
"cell_type": "code",
@@ -225,7 +262,7 @@
225262
"trusted": true
226263
},
227264
"outputs": [],
228-
"execution_count": 11
265+
"execution_count": 12
229266
},
230267
{
231268
"id": "36b1b0f7-00d9-47bf-8543-985e27088d07",
@@ -235,7 +272,7 @@
235272
"trusted": true
236273
},
237274
"outputs": [],
238-
"execution_count": 12
275+
"execution_count": 13
239276
},
240277
{
241278
"id": "b2647bb5-0c2e-4f12-b0ed-0c0f5c7ed65c",
@@ -249,16 +286,16 @@
249286
"output_type": "display_data",
250287
"data": {
251288
"application/vnd.jupyter.widget-view+json": {
252-
"model_id": "07f19b34aac74f97947e4e9b068ebe5f",
289+
"model_id": "2f0bf4f323ea4ccdb9337a9115e4320d",
253290
"version_major": 2,
254291
"version_minor": 1
255292
},
256-
"text/plain": "A Jupyter widget with unique id: 07f19b34aac74f97947e4e9b068ebe5f"
293+
"text/plain": "A Jupyter widget with unique id: 2f0bf4f323ea4ccdb9337a9115e4320d"
257294
},
258295
"metadata": {}
259296
}
260297
],
261-
"execution_count": 13
298+
"execution_count": 14
262299
},
263300
{
264301
"id": "0f3e4dcb-5d9f-479b-b568-8d7625683946",
@@ -268,7 +305,7 @@
268305
"trusted": true
269306
},
270307
"outputs": [],
271-
"execution_count": 14
308+
"execution_count": 15
272309
},
273310
{
274311
"id": "1eed2b39-b632-440c-9d3d-c8d377bc504c",
@@ -278,7 +315,7 @@
278315
"trusted": true
279316
},
280317
"outputs": [],
281-
"execution_count": 15
318+
"execution_count": 16
282319
},
283320
{
284321
"id": "4d1797e5-3ce1-4737-9561-a87a7e82cce1",
@@ -292,16 +329,141 @@
292329
"output_type": "display_data",
293330
"data": {
294331
"application/vnd.jupyter.widget-view+json": {
295-
"model_id": "e34c45cc453240cebac33426cd7c448d",
332+
"model_id": "39f80e8c2a204499bc095f1defdce65f",
296333
"version_major": 2,
297334
"version_minor": 1
298335
},
299-
"text/plain": "A Jupyter widget with unique id: e34c45cc453240cebac33426cd7c448d"
336+
"text/plain": "A Jupyter widget with unique id: 39f80e8c2a204499bc095f1defdce65f"
300337
},
301338
"metadata": {}
302339
}
303340
],
304-
"execution_count": 16
341+
"execution_count": 17
342+
},
343+
{
344+
"id": "ed69c0cd-c65a-47d7-9ee2-13502953e876",
345+
"cell_type": "code",
346+
"source": "#include <emscripten.h>\n\nint width2 = 400;\nint height2 = 400;\n\nauto canvas2 = xc::canvas().initialize()\n .width(width2)\n .height(height2)\n .finalize();\n\nusing canvas2_type = std::decay_t<decltype(canvas2)>;\n\nxcpp::display(canvas2);\n\nstruct Context2\n{\n canvas2_type *canvas = nullptr;\n int iter = 0;\n int stop = 100000;\n int width = 400;\n int height = 400;\n\n // the on_mouse_move callbacks would set these\n int mouse_pos_x = 200;\n int mouse_pos_y = 200;\n int mouse_is_down = 0;\n};\n\nvoid callback2(void* arg) {\n Context2 &ctx = *reinterpret_cast<Context2*>(arg);\n\n if (ctx.iter >= ctx.stop)\n {\n emscripten_cancel_main_loop();\n }\n\n // clear the canvas\n ctx.canvas->clear_rect(0, 0, ctx.width, ctx.height);\n\n std::stringstream color_ss;\n color_ss << \"rgba(\" << (ctx.iter % 255) << \", \"\n << (ctx.iter * 2 % 255) << \", \"\n << (ctx.iter * 3 % 255) << \", 0.5)\";\n\n // draw a circle at the mouse position\n ctx.canvas->begin_path();\n ctx.canvas->arc(ctx.mouse_pos_x, ctx.mouse_pos_y,\n 5 + (ctx.iter / 3) % 20, 0, 2 * M_PI);\n ctx.canvas->fill_style = color_ss.str();\n ctx.canvas->fill();\n\n ctx.iter++;\n}\n\n// type of the callback\nusing xy_callback_type2 = std::function<void(int, int)>;\n\nContext2 ctx2{};\nauto ctx2_ptr = &ctx2;\n\nxy_callback_type2 cb2_on_mouse_move([](int x, int y) {\n ctx2_ptr->mouse_pos_x = x;\n ctx2_ptr->mouse_pos_y = y;\n});\n\nxy_callback_type2 cb2_on_mouse_down([](int x, int y) {\n ctx2_ptr->mouse_is_down = 1;\n ctx2_ptr->mouse_pos_x = x;\n ctx2_ptr->mouse_pos_y = y;\n});\n\nxy_callback_type2 cb2_on_mouse_up([](int x, int y) {\n ctx2_ptr->mouse_is_down = 0;\n ctx2_ptr->mouse_pos_x = x;\n ctx2_ptr->mouse_pos_y = y;\n});\n\nxy_callback_type2 cb2_on_mouse_leave([](int x, int y) {\n ctx2_ptr->mouse_is_down = 0;\n ctx2_ptr->mouse_pos_x = x;\n ctx2_ptr->mouse_pos_y = y;\n});\n\ncanvas2.on_mouse_move(cb2_on_mouse_move);\ncanvas2.on_mouse_down(cb2_on_mouse_down);\ncanvas2.on_mouse_up(cb2_on_mouse_up);\ncanvas2.on_mouse_leave(cb2_on_mouse_leave);\n\nctx2.canvas = &canvas2;\nctx2.width = width2;\nctx2.height = height2;\n\nvoid* void_ctx2 = reinterpret_cast<void*>(&ctx2);\nemscripten_set_main_loop_arg(callback2, void_ctx2, 0, false);",
347+
"metadata": {
348+
"trusted": true
349+
},
350+
"outputs": [
351+
{
352+
"output_type": "display_data",
353+
"data": {
354+
"application/vnd.jupyter.widget-view+json": {
355+
"model_id": "a33b74e244e04db2931d1992de9e2817",
356+
"version_major": 2,
357+
"version_minor": 1
358+
},
359+
"text/plain": "A Jupyter widget with unique id: a33b74e244e04db2931d1992de9e2817"
360+
},
361+
"metadata": {}
362+
}
363+
],
364+
"execution_count": 18
365+
},
366+
{
367+
"id": "1587e911-0786-4353-9211-264f78691a62",
368+
"cell_type": "markdown",
369+
"source": "## Magic Commands\n\nMagics are special commands assisting code execution for the user. Specific to the kernel and are not a part of the C++ programming language.\n\nThere are defined with the symbol % for a line magic and %% for a cell magic.",
370+
"metadata": {}
371+
},
372+
{
373+
"id": "2178c1d9-2193-49b6-906b-55492099470f",
374+
"cell_type": "markdown",
375+
"source": "1. `%%file`: Open, read, write to a file. \n2. `%mamba`: Fetch packages from emscripten-forge at runtime.",
376+
"metadata": {}
377+
},
378+
{
379+
"id": "fb1d314e-647c-487e-ac44-d685c2c1bb28",
380+
"cell_type": "code",
381+
"source": "%%file tmp.txt\nDemo of magic command",
382+
"metadata": {
383+
"trusted": true
384+
},
385+
"outputs": [
386+
{
387+
"name": "stdout",
388+
"output_type": "stream",
389+
"text": "Writing tmp.txt\n"
390+
}
391+
],
392+
"execution_count": 19
393+
},
394+
{
395+
"id": "e400940c-c374-4a88-a9f5-6410ff80f170",
396+
"cell_type": "code",
397+
"source": "%%file -a tmp.txt\nappend at the end",
398+
"metadata": {
399+
"trusted": true
400+
},
401+
"outputs": [
402+
{
403+
"name": "stdout",
404+
"output_type": "stream",
405+
"text": "Appending to tmp.txt\n"
406+
}
407+
],
408+
"execution_count": 20
409+
},
410+
{
411+
"id": "057d0380-cbc0-4eb6-b996-3acb8f3ba631",
412+
"cell_type": "code",
413+
"source": "#include <fstream>\n\nstd::ifstream infile(\"tmp.txt\");\nstd::string line;\nwhile (std::getline(infile, line)) {\n std::cout << line << std::endl;\n}\ninfile.close();",
414+
"metadata": {
415+
"trusted": true
416+
},
417+
"outputs": [
418+
{
419+
"name": "stdout",
420+
"output_type": "stream",
421+
"text": "Demo of magic command\nappend at the end\n"
422+
}
423+
],
424+
"execution_count": 21
425+
},
426+
{
427+
"id": "a7d04714-7ced-4f68-98f4-118ce32ac745",
428+
"cell_type": "code",
429+
"source": "%mamba install doctest",
430+
"metadata": {
431+
"trusted": true
432+
},
433+
"outputs": [
434+
{
435+
"name": "stdout",
436+
"output_type": "stream",
437+
"text": "Specs: xeus-cpp, symengine, xtensor-blas, xsimd, xwidgets, xcanvas, doctest\nChannels: https://repo.prefix.dev/emscripten-forge-dev, conda-forge\n\nSolving environment...\nSolving took 7.976399999976159 seconds\n Name Version Build Channel \n────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────\n\u001b[0;32m+ doctest \u001b[0m2.4.12 h2072262_0 https://repo.prefix.dev/emscripten-forge-dev/\n\u001b[0;31m- pip \u001b[0m25.2 pyh145f28c_0 conda-forge \n"
438+
}
439+
],
440+
"execution_count": 22
441+
},
442+
{
443+
"id": "f5430288-b6d9-4648-a603-d555a847e9df",
444+
"cell_type": "code",
445+
"source": "#define DOCTEST_CONFIG_IMPLEMENT\n#include <doctest/doctest.h>\n\nTEST_CASE(\"Simple check\") {\n CHECK(1 == 2);\n}\n\nint main() {\n doctest::Context context;\n context.setOption(\"success\", true); // Show successful tests\n return context.run();\n}",
446+
"metadata": {
447+
"trusted": true
448+
},
449+
"outputs": [],
450+
"execution_count": 23
451+
},
452+
{
453+
"id": "19c66056-adfb-4618-aba1-38c3ea45afc7",
454+
"cell_type": "code",
455+
"source": "main();",
456+
"metadata": {
457+
"trusted": true
458+
},
459+
"outputs": [
460+
{
461+
"name": "stdout",
462+
"output_type": "stream",
463+
"text": "[doctest] doctest version is \"2.4.12\"\n[doctest] run with \"--help\" for options\n===============================================================================\ninput_line_21:4:\nTEST CASE: Simple check\n\ninput_line_21:5: ERROR: CHECK( 1 == 2 ) is NOT correct!\n values: CHECK( 1 == 2 )\n\n===============================================================================\n[doctest] test cases: 1 | 0 passed | 1 failed | 0 skipped\n[doctest] assertions: 1 | 0 passed | 1 failed |\n[doctest] Status: FAILURE!\n"
464+
}
465+
],
466+
"execution_count": 24
305467
},
306468
{
307469
"id": "d26a70d2-9dc6-4ca0-b974-2cfd4249a8a7",
@@ -323,10 +485,10 @@
323485
"text": "{\n \"age\": 30,\n \"is_student\": false,\n \"name\": \"John Doe\",\n \"skills\": [\n \"C++\",\n \"Python\",\n \"JavaScript\"\n ]\n}\n"
324486
}
325487
],
326-
"execution_count": 17
488+
"execution_count": 25
327489
},
328490
{
329-
"id": "ed69c0cd-c65a-47d7-9ee2-13502953e876",
491+
"id": "a9b6c51a-6202-46f6-99ac-c18d24b09549",
330492
"cell_type": "code",
331493
"source": "",
332494
"metadata": {

0 commit comments

Comments
 (0)