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])
 
#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);
 

Typedefs

typedef size_t aa_la_size
 
typedef void() aa_la_err_fun(const char *message)
 

Functions

AA_API void aa_la_err (const char *message)
 
AA_API void aa_la_set_err (aa_la_err_fun *fun)
 
static struct aa_dvec AA_DVEC_INIT (size_t len, double *data, size_t inc)
 Fill in a vector descriptor. More...
 
AA_API void aa_dvec_view (struct aa_dvec *vec, size_t len, double *data, size_t inc)
 Fill in a vector descriptor. More...
 
AA_API void aa_dmat_view (struct aa_dmat *mat, size_t rows, size_t cols, double *data, size_t ld)
 Fill in a matrix descriptor. More...
 
AA_API void aa_dmat_view_block (struct aa_dmat *dst, const struct aa_dmat *src, size_t row_start, size_t col_start, size_t rows, size_t cols)
 View a block of a matrix.
 
AA_API void aa_dvec_slice (const struct aa_dvec *src, size_t start, size_t stop, size_t step, struct aa_dvec *dst)
 View a slice of a vector.
 
AA_API void aa_dmat_block (const struct aa_dmat *src, size_t row_start, size_t col_start, size_t row_end, size_t col_end, struct aa_dmat *dst)
 View a block of a matrix.
 
AA_API void aa_dmat_row_vec (const struct aa_dmat *src, size_t 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, size_t 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 (size_t rows, size_t cols, double *data, size_t ld)
 Fill in a matrix descriptor. More...
 
AA_API struct aa_dvecaa_dvec_alloc (struct aa_mem_region *reg, size_t 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_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_alloc (struct aa_mem_region *reg, size_t rows, size_t cols)
 Region-allocate a matrix. More...
 
AA_API struct aa_dvecaa_dvec_malloc (size_t len)
 Heap-allocate a vector. More...
 
AA_API struct aa_dmataa_dmat_malloc (size_t rows, size_t 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 (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 (CBLAS_TRANSPOSE transA, 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 86 of file mat.h.

Function Documentation

◆ aa_dmat_alloc()

AA_API struct aa_dmat* aa_dmat_alloc ( struct aa_mem_region reg,
size_t  rows,
size_t  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 ( CBLAS_TRANSPOSE  transA,
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 ( 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 ( size_t  rows,
size_t  cols,
double *  data,
size_t  ld 
)
static

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 209 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 ( size_t  rows,
size_t  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_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,
size_t  rows,
size_t  cols,
double *  data,
size_t  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_dvec_alloc()

AA_API struct aa_dvec* aa_dvec_alloc ( struct aa_mem_region reg,
size_t  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 ( size_t  len,
double *  data,
size_t  inc 
)
static

Fill in a vector descriptor.

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

Definition at line 120 of file mat.h.

◆ aa_dvec_malloc()

AA_API struct aa_dvec* aa_dvec_malloc ( size_t  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_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()

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

Fill in a vector descriptor.

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