7 #ifndef ALPS_NUMERIC_ARRAY_HEADER 8 #define ALPS_NUMERIC_ARRAY_HEADER 15 #include <boost/throw_exception.hpp> 16 #include <boost/lambda/lambda.hpp> 17 #include <boost/array.hpp> 28 #define ALPS_NUMERIC_OPERATOR_EQ(OP_NAME, OPERATOR) \ 29 template<typename T, std::size_t N> \ 30 boost::array<T, N> & OP_NAME (boost::array<T, N> & lhs, boost::array<T, N> const & rhs) { \ 31 if(lhs.size() != rhs.size()) \ 32 boost::throw_exception(std::runtime_error("arrays must have the same size!" + ALPS_STACKTRACE)); \ 34 std::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs.begin(), std:: OPERATOR <T>() ); \ 43 #undef ALPS_NUMERIC_OPERATOR_EQ 46 template<std::
size_t N>
struct inf<
boost::array<double, N> > {
47 operator boost::array<double, N>
const() {
48 boost::array<double, N> retval;
49 for(
double & arg: retval) {
50 arg = std::numeric_limits<double>::infinity();
57 template<
typename T, std::
size_t N>
59 std::transform(lhs.begin(), lhs.end(), lhs.begin(), std::negate<T>());
64 template<
typename T,
typename U, std::
size_t N>
65 boost::array<T, N>
operator + (boost::array<T, N> lhs, boost::array<U, N>
const & rhs) {
66 std::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs.begin(), std::plus<T>() );
70 template<
typename T, std::
size_t N>
72 std::transform(arg.begin(), arg.end(), arg.begin(), boost::lambda::_1 + scalar);
75 template<
typename T, std::
size_t N>
77 std::transform(arg.begin(), arg.end(), arg.begin(), scalar + boost::lambda::_1);
82 template<
typename T,
typename U, std::
size_t N>
83 boost::array<T, N>
operator - (boost::array<T, N> lhs, boost::array<U, N>
const & rhs) {
84 std::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs.begin(), std::minus<T>() );
88 template<
typename T, std::
size_t N>
90 std::transform(arg.begin(), arg.end(), arg.begin(), boost::lambda::_1 - scalar);
93 template<
typename T, std::
size_t N>
95 std::transform(arg.begin(), arg.end(), arg.begin(), scalar - boost::lambda::_1);
100 template<
typename T,
typename U, std::
size_t N>
101 boost::array<T, N>
operator * (boost::array<T, N> lhs, boost::array<U, N>
const & rhs)
103 std::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs.begin(), std::multiplies<T>());
107 template<
typename T,
typename U, std::
size_t N>
108 boost::array<T, N>
operator / (boost::array<T, N> lhs, boost::array<U, N>
const & rhs)
110 std::transform(lhs.begin(), lhs.end(), rhs.begin(), lhs.begin(), std::multiplies<T>());
115 template<
typename T, std::
size_t N>
117 std::transform(lhs.begin(), lhs.end(), lhs.begin(), boost::lambda::_1 * scalar);
120 template<
typename T, std::
size_t N>
122 std::transform(rhs.begin(), rhs.end(), rhs.begin(), scalar * boost::lambda::_1);
127 template<
typename T, std::
size_t N>
129 std::transform(lhs.begin(), lhs.end(), lhs.begin(), boost::lambda::_1 / scalar);
132 template<
typename T, std::
size_t N>
134 std::transform(rhs.begin(), rhs.end(), rhs.begin(), scalar / boost::lambda::_1);
139 #define ALPS_NUMERIC_IMPLEMENT_FUNCTION(FUNCTION_NAME) \ 140 template<typename T, std::size_t N> boost::array<T, N> FUNCTION_NAME (boost::array<T, N> arg) { \ 141 using std:: FUNCTION_NAME ; \ 142 std::transform(arg.begin(), arg.end(), arg.begin(), static_cast<double (*)(double)>(& FUNCTION_NAME )); \ 160 #undef ALPS_NUMERIC_IMPLEMENT_FUNCTION 162 #define ALPS_NUMERIC_IMPLEMENT_FUNCTION(FUNCTION_NAME) \ 163 template<typename T, std::size_t N> boost::array<T, N> FUNCTION_NAME (boost::array<T, N> arg) { \ 164 using alps::numeric:: FUNCTION_NAME ; \ 165 std::transform(arg.begin(), arg.end(), arg.begin(), static_cast<double (*)(double)>(& FUNCTION_NAME )); \ 173 #undef ALPS_NUMERIC_IMPLEMENT_FUNCTION boost::array< T, N > sinh(boost::array< T, N > arg)
boost::array< T, N > tanh(boost::array< T, N > arg)
boost::array< T, N > cbrt(boost::array< T, N > arg)
boost::array< T, N > atan(boost::array< T, N > arg)
boost::array< T, N > log(boost::array< T, N > arg)
boost::array< T, N > sqrt(boost::array< T, N > arg)
#define ALPS_NUMERIC_IMPLEMENT_FUNCTION(FUNCTION_NAME)
boost::array< T, N > abs(boost::array< T, N > arg)
boost::array< T, N > operator*(boost::array< T, N > lhs, boost::array< U, N > const &rhs)
boost::array< T, N > cos(boost::array< T, N > arg)
boost::array< T, N > operator/(boost::array< T, N > lhs, boost::array< U, N > const &rhs)
mean_result< T > transform(no_prop, const transformer< T > &tf, const InResult &in)
Metafunction returning "mathematical scalar" type for type T.
boost::array< T, N > cosh(boost::array< T, N > arg)
boost::array< T, N > exp(boost::array< T, N > arg)
boost::array< T, N > operator+(boost::array< T, N > lhs, boost::array< U, N > const &rhs)
boost::array< T, N > asin(boost::array< T, N > arg)
boost::array< T, N > sin(boost::array< T, N > arg)
boost::array< T, N > acos(boost::array< T, N > arg)
#define ALPS_NUMERIC_OPERATOR_EQ(OP_NAME, OPERATOR)
boost::array< T, N > cb(boost::array< T, N > arg)
boost::array< T, N > tan(boost::array< T, N > arg)
boost::array< T, N > sq(boost::array< T, N > arg)
boost::array< T, N > operator-(boost::array< T, N > lhs)