2 #ifndef vnl_matrix_fixed_h_ 3 #define vnl_matrix_fixed_h_ 29 #include <vcl_compiler.h> 31 # include <vcl_msvc_warnings.h> 39 #include <vnl/vnl_config.h> 40 #include "vnl/vnl_export.h" 42 template <
class T,
unsigned int num_rows,
unsigned int num_cols>
class vnl_matrix_fixed;
86 template <
class T,
unsigned int num_rows,
unsigned int num_cols>
88 template <
class T,
unsigned M,
unsigned N>
91 template <
class T,
unsigned M,
unsigned N,
unsigned O>
103 template <
class T,
unsigned int num_rows,
unsigned int num_cols>
106 T data_[num_rows][num_cols];
132 assert( n == num_rows &&
m == num_cols );
139 unsigned int n = num_rows * num_cols;
147 std::memcpy(data_[0], datablck, num_rows*num_cols*
sizeof(T));
154 assert(rhs.
rows() == num_rows && rhs.
columns() == num_cols);
155 std::memcpy(data_[0], rhs.
data_block(), num_rows*num_cols*
sizeof(T));
171 inline unsigned int size()
const {
return num_rows*num_cols; }
174 inline unsigned int rows()
const {
return num_rows; }
178 inline unsigned int cols()
const {
return num_cols; }
182 inline unsigned int columns()
const {
return num_cols; }
185 inline void put (
unsigned r,
unsigned c, T
const&
v)
187 #if VNL_CONFIG_CHECK_BOUNDS 193 this->data_[r][c] =
v;
197 inline T get (
unsigned r,
unsigned c)
const 199 #if VNL_CONFIG_CHECK_BOUNDS 205 return this->data_[r][c];
209 vnl_matrix_fixed& set (
unsigned r,
unsigned c, T
const&
v) { (*this)(r,c) =
v;
return *
this; }
213 T * operator[] (
unsigned r) {
return data_[r]; }
217 T
const * operator[] (
unsigned r)
const {
return data_[r]; }
221 T & operator() (
unsigned r,
unsigned c);
225 T
const & operator() (
unsigned r,
unsigned c)
const;
285 void copy_out(T *)
const;
302 self::add( data_block(), s, data_block() );
return *
this;
308 self::sub( data_block(), s, data_block() );
return *
this;
314 self::mul( data_block(), s, data_block() );
return *
this;
320 self::div( data_block(), s, data_block() );
return *
this;
326 self::add( data_block(),
m.data_block(), data_block() );
return *
this;
332 assert(
m.rows() == rows() &&
m.cols() == cols() );
333 self::add( data_block(),
m.data_block(), data_block() );
return *
this;
339 self::sub( data_block(),
m.data_block(), data_block() );
return *
this;
345 assert(
m.rows() == rows() &&
m.cols() == cols() );
346 self::sub( data_block(),
m.data_block(), data_block() );
354 self::sub( T(0), data_block(), r.
data_block() );
362 for (
unsigned i = 0; i < num_rows; ++i)
363 for (
unsigned j = 0; j < num_cols; ++j)
365 T accum = this->data_[i][0] * s(0,j);
366 for (
unsigned k = 1; k < num_cols; ++k)
367 accum += this->data_[i][k] * s(k,j);
426 unsigned top=0,
unsigned left=0)
const;
434 unsigned top=0,
unsigned left=0)
const;
449 vnl_matrix<T> get_n_rows (
unsigned rowstart,
unsigned n)
const;
452 vnl_matrix<T> get_n_columns(
unsigned colstart,
unsigned n)
const;
555 abs_t absolute_value_sum()
const {
return array_one_norm(); }
558 abs_t absolute_value_max()
const {
return array_inf_norm(); }
561 abs_t operator_one_norm()
const;
564 abs_t operator_inf_norm()
const;
570 abs_t fro_norm()
const {
return frobenius_norm(); }
593 bool empty()
const {
return num_rows==0 && num_cols==0; }
596 bool is_identity()
const;
599 bool is_identity(
double tol)
const;
602 bool is_zero()
const;
605 bool is_zero(
double tol)
const;
611 bool is_finite()
const;
614 bool has_nans()
const;
618 void assert_size(
unsigned VXL_USED_IN_DEBUG(nr_rows),
unsigned VXL_USED_IN_DEBUG(nr_cols) )
const 621 assert_size_internal(nr_rows, nr_cols);
627 void assert_finite()
const 630 assert_finite_internal();
637 bool read_ascii(std::istream& s);
643 T
const* data_block()
const;
688 inline iterator begin() {
return data_[0]; }
690 inline iterator end() {
return begin() + size(); }
704 return equal( this->data_block(), rhs.
data_block() );
720 void print(std::ostream& os)
const;
729 static void add(
const T* a,
const T* b, T* r );
730 static void add(
const T* a, T b, T* r );
731 static void sub(
const T* a,
const T* b, T* r );
732 static void sub(
const T* a, T b, T* r );
733 static void sub( T a,
const T* b, T* r );
734 static void mul(
const T* a,
const T* b, T* r );
735 static void mul(
const T* a, T b, T* r );
736 static void div(
const T* a,
const T* b, T* r );
737 static void div(
const T* a, T b, T* r );
739 static bool equal(
const T* a,
const T* b );
742 void assert_finite_internal()
const;
744 void assert_size_internal(
unsigned,
unsigned)
const;
753 template <
class T,
unsigned m,
unsigned n>
762 template <
class T,
unsigned m,
unsigned n>
771 template <
class T,
unsigned m,
unsigned n>
781 template <
class T,
unsigned m,
unsigned n>
790 template <
class T,
unsigned m,
unsigned n>
799 template <
class T,
unsigned m,
unsigned n>
809 template <
class T,
unsigned m,
unsigned n>
818 template <
class T,
unsigned m,
unsigned n>
828 template <
class T,
unsigned m,
unsigned n>
838 template <
class T,
unsigned m,
unsigned n>
849 template <
class T,
unsigned m,
unsigned n>
863 template <
class T,
unsigned M,
unsigned N>
870 for (
unsigned i = 0; i < M; ++i)
872 T accum = a(i,0) * b(0);
873 for (
unsigned k = 1; k < N; ++k)
874 accum += a(i,k) * b(k);
880 template <
class T,
unsigned M,
unsigned N>
887 for (
unsigned i = 0; i < N; ++i)
889 T accum = a(0) * b(0,i);
890 for (
unsigned k = 1; k < M; ++k)
891 accum += a(k) * b(k,i);
898 template <
class T,
unsigned M,
unsigned N,
unsigned O>
905 for (
unsigned i = 0; i < M; ++i)
906 for (
unsigned j = 0; j < O; ++j)
908 T accum = a(i,0) * b(0,j);
909 for (
unsigned k = 1; k < N; ++k)
910 accum += a(i,k) * b(k,j);
921 template <
class T,
unsigned M,
unsigned N>
931 template <
class T,
unsigned M,
unsigned N>
940 template <
class T,
unsigned M,
unsigned N,
unsigned O>
952 template <
class T,
unsigned m,
unsigned n>
958 template <
class T,
unsigned m,
unsigned n>
964 template <
class T,
unsigned m,
unsigned n>
970 template <
class T,
unsigned m,
unsigned n>
976 template <
class T,
unsigned m,
unsigned n>
982 template <
class T,
unsigned m,
unsigned n>
988 template <
class T,
unsigned m,
unsigned n>
994 template <
class T,
unsigned n>
1003 template <
class T,
unsigned m,
unsigned n>
1011 template <
class T,
unsigned m,
unsigned n>
1021 template <
class T,
unsigned m,
unsigned n> VNL_EXPORT
1024 #define VNL_MATRIX_FIXED_INSTANTIATE(T, M, N) \ 1025 extern "please include vnl/vnl_matrix_fixed.hxx instead" 1027 #endif // vnl_matrix_fixed_h_ vnl_vector_fixed< T, n > element_quotient(const vnl_vector_fixed< T, n > &a, const vnl_vector_fixed< T, n > &b)
vnl_matrix_ref< T > as_ref()
Explicit conversion to a vnl_matrix_ref.
vnl_bignum operator+(vnl_bignum const &r1, long r2)
Returns the sum of two bignum numbers.
void swap(double &a, double &b)
An ordinary mathematical matrix.
static unsigned arg_min(T const *, unsigned)
Returns location of min value of the vector.
vnl_vector_fixed< T, M > vnl_matrix_fixed_mat_vec_mult(const vnl_matrix_fixed< T, M, N > &a, const vnl_vector_fixed< T, N > &b)
T const * data_block() const
Access the contiguous block storing the elements in the matrix row-wise. O(1).
static void mul(const T *a, const T *b, T *r)
vnl_vector_fixed< T, n > element_product(const vnl_vector_fixed< T, n > &a, const vnl_vector_fixed< T, n > &b)
static abs_t rms_norm(T const *p, unsigned n)
rms_norm : sqrt of mean sum of squared abs values.
static void sub(const T *a, const T *b, T *r)
void vnl_error_matrix_row_index(char const *fcn, int r)
Raise exception for invalid row index.
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.
void vnl_error_matrix_col_index(char const *fcn, int c)
Raise exception for invalid col index.
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.
std::ostream & operator<<(std::ostream &s, vnl_decnum const &r)
decimal output.
static unsigned arg_max(T const *, unsigned)
Returns location of max value of the vector.
bool read_ascii(std::istream &s)
static T min_value(T const *, unsigned)
Returns min value of the vector.
T const * const_iterator
Const iterators.
vnl_vector_fixed< T, N > vnl_matrix_fixed_vec_mat_mult(const vnl_vector_fixed< T, M > &a, const vnl_matrix_fixed< T, M, N > &b)
An ordinary mathematical matrix.
static T mean(T const *p, unsigned n)
bool operator!=(long r1, vnl_bignum const &r2)
void print(std::ostream &os) const
Print matrix to os in some hopefully sensible format.
vnl_matrix_fixed< T, m, n > operator-(const vnl_matrix_fixed< T, m, n > &mat1, const vnl_matrix_fixed< T, m, n > &mat2)
vnl_numeric_traits< T >::abs_t abs_t
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)
T const * data_block() const
Access the contiguous block storing the elements in the matrix row-wise. O(1).
Fixed length stack-stored, space-efficient vector.
Fixed length stack-stored vector.
unsigned int rows() const
Return the number of rows.
VNL_EXPORT std::istream & operator>>(std::istream &s, vnl_decnum &r)
decimal input.
bool operator==(const vnl_amoeba_SimplexCorner &a, const vnl_amoeba_SimplexCorner &b)
vnl_bignum operator-(vnl_bignum const &r1, vnl_bignum const &r2)
Returns the difference of two bignum numbers.
static T max_value(T const *, unsigned)
Returns max value of the vector.
vnl_matrix_fixed< T, M, O > vnl_matrix_fixed_mat_mat_mult(const vnl_matrix_fixed< T, M, N > &a, const vnl_matrix_fixed< T, N, O > &b)
static void div(const T *a, const T *b, T *r)
vnl_bignum operator/(vnl_bignum const &r1, vnl_bignum const &r2)
Returns the division of two bignum numbers.
vnl_matrix reference to user-supplied storage.
vnl_bignum operator *(vnl_bignum const &r1, vnl_bignum const &r2)
Returns the product of two bignum numbers.
unsigned int columns() const
Return the number of columns.
Math on blocks of memory.
static abs_t inf_norm(T const *p, unsigned n)
inf_norm : max of abs values.
vnl_matrix reference to user-supplied storage.
static void add(const T *a, const T *b, T *r)
vnl_c_vector< T >::abs_t abs_t
Type def for norms.