Go to the documentation of this file.00001
00002 #ifndef vnl_vector_fixed_txx_
00003 #define vnl_vector_fixed_txx_
00004
00005
00006 #include "vnl_vector_fixed.h"
00007 #include "vnl_matrix_fixed.h"
00008
00009 #include <vcl_cassert.h>
00010 #include <vcl_algorithm.h>
00011 #include <vcl_iostream.h>
00012 #include <vcl_cstdlib.h>
00013 #include <vnl/vnl_math.h>
00014
00015 template<class T, unsigned int n>
00016 vnl_vector_fixed<T,n>
00017 vnl_vector_fixed<T,n>::apply( T (*f)(T) )
00018 {
00019 vnl_vector_fixed<T,n> ret;
00020 for ( size_type i = 0; i < n; ++i )
00021 ret[i] = f( data_[i] );
00022 return ret;
00023 }
00024
00025 template<class T, unsigned int n>
00026 vnl_vector_fixed<T,n>
00027 vnl_vector_fixed<T,n>::apply( T (*f)(const T&) )
00028 {
00029 vnl_vector_fixed<T,n> ret;
00030 for ( size_type i = 0; i < n; ++i )
00031 ret[i] = f( data_[i] );
00032 return ret;
00033 }
00034
00035
00036 template<class T, unsigned int n>
00037 vnl_vector<T>
00038 vnl_vector_fixed<T,n>::extract( unsigned int len, unsigned int start ) const
00039 {
00040 assert( start < n && start + len <= n );
00041 return vnl_vector<T>( data_ + start, len );
00042 }
00043
00044 template<class T, unsigned int n>
00045 vnl_vector_fixed<T,n>&
00046 vnl_vector_fixed<T,n>::update( const vnl_vector<T>& v, unsigned int start )
00047 {
00048 size_type stop = start + v.size();
00049 assert( stop <= n );
00050 for (size_type i = start; i < stop; i++)
00051 this->data_[i] = v[i-start];
00052 return *this;
00053 }
00054
00055 template <class T, unsigned int n>
00056 vnl_vector_fixed<T,n>&
00057 vnl_vector_fixed<T,n>::flip()
00058 {
00059 for ( unsigned int i=0; 2*i+1 < n; ++i )
00060 vcl_swap( data_[i], data_[n-1-i] );
00061 return *this;
00062 }
00063
00064 template <class T, unsigned int n>
00065 bool
00066 vnl_vector_fixed<T,n>::is_finite() const
00067 {
00068 for ( size_type i = 0; i < this->size(); ++i )
00069 if ( !vnl_math_isfinite( (*this)[i] ) )
00070 return false;
00071
00072 return true;
00073 }
00074
00075
00076 template <class T, unsigned int n>
00077 bool
00078 vnl_vector_fixed<T,n>::is_zero() const
00079 {
00080 T const zero(0);
00081 for ( size_type i = 0; i < this->size(); ++i )
00082 if ( !( (*this)[i] == zero) )
00083 return false;
00084
00085 return true;
00086 }
00087
00088
00089 template <class T, unsigned int n>
00090 bool
00091 vnl_vector_fixed<T,n>::read_ascii(vcl_istream& s)
00092 {
00093 for (unsigned i = 0; i < this->size(); ++i)
00094 s >> (*this)(i);
00095
00096 return s.good() || s.eof();
00097 }
00098
00099 template <class T, unsigned int n>
00100 void
00101 vnl_vector_fixed<T,n>::assert_finite_internal() const
00102 {
00103 if (this->is_finite())
00104 return;
00105
00106 vcl_cerr << __FILE__ ": *** NAN FEVER **\n" << *this;
00107 vcl_abort();
00108 }
00109
00110 template <class T, unsigned int n>
00111 void
00112 vnl_vector_fixed<T,n>::print(vcl_ostream& s) const
00113 {
00114 if (this->size() > 0)
00115 s << (*this)[0];
00116 for (size_type i=1; i < this->size(); ++i)
00117 s << ' ' << (*this)[i];
00118 }
00119
00120
00121
00122
00123
00124 #define VNL_VECTOR_FIXED_INSTANTIATE(T,n) \
00125 template class vnl_vector_fixed<T,n >
00126
00127 #endif // vnl_vector_fixed_txx_