From 06d7d0fc860f744941bdf90274301e9d3c3253fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?El=20Kharroubi=20Micha=C3=ABl?= <michael.el-kharroubi@hesge.ch> Date: Mon, 26 Feb 2024 11:36:22 +0100 Subject: [PATCH] [WIP] STL algos --- GPGPU.typ | 2 +- cpp_basics_for_STL.typ | 71 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/GPGPU.typ b/GPGPU.typ index ae37dbe..d192f6e 100644 --- a/GPGPU.typ +++ b/GPGPU.typ @@ -86,7 +86,7 @@ #slide(title: "Déroulement classique d'un programmme GPGPU")[ + Le CPU envoie les données à traiter au GPU #pause + Le GPU applique un kernel sur les données #pause - + Le CPU récupère le résultat #pause + + Le CPU récupère le résultat ] #new-section-slide("Exemple de code CUDA et notions à retenir") diff --git a/cpp_basics_for_STL.typ b/cpp_basics_for_STL.typ index 301b157..1594aeb 100644 --- a/cpp_basics_for_STL.typ +++ b/cpp_basics_for_STL.typ @@ -304,6 +304,77 @@ int x = add_cst(10); // x vaut 12 #new-section-slide("Algorithmes STL") +#slide( + title: "Introduction", +)[ + La librairie standard propose un ensemble d'algorithmes qui permettent de + travailler avec des itérateurs. + + Ces algorithmes permettent entre autre de : + - initialiser/remplir + - trier + - transformer + - réduire + - supprimer/remplacer des éléments + + On retrouve des fonctions similaires avec les streams en java, ou les itérateurs + en Rust. + + Je vous recommande de lire la page suivante pour plus d'information #link("https://en.cppreference.com/w/cpp/algorithm"). +] + +#slide(title: "Exemple tri")[ +```cpp +std::vector<int> v = {6, 3, 4, 12, 1, 15}; + +std::sort(v.begin(), v.end()); + +std::vector<int> v_sorted = {1, 3, 4, 6, 12, 15}; + +bool is_sorted = std::equal(v.begin(), v.end(), v_sorted.begin()); + +std::cout << is_sorted << std::endl; +``` +] + +#slide(title: "Exemple de transformation")[ +```cpp +std::vector<int> v = {6, 3, 4, 12, 1, 15}; +std::vector<std::string> parity{6}; + +std::transform(v.begin(), + v.end(), + parity.begin(), + [](int i){ + std::string s = (i % 2) == 0 ? "even" : "odd"; + return s; + }); + +for (std::string &p : parity){ + std::cout << p << " "; +} +std::cout << std::endl; +``` +] + +#slide(title: "Exemple de reduction")[ +```cpp +constexpr int kN = 100; +std::vector<int> v{kN, 0}; + +std::iota(v.begin(), v.end(), 1); + +int sum = std::accumulate(v.begin(), + v.end(), + 0, + [](int acc, int i){ + return acc + i; + }); + +std::cout << sum << std::endl; +``` +] + #new-section-slide("Notions à retenir") #new-section-slide("Questions ?") \ No newline at end of file -- GitLab