vnl_int_matrix Class Reference

#include <vnl_int_matrix.h>

Inheritance diagram for vnl_int_matrix:

vnl_matrix< int > List of all members.

Detailed Description

Specializes vnl_matrix for integers, adding a vnl_matrix<double> ctor.

Definition at line 22 of file vnl_int_matrix.h.


Public Types

typedef vnl_c_vector< int
>::abs_t 
abs_t
 Type def for norms.
typedef int element_type
typedef int * iterator
 Iterators.
typedef intconst * const_iterator
 Const iterators.

Public Member Functions

 vnl_int_matrix ()
 vnl_int_matrix (char const *filename)
 Load from disk.
 vnl_int_matrix (unsigned r, unsigned c)
 vnl_int_matrix (unsigned r, unsigned c, int fillvalue)
 vnl_int_matrix (const vnl_matrix< double > &d)
 Construct from matrix of double.
 vnl_int_matrix (const vnl_matrix< int > &d)
vnl_int_matrixoperator= (const vnl_matrix< int > &d)
 Copies all elements of rhs matrix into lhs matrix.
unsigned rows () const
 Return number of rows.
unsigned columns () const
 Return number of columns.
unsigned cols () const
 Return number of columns.
unsigned size () const
 Return number of elements.
void put (unsigned r, unsigned c, intconst &)
 set element with boundary checks if error checking is on.
int get (unsigned r, unsigned c) const
 get element with boundary checks if error checking is on.
int * operator[] (unsigned r)
 return pointer to given row.
intconst * operator[] (unsigned r) const
 return pointer to given row.
int & operator() (unsigned r, unsigned c)
 Access an element for reading or writing.
intconst & operator() (unsigned r, unsigned c) const
 Access an element for reading.
void fill (intconst &)
 Set all elements of matrix to specified value.
void fill_diagonal (intconst &)
 Set all diagonal elements of matrix to specified value.
void copy_in (intconst *)
 Fill (laminate) this matrix with the given data.
void set (intconst *d)
 Fill (laminate) this matrix with the given data.
void copy_out (int *) const
 Fill the given array with this matrix.
vnl_matrix< int > & operator+= (intvalue)
 Add rhs to each element of lhs matrix in situ.
vnl_matrix< int > & operator+= (vnl_matrix< int > const &)
 Add rhs to lhs matrix in situ.
vnl_matrix< int > & operator-= (intvalue)
 Subtract rhs from each element of lhs matrix in situ.
vnl_matrix< int > & operator-= (vnl_matrix< int > const &)
 Subtract rhs from lhs matrix in situ.
vnl_matrix< int > & operator *= (intvalue)
 Scalar multiplication in situ of lhs matrix by rhs.
vnl_matrix< int > & operator *= (vnl_matrix< int > const &rhs)
 Multiply lhs matrix in situ by rhs.
vnl_matrix< int > & operator/= (intvalue)
 Scalar division of lhs matrix in situ by rhs.
vnl_matrix< int > operator- () const
 Negate all elements of matrix.
vnl_matrix< int > operator- (intconst &v) const
 Subtract rhs from each element of lhs matrix and return result in new matrix.
vnl_matrix< int > operator- (vnl_matrix< int > const &rhs) const
 Matrix subtract rhs from lhs and return result in new matrix.
vnl_matrix< int > operator+ (intconst &v) const
 Add rhs to each element of lhs matrix and return result in new matrix.
vnl_matrix< int > operator+ (vnl_matrix< int > const &rhs) const
 Matrix add rhs to lhs matrix and return result in new matrix.
vnl_matrix< int > operator * (intconst &v) const
 Scalar multiplication of lhs matrix by rhs and return result in new matrix.
vnl_matrix< int > operator * (vnl_matrix< int > const &rhs) const
 Matrix multiply lhs by rhs matrix and return result in new matrix.
vnl_matrix< int > operator/ (intconst &v) const
 Scalar division of lhs matrix by rhs and return result in new matrix.
vnl_matrix< int > apply (int(*f)(int)) const
 Make a new matrix by applying function to each element.
