Last change
on this file since 177 was
37,
checked in by (none), 15 years ago
|
Added original make3d
|
-
Property svn:executable set to
*
|
File size:
1000 bytes
|
Rev | Line | |
---|
[37] | 1 | /* compile with: cmex digamma.c mexutil.c util.c -lm |
---|
| 2 | * test in matlab: |
---|
| 3 | * digamma(1:10) |
---|
| 4 | */ |
---|
| 5 | /* Written by Tom Minka |
---|
| 6 | * (c) Microsoft Corporation. All rights reserved. |
---|
| 7 | */ |
---|
| 8 | #include "mex.h" |
---|
| 9 | #include "util.h" |
---|
| 10 | |
---|
| 11 | void mexFunction(int nlhs, mxArray *plhs[], |
---|
| 12 | int nrhs, const mxArray *prhs[]) |
---|
| 13 | { |
---|
| 14 | int ndims, len, i; |
---|
| 15 | int * dims; |
---|
| 16 | double *indata, *outdata; |
---|
| 17 | |
---|
| 18 | if((nlhs > 1) || (nrhs != 1)) |
---|
| 19 | mexErrMsgTxt("Usage: x = digamma(n)"); |
---|
| 20 | |
---|
| 21 | /* prhs[0] is first argument. |
---|
| 22 | * mxGetPr returns double* (data, col-major) |
---|
| 23 | */ |
---|
| 24 | ndims = mxGetNumberOfDimensions(prhs[0]); |
---|
| 25 | dims = (int*)mxGetDimensions(prhs[0]); |
---|
| 26 | indata = mxGetPr(prhs[0]); |
---|
| 27 | len = mxGetNumberOfElements(prhs[0]); |
---|
| 28 | |
---|
| 29 | if(mxIsSparse(prhs[0])) |
---|
| 30 | mexErrMsgTxt("Cannot handle sparse matrices. Sorry."); |
---|
| 31 | |
---|
| 32 | /* plhs[0] is first output */ |
---|
| 33 | plhs[0] = mxCreateNumericArray(ndims, dims, mxDOUBLE_CLASS, mxREAL); |
---|
| 34 | outdata = mxGetPr(plhs[0]); |
---|
| 35 | |
---|
| 36 | /* compute digamma of every element */ |
---|
| 37 | for(i=0;i<len;i++) |
---|
| 38 | *outdata++ = digamma(*indata++); |
---|
| 39 | } |
---|
| 40 | |
---|
Note: See
TracBrowser
for help on using the repository browser.