4.1.1.1.2 : Le fichier source
Écrivons le fichier sqrt_base.cpp :
Il nous faut tout d'abord inclure un header qui permet d'utiliser la racine carré :
1 |
#include <cmath>
|
Ensuite, nous incluons notre header :
1 |
#include "sqrt_base.h"
|
Et nous ajoutons notre fonction qui calcule un produit de hadamard :
1 2 3 4 5 6 7 8 9 10 11 |
///Do the Hadamard product /** @param[out] tabResult : table of results of tabX*tabY * @param tabX : input table * @param tabY : input table * @param nbElement : number of elements in the tables */ void sqrt_base(float* tabResult, const float* tabX, size_t nbElement){ for(size_t i(0lu); i < nbElement; ++i){ tabResult[i] = std::sqrt(tabX[i]); } } |
Le fichier sqrt_base.cpp complet :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
/*************************************** Auteur : Pierre Aubert Mail : pierre.aubert@lapp.in2p3.fr Licence : CeCILL-C ****************************************/ #include <cmath> #include "sqrt_base.h" ///Do the Hadamard product /** @param[out] tabResult : table of results of tabX*tabY * @param tabX : input table * @param tabY : input table * @param nbElement : number of elements in the tables */ void sqrt_base(float* tabResult, const float* tabX, size_t nbElement){ for(size_t i(0lu); i < nbElement; ++i){ tabResult[i] = std::sqrt(tabX[i]); } } |
Vous pouvez le télécharger ici.