void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { //I/O double *ptr_channel_in; double *ptr_sampleRate_hz_in; double *ptr_delay_seconds_in; double *ptr_timeWindow_seconds_in; //double *ptr_length_out; uint8_t *ptr_data_out; mwSize dims[2] = {0,0}; int ndims = 2; //Internals int channel; double sampleRate_hz; double delay_seconds; double timeWindow_seconds; int* length_int; std::vector<uint8_t>* dll_return; //Fetch inputs. ptr_channel_in = mxGetPr(prhs[0]); //Mex get pointer to real (double); ptr_timeWindow_seconds_in = mxGetPr(prhs[1]); ptr_sampleRate_hz_in = mxGetPr(prhs[2]); ptr_delay_seconds_in = mxGetPr(prhs[3]); //Copy to internals channel = (int)(*ptr_channel_in); sampleRate_hz = (*ptr_sampleRate_hz_in); delay_seconds = (*ptr_delay_seconds_in); timeWindow_seconds = (*ptr_timeWindow_seconds_in); length_int = (int*)mxCalloc(1, sizeof(int)); //Actually get the data. dll_return = librador_get_digital_data(channel, timeWindow_seconds, sampleRate_hz, delay_seconds); length_int[0] = dll_return->size(); //Abort now if there's no data!!! if(dll_return == NULL){ dims[0] = 1; dims[1] = 1; plhs[0] = mxCreateNumericArray(ndims, dims, mxDOUBLE_CLASS, mxREAL); double *ptr_zero = (double *) mxCalloc(1, sizeof(double)); ptr_zero[0] = 0; mxSetData(plhs[0], ptr_zero); return; } //Malloc all the outputs! //We need to copy from the DLL to MATLAB so that it can work with the data without cracking the sads. ptr_data_out = (uint8_t*)mxCalloc(length_int[0], sizeof(uint8_t)); memcpy(ptr_data_out, dll_return->data(), length_int[0] * sizeof(uint8_t)); dims[0] = 1; dims[1] = length_int[0]; //plhs[0] = mxCreateDoubleScalar((double)ptr_length_out[0]); plhs[0] = mxCreateNumericArray(ndims, dims, mxUINT8_CLASS, mxREAL); mxSetData(plhs[0], ptr_data_out); }
void homogToFlow(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { /* [us,vs]=homogToFlow(H,m,n,[r0],[r1],[c0],[c1]); */ int ind=0, i, j, m, n, m1, n1; double *H, *us, *vs; double r, c, r0, c0, r1, c1, m2, n2, z; /* extract inputs */ H = (double*) mxGetData(prhs[0]); m = (int) mxGetScalar(prhs[1]); n = (int) mxGetScalar(prhs[2]); if(nrhs==7) { r0 = mxGetScalar(prhs[3]); r1 = mxGetScalar(prhs[4]); c0 = mxGetScalar(prhs[5]); c1 = mxGetScalar(prhs[6]); m1 = (int) (r1-r0+1); n1 = (int) (c1-c0+1); } else { m1=m; r0 = (-m+1.0)/2.0; n1=n; c0 = (-n+1.0)/2.0; } m2 = (m-1.0)/2.0; n2 = (n-1.0)/2.0; /* initialize memory */ us = mxMalloc(sizeof(double)*m1*n1); vs = mxMalloc(sizeof(double)*m1*n1); /* Compute flow at each grid point */ for( i=0; i<9; i++ ) H[i]=H[i]/H[8]; if( H[2]==0 && H[5]==0 ) { for( i=0; i<n1; i++ ) { r = H[0]*r0 + H[3]*(c0+i) + H[6] + m2; c = H[1]*r0 + H[4]*(c0+i) + H[7] + n2 - i; for(j=0; j<m1; j++) { us[ind]=r-j; vs[ind]=c; r+=H[0]; c+=H[1]; ind++; } } } else { for( i=0; i<n1; i++ ) { r = H[0]*r0 + H[3]*(c0+i) + H[6]; c = H[1]*r0 + H[4]*(c0+i) + H[7]; z = H[2]*r0 + H[5]*(c0+i) + 1; for(j=0; j<m1; j++) { us[ind]=r/z+m2-j; vs[ind]=c/z+n2-i; r+=H[0]; c+=H[1]; z+=H[2]; ind++; } } } /* create output array */ plhs[0] = mxCreateNumericMatrix(0,0,mxDOUBLE_CLASS,mxREAL); plhs[1] = mxCreateNumericMatrix(0,0,mxDOUBLE_CLASS,mxREAL); mxSetData(plhs[0],us); mxSetM(plhs[0],m1); mxSetN(plhs[0],n1); mxSetData(plhs[1],vs); mxSetM(plhs[1],m1); mxSetN(plhs[1],n1); }
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { BYTE* originalData; double *nodeType; const mwSize dims[]={DATANUMS,1}; #ifdef CHECKARG /* check for proper number of arguments */ if(nrhs!=2) mexErrMsgTxt("Two input required."); /* input must be a if ( mxIsStruct(prhs[0]) != 1) mexErrMsgTxt("Input1 must be a array."); */ /* input must be a row vector */ if (mxGetM(prhs[0])!=1024) mexErrMsgTxt("输入数组长度必须为1024"); #endif /* Get Input Data */ originalData = (BYTE *)mxCalloc(DATANUMS*2,sizeof(UINT8_T)); originalData = (BYTE *)mxGetData(prhs[0]); nodeType = mxGetPr(prhs[1]); /* OutPut分配空间 */ if(*nodeType == 4.0) { INT16* out; out = (INT16*)mxCalloc(DATANUMS,sizeof(INT16_T)); plhs[0] = mxCreateNumericArray(2,dims,mxINT16_CLASS,mxREAL); for(int i = 0; i < DATANUMS; i++) out[i] = *((INT16*)(originalData+i*2)); mxSetData(plhs[0],out); } else if(*nodeType == 100.0) { UINT16* out; out = (UINT16*)mxCalloc(DATANUMS,sizeof(UINT16_T)); plhs[0] = mxCreateNumericArray(2,dims,mxUINT16_CLASS,mxREAL); for(int i = 0; i < DATANUMS; i++) out[i] = *((UINT16*)(originalData+i*2)); mxSetData(plhs[0],out); } // sscanf(input_buf, "%16x", mxGetData(plhs[0])); // long hexa //mxFree(originalData); return; }
/* MEX GATEWAY */ void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { int num, jobid, i; mwSize idx; double *arg_p; arg_p = mxGetPr(prhs[0]); /* TODO: This uses 2x the minimal necessary memory */ /* UINT8_T data[(int)arg_p[1]]; */ UINT8_T data[4096]; UINT8_T *mesg_data; get_shmem_mesg(data, prhs[0], &jobid); mesg_data = mxCalloc((int)arg_p[0], sizeof(UINT8_T)); for ( idx = 0; idx < (int)arg_p[0]; idx++ ) { mesg_data[idx] = data[idx]; } plhs[0] = mxCreateNumericMatrix(0, 0, mxUINT8_CLASS, mxREAL); /* printf(" mesg_data[0] : %d \n", mesg_data[0]); printf(" mesg_data[end] : %d \n", mesg_data[(int)arg_p[0]-1]); printf(" nbytes : %d \n", (int)arg_p[0]); */ /* Point mxArray to dynamicData */ mxSetData(plhs[0], mesg_data); mxSetM(plhs[0], (int)arg_p[0]); mxSetN(plhs[0], 1); return; }
/* the gateway routine. */ void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { double *num_bytes; num_bytes = mxGetPr(prhs[0]); int num; num = (int)*num_bytes; /* TODO: This uses 2x the minimal necessary memory */ UINT8_T data[num]; get_shmem_mesg(data, num); UINT8_T *mesg_data; mwSize idx; mesg_data = mxCalloc(num, sizeof(UINT8_T)); for ( idx = 0; idx < num; idx++ ) { mesg_data[idx] = data[idx]; } plhs[0] = mxCreateNumericMatrix(0, 0, mxUINT8_CLASS, mxREAL); /* Point mxArray to dynamicData */ mxSetData(plhs[0], mesg_data); mxSetM(plhs[0], num); mxSetN(plhs[0], 1); return; }
mxArray* GetMexArray(int N, int M) { mxArray* Array = mxCreateDoubleMatrix(0, 0, mxREAL); mxSetM(Array, N); mxSetN(Array, M); mxSetData(Array, mxMalloc(sizeof(double)*M*N)); return Array; }
/* * Arguments : const real_T u[1302] * const mxArray *y * Return Type : void */ static void emlrt_marshallOut(const real_T u[1302], const mxArray *y) { static const int32_T iv0[2] = { 1, 1302 }; mxSetData((mxArray *)y, (void *)u); emlrtSetDimensions((mxArray *)y, iv0, 2); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { #define spikes_out plhs[0] #define spikesA_in prhs[0] #define spikesB_in prhs[1] #define cespA_in prhs[2] #define cespB_in prhs[3] #define length_in prhs[4] int num_spikesA, num_spikesB, *length, i, j; float *spikesA, *spikesB, *spikes, *cespA, *cespB; spikesA = (float *)mxGetPr(spikesA_in); spikesB = (float *)mxGetPr(spikesB_in); cespA = (float *)mxGetPr(cespA_in); cespB = (float *)mxGetPr(cespB_in); length = (int *)mxGetPr(length_in); num_spikesA = mxGetN(spikesA_in); num_spikesB = mxGetN(spikesB_in); spikes_out = mxCreateNumericArray(0, 0, mxSINGLE_CLASS, mxREAL); mxSetM(spikes_out, 2); mxSetN(spikes_out, *length); mxSetData(spikes_out, mxMalloc(sizeof(float) * 2 * *length)); spikes = (float *)mxGetPr(spikes_out); i = 0; j = 0; while (i + j < *length) { if ((spikesA[i] < spikesB[j] && i < num_spikesA)||(j == num_spikesB)) { spikes[2*(i+j)] = cespA[i]; if (j > 0) spikes[1 + 2*(i+j)] = cespB[j-1]; else spikes[1 + 2*(i+j)] = 0; if (i < num_spikesA) i++; } else { spikes[1 + 2*(i+j)] = cespB[j]; if (i > 0) spikes[2*(i+j)] = cespA[i-1]; else spikes[2*(i+j)] = 0; if (j < num_spikesB) j++; } } return; }
void flowToInds(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { /* [rs,cs,is]=flowToInds(us,vs,m,n,flag); */ int m, n, m1, n1, flag; double *us, *vs; int *is, ind=0, i, j, fr, fc; double *rs, *cs, r, c; /* extract inputs */ us = (double*) mxGetData(prhs[0]); vs = (double*) mxGetData(prhs[1]); m = (int) mxGetScalar(prhs[2]); n = (int) mxGetScalar(prhs[3]); flag = (int) mxGetScalar(prhs[4]); /* initialize memory */ m1=(int)mxGetM(prhs[0]); n1=(int)mxGetN(prhs[0]); rs = mxMalloc(sizeof(double)*m1*n1); cs = mxMalloc(sizeof(double)*m1*n1); is = mxMalloc(sizeof(int)*m1*n1); /* clamp and compute ids according to flag */ if( flag==1 ) { /* nearest neighbor */ for(i=0; i<n1; i++) for(j=0; j<m1; j++) { r=us[ind]+j+1; r = r<1 ? 1 : (r>m ? m : r); c=vs[ind]+i+1; c = c<1 ? 1 : (c>n ? n : c); is[ind] = ((int) (r-.5)) + ((int) (c-.5)) * m; ind++; } } else if(flag==2) { /* bilinear */ for(i=0; i<n1; i++) for(j=0; j<m1; j++) { r=us[ind]+j+1; r = r<2 ? 2 : (r>m-1 ? m-1 : r); fr = (int) r; c=vs[ind]+i+1; c = c<2 ? 2 : (c>n-1 ? n-1 : c); fc = (int) c; rs[ind]=r-fr; cs[ind]=c-fc; is[ind]=(fr-1)+(fc-1)*m; ind++; } } else { /* other cases - clamp only */ for(i=0; i<n1; i++) for(j=0; j<m1; j++) { r=us[ind]+j+1; rs[ind] = r<2 ? 2 : (r>m-1 ? m-1 : r); c=vs[ind]+i+1; cs[ind] = c<2 ? 2 : (c>n-1 ? n-1 : c); ind++; } } /* create output array */ plhs[0] = mxCreateNumericMatrix(0,0,mxDOUBLE_CLASS,mxREAL); plhs[1] = mxCreateNumericMatrix(0,0,mxDOUBLE_CLASS,mxREAL); plhs[2] = mxCreateNumericMatrix(0,0,mxINT32_CLASS,mxREAL); mxSetData(plhs[0],rs); mxSetM(plhs[0],m1); mxSetN(plhs[0],n1); mxSetData(plhs[1],cs); mxSetM(plhs[1],m1); mxSetN(plhs[1],n1); mxSetData(plhs[2],is); mxSetM(plhs[2],m1); mxSetN(plhs[2],n1); }
void homogsToFlow(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { /* [us,vs]=homogsToFlow(H,M); */ int i, j, k, m, n, q, *dims, affine=1, ind=0; unsigned int *M; double *H, *H1, *us, *vs; double r, c, r0, c0, z; /* extract inputs */ H = (double*) mxGetData(prhs[0]); M = (unsigned int*) mxGetData(prhs[1]); m = (int) mxGetM(prhs[1]); n = (int) mxGetN(prhs[1]); if(mxGetNumberOfDimensions(prhs[0])==2) q=1; else { dims=(int*) mxGetDimensions(prhs[0]); q=dims[2]; } /* initialize memory */ us = mxMalloc(sizeof(double)*m*n); vs = mxMalloc(sizeof(double)*m*n); /* Compute flow at each grid point */ r0=(-m+1.0)/2.0; c0=(-n+1.0)/2.0; for( k=0; k<q; k++ ) { H1=H+k*9; for(i=0; i<9; i++) H1[i]=H1[i]/H1[8]; affine=affine && H1[2]==0 && H1[5]==0; } if( affine ) { for( i=0; i<n; i++ ) for(j=0; j<m; j++) { k=M[ind]; H1=H+k*9; r=r0+j; c=c0+i; us[ind] = H1[0]*r + H1[3]*c + H1[6] - r; vs[ind] = H1[1]*r + H1[4]*c + H1[7] - c; ind++; } } else { for( i=0; i<n; i++ ) for(j=0; j<m; j++) { k=M[ind]; H1=H+k*9; r=r0+j; c=c0+i; us[ind] = H1[0]*r + H1[3]*c + H1[6]; vs[ind] = H1[1]*r + H1[4]*c + H1[7]; z = H1[2]*r + H1[5]*c + 1; us[ind]=us[ind]/z-r; vs[ind]=vs[ind]/z-c; ind++; } } /* create output array */ plhs[0] = mxCreateNumericMatrix(0,0,mxDOUBLE_CLASS,mxREAL); plhs[1] = mxCreateNumericMatrix(0,0,mxDOUBLE_CLASS,mxREAL); mxSetData(plhs[0],us); mxSetM(plhs[0],m); mxSetN(plhs[0],n); mxSetData(plhs[1],vs); mxSetM(plhs[1],m); mxSetN(plhs[1],n); }
// Create [hxwxd] mxArray array, initialize to 0 if c=true mxArray* mxCreateMatrix3( int h, int w, int d, mxClassID id, bool c, void **I ){ const int dims[3]={h,w,d}, n=h*w*d; int b; mxArray* M; if( id==mxINT32_CLASS ) b=sizeof(int); else if( id==mxDOUBLE_CLASS ) b=sizeof(double); else if( id==mxSINGLE_CLASS ) b=sizeof(float); else mexErrMsgTxt("Unknown mxClassID."); *I = c ? mxCalloc(n,b) : mxMalloc(n*b); M = mxCreateNumericMatrix(0,0,id,mxREAL); mxSetData(M,*I); mxSetDimensions(M,dims,3); return M; }
/************************************************************************** * mexFunction: gateway routine for MATLAB interface. ***************************************************************************/ void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { // Argument checking if (nrhs != 9) mexErrMsgIdAndTxt(FUNC_NAME, "Wrong input."); if (nlhs != 3) mexErrMsgIdAndTxt(FUNC_NAME, "Wrong output."); // Input and output variables idx_t ne = (idx_t) mxGetScalar(ne_in); idx_t nn = (idx_t) mxGetScalar(nn_in); idx_t *eptr; GetIdxArray(eptr_in,&eptr); idx_t *eind; GetIdxArray(eind_in,&eind); idx_t *vwgt; GetIdxArray(vwgt_in,&vwgt); idx_t *vsize; GetIdxArray(vsize_in,&vsize); idx_t nparts = (idx_t) mxGetScalar(nparts_in); real_t *tpwgts; GetRealArray(tpwgts_in,&tpwgts); idx_t options[METIS_NOPTIONS]; GetOptions(options_in, options); idx_t objval; idx_t *epart = (idx_t*) mxCalloc (ne, sizeof(idx_t)); idx_t *npart = (idx_t*) mxCalloc (nn, sizeof(idx_t)); // Metis main function int info = METIS_PartMeshNodal( &ne, &nn, eptr, eind, vwgt, vsize, &nparts, tpwgts, options, &objval, epart, npart); CheckReturn(info, FUNC_NAME); // Output objval_out = mxCreateDoubleScalar( (double) objval ); epart_out = mxCreateDoubleMatrix(1,ne,mxREAL); mxSetData(epart_out,mxMalloc(sizeof(double)*ne)); double *epart_out_pr = mxGetPr(epart_out); for(idx_t i=0; i<ne; i++) epart_out_pr[i] = (double) epart[i]; npart_out = mxCreateDoubleMatrix(1,nn,mxREAL); mxSetData(npart_out,mxMalloc(sizeof(double)*nn)); double *npart_out_pr = mxGetPr(npart_out); for(idx_t i=0; i<nn; i++) npart_out_pr[i] = (double) npart[i]; }
static const mxArray *emlrt_marshallOut(emxArray_real_T *u) { const mxArray *y; static const int32_T iv2[2] = { 0, 0 }; const mxArray *m2; y = NULL; m2 = mxCreateNumericArray(2, (int32_T *)&iv2, mxDOUBLE_CLASS, mxREAL); mxSetData((mxArray *)m2, (void *)u->data); mxSetDimensions((mxArray *)m2, u->size, 2); emlrtAssign(&y, m2); return y; }
/* * Arguments : const emxArray_real_T *u * Return Type : const mxArray * */ static const mxArray *emlrt_marshallOut(const emxArray_real_T *u) { const mxArray *y; static const int32_T iv0[3] = { 0, 0, 0 }; const mxArray *m0; y = NULL; m0 = emlrtCreateNumericArray(3, iv0, mxDOUBLE_CLASS, mxREAL); mxSetData((mxArray *)m0, (void *)u->data); emlrtSetDimensions((mxArray *)m0, u->size, 3); emlrtAssign(&y, m0); return y; }
static const mxArray *f_emlrt_marshallOut(const emxArray_real_T *u) { const mxArray *y; static const int32_T iv83[2] = { 0, 0 }; const mxArray *m20; y = NULL; m20 = emlrtCreateNumericArray(2, iv83, mxDOUBLE_CLASS, mxREAL); mxSetData((mxArray *)m20, (void *)u->data); emlrtSetDimensions((mxArray *)m20, u->size, 2); emlrtAssign(&y, m20); return y; }
static const mxArray *g_emlrt_marshallOut(const emxArray_real_T *u) { const mxArray *y; static const int32_T iv84[1] = { 0 }; const mxArray *m21; y = NULL; m21 = emlrtCreateNumericArray(1, iv84, mxDOUBLE_CLASS, mxREAL); mxSetData((mxArray *)m21, (void *)u->data); emlrtSetDimensions((mxArray *)m21, u->size, 1); emlrtAssign(&y, m21); return y; }
static const mxArray *i_emlrt_marshallOut(const int32_T u_size[2]) { const mxArray *y; static const int32_T iv12[2] = { 0, 0 }; const mxArray *m8; y = NULL; m8 = emlrtCreateNumericArray(2, iv12, mxDOUBLE_CLASS, mxREAL); mxSetData((mxArray *)m8, NULL); emlrtSetDimensions((mxArray *)m8, u_size, 2); emlrtAssign(&y, m8); return y; }
void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[] ) { int *ns, ms[3], nDims, d, m, r, s; float *A, *B, p; mxClassID id; char type[1024]; // error checking on arguments if(nrhs!=4) mexErrMsgTxt("Four inputs required."); if(nlhs > 1) mexErrMsgTxt("One output expected."); nDims = mxGetNumberOfDimensions(prhs[1]); id = mxGetClassID(prhs[1]); ns = (int*) mxGetDimensions(prhs[1]); d = (nDims == 3) ? ns[2] : 1; m = (ns[0] < ns[1]) ? ns[0] : ns[1]; if( (nDims!=2 && nDims!=3) || id!=mxSINGLE_CLASS || m<4 ) mexErrMsgTxt("A must be a 4x4 or bigger 2D or 3D float array."); // extract inputs if(mxGetString(prhs[0],type,1024)) mexErrMsgTxt("Failed to get type."); A = (float*) mxGetData(prhs[1]); p = (float) mxGetScalar(prhs[2]); r = (int) mxGetScalar(prhs[2]); s = (int) mxGetScalar(prhs[3]); if( s<1 ) mexErrMsgTxt("Invalid sampling value s"); if( r<0 ) mexErrMsgTxt("Invalid radius r"); // create output array (w/o initializing to 0) ms[0]=ns[0]/s; ms[1]=ns[1]/s; ms[2]=d; B = (float*) mxMalloc(ms[0]*ms[1]*d*sizeof(float)); plhs[0] = mxCreateNumericMatrix(0, 0, mxSINGLE_CLASS, mxREAL); mxSetData(plhs[0], B); mxSetDimensions(plhs[0],(mwSize*)ms,nDims); // perform appropriate type of convolution if(!strcmp(type,"convBox")) { if(r>=m/2) mexErrMsgTxt("mask larger than image (r too large)"); convBox( A, B, ns[0], ns[1], d, r, s ); } else if(!strcmp(type,"convTri")) { if(r>=m/2) mexErrMsgTxt("mask larger than image (r too large)"); convTri( A, B, ns[0], ns[1], d, r, s ); } else if(!strcmp(type,"conv11")) { if( s>2 ) mexErrMsgTxt("conv11 can sample by at most s=2"); conv11( A, B, ns[0], ns[1], d, r, s ); } else if(!strcmp(type,"convTri1")) { if( s>2 ) mexErrMsgTxt("convTri1 can sample by at most s=2"); convTri1( A, B, ns[0], ns[1], d, p, s ); } else if(!strcmp(type,"convMax")) { if( s>1 ) mexErrMsgTxt("convMax cannot sample"); convMax( A, B, ns[0], ns[1], d, r ); } else { mexErrMsgTxt("Invalid type."); } }
int csimMexCreate(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { /* ** Create some fresh empty network */ if ( !TheNetwork ) TheNetwork = new MexNetwork(); if ( nrhs < 2 || nrhs > 3 || nlhs != 1 ) mexErrMsgTxt("CSIM-Usage: idx = csim('create',className[,n]);\n"); char *className; if ( getString(prhs[1],&className) ) mexErrMsgTxt("CSIM-Usage: idx = csim('create',className[,n]); className not a string.\n"); int n=1; if ( nrhs > 2 ) { double tmp; if ( getDouble(prhs[2],&tmp) ) mexErrMsgTxt("CSIM-Usage: idx = csim('create',className[,n]); n not a single double.\n"); n = (int)(tmp); } uint32 *idx = (uint32 *)mxCalloc(n,sizeof(uint32)); int switchError = 0; // #define __SWITCH_COMMAND__ { for(int i=0; i<n; i++) if ( (idx[i]=TheNetwork->addNewObject((Advancable *)(new TYPE))) < 0 ) { TheCsimError.add("can not add %s (i=%i)\n",className,i); return -1; } } Advancable *a; a=0; #define __SWITCH_COMMAND__ { for(int i=0; i<n; i++) { \ idx[i]=TheNetwork->addNewObject(a=(Advancable *)(new TYPE)); \ if ( a->init(a) < 0 ) { \ TheCsimError.add("csim('create',className,n): error calling init of %s!\n",className); \ return -1; \ } \ } \ } #include "switch.i" if ( switchError < 0 ) { TheCsimError.add("csim('create',className,n): Unknown className %s!\n",className); return -1; } else { plhs[0] = mxCreateNumericMatrix ( 0, 0, mxUINT32_CLASS, mxREAL ); mxSetM(plhs[0],1); mxSetN(plhs[0],n); mxSetData(plhs[0],(void *)idx); } return 0; }
/************************************************************************** * mexFunction: gateway routine for MATLAB interface. ***************************************************************************/ void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { // Argument checking if (nrhs != 4) mexErrMsgIdAndTxt(FUNC_NAME, "Wrong input."); if (nlhs != 2) mexErrMsgIdAndTxt(FUNC_NAME, "Wrong output."); // Input and output variables idx_t ne = (idx_t) mxGetScalar(ne_in); idx_t nn = (idx_t) mxGetScalar(nn_in); idx_t *eptr; GetIdxArray(eptr_in,&eptr); idx_t *eind; GetIdxArray(eind_in,&eind); idx_t numflag = 0; idx_t *xadj = NULL; idx_t *adjncy = NULL; // Metis main function int info = METIS_MeshToNodal( &ne, &nn, eptr, eind, &numflag, &xadj, &adjncy); CheckReturn(info, FUNC_NAME); // Output idx_t nvtxs = (idx_t) (sizeof(xadj)/sizeof(idx_t)); xadj_out = mxCreateDoubleMatrix(1,nvtxs+1,mxREAL); mxSetData(xadj_out,mxMalloc(sizeof(double)*(nvtxs+1))); double *xadj_out_pr = mxGetPr(xadj_out); for(idx_t i=0; i<nvtxs+1; i++) xadj_out_pr[i] = (double) xadj[i]; idx_t n = (idx_t) xadj[nvtxs]; adjncy_out = mxCreateDoubleMatrix(1,n,mxREAL); mxSetData(adjncy_out,mxMalloc(sizeof(double)*n)); double *adjncy_out_pr = mxGetPr(adjncy_out); for(idx_t i=0; i<n; i++) adjncy_out_pr[i] = (double) adjncy[i]; }
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){ //Input is unit8 matrix. Output is same size uint8 matrix to delete //Acquire and comfirm inputs/outputs //Pad with zeros around //loop through elements, pull the local 3x3, perform connectivity check //write to delete as 1 true, leave alone as 0 false #define A_IN prhs[0] #define X_OUT plhs[0] mxArray *A, *X, *PAD, *padSize, *toPad[2]; padSize = mxCreateNumericMatrix( 1, 2, mxUINT8_CLASS, mxREAL ); int M, N, m, n, *vals; vals[0] = 1; vals[1] = 1; mxSetData( padSize, vals ); if( nrhs != 1 ) mexErrMsgTxt("Wrong number of input arguments."); else if( nlhs != 1 ) mexErrMsgTxt("Wrong number of output arguments."); if( !IS_REAL_2D_FULL_UINT8( A_IN ) ) mexErrMsgTxt("Input must be uint8, not sparse, and 2D real."); M = mxGetM(A_IN); N = mxGetN(A_IN); A = (mxArray*)mxGetPr(A_IN); X = (mxArray*)mxGetPr(X_OUT); X = mxCreateNumericMatrix( 0, 0, mxUINT8_CLASS, mxREAL ); mxSetM( X, M+2 ); mxSetN( X, N+2 ); mxSetData( X, mxMalloc( sizeof(uint8_t)*(M+2)*(N+2) ) ); PAD = mxCreateNumericMatrix( 0, 0, mxUINT8_CLASS, mxREAL ); mxSetM( PAD, M+2 ); mxSetN( PAD, N+2 ); mxSetData( PAD, mxMalloc( sizeof(uint8_t)*(M+2)*(N+2) ) ); toPad[0] = A; toPad[1] = padSize; mexCallMATLAB( 1, &PAD, 2, toPad, "padarray" ); memcpy( mxGetPr(X), PAD, sizeof(uint8_t)*(M+2)*(N+2) ); return; }
mxArray* get_marker(Stim &stim) { extern const int red; mxArray* marker = mxCreateDoubleMatrix(0, 0, mxREAL); mxSetM(marker, 1); mxSetN(marker, stim.marker_stimulation.size()); mxSetData(marker, mxMalloc(sizeof(double)*stim.marker_stimulation.size())); double* Pr_Marker = mxGetPr(marker); unsigned counter = 0; /* Division by res transforms marker time from dt to sampling rate */ for(auto & elem : stim.marker_stimulation) { Pr_Marker[counter++] = elem/red; } return marker; }
static const mxArray *d_emlrt_marshallOut(const real_T u[7]) { const mxArray *y; static const int32_T iv3[2] = { 0, 0 }; const mxArray *m3; static const int32_T iv4[2] = { 1, 7 }; y = NULL; m3 = emlrtCreateNumericArray(2, iv3, mxDOUBLE_CLASS, mxREAL); mxSetData((mxArray *)m3, (void *)u); emlrtSetDimensions((mxArray *)m3, iv4, 2); emlrtAssign(&y, m3); return y; }
static const mxArray *c_emlrt_marshallOut(const real_T u[2]) { const mxArray *y; static const int32_T iv79[2] = { 0, 0 }; const mxArray *m17; static const int32_T iv80[2] = { 1, 2 }; y = NULL; m17 = emlrtCreateNumericArray(2, iv79, mxDOUBLE_CLASS, mxREAL); mxSetData((mxArray *)m17, (void *)u); emlrtSetDimensions((mxArray *)m17, iv80, 2); emlrtAssign(&y, m17); return y; }
static const mxArray *f_emlrt_marshallOut(const real_T u[2]) { const mxArray *y; static const int32_T iv7[2] = { 0, 0 }; const mxArray *m5; static const int32_T iv8[2] = { 1, 2 }; y = NULL; m5 = emlrtCreateNumericArray(2, iv7, mxDOUBLE_CLASS, mxREAL); mxSetData((mxArray *)m5, (void *)u); emlrtSetDimensions((mxArray *)m5, iv8, 2); emlrtAssign(&y, m5); return y; }
static const mxArray *c_emlrt_marshallOut(const real_T u[5]) { const mxArray *y; static const int32_T iv12[1] = { 0 }; const mxArray *m5; static const int32_T iv13[1] = { 5 }; y = NULL; m5 = emlrtCreateNumericArray(1, iv12, mxDOUBLE_CLASS, mxREAL); mxSetData((mxArray *)m5, (void *)u); emlrtSetDimensions((mxArray *)m5, iv13, 1); emlrtAssign(&y, m5); return y; }
static const mxArray *d_emlrt_marshallOut(const real_T u[25]) { const mxArray *y; static const int32_T iv14[2] = { 0, 0 }; const mxArray *m6; static const int32_T iv15[2] = { 5, 5 }; y = NULL; m6 = emlrtCreateNumericArray(2, iv14, mxDOUBLE_CLASS, mxREAL); mxSetData((mxArray *)m6, (void *)u); emlrtSetDimensions((mxArray *)m6, iv15, 2); emlrtAssign(&y, m6); return y; }
static const mxArray *e_emlrt_marshallOut(const real_T u[3]) { const mxArray *y; static const int32_T iv5[2] = { 0, 0 }; const mxArray *m4; static const int32_T iv6[2] = { 1, 3 }; y = NULL; m4 = emlrtCreateNumericArray(2, iv5, mxDOUBLE_CLASS, mxREAL); mxSetData((mxArray *)m4, (void *)u); emlrtSetDimensions((mxArray *)m4, iv6, 2); emlrtAssign(&y, m4); return y; }
/* * Arguments : const real_T u[5] * Return Type : const mxArray * */ static const mxArray *emlrt_marshallOut(const real_T u[5]) { const mxArray *y; static const int32_T iv0[1] = { 0 }; const mxArray *m0; static const int32_T iv1[1] = { 5 }; y = NULL; m0 = emlrtCreateNumericArray(1, iv0, mxDOUBLE_CLASS, mxREAL); mxSetData((mxArray *)m0, (void *)u); emlrtSetDimensions((mxArray *)m0, iv1, 1); emlrtAssign(&y, m0); return y; }
/* * Arguments : const real_T u[25] * Return Type : const mxArray * */ static const mxArray *b_emlrt_marshallOut(const real_T u[25]) { const mxArray *y; static const int32_T iv2[2] = { 0, 0 }; const mxArray *m1; static const int32_T iv3[2] = { 5, 5 }; y = NULL; m1 = emlrtCreateNumericArray(2, iv2, mxDOUBLE_CLASS, mxREAL); mxSetData((mxArray *)m1, (void *)u); emlrtSetDimensions((mxArray *)m1, iv3, 2); emlrtAssign(&y, m1); return y; }