1 // This is core/vnl/vnl_c_na_vector.h 2 #ifndef vnl_c_na_vector_h_ 3 #define vnl_c_na_vector_h_ 4 //: 5 // \file 6 // \brief Math on blocks of memory 7 // 8 // NA aware vnl_c_vector-like interfaces to lowlevel memory-block operations. 9 // 10 // \author Andrew W. Fitzgibbon, Ian Scott 11 // \date 3 Nov 2010 12 // 13 // \verbatim 14 // Modifications 15 // \endverbatim 16 // 17 //----------------------------------------------------------------------------- 18 19 #include <iosfwd> 20 #include <cmath> 21 #ifdef _MSC_VER 22 # include <vcl_msvc_warnings.h> 23 #endif 24 #include <vnl/vnl_numeric_traits.h> 25 #include "vnl/vnl_export.h" 26 27 // avoid messing about with aux_* functions for gcc 2.7 -- fsm 28 template <class T, class S> VNL_EXPORT void vnl_c_na_vector_one_norm(T const *p, unsigned n, S *out); 29 template <class T, class S> VNL_EXPORT void vnl_c_na_vector_two_norm(T const *p, unsigned n, S *out); 30 template <class T, class S> VNL_EXPORT void vnl_c_na_vector_two_norm_squared(T const *p, unsigned n, S *out); 31 32 //: vnl_c_na_vector interfaces to NA-aware lowlevel memory-block operations. 33 template <class T> 34 class VNL_EXPORT vnl_c_na_vector 35 { 36 public: 37 typedef typename vnl_numeric_traits<T>::abs_t abs_t; 38 typedef typename vnl_numeric_traits<T>::real_t real_t; 39 40 static T sum(T const* v, unsigned n); squared_magnitude(T const * p,unsigned n)41 static inline abs_t squared_magnitude(T const *p, unsigned n) 42 { abs_t val; vnl_c_na_vector_two_norm_squared(p, n, &val); return val; } 43 44 static T mean(T const *p, unsigned n); 45 46 //: one_norm : sum of abs values one_norm(T const * p,unsigned n)47 static inline abs_t one_norm(T const *p, unsigned n) 48 { abs_t val; vnl_c_na_vector_one_norm(p, n, &val); return val; } 49 50 //: two_norm : sqrt of sum of squared abs values two_norm(T const * p,unsigned n)51 static inline abs_t two_norm(T const *p, unsigned n) 52 { abs_t val; vnl_c_na_vector_two_norm(p, n, &val); return val; } 53 54 //: two_nrm2 : sum of squared abs values two_nrm2(T const * p,unsigned n)55 static inline abs_t two_nrm2(T const *p, unsigned n) 56 { abs_t val; vnl_c_na_vector_two_norm_squared(p, n, &val); return val; } 57 }; 58 59 //: Input & output 60 // \relatesalso vnl_c_na_vector 61 template <class T> VNL_EXPORT 62 std::ostream& print_na_vector(std::ostream&, T const*, unsigned); 63 64 #endif // vnl_c_na_vector_h_ 65