1 #ifndef RIVET_MATH_VECTORN
2 #define RIVET_MATH_VECTORN
4 #include "Rivet/Math/MathHeader.hh"
5 #include "Rivet/Math/MathUtils.hh"
7 #include "Rivet/Math/eigen/vector.h"
28 Vector() { _vec.loadZero(); }
31 : _vec(other._vec) { }
33 const double&
get(
const size_t index)
const {
35 throw std::runtime_error(
"Tried to access an invalid vector index.");
52 Vector<N>&
set(
const size_t index,
const double value) {
54 throw std::runtime_error(
"Tried to access an invalid vector index.");
67 bool isZero(
double tolerance=1E-5)
const {
68 for (
size_t i=0; i < N; ++i) {
78 for (
size_t i = 0; i <
size(); ++i) {
79 const double element =
get(i);
80 mod2 += element*element;
88 const double norm =
mod2();
100 bool operator==(
const Vector<N>& a)
const {
101 return _vec == a._vec;
104 bool operator!=(
const Vector<N>& a)
const {
105 return _vec != a._vec;
108 bool operator<(const Vector<N>& a)
const {
109 return _vec < a._vec;
112 bool operator<=(const Vector<N>& a)
const {
113 return _vec <= a._vec;
116 bool operator>(
const Vector<N>& a)
const {
117 return _vec > a._vec;
120 bool operator>=(
const Vector<N>& a)
const {
121 return _vec >= a._vec;
126 double&
get(
const size_t index) {
128 throw std::runtime_error(
"Tried to access an invalid vector index.");
135 Eigen::Vector<double,N> _vec;
166 for (
size_t i = 0; i < v.
size(); ++i) {
167 out << (fabs(v[i]) < 1E-30 ? 0.0 : v[i]);
168 if (i < v.
size()-1) out <<
", ";
176 inline std::ostream& operator<<(std::ostream& out, const Vector<N>& v) {
190 for (
size_t i = 0; i < N; ++i) {
191 const double a = va.get(i);
192 const double b = vb.get(i);
202 return v.
isZero(tolerance);