00001
00002 #ifndef vnl_c_vector_h_
00003 #define vnl_c_vector_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <vcl_iosfwd.h>
00026 #include <vnl/vnl_numeric_traits.h>
00027 #include <vcl_cstddef.h>
00028 #include <vcl_cmath.h>
00029
00030
00031 template <class T, class S> void vnl_c_vector_one_norm(T const *p, unsigned n, S *out);
00032 template <class T, class S> void vnl_c_vector_two_norm(T const *p, unsigned n, S *out);
00033 template <class T, class S> void vnl_c_vector_inf_norm(T const *p, unsigned n, S *out);
00034 template <class T, class S> void vnl_c_vector_two_norm_squared(T const *p, unsigned n, S *out);
00035 template <class T, class S> void vnl_c_vector_rms_norm(T const *p, unsigned n, S *out);
00036
00037
00038 export template <class T>
00039 class vnl_c_vector
00040 {
00041 public:
00042 typedef typename vnl_numeric_traits<T>::abs_t abs_t;
00043 typedef typename vnl_numeric_traits<T>::real_t real_t;
00044
00045 static T sum(T const* v, unsigned n);
00046 static inline abs_t squared_magnitude(T const *p, unsigned n)
00047 { abs_t val; vnl_c_vector_two_norm_squared(p, n, &val); return val; }
00048 static void normalize(T *, unsigned n);
00049 static void apply(T const *, unsigned, T (*f)(T), T* v_out);
00050 static void apply(T const *, unsigned, T (*f)(T const&), T* v_out);
00051
00052
00053 static void copy (T const *x, T *y, unsigned);
00054
00055
00056 static void scale (T const *x, T *y, unsigned, T const &);
00057
00058
00059 static void add (T const *x, T const *y, T *z, unsigned);
00060
00061
00062 static void add (T const *x, T const& y, T *z, unsigned);
00063
00064
00065 static void subtract(T const *x, T const *y, T *z, unsigned);
00066
00067
00068 static void subtract(T const *x, T const& y, T *z, unsigned);
00069
00070
00071 static void multiply(T const *x, T const *y, T *z, unsigned);
00072
00073
00074 static void multiply(T const *x, T const& y, T *z, unsigned);
00075
00076
00077 static void divide (T const *x, T const *y, T *z, unsigned);
00078
00079
00080 static void divide (T const *x, T const& y, T *z, unsigned);
00081
00082
00083
00084 static void negate (T const *x, T *y, unsigned);
00085
00086
00087 static void invert (T const *x, T *y, unsigned);
00088
00089
00090 static void saxpy (T const &a, T const *x, T *y, unsigned);
00091
00092
00093 static void fill (T *x, unsigned, T const &v);
00094
00095
00096 static void reverse (T *x, unsigned);
00097 static T dot_product (T const *, T const *, unsigned);
00098
00099
00100 static T inner_product(T const *, T const *, unsigned);
00101 static void conjugate(T const *, T *, unsigned);
00102
00103 static T max_value(T const *, unsigned);
00104 static T min_value(T const *, unsigned);
00105 static unsigned arg_max(T const *, unsigned);
00106 static unsigned arg_min(T const *, unsigned);
00107
00108 static T mean(T const *p, unsigned n) { return T(sum(p,n)/abs_t(n)); }
00109
00110
00111
00112
00113 static inline real_t std(T const *p, unsigned n) {
00114 return vcl_sqrt(real_t(sum_sq_diff_means(p, n))/real_t(abs_t(n-1)));}
00115
00116
00117 static T sum_sq_diff_means(T const* v, unsigned n);
00118
00119
00120 static inline abs_t one_norm(T const *p, unsigned n)
00121 { abs_t val; vnl_c_vector_one_norm(p, n, &val); return val; }
00122
00123
00124 static inline abs_t two_norm(T const *p, unsigned n)
00125 { abs_t val; vnl_c_vector_two_norm(p, n, &val); return val; }
00126
00127
00128 static inline abs_t inf_norm(T const *p, unsigned n)
00129 { abs_t val; vnl_c_vector_inf_norm(p, n, &val); return val; }
00130
00131
00132 static inline abs_t two_nrm2(T const *p, unsigned n)
00133 { abs_t val; vnl_c_vector_two_norm_squared(p, n, &val); return val; }
00134
00135
00136 static inline abs_t rms_norm(T const *p, unsigned n)
00137 { abs_t val; vnl_c_vector_rms_norm(p, n, &val); return val; }
00138
00139
00140
00141 static T euclid_dist_sq(T const *, T const *, unsigned);
00142
00143
00144 static T** allocate_Tptr(vcl_size_t n);
00145 static T* allocate_T(vcl_size_t n);
00146 static void deallocate(T**, vcl_size_t n_when_allocated);
00147 static void deallocate(T*, vcl_size_t n_when_allocated);
00148 };
00149
00150
00151
00152 template <class T>
00153 vcl_ostream& print_vector(vcl_ostream&, T const*, unsigned);
00154
00155 #endif // vnl_c_vector_h_