Line | |
---|
1 | /* Written by Tom Minka |
---|
2 | * (c) Microsoft Corporation. All rights reserved. |
---|
3 | */ |
---|
4 | #include "mex.h" |
---|
5 | #include "util.h" |
---|
6 | |
---|
7 | void mexFunction(int nlhs, mxArray *plhs[], |
---|
8 | int nrhs, const mxArray *prhs[]) |
---|
9 | { |
---|
10 | int ndims, len, i; |
---|
11 | int *dims; |
---|
12 | double *indata, *outdata; |
---|
13 | |
---|
14 | if((nlhs > 1) || (nrhs != 1)) |
---|
15 | mexErrMsgTxt("Usage: x = randgamma(a)"); |
---|
16 | |
---|
17 | /* prhs[0] is first argument. |
---|
18 | * mxGetPr returns double* (data, col-major) |
---|
19 | */ |
---|
20 | ndims = mxGetNumberOfDimensions(prhs[0]); |
---|
21 | dims = (int*)mxGetDimensions(prhs[0]); |
---|
22 | indata = mxGetPr(prhs[0]); |
---|
23 | len = mxGetNumberOfElements(prhs[0]); |
---|
24 | |
---|
25 | if(mxIsSparse(prhs[0])) |
---|
26 | mexErrMsgTxt("Cannot handle sparse matrices. Sorry."); |
---|
27 | |
---|
28 | /* plhs[0] is first output */ |
---|
29 | plhs[0] = mxCreateNumericArray(ndims, dims, mxDOUBLE_CLASS, mxREAL); |
---|
30 | outdata = mxGetPr(plhs[0]); |
---|
31 | |
---|
32 | for(i=0;i<len;i++) { |
---|
33 | *outdata++ = GammaRand(*indata++); |
---|
34 | } |
---|
35 | } |
---|
36 | |
---|
Note: See
TracBrowser
for help on using the repository browser.