Data Structures | Enumerations | Functions

Matrix - Matrix creates and manipulates data in 1D and 2D matrix form.
[Supporting Modules]

Data Structures

struct  MATRIX
struct  VECTOR

Enumerations

enum  MatrixType { REAL, COMPLEX, BOOL }
enum  MatrixOrder { ROW_MAJOR, COL_MAJOR }

Functions

MATRIX fftw (fits2d function)
MATRIX fftwReverse (MATRIX function, bool shift)
MATRIX fftwShift (MATRIX m)
MATRIX ifftwShift (MATRIX m)
MATRIX linearEqSolve (MATRIX A, MATRIX B)
MATRIX LinearEqSolveNRHS (MATRIX A, MATRIX B)
void linearEqSolveCleanup ()
MATRIX linearEqSolveCholesky (MATRIX A, MATRIX B)
MATRIX linearEqSolveSvd (MATRIX A, MATRIX B)
MASK newMask (int r, int c, int m)
MATRIX newMatrix (int r, int c)
MATRIX newMatrixI (int r, int c, void *Idata, MatrixType mType)
MATRIX newComplexMatrix (int r, int c)
MATRIX newMatrixG (int r, int c, MatrixType mType)
MATRIX newMatrixGI (int r, int c, void *Idata, MatrixType mType)
VECTOR newVector (int n)
void freeMatrix (MATRIX m)
void freeVector (VECTOR v)
MATRIX newRandomMatrix (int r, int c)
MATRIX multiplyMM2 (char TransA, char TransB, MATRIX A, MATRIX B)
MATRIX multiplyMMFull (char TransA, char TransB, Float alpha, Float beta, MATRIX A, MATRIX B)
MATRIX multiplyScalar (MATRIX m, Float scalar)
MATRIX multiplyScalarZ (MATRIX m, FloatComplex scalar)
FloattoRowMajor (Float *A, int R, int C)
FloattoColumnMajor (Float *AT, int R, int C)
MATRIX toColumnMajor2 (MATRIX m)
MATRIX toRowMajor2 (MATRIX m)
MATRIX toMatrix (fits2d f)
VECTOR toVector (fits2d f)
fits2d toFitsObject (VECTOR v)
fits2d MatrixToFitsObject (MATRIX m)
fits3d MatrixToFits3dObject (MATRIX m)
MATRIX expandDiagonalMatrix (VECTOR v)
MATRIX transpose (MATRIX m)
MATRIX conjugate (MATRIX m)
MATRIX matrix_copy (MATRIX m)
MATRIX inverseD (MATRIX m)
MATRIX inverse (MATRIX m)
MATRIX Cholesky (MATRIX m)
MATRIX ConvertToReal (MATRIX m)
MATRIX ConvertToComplex (MATRIX m)
bool isIdentity (MATRIX m)
VECTOR MatrixToVector (MATRIX m)
MATRIX VectorToMatrix_Column (VECTOR v)
void insertVector (Float *to, VECTOR from)
void APlusLambdaB (MATRIX A, Float lambda, MATRIX B, MATRIX C)
FloatComplex Norm2 (MATRIX m)
MATRIX BItimesV (MATRIX B, MATRIX V)
void splitMatrix (MATRIX m, MATRIX *real, MATRIX *imag)
void mergeMatrix (MATRIX *m, MATRIX real, MATRIX imag)
void setToNaN (VECTOR v)
void setToNaNMatrix (MATRIX m)
VECTOR readText (char *inputFilename)
void print_matrix (char *desc, int m, int n, Float *a, int lda, MatrixOrder order)
void print_matrix2 (char *desc, MATRIX m, MatrixOrder order)
void print_matrix2toFile (char *desc, MATRIX m, MatrixOrder order)
int tdSetup1d (MATRIX aM, MATRIX ad, MATRIX aR, MATRIX aCI, MATRIX aC)
void tdinvert3dFinish (Float lambda, TempData *tempData, bool debug, BaseDirectory *debugFilename)
void tdinvert1dFinish (Float lambda, int nStep, Model *model, bool debug, BaseDirectory *debugFilename)
void tdCleanup ()

