void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { // srand(0xffffff); //options struct HkmOptions opt; //get input class mxClassID classID = getClassID(dataIn); //get the inputs if (nrhs<1) mexErrMsgTxt("At least one input is required"); if (nrhs>1) opt.niters = (int) *(mxGetPr(nitersIn)); if (nrhs>2) opt.nlevels = (int) *(mxGetPr(nlevelsIn)); if (nrhs>3) opt.nbranches = (int) *(mxGetPr(nbranchesIn)); if (nrhs>4) opt.dist = getDistanceType(distIn); if (nrhs>5) opt.ntrees = (int) *(mxGetPr(ntreesIn)); if (nrhs>6) opt.nchecks = (int) *(mxGetPr(nchecksIn)); if (nrhs>7) opt.usekdt = (bool) *(mxGetPr(usekdtIn)); if (nrhs>8) opt.kdtopt.ntrees = (int) *(mxGetPr(nkdtreesIn)); if (nrhs>9) opt.kdtopt.varrange= (float) *(mxGetPr(varrangeIn)); if (nrhs>10) opt.kdtopt.meanrange = (float) *(mxGetPr(meanrangeIn)); if (nrhs>11) opt.kdtopt.cycle = (char) *(mxGetPr(cycleIn)); if (nrhs>12) opt.kdtopt.maxbins = (int) *(mxGetPr(maxbinsIn)); if (nrhs>13) opt.kdtopt.sample = (int) *(mxGetPr(sampleIn)); //set distance opt.kdtopt.dist = opt.dist; // //return output // mxArray* ret; //fill with the data #define __CASE(CLASS) \ { \ /*get the data*/ \ Data<TYPEOF_##CLASS> data; \ /*allocate the kdforest*/ \ Hkms<TYPEOF_##CLASS>* hkm = new Hkms<TYPEOF_##CLASS>(opt); \ /*set data*/ \ fillData(data, dataIn, false); \ /*create*/ \ hkm->create(data); \ /*clear data*/ \ data.clear(); \ /*put output*/ \ hkmOut = exportMatlabPointer(*hkm); \ } __SWITCH(classID, __CASE) // hkmOut = ret; // cout << "here" << endl; }
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { srand(0xffffff); //options struct KdtOptions opt; //get input class mxClassID classID = getClassID(dataIn); //get the inputs if (nrhs<1) mexErrMsgTxt("At least one input is required"); if (nrhs>1) opt.ntrees = (int) *(mxGetPr(ntreesIn)); if (nrhs>2) opt.varrange= (float) *(mxGetPr(varrangeIn)); if (nrhs>3) opt.meanrange = (float) *(mxGetPr(meanrangeIn)); if (nrhs>4) opt.maxdepth = (int) *(mxGetPr(maxdepthIn)); if (nrhs>5) opt.minvar = (float) *(mxGetPr(minvarIn)); if (nrhs>6) opt.cycle = (char) *(mxGetPr(cycleIn)); if (nrhs>7) opt.dist = getDistanceType(distIn); if (nrhs>8) opt.maxbins = (int) *(mxGetPr(maxbinsIn)); if (nrhs>9) opt.sample = (int) *(mxGetPr(sampleIn)); if (nrhs>10) opt.bitsperdim = (int) *(mxGetPr(bitsperdimIn)); // mexPrintf("depth = %d\n", opt.maxdepth); // mexPrintf("bitsperdim = %d\n", opt.bitsperdim); // mexPrintf("n inputs = %d\n", nrhs); // mexPrintf("sample = %f\n", opt.sample); // plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL); // return; //allocate the kdforest Kdf* kdf = new Kdf(opt); //fill with the data #define __CASE(CLASS) \ { \ /*get the data*/ \ Data<TYPEOF_##CLASS> data; \ /*set data*/ \ fillData(data, dataIn); \ /*create*/ \ create(*kdf, data); \ /*clear data*/ \ data.clear(); \ } __SWITCH(classID, __CASE) //return output mxArray* ret = mxCreateNumericMatrix(1,1,mxINDEX_CLASS,mxREAL); *(Kdf**) mxGetPr(ret) = kdf; kdfOut = ret; }
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; }