11 #ifndef __NUMERICS_HEADER
12 #define __NUMERICS_HEADER
14 #define OPERATOR(op) \
15 template<typename T> \
16 T operator op(T a, T const & b) { \
17 ASSERT(a.size() == b.size()) \
18 for(typename T::size_type i = 0; i < a.size(); ++i) { \
32 typename T::value_type
scalar(T
const & a, T
const & b) {
33 ASSERT(a.size() == b.size())
35 typename T::value_type res =
typename T::value_type();
36 for(
typename T::size_type
i = 0;
i < a.size(); ++
i) {
43 typename T::value_type
d1(T
const & a, T
const & b) {
44 ASSERT(a.size() == b.size())
46 typename T::value_type res =
typename T::value_type();
47 for(
typename T::size_type
i = 0;
i < a.size(); ++
i) {
57 typename T::value_type
d2(T
const & a, T
const & b) {
58 ASSERT(a.size() == b.size())
60 typename T::value_type res =
typename T::value_type();
61 for(
typename T::size_type
i = 0;
i < a.size(); ++
i) {
63 res += (a[i] - b[i])*(a[i] - b[i]);
65 res += (b[i] - a[i])*(b[i] - a[i]);
72 typename T::value_type res =
typename T::value_type();
73 for(
typename T::size_type
i = 0;
i < a.size(); ++
i) {
81 template<
typename R,
typename T>
83 ASSERT(a.size() == b.size())
86 for(
typename T::size_type
i = 0;
i < a.size(); ++
i) {
92 template<
typename R,
typename T>
93 R
d1(T
const & a, T
const & b) {
94 ASSERT(a.size() == b.size())
97 for(
typename T::size_type
i = 0;
i < a.size(); ++
i) {
101 res += (b[i] - a[i]);
106 template<
typename R,
typename T>
107 R
d2(T
const & a, T
const & b) {
108 ASSERT(a.size() == b.size())
111 for(
typename T::size_type
i = 0;
i < a.size(); ++
i) {
113 res += (a[i] - b[i])*(a[i] - b[i]);
115 res += (b[i] - a[i])*(b[i] - a[i]);
120 template<
typename R,
typename T>
123 for(
typename T::size_type
i = 0;
i < a.size(); ++
i) {
129 #endif //__NUMERICS_HEADER
T::value_type accumulate(T const &a)
Definition: numerics.hpp:71
#define OPERATOR(op)
Definition: numerics.hpp:14
T::value_type d2(T const &a, T const &b)
Definition: numerics.hpp:57
T::value_type d1(T const &a, T const &b)
Definition: numerics.hpp:43
#define ASSERT(exp)
Definition: ard_assert.hpp:33
T::value_type scalar(T const &a, T const &b)
Definition: numerics.hpp:32