/* * dpcore.c * Core of dynamic programming/DTW calculation * 2003-04-02 dpwe@ee.columbia.edu * $Header: /Users/dpwe/projects/dtw/RCS/dpcore.c,v 1.5 2014/06/20 21:08:53 dpwe Exp dpwe $ % Copyright (c) 2003-05 Dan Ellis % released under GPL - see file COPYRIGHT */ #include #include /* per Vigi Katlowitz for windows 2014-06-20 */ #include #include /* these two lines are to make it compile on Xcode 5.1 2014-06-20 */ #include typedef uint16_t char16_t; #include "mex.h" /* #define DEBUG */ /* #define INF HUGE_VAL */ #define INF DBL_MAX void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int i,j; long pvl, pvb[16]; #ifdef DEBUG mexPrintf("dpcore: Got %d lhs args and %d rhs args.\n", nlhs, nrhs); for (i=0;i 0){ mxArray *DMatrix, *PMatrix; int rows, cols, i, j, k, tb; double *pM, *pD, *pP, *pC; double d1, d2, d3, v; double *costs; int *steps; int ncosts; rows = mxGetM(prhs[0]); cols = mxGetN(prhs[0]); pM = mxGetPr(prhs[0]); DMatrix = mxCreateDoubleMatrix(rows, cols, mxREAL); pD = mxGetPr(DMatrix); PMatrix = mxCreateDoubleMatrix(rows, cols, mxREAL); pP = mxGetPr(PMatrix); plhs[0] = DMatrix; if (nlhs > 1) { plhs[1] = PMatrix; } /* setup costs */ if (nrhs == 1) { /* default C matrix */ int ii; ncosts = 3; costs = (double *)malloc(ncosts*sizeof(double)); for (ii = 0; ii= steps[2*k] && j >= steps[2*k+1] ) { d2 = costs[k]*d1 + pD[(i-steps[2*k]) + (j-steps[2*k+1])*rows]; if (d2 < v) { v = d2; tb = k+1; } } } pD[i + j*rows] = v; pP[i + j*rows] = (double)tb; v = INF; } } free((void *)costs); free((void *)steps); } #ifdef DEBUG mexPrintf("dpcore: returning...\n"); #endif /* DEBUG */ }