#ifndef WOLFF_MODELS_VECTOR_H #define WOLFF_MODELS_VECTOR_H #include #include #include namespace wolff { template class vector_t : public std::array { public: vector_t() { this->fill((T)0); (*this)[0] = (T)1; } vector_t(const T *x) { for (unsigned i = 0; i < q; i++) { (*this)[i] = x[i]; } } typedef vector_t M_t; typedef vector_t F_t; template inline vector_t& operator+=(const vector_t &v) { for (unsigned i = 0; i < q; i++) { (*this)[i] += (T)v[i]; } return *this; } template inline vector_t& operator-=(const vector_t &v) { for (unsigned i = 0; i < q; i++) { (*this)[i] -= (T)v[i]; } return *this; } inline vector_t operator*(unsigned x) const { vector_t result; for (unsigned i = 0; i < q; i++) { result[i] = x * (*this)[i]; } return result; } inline vector_t operator*(double x) const { vector_t result; for (unsigned i = 0; i < q; i++) { result[i] = x * (*this)[i]; } return result; } inline vector_t operator-(const vector_t& v) const { vector_t diff = *this; diff -= v; return diff; } inline T operator*(const vector_t& v) const { double prod = 0; for (unsigned i = 0; i < q; i++) { prod += v[i] * (*this)[i]; } return prod; } template inline vector_t operator/(U a) const { vector_t result; for (unsigned i = 0; i < q; i++) { result[i] = (*this)[i] / a; } return result; } }; template inline vector_t operator*(unsigned a, const vector_t&v) { return v * a; } template inline vector_t operator*(double a, const vector_t&v) { return v * a; } template std::ostream& operator<<(std::ostream& os, const vector_t&v) { os << "( "; for (T vi : v) { os << vi << " "; } os << ")"; return os; } } #endif