22 #ifndef KJB_M_VECTOR_D_IMPL_H
23 #define KJB_M_VECTOR_D_IMPL_H
26 #include <l/l_sys_rand.h>
27 #include <sample/sample_gauss.h>
28 #include <boost/array.hpp>
38 #ifdef KJB_HAVE_BST_SERIAL
39 #include <boost/serialization/array.hpp>
54 std::copy(v.begin(), v.end(), this->begin());
61 std::copy(v.begin(), v.end(), this->begin());
62 this->operator[](
D-1) = fill1;
69 std::copy(v.begin(), v.end(), this->begin());
70 this->operator[](
D-2) = fill1;
71 this->operator[](
D-1) = fill2;
84 std::copy(v.
begin(), v.
end(), this->begin());
99 this->operator[](0) =
x;
100 this->operator[](1) =
y;
111 this->operator[](0) =
x;
112 this->operator[](1) =
y;
113 this->operator[](2) =
z;
123 this->operator[](0) =
x;
124 this->operator[](1) = y;
125 this->operator[](2) = z;
126 this->operator[](3) = w;
141 return this->operator[](0);
155 return this->operator[](0);
176 return this->operator[](1);
191 return this->operator[](1);
211 return this->operator[](2);
225 return this->operator[](2);
243 return this->operator[](3);
257 return this->operator[](3);
269 Base::operator=(other);
277 if (other.
size() !=
D)
282 std::copy(other.
begin(), other.
end(), this->begin());
291 std::transform(this->begin(), this->end(), second.begin(), this->begin(), std::minus<double>());
299 std::transform(this->begin(), this->end(), this->begin(), std::bind2nd(std::minus<double>(), second));
307 std::transform(this->begin(), this->end(), second.begin(), this->begin(), std::plus<double>());
315 std::transform(this->begin(), this->end(), this->begin(), std::bind2nd(std::plus<double>(), second));
323 for (
size_t i = 0;
i <
D;
i++)
325 this->operator[](
i) *= s;
334 return (*
this) *= 1/s;
352 for (
typename Base::const_iterator it = this->begin(); it != this->end(); ++it)
364 return std::inner_product(this->begin(), this->end(), this->begin(), 0.0);
371 return sqrt(magnitude_squared());
378 *
this /= this->magnitude();
392 for (
size_t i = 0;
i < this->size(); ++
i)
394 this->operator[](
i) = -this->operator[](
i);
400 #ifdef KJB_HAVE_BST_SERIAL
402 template <
class Archive>
405 ar & ::boost::serialization::base_object<boost::array<double, D> >(*this);
412 template <std::
size_t D>
426 template <std::
size_t D_out, std::
size_t D_in>
427 Vector_d<D_out>
operator*(
const Matrix_d<D_out, D_in>&
m,
const Vector_d<D_in> v)
429 Vector_d<D_out> result();
431 for (
int row = 0; row < D_out; row++)
435 for (
size_t col = 0; col < D_in; col++)
437 x +=
m(row, col) * v[col];
454 template <std::
size_t D>
460 template <std::
size_t D>
466 template <std::
size_t D>
469 return -second + first;
472 template <std::
size_t D>
476 for (
size_t i = 0;
i <
D;
i++)
478 result[
i] = -result[
i];
484 template <std::
size_t D>
490 template <std::
size_t D>
496 template <std::
size_t D>
499 return second + first;
502 template <std::
size_t D>
508 template <std::
size_t D>
514 template <std::
size_t D>
520 template<std::
size_t N>
527 template<std::
size_t N>
531 return boost::operator==<double, N>(first, second);
534 template<std::
size_t N>
538 return boost::operator!= <double, N>(first, second);
541 template<std::
size_t N>
542 bool operator<(const Vector_d<N>& first,
const Vector_d<N>& second)
545 return boost::operator< <double, N>(first, second);
548 template<std::
size_t N>
552 return boost::operator> <double, N>(first, second);
555 template<std::
size_t N>
556 bool operator<=(const Vector_d<N>& first,
const Vector_d<N>& second)
559 return boost::operator<= <double, N>(first, second);
562 template<std::
size_t N>
566 return boost::operator>= <double, N>(first, second);
593 std::generate(result.begin(), result.end(), kjb_c::kjb_rand);
601 std::generate(result.begin(), result.end(), kjb_c::gauss_rand);
614 template <std::
size_t D>
615 std::ostream& operator<<(std::ostream& out, const Vector_d<D>& v)
618 std::streamsize w = out.width();
619 std::streamsize p = out.precision();
620 std::ios::fmtflags f = out.flags();
622 out << std::scientific;
623 for (
size_t i = 0;
i < v.size();
i++)
625 out << std::setw(16) << std::setprecision(8) << v[
i];
634 template <std::
size_t D>
638 for (
size_t i = 0;
i < v.size();
i++)
646 template <std::
size_t D>
649 return std::inner_product(op1.begin(), op1.end(), op2.begin(), 0.0);
657 template <std::
size_t D>
660 return (op2 - op1).magnitude();
668 template <std::
size_t D>
671 return (op2 - op1).magnitude_squared();
Vector_d()
default constructor
Definition: m_vector_d.impl.h:46
void set_z(double zv)
Changes the third element of a vector (if it exists).
Definition: m_vector_d.impl.h:230
double vector_distance(const Int_vector &op1, const Int_vector &op2)
Compute the Euclidian distance between two vectors.
Definition: l_int_vector.h:1569
Vector_d< 4 > Vector4
Definition: gr_opengl.h:38
double magnitude() const
return the l2-norm of this vector
Definition: m_vector_d.impl.h:369
double vector_distance_squared(const Int_vector &op1, const Int_vector &op2)
Compute the square of the Euclidian distance between two vectors.
Definition: l_int_vector.h:1581
Definition for the Matrix class, a thin wrapper on the KJB Matrix struct and its related functionalit...
Vector create_random_vector(int length)
Construct a vector with values drawn from a uniform distribution over [0,1].
Definition: m_vector.h:1643
size_type size() const
Alias to get_length(). Required to comply with stl Container concept.
Definition: m_vector.h:510
Vector_d< 3 > Vector3
Definition: g_quaternion.h:37
Object thrown when an argument is of the wrong size or dimensions.
Definition: l_exception.h:426
void set_x(double xv)
Definition: m_vector_d.impl.h:159
Vector_d< D > & operator/=(double s)
Definition: m_vector_d.impl.h:332
void swap(Perspective_camera &cam1, Perspective_camera &cam2)
Swap two cameras.
Definition: perspective_camera.h:599
double y() const
Definition: m_vector_d.impl.h:169
double z() const
Definition: m_vector_d.impl.h:205
Vector_d< D > normalized() const
Non-mutating (functionally pure) version of normalize()
Definition: m_vector_d.impl.h:384
Image operator-(const Image &im1, const Image &im2)
Subtract two images.
Definition: i_image.h:843
#define KJB_THROW(ex)
Definition: l_exception.h:46
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
void set_w(double wv)
Changes the fourth element of a vector (if it exists).
Definition: m_vector_d.impl.h:262
bool operator>=(const Int_vector &op1, const Int_vector &op2)
Test lexicographic ordering between vectors.
Definition: l_int_vector.h:1494
Vector_d< D > & operator*=(double s)
Definition: m_vector_d.impl.h:321
std::istream & operator>>(std::istream &ist, Detection_type &type)
Stream in an detection.
Definition: d_type.cpp:91
void resize(size_t n)
Definition: m_vector_d.impl.h:339
Image operator+(const Image &op1, const Image &op2)
Add two images.
Definition: i_image.h:834
double x() const
Definition: m_vector_d.impl.h:134
Vector_d< D > & operator-=(const Vector_d< D > &second)
Definition: m_vector_d.impl.h:289
iterator end()
Definition: m_vector.h:557
double w() const
read fourth element (i.e., index 3) of vector, if it exists.
Definition: m_vector_d.impl.h:241
Vector_d< D > & operator+=(const Vector_d< D > &second)
Definition: m_vector_d.impl.h:305
iterator begin()
Definition: m_vector.h:537
x
Definition: APPgetLargeConnectedEdges.m:100
Vector_d< D > & normalize()
normalize this vector to have l2-norm of 1.0
Definition: m_vector_d.impl.h:376
bool operator>(const Int_vector &op1, const Int_vector &op2)
Test lexicographic ordering between vectors.
Definition: l_int_vector.h:1485
double norm1() const
Definition: m_vector_d.impl.h:348
Image operator/(const Image &op1, double op2)
Scale an image in channel space, yielding a new image.
Definition: i_image.h:825
Vector multiply_matrix_and_vector_d_dispatch_(const Matrix &m, const double *v, size_t size)
dispatch for operator*(Matrix, Vector_d). This deals with a circular dependency between matrix...
Definition: m_vector_d.cpp:97
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
bool operator!=(const Int_matrix &op1, const Int_matrix::Impl_type &op2)
Test for any difference between two matrices.
Definition: l_int_matrix.h:1274
#define KJB_THROW_3(ex, fmt, params)
Definition: l_exception.h:56
Vector_d & operator=(const Vector_d &other)
assignment
Definition: m_vector_d.impl.h:267
bool operator==(const Int_matrix &op1, const Int_matrix::Impl_type &op2)
Test for exact equality between two matrices.
Definition: l_int_matrix.cpp:218
Vector create_gauss_random_vector(int length)
Construct a vector with values drawn from a standard Gaussian distribution (mean 0, variance 1);.
Definition: m_vector.cpp:390
double norm1(const Vector &op)
Compute L1-norm of vector.
Definition: m_vector.h:2020
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
Vector_d< D > create_unit_vector(size_t d)
Definition: m_vector_d.impl.h:606
Definition: g_quaternion.h:37
double norm2(const Int_vector &op1)
Compute l2-norm of vector.
Definition: l_int_vector.h:1558
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
void set_y(double yv)
Changes the second element of a vector (if it exists).
Definition: m_vector_d.impl.h:196
This class implements matrices, in the linear-algebra sense, with real-valued elements.
Definition: m_matrix.h:94
long int dot(const Int_vector &op1, const Int_vector &op2)
Returns dot product of this and op2.
Definition: l_int_vector.h:1532
for m
Definition: APPgetLargeConnectedEdges.m:64
D
Definition: APPgetLargeConnectedEdges.m:106
Support for error handling exception classes in libKJB.
Vector_d< D > & negate()
Definition: m_vector_d.impl.h:390
Vector_d< 2 > Vector2
Definition: gr_opengl.h:35
Gsl_Vector operator*(double scalar, const Gsl_Vector &vector)
multiply scalar and vector, scalar written on the left side
Definition: gsl_vector.h:661
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
double magnitude_squared() const
return the squared l2-norm of this vector
Definition: m_vector_d.impl.h:362
Object thrown when computation fails somehow during execution.
Definition: l_exception.h:321