44 #include "sphinxbase/clapack_lite.h"
58 for (i = 0; i < d1; i++) {
59 for (j = 0; j < d2; j++) {
62 for (k = 0, s = 0; k < d3; k++) {
70 for (k = 0; k < d3; k++) {
86 for (i = 0; i < d1; i++) {
87 for (j = 0; j < d2; j++) {
88 for (k = 0; k < d3; k++) {
89 out[i][j][k] += in[i][j][k];
104 for (i = 0; i < d1; i++) {
105 for (j = 0; j < d2; j++) {
106 for (k = 0; k < d3; k++) {
107 if ((m[i][j][k] != 0) && (m[i][j][k] < floor))
120 for (i = 0; i < d1; i++) {
121 if ((v[i] != 0) && (v[i] < floor))
133 for (i = 0; i < d1; i++) {
135 if ((v[i] > 0) && (v[i] < band)) {
138 else if ((v[i] < 0) && (v[i] > -band)) {
149 E_FATAL(
"No LAPACK library available, cannot compute determinant (FIXME)\n");
153 invert(float32 **ainv, float32 **a, int32 n)
155 E_FATAL(
"No LAPACK library available, cannot compute matrix inverse (FIXME)\n");
159 solve(float32 **a, float32 *b, float32 *out_x, int32 n)
161 E_FATAL(
"No LAPACK library available, cannot solve linear equations (FIXME)\n");
170 memset(c[0], 0, n*n*
sizeof(float32));
171 for (i = 0; i < n; ++i) {
172 for (j = 0; j < n; ++j) {
173 for (k = 0; k < n; ++k) {
174 c[i][k] += a[i][j] * b[j][k];
193 memcpy(tmp_a[0], a[0], n*n*
sizeof(float32));
196 spotrf_(&uplo, &n, tmp_a[0], &n, &info);
199 for (i = 1; i < n; ++i)
222 memcpy(tmp_a[0], a[0], n*n*
sizeof(float32));
223 memcpy(out_x, b, n*
sizeof(float32));
226 sposv_(&uplo, &n, &nrhs, tmp_a[0], &n, out_x, &n, &info);
237 invert(float32 ** ainv, float32 ** a, int32 n)
247 memcpy(tmp_a[0], a[0], n*n*
sizeof(float32));
250 memset(ainv[0], 0,
sizeof(float32) * n * n);
251 for (i = 0; i < n; i++)
256 sposv_(&uplo, &n, &nrhs, tmp_a[0], &n, ainv[0], &n, &info);
275 ssymm_(&side, &uplo, &n, &n, &alpha, a[0], &n, b[0], &n, &alpha, c[0], &n);
285 for (i = 0; i < len; ++i) {
286 a[i][i] = x[i] * y[i];
287 for (j = i + 1; j < len; ++j) {
288 a[i][j] = x[i] * y[j];
289 a[j][i] = x[j] * y[i];
299 for (i = 0; i < n; ++i) {
301 for (j = i+1; j < n; ++j) {
313 for (i = 0; i < n; ++i)
314 for (j = 0; j < n; ++j)
#define ckd_calloc_2d(d1, d2, sz)
Macro for ckd_calloc_2d
Sphinx's memory allocation/deallocation routines.
SPHINXBASE_EXPORT int32 solve(float32 **a, float32 *b, float32 *out_x, int32 n)
Solve (if possible) a positive-definite system of linear equations AX=B for X.
SPHINXBASE_EXPORT void outerproduct(float32 **out_a, float32 *x, float32 *y, int32 len)
Calculate the outer product of two vectors.
SPHINXBASE_EXPORT void accum_3d(float32 ***out, float32 ***in, uint32 d1, uint32 d2, uint32 d3)
Floor 3-d array.
SPHINXBASE_EXPORT int32 invert(float32 **out_ainv, float32 **a, int32 len)
Invert (if possible) a positive definite matrix with QR algorithm.
Implementation of logging routines.
Matrix and linear algebra functions.
SPHINXBASE_EXPORT void matrixadd(float32 **inout_a, float32 **b, int32 n)
Add A += B.
SPHINXBASE_EXPORT void band_nz_1d(float32 *v, uint32 d1, float32 band)
Ensures that non-zero values x such that -band < x < band, band > 0 are set to -band if x < 0 and ban...
SPHINXBASE_EXPORT float64 determinant(float32 **a, int32 len)
Calculate the determinant of a positive definite matrix.
SPHINXBASE_EXPORT void ckd_free_2d(void *ptr)
Free a 2-D array (ptr) previously allocated by ckd_calloc_2d.
SPHINXBASE_EXPORT void matrixmultiply(float32 **out_c, float32 **a, float32 **b, int32 n)
Multiply C=AB where A and B are symmetric matrices.
#define E_FATAL(...)
Exit with non-zero status after error message.
SPHINXBASE_EXPORT void scalarmultiply(float32 **inout_a, float32 x, int32 n)
Multiply a symmetric matrix by a constant in-place.
SPHINXBASE_EXPORT void floor_nz_1d(float32 *v, uint32 d1, float32 floor)
Floor 1-d array.
SPHINXBASE_EXPORT void norm_3d(float32 ***arr, uint32 d1, uint32 d2, uint32 d3)
Norm an array.
SPHINXBASE_EXPORT void floor_nz_3d(float32 ***m, uint32 d1, uint32 d2, uint32 d3, float32 floor)
Floor 3-d array.