Construction and I/O
[Modules]

Matrix constructors and outputs to string and binary forms. More...

Functions

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

 ml_matrix::ml_matrix (const ml_matrix &m)
 Copy constructor.

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

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

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

 ml_matrix::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::ml_matrix (void *bf)
 Constructs a matrix from a binary format as created by ml_matrix::to_binary().

 ml_matrix::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::~ml_matrix ()
 Destructor.

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

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

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

ml_matrix linspace (double start, double finish, int n)
 Creates a linearly spaced vector with n points between two values.

ml_matrix colon (double start, double incr, double end)
 Creates a vector using a fixed increment between two points.


Detailed Description

These functions permit matrices to be initialized in a variety of ways and provide matrix display, conversion to string for I/O, and conversion to binary format for efficient interprocess communication and across networks.

Function Documentation

ml_matrix::ml_matrix  )  [inherited]
 

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

ml_matrix::ml_matrix const ml_matrix m  )  [inline, inherited]
 

Creates a copy of a matrix.

Parameters:
m The matrix to be copied.

ml_matrix::ml_matrix int  rows,
int  cols = 1
[inline, inherited]
 

Creates a matrix and sets all elements to 0

Parameters:
rows The number of rows for the new matrix
cols The number of columns for the new matrix, default to 1

ml_matrix::ml_matrix int  rows,
int  cols,
double  value
[inherited]
 

Creates a matrix with all values equal to v

Parameters:
rows The number of rows for the new matrix
cols The number of columns for the new matrix
value The value for all elements of the new matrix

ml_matrix::ml_matrix int  rows,
int  cols,
double *  v
[inherited]
 

Constructor which builds a matrix from a given array

Parameters:
rows The number of rows for the new matrix
cols The number of columns for the new matrix
v The array to build the matrix from, with values listed row by row

ml_matrix::ml_matrix const char *  s  )  [inherited]
 

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

This function can return an error matrix of type ml_bad_string_format if the provided string is not a properly formatted matrix.

Parameters:
s Character string used to build the matrix.

ml_matrix::ml_matrix void *  bf  )  [inherited]
 

Constructs a matrix from a binary format as created by ml_matrix::to_binary(). By far the most efficient way to send matrix data over a network or transfer between applications is using the binary format, though it is possible to also use the string format as well.

This function can return an error matrix of type ml_invalid_buffer if the provided binary buffer does not contain a valid binary-format buffer.

Parameters:
bf Binary string used to build the matrix.

ml_matrix::ml_matrix FILE *  f,
int *  linenum = NULL
[inherited]
 

Constructs a matrix from a string format as used in MATLAB or created by ml_matrix::to_string(). The string is read from the provided file.

This function can return an error matrix of type ml_bad_file_pointer if the provided file is NULL, or of type ml_bad_string_format if the file does not contain a valid string-format matrix.

Parameters:
f The file used to read the matrix from.
linenum A pointer to an int giving the current line number within the file. The number will be incremented each time a newline character is encountered.

char * ml_matrix::to_string int  human_readable = 0  )  [inherited]
 

Returns a character string representation of the matrix

Parameters:
human_readable if nonzero, includes spaces and newlines to make the matrix easy for a human reader to view. If zero, removes extraneous spaces and newlines to represent the matrix in a more compact, one-line representation that is easier to parse. Note that the matrix constructor can read either version.
Returns:
String representation of the matrix in "MATLAB readable" format

void ml_matrix::display char *  s = NULL  )  [inherited]
 

Display function. Formats the matrix in a human readable fashion and prints to standard out.

void * ml_matrix::to_binary unsigned int *  size = NULL  )  const [inherited]
 

Creates binary representation of matrix for efficient transfer. This function allocates memory that must be freed by the caller.

Parameters:
size Pointer to an integer in which to place the size of the allocated buffer or NULL if the caller is not interested in the size.
Returns:
Returns a byte array representation of the matrix.

ml_matrix linspace double  start,
double  finish,
int  n
 

Creates a linearly spaced vector with n points between two values.

Parameters:
start Initial value.
finish Final value.
n Number of points.
Returns:
Returns a linearly spaced vector.

ml_matrix colon double  start,
double  incr,
double  end
 

Creates a vector using a fixed increment between two points.

Parameters:
start Initial value.
incr Increment value.
end Final value.
Returns:
Returns a vector of the form start:incr:end.