Conjugate Gradient
Typedefs | Functions
cg_impls.h File Reference

Headers for function prototypes and typedefs. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef void(* Aop) (void *, int, const double *, int, double *, int)
 The prototype of all matrix-vector operators. It requires six parameters and has no return value. More...
 

Functions

int rb_dcgsv (int, Aop, void *, const double *, double *)
 Solves a linear system using conjugate method. More...
 
void rb_dscal (int, double, double *, int)
 Scales a vector by a constant. $x\leftarrow ax$. More...
 
void rb_daxpy (int, double, const double *, int, double *, int)
 Scale a vector X by a constant add add it to another vector Y. $y\leftarrow y+ax$. More...
 
double rb_damax (int, const double *, int)
 Finds the element in X which has the maximum absolute value. More...
 
double rb_ddot (int, const double *, int, const double *, int)
 Perform inner product $x^Ty$. More...
 
void rb_dsub (int, const double *, int, const double *, int, double *, int)
 Perform vector substraction, i.e. $z=x-y$. More...
 
void rb_dcopy (int, const double *, int, double *, int)
 Copy a vector to another. More...
 

Detailed Description

Headers for function prototypes and typedefs.

Typedef Documentation

typedef void(* Aop)(void *, int, const double *, int, double *, int)

The prototype of all matrix-vector operators. It requires six parameters and has no return value.

Parameters
ctxtType void*. All necessary contexts needed by the operator.
nType int. the length of X and Y.
XType const double*. The pointer to the storage of X.
incxType int. The increment of indices of X.
YType double*. Input/Output. The pointer to the storage of Y.
incyType int. The increment of indices of Y.

Function Documentation

double rb_damax ( int  n,
const double *  X,
int  incx 
)

Finds the element in X which has the maximum absolute value.

Parameters
nThe length of X.
XThe pointer to the storage of X.
incxThe increment of indices of X.
Returns
The element which has the maximum absolute value
void rb_daxpy ( int  n,
double  a,
const double *  X,
int  incx,
double *  Y,
int  incy 
)

Scale a vector X by a constant add add it to another vector Y. $y\leftarrow y+ax$.

Parameters
nThe length of X and Y.
aThe scaling constant.
XThe pointer to the storage of X.
incxThe increment of indices of X.
YInput/Output. The pointer to the storage of Y.
incyThe increment of indices of Y.
int rb_dcgsv ( int  n,
Aop  A,
void *  ctxt,
const double *  b,
double *  sol 
)

Solves a linear system using conjugate method.

Parameters
nThe dimension of A.
AThe function pointer of type Aop.
ctxtThe context needed by A.
bThe right hand side of $Ax=b$.
solOutput. The computed solution of the equation.
Returns
The number of iterations in the conjugate method.

The function rb_dcgsv solves the linear system $Ax=b$ with conjugate gradient method. It requires $A$ to be positive definite.

Conjugate gradient method doesn't need the matrix $A$ to be given explicitly. It only needs $A$ when applying it to a vector. That is, the user only has to tell how to perform $y\leftarrow Ax$, by providing the parameter of type Aop and all the context needed by the operator.

void rb_dcopy ( int  n,
const double *  X,
int  incx,
double *  Y,
int  incy 
)

Copy a vector to another.

Parameters
nThe length of X and Y.
XThe pointer to the storage of X.
incxThe increment of indices of X.
YThe pointer to the storage of Y.
incyThe increment of indices of Y.
double rb_ddot ( int  n,
const double *  X,
int  incx,
const double *  Y,
int  incy 
)

Perform inner product $x^Ty$.

Parameters
nThe length of X and Y.
XThe pointer to the storage of X.
incxThe increment of indices of X.
YThe pointer to the storage of Y.
incyThe increment of indices of Y.
Returns
The inner product.
void rb_dscal ( int  n,
double  a,
double *  X,
int  incx 
)

Scales a vector by a constant. $x\leftarrow ax$.

Parameters
nThe length of X.
aThe scaling factor.
XThe pointer to the storage of X.
incxThe increment of indices.
void rb_dsub ( int  n,
const double *  X,
int  incx,
const double *  Y,
int  incy,
double *  Z,
int  incz 
)

Perform vector substraction, i.e. $z=x-y$.

Parameters
nThe length of X and Y.
XThe pointer to the storage of X.
incxThe increment of indices of X.
YThe pointer to the storage of Y.
incyThe increment of indices of Y.
ZOutput. The pointer to the storage of Z.
incyThe increment of indices of Z.