Debian Codegraph @

src/Libpfs/utils/dotproduct.hxx

raw
1 /*
2 * This file is a part of Luminance HDR package.
3 * ----------------------------------------------------------------------
4 * Copyright (C) 2012 Davide Anastasia
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * ----------------------------------------------------------------------
20 */
21
22 //! \author Davide Anastasia <[email protected]>
23
24 #ifndef PFS_UTILS_DOTPRODUCT_HXX
25 #define PFS_UTILS_DOTPRODUCT_HXX
26
27 #include <Libpfs/utils/dotproduct.h>
28
29 namespace pfs {
30 namespace utils {
31
32 template <typename _Type>
33 _Type dotProduct(const _Type *v1, const _Type *v2, size_t N) {
34 double dotProd = _Type();
35 #pragma omp parallel for reduction(+ : dotProd)
36 for (int idx = 0; idx < static_cast<int>(N); idx++) {
37 dotProd = dotProd + (v1[idx] * v2[idx]);
38 }
39 return static_cast<_Type>(dotProd);
40 }
41
42 template <typename _Type>
43 _Type dotProduct(const _Type *v1, size_t N) {
44 double dotProd = _Type();
45 #pragma omp parallel for reduction(+ : dotProd)
46 for (int idx = 0; idx < static_cast<int>(N); idx++) {
47 dotProd = dotProd + (v1[idx] * v1[idx]);
48 }
49 return static_cast<_Type>(dotProd);
50 }
51
52 } // utils
53 } // pfs
54
55 #endif // PFS_UTILS_DOTPRODUCT_HXX