amino
1.0-beta2
Lightweight Robot Utility Library
|
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_dvec * | aa_dvec_alloc (struct aa_mem_region *reg, aa_la_size len) |
Region-allocate a vector. More... | |
AA_API struct aa_dvec * | aa_dvec_dup (struct aa_mem_region *reg, const struct aa_dvec *src) |
Duplicate vector out of region. More... | |
AA_API struct aa_dvec * | aa_dvec_mdup (const struct aa_dvec *src) |
Duplicate vector in the heap. More... | |
AA_API struct aa_dmat * | aa_dmat_dup (struct aa_mem_region *reg, const struct aa_dmat *src) |
Duplicate matrix out of region. More... | |
AA_API struct aa_dmat * | aa_dmat_mdup (const struct aa_dmat *src) |
Duplicate matrix in the heap. More... | |
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. More... | |
AA_API struct aa_dvec * | aa_dvec_malloc (aa_la_size len) |
Heap-allocate a vector. More... | |
AA_API struct aa_dmat * | aa_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. | |
Block matrix descriptors and linear algebra operations.
Definition in file mat.h.
#define AA_DMAT_REF | ( | M, | |
i, | |||
j | |||
) | (((M)->data)[(M)->ld*(j) + (i)]) |
#define AA_DVEC_REF | ( | v, | |
i | |||
) | ((v)->data[(i) * (v)->inc]) |
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_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_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_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} \]
|
inlinestatic |
Copies all or part of a two-dimensional matrix A to another matrix B.
[in] | uplo | Specifies the part of the matrix A to be copied to B.
|
[in] | A | dimension (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] | B | dimension (LDB,N) On exit, B = A in the locations specified by UPLO. |
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.
Duplicate matrix in the heap.
When finished, free the descriptor.
Pseudo-inverse.
Singular values less than tol are ignored. If tol < 0, then a sane default is used.
Fill a matrix diagonal and off-diagonal elements.
[in] | A | The matrix to fill |
[in] | alpha | off-diagonal entries of A |
[in] | beta | diagonal entries of A |
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.
mat | Pointer to descriptor |
rows | Number of rows in matrix |
cols | Number of colums in matrix |
data | Pointer to vector data |
ld | Leading dimension of matrix |
|
inlinestatic |
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.
Alpha x plus y.
\[ \mathbf{y} \leftarrow \alpha \mathbf{x} + \mathbf{y} \]
Copy x to y.
\[ \mathbf{y} \leftarrow \mathbf{x} \]
Dot product.
\[ \mathbf{x}^T \mathbf{y} \]
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.
Increment x by alpha.
\[ \mathbf{x} \leftarrow \alpha + \mathbf{x} \]
|
inlinestatic |
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.
Duplicate vector in the heap.
When finished, free the descriptor.
Euclidean Norm.
\[ \left\Vert \mathbf{x} \right\Vert_2 \]
Scale x by alpha.
\[ \mathbf{x} \leftarrow \alpha \mathbf{x} \]
Swap x and y.
\[ \mathbf{x} \leftrightarrow \mathbf{y} \]
|
inlinestatic |
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.
vec | Pointer to descriptor |
len | Number of elements in vector |
data | Pointer to vector data |
inc | Increment between sucessive elements |