Debian Codegraph @

src/Libpfs/utils/numeric.h

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_UTILS_NUMERIC_H
23 #define PFS_UTILS_NUMERIC_H
24
25 //! \brief This file contains a series of extensions for vector operations
26 //! \author Davide Anastasia <[email protected]>
27
28 #include <cstddef>
29 #include <functional>
30 #include <numeric>
31
32 namespace pfs {
33 namespace utils {
34
35 namespace numeric {
36 //! \brief Extension of std::plus to compute A + s*B
37 template <typename T>
38 struct vadds {
39 vadds(const T &s) : s_(s) {}
40 T operator()(const T &t1, const T &t2) const { return (t1 + (s_ * t2)); }
41
42 private:
43 T s_;
44 };
45
46 //! \brief Extension of std::plus to compute A + s
47 template <typename T>
48 struct vsadd {
49 vsadd(const T &s) : s_(s) {}
50 T operator()(const T &t1) const { return (t1 + s_ ); }
51
52 private:
53 T s_;
54 };
55
56 //! \brief Extension of std::multiply to compute A * s
57 template <typename T, typename Ts>
58 struct vsmul {
59 vsmul(const Ts &s) : s_(s) {}
60 T operator()(const T &t1) const { return (t1 * s_ ); }
61
62 private:
63 Ts s_;
64 };
65
66 //! \brief Extension of std::minus to compute A - s*B
67 template <typename T>
68 struct vsubs {
69 vsubs(const T &s) : s_(s) {}
70 T operator()(const T &t1, const T &t2) const { return (t1 - (s_ * t2)); }
71
72 private:
73 T s_;
74 };
75 } // numeric
76
77 //! \brief multiplies element-wise \c A and \c B and stores into \c C
78 //! C[i] = A[i] * B[i]
79 //! \param[in] A first input vector
80 //! \param[in] B second input vector
81 //! \param[out] C output vector
82 //! \param[in] N size of the vectors
83 //! \note caller is in charge of properly allocate all the vectors
84 template <typename _Type>
85 void vmul(const _Type *A, const _Type *B, _Type *C, size_t size);
86
87 //! \brief divides element-wise \c A and \c B and stores into \c C
88 //! C[i] = A[i] / B[i]
89 template <typename _Type>
90 void vdiv(const _Type *A, const _Type *B, _Type *C, size_t size);
91
92 //! \brief sum element-wise \c A and \c B and stores into \c C
93 //! C[i] = A[i] + B[i]
94 template <typename _Type>
95 void vadd(const _Type *A, const _Type *B, _Type *C, size_t size);
96
97 //! \brief sum element-wise \c s to \c A and stores into \c B
98 //! B[i] = A[i] + s
99 template <typename _Type>
100 void vsadd(const _Type *A, const _Type &s, _Type *B, size_t size);
101
102 //! \brief multiplies element-wise \c s and \c B, sum it to \c A and stores into
103 //! \c C
104 //! C[i] = A[i] + (s * B[i])
105 template <typename _Type>
106 void vadds(const _Type *A, const _Type &s, const _Type *B, _Type *C,
107 size_t size);
108
109 //! \brief subtract element-wise \c A and \c B and stores into \c C
110 //! C[i] = A[i] - B[i]
111 template <typename _Type>
112 void vsub(const _Type *A, const _Type *B, _Type *C, size_t size);
113
114 //! \brief multiplies element-wise \c s and \c B, subtract it from \c A and
115 //! stores into \c C
116 //! C[i] = A[i] - (s * B[i])
117 template <typename _Type>
118 void vsubs(const _Type *A, const _Type &s, const _Type *B, _Type *C,
119 size_t size);
120
121 //! // O[i] = c * I[i]
122 template <typename _Type, typename _Type_c>
123 void vsmul(const _Type *I, const _Type_c &c, _Type *O, size_t size);
124
125 } // utils
126 } // pfs
127
128 #include <Libpfs/utils/numeric.hxx>
129 #endif // PFS_UTILS_NUMERIC_H