ml_matrix Class Reference

Class definition for ml_matrix.

List of all members.

Public Member Functions

 ml_matrix ()
 Default Constructor. Creates an empty (0 x 0) matrix.

 ml_matrix (const ml_matrix &m)
 Copy constructor.

 ml_matrix (int rows, int cols=1)
 Creates a matrix and sets all elements to 0.

 ml_matrix (int rows, int cols, double value)
 Creates a matrix with all values equal to value.

 ml_matrix (int rows, int cols, double *v)
 Constructor which builds a matrix from a given array.

 ml_matrix (const char *s)
 Constructs a matrix from a string format as used in MATLAB or created by ml_matrix::to_string().

 ml_matrix (void *bf)
 Constructs a matrix from a binary format as created by ml_matrix::to_binary().

 ml_matrix (FILE *f, int *linenum=NULL)
 Constructs a matrix from a string format as used in MATLAB or created by ml_matrix::to_string(), and read from a file.

 ~ml_matrix ()
 Destructor.

char * to_string (int human_readable=0)
 Returns a character string representation of the matrix.

void display (char *s=NULL)
 Display function. Formats the matrix in a human readable fashion and prints to standard out.

void * to_binary (unsigned int *size=NULL) const
 Creates binary representation of matrix for efficient transfer.

double & operator() (int row, int col)
 Accesses or assigns an element, resizes matrix if out of bounds.

double get (int row, int col) const
 Accesses an element. Will not resize the matrix.

void resize (int rows, int cols)
 Resizes the matrix, initializes new values to zero.

ml_matrixappend_identity ()
 Adds an appropriately sized identity matrix to the existing matrix.

ml_matrix sub_matrix (int from_row, int to_row, int from_col, int to_col) const
 Extracts a submatrix using a range of rows and columns.

ml_matrix sub_matrix (int n_rows, int *rows, int n_cols, int *cols) const
 Extracts a submatrix using two arrays to select the rows and columns.

ml_matrix sub_matrix (const ml_int_array &rows, const ml_int_array &cols) const
 Extracts a submatrix using two ml_int_arrays to select the rows and columns.

ml_matrix get_row (int row) const
 Gets a single row.

ml_matrix get_col (int col) const
 Gets a single column.

ml_matrix get_row_set (int n_rows, int *rows) const
 Gets a set of rows defined by an array.

ml_matrix get_row_set (const ml_int_array &rows) const
 Gets a set of rows defined by a ml_int_array.

ml_matrix get_col_set (int n_cols, int *cols) const
 Gets a set of columns defined by an array.

ml_matrix get_col_set (const ml_int_array &cols) const
 Gets a set of columns defined by a ml_int_array.

ml_matrix sub_mat_row (int row, int n_cols, int *cols) const
 Returns a submatrix based on a row and an array of columns.

ml_matrix sub_mat_row (int row, const ml_int_array &cols) const
 Returns a submatrix based on a row and a ml_int_array of columns.

ml_matrix sub_mat_col (int n_rows, int *rows, int col) const
 Returns a submatrix based on an array of rows and a single column.

ml_matrix sub_mat_col (const ml_int_array &rows, int col) const
 Returns a submatrix based on a ml_int_array of rows and a single column.

ml_matrix extract_elements (const ml_matrix &elements)
 Extracts a set of elements as a column matrix.

ml_matrixdelete_rows_cols (int n_rows, int *rows, int n_cols, int *cols)
 Deletes the rows and/or columns specified in the arrays.

ml_matrixdelete_rows_cols (const ml_int_array &rows, const ml_int_array &cols)
 Deletes the rows and/or columns specified in the ml_int_arrays.

ml_matrixdelete_rows_cols (int row, const ml_int_array &cols)
 Deletes the row and/or columns specified.

ml_matrixdelete_rows_cols (const ml_int_array &rows, int col)
 Deletes the rows and/or column specified.

ml_matrixdelete_rows_cols (int row, int col)
 Deletes the row and/or column specified.

ml_matrixinc_sub_matrix (const ml_matrix &m, int n_rows, int *rows)
 Inserts the given matrix values into the specified locations.

ml_matrixinc_sub_matrix (const ml_matrix &m, const ml_int_array &rows)
 Inserts the given matrix values into the specified locations.

ml_matrixinc_sub_matrix (const ml_matrix &m, int n_rows, int *rows, int n_cols, int *cols)
 Inserts the given matrix values into the specified locations.

ml_matrixinc_sub_matrix (const ml_matrix &m, const ml_int_array &rows, const ml_int_array &cols)
 Inserts the given matrix values into the specified locations.

ml_matrixinc_sub_matrix (const ml_matrix &m, int row, int n_cols, int *cols)
 Inserts the given matrix values into the specified locations.

ml_matrixinc_sub_matrix (const ml_matrix &m, int row, const ml_int_array &cols)
 Inserts the given matrix values into the specified locations.

