source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/lightspeed/randgamma.c @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 869 bytes
Line 
1/* Written by Tom Minka
2 * (c) Microsoft Corporation. All rights reserved.
3 */
4#include "mex.h"
5#include "util.h"
6
7void 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.