-
Notifications
You must be signed in to change notification settings - Fork 5
/
mex_dgeqrf.c
68 lines (52 loc) · 1.35 KB
/
mex_dgeqrf.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "mex.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <sys/timeb.h>
#include "config.h"
#ifdef BLAS_UNDERSCORE
#define DGEQRF dgeqrf_
#else
#define DGEQRF dgeqrf
#endif
double wtime()
{
struct timeb T;
static time_t time_diff;
static time_t mill_diff;
double dt;
(void) ftime( &T );
time_diff = T.time;
mill_diff = T.millitm;
dt = ((double) time_diff) + (1e-3) * ((double) mill_diff);
return dt;
}
void mexFunction(int nargout, mxArray *argout[], int nargin, const mxArray *argin[])
{
long m, n;
double *tau, *A;
long workspace_size, info;
double *workspace;
double wsize_d;
m = mxGetM(argin[0]);
n = mxGetN(argin[0]);
argout[0] = mxDuplicateArray(argin[0]);
A = mxGetPr(argout[0]);
if (nargout > 1) {
argout[1] = mxCreateDoubleMatrix(n, 1, mxREAL);
tau = mxGetPr(argout[1]);
} else
tau = mxMalloc(n * sizeof(double));
/* Query workspace size */
workspace_size = -1;
workspace = &wsize_d;
DGEQRF(&m, &n, A, &m, tau, workspace, &workspace_size, &info);
/* Compute */
workspace_size = (long)wsize_d;
workspace = (double *)mxMalloc(sizeof(double) * workspace_size);
DGEQRF(&m, &n, A, &m, tau, workspace, &workspace_size, &info);
mxFree(workspace);
if (nargout < 1)
mxFree(tau);
}