-
Notifications
You must be signed in to change notification settings - Fork 36
/
randgamma.c
36 lines (29 loc) · 883 Bytes
/
randgamma.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
/* Written by Tom Minka
* (c) Microsoft Corporation. All rights reserved.
*/
#include "mexutil.h"
#include "util.h"
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
mwSize ndims, len, i;
mwSize *dims;
double *indata, *outdata;
if((nlhs > 1) || (nrhs != 1))
mexErrMsgTxt("Usage: x = randgamma(a)");
/* prhs[0] is first argument.
* mxGetPr returns double* (data, col-major)
*/
ndims = mxGetNumberOfDimensions(prhs[0]);
dims = (mwSize*)mxGetDimensions(prhs[0]);
indata = mxGetPr(prhs[0]);
len = mxGetNumberOfElements(prhs[0]);
if(mxIsSparse(prhs[0]))
mexErrMsgTxt("Cannot handle sparse matrices. Sorry.");
/* plhs[0] is first output */
plhs[0] = mxCreateNumericArrayE(ndims, dims, mxDOUBLE_CLASS, mxREAL);
outdata = mxGetPr(plhs[0]);
for(i=0;i<len;i++) {
*outdata++ = GammaRand(*indata++);
}
}