cholmod_dense *spqr_mx_get_dense ( const mxArray *Amatlab, // MATLAB version of the matrix cholmod_dense *A, // CHOLMOD version of the matrix double *dummy // a pointer to a valid scalar double ) { A->nrow = mxGetM (Amatlab) ; A->ncol = mxGetN (Amatlab) ; A->d = A->nrow ; A->nzmax = A->nrow * A->ncol ; A->dtype = CHOLMOD_DOUBLE ; if (mxIsEmpty (Amatlab)) { A->x = dummy ; A->z = dummy ; } else if (mxIsDouble (Amatlab)) { A->x = mxGetPr (Amatlab) ; A->z = mxGetPi (Amatlab) ; } else { // only full double matrices supported mexErrMsgIdAndTxt ("QR:invalidInput", "matrix type not supported") ; } A->xtype = mxIsComplex (Amatlab) ? CHOLMOD_ZOMPLEX : CHOLMOD_REAL ; return (A) ; }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { // check correct number of arguments if( (nlhs!=0) || (nrhs!=1) ) mexErrMsgTxt("Please use as: [<periphery_pixels>, <fovea_pixels>] = logmap(<input_img>)\n"); // check correct handle type if(!mxIsUint64(prhs[0])) mexErrMsgTxt("Invalid handle\n"); if(mxIsEmpty(prhs[0])) mexErrMsgTxt("Invalid handle\n"); //get handle unsigned long long *pointer = (unsigned long long*)mxGetData(prhs[0]); CMatlabLogPolarCam *cam = (CMatlabLogPolarCam *)pointer[0]; if( cam->id != CMATLABLOGPOLARCAMHANDLEID ) mexErrMsgTxt("Invalid object\n"); //deallocate memory cam->id = NULL; cam->destroy_logpolar_sensor(); delete cam; return; }
int mxW_CVodeBBDgcom(long int Nlocal, realtype t, N_Vector y, void *user_data) { cvmPbData fwdPb; mxArray *mx_in[4], *mx_out[2]; int ret; /* Extract global interface data from user-data */ fwdPb = (cvmPbData) user_data; /* Inputs to the Matlab function */ mx_in[0] = mxCreateDoubleScalar(t); /* current t */ mx_in[1] = mxCreateDoubleMatrix(N,1,mxREAL); /* current y */ mx_in[2] = fwdPb->GCOMfct; /* matlab function handle */ mx_in[3] = fwdPb->mtlb_data; /* matlab user data */ /* Call matlab wrapper */ GetData(y, mxGetPr(mx_in[1]), N); mexCallMATLAB(2,mx_out,4,mx_in,"cvm_gcom"); ret = (int)*mxGetPr(mx_out[0]); if (!mxIsEmpty(mx_out[1])) { UpdateUserData(mx_out[1], fwdPb); } /* Free temporary space */ mxDestroyArray(mx_in[0]); mxDestroyArray(mx_in[1]); mxDestroyArray(mx_out[0]); mxDestroyArray(mx_out[1]); return(ret); }
int mtlb_IdaDenseJacB(long int NeqB, realtype tt, N_Vector yy, N_Vector yp, N_Vector yyB, N_Vector ypB, N_Vector rrB, realtype c_jB, void *jac_dataB, DenseMat JacB, N_Vector tmp1B, N_Vector tmp2B, N_Vector tmp3B) { double *JB_data; long int i; mxArray *mx_in[10], *mx_out[3]; int ret; /* Inputs to the Matlab function */ mx_in[0] = mxCreateScalarDouble(-1.0); /* type=-1: backward ODE */ mx_in[1] = mxCreateScalarDouble(tt); /* current t */ mx_in[2] = mxCreateDoubleMatrix(N,1,mxREAL); /* current yy */ mx_in[3] = mxCreateDoubleMatrix(N,1,mxREAL); /* current yp */ mx_in[4] = mxCreateDoubleMatrix(NB,1,mxREAL); /* current yyB */ mx_in[5] = mxCreateDoubleMatrix(NB,1,mxREAL); /* current ypB */ mx_in[6] = mxCreateDoubleMatrix(NB,1,mxREAL); /* current rrB */ mx_in[7] = mxCreateScalarDouble(c_jB); /* current c_jB */ mx_in[8] = mx_JACfctB; /* matlab function handle */ mx_in[9] = mx_data; /* matlab user data */ /* Call matlab wrapper */ GetData(yy, mxGetPr(mx_in[2]), N); GetData(yp, mxGetPr(mx_in[3]), N); GetData(yyB, mxGetPr(mx_in[4]), NB); GetData(ypB, mxGetPr(mx_in[5]), NB); GetData(rrB, mxGetPr(mx_in[6]), NB); mexCallMATLAB(3,mx_out,10,mx_in,"idm_djac"); JB_data = mxGetPr(mx_out[0]); for (i=0; i<NB; i++) memcpy(DENSE_COL(JacB,i), JB_data + i*NB, NB*sizeof(double)); ret = (int)*mxGetPr(mx_out[1]); if (!mxIsEmpty(mx_out[2])) { UpdateUserData(mx_out[2]); } /* Free temporary space */ mxDestroyArray(mx_in[0]); mxDestroyArray(mx_in[1]); mxDestroyArray(mx_in[2]); mxDestroyArray(mx_in[3]); mxDestroyArray(mx_in[4]); mxDestroyArray(mx_in[5]); mxDestroyArray(mx_in[6]); mxDestroyArray(mx_in[7]); mxDestroyArray(mx_out[0]); mxDestroyArray(mx_out[1]); mxDestroyArray(mx_out[2]); return(ret); }
void addflops(unsigned fl) { #if 0 mxArray *flopcount = mexGetArray("flopcount","global"); if(flopcount && !mxIsEmpty(flopcount))) { *mxGetPr(flopcount) += fl; mexPutArray(flopcount,"global"); } #else /* Matlab 6.5 */ mxArray *flopcount = mexGetVariable("global","flopcount"); if(flopcount && !mxIsEmpty(flopcount)) { *mxGetPr(flopcount) += fl; mexPutVariable("global","flopcount",flopcount); } #endif }
/** * @brief Interfaces C and Matlab data. * This function is the MEX-file gateway routine. Please see the Matlab * MEX-file documentation (http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f43721.html) * for more information. */ void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { /* allocate variables */ struct histcond *in; struct options_entropy *opts; int status; /* check number of inputs (nargin) and outputs (nargout) */ if((nrhs<1) | (nrhs>2)) mexErrMsgIdAndTxt("STAToolkit:infocond:numArgs","1 or 2 input arguments required."); if((nlhs<1) | (nlhs>2)) mexErrMsgIdAndTxt("STAToolkit:infocond:numArgs","1 or 2 outputs argument required."); /* get or set options */ if(nrhs<2) opts = ReadOptionsEntropy(mxCreateEmptyStruct()); else if(mxIsEmpty(prhs[1])) opts = ReadOptionsEntropy(mxCreateEmptyStruct()); else opts = ReadOptionsEntropy(prhs[1]); plhs[0] = mxDuplicateArray(prhs[0]); in = ReadHistCond(plhs[0],opts); status = InfoCondComp(in,opts); if(status!=EXIT_SUCCESS) mexWarnMsgIdAndTxt("STAToolkit:infocond:failure","Function infocond returned with errors. Please check messages."); /* Augment the mx histogram with the new info */ WriteHistCondAgain(in,plhs[0]); /* output options used */ if(nrhs<2) plhs[1] = WriteOptionsEntropy(mxCreateEmptyStruct(),opts); else if(mxIsEmpty(prhs[1])) plhs[1] = WriteOptionsEntropy(mxCreateEmptyStruct(),opts); else plhs[1] = WriteOptionsEntropy(prhs[1],opts); mxFree(in); return; }
/** * @brief Read in the option possible_words. * Reads the option possible_words, converting string data into its numerical * representation, and returning a flag to indicate the status. */ int ReadOptionPossibleWords(const mxArray *in,const char *field_name,double *member) { /* declare local variables */ mxArray *tmp; double num; int stringLength, flag, i; char *str; tmp = mxGetField(in,0,field_name); if((tmp==NULL) || mxIsEmpty(tmp)) /* field is empty */ flag = 0; else { if(mxIsChar(tmp)) /* field is string */ { /* copy string and set to lowercase */ stringLength = mxGetNumberOfElements(tmp) + 1; str = mxCalloc(stringLength,sizeof(char)); if(mxGetString(tmp,str,stringLength)!=0) mexErrMsgIdAndTxt("STAToolkit:ReadOptionPossibleWords:invalidValue","Could not convert string data."); for(i=0;str[i];i++) str[i] = tolower(str[i]); /* use string to set member value */ flag = 1; if(strcmp(str,"recommended")==0) *member = (double)(-1.0); else if(strcmp(str,"unique")==0) *member = (double)(-2.0); else if(strcmp(str,"total")==0) *member = (double)(-3.0); else if(strcmp(str,"possible")==0) *member = (double)(-4.0); else if(strcmp(str,"min_tot_pos")==0) *member = (double)(-5.0); else if(strcmp(str,"min_lim_tot_pos")==0) *member = (double)(-6.0); else { mexWarnMsgIdAndTxt("STAToolkit:ReadOptionPossibleWords:invalidValue","Unrecognized option \"%s\" for possible_words. Using default \"recommended\".",str); *member = (double)(-1.0); } } else /* field is scalar */ { flag = 2; num = mxGetScalar(tmp); if(num==mxGetInf()) *member = (double)(0.0); else if((num<1.0) || (fmod(num,1.0)>mxGetEps())) mexErrMsgIdAndTxt("STAToolkit:ReadOptionPossibleWords:invalidValue","possible_words must be a positive integer. Current value is %f.",num); else *member = num; } } return flag; }
// FunctionID 10: PCRand void PCRand(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { //declare variables double *U, *V, *theta, *Rotation; double *Family, *N; int family, rotation; unsigned int n; //associate inputs Family = mxGetPr(prhs[2]); family = (int) *Family; N = mxGetPr(prhs[3]); n = (unsigned int) *N; theta = mxGetPr(prhs[4]); // Load the state of the seed double *OldState, *StateExport; int i; OldState = mxGetPr(prhs[1]); std::vector<unsigned int> StateImport(624); for (i=0;i<624;i++) { StateImport[i] = (unsigned int) OldState[i]; } //associate outputs plhs[1] = mxCreateDoubleMatrix(n,1,mxREAL); plhs[2] = mxCreateDoubleMatrix(n,1,mxREAL); U = mxGetPr(plhs[1]); V = mxGetPr(plhs[2]); if (nrhs==6 && !mxIsEmpty(prhs[5])) { Rotation = mxGetPr(prhs[5]); rotation = (int) *Rotation; PairCopulaRand(StateImport,family,rotation,theta,U,V,n); } else { PairCopulaRand(StateImport,family,theta,U,V,n); } plhs[0] = mxCreateDoubleMatrix(624, 1, mxREAL); StateExport = mxGetPr(plhs[0]); for (i=0;i<624;i++) { StateExport[i] = (double) StateImport[i]; } return; }
int opt_getIntFromOpt (const mxArray *opt, POptionSettings optSet, const char *name, int defaultValue) { mxArray *field; mxClassID classID; void *data; field=mxGetField(opt,(mwIndex)0,name); if ((field==NULL) || (mxIsEmpty(field))) { if (optSet->warnMiss) mexPrintf("Option '%s' fehlt, nehme default %i\n",name,defaultValue); return defaultValue; } classID=mxGetClassID(field); switch (classID) { case mxDOUBLE_CLASS: case mxINT8_CLASS: case mxUINT8_CLASS: case mxINT16_CLASS: case mxUINT16_CLASS: case mxINT32_CLASS: case mxUINT32_CLASS: case mxINT64_CLASS: case mxUINT64_CLASS: break; default: if (optSet->warnType) mexPrintf("Option '%s' hat falschen Typ, nehme default %i\n", name,defaultValue); return defaultValue; } if ((mxGetNumberOfDimensions(field)!=(mwSize)2) || (mxGetM(field)!=(size_t)1) || (mxGetN(field)!=(size_t)1)) { if (optSet->warnSize) mexPrintf("Option '%s' hat falsche Größe, nehme default %i\n", name,defaultValue); return defaultValue; } data=mxGetData(field); switch (classID) { case mxDOUBLE_CLASS: return (int)*((double*) data);break; case mxINT8_CLASS: return (int)*((int8_t*) data);break; case mxUINT8_CLASS: return (int)*((uint8_t*) data);break; case mxINT16_CLASS: return (int)*((int16_t*) data);break; case mxUINT16_CLASS: return (int)*((uint16_t*)data);break; case mxINT32_CLASS: return (int)*((int32_t*) data);break; case mxUINT32_CLASS: return (int)*((uint32_t*)data);break; case mxINT64_CLASS: return (int)*((int64_t*) data);break; case mxUINT64_CLASS: return (int)*((uint64_t*)data);break; default: return defaultValue; } mxAssert(0,"getIntFromOpt: should not happen"); return 0; }
int mtlb_IdaSpilsPsolB(realtype tt, N_Vector yy, N_Vector yp, N_Vector yyB, N_Vector ypB, N_Vector rrB, N_Vector rvecB, N_Vector zvecB, realtype c_jB, realtype deltaB, void *prec_dataB, N_Vector tmpB) { mxArray *mx_in[11], *mx_out[3]; int ret; /* Inputs to the Matlab function */ mx_in[0] = mxCreateScalarDouble(-1.0); /* type=-1: backward ODE */ mx_in[1] = mxCreateScalarDouble(tt); /* current t */ mx_in[2] = mxCreateDoubleMatrix(N,1,mxREAL); /* current yy */ mx_in[3] = mxCreateDoubleMatrix(N,1,mxREAL); /* current yp */ mx_in[4] = mxCreateDoubleMatrix(NB,1,mxREAL); /* current yyB */ mx_in[5] = mxCreateDoubleMatrix(NB,1,mxREAL); /* current ypB */ mx_in[6] = mxCreateDoubleMatrix(NB,1,mxREAL); /* current rrB */ mx_in[7] = mxCreateDoubleMatrix(NB,1,mxREAL); /* right hand side rB */ mx_in[8] = mxCreateScalarDouble(c_jB); /* current c_jB */ mx_in[9] = mx_PSOLfctB; /* matlab function handle */ mx_in[10] = mx_data; /* matlab user data */ /* Call matlab wrapper */ GetData(yy, mxGetPr(mx_in[2]), N); GetData(yp, mxGetPr(mx_in[3]), N); GetData(yyB, mxGetPr(mx_in[4]), NB); GetData(ypB, mxGetPr(mx_in[5]), NB); GetData(rrB, mxGetPr(mx_in[6]), NB); GetData(rvecB, mxGetPr(mx_in[7]), NB); mexCallMATLAB(3,mx_out,11,mx_in,"idm_psol"); PutData(zvecB, mxGetPr(mx_out[0]), NB); ret = (int)*mxGetPr(mx_out[1]); if (!mxIsEmpty(mx_out[2])) { UpdateUserData(mx_out[2]); } /* Free temporary space */ mxDestroyArray(mx_in[0]); mxDestroyArray(mx_in[1]); mxDestroyArray(mx_in[2]); mxDestroyArray(mx_in[3]); mxDestroyArray(mx_in[4]); mxDestroyArray(mx_in[5]); mxDestroyArray(mx_in[6]); mxDestroyArray(mx_in[7]); mxDestroyArray(mx_in[8]); mxDestroyArray(mx_out[0]); mxDestroyArray(mx_out[1]); mxDestroyArray(mx_out[2]); return(ret); }
static inline uint32_t getSize(const mxArray* InputmxArray) { size_t NumElems = 0; // If array is non-empty, calculate size if (InputmxArray != nullptr && !mxIsEmpty(InputmxArray)) { NumElems = mxGetNumberOfElements(InputmxArray); } return NumElems; }
int mxW_CVodeSensRhs(int Nsens, realtype t, N_Vector y, N_Vector yd, N_Vector *yS, N_Vector *ySd, void *user_data, N_Vector tmp1, N_Vector tmp2) { cvmPbData fwdPb; mxArray *mx_in[7], *mx_out[3]; int is, ret; double *tmp; /* Extract global interface data from user-data */ fwdPb = (cvmPbData) user_data; /* Inputs to the Matlab function */ mx_in[0] = mxCreateDoubleScalar(t); /* current t */ mx_in[1] = mxCreateDoubleMatrix(N,1,mxREAL); /* current y */ mx_in[2] = mxCreateDoubleMatrix(N,1,mxREAL); /* current yd */ mx_in[3] = mxCreateDoubleScalar(Ns); /* number of sensitivities */ mx_in[4] = mxCreateDoubleMatrix(N*Ns,1,mxREAL); /* current yS */ mx_in[5] = fwdPb->SRHSfct; /* matlab function handle */ mx_in[6] = fwdPb->mtlb_data; /* matlab user data */ /* Call matlab wrapper */ GetData(y, mxGetPr(mx_in[1]), N); GetData(yd, mxGetPr(mx_in[2]), N); tmp = mxGetPr(mx_in[4]); for (is=0; is<Ns; is++) GetData(yS[is], &tmp[is*N], N); mexCallMATLAB(3,mx_out,7,mx_in,"cvm_rhsS"); tmp = mxGetPr(mx_out[0]); for(is=0;is<Ns;is++) PutData(ySd[is], &tmp[is*N], N); ret = (int)*mxGetPr(mx_out[1]); if (!mxIsEmpty(mx_out[2])) { UpdateUserData(mx_out[2], fwdPb); } /* Free temporary space */ mxDestroyArray(mx_in[0]); mxDestroyArray(mx_in[1]); mxDestroyArray(mx_in[2]); mxDestroyArray(mx_in[3]); mxDestroyArray(mx_in[4]); mxDestroyArray(mx_out[0]); mxDestroyArray(mx_out[1]); mxDestroyArray(mx_out[2]); return(ret); }
int mxW_CVodeQUADfctBS(realtype t, N_Vector y, N_Vector *yS, N_Vector yB, N_Vector yQBd, void *user_dataB) { cvmPbData fwdPb, bckPb; mxArray *mx_in[8], *mx_out[3]; int is, ret; double *tmp; /* Extract global interface data from user-data */ bckPb = (cvmPbData) user_dataB; fwdPb = bckPb->fwd; /* Inputs to the Matlab function */ mx_in[0] = mxCreateDoubleScalar(1.0); /* type=1: dependent on yS */ mx_in[1] = mxCreateDoubleScalar(t); /* current t */ mx_in[2] = mxCreateDoubleMatrix(N,1,mxREAL); /* current y */ mx_in[3] = mxCreateDoubleScalar(Ns); /* number of sensitivities */ mx_in[4] = mxCreateDoubleMatrix(N*Ns,1,mxREAL); /* current yS */ mx_in[5] = mxCreateDoubleMatrix(NB,1,mxREAL); /* current yB */ mx_in[6] = bckPb->QUADfct; /* matlab function handle */ mx_in[7] = bckPb->mtlb_data; /* matlab user data */ /* Call matlab wrapper */ GetData(y, mxGetPr(mx_in[2]), N); tmp = mxGetPr(mx_in[4]); for (is=0; is<Ns; is++) GetData(yS[is], &tmp[is*N], N); GetData(yB, mxGetPr(mx_in[5]), NB); mexCallMATLAB(3,mx_out,8,mx_in,"cvm_rhsQB"); PutData(yQBd, mxGetPr(mx_out[0]), NqB); ret = (int)*mxGetPr(mx_out[1]); if (!mxIsEmpty(mx_out[2])) { UpdateUserData(mx_out[2], bckPb); } /* Free temporary space */ mxDestroyArray(mx_in[0]); mxDestroyArray(mx_in[1]); mxDestroyArray(mx_in[2]); mxDestroyArray(mx_in[3]); mxDestroyArray(mx_in[4]); mxDestroyArray(mx_in[5]); mxDestroyArray(mx_out[0]); mxDestroyArray(mx_out[1]); mxDestroyArray(mx_out[2]); return(ret); }
int mxW_CVodeSpilsPsetB(realtype t, N_Vector y, N_Vector yB, N_Vector fyB, booleantype jokB, booleantype *jcurPtrB, realtype gammaB, void *user_dataB, N_Vector tmp1B, N_Vector tmp2B, N_Vector tmp3B) { cvmPbData fwdPb, bckPb; mxArray *mx_in[8], *mx_out[3]; int ret; /* Extract global interface data from user-data */ bckPb = (cvmPbData) user_dataB; fwdPb = bckPb->fwd; /* Inputs to the Matlab function */ mx_in[0] = mxCreateDoubleScalar(t); /* current t */ mx_in[1] = mxCreateDoubleMatrix(N,1,mxREAL); /* current y */ mx_in[2] = mxCreateDoubleMatrix(NB,1,mxREAL); /* current yB */ mx_in[3] = mxCreateDoubleMatrix(NB,1,mxREAL); /* current fyB */ mx_in[4] = mxCreateLogicalScalar(jokB); /* jokB flag */ mx_in[5] = mxCreateDoubleScalar(gammaB); /* gammaB value */ mx_in[6] = bckPb->PSETfct; /* matlab function handle */ mx_in[7] = bckPb->mtlb_data; /* matlab user data */ /* Call matlab wrapper */ GetData(y, mxGetPr(mx_in[1]), N); GetData(yB, mxGetPr(mx_in[2]), NB); GetData(fyB, mxGetPr(mx_in[3]), NB); mexCallMATLAB(3,mx_out,8,mx_in,"cvm_psetB"); *jcurPtrB = mxIsLogicalScalarTrue(mx_out[0]); ret = (int)*mxGetPr(mx_out[1]); if (!mxIsEmpty(mx_out[2])) { UpdateUserData(mx_out[2], bckPb); } /* Free temporary space */ mxDestroyArray(mx_in[0]); mxDestroyArray(mx_in[1]); mxDestroyArray(mx_in[2]); mxDestroyArray(mx_in[3]); mxDestroyArray(mx_in[4]); mxDestroyArray(mx_in[5]); mxDestroyArray(mx_out[0]); mxDestroyArray(mx_out[1]); mxDestroyArray(mx_out[2]); return(ret); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { struct keyword *pk; /* pointer to keyword structure */ mxArray *pp, *pv; /* pointer to property and value */ element_t *pe; /* pointer to element */ element_t el; int nc, idx; char pstr[PS_LEN]; /* property name string */ char errmsg[ERR_LEN]; if (nrhs != 2) mexErrMsgTxt("set_element_data : must have exactly two arguments."); /* get pointer to input element and make local copy */ pe = (element_t *)mxGetData(prhs[0]); memcpy(&el, pe, sizeof(element_t)); /* check 2nd argument */ if ( !mxIsCell(prhs[1]) ) mexErrMsgTxt("set_element_data : 2nd argument must be cell array."); /* get number of cells */ nc = mxGetNumberOfElements(prhs[1]); if (nc % 2) mexErrMsgTxt("set_element_data : 2nd argument must consist of propery/value pairs."); /* store property/value pairs one-by-one */ for (idx = 0; idx<nc; idx+=2) { /* get next property value pair */ pp = mxGetCell(prhs[1], idx); pv = mxGetCell(prhs[1], idx+1); /* decode property argument using the hash function in prop_hash.h */ if ( !mxIsChar(pp) ) mexErrMsgTxt("set_element_data : properties must be character strings."); mxGetString(pp, pstr, PS_LEN); pk = (struct keyword *)in_word_set(pstr, strlen(pstr)); if (pk == NULL) { sprintf(errmsg, "set_element_data : unknown element property -> %s", pstr); mexErrMsgTxt(errmsg); } /* store the property value in internal structure */ if ( !mxIsEmpty(pv) ) (*pk->set_prop_func)(&el, pv); } /* return element to caller */ plhs[0] = copy_element_to_array(&el); }
int mtlb_IdaBandJac(long int Neq, long int mupper, long int mlower, realtype tt, N_Vector yy, N_Vector yp, N_Vector rr, realtype c_j, void *jac_data, BandMat Jac, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3) { double *J_data; long int eband, i; int ret; mxArray *mx_in[8], *mx_out[3]; /* Inputs to the Matlab function */ mx_in[0] = mxCreateScalarDouble(1.0); /* type=1: forward ODE */ mx_in[1] = mxCreateScalarDouble(tt); /* current t */ mx_in[2] = mxCreateDoubleMatrix(N,1,mxREAL); /* current yy */ mx_in[3] = mxCreateDoubleMatrix(N,1,mxREAL); /* current yp */ mx_in[4] = mxCreateDoubleMatrix(N,1,mxREAL); /* current rr */ mx_in[5] = mxCreateScalarDouble(c_j); /* current c_j */ mx_in[6] = mx_JACfct; /* matlab function handle */ mx_in[7] = mx_data; /* matlab user data */ /* Call matlab wrapper */ GetData(yy, mxGetPr(mx_in[2]), N); GetData(yp, mxGetPr(mx_in[3]), N); GetData(rr, mxGetPr(mx_in[4]), N); mexCallMATLAB(3,mx_out,8,mx_in,"idm_bjac"); /* Extract data */ eband = mupper + mlower + 1; J_data = mxGetPr(mx_out[0]); for (i=0; i<N; i++) memcpy(BAND_COL(Jac,i) - mupper, J_data + i*eband, eband*sizeof(double)); ret = (int)*mxGetPr(mx_out[1]); if (!mxIsEmpty(mx_out[2])) { UpdateUserData(mx_out[2]); } /* Free temporary space */ mxDestroyArray(mx_in[0]); mxDestroyArray(mx_in[1]); mxDestroyArray(mx_in[2]); mxDestroyArray(mx_in[3]); mxDestroyArray(mx_in[4]); mxDestroyArray(mx_in[5]); mxDestroyArray(mx_out[0]); mxDestroyArray(mx_out[1]); mxDestroyArray(mx_out[2]); return(ret); }
static inline bool CheckType(const mxArray* InputmxArray) { bool isValid = true; if (InputmxArray != nullptr && !mxIsEmpty(InputmxArray) && mxIsCell(InputmxArray)) { const mxArray* * SubVectorArray = reinterpret_cast<const mxArray* *>(mxGetData(InputmxArray)); size_t NSubElems = mxGetNumberOfElements(InputmxArray); // Validate each subvector for (int i = 0; i < NSubElems; ++i) { if (!FieldInfo<typename isMexVectVector<T>::elemType>::CheckType(SubVectorArray[i])) { isValid = false; break; } } } else if (InputmxArray != nullptr && !mxIsEmpty(InputmxArray)) { isValid = false; } else { isValid = true; } return isValid; }
void setCameraProperty(const EdsCameraRef handle, const mxArray* mxstruct) { if (mxIsStruct(mxstruct)) { unsigned numProperties = mxGetNumberOfFields(mxstruct); for (unsigned iterProperty = 0; iterProperty < numProperties; ++iterProperty) { setCameraProperty(handle, stringToCameraProperty(mxGetFieldNameByNumber(mxstruct, iterProperty)), \ mxGetFieldByNumber(mxstruct, 0, iterProperty)); } } else if (!mxIsEmpty(mxstruct)) { mexErrMsgIdAndTxt(ERROR_ID, "For setting multiple attributes, a struct array must be provided."); } }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { if(nrhs < 2) mexErrMsgTxt("At least two inputs are required."); btkMXCheckNoOuput(nlhs, plhs); // Only when there is no output for the function. if ((mxGetClassID(prhs[1]) != mxDOUBLE_CLASS) || mxIsEmpty(prhs[1]) || mxIsComplex(prhs[1]) || (mxGetNumberOfElements(prhs[1]) != 1)) mexErrMsgTxt("The first frame must be set by one double value representing an integer."); int adaptEventsOption = 0; if (nrhs >= 3) { if ((mxGetClassID(prhs[2]) != mxDOUBLE_CLASS) || mxIsEmpty(prhs[2]) || mxIsComplex(prhs[2]) || (mxGetNumberOfElements(prhs[2]) != 1)) mexErrMsgTxt("The option to adapt events' frame/time must be set by one double value representing an integer."); adaptEventsOption = static_cast<int>(mxGetScalar(prhs[2])); } btk::Acquisition::Pointer acq = btk_MOH_get_object<btk::Acquisition>(prhs[0]); acq->SetFirstFrame(static_cast<int>(mxGetScalar(prhs[1])), adaptEventsOption != 0); };
int mxW_CVodeBandJacB(long int NeqB, long int mupperB, long int mlowerB, realtype t, N_Vector y, N_Vector yB, N_Vector fyB, DlsMat JB, void *user_dataB, N_Vector tmp1B, N_Vector tmp2B, N_Vector tmp3B) { cvmPbData fwdPb, bckPb; double *JB_data; mxArray *mx_in[6], *mx_out[3]; long int ebandB, i; int ret; /* Extract global interface data from user-data */ bckPb = (cvmPbData) user_dataB; fwdPb = bckPb->fwd; /* Inputs to the Matlab function */ mx_in[0] = mxCreateDoubleScalar(t); /* current t */ mx_in[1] = mxCreateDoubleMatrix(N,1,mxREAL); /* current y */ mx_in[2] = mxCreateDoubleMatrix(NB,1,mxREAL); /* current yB */ mx_in[3] = mxCreateDoubleMatrix(NB,1,mxREAL); /* current fyB */ mx_in[4] = bckPb->JACfct; /* matlab function handle */ mx_in[5] = bckPb->mtlb_data; /* matlab user data */ /* Call matlab wrapper */ GetData(y, mxGetPr(mx_in[1]), N); GetData(yB, mxGetPr(mx_in[2]), NB); GetData(fyB, mxGetPr(mx_in[3]), NB); mexCallMATLAB(3,mx_out,6,mx_in,"cvm_bjacB"); ebandB = mupperB + mlowerB + 1; JB_data = mxGetPr(mx_out[0]); for (i=0;i<NB;i++) memcpy(BAND_COL(JB,i) - mupperB, JB_data + i*ebandB, ebandB*sizeof(double)); ret = (int)*mxGetPr(mx_out[1]); if (!mxIsEmpty(mx_out[2])) { UpdateUserData(mx_out[2], bckPb); } /* Free temporary space */ mxDestroyArray(mx_in[0]); mxDestroyArray(mx_in[1]); mxDestroyArray(mx_in[2]); mxDestroyArray(mx_in[3]); mxDestroyArray(mx_out[0]); mxDestroyArray(mx_out[1]); mxDestroyArray(mx_out[2]); return(ret); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { if(nrhs != 1) mexErrMsgTxt("One input required."); if (nlhs > 3) mexErrMsgTxt("Too many output arguments."); if (!mxIsChar(prhs[0]) || mxIsEmpty(prhs[0])) mexErrMsgTxt("The filename must be a string and can't be empty."); // Redirection of the btk::Logger::Warning stream. btk::MEXWarnLogToWarnMsgTxt warnRedir = btk::MEXWarnLogToWarnMsgTxt("btk:ReadAcquisition"); size_t strlen_ = (mxGetM(prhs[0]) * mxGetN(prhs[0]) * sizeof(mxChar)) + 1; char* filename = (char*)mxMalloc(strlen_); mxGetString(prhs[0], filename, strlen_); btk::AcquisitionFileReader::Pointer reader = btk::AcquisitionFileReader::New(); reader->SetFilename(std::string(filename)); mxFree(filename); try { reader->Update(); } catch(std::exception& e) { // Octave seems to not call the destructor of the btkSharedPtr when an exception is thrown (possible memory leak). reader.reset(); mexErrMsgTxt(e.what()); } catch(...) { reader.reset(); mexErrMsgTxt("An unexpected error occurred."); } plhs[0] = btk_MOH_create_handle(reader->GetOutput()); if (nlhs > 1) // Byte Order plhs[1] = mxCreateString(reader->GetAcquisitionIO()->GetByteOrderAsString().c_str()); if (nlhs > 2) // Storage format plhs[2] = mxCreateString(reader->GetAcquisitionIO()->GetStorageFormatAsString().c_str()); #if defined(__APPLE__) || (defined(BTK_BUILD_SHARED_LIBS) && defined(__unix__)) // It seems to be related only to Linux with shared libraries // This fix was only tested with Matlab r2009a (7.8) // FIXME: This solution clear all the acquisitions and not only the ones // created from this function mexAtExit(btk::MEXHandleCollector<btk::Acquisition>::ManualClear); #endif };
char* opt_getStringFromOpt (const mxArray *opt, POptionSettings optSet, const char *name, char* defaultValue) { static const char* noString = "<NULL>"; mxArray *field; char takeDefault; size_t buflen; char* erg; takeDefault=(char)0; field=mxGetField(opt,(mwIndex)0,name); if ((field==NULL) || (mxIsEmpty(field))) { if (optSet->warnMiss) mexPrintf("Option '%s' fehlt, nehme default '%s'\n",name, defaultValue==NULL?noString:defaultValue); takeDefault=(char)1; } if ((!takeDefault) && (!mxIsChar(field))) { if (optSet->warnType) mexPrintf("Option '%s' hat falschen Typ, nehme default %s\n", name,defaultValue==NULL?noString:defaultValue); takeDefault=(char)1; } if (!takeDefault) { if ((mxGetNumberOfDimensions(field)!=(mwSize)2) || (mxGetM(field)!=(size_t)1)) { if (optSet->warnSize) mexPrintf("Option '%s' hat falsche Größe, nehme default %s\n", name,defaultValue==NULL?noString:defaultValue); takeDefault=(char)1; } } if (takeDefault) { if (defaultValue==NULL) return NULL; buflen=strlen(defaultValue)+(size_t)1; erg=mxMalloc(buflen); strcpy(erg,defaultValue); } else { erg=mxArrayToString(field); } return erg; }
void checkInputs(const mxArray *prhs[], int nrhs) { if(nrhs < 4) mexErrMsgTxt("You must supply at least 4 arguments to lmder!\n\nlmder(fun,grad,x0,ydata)\n"); //Check Types if(!mxIsFunctionHandle(prhs[0]) && !mxIsChar(prhs[0])) mexErrMsgTxt("fun must be a function handle or function name!"); if(!mxIsEmpty(prhs[1]) && (!mxIsFunctionHandle(prhs[1]) && !mxIsChar(prhs[1]))) mexErrMsgTxt("grad must be a function handle or function name!"); if(!mxIsDouble(prhs[2]) || mxIsComplex(prhs[2]) || mxIsEmpty(prhs[2])) mexErrMsgTxt("x0 must be a real double column vector!"); if(!mxIsDouble(prhs[3]) || mxIsComplex(prhs[3]) || mxIsEmpty(prhs[3])) mexErrMsgTxt("ydata must be a real double column vector!"); //Check Options if(nrhs > 4) { if(!mxIsStruct(prhs[4])) mexErrMsgTxt("The specified options must be a structure!"); } }
void mxW_CVodeMonitor(int call, double t, N_Vector y, N_Vector yQ, N_Vector *yS, cvmPbData fwdPb) { mxArray *mx_in[8], *mx_out[1]; double *tmp; int is; mx_in[0] = mxCreateDoubleScalar(call); /* call type (0:first, 1:interm. 2:last) */ mx_in[1] = mxCreateDoubleScalar(t); /* current time */ mx_in[2] = mxCreateDoubleMatrix(N,1,mxREAL); /* current solution */ if (quadr) mx_in[3] = mxCreateDoubleMatrix(Nq,1,mxREAL); /* current quadratures */ else mx_in[3] = mxCreateDoubleMatrix(0,0,mxREAL); mx_in[4] = mxCreateDoubleScalar(Ns); /* number of sensitivities */ if (fsa) mx_in[5] = mxCreateDoubleMatrix(N*Ns,1,mxREAL); /* current sensitivities */ else mx_in[5] = mxCreateDoubleMatrix(0,0,mxREAL); mx_in[6] = fwdPb->MONfct; /* Matlab monitor function */ mx_in[7] = fwdPb->MONdata; /* data for monitor function */ if (call == 1) { GetData(y, mxGetPr(mx_in[2]), N); if (quadr) GetData(yQ, mxGetPr(mx_in[3]), Nq); if (fsa) { tmp = mxGetPr(mx_in[5]); for (is=0; is<Ns; is++) GetData(yS[is], &tmp[is*N], N); } } mexCallMATLAB(1,mx_out,8,mx_in,"cvm_monitor"); if (!mxIsEmpty(mx_out[0])) { UpdateMonitorData(mx_out[0], fwdPb); } mxDestroyArray(mx_in[0]); mxDestroyArray(mx_in[1]); mxDestroyArray(mx_in[2]); mxDestroyArray(mx_in[3]); mxDestroyArray(mx_in[4]); mxDestroyArray(mx_in[5]); mxDestroyArray(mx_out[0]); }
int mxW_CVodeSpilsPsolB(realtype t, N_Vector y, N_Vector yB, N_Vector fyB, N_Vector rB, N_Vector zB, realtype gammaB, realtype deltaB, int lrB, void *user_dataB, N_Vector tmpB) { cvmPbData fwdPb, bckPb; mxArray *mx_in[7], *mx_out[3]; int ret; /* Extract global interface data from user-data */ bckPb = (cvmPbData) user_dataB; fwdPb = bckPb->fwd; /* Inputs to the Matlab function */ mx_in[0] = mxCreateDoubleScalar(t); /* current t */ mx_in[1] = mxCreateDoubleMatrix(N,1,mxREAL); /* current y */ mx_in[2] = mxCreateDoubleMatrix(NB,1,mxREAL); /* current yB */ mx_in[3] = mxCreateDoubleMatrix(NB,1,mxREAL); /* current fyB */ mx_in[4] = mxCreateDoubleMatrix(NB,1,mxREAL); /* right hand side rB */ mx_in[5] = bckPb->PSOLfct; /* matlab function handle */ mx_in[6] = bckPb->mtlb_data; /* matlab user data */ /* Call matlab wrapper */ GetData(y, mxGetPr(mx_in[1]), N); GetData(yB, mxGetPr(mx_in[2]), NB); GetData(fyB, mxGetPr(mx_in[3]), NB); GetData(rB, mxGetPr(mx_in[4]), NB); mexCallMATLAB(3,mx_out,7,mx_in,"cvm_psolB"); PutData(zB, mxGetPr(mx_out[0]), NB); ret = (int)*mxGetPr(mx_out[1]); if (!mxIsEmpty(mx_out[2])) { UpdateUserData(mx_out[2], bckPb); } /* Free temporary space */ mxDestroyArray(mx_in[0]); mxDestroyArray(mx_in[1]); mxDestroyArray(mx_in[2]); mxDestroyArray(mx_in[3]); mxDestroyArray(mx_in[4]); mxDestroyArray(mx_out[0]); mxDestroyArray(mx_out[1]); mxDestroyArray(mx_out[2]); return(ret); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { FloatImage im; PatchFeatureOpt opt; FloatImage patch_feat; // image input bool im_copy = MatReadFloatMatrix(prhs[0], &im); // option MatReadPatchFeatureOpt(prhs[1], &opt); opt.use_grids = false; // whether use default grids if(nrhs < 3 || mxIsEmpty(prhs[2])) opt.use_grids = true; if(!opt.use_grids) { nlhs = 1; if(mxGetClassID(prhs[2]) != mxINT32_CLASS && mxGetM(prhs[2]) != 2) mexErrMsgTxt("Wrong Patch Coordinate Input"); // self defined patch position opt.coord = (int *)mxGetPr(prhs[2]); opt.num = mxGetN(prhs[2]); } else { nlhs = 2; opt.coord = NULL; } InitPatchFeature(&im, &opt); // allocate return variables plhs[0] = MatAllocateFloatMatrix(&patch_feat, opt.length, opt.num, 1); if(opt.use_grids) plhs[1] = MatAllocateGrids(&opt.grids); // mexPrintf("%d, %d\n", opt.length, opt.num); // process PatchFeature(&im, &patch_feat, &opt); if (im_copy) FreeImage(&im); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { const int dimsA[]={1}; const int dimsB[]={1}; int *a, *b; // double *a, *b, *C, *w, z, eps=0.001; double *aIn, *bIn, *C, *w, z; int D, n, m, i, j, k; if (nrhs < 3 || nlhs > 1) mexErrMsgTxt("Usage: C = w_ham_dist(a,b,l), where the b matrix may be empty."); aIn = mxGetData(prhs[0]); // mxGetData is like mxGetPr, but returns void *, so we can assign it to int * m = mxGetN(prhs[0]); D = mxGetM(prhs[0]); if (mxIsEmpty(prhs[1])) { bIn = aIn; n = m; } else { bIn = mxGetData(prhs[1]); n = mxGetN(prhs[1]); if (D != mxGetM(prhs[1])) mexErrMsgTxt("Error: column lengths must agree"); } w = mxGetPr(prhs[2]); if (D != mxGetM(prhs[2]) || 1 != mxGetN(prhs[2])){ printf("Length scale vector is %d by %d (not %d by 1)", mxGetM(prhs[2]), mxGetN(prhs[2]), D); mexErrMsgTxt("Error: length scale vector must be D by 1"); } // Construct a and b as integer arrays. a = mxCreateNumericArray(1, dimsA, mxClassIDFromClassName('uint16'), 0); b = mxCreateNumericArray(1, dimsB, mxClassIDFromClassName('uint16'), 0); //=== Passing is done, do the computation for (i=0; i<D; i++) {w[i] = 1.0/(w[i]*w[i]);} plhs[0] = mxCreateDoubleMatrix(m, n, mxREAL); C = mxGetPr(plhs[0]); for (i=0; i<m; i++) for (j=0; j<n; j++) { z = 0.0; for (k=0; k<D; k++) { z += (a[D*i+k] == b[D*j+k])? 0 : w[k]; // Boolean arithmetic way faster! // Original: // z += (1- ((a[D*i+k] < b[D*j+k]+eps) && (a[D*i+k] > b[D*j+k]-eps)) ); // Faster: // z += w[k]*(a[D*i+k] != b[D*j+k]);// boolean arithmetic way faster! 1- ((a[D*i+k] < b[D*j+k]+eps) && (a[D*i+k] > b[D*j+k]-eps)) ); } C[i+j*m] = z; } }
/* Function: mdlCheckParameters ============================================= * Abstract: * Validate our parameters to verify: * o The numerator must be of a lower order than the denominator. * o The sample time must be a real positive nonzero value. */ static void mdlCheckParameters(SimStruct *S) { // SFUNPRINTF("Calling mdlCheckParameters"); // Tsim if (mxIsEmpty( ssGetSFcnParam(S,0)) || mxIsSparse( ssGetSFcnParam(S,0)) || mxIsComplex( ssGetSFcnParam(S,0)) || mxIsLogical( ssGetSFcnParam(S,0)) || !mxIsNumeric( ssGetSFcnParam(S,0)) || !mxIsDouble( ssGetSFcnParam(S,0)) || mxGetNumberOfElements(ssGetSFcnParam(S,0)) != 1) { ssSetErrorStatus(S,"Simulation time must be a single double Value"); return; } // Prefix Topic if (!mxIsChar( ssGetSFcnParam(S,1)) ) { ssSetErrorStatus(S,"Prefix value must be char array (string)"); return; } // Robot Array if (mxIsEmpty( ssGetSFcnParam(S,2)) || mxIsSparse( ssGetSFcnParam(S,2)) || mxIsComplex( ssGetSFcnParam(S,2)) || mxIsLogical( ssGetSFcnParam(S,2)) || !mxIsChar( ssGetSFcnParam(S,2)) ) { ssSetErrorStatus(S,"Robot Vector must be a char vector of robot ids"); return; } // Postfix Topic if (!mxIsChar( ssGetSFcnParam(S,3)) ) { ssSetErrorStatus(S,"Postfix value must be char array (string)"); return; } }
int mxW_KINSpilsPsol(N_Vector y, N_Vector yscale, N_Vector fy, N_Vector fscale, N_Vector v, void *user_data, N_Vector vtemp) { kimInterfaceData kimData; mxArray *mx_in[7], *mx_out[3]; int ret; /* Extract global interface data from user-data */ kimData = (kimInterfaceData) user_data; /* Inputs to the Matlab function */ mx_in[0] = mxCreateDoubleMatrix(N,1,mxREAL); /* current y */ mx_in[1] = mxCreateDoubleMatrix(N,1,mxREAL); /* current yscale */ mx_in[2] = mxCreateDoubleMatrix(N,1,mxREAL); /* current fy */ mx_in[3] = mxCreateDoubleMatrix(N,1,mxREAL); /* current fscale */ mx_in[4] = mxCreateDoubleMatrix(N,1,mxREAL); /* right hand side */ mx_in[5] = kimData->PSOLfct; /* matlab function handle */ mx_in[6] = kimData->mtlb_data; /* matlab user data */ /* Call matlab wrapper */ GetData(y, mxGetPr(mx_in[0]), N); GetData(yscale, mxGetPr(mx_in[1]), N); GetData(fy, mxGetPr(mx_in[2]), N); GetData(fscale, mxGetPr(mx_in[3]), N); GetData(v, mxGetPr(mx_in[4]), N); mexCallMATLAB(3,mx_out,7,mx_in,"kim_psol"); PutData(v, mxGetPr(mx_out[0]), N); ret = (int)*mxGetPr(mx_out[1]); if (!mxIsEmpty(mx_out[2])) { UpdateUserData(mx_out[2], kimData); } /* Free temporary space */ mxDestroyArray(mx_in[0]); mxDestroyArray(mx_in[1]); mxDestroyArray(mx_in[2]); mxDestroyArray(mx_in[3]); mxDestroyArray(mx_in[4]); mxDestroyArray(mx_out[0]); mxDestroyArray(mx_out[1]); mxDestroyArray(mx_out[2]); return(ret); }
char opt_getSizeOfOptField (const mxArray *opt, const char *name, size_t *m, size_t *n) { mxArray *field; field=mxGetField(opt,(mwIndex)0,name); if (field==NULL) return (char)1; if (mxGetNumberOfDimensions(field)!=(size_t)2) return (char)2; if (mxIsEmpty(field)) return (char)3; *m=mxGetM(field);*n=mxGetN(field); return 0; }