vnl_matrix< int > apply (int(*f)(intconst &)) const
 Make a new matrix by applying function to each element.
vnl_matrix< int > transpose () const
 Return transpose.
vnl_matrix< int > conjugate_transpose () const
 Return conjugate transpose.
vnl_matrix< int > & update (vnl_matrix< int > const &, unsigned top=0, unsigned left=0)
 Set values of this matrix to those of M, starting at [top,left].
void set_column (unsigned i, intconst *v)
 Set the elements of the i'th column to v[j] (No bounds checking).
void set_column (unsigned i, intvalue)
 Set the elements of the i'th column to value.
void set_column (unsigned j, vnl_vector< int > const &v)
 Set j-th column to v.
void set_columns (unsigned starting_column, vnl_matrix< int > const &M)
 Set columns to those in M, starting at starting_column.
void set_row (unsigned i, intconst *v)
 Set the elements of the i'th row to v[j] (No bounds checking).
void set_row (unsigned i, intvalue)
 Set the elements of the i'th row to value.
void set_row (unsigned i, vnl_vector< int > const &)
 Set the i-th row.
vnl_matrix< int > extract (unsigned r, unsigned c, unsigned top=0, unsigned left=0) const
 Extract a sub-matrix of size r x c, starting at (top,left).
void extract (vnl_matrix< int > &sub_matrix, unsigned top=0, unsigned left=0) const
 Extract a sub-matrix starting at (top,left).
vnl_vector< int > get_row (unsigned r) const
 Get a vector equal to the given row.
vnl_vector< int > get_column (unsigned c) const
 Get a vector equal to the given column.
vnl_matrix< int > get_n_rows (unsigned rowstart, unsigned n) const
 Get n rows beginning at rowstart.
vnl_matrix< int > get_n_columns (unsigned colstart, unsigned n) const
 Get n columns beginning at colstart.
void set_identity ()
 Set this matrix to an identity matrix.
void inplace_transpose ()
 Transpose this matrix efficiently.
void flipud ()
 Reverse order of rows.
void fliplr ()
 Reverse order of columns.
void normalize_rows ()
 Normalize each row so it is a unit vector.
void normalize_columns ()
 Normalize each column so it is a unit vector.
void scale_row (unsigned row, intvalue)
 Scale elements in given row by a factor of T.
void scale_column (unsigned col, intvalue)
 Scale elements in given column by a factor of T.
void swap (vnl_matrix< int > &that)
 Swap this matrix with that matrix.
abs_t array_one_norm () const
 Return sum of absolute values of elements.
abs_t array_two_norm () const
 Return square root of sum of squared absolute element values.
abs_t array_inf_norm () const
 Return largest absolute element value.
abs_t absolute_value_sum () const
 Return sum of absolute values of elements.
abs_t absolute_value_max () const
 Return largest absolute value.
abs_t operator_one_norm () const
abs_t operator_inf_norm () const
abs_t frobenius_norm () const
 Return Frobenius norm of matrix (sqrt of sum of squares of its elements).
abs_t fro_norm () const
 Return Frobenius norm of matrix (sqrt of sum of squares of its elements).
abs_t rms () const
 Return RMS of all elements.
int min_value () const
 Return minimum value of elements.
int max_value () const
 Return maximum value of elements.
int mean () const
 Return mean of all matrix elements.
bool empty () const
 Return true iff the size is zero.
bool is_identity () const
 Return true if all elements equal to identity.
bool is_identity (double tol) const
 Return true if all elements equal to identity, within given tolerance.
bool is_zero () const
 Return true if all elements equal to zero.
bool is_zero (double tol) const
 Return true if all elements equal to zero, within given tolerance.
bool is_finite () const
 Return true if finite.
bool has_nans () const
 Return true if matrix contains NaNs.
void assert_size (unsigned r, unsigned c) const
 abort if size is not as expected.
void assert_finite () const
 abort if matrix contains any INFs or NANs.
bool read_ascii (vcl_istream &s)
intconst * data_block () const
 Access the contiguous block storing the elements in the matrix row-wise. O(1).
int * data_block ()
 Access the contiguous block storing the elements in the matrix row-wise. O(1).
