4 #ifdef __INTEL_COMPILER 5 #pragma warning disable 444 37 #include <vcl_compiler.h> 39 # include <vcl_msvc_warnings.h> 43 #include <vnl/vnl_config.h> 46 # if VNL_CONFIG_CHECK_BOUNDS 50 # undef VNL_CONFIG_CHECK_BOUNDS 51 # define VNL_CONFIG_CHECK_BOUNDS 0 52 # undef ERROR_CHECKING 54 #include "vnl/vnl_export.h" 61 #ifndef DOXYGEN_SHOULD_SKIP_THIS 62 #define v vnl_vector<T> 63 #define m vnl_matrix<T> 64 #endif // DOXYGEN_SHOULD_SKIP_THIS 65 template <
class T> VNL_EXPORT
m operator+(T
const&,
m const&);
66 template <
class T> VNL_EXPORT
m operator-(T
const&,
m const&);
67 template <
class T> VNL_EXPORT
m operator*(T
const&,
m const&);
70 template <
class T> VNL_EXPORT T
dot_product(
m const&,
m const&);
72 template <
class T> VNL_EXPORT T
cos_angle(
m const&,
m const& );
73 template <
class T> VNL_EXPORT std::ostream&
operator<<(std::ostream&,
m const&);
74 template <
class T> VNL_EXPORT std::istream&
operator>>(std::istream&,
m&);
131 vnl_matrix(
unsigned r,
unsigned c, T
const& v0);
141 vnl_matrix(
unsigned r,
unsigned c,
unsigned n, T
const values[]);
146 vnl_matrix(T
const* data_block,
unsigned r,
unsigned c);
152 #ifndef VXL_DOXYGEN_SHOULD_SKIP_THIS 164 : num_rows(that.num_rows), num_cols(that.num_cols), data(that.data)
176 inline unsigned int size()
const {
return this->num_rows*this->num_cols; }
179 inline unsigned int rows()
const {
return this->num_rows; }
183 inline unsigned int cols()
const {
return this->num_cols; }
187 inline unsigned int columns()
const {
return this->num_cols; }
190 inline void put(
unsigned r,
unsigned c, T
const&);
193 inline T get(
unsigned r,
unsigned c)
const;
205 T & operator()(
unsigned r,
unsigned c);
209 T
const & operator()(
unsigned r,
unsigned c)
const;
270 void copy_out(T *)
const;
373 unsigned top=0,
unsigned left=0)
const;
381 unsigned top=0,
unsigned left=0)
const;
397 vnl_matrix<T> get_n_rows(
unsigned rowstart,
unsigned n)
const;
400 vnl_matrix<T> get_n_columns(
unsigned colstart,
unsigned n)
const;
493 vnl_matrix& scale_column(
unsigned col, T value);
517 abs_t operator_one_norm()
const;
520 abs_t operator_inf_norm()
const;
549 bool empty()
const {
return !data || !num_rows || !num_cols; }
552 bool is_identity()
const;
555 bool is_identity(
double tol)
const;
558 bool is_zero()
const;
561 bool is_zero(
double tol)
const;
567 bool is_finite()
const;
570 bool has_nans()
const;
574 void assert_size(
unsigned VXL_USED_IN_DEBUG(r),
unsigned VXL_USED_IN_DEBUG(c))
const 577 assert_size_internal(r, c);
585 assert_finite_internal();
595 bool read_ascii(std::istream& s);
652 void print(std::ostream& os)
const;
659 bool set_size(
unsigned r,
unsigned c);
668 void assert_size_internal(
unsigned r,
unsigned c)
const;
669 void assert_finite_internal()
const;
686 #if VNL_CONFIG_CHECK_BOUNDS 687 if (r >= this->num_rows)
689 if (c >= this->num_cols)
692 return this->data[r][c];
700 ::put(
unsigned r,
unsigned c, T
const&
v)
702 #if VNL_CONFIG_CHECK_BOUNDS 703 if (r >= this->num_rows)
705 if (c >= this->num_cols)
708 this->data[r][c] =
v;
736 #endif // vnl_matrix_h_ vnl_matrix< T > & operator=(T const &v)
Set all elements to value v.
vnl_c_vector< T >::abs_t abs_t
Type def for norms.
vnl_vector_fixed< T, n > element_quotient(const vnl_vector_fixed< T, n > &a, const vnl_vector_fixed< T, n > &b)
unsigned int cols() const
Return the number of columns.
vnl_matrix()
Default constructor creates an empty matrix of size 0,0.
abs_t absolute_value_max() const
Return largest absolute value.
void assert_finite() const
abort if matrix contains any INFs or NANs.
const_iterator begin() const
Iterator pointing to start of data.
vnl_bignum operator+(vnl_bignum const &r1, long r2)
Returns the sum of two bignum numbers.
abs_t absolute_value_sum() const
Return sum of absolute values of elements.
abs_t rms() const
Return RMS of all elements.
vnl_matrix< T > operator/(T const &v) const
Scalar division of lhs matrix by rhs and return result in new matrix.
iterator end()
Iterator pointing to element beyond end of data.
const_iterator end() const
Iterator pointing to element beyond end of data.
vnl_matrix(vnl_matrix< T > &that, vnl_tag_grab)
abs_t array_one_norm() const
Return sum of absolute values of elements.
static unsigned arg_min(T const *, unsigned)
Returns location of min value of the vector.
vnl_matrix< T > & as_ref()
Return a reference to this.
abs_t fro_norm() const
Return Frobenius norm of matrix (sqrt of sum of squares of its elements).
T * operator[](unsigned r)
return pointer to given row.
vnl_matrix< T > operator-(T const &v) const
Subtract rhs from each element of lhs matrix and return result in new matrix.
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.
T const * operator[](unsigned r) const
return pointer to given row.
iterator begin()
Iterator pointing to start of data.
void vnl_error_matrix_row_index(char const *fcn, int r)
Raise exception for invalid row index.
void vnl_error_matrix_col_index(char const *fcn, int c)
Raise exception for invalid col index.
abs_t frobenius_norm() const
Return Frobenius norm of matrix (sqrt of sum of squares of its elements).
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.
enum VNL_EXPORT vnl_matrix_type
abs_t array_inf_norm() const
Return largest absolute element value.
std::ostream & operator<<(std::ostream &s, vnl_decnum const &r)
decimal output.
unsigned arg_min() const
Return location of minimum value of elements.
vnl_matrix & set(T const *d)
Fills (laminates) this matrix with the given data, then returns it.
T get(unsigned r, unsigned c) const
get element with boundary checks if error checking is on.
T * data_block()
Access the contiguous block storing the elements in the matrix row-wise. O(1).
abs_t array_two_norm() const
Return square root of sum of squared absolute element values.
T ** data_array()
Access the 2D array, so that elements can be accessed with array[row][col] directly.
vnl_matrix< T > const & as_ref() const
Return a reference to this.
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.
An ordinary mathematical matrix.
T max_value() const
Return maximum value of elements.
static T mean(T const *p, unsigned n)
T mean() const
Return mean of all matrix elements.
bool operator==(vnl_matrix< T > const &that) const
Equality operator.
VNL_EXPORT T inner_product(m const &, m const &)
VNL_EXPORT m operator-(T const &, m const &)
vnl_matrix< T > operator+(vnl_matrix< T > const &rhs) const
Matrix add rhs to lhs matrix and return result in new matrix.
void assert_size(unsigned VXL_USED_IN_DEBUG(r), unsigned VXL_USED_IN_DEBUG(c)) const
abort if size is not as expected.
T const *const * data_array() const
Access the 2D array, so that elements can be accessed with array[row][col] directly.
T dot_product(const vnl_vector_fixed< T, n > &a, const vnl_vector_fixed< T, n > &b)
void swap(vnl_matrix< T > &that)
Swap this matrix with that matrix.
vnl_numeric_traits< T >::abs_t abs_t
bool empty() const
Return true iff the size is zero.
void swap(vnl_matrix< T > &A, vnl_matrix< T > &B)
Swap two matrices.
Mathematical vector class, templated by type of element.
T const * data_block() const
Access the contiguous block storing the elements in the matrix row-wise. O(1).
T const * const_iterator
Const iterators.
unsigned int size() const
Return the total number of elements stored by the matrix.
bool operator!=(vnl_matrix< T > const &that) const
Inequality operator.
unsigned int rows() const
Return the number of rows.
unsigned arg_max() const
Return location of maximum value of elements.
vnl_matrix< T > operator-(vnl_matrix< T > const &rhs) const
Matrix subtract rhs from lhs and return result in new matrix.
T min_value() const
Return minimum value of elements.
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.
static T max_value(T const *, unsigned)
Returns max value of the vector.
void swap(vnl_matrix< T > &A, vnl_matrix< T > &B)
Swap two matrices.
VNL_EXPORT m operator *(T const &, m const &)
VNL_EXPORT T cos_angle(m const &, m const &)
vnl_matrix< T > operator+(T const &v) const
Add rhs to each element of lhs matrix and return result in new matrix.
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.
void put(unsigned r, unsigned c, T const &)
set element with boundary checks if error checking is on.