Debian Codegraph @

src/Libpfs/utils/numeric.hxx

raw
1 /*
2 * This file is a part of Luminance HDR package.
3 * ----------------------------------------------------------------------
4 * Copyright (C) 2011-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 #ifndef PFS_NUMERIC_HXX
23 #define PFS_NUMERIC_HXX
24
25 #include <Libpfs/utils/numeric.h>
26
27 #include <algorithm>
28 #include <functional>
29 #include <numeric>
30
31 namespace pfs {
32 namespace utils {
33
34 namespace detail {
35
36 template <typename _Type, typename _Op>
37 inline void op(const _Type *A, const _Type *B, _Type *C, size_t size,
38 const _Op &currOp) {
39 #pragma omp parallel for
40 for (size_t idx = 0; idx < size; idx++) {
41 C[idx] = currOp(A[idx], B[idx]);
42 }
43 }
44
45 template <typename _Type, typename _Op>
46 inline void op(const _Type *A, _Type *B, size_t size,
47 const _Op &currOp) {
48 #pragma omp parallel for
49 for (size_t idx = 0; idx < size; idx++) {
50 B[idx] = currOp(A[idx]);
51 }
52 }
53 } // detail
54
55 template <typename _Type>
56 void vmul(const _Type *A, const _Type *B, _Type *C, size_t size) {
57 detail::op(A, B, C, size, std::multiplies<_Type>());
58 }
59
60 template <typename _Type>
61 void vdiv(const _Type *A, const _Type *B, _Type *C, size_t size) {
62 detail::op(A, B, C, size, std::divides<_Type>());
63 }
64
65 template <typename _Type>
66 void vadd(const _Type *A, const _Type *B, _Type *C, size_t size) {
67 detail::op(A, B, C, size, std::plus<_Type>());
68 }
69
70 template <typename _Type>
71 void vsadd(const _Type *A, const _Type &s, _Type *B, size_t size) {
72 detail::op(A, B, size, numeric::vsadd<_Type>(s));
73 }
74
75 template <typename _Type>
76 void vadds(const _Type *A, const _Type &s, const _Type *B, _Type *C,
77 size_t size) {
78 detail::op(A, B, C, size, numeric::vadds<_Type>(s));
79 }
80
81 template <typename _Type>
82 void vsub(const _Type *A, const _Type *B, _Type *C, size_t size) {
83 detail::op(A, B, C, size, std::minus<_Type>());
84 }
85
86 template <typename _Type>
87 void vsubs(const _Type *A, const _Type &s, const _Type *B, _Type *C,
88 size_t size) {
89 detail::op(A, B, C, size, numeric::vsubs<_Type>(s));
90 }
91
92 template <typename _Type, typename _Type_s>
93 void vsmul(const _Type *I, const _Type_s &c, _Type *O, size_t size) {
94 detail::op(I, O, size, numeric::vsmul<_Type, _Type_s>(c));
95 }
96
97 } // utils
98 } // pfs
99
100 #endif // PFS_NUMERIC_HXX