8 #ifndef IMPALGEBRA_VECTOR_D_H 
    9 #define IMPALGEBRA_VECTOR_D_H 
   11 #include <IMP/algebra/algebra_config.h> 
   20 #include <boost/random/variate_generator.hpp> 
   21 #include <boost/random/normal_distribution.hpp> 
   22 #include <boost/range.hpp> 
   23 #include "internal/vector.h" 
   27 #include <boost/random/normal_distribution.hpp> 
   29 IMPALGEBRA_BEGIN_NAMESPACE
 
   42   IMP_ALGEBRA_VECTOR_METHODS(D);
 
   47   std::vector<double> get_range(
double x0, 
double x1, 
double x2, 
double x3,
 
   48                                 double x4, 
double x5) {
 
   51     std::vector<double> ret;
 
   53     if (x1 != std::numeric_limits<double>::max()) ret.push_back(x1);
 
   54     if (x2 != std::numeric_limits<double>::max()) ret.push_back(x2);
 
   55     if (x3 != std::numeric_limits<double>::max()) ret.push_back(x3);
 
   56     if (x4 != std::numeric_limits<double>::max()) ret.push_back(x4);
 
   57     if (x5 != std::numeric_limits<double>::max()) ret.push_back(x5);
 
   62   IMP_ALGEBRA_VECTOR_METHODS(-1);
 
   63   explicit VectorD(
double x0, 
double x1 = std::numeric_limits<double>::max(),
 
   64                    double x2 = std::numeric_limits<double>::max(),
 
   65                    double x3 = std::numeric_limits<double>::max(),
 
   66                    double x4 = std::numeric_limits<double>::max(),
 
   67                    double x5 = std::numeric_limits<double>::max())
 
   68       : P(get_range(x0, x1, x2, x3, x4, x5)) {}
 
   72 class VectorD<1> : 
public VectorBaseD<1> {
 
   74   IMP_ALGEBRA_VECTOR_METHODS(1);
 
   77   VectorD(
double x) { P::operator[](0) = x; }
 
   80 class VectorD<2> : 
public VectorBaseD<2> {
 
   82   IMP_ALGEBRA_VECTOR_METHODS(2);
 
   84   VectorD(
double x, 
double y) {
 
   90 class VectorD<3> : 
public VectorBaseD<3> {
 
   92   IMP_ALGEBRA_VECTOR_METHODS(3);
 
   94   VectorD(
double x, 
double y, 
double z) {
 
  101 class VectorD<4> : 
public VectorBaseD<4> {
 
  103   IMP_ALGEBRA_VECTOR_METHODS(4);
 
  105   VectorD(
double x0, 
double x1, 
double x2, 
double x3) {
 
  106     P::operator[](0) = x0;
 
  107     P::operator[](1) = x1;
 
  108     P::operator[](2) = x2;
 
  109     P::operator[](3) = x3;
 
  113 class VectorD<5> : 
public VectorBaseD<5> {
 
  115   IMP_ALGEBRA_VECTOR_METHODS(5);
 
  117   VectorD(
double x0, 
double x1, 
double x2, 
double x3, 
double x4) {
 
  118     P::operator[](0) = x0;
 
  119     P::operator[](1) = x1;
 
  120     P::operator[](2) = x2;
 
  121     P::operator[](3) = x3;
 
  122     P::operator[](4) = x4;
 
  126 class VectorD<6> : 
public VectorBaseD<6> {
 
  128   IMP_ALGEBRA_VECTOR_METHODS(6);
 
  130   VectorD(
double x0, 
double x1, 
double x2, 
double x3, 
double x4, 
double x5) {
 
  131     P::operator[](0) = x0;
 
  132     P::operator[](1) = x1;
 
  133     P::operator[](2) = x2;
 
  134     P::operator[](3) = x3;
 
  135     P::operator[](4) = x4;
 
  136     P::operator[](5) = x5;
 
  143 inline std::ostream &operator<<(std::ostream &out, const VectorD<D> &v) {
 
  151 inline std::istream &operator>>(std::istream &in, VectorD<D> &v) {
 
  152   for (
unsigned int i = 0; i < D; ++i) {
 
  168                   "Dimensions don't match.");
 
  169   for (
unsigned int i = 0; i < a.get_dimension(); ++i) {
 
  172     else if (a[i] > b[i])
 
  189   return (v1 - v2).get_squared_magnitude();
 
  210   IMP_USAGE_CHECK(coordinate < D, 
"There are only " << D << 
" basis vectors");
 
  212   for (
unsigned int i = 0; i < D; ++i) {
 
  226   return get_basis_vector_d<D>(coordinate);
 
  234                   "There are only " << D << 
" basis vectors");
 
  235   boost::scoped_array<double> vs(
new double[D]);
 
  236   for (
int i = 0; i < D; ++i) {
 
  237     if (i == static_cast<int>(coordinate))
 
  242   return VectorD<-1>(vs.get(), vs.get() + D);
 
  255   for (
int i = 0; i < D; ++i) {
 
  266   return get_zero_vector_d<D>();
 
  274   return VectorD<-1>(vs.begin(), vs.end());
 
  287   for (
unsigned int i = 0; i < D; ++i) {
 
  299   return get_ones_vector_d<D>(v);
 
  306   boost::scoped_array<double> vv(
new double[D]);
 
  307   for (
unsigned int i = 0; i < D; ++i) {
 
  310   return VectorD<-1>(vv.get(), vv.get() + D);
 
  329 inline double get_l2_norm(
const VectorD<D> &v) {
 
  330   return v.get_magnitude();
 
  334 inline double get_l1_norm(
const VectorD<D> &v) {
 
  335   double n = std::abs(v[0]);
 
  336   for (
unsigned int i = 1; i < v.get_dimension(); ++i) {
 
  343 inline double get_linf_norm(
const VectorD<D> &v) {
 
  344   double n = std::abs(v[0]);
 
  345   for (
unsigned int i = 1; i < v.get_dimension(); ++i) {
 
  346     n = std::max(n, std::abs(v[i]));
 
  357   const VectorD<D> &v_;
 
  358   SpacesIO(
const VectorD<D> &v) : v_(v) {}
 
  363   const VectorD<D> &v_;
 
  364   CommasIO(
const VectorD<D> &v) : v_(v) {}
 
  367 inline std::ostream &operator<<(std::ostream &out, const SpacesIO<D> &s) {
 
  368   s.v_.show(out, 
" ", 
false);
 
  372 inline std::ostream &operator<<(std::ostream &out, const CommasIO<D> &s) {
 
  373   s.v_.show(out, 
", ", 
false);
 
  383 inline SpacesIO<D> spaces_io(
const VectorD<D> &v) {
 
  384   return SpacesIO<D>(v);
 
  393 inline CommasIO<D> commas_io(
const VectorD<D> &v) {
 
  394   return CommasIO<D>(v);
 
  435 template <
class C, 
class E>
 
  447   for (
unsigned int i = 0; i < ret.get_dimension(); ++i) {
 
  458   IMP_USAGE_CHECK(a.size() == b.get_dimension(), 
"Dimensions don't match,");
 
  460   for (
unsigned int i = 0; i < ret.get_dimension(); ++i) {
 
  466 IMPALGEBRA_END_NAMESPACE
 
Vector< VectorD< 1 > > Vector1Ds
 
Vector< VectorD< 3 > > Vector3Ds
 
double get_squared_distance(const VectorD< D > &v1, const VectorD< D > &v2)
Compute the squared distance between two vectors. 
 
Vector< VectorD< 5 > > Vector5Ds
 
Exception definitions and assertions. 
 
Vector< VectorD< 2 > > Vector2Ds
 
const VectorD< C::DIMENSION > & get_vector_geometry(const C &g)
 
A Cartesian vector in D-dimensions. 
 
#define IMP_UNUSED(variable)
 
VectorD< D > get_elementwise_product(const Ints &a, const algebra::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 > > VectorKDs
 
VectorD< D > get_basis_vector_d(unsigned int coordinate)
Return the basis vector for the given coordinate. 
 
void set_vector_geometry(C &g, const E &v)
 
Vector< VectorD< 6 > > Vector6Ds
 
Various general useful functions for IMP. 
 
Vector< VectorD< 4 > > Vector4Ds
 
VectorD<-1 > get_ones_vector_kd(unsigned int D, double v)
Return a vector of ones (or another constant) 
 
VectorD< D > get_ones_vector_d(double v=1)
Return a vector of ones (or another constant) 
 
Helper macros for throwing and handling exceptions. 
 
VectorD<-1 > get_basis_vector_kd(int D, unsigned int coordinate)
Return a dynamically sized basis vector. 
 
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method. 
 
VectorD< D > operator*(double s, VectorD< D > o)
 
double get_distance(const VectorD< D > &v1, const VectorD< D > &v2)
Compute the distance between two vectors. 
 
Random number generators used by IMP. 
 
A Cartesian vector in D-dimensions. 
 
VectorD<-1 > get_zero_vector_kd(int D)
Return a dynamically sized vector of zeros.