• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  (C) Copyright John Maddock 2007.
2 //  Use, modification and distribution are subject to the
3 //  Boost Software License, Version 1.0. (See accompanying file
4 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 #include <boost/math/special_functions/trunc.hpp>
7 
8 
9 #ifndef BOOST_MATH_TEST_FUNCTOR_HPP
10 #define BOOST_MATH_TEST_FUNCTOR_HPP
11 
12 template <class Real>
13 struct extract_result_type
14 {
extract_result_typeextract_result_type15    extract_result_type(unsigned i) : m_location(i){}
16 
17    template <class S>
operator ()extract_result_type18    Real operator()(const S& row)
19    {
20       return row[m_location];
21    }
22 private:
23    unsigned m_location;
24 };
25 
26 template <class Real>
extract_result(unsigned i)27 inline extract_result_type<Real> extract_result(unsigned i)
28 {
29    return extract_result_type<Real>(i);
30 }
31 
32 template <class Real, class F>
33 struct row_binder1
34 {
row_binder1row_binder135    row_binder1(F _f, unsigned i) : f(_f), m_i(i) {}
36 
37    template <class S>
operator ()row_binder138    Real operator()(const S& row)
39    {
40       return f(row[m_i]);
41    }
42 
43 private:
44    F f;
45    unsigned m_i;
46 };
47 
48 template<class Real, class F>
bind_func(F f,unsigned i)49 inline row_binder1<Real, F> bind_func(F f, unsigned i)
50 {
51    return row_binder1<Real, F>(f, i);
52 }
53 
54 template <class Real, class F>
55 struct row_binder2
56 {
row_binder2row_binder257    row_binder2(F _f, unsigned i, unsigned j) : f(_f), m_i(i), m_j(j) {}
58 
59    template <class S>
operator ()row_binder260    Real operator()(const S& row)
61    {
62       return f(row[m_i], row[m_j]);
63    }
64 
65 private:
66    F f;
67    unsigned m_i, m_j;
68 };
69 
70 template<class Real, class F>
bind_func(F f,unsigned i,unsigned j)71 inline row_binder2<Real, F> bind_func(F f, unsigned i, unsigned j)
72 {
73    return row_binder2<Real, F>(f, i, j);
74 }
75 
76 template <class Real, class F>
77 struct row_binder3
78 {
row_binder3row_binder379    row_binder3(F _f, unsigned i, unsigned j, unsigned k) : f(_f), m_i(i), m_j(j), m_k(k) {}
80 
81    template <class S>
operator ()row_binder382    Real operator()(const S& row)
83    {
84       return f(row[m_i], row[m_j], row[m_k]);
85    }
86 
87 private:
88    F f;
89    unsigned m_i, m_j, m_k;
90 };
91 
92 template<class Real, class F>
bind_func(F f,unsigned i,unsigned j,unsigned k)93 inline row_binder3<Real, F> bind_func(F f, unsigned i, unsigned j, unsigned k)
94 {
95    return row_binder3<Real, F>(f, i, j, k);
96 }
97 
98 template <class Real, class F>
99 struct row_binder4
100 {
row_binder4row_binder4101    row_binder4(F _f, unsigned i, unsigned j, unsigned k, unsigned l) : f(_f), m_i(i), m_j(j), m_k(k), m_l(l) {}
102 
103    template <class S>
operator ()row_binder4104    Real operator()(const S& row)
105    {
106       return f(row[m_i], row[m_j], row[m_k], row[m_l]);
107    }
108 
109 private:
110    F f;
111    unsigned m_i, m_j, m_k, m_l;
112 };
113 
114 template<class Real, class F>
bind_func(F f,unsigned i,unsigned j,unsigned k,unsigned l)115 inline row_binder4<Real, F> bind_func(F f, unsigned i, unsigned j, unsigned k, unsigned l)
116 {
117    return row_binder4<Real, F>(f, i, j, k, l);
118 }
119 
120 template <class Real, class F>
121 struct row_binder2_i1
122 {
row_binder2_i1row_binder2_i1123    row_binder2_i1(F _f, unsigned i, unsigned j) : f(_f), m_i(i), m_j(j) {}
124 
125    template <class S>
operator ()row_binder2_i1126    Real operator()(const S& row)
127    {
128       return f(boost::math::itrunc(Real(row[m_i])), row[m_j]);
129    }
130 
131 private:
132    F f;
133    unsigned m_i, m_j;
134 };
135 
136 template<class Real, class F>
bind_func_int1(F f,unsigned i,unsigned j)137 inline row_binder2_i1<Real, F> bind_func_int1(F f, unsigned i, unsigned j)
138 {
139    return row_binder2_i1<Real, F>(f, i, j);
140 }
141 
142 template <class Real, class F>
143 struct row_binder3_i2
144 {
row_binder3_i2row_binder3_i2145    row_binder3_i2(F _f, unsigned i, unsigned j, unsigned k) : f(_f), m_i(i), m_j(j), m_k(k) {}
146 
147    template <class S>
operator ()row_binder3_i2148    Real operator()(const S& row)
149    {
150       return f(
151          boost::math::itrunc(Real(row[m_i])),
152          boost::math::itrunc(Real(row[m_j])),
153          row[m_k]);
154    }
155 
156 private:
157    F f;
158    unsigned m_i, m_j, m_k;
159 };
160 
161 template<class Real, class F>
bind_func_int2(F f,unsigned i,unsigned j,unsigned k)162 inline row_binder3_i2<Real, F> bind_func_int2(F f, unsigned i, unsigned j, unsigned k)
163 {
164    return row_binder3_i2<Real, F>(f, i, j, k);
165 }
166 
167 template <class Real, class F>
168 struct row_binder4_i2
169 {
row_binder4_i2row_binder4_i2170    row_binder4_i2(F _f, unsigned i, unsigned j, unsigned k, unsigned l) : f(_f), m_i(i), m_j(j), m_k(k), m_l(l) {}
171 
172    template <class S>
operator ()row_binder4_i2173    Real operator()(const S& row)
174    {
175       return f(
176          boost::math::itrunc(Real(row[m_i])),
177          boost::math::itrunc(Real(row[m_j])),
178          row[m_k],
179          row[m_l]);
180    }
181 
182 private:
183    F f;
184    unsigned m_i, m_j, m_k, m_l;
185 };
186 
187 template<class Real, class F>
bind_func_int2(F f,unsigned i,unsigned j,unsigned k,unsigned l)188 inline row_binder4_i2<Real, F> bind_func_int2(F f, unsigned i, unsigned j, unsigned k, unsigned l)
189 {
190    return row_binder4_i2<Real, F>(f, i, j, k, l);
191 }
192 
193 template <class Real, class F>
194 struct negate_type
195 {
negate_typenegate_type196    negate_type(F f) : m_f(f){}
197 
198    template <class S>
operator ()negate_type199    Real operator()(const S& row)
200    {
201       return -Real(m_f(row));
202    }
203 private:
204    F m_f;
205 };
206 
207 template <class Real, class F>
negate(F f)208 inline negate_type<Real, F> negate(F f)
209 {
210    return negate_type<Real, F>(f);
211 }
212 
213 #endif
214