Enumeration Type Documentation

MatrixOrder designates the layout of data in a matrix.

Enumerator:
ROW_MAJOR 
COL_MAJOR 
enum MatrixType

Type of data kept in matrix: either Real (Float) or complex (FloatComplex)

Enumerator:
REAL 
COMPLEX 
BOOL 

Function Documentation

void APlusLambdaB ( MATRIX  A,
Float  lambda,
MATRIX  B,
MATRIX  C 
)

Calculate A + lambda * B = C

Parameters:
[in] A A matrix.
[in] B A matrix.
[in] lambda A scalar value.
[in,out] C The result matrix.
MATRIX BItimesV ( MATRIX  B,
MATRIX  V 
)

Calculate$F=B^{-1} V$ by solving BF = V for F then solving system of linear equations k times where k is the number of columns in V.

Parameters:
[in] B A matrix.
[in] V A matrix.
Returns:
The resulting matrix, F.
MATRIX Cholesky ( MATRIX  m  ) 

Cholesky factorization of a symmetric, positive, definite matrix.

Parameters:
[in] m is a matrix to factor.
Returns:
An upper triangular matrix that is the Cholesky factorization of the matrix, m.
MATRIX conjugate ( MATRIX  m  ) 

Take the complex conjugate of a matrix. Returns a new matrix.

Parameters:
[in] m Take complex conjugate of this matrix.
Returns:
New matrix containing conjugate of original matrix.
MATRIX ConvertToComplex ( MATRIX  m  ) 

Convert a real matrix to a complex matrix.

Parameters:
[in] m A real matrix.
Returns:
A complex matrix.
MATRIX ConvertToReal ( MATRIX  m  ) 

Convert a complex matrix to a real matrix. If the imaginary part of the complex matrix elements is nearly zero, the conversion proceeds. Otherwise, an error is thrown.

Parameters:
[in] m A complex matrix.
Returns:
A real matrix.
MATRIX expandDiagonalMatrix ( VECTOR  v  ) 

Expand a compact representation of a diagonal matrix.

Parameters:
[in] v A vector containing the diagonal elements of a matrix.
Returns:
A diagonal matrix with diagonal elements taken from input vector.
MATRIX fftw ( fits2d  function  ) 

fftw Performs a forward Fourier transform using the Fasted Fourier Transform in the West (FFTW) library.

Parameters:
[in] function A fits2d object which contains data values for a function to transform.
Returns:
A MATRIX object containing the transformed data.
MATRIX fftwReverse ( MATRIX  function,
bool  shift 
)

fftwReverse Performs an inverse Fourier transform using the Fasted Fourier Transform in the West (FFTW) library.

Parameters:
[in] function A MATRIX object which contains data values for a function to transform.
[in] shift A boolean value whether to shift the data values. true means shift the values. false means no shift.
Returns:
A MATRIX object containing the transformed data.
MATRIX fftwShift ( MATRIX  m  ) 

fftwShift shifts data values after a reverse transform. Because of the way FFTW performs the Fourier transform, the data sometimes needs to be shifted.

Parameters:
[in] m A MATRIX containing data to shift.
Returns:
A MATRIX containing shifted data.
void freeMatrix ( MATRIX  m  ) 

Free memory that stores matrix data. The matrix structure is not released.

Parameters:
[in] m matrix with data to free.
void freeVector ( VECTOR  v  ) 

Free memory that stores vector data. The vector structure is not released.

Parameters:
[in] v Vector with data to free.
MATRIX ifftwShift ( MATRIX  m  ) 

ifftwShift (use for odd size matrix) shifts data values after a reverse transform. Because of the way FFTW performs the Fourier transform, the data sometimes needs to be shifted.

Parameters:
[in] m A MATRIX containing data to shift.
Returns:
A MATRIX containing shifted data.
void insertVector ( Float to,
VECTOR  from 
)

Insert a vector into an array.

Parameters:
[in,out] to An array.
[in] from A vector of data to insert.
MATRIX inverse ( MATRIX  m  ) 

Inverse of a general matrix.

