void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { if (nrhs<3) mexErrMsgTxt("Three inputs required"); //get the lsh objcect Kdf* kdf = *(Kdf**)mxGetData(kdfIn); //get the class of points mxClassID classID = getClassID(pointsIn); //get number of points in search data mwSize npoints = getNpoints(pointsIn); //number of nearest neighbors to return uint k = (uint) *mxGetPr(kIn); //return all points -> return a cell array, otherwise returna matrix kxnpoints mxClassID retId; switch (numeric_limits<uint>::digits) { case 32: retId = mxUINT32_CLASS; break; case 64: retId = mxUINT64_CLASS; break; } // mexPrintf("sizes are: %dx%d %dx%d\n", rows1, cols1, rows2, cols2); uint n1; #define __CASE(CLASS) \ { \ /*datas*/ \ Data<TYPEOF_##CLASS> points; \ fillData(points, pointsIn); \ /*allocate output*/ \ n1 = points.size(); \ /*return cell array*/ \ if (k == 0) \ idsOut = mxCreateCellMatrix(1, n1); \ /*return array*/ \ else if (k > 0) \ idsOut = mxCreateNumericMatrix((mwSize)k, (mwSize)n1, retId, mxREAL); \ /*loop*/ \ KdtPointList pl; \ for (uint i=0; i<n1; ++i) \ { \ /*get ids*/ \ getIds(*kdf, points, i, pl); \ /*put back*/ \ fillPlist(idsOut, pl, i, k, retId); \ } \ /*clear memory*/ \ points.clear(); \ } __SWITCH(classID, __CASE) }
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { if (nrhs!=5) mexErrMsgTxt("Five inputs required"); //get the lsh objcect Lsh* lsh = *(Lsh**)mxGetData(lshIn); //get the class of points mxClassID classID = getClassID(lshPointsIn); //get number of points in search data mwSize npoints = getNpoints(pointsIn); //number of nearest neighbors to return uint k = (uint) *mxGetPr(kIn); //empty distance, then use the one inside the lsh DistanceType dist; if (mxIsEmpty(distIn)) dist = lsh->opt.dist; else dist = getDistanceType(distIn); // mexPrintf("sizes are: %dx%d %dx%d\n", rows1, cols1, rows2, cols2); mxArray *dists, *ids; uint n1; #define __CASE(CLASS) \ { \ /*datas*/ \ Data<TYPEOF_##CLASS> lshPoints, points; \ fillData(lshPoints, lshPointsIn); \ fillData(points, pointsIn); \ /*allocate output*/ \ n1 = points.size(); \ dists = mxCreateNumericMatrix(k, n1, mxSINGLE_CLASS, mxREAL); \ ids = mxCreateNumericMatrix(k, n1, mxUINT32_CLASS, mxREAL); \ /*compute*/ \ getKnn(*lsh, lshPoints, points, k, dist, (uint*) mxGetData(ids), \ (float*) mxGetData(dists)); \ /*clear memory*/ \ lshPoints.clear(); \ points.clear(); \ } __SWITCH(classID, __CASE) //add one to the ids to make it Matlab compatible uint* idp = (uint*) mxGetData(ids); float* distp = (float*) mxGetData(dists); for (mwSize i=0; i<k*n1; ++i) { if (distp[i] < numeric_limits<float>::infinity()) idp[i] += 1; } idsOut = ids; if (nlhs>1) distsOut = dists; }
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { if (nrhs!=3) mexErrMsgTxt("Three inputs required"); //get the lsh objcect Lsh* lsh = *(Lsh**)mxGetData(lshIn); //get the class of points mxClassID classID = getClassID(pointsIn); //get number of points mwSize npoints = getNpoints(pointsIn); //number of returns bool cellout = (bool) *mxGetPr(celloutIn); //create an array of LshPointList LshFuncValList* vals = new LshFuncValList[npoints]; //now loop on the points and search #define __CASE(CLASS) \ { \ /*get the data*/ \ Data<TYPEOF_##CLASS> data; \ /*set data*/ \ fillData(data, pointsIn); \ /*insert*/ \ getFuncVal(*lsh, data, vals); \ /*clear data*/ \ data.clear(); \ } __SWITCH(classID, __CASE) //allocate output data and get pointer //## change the type of this matlab type if uint is something other than unsigned int mxClassID retId; switch (numeric_limits<LshFuncVal_t>::digits) { case 32: retId = mxUINT32_CLASS; break; case 64: retId = mxUINT64_CLASS; break; } //check if to return cell: if requested by user, or if have more than one table //otherwise, we can just return a matrix where each column is for a point //and each row is for a function cellout = cellout || (lsh->opt.ntables > 1); //return all points -> return a cell array if (cellout) valsOut = mxCreateCellMatrix(1, npoints); //return an array else valsOut = mxCreateNumericMatrix((mwSize)lsh->opt.nfuncs, (mwSize)npoints, retId, mxREAL); //loop on points and put output for (uint i=0; i<npoints; ++i) { //get pointer LshFuncVal_t* valsp; if (cellout) { //get cell array mxArray* pcell = mxCreateNumericMatrix(lsh->opt.nfuncs, lsh->opt.ntables, retId, mxREAL); mxSetCell(valsOut, i, pcell); //allocate valsp = (LshFuncVal_t*) mxGetPr(pcell); } else { //get pointer valsp = (LshFuncVal_t*) mxGetPr(valsOut); valsp += lsh->opt.nfuncs*i; } //loop on lists for (uint j=0; j<vals[i].size(); ++j) //get value valsp[j] = vals[i][j]; //clear this list vals[i].clear(); } //clear list of plist delete [] vals; }