amino  1.0-beta2
Lightweight Robot Utility Library
mat.h File Reference

Block matrix descriptors and linear algebra operations. More...

#include <cblas.h>

Go to the source code of this file.

Classes

struct  aa_dvec
 Descriptor for a vector. More...
 
struct  aa_dmat
 Descriptor for a block matrix. More...
 

Macros

#define AA_DVEC_REF(v, i)   ((v)->data[(i) * (v)->inc])
 Return an element of a dvec. More...
 
#define AA_DMAT_REF(M, i, j)   (((M)->data)[(M)->ld*(j) + (i)])
 Reference a matrix entry. More...
 
#define AA_VEC_ARGS(X)   (X->data), ((int)(X->inc))
 BLAS arguments for a vector.
 
#define AA_MAT_ARGS(X)   (X->data), ((int)(X->ld))
 BLAS arguments for a matrix.
 
#define AA_MAT_DIAG(VEC, MAT)    aa_dvec_view((VEC), (MAT)->cols, (MAT)->data, 1+(MAT)->ld);
 Set VEC to a descriptor for the diagonal vector of MAT.
 

Typedefs

typedef size_t aa_la_size
 Type for sizes of vectors and matrices.
 
typedef void() aa_la_err_fun(const char *message)
 Callback type for linear algebra errors.
 

Functions

AA_API void aa_la_err (const char *message)
 Default handler function for linear algebra errors.
 
AA_API void aa_la_set_err (aa_la_err_fun *fun)
 Set the handler function for linear algebra errors.
 
static struct aa_dvec AA_DVEC_INIT (aa_la_size len, double *data, aa_la_size inc)
 Fill in a vector descriptor. More...
 
static void AA_DVEC_VIEW (struct aa_dvec *vec, aa_la_size len, double *data, aa_la_size inc)
 Fill in a vector descriptor. More...
 
AA_API void aa_dvec_view (struct aa_dvec *vec, aa_la_size len, double *data, aa_la_size inc)
 Fill in a vector descriptor. More...
 
AA_API void aa_dmat_view (struct aa_dmat *mat, aa_la_size rows, aa_la_size cols, double *data, aa_la_size ld)
 Fill in a matrix descriptor. More...
 
AA_API void aa_dmat_view_block (struct aa_dmat *dst, const struct aa_dmat *src, aa_la_size row_start, aa_la_size col_start, aa_la_size rows, aa_la_size cols)
 View a block of a matrix.
 
AA_API void aa_dvec_slice (const struct aa_dvec *src, aa_la_size start, aa_la_size stop, aa_la_size step, struct aa_dvec *dst)
 View a slice of a vector.
 
AA_API void aa_dmat_block (const struct aa_dmat *src, aa_la_size row_start, aa_la_size col_start, aa_la_size row_end, aa_la_size col_end, struct aa_dmat *dst)
 View a block of a matrix.
 
AA_API void aa_dmat_row_vec (const struct aa_dmat *src, aa_la_size row, struct aa_dvec *dst)
 View a row of a matrix as a vector.
 
AA_API void aa_dmat_col_vec (const struct aa_dmat *src, aa_la_size col, struct aa_dvec *dst)
 View a column of a matrix as a vector.
 
AA_API void aa_dmat_diag_vec (const struct aa_dmat *src, struct aa_dvec *dst)
 View the diagonal of a matrix as a vector.
 
static struct aa_dmat AA_DMAT_INIT (aa_la_size rows, aa_la_size cols, double *data, aa_la_size ld)
 Fill in a matrix descriptor. More...
 
static void AA_DMAT_VIEW (struct aa_dmat *mat, aa_la_size rows, aa_la_size cols, double *data, aa_la_size ld)
 Fill in a matrix descriptor. More...
 
AA_API struct aa_dvecaa_dvec_alloc (struct aa_mem_region *reg, aa_la_size len)
 Region-allocate a vector. More...
 
AA_API struct aa_dvecaa_dvec_dup (struct aa_mem_region *reg, const struct aa_dvec *src)
 Duplicate vector out of region. More...
 
AA_API struct aa_dvecaa_dvec_mdup (const struct aa_dvec *src)
 Duplicate vector in the heap. More...
 
AA_API struct aa_dmataa_dmat_dup (struct aa_mem_region *reg, const struct aa_dmat *src)
 Duplicate matrix out of region. More...
 