Parameters:
[in] m A matrix.
Returns:
The inverse of the matrix. If an error occurs during the inversion, the matrix returned has data = NULL, and dimensions are -1.
MATRIX inverseD ( MATRIX  m  ) 

Inverse of a diagonal matrix is 1/aii, where aii are the diagonal elements

Parameters:
[in] m A diagonal matrix.
Returns:
The inverse of the matrix
bool isIdentity ( MATRIX  m  ) 

Identify a matrix as the identity matrix.

Parameters:
[in] m A real matrix.
Returns:
True if the diagonal elements are unity and all other elements are zero.
MATRIX linearEqSolve ( MATRIX  A,
MATRIX  B 
)

Solve Ax=B for x.

Parameters:
[in] A Matrix
[in] B Matrix
Returns:
A Matrix containing the solution x.
MATRIX linearEqSolveCholesky ( MATRIX  A,
MATRIX  B 
)

Solve Ax=B for x.

Parameters:
[in] A Matrix
[in] B Matrix
Returns:
A Matrix containing the solution x.
void linearEqSolveCleanup (  ) 

Free memory allocated for LUDecomp and IPiv intermediate values.

MATRIX LinearEqSolveNRHS ( MATRIX  A,
MATRIX  B 
)

Using this function requires first calling linearEqSolve to calculate the LUDecomp of Matrix A. Solves set of linear equations with multiple right-hand sides, i.e. the number of columns of matrix B.

Parameters:
[in] A Matrix
[in] B Matrix
Returns:
A Matrix containing the solution x.
MATRIX linearEqSolveSvd ( MATRIX  A,
MATRIX  B 
)

Solve Ax=B for x, using SVD.

Parameters:
[in] A Matrix
[in] B Matrix
Returns:
A Matrix containing the solution x.
MATRIX matrix_copy ( MATRIX  m  ) 

Return a copy of a matrix. Returns a new matrix.

Parameters:
[in] m A matrix.
Returns:
New matrix containing copy of original matrix.
fits3d MatrixToFits3dObject ( MATRIX  m  ) 

Convert from a Matrix object to a fits3d object.

Parameters:
[in] m A matrix.
Returns:
The converted matrix as a fits3d object.
fits2d MatrixToFitsObject ( MATRIX  m  ) 

Convert from a Matrix object to a fits2d object.

Parameters:
[in] m A matrix.
Returns:
The converted matrix as a fits2d object; i.e. a 2-d array with different member names and always data of type Float.
VECTOR MatrixToVector ( MATRIX  m  ) 

Convert a matrix where one dimension is unity to a vector.

Parameters:
[in] m A matrix with either 1 row or 1 column.
Returns:
The matrix as a vector equivalent.
void mergeMatrix ( MATRIX m,
MATRIX  real,
MATRIX  imag 
)

Build a complex matrix from separate real and imaginary parts.

Parameters:
[in,out] m A complex matrix.
[in] real A matrix containing real part.
[in] imag A matrix containing imaginary part.
MATRIX multiplyMM2 ( char  TransA,
char  TransB,
MATRIX  A,
MATRIX  B 
)

Multiply two matrices and return a new matrix containing the product of AB. data.

Parameters:
[in] TransA Letter 'N', 'T', or 'C', for no transpose, transpose, and conjugate transpose.
[in] TransB Letter 'N', 'T', or 'C', for no transpose, transpose, and conjugate transpose.
[in] A Matrix A
[in] B Matrix B
Returns:
A new matrix AB
MATRIX multiplyMMFull ( char  TransA,
char  TransB,
Float  alpha,
Float  beta,
MATRIX  A,
MATRIX  B 
)

Multiply two matrices and return a new matrix containing the product of AB. data. C = alpha A x B + beta C

Parameters:
[in] TransA Letter 'N', 'T', or 'C', for no transpose, transpose, and conjugate transpose.
[in] TransB Letter 'N', 'T', or 'C', for no transpose, transpose, and conjugate transpose.
[in] alpha Multiply matrix A by scalar alpha.
[in] beta Multiply matrix C by scalar beta.
[in] A Matrix A
[in] B Matrix B
Returns:
A new matrix AB
MATRIX multiplyScalar ( MATRIX  m,
Float  scalar 
)

