-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsheetmultip.c
62 lines (47 loc) · 1.43 KB
/
sheetmultip.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
#include <math.h>
#include "mex.h"
#include "blas.h"
bool mxUnshareArray(mxArray *array_ptr, bool noDeepCopy);
void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
{
/* sheetmulti(A,R,P,beta)
* returns P(:,i) = A'*R(:,:,i) + beta*P(:,i) for i=1:Kr
* where
* size(P) = [Kth, Kr]
* size(R) = [MN, Kth, Kr]
* size(A) = [MN, 1]
*
* Saves values in place
*/
double *R, *P, *A;
double *Rr, *Pr;
double beta;
ptrdiff_t MN,Kr,Kth;;
int r;
const mwSize* dimR = mxGetDimensions(prhs[1]);
char *chn = "N";
char *cht = "T";
/* scalar values to use in dgemm */
double one = 1.0, zero = 0.0;
ptrdiff_t ione = 1;
if(nrhs != 4){
mexErrMsgIdAndTxt( "MATLAB:convec:invalidNumInputs", "Four inputs required.");
}
plhs[0] = (mxArray*) prhs[2];
/* Make sure array is not waiting for COW */
mxUnshareArray(plhs[0], true);
/* mexPrintf("r = %d\n",r); */
MN = dimR[0];
Kth = dimR[1];
Kr = dimR[2];
A = mxGetPr(prhs[0]);
R = mxGetPr(prhs[1]); /* N*M x Kth x Kr */
P = mxGetPr(plhs[0]);
beta = mxGetScalar(prhs[3]);
/* mexPrintf("beta = %f\n",beta); */
for(r=0;r<Kr;r++) {
Rr = R + r*Kth*MN; /* rth sheet of R. ie R(:,:,r) */
Pr = P + r*Kth; /* rth column of P. ie P(:,r); */
dgemv(cht, &MN, &Kth, &one, Rr, &MN, A, &ione, &beta,Pr, &ione);
}
}