intconst *const * data_array () const
 Access the 2D array, so that elements can be accessed with array[row][col] directly.
int ** data_array ()
 Access the 2D array, so that elements can be accessed with array[row][col] directly.
iterator begin ()
 Iterator pointing to start of data.
const_iterator begin () const
 Iterator pointing to start of data.
iterator end ()
 Iterator pointing to element beyond end of data.
const_iterator end () const
 Iterator pointing to element beyond end of data.
vnl_matrix< int > const & as_ref () const
 Return a reference to this.
vnl_matrix< int > & as_ref ()
 Return a reference to this.
bool operator_eq (vnl_matrix< int > const &rhs) const
 Return true if *this == rhs.
bool operator== (vnl_matrix< int > const &that) const
 Equality operator.
bool operator!= (vnl_matrix< int > const &that) const
 Inequality operator.
void print (vcl_ostream &os) const
 Print matrix to os in some hopefully sensible format.
void clear ()
 Make the matrix as if it had been default-constructed.
bool set_size (unsigned r, unsigned c)
 Resize to r rows by c columns. Old data lost.

Static Public Member Functions

static vnl_matrix< int > read (vcl_istream &s)
 Read a vnl_matrix from an ascii vcl_istream, automatically determining file size if the input matrix has zero size.

Protected Member Functions

void assert_size_internal (unsigned r, unsigned c) const
void assert_finite_internal () const
void destroy ()
 Delete data.

Static Protected Member Functions

static void inline_function_tickler ()

Protected Attributes

unsigned num_rows
unsigned num_cols
int ** data

Private Types

typedef vnl_matrix< int > Base

Member Typedef Documentation

typedef vnl_matrix<int> vnl_int_matrix::Base [private]

Definition at line 24 of file vnl_int_matrix.h.

typedef vnl_c_vector<int >::abs_t vnl_matrix< int >::abs_t [inherited]

Type def for norms.

Definition at line 370 of file vnl_matrix.h.

typedef int vnl_matrix< int >::element_type [inherited]

Definition at line 477 of file vnl_matrix.h.

typedef int * vnl_matrix< int >::iterator [inherited]

Iterators.

Definition at line 480 of file vnl_matrix.h.

typedef int const* vnl_matrix< int >::const_iterator [inherited]

Const iterators.

Definition at line 487 of file vnl_matrix.h.


Constructor & Destructor Documentation

vnl_int_matrix::vnl_int_matrix (  )  [inline]

Definition at line 27 of file vnl_int_matrix.h.

vnl_int_matrix::vnl_int_matrix ( char const *  filename  ) 

Load from disk.

Definition at line 30 of file vnl_int_matrix.cxx.

vnl_int_matrix::vnl_int_matrix ( unsigned  r,
unsigned  c 
) [inline]

Definition at line 29 of file vnl_int_matrix.h.

vnl_int_matrix::vnl_int_matrix ( unsigned  r,
unsigned  c,
int  fillvalue 
) [inline]

Definition at line 30 of file vnl_int_matrix.h.

vnl_int_matrix::vnl_int_matrix ( const vnl_matrix< double > &  d  ) 

Construct from matrix of double.

The double-to-int conversion is simply the standard (int) cast.

Definition at line 18 of file vnl_int_matrix.cxx.

vnl_int_matrix::vnl_int_matrix ( const vnl_matrix< int > &  d  )  [inline]

Definition at line 32 of file vnl_int_matrix.h.


Member Function Documentation

vnl_int_matrix& vnl_int_matrix::operator= ( const vnl_matrix< int > &  d  )  [inline]

Copies all elements of rhs matrix into lhs matrix.

Complexity $O(\min(r,c))$

Reimplemented from vnl_matrix< int >.

Definition at line 33 of file vnl_int_matrix.h.

unsigned vnl_matrix< int >::rows (  )  const [inline, inherited]

Return number of rows.

Definition at line 145 of file vnl_matrix.h.

unsigned vnl_matrix< int >::columns (  )  const [inline, inherited]

Return number of columns.

A synonym for cols()