multiply matrix by a scalar value

Parameters:
[in] m A Matrix.
[in] scalar A single value.
Returns:
The resulting matrix.
MATRIX multiplyScalarZ ( MATRIX  m,
FloatComplex  scalar 
)

multiply matrix by a scalar value

Parameters:
[in] m A Matrix.
[in] scalar A single value.
Returns:
The resulting matrix.
MATRIX newComplexMatrix ( int  r,
int  c 
)

Creates a new matrix of FloatComplex values and allocates space for data.

Parameters:
[in] r The number of rows
[in] c The number of columns
Returns:
A new matrix
MASK newMask ( int  r,
int  c,
int  m 
)

Creates a new 3D matrix and allocates space for the data of type boolean

Parameters:
[in] r number of rows
[in] c number of columns
[in] m number of masks; corresponds to the number of maps
Returns:
A new matrix
MATRIX newMatrix ( int  r,
int  c 
)

Creates a new matrix and allocates space for the data of type Float

Parameters:
[in] r number of rows
[in] c number of columns
Returns:
A new matrix
MATRIX newMatrixG ( int  r,
int  c,
MatrixType  mType 
)

Creates a new matrix of FloatComplex values and allocates space for data.

Parameters:
[in] r The number of rows
[in] c The number of columns
[in] mType REAL, COMPLEX, BOOL, see MatrixType
Returns:
A new matrix
MATRIX newMatrixGI ( int  r,
int  c,
void *  Idata,
MatrixType  mType 
)

Creates a new matrix and initializes the data to array sent

Parameters:
[in] r number of rows
[in] c number of columns
[in] Idata point to initial data values
[in] mType MatrixType either REAL, COMPLEX, or BOOL
Returns:
A new matrix
MATRIX newMatrixI ( int  r,
int  c,
void *  Idata,
MatrixType  mType 
)

Creates a new matrix and initializes the data to array sent

Parameters:
[in] r number of rows
[in] c number of columns
[in] Idata point to initial data values
[in] mType MatrixType either REAL or COMPLEX
Returns:
A new matrix
MATRIX newRandomMatrix ( int  r,
int  c 
)

Creates a new matrix of random numbers and allocates space for the data of type FloatComplex. NOTE: the seed for the random number generator is set separately.

Parameters:
[in] r number of rows
[in] c number of columns
Returns:
A new matrix
VECTOR newVector ( int  n  ) 

Creates a new VECTOR.

Parameters:
[in] n the size of the vector
Returns:
A new VECTOR object.
FloatComplex Norm2 ( MATRIX  m  ) 

Calculate the ||M||_2 of a matrix, M.

Parameters:
[in] m A matrix.
Returns:
The second norm of matrix.
void print_matrix ( char *  desc,
int  m,
int  n,
Float a,
int  lda,
MatrixOrder  order 
)

Print a matrix.

Parameters:
[in] desc A description or name of the matrix.
[in] m The number of rows in the matrix.
[in] n The number of columns in the matrix.
[in] a An array of the data in the matrix.
[in] lda Leading dimension of the matrix.
[in] order Layout of the matrix data, either row-major or column-major.
void print_matrix2 ( char *  desc,
MATRIX  m,
MatrixOrder  order 
)

Print a matrix.

Parameters:
[in] desc A description or name of the matrix.
[in] m A matrix.
[in] order Layout of the matrix data, either row-major or column-major.
void print_matrix2toFile ( char *  desc,
MATRIX  m,
MatrixOrder  order 
)

Print a matrix to a file.

Parameters:
[in] desc A description or name of the matrix. This is also the name of the file.
[in] m A matrix.
[in] order Layout of the matrix data, either row-major or column-major.
VECTOR readText ( char *  inputFilename  ) 

Read a vector from a file Format of the file can be eol, tab, comma, space, separated list of numbers

Parameters:
[in] inputFilename Name of file to read.
Returns:
Vector object containing data from file.
void setToNaN ( VECTOR  v  ) 

Set a vector to NaN.

