8#ifndef IMPKERNEL_VECTOR_D_H
9#define IMPKERNEL_VECTOR_D_H
11#include <IMP/kernel_config.h>
12#include <IMP/internal/VectorBaseD.h>
20#include <boost/random/variate_generator.hpp>
21#include <boost/random/normal_distribution.hpp>
22#include <boost/range.hpp>
26#include <boost/random/normal_distribution.hpp>
28IMPKERNEL_BEGIN_NAMESPACE
38class VectorD :
public internal::VectorBaseD<D> {
41 IMP_VECTOR_METHODS(D);
45class VectorD<-1> :
public internal::VectorBaseD<-1> {
46 std::vector<double> get_range(
double x0,
double x1,
double x2,
double x3,
47 double x4,
double x5) {
50 std::vector<double> ret;
52 if (x1 != std::numeric_limits<double>::max()) ret.push_back(x1);
53 if (x2 != std::numeric_limits<double>::max()) ret.push_back(x2);
54 if (x3 != std::numeric_limits<double>::max()) ret.push_back(x3);
55 if (x4 != std::numeric_limits<double>::max()) ret.push_back(x4);
56 if (x5 != std::numeric_limits<double>::max()) ret.push_back(x5);
61 IMP_VECTOR_METHODS(-1);
62 explicit VectorD(
double x0,
double x1 = std::numeric_limits<double>::max(),
63 double x2 = std::numeric_limits<double>::max(),
64 double x3 = std::numeric_limits<double>::max(),
65 double x4 = std::numeric_limits<double>::max(),
66 double x5 = std::numeric_limits<double>::max())
67 : P(get_range(x0, x1, x2, x3, x4, x5)) {}
71class VectorD<1> :
public internal::VectorBaseD<1> {
73 IMP_VECTOR_METHODS(1);
76 VectorD(
double x) { P::operator[](0) = x; }
79class VectorD<2> :
public internal::VectorBaseD<2> {
81 IMP_VECTOR_METHODS(2);
83 VectorD(
double x,
double y) {
89class VectorD<3> :
public internal::VectorBaseD<3> {
91 IMP_VECTOR_METHODS(3);
93 VectorD(
double x,
double y,
double z) {
100class VectorD<4> :
public internal::VectorBaseD<4> {
102 IMP_VECTOR_METHODS(4);
104 VectorD(
double x0,
double x1,
double x2,
double x3) {
105 P::operator[](0) = x0;
106 P::operator[](1) = x1;
107 P::operator[](2) = x2;
108 P::operator[](3) = x3;
112class VectorD<5> :
public internal::VectorBaseD<5> {
114 IMP_VECTOR_METHODS(5);
116 VectorD(
double x0,
double x1,
double x2,
double x3,
double x4) {
117 P::operator[](0) = x0;
118 P::operator[](1) = x1;
119 P::operator[](2) = x2;
120 P::operator[](3) = x3;
121 P::operator[](4) = x4;
125class VectorD<6> :
public internal::VectorBaseD<6> {
127 IMP_VECTOR_METHODS(6);
129 VectorD(
double x0,
double x1,
double x2,
double x3,
double x4,
double x5) {
130 P::operator[](0) = x0;
131 P::operator[](1) = x1;
132 P::operator[](2) = x2;
133 P::operator[](3) = x3;
134 P::operator[](4) = x4;
135 P::operator[](5) = x5;
142inline std::ostream &operator<<(std::ostream &out,
const VectorD<D> &v) {
150inline std::istream &operator>>(std::istream &in, VectorD<D> &v) {
151 for (
unsigned int i = 0; i < D; ++i) {
167 "Dimensions don't match.");
168 for (
unsigned int i = 0; i < a.get_dimension(); ++i) {
171 else if (a[i] > b[i])
188 return (v1 - v2).get_squared_magnitude();
209 IMP_USAGE_CHECK(coordinate < D,
"There are only " << D <<
" basis vectors");
211 for (
unsigned int i = 0; i < D; ++i) {
233 "There are only " << D <<
" basis vectors");
234 boost::scoped_array<double> vs(
new double[D]);
235 for (
int i = 0; i < D; ++i) {
236 if (i ==
static_cast<int>(coordinate))
241 return VectorD<-1>(vs.get(), vs.get() + D);
245inline VectorD<-1> get_basis_vector_kd(
int D,
unsigned int coordinate) {
246 return get_basis_vector_kd<-1>(D, coordinate);
254 for (
int i = 0; i < D; ++i) {
273 return VectorD<-1>(vs.begin(), vs.end());
277inline VectorD<-1> get_zero_vector_kd(
int D) {
278 return get_zero_vector_kd<-1>(D);
286 for (
unsigned int i = 0; i < D; ++i) {
305 boost::scoped_array<double> vv(
new double[D]);
306 for (
unsigned int i = 0; i < D; ++i) {
309 return VectorD<-1>(vv.get(), vv.get() + D);
313inline VectorD<-1> get_ones_vector_kd(
unsigned int D,
double v = 1) {
314 return get_ones_vector_kd<-1>(D, v);
328inline double get_l2_norm(
const VectorD<D> &v) {
329 return v.get_magnitude();
333inline double get_l1_norm(
const VectorD<D> &v) {
334 double n = std::abs(v[0]);
335 for (
unsigned int i = 1; i < v.get_dimension(); ++i) {
342inline double get_linf_norm(
const VectorD<D> &v) {
343 double n = std::abs(v[0]);
344 for (
unsigned int i = 1; i < v.get_dimension(); ++i) {
345 n = std::max(n, std::abs(v[i]));
356 const VectorD<D> &v_;
357 SpacesIO(
const VectorD<D> &v) : v_(v) {}
362 const VectorD<D> &v_;
363 CommasIO(
const VectorD<D> &v) : v_(v) {}
366inline std::ostream &operator<<(std::ostream &out,
const SpacesIO<D> &s) {
367 s.v_.show(out,
" ",
false);
371inline std::ostream &operator<<(std::ostream &out,
const CommasIO<D> &s) {
372 s.v_.show(out,
", ",
false);
382inline SpacesIO<D> spaces_io(
const VectorD<D> &v) {
383 return SpacesIO<D>(v);
392inline CommasIO<D> commas_io(
const VectorD<D> &v) {
393 return CommasIO<D>(v);
434template <
class C,
class E>
446 for (
unsigned int i = 0; i < ret.get_dimension(); ++i) {
457 IMP_USAGE_CHECK(a.size() == b.get_dimension(),
"Dimensions don't match,");
459 for (
unsigned int i = 0; i < ret.get_dimension(); ++i) {
465IMPKERNEL_END_NAMESPACE
469 template <
unsigned int I,
int D>
471 static_assert(D > 0,
"std::get does not work for VectorKD");
472 static_assert(I < D,
"vector index is within bounds");
473 return *(v.begin() + I);
476 template <
unsigned int I,
int D>
477 double& get(IMP::VectorD<D> &v) {
478 static_assert(D > 0,
"std::get does not work for VectorKD");
479 static_assert(I < D,
"vector index is within bounds");
480 return *(v.begin() + I);
Helper macros for throwing and handling exceptions.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
A Cartesian vector in D-dimensions.
A more IMP-like version of the std::vector.
VectorD(const Range &r)
Will accept a list of floats from Python.
Exception definitions and assertions.
Vector< VectorD< 3 > > Vector3Ds
Vector< VectorD< 6 > > Vector6Ds
Vector< VectorD<-1 > > VectorKDs
VectorD< D > get_zero_vector_kd(int Di)
Return a dynamically sized vector of zeros.
Vector< VectorD< 2 > > Vector2Ds
double get_squared_distance(const VectorD< D > &v1, const VectorD< D > &v2)
Compute the squared distance between two vectors.
const algebra::Vector3D & get_vector_geometry(Particle *p)
VectorD< D > get_basis_vector_d(unsigned int coordinate)
Return the basis vector for the given coordinate.
IMP::Vector< Int > Ints
Standard way to pass a bunch of Int values.
Vector< VectorD< 5 > > Vector5Ds
VectorD< D > get_ones_vector_d(double v=1)
Return a vector of ones (or another constant).
VectorD< D > get_ones_vector_kd(unsigned int Di, double v=1)
Return a vector of ones (or another constant).
VectorD< D > get_elementwise_product(const VectorD< D > &a, const VectorD< D > &b)
Return the vector that is the elementwise product of the two.
int compare(const VectorD< D > &a, const VectorD< D > &b)
lexicographic comparison of two vectors
VectorD< D > get_zero_vector_d()
Return a vector of zeros.
Vector< VectorD< 1 > > Vector1Ds
Vector< VectorD< 4 > > Vector4Ds
VectorD< D > get_basis_vector_kd(int Di, unsigned int coordinate)
Return the basis vector for the given coordinate.
VectorD< D > operator*(double s, VectorD< D > o)
IMP::Vector< Float > Floats
Standard way to pass a bunch of Float values.
double get_distance(const VectorD< D > &v1, const VectorD< D > &v2)
Compute the distance between two vectors.
void set_vector_geometry(Particle *p, const algebra::Vector3D &v)
Random number generators used by IMP.
Various general useful functions for IMP.
Various helper macros for the VectorD class.
#define IMP_UNUSED(variable)