AA_API struct aa_dmataa_dmat_mdup (const struct aa_dmat *src)
 Duplicate matrix in the heap. More...
 
AA_API struct aa_dmataa_dmat_alloc (struct aa_mem_region *reg, aa_la_size rows, aa_la_size cols)
 Region-allocate a matrix. More...
 
AA_API struct aa_dvecaa_dvec_malloc (aa_la_size len)
 Heap-allocate a vector. More...
 
AA_API struct aa_dmataa_dmat_malloc (aa_la_size rows, aa_la_size cols)
 Heap-allocate a matrix. More...
 
AA_API void aa_dvec_zero (struct aa_dvec *vec)
 Zero a vector.
 
AA_API void aa_dvec_set (struct aa_dvec *vec, double alpha)
 Fill a vector.
 
AA_API void aa_dmat_set (struct aa_dmat *A, double alpha, double beta)
 Fill a matrix diagonal and off-diagonal elements. More...
 
AA_API void aa_dmat_zero (struct aa_dmat *mat)
 Zero a matrix.
 
AA_API void aa_dvec_swap (struct aa_dvec *x, struct aa_dvec *y)
 Swap x and y. More...
 
AA_API void aa_dvec_scal (double alpha, struct aa_dvec *x)
 Scale x by alpha. More...
 
AA_API void aa_dvec_inc (double alpha, struct aa_dvec *x)
 Increment x by alpha. More...
 
AA_API void aa_dvec_copy (const struct aa_dvec *x, struct aa_dvec *y)
 Copy x to y. More...
 
AA_API void aa_dvec_axpy (double a, const struct aa_dvec *x, struct aa_dvec *y)
 Alpha x plus y. More...
 
AA_API double aa_dvec_dot (const struct aa_dvec *x, struct aa_dvec *y)
 Dot product. More...
 
AA_API double aa_dvec_nrm2 (const struct aa_dvec *x)
 Euclidean Norm. More...
 
AA_API void aa_dmat_gemv (AA_CBLAS_TRANSPOSE trans, double alpha, const struct aa_dmat *A, const struct aa_dvec *x, double beta, struct aa_dvec *y)
 General Matrix-Vector multiply. More...
 
AA_API void aa_dmat_gemm (AA_CBLAS_TRANSPOSE transA, AA_CBLAS_TRANSPOSE transB, double alpha, const struct aa_dmat *A, const struct aa_dmat *B, double beta, struct aa_dmat *C)
 General Matrix-Matrix multiply. More...
 
AA_API void aa_dmat_lacpy (const char uplo[1], const struct aa_dmat *A, struct aa_dmat *B)
 Copies all or part of a two-dimensional matrix A to another matrix B. More...
 
AA_API double aa_dvec_ssd (const struct aa_dvec *x, const struct aa_dvec *y)
 sum-square-differences of two vectors
 
AA_API void aa_dmat_axpy (double alpha, const struct aa_dmat *X, struct aa_dmat *Y)
 Y += alpha * X.
 
AA_API double aa_dmat_ssd (const struct aa_dmat *x, const struct aa_dmat *y)
 sum-square-differences of two matrices
 
AA_API void aa_dmat_scal (struct aa_dmat *A, double alpha)
 Scale the matrix A by alpha.
 
AA_API void aa_dmat_inc (struct aa_dmat *A, double alpha)
 Increment the matrix A by alpha.
 
AA_API double aa_dmat_nrm2 (const struct aa_dmat *x)
 Euclidean Norm.
 
AA_API void aa_dmat_trans (const struct aa_dmat *A, struct aa_dmat *At)
 Matrix transpose.
 
AA_API int aa_dmat_inv (struct aa_dmat *A)
 Matrix inverse, in-place.
 
AA_API int aa_dmat_pinv (const struct aa_dmat *A, double tol, struct aa_dmat *As)
 Pseudo-inverse. More...
 
AA_API int aa_dmat_dpinv (const struct aa_dmat *A, double k, struct aa_dmat *As)
 Damped pseudo-inverse.
 
AA_API int aa_dmat_dzdpinv (const struct aa_dmat *A, double s_min, struct aa_dmat *As)
 Dead-zone damped pseudo-inverse.
 
AA_API void aa_dmat_copy (const struct aa_dmat *A, struct aa_dmat *B)
 Copy a matrix.
 

Detailed Description

Block matrix descriptors and linear algebra operations.

Definition in file mat.h.

Macro Definition Documentation

◆ AA_DMAT_REF

#define AA_DMAT_REF (   M,
  i,
 
)    (((M)->data)[(M)->ld*(j) + (i)])

Reference a matrix entry.

Parameters
Mmatrix
irow
jcolumn

Definition at line 94 of file mat.h.

◆ AA_DVEC_REF

#define AA_DVEC_REF (   v,
 
)    ((v)->data[(i) * (v)->inc])

Return an element of a dvec.

Parameters
van aa_dvec
ithe index of the element in v to return

Definition at line 85 of file mat.h.

Function Documentation

◆ aa_dmat_alloc()

AA_API struct aa_dmat* aa_dmat_alloc ( struct aa_mem_region reg,
aa_la_size  rows,
aa_la_size  cols 
)

Region-allocate a matrix.

When finished, pop the descriptor.

◆ aa_dmat_dup()

AA_API struct aa_dmat* aa_dmat_dup ( struct aa_mem_region reg,
const struct aa_dmat src 
)

Duplicate matrix out of region.

When finished, pop the descriptor.

◆ aa_dmat_gemm()

AA_API void aa_dmat_gemm ( AA_CBLAS_TRANSPOSE  transA,
AA_CBLAS_TRANSPOSE  transB,
double  alpha,
const struct aa_dmat A,
const struct aa_dmat B,
double  beta,
struct aa_dmat C 
)

General Matrix-Matrix multiply.

\[ \mathbf{y} \leftarrow \alpha \mathbf{A}^{\rm opA} \mathbf{B}^\rm{opB} + \beta \mathbf{C} \]

◆ aa_dmat_gemv()

AA_API void aa_dmat_gemv ( AA_CBLAS_TRANSPOSE  trans,
double  alpha,
const struct aa_dmat A,
const struct aa_dvec x,
double  beta,
struct aa_dvec y 
)

General Matrix-Vector multiply.

\[ \mathbf{y} \leftarrow \alpha \mathbf{A}^{\rm op} \mathbf{x} + \beta \mathbf{y} \]

◆ AA_DMAT_INIT()

static struct aa_dmat AA_DMAT_INIT ( aa_la_size  rows,
aa_la_size  cols,
double *  data,
aa_la_size  ld 
)
inlinestatic

Fill in a matrix descriptor.

Parameters
rowsNumber of rows in matrix
colsNumber of colums in matrix
dataPointer to vector data
ldLeading dimension of matrix

Definition at line 225 of file mat.h.

◆ aa_dmat_lacpy()

AA_API void aa_dmat_lacpy ( const char  uplo[1],
const struct aa_dmat A,
struct aa_dmat B 
)

Copies all or part of a two-dimensional matrix A to another matrix B.

Parameters
[in]uploSpecifies the part of the matrix A to be copied to B.
  • = 'U': Upper triangular part
  • = 'L': Lower triangular part
  • Otherwise: All of the matrix A
[in]Adimension (LDA,N) The m by n matrix A. If UPLO = 'U', only the upper triangle or trapezoid is accessed; if UPLO = 'L', only the lower triangle or trapezoid is accessed.
[out]Bdimension (LDB,N) On exit, B = A in the locations specified by UPLO.

◆ aa_dmat_malloc()

AA_API struct aa_dmat* aa_dmat_malloc ( aa_la_size  rows,
aa_la_size  cols 
)

Heap-allocate a matrix.

The descriptor and data are contained in a single malloc()'ed block. When finished, call free() on the descriptor.

◆ aa_dmat_mdup()

AA_API struct aa_dmat* aa_dmat_mdup ( const struct aa_dmat src)

Duplicate matrix in the heap.

When finished, free the descriptor.

◆ aa_dmat_pinv()

AA_API int aa_dmat_pinv ( const struct aa_dmat A,
double  tol,
struct aa_dmat As 
)

Pseudo-inverse.

Singular values less than tol are ignored. If tol < 0, then a sane default is used.

◆ aa_dmat_set()

AA_API void aa_dmat_set ( struct aa_dmat A,
double  alpha,
double  beta 
)

Fill a matrix diagonal and off-diagonal elements.

Parameters
[in]AThe matrix to fill
[in]alphaoff-diagonal entries of A
[in]betadiagonal entries of A

◆ aa_dmat_view()

AA_API void aa_dmat_view ( struct aa_dmat mat,
aa_la_size  rows,
aa_la_size  cols,
double *  data,
aa_la_size  ld 
)