Parameters:
[in,out] v A vector.
void setToNaNMatrix ( MATRIX  m  ) 

Set a matrix to NaN.

Parameters:
[in,out] m A matrix.
void splitMatrix ( MATRIX  m,
MATRIX real,
MATRIX imag 
)

Split a complex matrix into real and imaginary parts.

Parameters:
[in] m A complex matrix.
[in,out] real A matrix containing real part.
[in,out] imag A matrix containing imaginary part.
void tdCleanup (  ) 

free memory used by static variables internal to inversion

void tdinvert1dFinish ( Float  lambda,
int  nStep,
Model model,
bool  debug,
BaseDirectory debugFilename 
)

Completes the inversion calculation. By sending the individual lambda values the inversion calculation is finished.

Parameters:
[in] lambda regularization parameter
[in] nStep Nth step in lambda-parameter range
[in] debug Flag to print intermediate matrices during inversion
[in] debugFilename Base directory and filename for intermediate, debug values.
[in,out] model Model structure contains all calculated solutions including averaging kernel and error covariance.
void tdinvert3dFinish ( Float  lambda,
TempData tempData,
bool  debug,
BaseDirectory debugFilename 
)

Completes the inversion calculation. By sending the individual lambda values the inversion calculation is finished.

Parameters:
[in] lambda regularization parameter
[in] debug Flag to print intermediate matrices during inversion
[in] debugFilename Base directory and filename for intermediate, debug values.
[in,out] tempData TempData structure contains all calculated solutions including averaging kernel and error covariance for one wave number.
int tdSetup1d ( MATRIX  aM,
MATRIX  ad,
MATRIX  aR,
MATRIX  aCI,
MATRIX  aC 
)

tdSetup calculates all the non-changing, static matrices

Parameters:
[in] aM Kernel matrix
[in] ad map data
[in] aR Regularization matrix; symmetric positive-definite matrix
[in] aCI Inverse of matrix C, a noise covariance matrix
[in] aC matrix C, a noise covariance matrix
Float* toColumnMajor ( Float AT,
int  R,
int  C 
)

Copy a 2D array in row-major layout return the copy in column-major layout.

Parameters:
[in] AT The array of data in row-major layout.
[in] R The number of rows.
[in] C The number of columns.
Returns:
A 2D array in column-major layout.
MATRIX toColumnMajor2 ( MATRIX  m  ) 

Copy a matrix stored in row-major order and convert it to column-major order.

Parameters:
[in] m A row-major matrix
Returns:
A copy of matrix m with column-major layout of data.
fits2d toFitsObject ( VECTOR  v  ) 

Convert from a Vector object to a fits2d object.

Parameters:
[in] v A vector
Returns:
The converted vector as a fits2d object; i.e. a 2-d array with different member names and always data of type Float.
MATRIX toMatrix ( fits2d  f  ) 

Convert a fits2d object to a Matrix object.

Parameters:
[in] f A fits2d object; i.e. a 2-d array with different member names and always data of type Float.
Returns:
The converted object as a matrix.
Float* toRowMajor ( Float A,
int  R,
int  C 
)

Copy a 2D array in column-major layout return the copy in row-major layout.

Parameters:
[in] A The array of data in column-major layout.
[in] R The number of rows.
[in] C The number of columns.
Returns:
A 2D array in row-major layout.
MATRIX toRowMajor2 ( MATRIX  m  ) 

Copy a matrix stored in column-major order and convert it to row-major order.

Parameters:
[in] m A column-major matrix
Returns:
A copy of matrix n with row-major layout of data.
VECTOR toVector ( fits2d  f  ) 

Convert a fits2d object to a Vector object.

Parameters:
[in] f A fits2d object; i.e. a 2-d array with different member names and always data of type Float.
Returns:
The converted object as a vector.
MATRIX transpose ( MATRIX  m  ) 

Transpose a matrix.

Parameters:
[in] m A matrix.
Returns:
The transpose of the matrix.
MATRIX VectorToMatrix_Column ( VECTOR  v  ) 

Convert vector to a matrix with a single column vector.

Parameters:
[in] v A vector.
Returns:
A matrix containing the vector as a column.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines