vnl_vector_fixed_ref.h
Go to the documentation of this file.
1 // This is core/vnl/vnl_vector_fixed_ref.h
2 #ifndef vnl_vector_fixed_ref_h_
3 #define vnl_vector_fixed_ref_h_
4 //:
5 // \file
6 // \brief Fixed size vnl_vector using user-supplied storage
7 // See vnl_matrix_fixed_ref for rationale.
8 // See also vnl_vector_ref, vnl_vector_fixed
9 //
10 // \author Paul P. Smyth, Vicon Motion Systems Ltd.
11 // \date 02 May 2001
12 //
13 // \verbatim
14 // Modifications
15 // 4-Jul-2003 - Paul Smyth - general cleanup and rewrite; interface now as vnl_vector_fixed
16 // 30-Mar-2009 - Peter Vanroose - added arg_min() and arg_max()
17 // 24-Oct-2010 - Peter Vanroose - mutators and setters now return *this
18 // \endverbatim
19 
20 #include <iosfwd>
21 #include <cassert>
22 #include <vnl/vnl_vector_fixed.h>
23 #ifdef _MSC_VER
24 # include <vcl_msvc_warnings.h>
25 #endif
26 #include "vnl/vnl_export.h"
27 
28 template <class T, unsigned int n>
29 class VNL_EXPORT vnl_vector_fixed_ref_const
30 {
31  protected:
32  const T* data_;
33 
34  public:
35  typedef size_t size_type;
36 
37  vnl_vector_fixed_ref_const(vnl_vector_fixed<T,n> const& rhs) : data_(rhs.data_block()) {}
38 
39  explicit vnl_vector_fixed_ref_const(const T * dataptr) : data_(dataptr) {}
40 
41  vnl_vector_fixed_ref_const(const vnl_vector_fixed_ref_const<T,n> & rhs) : data_(rhs.data_block()) {}
42 
43  const T * data_block() const { return data_; }
44 
45  // Don't out-of-line the constructors, as the extra function call
46  // adds a significant overhead. (memcpy is often implemented with a
47  // couple of assembly instructions.)
48 
49 
50  //: Length of the vector.
51  // This is always \a n.
52  unsigned size() const { return n; }
53 
54  //: Get value at element i
55  T get (unsigned int i) const { return data_[i]; }
56 
57  //: Copy elements to ptr[i]
58  // Note: ptr[i] must be valid for i=0..size()-1
59  void copy_out( T* ptr ) const {
60  for ( size_type i = 0; i < n; ++i )
61  ptr[i] = data_[i];
62  }
63 
64 
65  //: Return reference to the element at specified index.
66  // There are assert style boundary checks - #define NDEBUG to turn them off.
67  T const & operator() (unsigned int i) const
68  {
69 #if VNL_CONFIG_CHECK_BOUNDS && (!defined NDEBUG)
70  assert(i<n); // Check the index is valid
71 #endif
72  return data_[i];
73  }
74 
75 
76  //: Return the i-th element
77  const T& operator[] ( unsigned int i ) const { return data_[i]; }
78 
79 
80  //----------------------------------------------------------------------
81  // Conversion to vnl_vector_ref.
82 
83  // The const version of as_ref should return a const vnl_vector_ref
84  // so that the vnl_vector_ref::non_const() cannot be used on
85  // it. This prevents a vnl_vector_fixed_ref_const from being cast into a
86  // non-const vnl_vector reference, giving a slight increase in type safety.
87 
88  //: Explicit conversion to a vnl_vector_ref.
89  // This is a cheap conversion for those functions that have an interface
90  // for vnl_vector_ref but not for vnl_vector_fixed_ref. There is also a
91  // conversion operator that should work most of the time.
92  // \sa vnl_vector_ref::non_const
93  const vnl_vector_ref<T> as_ref() const { return vnl_vector_ref<T>( n, const_cast<T*>(data_) ); }
94 
95  //: Cheap conversion to vnl_vector_ref
96  // Sometimes, such as with templated functions, the compiler cannot
97  // use this user-defined conversion. For those cases, use the
98  // explicit as_ref() method instead.
99  operator const vnl_vector_ref<T>() const { return vnl_vector_ref<T>( n, const_cast<T*>(data_) ); }
100 
101  //----------------------------------------------------------------------
102 
103  //: Type defs for iterators
104  typedef T element_type;
105  //: Type defs for iterators
106  typedef T const *iterator;
107 
108  //: Const iterator type
109  typedef T const *const_iterator;
110  //: Iterator pointing to start of data
111  const_iterator begin() const { return data_; }
112  //: Iterator pointing to element beyond end of data
113  const_iterator end() const { return data_+n; }
114 
115 
116  //: Apply f to each element.
117  // Returns a new vector with the result.
118  vnl_vector_fixed<T,n> apply(T (*f)(T)) const;
119 
120  //: Apply f to each element.
121  // Returns a new vector with the result.
122  vnl_vector_fixed<T,n> apply(T (*f)(const T&)) const;
123 
124  //:
126  vnl_vector_fixed<T,n> result;
127  sub( (T)0, data_, result.data_block() );
128  return result;
129  }
130 
131  //: Returns a subvector specified by the start index and length. O(n).
132  vnl_vector<T> extract (unsigned int len, unsigned int start=0) const;
133 
134  //: Convert to a vnl_vector.
135  vnl_vector<T> as_vector() const { return extract(n); }
136 
137 
138  // norms etc
139  typedef typename vnl_c_vector<T>::abs_t abs_t;
140 
141  //: Return sum of squares of elements
142  abs_t squared_magnitude() const { return vnl_c_vector<T>::two_nrm2(begin(), n); }
143 
144  //: Return magnitude (length) of vector
145  abs_t magnitude() const { return two_norm(); }
146 
147  //: Return sum of absolute values of the elements
148  abs_t one_norm() const { return vnl_c_vector<T>::one_norm(begin(), n); }
149 
150  //: Return sqrt of sum of squares of values of elements
151  abs_t two_norm() const { return vnl_c_vector<T>::two_norm(begin(), n); }
152 
153  //: Return largest absolute element value
154  abs_t inf_norm() const { return vnl_c_vector<T>::inf_norm(begin(), n); }
155 
156 
157  // These next 6 functions are should really be helper functions since they aren't
158  // really proper functions on a vector in a philosophical sense.
159 
160  //: Root Mean Squares of values
161  abs_t rms () const { return vnl_c_vector<T>::rms_norm(begin(), n); }
162 
163  //: Smallest value
164  T min_value () const { return vnl_c_vector<T>::min_value(begin(), n); }
165 
166  //: Largest value
167  T max_value () const { return vnl_c_vector<T>::max_value(begin(), n); }
168 
169  //: Location of smallest value
170  unsigned arg_min() const { return vnl_c_vector<T>::arg_min(begin(), n); }
171 
172  //: Location of largest value
173  unsigned arg_max() const { return vnl_c_vector<T>::arg_max(begin(), n); }
174 
175  //: Mean of values in vector
176  T mean() const { return vnl_c_vector<T>::mean(begin(), n); }
177 
178  //: Sum of values in a vector
179  T sum() const { return vnl_c_vector<T>::sum(begin(), n); }
180 
181 
182  //: Check that size()==sz if not, abort();
183  // This function does or tests nothing if NDEBUG is defined
184 #if !defined(NDEBUG)
185  void assert_size( unsigned sz ) const { assert( sz == n ); }
186 #else
187  void assert_size( unsigned /* sz */ ) const { }
188 #endif
189 
190  //: Check that this is finite if not, abort();
191  // This function does or tests nothing if NDEBUG is defined
192  void assert_finite() const {
193 #ifndef NDEBUG
194  assert_finite_internal();
195 #endif
196  }
197 
198  //: Return true if it's finite
199  bool is_finite() const;
200 
201  //: Return true iff all the entries are zero.
202  bool is_zero() const;
203 
204  //: Return true iff the size is zero.
205  bool empty() const { return n==0; }
206 
207  //: Return true if *this == v
209  for ( size_type i = 0; i < n; ++i )
210  if ( (*this)[i] != v[i] )
211  return false;
212  return true;
213  }
214 
215  //: Return true if *this == v
216  bool operator_eq (vnl_vector<T> const& v) const {
217  assert( v.size() == n );
218  for ( size_type i = 0; i < n; ++i )
219  if ( (*this)[i] != v[i] )
220  return false;
221  return true;
222  }
223 
224 
225  //: Display the vector
226  // Output each element separated by a single space.
227  void print( std::ostream& s ) const;
228 
229  public:
230  // Helper routines for arithmetic. n is the size, and is the
231  // template parameter.
232 
233  inline static void add( const T* a, const T* b, T* r ) {
234  for ( unsigned int i=0; i < n; ++i,++r,++a,++b )
235  *r = *a + *b;
236  }
237 
238  inline static void add( const T* a, T b, T* r ) {
239  for ( unsigned int i=0; i < n; ++i,++r,++a )
240  *r = *a + b;
241  }
242 
243  inline static void sub( const T* a, const T* b, T* r ) {
244  for ( unsigned int i=0; i < n; ++i,++r,++a,++b )
245  *r = *a - *b;
246  }
247 
248  inline static void sub( const T* a, T b, T* r ) {
249  for ( unsigned int i=0; i < n; ++i,++r,++a )
250  *r = *a - b;
251  }
252 
253  inline static void sub( T a, const T* b, T* r ) {
254  for ( unsigned int i=0; i < n; ++i,++r,++b )
255  *r = a - *b;
256  }
257 
258  inline static void mul( const T* a, const T* b, T* r ) {
259  for ( unsigned int i=0; i < n; ++i,++r,++a,++b )
260  *r = *a * *b;
261  }
262 
263  inline static void mul( const T* a, T b, T* r ) {
264  for ( unsigned int i=0; i < n; ++i,++r,++a )
265  *r = *a * b;
266  }
267 
268  inline static void div( const T* a, const T* b, T* r ) {
269  for ( unsigned int i=0; i < n; ++i,++r,++a,++b )
270  *r = *a / *b;
271  }
272 
273  inline static void div( const T* a, T b, T* r ) {
274  for ( unsigned int i=0; i < n; ++i,++r,++a )
275  *r = *a / b;
276  }
277 
278 
279  //: Equality operator
280  bool operator==(vnl_vector_fixed_ref_const<T,n> const &that) const { return this->operator_eq(that); }
281 
282  //: Inequality operator
283  bool operator!=(vnl_vector_fixed_ref_const<T,n> const &that) const { return !this->operator_eq(that); }
284 
285  private:
286  //: See assert_finite().
288  {
289  assert(!"Assignment is illegal for a vnl_vector_fixed_ref_const");
290  return *this;
291  }
293  {
294  assert(!"Assignment is illegal for a vnl_vector_fixed_ref_const");
295  return *this;
296  }
297  void assert_finite_internal() const;
298 };
299 
300 // Non const vector fixed reference
301 
302 template <class T, unsigned n>
303 class VNL_EXPORT vnl_vector_fixed_ref : public vnl_vector_fixed_ref_const<T,n>
304 {
306 
307  public:
308  typedef unsigned int size_type;
309 
310  // this is the only point where the const_cast happens
311  // the base class is used to store the pointer, so that conversion is not necessary
312  T * data_block() const { return const_cast<T*>(this->data_); }
313 
314  vnl_vector_fixed_ref(vnl_vector_fixed<T,n>& rhs) : base(rhs.data_block()) {}
315 
316  explicit vnl_vector_fixed_ref(T * dataptr) : base(dataptr) {}
317 
318  //: Copy operator
320  std::memcpy( data_block(), rhs.data_block(), n * sizeof(T) );
321  return *this;
322  }
323 
324  //: Copy operator
326  std::memcpy( data_block(), rhs.data_block(), n * sizeof(T) );
327  return *this;
328  }
329 
330  //: Copy operator
332  std::memcpy( data_block(), rhs.data_block(), n * sizeof(T) );
333  return *this;
334  }
335 
336 
337  //: Put value at given position in vector.
338  void put (unsigned int i, T const& v) const { data_block()[i] = v; }
339 
340  //: Set all values to v
342  {
343  for ( size_type i = 0; i < n; ++i ) data_block()[i] = v;
344  return *this;
345  }
346 
347  //: Sets elements to ptr[i]
348  // Note: ptr[i] must be valid for i=0..size()-1
349  vnl_vector_fixed_ref const& copy_in( T const * ptr ) const
350  {
351  for ( size_type i = 0; i < n; ++i ) data_block()[i] = ptr[i];
352  return *this;
353  }
354 
355  //: Sets elements to ptr[i]
356  // Note: ptr[i] must be valid for i=0..size()-1
357  vnl_vector_fixed_ref const& set( T const *ptr ) const { copy_in(ptr); return *this; }
358 
359  //: Return reference to the element at specified index.
360  // There are assert style boundary checks - #define NDEBUG to turn them off.
361  T & operator() (unsigned int i) const
362  {
363 #if VNL_CONFIG_CHECK_BOUNDS && (!defined NDEBUG)
364  assert(i<n); // Check the index is valid.
365 #endif
366  return data_block()[i];
367  }
368 
369  //: Return the i-th element
370  T& operator[] ( unsigned int i ) const { return data_block()[i]; }
371 
372  // \sa vnl_vector_ref::non_const
374 
375  typedef T *iterator;
376  //: Iterator pointing to start of data
377  iterator begin() const { return data_block(); }
378 
379  //: Iterator pointing to element beyond end of data
380  iterator end() const { return begin()+n; }
381 
382  //: Replaces elements with index beginning at start, by values of v. O(n).
383  vnl_vector_fixed_ref const& update (vnl_vector<T> const&, unsigned int start=0) const;
384 
385  //: Read from text stream
386  bool read_ascii(std::istream& s) const;
387 
388  vnl_vector_fixed_ref const& flip() const;
389 
390  //:
391  vnl_vector_fixed_ref<T,n> const & operator+=( T s ) const {
392  base::add( data_block(), s, data_block() ); return *this;
393  }
394 
395  //:
396  vnl_vector_fixed_ref<T,n> const & operator-=( T s ) const {
397  base::sub( data_block(), s, data_block() ); return *this;
398  }
399 
400  //:
401  vnl_vector_fixed_ref<T,n> const & operator*=( T s ) const {
402  base::mul( data_block(), s, data_block() ); return *this;
403  }
404 
405  //:
406  vnl_vector_fixed_ref<T,n> const & operator/=( T s ) const {
407  base::div( data_block(), s, data_block() ); return *this;
408  }
409 
410  //:
412  base::add( data_block(), v.data_block(), data_block() ); return *this;
413  }
414 
415  //:
417  base::sub( data_block(), v.data_block(), data_block() ); return *this;
418  }
419 
420  //:
422  assert( v.size() == n );
423  base::add( data_block(), v.data_block(), data_block() ); return *this;
424  }
425 
426  //:
428  assert( v.size() == n );
429  base::sub( data_block(), v.data_block(), data_block() ); return *this;
430  }
431 };
432 
433 
434 // Make the operators below inline because (1) they are small and
435 // (2) we then have less explicit instantiation trouble.
436 
437 
438 // --- Vector-scalar operators ----------------------------------------
439 
440 
441 //: \relatesalso vnl_vector_fixed
442 template<class T, unsigned int n>
444 {
446  vnl_vector_fixed<T,n>::add( v.data_block(), s, r.data_block() );
447  return r;
448 }
449 
450 //: \relatesalso vnl_vector_fixed
451 template<class T, unsigned int n>
453 {
455  vnl_vector_fixed<T,n>::add( v.data_block(), s, r.data_block() );
456  return r;
457 }
458 
459 //: \relatesalso vnl_vector_fixed
460 template<class T, unsigned int n>
462 {
464  vnl_vector_fixed<T,n>::sub( v.data_block(), s, r.data_block() );
465  return r;
466 }
467 
468 //: \relatesalso vnl_vector_fixed
469 template<class T, unsigned int n>
471 {
473  vnl_vector_fixed<T,n>::sub( s, v.data_block(), r.data_block() );
474  return r;
475 }
476 
477 //: \relatesalso vnl_vector_fixed
478 template<class T, unsigned int n>
480 {
482  vnl_vector_fixed<T,n>::mul( v.data_block(), s, r.data_block() );
483  return r;
484 }
485 
486 //: \relatesalso vnl_vector_fixed
487 template<class T, unsigned int n>
489 {
491  vnl_vector_fixed<T,n>::mul( v.data_block(), s, r.data_block() );
492  return r;
493 }
494 
495 //: \relatesalso vnl_vector_fixed
496 template<class T, unsigned int n>
498 {
500  vnl_vector_fixed<T,n>::div( v.data_block(), s, r.data_block() );
501  return r;
502 }
503 
504 
505 // --- Vector-vector operators ----------------------------------------
506 
507 
508 //: \relatesalso vnl_vector_fixed
509 template<class T, unsigned int n>
511 {
514  return r;
515 }
516 
517 //: \relatesalso vnl_vector_fixed
518 template<class T, unsigned int n>
520 {
523  return r;
524 }
525 
526 template<class T, unsigned int n>
528 {
531  return r;
532 }
533 
534 template<class T, unsigned int n>
536 {
539  return r;
540 }
541 
542 template<class T>
544 {
545  vnl_vector_fixed<T,3> result;
546 
547  result[0] = v1[1] * v2[2] - v1[2] * v2[1];
548  result[1] = v1[2] * v2[0] - v1[0] * v2[2];
549  result[2] = v1[0] * v2[1] - v1[1] * v2[0];
550  return result;
551 }
552 
553 // These overloads for the common case of mixing a fixed with a
554 // non-fixed. Because the operator* are templated, the fixed will not
555 // be automatically converted to a non-fixed-ref. These do it for you.
556 
557 template<class T, unsigned int n>
559 {
560  return a.as_ref() + b;
561 }
562 
563 template<class T, unsigned int n>
565 {
566  return a + b.as_ref();
567 }
568 
569 template<class T, unsigned int n>
571 {
572  return a.as_ref() - b;
573 }
574 
575 template<class T, unsigned int n>
577 {
578  return a - b.as_ref();
579 }
580 
581 
582 template<class T, unsigned n>
584 {
585  return dot_product( a.as_ref(), b.as_ref() );
586 }
587 
588 template<class T, unsigned n>
590 {
591  return dot_product( a.as_ref(), b );
592 }
593 
594 template<class T, unsigned n>
596 {
597  return dot_product( a, b.as_ref() );
598 }
599 
600 template<class T, unsigned int m, unsigned int n>
602 {
603  vnl_matrix_fixed<T,m,n> out; // = a.column() * b.row()
604  for (unsigned int i = 0; i < m; i++)
605  for (unsigned int j = 0; j < n; j++)
606  out[i][j] = a[i] * b[j];
607  return out;
608 }
609 
610 template<class T,unsigned int n>
612  return vnl_cross_3d( a.as_ref(), b);
613 }
614 
615 template<class T,unsigned int n>
617  return vnl_cross_3d( a, b.as_ref());
618 }
619 
620 template<class T, unsigned int n>
622 {
623  return outer_product( a, b.as_ref());
624 }
625 
626 template<class T, unsigned int n>
628 {
629  return outer_product( a.as_ref(), b);
630 }
631 
632 template<class T, unsigned n>
634 {
635  return angle( a.as_ref(), b.as_ref() );
636 }
637 
638 template<class T, unsigned n>
640 {
641  return angle( a.as_ref(), b );
642 }
643 
644 template<class T, unsigned n>
646 {
647  return angle( a, b.as_ref() );
648 }
649 
650 
651 template<class T, unsigned n>
653 {
654  return vnl_vector_ssd( a.as_ref(), b.as_ref() );
655 }
656 
657 template<class T, unsigned n>
659 {
660  return vnl_vector_ssd( a.as_ref(), b );
661 }
662 
663 template<class T, unsigned n>
665 {
666  return vnl_vector_ssd( a, b.as_ref() );
667 }
668 
669 
670 // --- I/O operators -------------------------------------------------
671 
672 
673 //: \relatesalso vnl_vector_fixed
674 template<class T, unsigned int n>
675 inline
676 std::ostream& operator<<(std::ostream& o,const vnl_vector_fixed_ref_const<T,n>& v)
677 {
678  v.print(o);
679  return o;
680 }
681 
682 //: \relatesalso vnl_vector_fixed
683 template<class T, unsigned int n>
684 inline
685 std::istream& operator>>(std::istream& i, const vnl_vector_fixed_ref<T,n>& v)
686 {
687  v.read_ascii(i);
688  return i;
689 }
690 
691 
692 #endif // vnl_vector_fixed_ref_h_
const vnl_vector_fixed_ref_const< T, n > & operator=(const vnl_vector_fixed_ref_const< T, n > &) const
static void sub(T a, const T *b, T *r)
static void mul(const T *a, const T *b, T *r)
const_iterator begin() const
Iterator pointing to start of data.
vnl_vector_fixed< T, n > element_quotient(const vnl_vector_fixed< T, n > &a, const vnl_vector_fixed< T, n > &b)
vnl_vector_fixed_ref_const< T, n > base
iterator end() const
Iterator pointing to element beyond end of data.
vnl_bignum operator+(vnl_bignum const &r1, long r2)
Returns the sum of two bignum numbers.
Definition: vnl_bignum.h:279
T get(unsigned int i) const
Get value at element i.
vnl_vector_fixed_ref< T, n > const & operator+=(const vnl_vector_fixed< T, n > &v) const
T vnl_vector_ssd(vnl_vector< T > const &v1, vnl_vector< T > const &v2)
Euclidean Distance between two vectors.
Definition: vnl_vector.h:480
vnl_vector< T > as_vector() const
Convert to a vnl_vector.
T max_value() const
Largest value.
vnl_vector_fixed< T, n > operator-() const
vnl_vector_fixed_ref< T, n > const & operator-=(T s) const
static unsigned arg_min(T const *, unsigned)
Returns location of min value of the vector.
void assert_finite() const
Check that this is finite if not, abort();.
vnl_vector_ref< T > as_ref()
vnl_vector using user-supplied storage.
Definition: vnl_fwd.h:17
abs_t inf_norm() const
Return largest absolute element value.
vnl_vector_fixed_ref< T, n > const & operator=(const vnl_vector_fixed_ref_const< T, n > &rhs) const
Copy operator.
vnl_vector_fixed_ref< T, n > const & operator/=(T s) const
vnl_vector_fixed_ref< T, n > const & operator+=(const vnl_vector< T > &v) const
static T sum(T const *v, unsigned n)
#define m
Definition: vnl_vector.h:43
vnl_vector_fixed_ref< T, n > const & operator=(const vnl_vector_fixed< T, n > &rhs) const
Copy operator.
vnl_vector_fixed< T, n > element_product(const vnl_vector_fixed< T, n > &a, const vnl_vector_fixed< T, n > &b)
static void add(const T *a, const T *b, T *r)
static abs_t rms_norm(T const *p, unsigned n)
rms_norm : sqrt of mean sum of squared abs values.
Definition: vnl_c_vector.h:136
iterator begin() const
Iterator pointing to start of data.
void add(const vnl_bignum &b1, const vnl_bignum &b2, vnl_bignum &sum)
add two non-infinite vnl_bignum values and save their sum.
Definition: vnl_bignum.cxx:887
static void div(const T *a, const T *b, T *r)
Fixed size, stack-stored, space-efficient matrix.
Definition: vnl_fwd.h:23
T const & operator()(unsigned int i) const
Return reference to the element at specified index.
bool operator==(vnl_vector_fixed_ref_const< T, n > const &that) const
Equality operator.
T const * const_iterator
Const iterator type.
vnl_vector_fixed_ref(vnl_vector_fixed< T, n > &rhs)
vnl_c_vector< T >::abs_t abs_t
T const * iterator
Type defs for iterators.
const T & operator[](unsigned int i) const
Return the i-th element.
vnl_vector_fixed_ref const & copy_in(T const *ptr) const
Sets elements to ptr[i].
static abs_t one_norm(T const *p, unsigned n)
one_norm : sum of abs values.
Definition: vnl_c_vector.h:120
static abs_t two_norm(T const *p, unsigned n)
two_norm : sqrt of sum of squared abs values.
Definition: vnl_c_vector.h:124
vnl_vector_fixed_ref< T, n > const & operator+=(T s) const
static void sub(const T *a, const T *b, T *r)
std::ostream & operator<<(std::ostream &s, vnl_decnum const &r)
decimal output.
Definition: vnl_decnum.h:393
#define v
Definition: vnl_vector.h:42
static void add(const T *a, T b, T *r)
const_iterator end() const
Iterator pointing to element beyond end of data.
void put(unsigned int i, T const &v) const
Put value at given position in vector.
static unsigned arg_max(T const *, unsigned)
Returns location of max value of the vector.
static T min_value(T const *, unsigned)
Returns min value of the vector.
An ordinary mathematical matrix.
Definition: vnl_adjugate.h:22
static T mean(T const *p, unsigned n)
Definition: vnl_c_vector.h:108
unsigned arg_min() const
Location of smallest value.
static void mul(const T *a, T b, T *r)
T const * data_block() const
Access the contiguous block storing the elements in the vector.
unsigned size() const
Length of the vector.
T min_value() const
Smallest value.
vnl_vector_fixed_ref_const(vnl_vector_fixed< T, n > const &rhs)
T dot_product(const vnl_vector_fixed< T, n > &a, const vnl_vector_fixed< T, n > &b)
T mean() const
Mean of values in vector.
bool operator_eq(vnl_vector< T > const &v) const
Return true if *this == v.
vnl_numeric_traits< T >::abs_t abs_t
Definition: vnl_c_vector.h:42
Mathematical vector class, templated by type of element.
Definition: vnl_fwd.h:16
VNL_EXPORT vnl_matrix_fixed< T, m, n > outer_product(vnl_vector_fixed< T, m > const &a, vnl_vector_fixed< T, n > const &b)
bool operator!=(vnl_vector_fixed_ref_const< T, n > const &that) const
Inequality operator.
vnl_vector_fixed_ref< T, n > const & operator=(const vnl_vector_fixed_ref< T, n > &rhs) const
Copy operator.
Fixed length stack-stored, space-efficient vector.
Definition: vnl_fwd.h:22
Fixed length stack-stored vector.
abs_t one_norm() const
Return sum of absolute values of the elements.
abs_t rms() const
Root Mean Squares of values.
void assert_size(unsigned sz) const
Check that size()==sz if not, abort();.
vnl_vector_fixed_ref< T, n > const & operator-=(const vnl_vector< T > &v) const
vnl_vector_fixed_ref & fill(T const &v)
Set all values to v.
T angle(const vnl_vector_fixed< T, n > &a, const vnl_vector_fixed< T, n > &b)
VNL_EXPORT std::istream & operator>>(std::istream &s, vnl_decnum &r)
decimal input.
Definition: vnl_decnum.cxx:411
vnl_bignum operator-(vnl_bignum const &r1, vnl_bignum const &r2)
Returns the difference of two bignum numbers.
Definition: vnl_bignum.h:290
static T max_value(T const *, unsigned)
Returns max value of the vector.
abs_t squared_magnitude() const
Return sum of squares of elements.
vnl_vector_fixed_ref const & set(T const *ptr) const
Sets elements to ptr[i].
abs_t two_norm() const
Return sqrt of sum of squares of values of elements.
static void add(const T *a, const T *b, T *r)
vnl_vector_fixed_ref_const(const T *dataptr)
static void sub(const T *a, T b, T *r)
vnl_vector_fixed_ref< T, n > const & operator-=(const vnl_vector_fixed< T, n > &v) const
bool empty() const
Return true iff the size is zero.
bool operator_eq(vnl_vector_fixed_ref_const< T, n > const &v) const
Return true if *this == v.
T sum() const
Sum of values in a vector.
unsigned arg_max() const
Location of largest value.
vnl_bignum operator/(vnl_bignum const &r1, vnl_bignum const &r2)
Returns the division of two bignum numbers.
Definition: vnl_bignum.h:349
abs_t magnitude() const
Return magnitude (length) of vector.
vnl_vector_fixed_ref_const(const vnl_vector_fixed_ref_const< T, n > &rhs)
const vnl_vector_fixed_ref_const< T, n > & operator=(const vnl_vector_fixed< T, n > &) const
See assert_finite().
vnl_bignum operator *(vnl_bignum const &r1, vnl_bignum const &r2)
Returns the product of two bignum numbers.
Definition: vnl_bignum.h:302
static abs_t two_nrm2(T const *p, unsigned n)
two_nrm2 : sum of squared abs values.
Definition: vnl_c_vector.h:132
static void mul(const T *a, const T *b, T *r)
T element_type
Type defs for iterators.
static abs_t inf_norm(T const *p, unsigned n)
inf_norm : max of abs values.
Definition: vnl_c_vector.h:128
void copy_out(T *ptr) const
Copy elements to ptr[i].
static void sub(const T *a, const T *b, T *r)
const vnl_vector_ref< T > as_ref() const
Explicit conversion to a vnl_vector_ref.
vnl_vector< T > vnl_cross_3d(const vnl_vector< T > &v1, const vnl_vector< T > &v2)
Compute the 3-D cross product.
Definition: vnl_cross.h:65
static void div(const T *a, const T *b, T *r)
static void div(const T *a, T b, T *r)