2 #ifndef vnl_vector_fixed_h_ 3 #define vnl_vector_fixed_h_ 32 # include <vcl_msvc_warnings.h> 38 #include <vnl/vnl_config.h> 40 #include "vnl/vnl_export.h" 43 template <
class T,
unsigned int num_rows,
unsigned int num_cols>
class vnl_matrix_fixed;
86 template <
class T,
unsigned int n>
118 assert( n == rhs.
size() );
119 std::memcpy( data_, rhs.
data_block(),
sizeof data_ );
129 std::memcpy( data_, datablck,
sizeof data_ );
145 data_[0] = x0; data_[1] = x1;
160 data_[0] = x0; data_[1] = x1; data_[2] = x2;
173 data_[0] = x0; data_[1] = x1; data_[2] = x2; data_[3] = x3;
179 assert( n == rhs.
size() );
180 std::memcpy( data_, rhs.
data_block(),
sizeof data_ );
186 unsigned int size()
const {
return n; }
189 inline void put (
unsigned int i, T
const&
v)
191 #if VNL_CONFIG_CHECK_BOUNDS 192 if (i >= this->size())
199 T get(
unsigned int i)
const;
232 T & operator() (
unsigned int i);
236 T
const & operator() (
unsigned int i)
const;
240 T& operator[] (
const size_t i);
243 const T& operator[] (
const size_t i)
const;
248 T
const* data_block()
const;
332 assert(
v.size() == n );
333 self::add( data_,
v.data_block(), data_ );
return *
this;
339 assert(
v.size() == n );
340 self::sub( data_,
v.data_block(), data_ );
return *
this;
347 self::sub( (T)0, data_, result.
data_ );
354 assert( start < n && start + len <= n );
415 void assert_size(
unsigned sz )
const { assert( sz == n ); (void)sz; }
422 assert_finite_internal();
427 bool is_finite()
const;
430 bool is_zero()
const;
439 if ( (*
this)[i] !=
v[i] )
447 assert(
v.size() == n );
449 if ( (*
this)[i] !=
v[i] )
456 bool read_ascii(std::istream& s);
460 void print( std::ostream& s )
const;
466 inline static void add(
const T* a,
const T* b, T* r )
468 for (
unsigned int i=0; i < n; ++i,++r,++a,++b )
472 inline static void add(
const T* a, T b, T* r )
474 for (
unsigned int i=0; i < n; ++i,++r,++a )
478 inline static void sub(
const T* a,
const T* b, T* r )
480 for (
unsigned int i=0; i < n; ++i,++r,++a,++b )
484 inline static void sub(
const T* a, T b, T* r )
486 for (
unsigned int i=0; i < n; ++i,++r,++a )
490 inline static void sub( T a,
const T* b, T* r )
492 for (
unsigned int i=0; i < n; ++i,++r,++b )
496 inline static void mul(
const T* a,
const T* b, T* r )
498 for (
unsigned int i=0; i < n; ++i,++r,++a,++b )
502 inline static void mul(
const T* a, T b, T* r )
504 for (
unsigned int i=0; i < n; ++i,++r,++a )
508 inline static void div(
const T* a,
const T* b, T* r )
510 for (
unsigned int i=0; i < n; ++i,++r,++a,++b )
514 inline static void div(
const T* a, T b, T* r )
516 for (
unsigned int i=0; i < n; ++i,++r,++a )
522 void assert_finite_internal()
const;
530 template<
class T,
unsigned int n>
540 template<
class T,
unsigned int n>
551 template<
class T,
unsigned int n>
561 template<
class T,
unsigned int n>
572 template<
class T,
unsigned int n>
582 template<
class T,
unsigned int n>
593 template<
class T,
unsigned int n>
610 template<
class T,
unsigned int n>
621 template<
class T,
unsigned int n>
630 template<
class T,
unsigned int n>
638 template<
class T,
unsigned int n>
649 template<
class T,
unsigned int n>
658 template<
class T,
unsigned int n>
666 template<
class T,
unsigned int n>
677 template<
class T,
unsigned int n>
680 assert( b.
size() == n );
689 template<
class T,
unsigned int n>
692 assert( a.
size() == n );
700 template<
class T,
unsigned int n>
711 template<
class T,
unsigned int n>
714 assert( b.
size() == n );
723 template<
class T,
unsigned int n>
726 assert( a.
size() == n );
734 template<
class T,
unsigned n>
743 template<
class T,
unsigned n>
752 template<
class T,
unsigned n>
761 template<
class T,
unsigned int n>
770 template<
class T,
unsigned int n>
778 template<
class T,
unsigned n>
787 template<
class T,
unsigned n>
796 template<
class T,
unsigned n>
805 template<
class T,
unsigned n>
814 template<
class T,
unsigned n>
823 template<
class T,
unsigned n>
832 template<
class T,
unsigned int n>
841 template<
class T,
unsigned int n>
850 template<
class T,
unsigned int n>
858 template<
class T,
unsigned int n>
867 template<
class T,
unsigned int n>
876 template<
class T,
unsigned int n>
888 template<
class T,
unsigned int n>
898 template<
class T,
unsigned int n>
902 v.read_ascii( ostr );
906 #endif // vnl_vector_fixed_h_ static void mul(const T *a, const T *b, T *r)
vnl_vector_fixed< T, n > element_quotient(const vnl_vector_fixed< T, n > &a, const vnl_vector_fixed< T, n > &b)
abs_t magnitude() const
Return magnitude (length) of vector.
vnl_vector_fixed & copy_in(T const *ptr)
Sets elements to ptr[i].
vnl_bignum operator+(vnl_bignum const &r1, long r2)
Returns the sum of two bignum numbers.
const vnl_vector_ref< T > as_ref() const
Explicit conversion to a vnl_vector_ref.
void copy_out(T *ptr) const
Copy elements to ptr[i].
T vnl_vector_ssd(vnl_vector< T > const &v1, vnl_vector< T > const &v2)
Euclidean Distance between two vectors.
vnl_vector_fixed< T, n > & operator=(const vnl_vector< T > &rhs)
Copy data from a dynamic vector.
An ordinary mathematical matrix.
static void add(const T *a, T b, T *r)
static unsigned arg_min(T const *, unsigned)
Returns location of min value of the vector.
vnl_vector_fixed(const T &x0, const T &x1, const T &x2)
Convenience constructor for 3-D vectors.
vnl_vector using user-supplied storage
vnl_vector using user-supplied storage.
void assert_finite() const
Check that this is finite if not, abort();.
bool operator_eq(vnl_vector_fixed< T, n > const &v) const
Return true if *this == v.
T element_type
Type defs for iterators.
unsigned arg_min() const
Location of smallest value.
static T sum(T const *v, unsigned n)
vnl_vector_fixed< T, n > & operator-=(const vnl_vector< T > &v)
vnl_vector_fixed< T, n > element_product(const vnl_vector_fixed< T, n > &a, const vnl_vector_fixed< T, n > &b)
size_t size() const
Return the length, number of elements, dimension of this vector.
T const * data_block() const
Access the contiguous block storing the elements in the vector. O(1).
vnl_vector_fixed(const T &x0, const T &x1)
Convenience constructor for 2-D vectors.
static abs_t rms_norm(T const *p, unsigned n)
rms_norm : sqrt of mean sum of squared abs values.
unsigned int size() const
Length of the vector.
vnl_vector_fixed(const T *datablck)
Construct a fixed-n-vector initialized from datablck.
static void sub(const T *a, T b, T *r)
void add(const vnl_bignum &b1, const vnl_bignum &b2, vnl_bignum &sum)
add two non-infinite vnl_bignum values and save their sum.
vnl_vector_ref< T > as_ref()
Explicit conversion to a vnl_vector_ref.
Fixed size, stack-stored, space-efficient matrix.
vnl_vector_fixed & fill(T const &v)
Set all values to v.
static void sub(T a, const T *b, T *r)
const_iterator end() const
Iterator pointing to element beyond end of data.
T const * const_iterator
Const iterator type.
vnl_vector_fixed< T, n > & operator-=(const vnl_vector_fixed< T, n > &v)
static abs_t one_norm(T const *p, unsigned n)
one_norm : sum of abs values.
static abs_t two_norm(T const *p, unsigned n)
two_norm : sqrt of sum of squared abs values.
abs_t one_norm() const
Return sum of absolute values of the elements.
iterator end()
Iterator pointing to element beyond end of data.
std::ostream & operator<<(std::ostream &s, vnl_decnum const &r)
decimal output.
vnl_vector_fixed(const T &x0, const T &x1, const T &x2, const T &x3)
Convenience constructor for 4-D vectors.
vnl_vector_fixed< T, n > & operator-=(T s)
abs_t rms() const
Root Mean Squares of values.
void vnl_error_vector_dimension(char const *fcn, int l1, int l2)
Raise exception for invalid dimension.
vnl_vector_fixed(const T &v)
Constructs n-vector with all elements initialised to v.
abs_t squared_magnitude() const
Return sum of squares of elements.
T mean() const
Mean of values in vector.
bool operator==(int r1, vnl_finite_int< N > const &r2)
void assert_size(unsigned sz) const
Check that size()==sz if not, abort();.
T * iterator
Type defs for iterators.
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.
vnl_vector_fixed< T, n > & operator+=(const vnl_vector_fixed< T, n > &v)
T max_value() const
Largest value.
An ordinary mathematical matrix.
T min_value() const
Smallest value.
static T mean(T const *p, unsigned n)
vnl_vector_fixed< T, n > & operator+=(const vnl_vector< T > &v)
T const * data_block() const
Access the contiguous block storing the elements in the vector.
vnl_vector< T > extract(unsigned int len, unsigned int start=0) const
Returns a subvector specified by the start index and length. O(n).
T dot_product(const vnl_vector_fixed< T, n > &a, const vnl_vector_fixed< T, n > &b)
vnl_vector< T > as_vector() const
Convert to a vnl_vector.
vnl_numeric_traits< T >::abs_t abs_t
abs_t inf_norm() const
Return largest absolute element value.
Mathematical vector class, templated by type of element.
VNL_EXPORT vnl_matrix_fixed< T, m, n > outer_product(vnl_vector_fixed< T, m > const &a, vnl_vector_fixed< T, n > const &b)
vnl_c_vector< T >::abs_t abs_t
const_iterator begin() const
Iterator pointing to start of data.
Fixed length stack-stored, space-efficient vector.
vnl_vector_fixed & set(T const *ptr)
Sets elements to ptr[i].
static void normalize(T *, unsigned n)
iterator begin()
Iterator pointing to start of data.
static void mul(const T *a, T b, T *r)
vnl_vector_fixed< T, n > & operator+=(T s)
abs_t two_norm() const
Return sqrt of sum of squares of values of elements.
static void div(const T *a, T b, T *r)
T angle(const vnl_vector_fixed< T, n > &a, const vnl_vector_fixed< T, n > &b)
vnl_vector_fixed(const vnl_vector< T > &rhs)
Construct a fixed-n-vector copy of rhs.
VNL_EXPORT std::istream & operator>>(std::istream &s, vnl_decnum &r)
decimal input.
vnl_bignum operator-(vnl_bignum const &r1, vnl_bignum const &r2)
Returns the difference of two bignum numbers.
bool operator!=(int r1, vnl_finite_int< N > const &r2)
void vnl_error_vector_index(char const *fcn, int index)
Raise exception for invalid index.
static T max_value(T const *, unsigned)
Returns max value of the vector.
static void add(const T *a, const T *b, T *r)
vnl_vector_fixed< T, n > & normalize()
Normalise by dividing through by the magnitude.
void put(unsigned int i, T const &v)
Put value at given position in vector.
vnl_bignum operator/(vnl_bignum const &r1, vnl_bignum const &r2)
Returns the division of two bignum numbers.
bool empty() const
Return true iff the size is zero.
vnl_bignum operator *(vnl_bignum const &r1, vnl_bignum const &r2)
Returns the product of two bignum numbers.
vnl_vector_fixed< T, n > operator-() const
static abs_t two_nrm2(T const *p, unsigned n)
two_nrm2 : sum of squared abs values.
Math on blocks of memory.
unsigned arg_max() const
Location of largest value.
static abs_t inf_norm(T const *p, unsigned n)
inf_norm : max of abs values.
bool operator_eq(vnl_vector< T > const &v) const
Return true if *this == v.
static void sub(const T *a, const T *b, T *r)
T sum() const
Sum of values in a vector.
static void div(const T *a, const T *b, T *r)
vnl_vector_fixed< T, n > & operator/=(T s)