Fill in a matrix descriptor.

Parameters
matPointer to descriptor
rowsNumber of rows in matrix
colsNumber of colums in matrix
dataPointer to vector data
ldLeading dimension of matrix

◆ AA_DMAT_VIEW()

static void AA_DMAT_VIEW ( struct aa_dmat mat,
aa_la_size  rows,
aa_la_size  cols,
double *  data,
aa_la_size  ld 
)
inlinestatic

Fill in a matrix descriptor.

Parameters
matPointer to descriptor
rowsNumber of rows in matrix
colsNumber of colums in matrix
dataPointer to vector data
ldLeading dimension of matrix

Definition at line 257 of file mat.h.

◆ aa_dvec_alloc()

AA_API struct aa_dvec* aa_dvec_alloc ( struct aa_mem_region reg,
aa_la_size  len 
)

Region-allocate a vector.

When finished, pop the descriptor.

◆ aa_dvec_axpy()

AA_API void aa_dvec_axpy ( double  a,
const struct aa_dvec x,
struct aa_dvec y 
)

Alpha x plus y.

\[ \mathbf{y} \leftarrow \alpha \mathbf{x} + \mathbf{y} \]

◆ aa_dvec_copy()

AA_API void aa_dvec_copy ( const struct aa_dvec x,
struct aa_dvec y 
)

Copy x to y.

\[ \mathbf{y} \leftarrow \mathbf{x} \]

◆ aa_dvec_dot()

AA_API double aa_dvec_dot ( const struct aa_dvec x,
struct aa_dvec y 
)

Dot product.

\[ \mathbf{x}^T \mathbf{y} \]

◆ aa_dvec_dup()

AA_API struct aa_dvec* aa_dvec_dup ( struct aa_mem_region reg,
const struct aa_dvec src 
)

Duplicate vector out of region.

When finished, pop the descriptor.

◆ aa_dvec_inc()

AA_API void aa_dvec_inc ( double  alpha,
struct aa_dvec x 
)

Increment x by alpha.

\[ \mathbf{x} \leftarrow \alpha + \mathbf{x} \]

◆ AA_DVEC_INIT()

static struct aa_dvec AA_DVEC_INIT ( aa_la_size  len,
double *  data,
aa_la_size  inc 
)
inlinestatic

Fill in a vector descriptor.

Parameters
lenNumber of elements in vector
dataPointer to vector data
incIncrement between sucessive elements

Definition at line 113 of file mat.h.

◆ aa_dvec_malloc()

AA_API struct aa_dvec* aa_dvec_malloc ( aa_la_size  len)

Heap-allocate a vector.

The descriptor and data are contained in a single malloc()'ed block. When finished, call free() on the descriptor.

◆ aa_dvec_mdup()

AA_API struct aa_dvec* aa_dvec_mdup ( const struct aa_dvec src)

Duplicate vector in the heap.

When finished, free the descriptor.

◆ aa_dvec_nrm2()

AA_API double aa_dvec_nrm2 ( const struct aa_dvec x)

Euclidean Norm.

\[ \left\Vert \mathbf{x} \right\Vert_2 \]

◆ aa_dvec_scal()

AA_API void aa_dvec_scal ( double  alpha,
struct aa_dvec x 
)

Scale x by alpha.

\[ \mathbf{x} \leftarrow \alpha \mathbf{x} \]

◆ aa_dvec_swap()

AA_API void aa_dvec_swap ( struct aa_dvec x,
struct aa_dvec y 
)

Swap x and y.

\[ \mathbf{x} \leftrightarrow \mathbf{y} \]

◆ AA_DVEC_VIEW()

static void AA_DVEC_VIEW ( struct aa_dvec vec,
aa_la_size  len,
double *  data,
aa_la_size  inc 
)
inlinestatic

Fill in a vector descriptor.

Parameters
vecPointer to descriptor
lenNumber of elements in vector
dataPointer to vector data
incIncrement between sucessive elements

Definition at line 151 of file mat.h.

◆ aa_dvec_view()

AA_API void aa_dvec_view ( struct aa_dvec vec,
aa_la_size  len,
double *  data,
aa_la_size  inc 
)

Fill in a vector descriptor.

Parameters
vecPointer to descriptor
lenNumber of elements in vector
dataPointer to vector data
incIncrement between sucessive elements