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

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

Added original make3d

  • Property svn:executable set to *
File size: 979 bytes
Line 
1/* compile with: cmex trigamma.c util.c -lm
2 * test in matlab:
3 *   trigamma(1:10)
4 */
5#include "mex.h"
6#include "util.h"
7
8void mexFunction(int nlhs, mxArray *plhs[],
9                 int nrhs, const mxArray *prhs[])
10{
11  int ndims, len, i;
12  int *dims;
13  double *indata, *outdata;
14
15  if((nrhs != 1) || (nlhs > 1))   
16    mexErrMsgTxt("Usage: x = trigamma(n)");
17
18  /* prhs[0] is first argument.
19   * mxGetPr returns double*  (data, col-major)
20   * mxGetM returns int  (rows)
21   * mxGetN returns int  (cols)
22   */
23  ndims = mxGetNumberOfDimensions(prhs[0]);
24  dims = (int*)mxGetDimensions(prhs[0]);
25  indata = mxGetPr(prhs[0]);
26  len = mxGetNumberOfElements(prhs[0]);
27
28  if(mxIsSparse(prhs[0]))
29    mexErrMsgTxt("Cannot handle sparse matrices.  Sorry.");
30
31  /* plhs[0] is first output */
32  plhs[0] = mxCreateNumericArray(ndims, dims, mxDOUBLE_CLASS, mxREAL);
33  outdata = mxGetPr(plhs[0]);
34
35  /* compute trigamma of every element */
36  for(i=0;i<len;i++)
37    *outdata++ = trigamma(*indata++);
38}
39
Note: See TracBrowser for help on using the repository browser.