Definition at line 149 of file vnl_matrix.h.

unsigned vnl_matrix< int >::cols (  )  const [inline, inherited]

Return number of columns.

A synonym for columns()

Definition at line 153 of file vnl_matrix.h.

unsigned vnl_matrix< int >::size (  )  const [inline, inherited]

Return number of elements.

This equals rows() * cols()

Definition at line 157 of file vnl_matrix.h.

void vnl_matrix< int >::put ( unsigned  r,
unsigned  c,
int const &   
) [inherited]

set element with boundary checks if error checking is on.

Checks for valid range of indices.

int vnl_matrix< int >::get ( unsigned  r,
unsigned  c 
) const [inherited]

get element with boundary checks if error checking is on.

Checks for valid range of indices.

int * vnl_matrix< int >::operator[] ( unsigned  r  )  [inline, inherited]

return pointer to given row.

No boundary checking here.

Definition at line 167 of file vnl_matrix.h.

int const* vnl_matrix< int >::operator[] ( unsigned  r  )  const [inline, inherited]

return pointer to given row.

No boundary checking here.

Definition at line 171 of file vnl_matrix.h.

int & vnl_matrix< int >::operator() ( unsigned  r,
unsigned  c 
) [inline, inherited]

Access an element for reading or writing.

There are assert style boundary checks - define NDEBUG to turn them off.

Definition at line 175 of file vnl_matrix.h.

int const& vnl_matrix< int >::operator() ( unsigned  r,
unsigned  c 
) const [inline, inherited]

Access an element for reading.

There are assert style boundary checks - define NDEBUG to turn them off.

Definition at line 186 of file vnl_matrix.h.

void vnl_matrix< int >::fill ( int const &   )  [inherited]

Set all elements of matrix to specified value.

Complexity $O(r.c)$

void vnl_matrix< int >::fill_diagonal ( int const &   )  [inherited]

Set all diagonal elements of matrix to specified value.

Complexity $O(\min(r,c))$

void vnl_matrix< int >::copy_in ( int const *   )  [inherited]

Fill (laminate) this matrix with the given data.

We assume that p points to a contiguous rows*cols array, stored rowwise.

void vnl_matrix< int >::set ( int const *  d  )  [inline, inherited]

Fill (laminate) this matrix with the given data.

A synonym for copy_in()

Definition at line 212 of file vnl_matrix.h.

void vnl_matrix< int >::copy_out ( int *   )  const [inherited]

Fill the given array with this matrix.

We assume that p points to a contiguous rows*cols array, stored rowwise. No bounds checking on the array.

vnl_matrix<int >& vnl_matrix< int >::operator+= ( int   value  )  [inherited]

Add rhs to each element of lhs matrix in situ.

vnl_matrix<int >& vnl_matrix< int >::operator+= ( vnl_matrix< int > const &   )  [inherited]

Add rhs to lhs matrix in situ.

O(m*n). The dimensions of the two matrices must be identical.

vnl_matrix<int >& vnl_matrix< int >::operator-= ( int   value  )  [inherited]

Subtract rhs from each element of lhs matrix in situ.

vnl_matrix<int >& vnl_matrix< int >::operator-= ( vnl_matrix< int > const &   )  [inherited]

Subtract rhs from lhs matrix in situ.

O(m*n). The dimensions of the two matrices must be identical.

vnl_matrix<int >& vnl_matrix< int >::operator *= ( int   value  )  [inherited]

Scalar multiplication in situ of lhs matrix by rhs.

vnl_matrix<int >& vnl_matrix< int >::operator *= ( vnl_matrix< int > const &  rhs  )  [inline, inherited]

Multiply lhs matrix in situ by rhs.

Definition at line 249 of file vnl_matrix.h.

vnl_matrix<int >& vnl_matrix< int >::operator/= ( int   value  )  [inherited]

Scalar division of lhs matrix in situ by rhs.

vnl_matrix<int > vnl_matrix< int >::operator- (  )  const [inherited]

Negate all elements of matrix.

O(m*n).

vnl_matrix<int > vnl_matrix< int >::operator- ( int const &  v  )  const [inline, inherited]