ml_matrixinc_sub_matrix (const ml_matrix &m, int n_rows, int *rows, int col)
 Inserts the given matrix values into the specified locations.

ml_matrixinc_sub_matrix (const ml_matrix &m, const ml_int_array &rows, int col)
 Inserts the given matrix values into the specified locations.

ml_matrixinc_rows (const ml_matrix &a, int from_row, int to_row)
 Includes the specified rows from the given matrix into the original matrix.

ml_matrixinc_cols (const ml_matrix &m, int from_col, int to_col)
 Includes the specified columns from the given matrix into the original matrix.

ml_matrixinc_elements (const ml_matrix &values, const ml_matrix &elements)
 Incorporates a column matrix at the specified elements.

ml_matrixdup_rows (int num)
 Duplicates the rows of the matrix the specified number of times.

ml_matrixdup_cols (int num)
 Duplicates the columns of the matrix the specified number of times.

ml_matrixappend (const ml_matrix &b)
 Returns a new matrix with the columns from the two matrices appended side by side.

ml_matrixstack (const ml_matrix &b)
 Returns a new matrix with the rows from the second matrix stacked below the rows of the first matrix.

double * raw_data () const
 Access the raw representation of the matrix data.

int data_stride () const
 Access the stride used in the representation of the matrix.

int is_empty () const
 Checks for an empty matrix.

int operator== (const ml_matrix &m) const
 Tests two matrices for equality.

int operator!= (const ml_matrix &m) const
 Inequality function. Returns the opposite of the equality function.

ml_matrix find (ml_comparison op, double target) const
 Determines the indices of all elements for which a specified comparison and value are true.

void sort (int direction=0)
 Sorts all the elements of the matrix. Ascending order is the default, pass a non-zero value for descending sort.

ml_matrix sort_indices (int direction=0) const
 Returns the indices that produce a sorted version of the original matrix.

void permute (const ml_matrix &elements)
 Permute a matrix based on a return from sort_indices.

ml_matrix sum_rows () const
 Returns a column matrix containing the sums of the values from each row.

ml_matrix sum_cols () const
 Returns a row matrix containing the sums of the values from each column.

ml_matrix max () const
 Finds the value and indices of the largest element in the matrix.

ml_matrix row_max () const
 Finds the maximum value and index for each row in the matrix.

ml_matrix col_max () const
 Finds the maximum value and index for each column in the matrix.

ml_matrix min () const
 Finds the value and indices of the smallest element in the matrix.

ml_matrix row_min () const
 Finds the minimum value and index for each row in the matrix.

ml_matrix col_min () const
 Finds the minimum value and index for each column in the matrix.

ml_matrix interpolate (int col, double value) const
 Linear interpolation based on the specified column.

int rows () const
 Returns the number of rows in the matrix.

int cols () const
 Returns the number of columns in the matrix.

ml_matrixoperator= (const ml_matrix &m)
 Sets matrix equal to another matrix.

ml_matrixoperator= (const char *s)
 Assigns the MATLAB string representation of a matrix to this matrix.

void zero ()
 Replaces all values in the matrix with zero.

void ones ()
 Replaces all values in the matrix with one.

void set_val (double v)
 Replaces all values in the matrix with the given value.

void set_val (const ml_matrix &elements, double v)
 Replaces all values at the specified indices in the matrix with a given value.

ml_matrixapply (double(*func)(double))
 Applies a specified function to every element in the matrix.

void apply_to_elements (const ml_matrix &elements, double(*func)(double))
 Applies a specified function to a subset of the elements in the matrix.

void identity ()
 Changes the matrix to an identity matrix.

void rand_seed (double seed)
 Sets the random seed for this matrix.

void rand ()
 Replaces all values in the matrix with randomly generated values.

void randn (double std_dev)
 Replaces all values in the matrix with randomly generated values, given a standard deviation.

ml_matrixoperator *= (const ml_matrix &m)
 Matrix multiplication operator.

ml_matrixoperator *= (double a)
 Scalar multiplication operator.

ml_matrixdotstar_eq (const ml_matrix &m)
 Element by element multiplication, inserting the results into the original matrix.

ml_matrixoperator/= (const ml_matrix &m)
 Matrix division operator.

ml_matrixoperator/= (double a)
 Scalar division operator.

ml_matrixdotslash_eq (const ml_matrix &m)
 Element by element division, inserting the results into the original matrix.

ml_matrixoperator+= (const ml_matrix &m)
 Matrix addition operator, adds corresponding elements.

ml_matrixoperator+= (double a)
 Scalar addition operator.

ml_matrixoperator-= (const ml_matrix &m)
 Matrix subtraction operator, adds corresponding elements.

ml_matrixoperator-= (double a)
 Scalar subtraction operator.

