pomp
Inference for partially observed Markov processes
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pomp_mat.h
Go to the documentation of this file.
1#ifndef _POMP_MAT_H_
2#define _POMP_MAT_H_
3
4#include <Rconfig.h>
5#include <R_ext/Lapack.h>
6#ifndef FCONE
7#define FCONE
8#endif
9#include "internal.h"
10
11static R_INLINE void pomp_backsolve
12(
13 double *a, int lda, int n, double *x, int incx,
14 char *uplo, char *transpose, char *unit
15 ) {
16 // Level 2 BLAS triangular-matrix solver DTRSV(UPLO,TRANS,DIAG,N,A,LDA,X,INCX)
17 // DTRSV: x <- A ^{-1} x -or- x <- A ^{-T} x, A triangular
18 // N is the order of A
19 // LDA is A's leading dimension
20 // INCX is the increment between successive X locations
21 // UPLO is "U" or "L" depending on whether A is upper or lower triangular
22 // TRANSPOSE is "T" or "N" depending on whether the transpose is desired
23 // DIAG is "U" or "N" depending on whether A is unit triangular or not
24 F77_CALL(dtrsv)(uplo,transpose,unit,&n,a,&lda,x,&incx FCONE FCONE FCONE);
25}
26
27static R_INLINE void pomp_qr
28(
29 double *a, int m, int n, int *pivot, double *tau
30 ) {
31 int info, j, lwork = -1;
32 double work1;
33 // zero out the pivots (assumed by DGEQP3)
34 for (j = 0; j < n; j++) pivot[j] = 0;
35 // LAPACK QR decomposition routine
36 // DGEQP3(M,N,A,LDA,JPVT,TAU,WORK,LWORK,INFO)
37 F77_CALL(dgeqp3)(&m,&n,a,&m,pivot,tau,&work1,&lwork,&info); // workspace query
38 lwork = (int) ceil(work1);
39 {
40 double work[lwork];
41 F77_CALL(dgeqp3)(&m,&n,a,&m,pivot,tau,work,&lwork,&info); // actual call
42 }
43 for (j = 0; j < n; j++) pivot[j]--;
44}
45
46static R_INLINE void pomp_qrqy
47(
48 double *c, double *a, int lda, double *tau,
49 int m, int n, int k, char *side, char *transpose
50 ) {
51 int info, lwork = -1;
52 double work1;
53 // workspace query
54 // DORMQR(SIDE,TRANS,M,N,K,A,LDA,TAU,C,LDC,WORK,LWORK,INFO)
55 F77_CALL(dormqr)(side,transpose,&m,&n,&k,a,&lda,tau,c,&m,&work1,&lwork,&info FCONE FCONE);
56 lwork = (int) ceil(work1);
57 { // actual call
58 double work[lwork];
59 F77_CALL(dormqr)(side,transpose,&m,&n,&k,a,&lda,tau,c,&m,work,&lwork,&info FCONE FCONE);
60 }
61}
62
63#endif
#define tau
Definition gompertz.c:94
#define FCONE
Definition pomp_mat.h:7
static R_INLINE void pomp_qr(double *a, int m, int n, int *pivot, double *tau)
Definition pomp_mat.h:28
static R_INLINE void pomp_qrqy(double *c, double *a, int lda, double *tau, int m, int n, int k, char *side, char *transpose)
Definition pomp_mat.h:47
static R_INLINE void pomp_backsolve(double *a, int lda, int n, double *x, int incx, char *uplo, char *transpose, char *unit)
Definition pomp_mat.h:12