Vector.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2008-2015 Imperial College London
5  * Copyright 2008-2015 Daniel Rueckert, Julia Schnabel
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef MIRTK_Vector_H
21 #define MIRTK_Vector_H
22 
23 #include "mirtk/Object.h"
24 
25 #include "mirtk/Math.h"
26 #include "mirtk/Indent.h"
27 #include "mirtk/Cfstream.h"
28 #include "mirtk/Memory.h"
29 #include "mirtk/Array.h"
30 
31 
32 namespace mirtk {
33 
34 
35 // Forward declaration of specialized vector types included after
36 // declaration of Vector for definition of inline functions
37 template <class T> struct Vector3D;
38 template <class T> struct Vector4D;
39 
40 /**
41  * Vector class.
42  */
43 class Vector : public Object
44 {
45  mirtkObjectMacro(Vector);
46 
47  // ---------------------------------------------------------------------------
48  // Data members
49 
50 protected:
51 
52  /// Number of rows
53  int _rows;
54 
55  /// Vector elements
56  double *_vector;
57 
58 public:
59 
60  // ---------------------------------------------------------------------------
61  // Construction/Destruction
62 
63  /// Default constructor
64  Vector();
65 
66  /// Constructor for given row dimensions
67  explicit Vector(int);
68 
69  /// Constructor for given row dimensions
70  Vector(int, double);
71 
72  /// Constructor for given row dimensions
73  Vector(int, double *);
74 
75  /// Copy constructor
76  Vector(const Vector &);
77 
78  /// Construct vector from 3D vector
79  template <class T> Vector(const Vector3D<T> &);
80 
81  /// Construct vector from 4D vector
82  template <class T> Vector(const Vector4D<T> &);
83 
84  /// Destructor
85  ~Vector();
86 
87  /// Intialize matrix with number of rows
88  void Initialize(int);
89 
90  /// Intialize matrix with number of rows
91  void Initialize(int, double);
92 
93  /// Intialize matrix with number of rows
94  void Initialize(int, double *);
95 
96  /// Change size of vector, preserving existing rows
97  void Resize(int, double = .0);
98 
99  /// Free vector
100  void Clear();
101 
102  /// Initialize from 3D vector
103  template <class T> Vector &Put(const Vector3D<T> &);
104 
105  /// Initialize from 4D vector
106  template <class T> Vector &Put(const Vector4D<T> &);
107 
108  /// Whether vector is non-empty, i.e., initialized and number of rows greater zero
109  operator bool() const;
110 
111  // ---------------------------------------------------------------------------
112  // Vector access functions
113 
114  /// Returns number of rows
115  int Rows() const;
116 
117  /// Puts vector value
118  void Put(int, double);
119 
120  /// Gets vector value
121  const double &Get(int) const;
122 
123  // ---------------------------------------------------------------------------
124  // Element access
125 
126  /// Get pointer to linear memory which stores vector elements
127  double *RawPointer(int r = 0);
128 
129  /// Get pointer to linear memory which stores vector elements
130  const double *RawPointer(int r = 0) const;
131 
132  /// Puts vector value
133  double &operator()(int);
134 
135  /// Gets vector value
136  const double &operator()(int) const;
137 
138  // ---------------------------------------------------------------------------
139  // Vector/scalar operations
140 
141  /// Assignment of double
142  Vector &operator =(double);
143 
144  /// Subtraction of a double
145  Vector &operator-=(double);
146 
147  /// Addition of a double
148  Vector &operator+=(double);
149 
150  /// Multiplication with a double
151  Vector &operator*=(double);
152 
153  /// Division by a double
154  Vector &operator/=(double);
155 
156  /// Return result of subtraction of a double
157  Vector operator- (double) const;
158 
159  /// Return result of addition of a double
160  Vector operator+ (double) const;
161 
162  /// Return result of multiplication with a double
163  Vector operator* (double) const;
164 
165  /// Return result of division by a double
166  Vector operator/ (double) const;
167 
168  // ---------------------------------------------------------------------------
169  // Element-wise vector/vector operations
170 
171  /// Unary negation operator
172  Vector operator -() const;
173 
174  /// Vector copy operator
175  Vector &operator =(const Vector &);
176 
177  /// Vector subtraction operator
178  Vector &operator-=(const Vector &);
179 
180  /// Vector addition operator
181  Vector &operator+=(const Vector &);
182 
183  /// Vector componentwise multiplication operator (no scalar nor cross product)
184  Vector &operator*=(const Vector &);
185 
186  /// Vector componentwise division operator
187  Vector &operator/=(const Vector &);
188 
189  /// Return result for vector subtraction
190  Vector operator- (const Vector &) const;
191 
192  /// Return result for vector addition
193  Vector operator+ (const Vector &) const;
194 
195  /// Return result for componentwise vector multiplication (no scalar nor cross product)
196  Vector operator* (const Vector &) const;
197 
198  /// Return result for componentwise vector division
199  Vector operator/ (const Vector &) const;
200 
201  // ---------------------------------------------------------------------------
202  // Comparison
203 
204  /// Comparison operator ==
205  bool operator==(const Vector &) const;
206 
207  /// Comparison operator !=
208  bool operator!=(const Vector &) const;
209 
210  /// Comparison operator <
211  bool operator<(const Vector &) const;
212 
213  // ---------------------------------------------------------------------------
214  // Vector products
215 
216  /// Scalar/dot product
217  double ScalarProduct(const Vector &) const;
218 
219  /// Scalar/dot product
220  double DotProduct(const Vector &) const;
221 
222  /// Vector/cross product
223  Vector CrossProduct(const Vector &) const;
224 
225  // ---------------------------------------------------------------------------
226  // Other vector functions
227 
228  /// Returns sum of a vector components
229  double Sum() const;
230 
231  /// Compute mean value of vector components
232  double Mean() const;
233 
234  /// Returns norm of a vector
235  double Norm() const;
236 
237  /// Normalize vector
238  Vector &Normalize();
239 
240  /// Replace each vector element by its inverse
241  Vector &Inverse();
242 
243  /// Permute vector elements
244  void PermuteRows(Array<int>);
245 
246  /// Permute vector elements (cf. PermuteRows)
247  void Permute(const Array<int> &);
248 
249  // ---------------------------------------------------------------------------
250  // I/O
251 
252  /// Print vector
253  void Print(Indent = 0) const;
254 
255  /// Read vector from file
256  void Read(const char *);
257 
258  /// Write vector to file
259  void Write(const char *) const;
260 
261  /// Interface to output stream
262  friend ostream &operator<< (ostream &, const Vector &);
263 
264  /// Interface to input stream
265  friend istream &operator>> (istream &, Vector &);
266 
267  /// Interface to output stream
268  friend Cofstream &operator<< (Cofstream &, const Vector &);
269 
270  /// Interface to input stream
271  friend Cifstream &operator>> (Cifstream &, Vector &);
272 
273  /// Write vector to MAT-file
274  ///
275  /// \note Use only when MIRTK_Numerics_WITH_MATLAB is 1.
276  bool WriteMAT(const char *, const char * = "A") const;
277 
278 };
279 
280 
281 } // namespace mirtk
282 
283 #include "mirtk/Vector3D.h"
284 #include "mirtk/Vector4D.h"
285 
286 namespace mirtk {
287 
288 ////////////////////////////////////////////////////////////////////////////////
289 // Inline definitions
290 ////////////////////////////////////////////////////////////////////////////////
291 
292 // =============================================================================
293 // Construction/Destruction
294 // =============================================================================
295 
296 // -----------------------------------------------------------------------------
298 :
299  _rows (0),
300  _vector(NULL)
301 {
302 }
303 
304 // -----------------------------------------------------------------------------
305 inline Vector::Vector(int rows)
306 :
307  _rows (0),
308  _vector(NULL)
309 {
310  Initialize(rows);
311 }
312 
313 // -----------------------------------------------------------------------------
314 inline Vector::Vector(int rows, double s)
315 :
316  _rows (0),
317  _vector(NULL)
318 {
319  Initialize(rows, s);
320 }
321 
322 // -----------------------------------------------------------------------------
323 inline Vector::Vector(int rows, double *v)
324 :
325  _rows (0),
326  _vector(NULL)
327 {
328  Initialize(rows, v);
329 }
330 
331 // -----------------------------------------------------------------------------
332 inline Vector::Vector(const Vector& v)
333 :
334  Object(v),
335  _rows (0),
336  _vector(NULL)
337 {
338  Initialize(v._rows, v._vector);
339 }
340 
341 // -----------------------------------------------------------------------------
342 template <class T>
343 inline Vector::Vector(const Vector3D<T> &v)
344 {
345  _rows = 3;
346  _vector = new double[3];
347  _vector[0] = static_cast<double>(v._x);
348  _vector[1] = static_cast<double>(v._y);
349  _vector[2] = static_cast<double>(v._z);
350 }
351 
352 // -----------------------------------------------------------------------------
353 template <class T>
354 inline Vector::Vector(const Vector4D<T> &v)
355 {
356  _rows = 4;
357  _vector = new double[4];
358  _vector[0] = static_cast<double>(v._x);
359  _vector[1] = static_cast<double>(v._y);
360  _vector[2] = static_cast<double>(v._z);
361  _vector[3] = static_cast<double>(v._t);
362 }
363 
364 // -----------------------------------------------------------------------------
366 {
367  delete[] _vector;
368 }
369 
370 // -----------------------------------------------------------------------------
371 inline void Vector::Initialize(int rows)
372 {
373  if (_rows != rows) {
374  delete[] _vector;
375  _rows = rows;
376  _vector = (_rows > 0) ? new double[_rows] : NULL;
377  }
378  memset(_vector, 0, _rows * sizeof(double));
379 }
380 
381 // -----------------------------------------------------------------------------
382 inline void Vector::Initialize(int rows, double s)
383 {
384  if (_rows != rows) {
385  delete[] _vector;
386  _rows = rows;
387  _vector = (_rows > 0) ? new double[_rows] : NULL;
388  }
389  for (int i = 0; i < _rows; i++) _vector[i] = s;
390 }
391 
392 // -----------------------------------------------------------------------------
393 inline void Vector::Initialize(int rows, double *v)
394 {
395  if (_rows != rows) {
396  delete[] _vector;
397  _rows = rows;
398  _vector = (_rows > 0) ? new double[_rows] : NULL;
399  }
400  if (v) memcpy(_vector, v, _rows * sizeof(double));
401 }
402 
403 // -----------------------------------------------------------------------------
404 inline void Vector::Clear()
405 {
406  delete[] _vector;
407  _vector = NULL;
408  _rows = 0;
409 }
410 
411 // -----------------------------------------------------------------------------
412 inline void Vector::Resize(int n, double value)
413 {
414  if (n <= 0) {
415  Clear();
416  } else if (_rows != n) {
417  double *vector = new double[n];
418  const int m = min(n, _rows);
419  for (int i = 0; i < m; ++i) vector[i] = _vector[i];
420  for (int i = m; i < n; ++i) vector[i] = value;
421  delete[] _vector;
422  _vector = vector;
423  _rows = n;
424  }
425 }
426 
427 // -----------------------------------------------------------------------------
428 inline Vector::operator bool() const
429 {
430  return _rows != 0;
431 }
432 
433 // =============================================================================
434 // Access operators
435 // =============================================================================
436 
437 // -----------------------------------------------------------------------------
438 inline int Vector::Rows() const
439 {
440  return _rows;
441 }
442 
443 // -----------------------------------------------------------------------------
444 inline double *Vector::RawPointer(int r)
445 {
446  return &_vector[r];
447 }
448 
449 // -----------------------------------------------------------------------------
450 inline const double *Vector::RawPointer(int r) const
451 {
452  return &_vector[r];
453 }
454 
455 // -----------------------------------------------------------------------------
456 inline void Vector::Put(int rows, double vector)
457 {
458  _vector[rows] = vector;
459 }
460 
461 // -----------------------------------------------------------------------------
462 template <class T>
463 inline Vector &Vector::Put(const Vector3D<T> &v)
464 {
465  if (_rows != 3) {
466  delete[] _vector;
467  _rows = 3;
468  _vector = new double[3];
469  }
470  _vector[0] = static_cast<double>(v._x);
471  _vector[1] = static_cast<double>(v._y);
472  _vector[2] = static_cast<double>(v._z);
473  return *this;
474 }
475 
476 // -----------------------------------------------------------------------------
477 template <class T>
478 inline Vector &Vector::Put(const Vector4D<T> &v)
479 {
480  if (_rows != 4) {
481  delete[] _vector;
482  _rows = 4;
483  _vector = new double[4];
484  }
485  _vector[0] = static_cast<double>(v._x);
486  _vector[1] = static_cast<double>(v._y);
487  _vector[2] = static_cast<double>(v._z);
488  _vector[3] = static_cast<double>(v._t);
489  return *this;
490 }
491 
492 // -----------------------------------------------------------------------------
493 inline const double &Vector::Get(int rows) const
494 {
495  return _vector[rows];
496 }
497 
498 // -----------------------------------------------------------------------------
499 inline double &Vector::operator()(int rows)
500 {
501  return _vector[rows];
502 }
503 
504 // -----------------------------------------------------------------------------
505 inline const double &Vector::operator()(int rows) const
506 {
507  return _vector[rows];
508 }
509 
510 // =============================================================================
511 // Vector/scalar operations
512 // =============================================================================
513 
514 // -----------------------------------------------------------------------------
515 inline Vector &Vector::operator =(double x)
516 {
517  for (int i = 0; i < _rows; ++i) _vector[i] = x;
518  return *this;
519 }
520 
521 // -----------------------------------------------------------------------------
522 inline Vector &Vector::operator-=(double x)
523 {
524  for (int i = 0; i < _rows; ++i) _vector[i] -= x;
525  return *this;
526 }
527 
528 // -----------------------------------------------------------------------------
529 inline Vector &Vector::operator+=(double x)
530 {
531  for (int i = 0; i < _rows; ++i) _vector[i] += x;
532  return *this;
533 }
534 
535 // -----------------------------------------------------------------------------
536 inline Vector &Vector::operator*=(double x)
537 {
538  for (int i = 0; i < _rows; ++i) _vector[i] *= x;
539  return *this;
540 }
541 
542 // -----------------------------------------------------------------------------
543 inline Vector &Vector::operator/=(double x)
544 {
545  for (int i = 0; i < _rows; ++i) _vector[i] /= x;
546  return *this;
547 }
548 
549 // -----------------------------------------------------------------------------
550 inline Vector Vector::operator- (double x) const
551 {
552  return (Vector(*this) -= x);
553 }
554 
555 // -----------------------------------------------------------------------------
556 inline Vector Vector::operator+ (double x) const
557 {
558  return (Vector(*this) += x);
559 }
560 
561 // -----------------------------------------------------------------------------
562 inline Vector Vector::operator* (double x) const
563 {
564  return (Vector(*this) *= x);
565 }
566 
567 // -----------------------------------------------------------------------------
568 inline Vector Vector::operator/ (double x) const
569 {
570  return (Vector(*this) /= x);
571 }
572 
573 // -----------------------------------------------------------------------------
574 inline Vector operator- (double x, const Vector &v)
575 {
576  return v - x;
577 }
578 
579 // -----------------------------------------------------------------------------
580 inline Vector operator+ (double x, const Vector &v)
581 {
582  return v + x;
583 }
584 
585 // -----------------------------------------------------------------------------
586 inline Vector operator* (double x, const Vector &v)
587 {
588  return v * x;
589 }
590 
591 // =============================================================================
592 // Element-wise vector/vector operations
593 // =============================================================================
594 
595 // -----------------------------------------------------------------------------
597 {
598  Vector negative(_rows);
599  for (int i = 0; i < _rows; ++i) negative._vector[i] = -_vector[i];
600  return negative;
601 }
602 
603 // -----------------------------------------------------------------------------
605 {
606  Initialize(v._rows, v._vector);
607  return *this;
608 }
609 
610 // -----------------------------------------------------------------------------
612 {
613  if (_rows != v._rows) {
614  cerr << "Vector::operator-=: Size mismatch" << endl;
615  exit(1);
616  }
617  for (int i = 0; i < _rows; ++i) _vector[i] -= v._vector[i];
618  return *this;
619 }
620 
621 // -----------------------------------------------------------------------------
623 {
624  if (_rows != v._rows) {
625  cerr << "Vector::operator+=: Size mismatch" << endl;
626  exit(1);
627  }
628  for (int i = 0; i < _rows; ++i) _vector[i] += v._vector[i];
629  return *this;
630 }
631 
632 // -----------------------------------------------------------------------------
634 {
635  if (_rows != v._rows) {
636  cerr << "Vector::operator*=: Size mismatch" << endl;
637  exit(1);
638  }
639  for (int i = 0; i < _rows; ++i) _vector[i] *= v._vector[i];
640  return *this;
641 }
642 
643 // -----------------------------------------------------------------------------
645 {
646  if (_rows != v._rows) {
647  cerr << "Vector::operator/=: Size mismatch" << endl;
648  exit(1);
649  }
650  for (int i = 0; i < _rows; ++i) _vector[i] /= v._vector[i];
651  return *this;
652 }
653 
654 // -----------------------------------------------------------------------------
655 inline Vector Vector::operator- (const Vector &v) const
656 {
657  return (Vector(*this) -= v);
658 }
659 
660 // -----------------------------------------------------------------------------
661 inline Vector Vector::operator+ (const Vector &v) const
662 {
663  return (Vector(*this) += v);
664 }
665 
666 // -----------------------------------------------------------------------------
667 inline Vector Vector::operator* (const Vector &v) const
668 {
669  return (Vector(*this) *= v);
670 }
671 
672 // -----------------------------------------------------------------------------
673 inline Vector Vector::operator/ (const Vector& v) const
674 {
675  return (Vector(*this) /= v);
676 }
677 
678 // =============================================================================
679 // Comparison
680 // =============================================================================
681 
682 // -----------------------------------------------------------------------------
683 inline bool Vector::operator==(const Vector &v) const
684 {
685  if (_rows != v._rows) return false;
686  for (int i = 0; i < _rows; ++i) {
687  if (!fequal(_vector[i], v._vector[i])) return false;
688  }
689  return true;
690 }
691 
692 // -----------------------------------------------------------------------------
693 inline bool Vector::operator!=(const Vector &v) const
694 {
695  return !(*this == v);
696 }
697 
698 // -----------------------------------------------------------------------------
699 inline bool Vector::operator<(const Vector &v) const
700 {
701  if (_rows > v._rows) return false;
702  for (int i = 0; i < _rows; ++i) {
703  if (_vector[i] >= v._vector[i]) return false;
704  }
705  return true;
706 }
707 
708 // =============================================================================
709 // Vector products
710 // =============================================================================
711 
712 // -----------------------------------------------------------------------------
713 inline double Vector::ScalarProduct(const Vector &v) const
714 {
715  if (_rows != v._rows) {
716  cerr << "Vector::ScalarProduct: Size mismatch" << endl;
717  exit(1);
718  }
719  double s = .0;
720  for (int i = 0; i < _rows; ++i) {
721  s += _vector[i] * v._vector[i];
722  }
723  return s;
724 }
725 
726 // -----------------------------------------------------------------------------
727 inline double ScalarProduct(const Vector &a, const Vector &b)
728 {
729  return a.ScalarProduct(b);
730 }
731 
732 // -----------------------------------------------------------------------------
733 inline double Vector::DotProduct(const Vector &v) const
734 {
735  return ScalarProduct(v);
736 }
737 
738 // -----------------------------------------------------------------------------
739 inline double DotProduct(const Vector &a, const Vector &b)
740 {
741  return a.DotProduct(b);
742 }
743 
744 // -----------------------------------------------------------------------------
745 inline Vector Vector::CrossProduct(const Vector &v) const
746 {
747  if (_rows != v._rows) {
748  cerr << "Vector::CrossProduct: Size mismatch" << endl;
749  exit(1);
750  }
751  int a, b;
752  Vector c(_rows, (double*)NULL); // allocate without initialization
753  for (int i = 0; i < _rows; ++i) {
754  a = (i+1) % _rows;
755  b = (i+2) % _rows;
756  c._vector[i] = _vector[a] * v._vector[b] - _vector[b] * v._vector[a];
757  }
758  return c;
759 }
760 
761 // -----------------------------------------------------------------------------
762 inline Vector CrossProduct(const Vector &a, const Vector &b)
763 {
764  return a.CrossProduct(b);
765 }
766 
767 // =============================================================================
768 // Functions
769 // =============================================================================
770 
771 // -----------------------------------------------------------------------------
772 inline double Vector::Sum() const
773 {
774  double sum = .0;
775  for (int i = 0; i < _rows; i++) sum += _vector[i];
776  return sum;
777 }
778 
779 // -----------------------------------------------------------------------------
780 inline double Vector::Mean() const
781 {
782  return Sum() / _rows;
783 }
784 
785 // -----------------------------------------------------------------------------
786 inline double Vector::Norm() const
787 {
788  double norm = .0;
789  for (int i = 0; i < _rows; i++) norm += _vector[i] * _vector[i];
790  return sqrt(norm);
791 }
792 
793 // -----------------------------------------------------------------------------
795 {
796  double norm = Norm();
797  if (norm != .0) (*this) /= norm;
798  return *this;
799 }
800 
801 // -----------------------------------------------------------------------------
803 {
804  for (int i = 0; i < _rows; i++) {
805  if (_vector[i] != .0) _vector[i] = 1.0 / _vector[i];
806  }
807  return *this;
808 }
809 
810 // -----------------------------------------------------------------------------
811 inline void Vector::Permute(const Array<int> &idx)
812 {
813  PermuteRows(idx);
814 }
815 
816 
817 } // namespace mirtk
818 
819 #endif // MIRTK_Vector_H
double Mean() const
Compute mean value of vector components.
Definition: Vector.h:780
void Clear()
Free vector.
Definition: Vector.h:404
Vector operator/(double) const
Return result of division by a double.
Definition: Vector.h:568
bool operator!=(const Vector &) const
Comparison operator !=.
Definition: Vector.h:693
Vector & operator/=(double)
Division by a double.
Definition: Vector.h:543
Vector & Put(const Vector3D< T > &)
Initialize from 3D vector.
Definition: Vector.h:463
double Sum() const
Returns sum of a vector components.
Definition: Vector.h:772
void Print(Indent=0) const
Print vector.
const double & Get(int) const
Gets vector value.
Definition: Vector.h:493
Vector CrossProduct(const Vector &) const
Vector/cross product.
Definition: Vector.h:745
Vector & operator-=(double)
Subtraction of a double.
Definition: Vector.h:522
~Vector()
Destructor.
Definition: Vector.h:365
void Permute(const Array< int > &)
Permute vector elements (cf. PermuteRows)
Definition: Vector.h:811
bool operator==(const Vector &) const
Comparison operator ==.
Definition: Vector.h:683
void Write(const char *) const
Write vector to file.
Vector operator-() const
Unary negation operator.
Definition: Vector.h:596
T _z
The z component.
Definition: Vector4D.h:45
double * _vector
Vector elements.
Definition: Vector.h:56
bool WriteMAT(const char *, const char *="A") const
double * RawPointer(int r=0)
Get pointer to linear memory which stores vector elements.
Definition: Vector.h:444
void Read(const char *)
Read vector from file.
MIRTKCU_API bool fequal(double a, double b, double tol=1e-12)
Definition: Math.h:138
T _t
The t component.
Definition: Vector4D.h:46
int _rows
Number of rows.
Definition: Vector.h:53
Definition: IOConfig.h:41
Vector()
Default constructor.
Definition: Vector.h:297
int Rows() const
Returns number of rows.
Definition: Vector.h:438
double Norm() const
Returns norm of a vector.
Definition: Vector.h:786
double & operator()(int)
Puts vector value.
Definition: Vector.h:499
Vector & operator=(double)
Assignment of double.
Definition: Vector.h:515
Vector operator+(double) const
Return result of addition of a double.
Definition: Vector.h:556
friend ostream & operator<<(ostream &, const Vector &)
Interface to output stream.
T _x
The x component.
Definition: Vector4D.h:43
double DotProduct(const Vector &) const
Scalar/dot product.
Definition: Vector.h:733
Vector & operator*=(double)
Multiplication with a double.
Definition: Vector.h:536
double ScalarProduct(const Vector &) const
Scalar/dot product.
Definition: Vector.h:713
Vector & Normalize()
Normalize vector.
Definition: Vector.h:794
T _z
The z component.
Definition: Vector3D.h:60
Vector & Inverse()
Replace each vector element by its inverse.
Definition: Vector.h:802
T _y
The y component.
Definition: Vector3D.h:59
void PermuteRows(Array< int >)
Permute vector elements.
bool operator<(const Vector &) const
Comparison operator <.
Definition: Vector.h:699
T _x
The x component.
Definition: Vector3D.h:58
void Resize(int, double=.0)
Change size of vector, preserving existing rows.
Definition: Vector.h:412
T _y
The y component.
Definition: Vector4D.h:44
Vector operator*(double) const
Return result of multiplication with a double.
Definition: Vector.h:562
void Initialize(int)
Intialize matrix with number of rows.
Definition: Vector.h:371
friend istream & operator>>(istream &, Vector &)
Interface to input stream.
Vector & operator+=(double)
Addition of a double.
Definition: Vector.h:529