ml_matrixabs ()
 Absolute value function - changes all values in the matrix to the absolute value of the element.

ml_matrixceil ()
 Changes each element to the smallest integer greater than or equal to that element.

ml_matrixfloor ()
 Changes each element to the largest integer less than or equal to that element.

ml_matrixround ()
 Rounds each element to the nearest integral value, rounding half-way cases away from zero.

ml_matrixrint ()
 Rounds each element to the nearest integral value according to the prevailing rounding mode.

ml_matrixdotpow (double n)
 Raises each element of the matrix to the given power.

ml_matrixsqrt ()
 Sets each element equal to its square root.

ml_matrixexp ()
 Computes the base-e exponential of each element in the matrix.

ml_matrixexpm1 ()
 Computes the base-e exponential of each element in the matrix, minus 1.

ml_matrixlog ()
 Computes the natural logarithm of each element in the matrix.

ml_matrixlog10 ()
 Computes the logarithm of each element in the matrix to base 10.

ml_matrixlog1p ()
 Computes the natural logarithm of each element in the matrix plus 1.

ml_matrixlog2 ()
 Computes the logarithm of each element in the matrix to base 2.

ml_matrixlogb ()
 Computes the exponent of each element in the matrix.

ml_matrixtranspose ()
 Transposes the matrix.

ml_matrixinv ()
 Finds the inverse of the matrix. Principally used for matrix division.

ml_matrix invp (const ml_matrix &n, int k) const
 Returns the product form of the matrix inverse.

ml_matrixmpow (int n)
 Returns a matrix raised to a power.

ml_matrix diag () const
 Creates a diagonal matrix from a row or column matrix, or creates a row matrix from a diagonal matrix.

double trace () const
 Returns the trace of the matrix.

ml_matrix mag () const
 Returns a row matrix containing the magnitudes of each column of the matrix.

double vmag () const
 Returns the magnitude of a column or row matrix.

ml_matrixcross (const ml_matrix &n)
 Crosses the matrix with the given matrix.

double dot (const ml_matrix &n) const
 Takes the dot product of two column vectors.

ml_matrix skew_symm () const
 Creates a skew symmetric matrix from a vector of three numbers.

ml_matrixunit ()
 Makes each column into a row vector.

ml_matrixsign ()
 Changes all positive elements into 1, all negative elements into -1.

ml_matrixvunit ()
 Unitize a vector matrix by dividing by its vector magnitude.

double norm () const
 Returns the normal of the matrix (largest singular value).

ml_matrixsolve_ax_eq_b (const ml_matrix &a)
 Solve the general system of linear equations AX=B.

ml_matrixrow_mult (int row, double fac)
ml_matrixsin ()
 Returns the element by element sin of the matrix.

ml_matrixcos ()
 Returns the element by element cosine of the matrix.

ml_matrixtan ()
 Returns the element by element tangent of the matrix.

ml_matrixcsc ()
 Returns the element by element cosecant of the matrix.

ml_matrixsec ()
 Returns the element by element secant of the matrix.

ml_matrixcot ()
 Returns the element by element cotangent of the matrix.

ml_matrixasin ()
 Returns the element by element arcsine of the matrix.

ml_matrixacos ()
 Returns the element by element arccosine of the matrix.

ml_matrixatan ()
 Returns the element by element arctangent of the matrix.

ml_matrixacsc ()
 Returns the element by element arccosecant of the matrix.

ml_matrixasec ()
 Returns the element by element arcsecant of the matrix.

ml_matrixacot ()
 Returns the element by element arccotangent of the matrix.

ml_matrixsinh ()
 Returns the element by element hyperbolic sine of the matrix.

ml_matrixcosh ()
 Returns the element by element hyperbolic cosine of the matrix.

ml_matrixtanh ()
 Returns the element by element hyperbolic tangent of the matrix.

ml_matrixcsch ()
 Returns the element by element hyperbolic cosecant of the matrix.

ml_matrixsech ()
 Returns the element by element hyperbolic secant of the matrix.

ml_matrixcoth ()
 Returns the element by element hyperbolic cotangent of the matrix.

ml_matrixasinh ()
 Returns the element by element hyperbolic arcsine of the matrix.

ml_matrixacosh ()
 Returns the element by element hyperbolic arccosine of the matrix.

ml_matrixatanh ()
 Returns the element by element hyperbolic arctangent of the matrix.

ml_matrixacsch ()
 Returns the element by element hyperbolic arccosecant of the matrix.

ml_matrixasech ()
 Returns the element by element hyperbolic arcsecant of the matrix.

ml_matrixacoth ()
 Returns the element by element hyperbolic arccotangent of the matrix.

ml_matrixatan2 (const ml_matrix &m)
 Returns the element by element arctangent"2" of the matrix with respect to the 2nd matrix.


Public Attributes

int error
 The current error status of the matrix.