12 #ifndef THRILL_COMMON_VECTOR_HEADER 13 #define THRILL_COMMON_VECTOR_HEADER 27 template <
size_t D,
typename Type =
double>
36 static size_t dim() {
return D; }
37 static size_t size() {
return D; }
45 std::fill(p.
x, p.
x +
D, 0.0);
49 std::fill(x, x +
D, init_val);
52 template <
typename Distribution,
typename Generator>
56 for (
size_t i = 0; i <
D; ++i) p.
x[i] = dist(gen);
61 for (
size_t i = 0; i <
D; ++i) sum += x[i] * x[i];
62 return std::sqrt(sum);
66 for (
size_t i = 0; i <
D; ++i) sum += (x[i] - b.
x[i]) * (x[i] - b.
x[i]);
74 for (
size_t i = 0; i <
D; ++i) p.
x[i] = x[i] + b.
x[i];
78 for (
size_t i = 0; i <
D; ++i) x[i] += b.
x[i];
83 for (
size_t i = 0; i <
D; ++i) p.
x[i] = x[i] - b.
x[i];
88 for (
size_t i = 0; i <
D; ++i) p.
x[i] = x[i] / s;
92 for (
size_t i = 0; i <
D; ++i) x[i] /= s;
97 for (
size_t i = 1; i !=
D; ++i) os <<
',' << a.
x[i];
102 for (
size_t i = 0; i <
D; ++i) r += x[i] * b.
x[i];
108 template <
typename Archive>
117 for (
size_t i = 0; i <
D; ++i) p.
x[i] = a * b.
x[i];
122 template <
typename Type =
double>
136 size_t dim()
const {
return x.size(); }
137 size_t size()
const {
return x.size(); }
143 std::fill(x.begin(), x.end(), init_val);
146 template <
typename Distribution,
typename Generator>
149 for (
size_t i = 0; i <
D; ++i) p.
x[i] = dist(gen);
153 assert(x.size() == b.
x.size());
155 for (
size_t i = 0; i < x.size(); ++i)
156 sum += (x[i] - b.
x[i]) * (x[i] - b.
x[i]);
164 for (
size_t i = 0; i < x.size(); ++i) sum += x[i] * x[i];
165 return std::sqrt(sum);
168 assert(x.size() == b.
x.size());
170 for (
size_t i = 0; i < x.size(); ++i) p.
x[i] = x[i] + b.
x[i];
174 assert(x.size() == b.
x.size());
175 for (
size_t i = 0; i < x.size(); ++i) x[i] += b.
x[i];
179 assert(x.size() == b.
x.size());
181 for (
size_t i = 0; i < x.size(); ++i) p.
x[i] = x[i] - b.
x[i];
186 for (
size_t i = 0; i < x.size(); ++i) p.
x[i] = x[i] / s;
190 for (
size_t i = 0; i < x.size(); ++i) x[i] /= s;
195 for (
size_t i = 0; i < x.size(); ++i) r += x[i] * b.
x[i];
200 for (
size_t i = 1; i != a.
x.size(); ++i) os <<
',' << a.
x[i];
205 template <
typename Archive>
213 for (
size_t i = 0; i < b.
x.size(); ++i) p.
x[i] = a * b.
x[i];
220 #endif // !THRILL_COMMON_VECTOR_HEADER static Vector Make(size_t D_)
Vector operator-(const Vector &b) const
A variable-length D-dimensional point with double precision.
void serialize(Archive &archive)
static VVector Random(size_t D, Distribution &dist, Generator &gen)
Vector operator/(const Type &s) const
void serialize(Archive &archive)
serialization method for cereal.
Type dot(const VVector &b) const
TypeVector x
coordinates array
Vector & operator+=(const Vector &b)
friend std::ostream & operator<<(std::ostream &os, const Vector &a)
static Vector Random(size_t dim, Distribution &dist, Generator &gen)
Type DistanceSquare(const Vector &b) const
Vector< D > operator*(const double a, const Vector< D > &b)
Type dot(const Vector &b) const
Vector fill(const Type init_val)
thrill::common::Vector< D, double > Vector
static VVector Make(size_t D)
thrill::common::VVector< double > VVector
std::vector< Type > TypeVector
Vector & operator/=(const Type &s)
Type Distance(const Vector &b) const
Vector operator+(const Vector &b) const
VVector fill(const Type init_val)
Type DistanceSquare(const VVector &b) const
Type x[D]
coordinates array
Type Distance(const VVector &b) const
A compile-time fixed-length D-dimensional point with double precision.