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