5.6.2 : Le fichier hadamard_product.cpp

Développons le hadamard_product.cpp :

Toutes les fonctionnalités telles que std::transform proviennent de algorithm :
1
#include <algorithm>


Ensuite on précise le type d'exécution avec execution :
1
#include <execution>


On inclut notre header :
1
#include "hadamard_product.h"


Et on définit notre fonction :
1
2
3
4
5
6
///Perform an Hadamard Product
/**	@param[out] tabRes : vector of result
 * 	@param tabX : vector of values
 * 	@param tabY : vector of values
*/
void hadamard_product(std::vector<float> & tabRes, const std::vector<float> & tabX, const std::vector<float> & tabY){


On parcourt tabX, tabY et tabRes et on appelle la fonction lambda sur chaque paire (x, y) :
1
2
3
	std::transform(std::execution::par_unseq, std::begin(tabX), std::end(tabX), std::begin(tabY), std::begin(tabRes),
			[](float xi, float yi){ return xi * yi; });
}


Le fichier hadamard_product.cpp complet :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/***************************************
	Auteur : Pierre Aubert
	Mail : pierre.aubert@lapp.in2p3.fr
	Licence : CeCILL-C
****************************************/
#include <algorithm>
#include <execution>
#include "hadamard_product.h"
///Perform an Hadamard Product
/**	@param[out] tabRes : vector of result
 * 	@param tabX : vector of values
 * 	@param tabY : vector of values
*/
void hadamard_product(std::vector<float> & tabRes, const std::vector<float> & tabX, const std::vector<float> & tabY){
	std::transform(std::execution::par_unseq, std::begin(tabX), std::end(tabX), std::begin(tabY), std::begin(tabRes),
			[](float xi, float yi){ return xi * yi; });
}


Le fichier hadamard_product.cpp est disponible ici.