From 8de333950b6bf3da00073a82af4bd2f87d0b54eb Mon Sep 17 00:00:00 2001 From: Marcus Mohr <marcus.mohr@lmu.de> Date: Mon, 21 Nov 2022 16:39:36 +0100 Subject: [PATCH] Perform small update to notebooks #08 and #09 - in #08: use real_c() in HyTeG snippet - in #09: fix some text pieces --- notebooks/08_Functors+Lambdas.ipynb | 80 ++++++++++++++--------------- notebooks/09_Inheritance.ipynb | 55 ++++++++++---------- 2 files changed, 69 insertions(+), 66 deletions(-) diff --git a/notebooks/08_Functors+Lambdas.ipynb b/notebooks/08_Functors+Lambdas.ipynb index 9fdc6f4..535dae0 100644 --- a/notebooks/08_Functors+Lambdas.ipynb +++ b/notebooks/08_Functors+Lambdas.ipynb @@ -326,7 +326,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 11, "id": "21120bbb-03a7-4048-97f4-0426c40c5bac", "metadata": {}, "outputs": [], @@ -337,7 +337,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 12, "id": "bab0ab95-e5fd-4368-b3c2-77bcb869cfe0", "metadata": {}, "outputs": [], @@ -353,7 +353,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 13, "id": "b4e3f68a-6c70-49e7-a04c-924804c4cb35", "metadata": {}, "outputs": [ @@ -374,7 +374,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 14, "id": "c5b3e4d0-64b4-47c6-848f-f787bf9c0b17", "metadata": {}, "outputs": [ @@ -405,7 +405,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 15, "id": "ff8d558b-da83-46d9-9842-8e0d9d5ba56d", "metadata": {}, "outputs": [], @@ -418,7 +418,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 16, "id": "b5790b96-bf62-4d6e-ad9c-e56839882728", "metadata": {}, "outputs": [ @@ -428,7 +428,7 @@ "6" ] }, - "execution_count": 7, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -456,7 +456,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 17, "id": "646b302f-cdf5-40ed-98f8-01d98a9b277a", "metadata": {}, "outputs": [], @@ -473,7 +473,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 18, "id": "b56b370a-654f-4665-a86d-1b4a1497a813", "metadata": {}, "outputs": [], @@ -483,7 +483,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 19, "id": "b267e62f", "metadata": {}, "outputs": [ @@ -523,7 +523,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 20, "id": "24ad0ef1", "metadata": {}, "outputs": [ @@ -591,7 +591,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 21, "id": "3514f84c", "metadata": {}, "outputs": [], @@ -618,7 +618,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 22, "id": "7bca56ac", "metadata": {}, "outputs": [ @@ -658,7 +658,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 23, "id": "f0fd0543", "metadata": {}, "outputs": [ @@ -668,7 +668,7 @@ "text": [ "5.0 is of type d\n", "type of a is i\n", - "What is lambda? ZN12__cling_N52216__cling_Un1Qu318EPvE3$_6\n" + "What is lambda? ZN12__cling_N52216__cling_Un1Qu314EPvE3$_2\n" ] } ], @@ -692,7 +692,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 24, "id": "a32b1635", "metadata": {}, "outputs": [ @@ -700,7 +700,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Writing lambda.cpp\n" + "Overwriting lambda.cpp\n" ] } ], @@ -718,7 +718,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 25, "id": "85373b9f", "metadata": {}, "outputs": [], @@ -728,7 +728,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 26, "id": "fa038d35", "metadata": {}, "outputs": [ @@ -766,7 +766,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 27, "id": "03a872a9", "metadata": {}, "outputs": [ @@ -774,7 +774,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Writing join.cpp\n" + "Overwriting join.cpp\n" ] } ], @@ -795,7 +795,7 @@ " if( str.size() == 0 ) return joinStr;\n", "\n", " std::for_each( str.begin(), str.end()-1,\n", - " [ &joinStr, sep ] (std::string v) { joinStr += v + sep; } );\n", + " [ &joinStr, &sep ] (const std::string &v) { joinStr += v + sep; } );\n", "\n", " joinStr += str.back(); // back() returns reference to last entry\n", " return joinStr;\n", @@ -827,7 +827,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 28, "id": "933de670", "metadata": {}, "outputs": [], @@ -837,7 +837,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 29, "id": "c485b43f", "metadata": {}, "outputs": [ @@ -869,7 +869,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 30, "id": "dcaec377", "metadata": {}, "outputs": [ @@ -919,10 +919,10 @@ " for( int i = 1; i <= NUM; ++i ) dice.push_back( six( engine ) );\n", "\n", " std::cout << std::count_if( dice.begin(), dice.end(), inRange(6,6) )\n", - " << \" of \" << NUM << \" inRange(6,6)\" << std::endl;\n", + " << \" of \" << NUM << \" inRange(6,6)\" << std::endl;\n", "\n", " std::cout << std::count_if( dice.begin(), dice.end(), inRange(4,6) )\n", - " << \" of \" << NUM << \" inRange(4,6)\" << std::endl;\n", + " << \" of \" << NUM << \" inRange(4,6)\" << std::endl;\n", "\n", " // remove all elements for 1 to 4\n", " dice.erase( std::remove_if( dice.begin(), dice.end(), inRange(1,4) ),\n", @@ -939,7 +939,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 31, "id": "b45b0e4f", "metadata": {}, "outputs": [], @@ -949,7 +949,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 32, "id": "f85b1bc8", "metadata": {}, "outputs": [ @@ -962,8 +962,8 @@ "5 inRange(5,10): true\n", "\n", "7 of 60 inRange(6,6)\n", - "30 of 60 inRange(4,6)\n", - "All numbers 5 and 6: 5 5 6 5 6 5 6 5 6 5 5 6 6 6 5 5 \n", + "35 of 60 inRange(4,6)\n", + "All numbers 5 and 6: 6 6 6 5 6 6 6 5 5 5 5 6 5 5 5 5 \n", "\n" ] } @@ -987,7 +987,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 33, "id": "cf33e115", "metadata": {}, "outputs": [ @@ -995,7 +995,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Writing convert.cpp\n" + "Overwriting convert.cpp\n" ] } ], @@ -1038,7 +1038,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 34, "id": "3fbad575", "metadata": {}, "outputs": [], @@ -1048,7 +1048,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 35, "id": "0584e221", "metadata": {}, "outputs": [ @@ -1081,7 +1081,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 36, "id": "ae57e2ba", "metadata": {}, "outputs": [ @@ -1091,7 +1091,7 @@ "10.000000" ] }, - "execution_count": 33, + "execution_count": 36, "metadata": {}, "output_type": "execute_result" } @@ -1109,11 +1109,11 @@ "***\n", "In <a href=\"https://i10git.cs.fau.de/hyteg/hyteg\">HyTeG</a> we often make use of lambdas. Especially for initialising functions and setting boundary conditions. Like in this snippet: \n", "```c++\n", - "real_t k = 2.0;\n", - "real_t m = 5.0;\n", + "real_t k = real_c(2);\n", + "real_t m = real_c(5);\n", "\n", "std::function< real_t(const Point3D&) > solFunc =\n", - " [k, m](const Point3D& x) { sin( k * pi * x[0] ) * sin( m * pi * x[1]; };\n", + " [k, m](const Point3D& x) { return sin( k * pi * x[0] ) * sin( m * pi * x[1]; };\n", "\n", "P1Function< real_t > uExact( \"u_analytic\", storage, maxLevel, maxLevel );\n", "uExact.interpolate( solFunc, maxLevel );\n", diff --git a/notebooks/09_Inheritance.ipynb b/notebooks/09_Inheritance.ipynb index 1e185f3..3bc2dcf 100644 --- a/notebooks/09_Inheritance.ipynb +++ b/notebooks/09_Inheritance.ipynb @@ -158,7 +158,7 @@ "source": [ "Answer to the question is that `student` has no access to `person::name` because the latter is marked `private`. However, it inherits `name`, that's also why the constructor delegation worked.\n", "\n", - "**Note:** A child inherits **all** methods and attributes from its parent, but necessarily access to these." + "**Note:** A child inherits **all** methods and attributes from its parent, but does not necessarily have access to these." ] }, { @@ -171,7 +171,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 8, "id": "bd768c68", "metadata": {}, "outputs": [], @@ -191,12 +191,14 @@ " pv.all_info();\n", " pr.all_info();\n", " pp->all_info();\n", + " \n", + " std::cout << joe.get_name();\n", "}" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 9, "id": "780348e2", "metadata": {}, "outputs": [ @@ -208,7 +210,8 @@ "[student] My name is Joe Smith, I study Geophysics\n", "[person] My name is Joe Smith\n", "[person] My name is Joe Smith\n", - "[person] My name is Joe Smith\n" + "[person] My name is Joe Smith\n", + "Joe Smith" ] } ], @@ -332,7 +335,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 10, "id": "4d0cddfe", "metadata": {}, "outputs": [], @@ -353,7 +356,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 11, "id": "9e8483cd", "metadata": {}, "outputs": [ @@ -384,7 +387,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 12, "id": "a1919205", "metadata": {}, "outputs": [], @@ -405,7 +408,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 15, "id": "742d12ee", "metadata": {}, "outputs": [ @@ -438,7 +441,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 20, "id": "7976790d", "metadata": {}, "outputs": [], @@ -451,7 +454,7 @@ " << arg << \"'\" << std::endl;\n", " }\n", "\n", - "// private: // note that also the using directive has a visibility!\n", + " // private: // note that also the using directive has a visibility!\n", " using Parent::func; // \"import\"\n", " \n", "};" @@ -459,7 +462,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 21, "id": "869bae76", "metadata": {}, "outputs": [ @@ -490,7 +493,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 22, "id": "d1ea8b46", "metadata": {}, "outputs": [ @@ -498,20 +501,20 @@ "name": "stderr", "output_type": "stream", "text": [ - "\u001b[1minput_line_20:3:13: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1mno matching constructor for initialization of '__cling_N514::researcher'\u001b[0m\n", + "\u001b[1minput_line_28:3:13: \u001b[0m\u001b[0;1;31merror: \u001b[0m\u001b[1mno matching constructor for initialization of '__cling_N522::researcher'\u001b[0m\n", " researcher smart( \"Smartie Clever\");\n", "\u001b[0;1;32m ^ ~~~~~~~~~~~~~~~~\n", - "\u001b[0m\u001b[1minput_line_20:1:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor (the implicit copy constructor) not viable: no known\n", - " conversion from 'const char [15]' to 'const __cling_N514::researcher' for\n", + "\u001b[0m\u001b[1minput_line_28:1:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor (the implicit copy constructor) not viable: no known\n", + " conversion from 'const char [15]' to 'const __cling_N522::researcher' for\n", " 1st argument\u001b[0m\n", "class researcher : public person {};\n", "\u001b[0;1;32m ^\n", - "\u001b[0m\u001b[1minput_line_20:1:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor (the implicit move constructor) not viable: no known\n", - " conversion from 'const char [15]' to '__cling_N514::researcher' for 1st\n", + "\u001b[0m\u001b[1minput_line_28:1:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor (the implicit move constructor) not viable: no known\n", + " conversion from 'const char [15]' to '__cling_N522::researcher' for 1st\n", " argument\u001b[0m\n", "class researcher : public person {};\n", "\u001b[0;1;32m ^\n", - "\u001b[0m\u001b[1minput_line_20:1:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor (the implicit default constructor) not viable: requires 0\n", + "\u001b[0m\u001b[1minput_line_28:1:7: \u001b[0m\u001b[0;1;30mnote: \u001b[0mcandidate constructor (the implicit default constructor) not viable: requires 0\n", " arguments, but 1 was provided\u001b[0m\n" ] }, @@ -539,7 +542,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 23, "id": "481fc3f5", "metadata": {}, "outputs": [ @@ -555,7 +558,7 @@ "class researcher : public person {\n", " using person::person;\n", "};\n", - "researcher smart( \"Smartie Clever\");\n", + "researcher smart( \"Smartie Clever\" );\n", "std::cout << smart.get_name() << std::endl;" ] }, @@ -569,7 +572,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 25, "id": "ed941226", "metadata": {}, "outputs": [ @@ -583,8 +586,8 @@ ], "source": [ "class researcher : public person {\n", - " using person::person; \n", "public:\n", + " using person::person; \n", " researcher( const std::string& n ) {\n", " name = n;\n", " std::cout << \"Hello \" << name << std::endl;\n", @@ -606,7 +609,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 26, "id": "1493af7c", "metadata": {}, "outputs": [], @@ -632,7 +635,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 27, "id": "7802babb", "metadata": {}, "outputs": [ @@ -651,7 +654,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 28, "id": "57215968", "metadata": {}, "outputs": [ @@ -671,7 +674,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 29, "id": "be7a63fe", "metadata": {}, "outputs": [ -- GitLab