Subtract rhs from each element of lhs matrix and return result in new matrix.

Definition at line 259 of file vnl_matrix.h.

vnl_matrix<int > vnl_matrix< int >::operator- ( vnl_matrix< int > const &  rhs  )  const [inline, inherited]

Matrix subtract rhs from lhs and return result in new matrix.

Definition at line 270 of file vnl_matrix.h.

vnl_matrix<int > vnl_matrix< int >::operator+ ( int const &  v  )  const [inline, inherited]

Add rhs to each element of lhs matrix and return result in new matrix.

Definition at line 256 of file vnl_matrix.h.

vnl_matrix<int > vnl_matrix< int >::operator+ ( vnl_matrix< int > const &  rhs  )  const [inline, inherited]

Matrix add rhs to lhs matrix and return result in new matrix.

Definition at line 268 of file vnl_matrix.h.

vnl_matrix<int > vnl_matrix< int >::operator * ( int const &  v  )  const [inline, inherited]

Scalar multiplication of lhs matrix by rhs and return result in new matrix.

Definition at line 262 of file vnl_matrix.h.

vnl_matrix<int > vnl_matrix< int >::operator * ( vnl_matrix< int > const &  rhs  )  const [inline, inherited]

Matrix multiply lhs by rhs matrix and return result in new matrix.

Definition at line 272 of file vnl_matrix.h.

vnl_matrix<int > vnl_matrix< int >::operator/ ( int const &  v  )  const [inline, inherited]

Scalar division of lhs matrix by rhs and return result in new matrix.

Definition at line 265 of file vnl_matrix.h.

vnl_matrix<int > vnl_matrix< int >::apply ( int (*)(int )  f  )  const [inherited]

Make a new matrix by applying function to each element.

vnl_matrix<int > vnl_matrix< int >::apply ( int (*)(int const &)  f  )  const [inherited]

Make a new matrix by applying function to each element.

vnl_matrix<int > vnl_matrix< int >::transpose (  )  const [inherited]

Return transpose.

O(m*n).

vnl_matrix<int > vnl_matrix< int >::conjugate_transpose (  )  const [inherited]

Return conjugate transpose.

vnl_matrix<int >& vnl_matrix< int >::update ( vnl_matrix< int > const &  ,
unsigned  top = 0,
unsigned  left = 0 
) [inherited]

Set values of this matrix to those of M, starting at [top,left].

This is the reverse of extract().

void vnl_matrix< int >::set_column ( unsigned  i,
int const *  v 
) [inherited]

Set the elements of the i'th column to v[j] (No bounds checking).

void vnl_matrix< int >::set_column ( unsigned  i,
int   value 
) [inherited]

Set the elements of the i'th column to value.

void vnl_matrix< int >::set_column ( unsigned  j,
vnl_vector< int > const &  v 
) [inherited]

Set j-th column to v.

void vnl_matrix< int >::set_columns ( unsigned  starting_column,
vnl_matrix< int > const &  M 
) [inherited]

Set columns to those in M, starting at starting_column.

void vnl_matrix< int >::set_row ( unsigned  i,
int const *  v 
) [inherited]

Set the elements of the i'th row to v[j] (No bounds checking).

void vnl_matrix< int >::set_row ( unsigned  i,
int   value 
) [inherited]

Set the elements of the i'th row to value.

void vnl_matrix< int >::set_row ( unsigned  i,
vnl_vector< int > const &   
) [inherited]

Set the i-th row.

vnl_matrix<int > vnl_matrix< int >::extract ( unsigned  r,
unsigned  c,
unsigned  top = 0,
unsigned  left = 0 
) const [inherited]

Extract a sub-matrix of size r x c, starting at (top,left).

Thus it contains elements [top,top+r-1][left,left+c-1]

void vnl_matrix< int >::extract ( vnl_matrix< int > &  sub_matrix,
unsigned  top = 0,
unsigned  left = 0 
) const [inherited]

Extract a sub-matrix starting at (top,left).

The output is stored in sub_matrix, and it should have the required size on entry. Thus the result will contain elements [top,top+sub_matrix.rows()-1][left,left+sub_matrix.cols()-1]

vnl_vector<int > vnl_matrix< int >::get_row ( unsigned  r  )  const [inherited]

Get a vector equal to the given row.

vnl_vector<int > vnl_matrix< int >::get_column ( unsigned  c  )  const [inherited]

Get a vector equal to the given column.

vnl_matrix<int > vnl_matrix< int >::get_n_rows ( unsigned  rowstart,
unsigned  n 
) const [inherited]

Get n rows beginning at rowstart.

vnl_matrix<int > vnl_matrix< int >::get_n_columns ( unsigned  colstart,
unsigned  n 
) const [inherited]

Get n columns beginning at colstart.

void vnl_matrix< int >::set_identity (  )  [inherited]

Set this matrix to an identity matrix.

Abort if the matrix is not square

void vnl_matrix< int >::inplace_transpose (  )  [inherited]

Transpose this matrix efficiently.

Works for rectangular matrices using an enormously clever algorithm from ACM TOMS.

void vnl_matrix< int >::flipud (  )  [inherited]

Reverse order of rows.

void vnl_matrix< int >::fliplr (  )  [inherited]

Reverse order of columns.

void vnl_matrix< int >::normalize_rows (  )  [inherited]

Normalize each row so it is a unit vector.

Zero rows are ignored

void vnl_matrix< int >::normalize_columns (  )  [inherited]

Normalize each column so it is a unit vector.

Zero columns are ignored

void vnl_matrix< int >::scale_row ( unsigned  row,
int   value 
) [inherited]

Scale elements in given row by a factor of T.

void vnl_matrix< int >::scale_column ( unsigned  col,
int   value 
) [inherited]

Scale elements in given column by a factor of T.

void vnl_matrix< int >::swap ( vnl_matrix< int > &  that  )  [inherited]

Swap this matrix with that matrix.

abs_t vnl_matrix< int >::array_one_norm (  )  const [inline, inherited]

Return sum of absolute values of elements.

Definition at line 373 of file vnl_matrix.h.

abs_t vnl_matrix< int >::array_two_norm (  )  const [inline, inherited]

Return square root of sum of squared absolute element values.

Definition at line 376 of file vnl_matrix.h.

abs_t vnl_matrix< int >::array_inf_norm (  )  const [inline, inherited]

Return largest absolute element value.

Definition at line 379 of file vnl_matrix.h.

abs_t vnl_matrix< int >::absolute_value_sum (  )  const [inline, inherited]

Return sum of absolute values of elements.

Definition at line 382 of file vnl_matrix.h.

abs_t vnl_matrix< int >::absolute_value_max (  )  const [inline, inherited]

Return largest absolute value.

Definition at line 385 of file vnl_matrix.h.

abs_t vnl_matrix< int >::operator_one_norm (  )  const [inherited]

abs_t vnl_matrix< int >::operator_inf_norm (  )  const [inherited]

abs_t vnl_matrix< int >::frobenius_norm (  )  const [inline, inherited]

Return Frobenius norm of matrix (sqrt of sum of squares of its elements).

Definition at line 394 of file vnl_matrix.h.

abs_t vnl_matrix< int >::fro_norm (  )  const [inline, inherited]

Return Frobenius norm of matrix (sqrt of sum of squares of its elements).

Definition at line 397 of file vnl_matrix.h.

abs_t vnl_matrix< int >::rms (  )  const [inline, inherited]

Return RMS of all elements.

Definition at line 400 of file vnl_matrix.h.

int vnl_matrix< int >::min_value (  )  const [inline, inherited]

Return minimum value of elements.

Definition at line 403 of file vnl_matrix.h.

int vnl_matrix< int >::max_value (  )  const [inline, inherited]

Return maximum value of elements.

Definition at line 406 of file vnl_matrix.h.

int vnl_matrix< int >::mean (  )  const [inline, inherited]

Return mean of all matrix elements.

Definition at line 409 of file vnl_matrix.h.

bool vnl_matrix< int >::empty (  )  const [inline, inherited]

Return true iff the size is zero.

Definition at line 414 of file vnl_matrix.h. </