void mexFunction(const int nlhs, mxArray *plhs[], const int nrhs, const mxArray *prhs[]) {
    size_t n,j;
    size_t nCard;
    bool isLast, lastPassed;
    mxArray *codeArray;
    
    if(nrhs<1){
        mexErrMsgTxt("Not enough inputs.");
    }
    
    if(nrhs>2){
        mexErrMsgTxt("Too many inputs.");
    }
    
    if(nlhs>4) {
        mexErrMsgTxt("Too many outputs.");
    }
    
    //If an empty code matrix is passed, then the second argument is
    //required, and we will return the first gray code in the sequence.
    if(mxIsEmpty(prhs[0])) {
        mwSize dims[2];
        if(nrhs<2) {
            mexErrMsgTxt("The second argument is required when an empty code matrix is passed.");
        }
        
        dims[0]=getSizeTFromMatlab(prhs[1]);
        dims[1]=1;
        //Allocate the array; this also initializes all of the elements to
        //0.
        codeArray=mxCreateLogicalArray(2, dims);
        
        //This is the code
        plhs[0]=codeArray;
        
        if(nlhs>1) {
            //This is nCard
            plhs[1]=mxCreateDoubleScalar(0.0);
            
            if(nlhs>2) {
                //This is isLast
                plhs[2]=mxCreateLogicalScalar(false);
                
                if(nlhs>3) {
                    //This is j.
                    plhs[3]=mxCreateDoubleMatrix(0, 0, mxREAL);
                }
            }
        }
        return;
    }
    
    //The code array cannot be complex.
    if(mxIsComplex(prhs[0])!=false) {
        mexErrMsgTxt("The code array cannot be complex.");
    }
    
    //Copy the code value so that the input matrix is not modified on
    //return.
    {
        size_t n1,n2;
        n1=mxGetM(prhs[0]);
        n2=mxGetN(prhs[0]);

        if((n1==1&&n2>=1)||(n2==1&&n1>=1)) {
            n=std::max(n1,n2);
            
            codeArray=mxDuplicateArray(prhs[0]);
        } else {
            mexErrMsgTxt("The code vector has the wrong dimensionality.");
        }
    }

    if(nrhs>1) {
        nCard=getSizeTFromMatlab(prhs[1]);
    } else {
        mxArray *lhs[1];
        //Sum up the ones in codeArray to get nCard if it is not provided.
        mexCallMATLAB(1,lhs,1, &codeArray, "sum");
        nCard=getSizeTFromMatlab(lhs[0]);
        mxDestroyArray(lhs[0]);
    }
    
    //The type of the data in the code array is whatever the user passed to
    //the function. The function has to be called with the correct template 
    //value for the type of the code.
    lastPassed=false;
    switch(mxGetClassID(codeArray)){
        case mxCHAR_CLASS:
        {
            mxChar *code=(mxChar*)mxGetData(codeArray);
            
            if(nCard==(size_t)code[n-1]&&nCard!=0) {
                lastPassed=true;
            } else{
                isLast=getNextGrayCodeCPP(n, code, nCard, j);
            }
            break;
        }
        case mxLOGICAL_CLASS:
        {
            mxLogical* code=(mxLogical*)mxGetData(codeArray); 
            
            if(nCard==(size_t)code[n-1]&&nCard!=0) {
                lastPassed=true;
            } else{
                isLast=getNextGrayCodeCPP(n, code, nCard, j);
            }
            break;
        }
        case mxDOUBLE_CLASS:
        {
            double* code=(double*)mxGetData(codeArray);
            
            if(nCard==(size_t)code[n-1]&&nCard!=0) {
                lastPassed=true;
            } else{
                isLast=getNextGrayCodeCPP(n, code, nCard, j);
            }
            break;
        }
        case mxSINGLE_CLASS:
        {
            float* code=(float*)mxGetData(codeArray);
            
            if(nCard==(size_t)code[n-1]&&nCard!=0) {
                lastPassed=true;
            } else{
                isLast=getNextGrayCodeCPP(n, code, nCard, j);
            }
            break;
        }
        case mxINT8_CLASS:
        {
            int8_T* code=(int8_T*)mxGetData(codeArray);
            
            if(nCard==(size_t)code[n-1]&&nCard!=0) {
                lastPassed=true;
            } else{
                isLast=getNextGrayCodeCPP(n, code, nCard, j);
            }
            break;
        }
        case mxUINT8_CLASS:
        {
            uint8_T* code=(uint8_T*)mxGetData(codeArray);
            
            if(nCard==(size_t)code[n-1]&&nCard!=0) {
                lastPassed=true;
            } else{
                isLast=getNextGrayCodeCPP(n, code, nCard, j);
            }
            break;
        }
        case mxINT16_CLASS:
        {
            int16_T* code=(int16_T*)mxGetData(codeArray);
            
            if(nCard==(size_t)code[n-1]&&nCard!=0) {
                lastPassed=true;
            } else{
                isLast=getNextGrayCodeCPP(n, code, nCard, j);
            }
            break;
        }
        case mxUINT16_CLASS:
        {
            uint16_T* code=(uint16_T*)mxGetData(codeArray);
            
            if(nCard==(size_t)code[n-1]&&nCard!=0) {
                lastPassed=true;
            } else{
                isLast=getNextGrayCodeCPP(n, code, nCard, j);
            }
            break;
        }
        case mxINT32_CLASS:
        {
            int32_T* code=(int32_T*)mxGetData(codeArray);
            
            if(nCard==(size_t)code[n-1]&&nCard!=0) {
                lastPassed=true;
            } else{
                isLast=getNextGrayCodeCPP(n, code, nCard, j);
            }
            break;
        }
        case mxUINT32_CLASS:
        {
            uint32_T* code=(uint32_T*)mxGetData(codeArray);
            
            if(nCard==(size_t)code[n-1]&&nCard!=0) {
                lastPassed=true;
            } else{
                isLast=getNextGrayCodeCPP(n, code, nCard, j);
            }
            break;
        }
        case mxINT64_CLASS:
        {
            int64_T* code=(int64_T*)mxGetData(codeArray);
            
            if(nCard==(size_t)code[n-1]&&nCard!=0) {
                lastPassed=true;
            } else{
                isLast=getNextGrayCodeCPP(n, code, nCard, j);
            }
            break;
        }
        case mxUINT64_CLASS:
        {
            uint64_T* code=(uint64_T*)mxGetData(codeArray);   
            
            if(nCard==(size_t)code[n-1]&&nCard!=0) {
                lastPassed=true;
            } else{
                isLast=getNextGrayCodeCPP(n, code, nCard, j);
            }
            break;
        }
        default:
            mexErrMsgTxt("The code vector is of an unknown data type.");
    }
    
    //If the final gray code was passed, then just return empty matrices
    //and put n in nCard. That way, if called again, the function will
    //start from the beginning.
    if(lastPassed==true) {
        mxDestroyArray(codeArray);
        plhs[0]=mxCreateDoubleMatrix(0, 0, mxREAL);
        if(nlhs>1) {
            mxArray *nCardMat=allocUnsignedSizeMatInMatlab(1, 1);
            *(size_t*)mxGetData(nCardMat)=n;

            plhs[1]=nCardMat;
            if(nlhs>2) {
                //This is isLast
                plhs[2]=mxCreateDoubleMatrix(0, 0, mxREAL);;

                if(nlhs>3) {
                    //This is j
                    plhs[3]=mxCreateDoubleMatrix(0, 0, mxREAL);;
                }
            }
        }
        
        return;   
    }
    
    //Set the return values for the case when the last code was not passed.
    plhs[0]=codeArray;
    if(nlhs>1) {
        mxArray *nCardMat=allocUnsignedSizeMatInMatlab(1, 1);
        *(size_t*)mxGetData(nCardMat)=nCard;
        
        plhs[1]=nCardMat;
        if(nlhs>2) {
            //This is isLast
            plhs[2]=mxCreateLogicalScalar(isLast);

            if(nlhs>3) {
                mxArray *jMat=allocUnsignedSizeMatInMatlab(1, 1);
                //Increment j to be an index for Matlab.
                j++;
                *(size_t*)mxGetData(jMat)=j;
                
                plhs[3]=jMat;
            }
        }
    }
}
Ejemplo n.º 2
0
mxArray *sf_c2_MPC_framework_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] =
  {"checksum","inputs","parameters","outputs"};
  mxArray *mxAutoinheritanceInfo =
  mxCreateStructMatrix(1,1,4,autoinheritanceFields);
  {
    mxArray *mxChecksum = mxCreateDoubleMatrix(4,1,mxREAL);
    double *pr = mxGetPr(mxChecksum);
    pr[0] = (double)(4146277402U);
    pr[1] = (double)(3031080980U);
    pr[2] = (double)(1162626880U);
    pr[3] = (double)(4240345295U);
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }
  {
    const char *dataFields[] = {"size","type","complexity"};
    mxArray *mxData = mxCreateStructMatrix(1,6,3,dataFields);
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }
    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }
    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,2,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,2,"type",mxType);
    }
    mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,3,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,3,"type",mxType);
    }
    mxSetField(mxData,3,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,4,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,4,"type",mxType);
    }
    mxSetField(mxData,4,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,5,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,5,"type",mxType);
    }
    mxSetField(mxData,5,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }
  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,mxREAL));
  }
  {
    const char *dataFields[] = {"size","type","complexity"};
    mxArray *mxData = mxCreateStructMatrix(1,3,3,dataFields);
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }
    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }
    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,2,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(3));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(3));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,2,"type",mxType);
    }
    mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }
  return(mxAutoinheritanceInfo);
}
Ejemplo n.º 3
0
mxArray *sf_c6_TTR_mdl_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateString("VVPNWBOOtqWmckFbbcB3AH");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,2,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(2);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  return(mxAutoinheritanceInfo);
}
mxArray *sf_c13_ARP_02_RPSs_Bdr_GK_BIS7_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateString("yPPzDIGn5DPyGYnrHi4YC");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  return(mxAutoinheritanceInfo);
}
Ejemplo n.º 5
0
/// @brief get a frame from the leap controller
///
/// @param nlhs matlab mex output interface
/// @param plhs[] matlab mex output interface
void get_frame (int nlhs, mxArray *plhs[])
{
    // get the frame
    const matleap::frame &f = fg->get_frame ();
    // create matlab frame struct
    const char *frame_field_names[] =
    {
        "id",
        "timestamp",
        "pointables",
        "hands"
    };
    int frame_fields = sizeof (frame_field_names) / sizeof (*frame_field_names);
    plhs[0] = mxCreateStructMatrix (1, 1, frame_fields, frame_field_names);
    // fill the frame struct
    mxSetFieldByNumber (plhs[0], 0, 0, mxCreateDoubleScalar (f.id));
    mxSetFieldByNumber (plhs[0], 0, 1, mxCreateDoubleScalar (f.timestamp));
    // create the pointables structs

    if (f.pointables.count () > 0)
    {
        const char *pointable_field_names[] =
        {
            "id",
            "position",
            "velocity",
            "direction",
            "is_extended",
            "is_finger",
            "is_tool",
            "is_valid",
            "length",
            "width",
            "touch_distance",
            "time_visible"
        };
        int pointable_fields = sizeof (pointable_field_names) / sizeof (*pointable_field_names);
        mxArray *p = mxCreateStructMatrix (1, f.pointables.count (), pointable_fields, pointable_field_names);
        mxSetFieldByNumber (plhs[0], 0, 2, p); 
        // fill the pointables structs
		
		
        for (size_t i = 0; i < f.pointables.count (); ++i)
        {
            // set the id
            mxSetFieldByNumber (p, i, 0, mxCreateDoubleScalar (f.pointables[i].id ()));
            // create and fill arrays for vectors
            mxArray *pos = create_and_fill (f.pointables[i].tipPosition ());
            mxArray *vel = create_and_fill (f.pointables[i].tipVelocity ());
            mxArray *dir = create_and_fill (f.pointables[i].direction ());
			
            // set them in the struct
            mxSetFieldByNumber (p, i, 1, pos);
            mxSetFieldByNumber (p, i, 2, vel);
            mxSetFieldByNumber (p, i, 3, dir);
            mxSetFieldByNumber (p, i, 4, mxCreateDoubleScalar (f.pointables[i].isExtended ()));
            mxSetFieldByNumber (p, i, 5, mxCreateDoubleScalar (f.pointables[i].isFinger ()));
            mxSetFieldByNumber (p, i, 6, mxCreateDoubleScalar (f.pointables[i].isTool ()));
            mxSetFieldByNumber (p, i, 7, mxCreateDoubleScalar (f.pointables[i].isValid ()));
            mxSetFieldByNumber (p, i, 8, mxCreateDoubleScalar (f.pointables[i].length ()));
            mxSetFieldByNumber (p, i, 9, mxCreateDoubleScalar (f.pointables[i].width ()));
            mxSetFieldByNumber (p, i, 10, mxCreateDoubleScalar (f.pointables[i].touchDistance ()));
            mxSetFieldByNumber (p, i, 11, mxCreateDoubleScalar (f.pointables[i].timeVisible ()));
        }
		
    }
    
    
    if (f.hands.count () > 0)
    {
        const char *hand_field_names[] =
        {
            "id", // 0

            "basis", // 1
            "confidence", // 2
            "direction", // 3
            
            "grab_strength", // 4
            
            "is_left", // 5
            "is_right", // 6
            "is_valid", // 7
            
            "palm_normal", // 8
            "palm_position", // 9
            "palm_velocity", // 10
            "palm_width", // 11
            
            "pinch_strength", // 12

            "sphere_center", // 13
            "sphere_radius", // 14
            
            "stabilized_palm_position", // 15
            
            "time_visible", // 16
            "wrist_position" // 17
        };
        
        
        int hand_fields = sizeof (hand_field_names) / sizeof (*hand_field_names);
        mxArray *p = mxCreateStructMatrix (1, f.hands.count (), hand_fields, hand_field_names);
        mxSetFieldByNumber (plhs[0], 0, 3, p);  
        // 3 because hands is the third (fourth) field name in 
        // the overall struct we are creating.
        
        for (size_t i = 0; i < f.hands.count (); ++i)
        {
            // one by one, get the fields for the hand
            mxSetFieldByNumber (p, i, 0, mxCreateDoubleScalar (f.hands[i].id ()));
            
            mxSetFieldByNumber (p, i, 1, create_and_fill (f.hands[i].basis ()));
            mxSetFieldByNumber (p, i, 2, mxCreateDoubleScalar (f.hands[i].confidence ()));
            
            mxSetFieldByNumber (p, i, 3, create_and_fill (f.hands[i].direction ()));
            
            mxSetFieldByNumber (p, i, 4, mxCreateDoubleScalar (f.hands[i].grabStrength ()));
            
            mxSetFieldByNumber (p, i, 5, mxCreateDoubleScalar (f.hands[i].isLeft ()));
            mxSetFieldByNumber (p, i, 6, mxCreateDoubleScalar (f.hands[i].isRight ()));
            
            mxSetFieldByNumber (p, i, 7, mxCreateDoubleScalar (f.hands[i].isValid ()));
            
            mxSetFieldByNumber (p, i, 8, create_and_fill (f.hands[i].palmNormal ()));
            mxSetFieldByNumber (p, i, 9, create_and_fill (f.hands[i].palmPosition ()));
            mxSetFieldByNumber (p, i, 10, create_and_fill (f.hands[i].palmVelocity ()));
            mxSetFieldByNumber (p, i, 11, mxCreateDoubleScalar (f.hands[i].palmWidth ()));
            
            mxSetFieldByNumber (p, i, 12, mxCreateDoubleScalar (f.hands[i].pinchStrength ()));
            
            mxSetFieldByNumber (p, i, 13, create_and_fill (f.hands[i].sphereCenter ()));
            mxSetFieldByNumber (p, i, 14, mxCreateDoubleScalar (f.hands[i].sphereRadius ()));
            
            mxSetFieldByNumber (p, i, 15, create_and_fill (f.hands[i].stabilizedPalmPosition ()));
            
            mxSetFieldByNumber (p, i, 16, mxCreateDoubleScalar (f.hands[i].timeVisible ()));
            
            mxSetFieldByNumber (p, i, 17, create_and_fill (f.hands[i].wristPosition ()));
        } // re: for f.hands.count()
    } // re: if f.hands.count() > 0
}
DLL_EXPORT_SYM
void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
  if (nrhs != 3 || nlhs != 8) {
    mexErrMsgIdAndTxt(
        "Drake:testMultipleTimeLinearPostureConstrainttmex:BadInputs",
        "Usage [num_cnst, cnst_val, iAfun, jAvar, A, cnst_name, lb, ub] = "
        "testMultipleTimeLinearPostureConstraintmex(kinCnst, q, t)");
  }
  MultipleTimeLinearPostureConstraint* cnst =
      (MultipleTimeLinearPostureConstraint*)getDrakeMexPointer(prhs[0]);
  int n_breaks = static_cast<int>(mxGetNumberOfElements(prhs[2]));
  double* t_ptr = new double[n_breaks];
  memcpy(t_ptr, mxGetPrSafe(prhs[2]), sizeof(double) * n_breaks);
  int nq = cnst->getRobotPointer()->get_num_positions();
  Eigen::MatrixXd q(nq, n_breaks);
  if (mxGetM(prhs[1]) != nq || mxGetN(prhs[1]) != n_breaks) {
    mexErrMsgIdAndTxt(
        "Drake:testMultipleTimeLinearPostureConstraintmex:BadInputs",
        "Argument 2 must be of size nq*n_breaks");
  }
  memcpy(q.data(), mxGetPrSafe(prhs[1]), sizeof(double) * nq * n_breaks);
  int num_cnst = cnst->getNumConstraint(t_ptr, n_breaks);
  Eigen::VectorXd c(num_cnst);
  cnst->feval(t_ptr, n_breaks, q, c);
  Eigen::VectorXi iAfun;
  Eigen::VectorXi jAvar;
  Eigen::VectorXd A;
  cnst->geval(t_ptr, n_breaks, iAfun, jAvar, A);
  std::vector<std::string> cnst_names;
  cnst->name(t_ptr, n_breaks, cnst_names);
  Eigen::VectorXd lb(num_cnst);
  Eigen::VectorXd ub(num_cnst);
  cnst->bounds(t_ptr, n_breaks, lb, ub);
  Eigen::VectorXd iAfun_tmp(iAfun.size());
  Eigen::VectorXd jAvar_tmp(jAvar.size());
  for (int i = 0; i < iAfun.size(); i++) {
    iAfun_tmp(i) = (double)iAfun(i) + 1;
    jAvar_tmp(i) = (double)jAvar(i) + 1;
  }
  plhs[0] = mxCreateDoubleScalar((double)num_cnst);
  plhs[1] = mxCreateDoubleMatrix(num_cnst, 1, mxREAL);
  memcpy(mxGetPrSafe(plhs[1]), c.data(), sizeof(double) * num_cnst);
  plhs[2] = mxCreateDoubleMatrix(iAfun_tmp.size(), 1, mxREAL);
  memcpy(mxGetPrSafe(plhs[2]), iAfun_tmp.data(),
         sizeof(double) * iAfun_tmp.size());
  plhs[3] = mxCreateDoubleMatrix(jAvar_tmp.size(), 1, mxREAL);
  memcpy(mxGetPrSafe(plhs[3]), jAvar_tmp.data(),
         sizeof(double) * jAvar_tmp.size());
  plhs[4] = mxCreateDoubleMatrix(A.size(), 1, mxREAL);
  memcpy(mxGetPrSafe(plhs[4]), A.data(), sizeof(double) * A.size());
  int name_ndim = 1;
  mwSize name_dims[] = {(mwSize)num_cnst};
  plhs[5] = mxCreateCellArray(name_ndim, name_dims);
  mxArray* name_ptr;
  for (int i = 0; i < num_cnst; i++) {
    name_ptr = mxCreateString(cnst_names[i].c_str());
    mxSetCell(plhs[5], i, name_ptr);
  }
  plhs[6] = mxCreateDoubleMatrix(num_cnst, 1, mxREAL);
  plhs[7] = mxCreateDoubleMatrix(num_cnst, 1, mxREAL);
  memcpy(mxGetPrSafe(plhs[6]), lb.data(), sizeof(double) * num_cnst);
  memcpy(mxGetPrSafe(plhs[7]), ub.data(), sizeof(double) * num_cnst);
  delete[] t_ptr;
}
Ejemplo n.º 7
0
mxArray *sf_c2_object_tracker_intensity_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] =
  {"checksum","inputs","parameters","outputs"};
  mxArray *mxAutoinheritanceInfo =
  mxCreateStructMatrix(1,1,4,autoinheritanceFields);
  {
    mxArray *mxChecksum = mxCreateDoubleMatrix(4,1,mxREAL);
    double *pr = mxGetPr(mxChecksum);
    pr[0] = (double)(854637128U);
    pr[1] = (double)(4226084400U);
    pr[2] = (double)(14798454U);
    pr[3] = (double)(2387218890U);
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }
  {
    const char *dataFields[] = {"size","type","complexity"};
    mxArray *mxData = mxCreateStructMatrix(1,4,3,dataFields);
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(2);
      pr[1] = (double)(10);
      mxSetField(mxData,0,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(5));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(5));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }
    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }
    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(2);
      pr[1] = (double)(1);
      mxSetField(mxData,2,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(5));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(5));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,2,"type",mxType);
    }
    mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(2);
      pr[1] = (double)(1);
      mxSetField(mxData,3,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(5));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(5));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,3,"type",mxType);
    }
    mxSetField(mxData,3,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }
  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,mxREAL));
  }
  {
    const char *dataFields[] = {"size","type","complexity"};
    mxArray *mxData = mxCreateStructMatrix(1,3,3,dataFields);
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(2);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(5));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }
    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(4);
      mxSetField(mxData,1,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(5));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }
    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,2,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(5));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,2,"type",mxType);
    }
    mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }
  return(mxAutoinheritanceInfo);
}
Ejemplo n.º 8
0
void mexFunction( int nlhs,       mxArray *plhs[],
                  int nrhs, const mxArray *prhs[] 
                 )
                
{   const double *h1, *h2;
    mwSize nrow1, nrow2;
    mwIndex *ir1, *ir2, i1, i2;
    mwIndex maxc1, maxc2;
    double ret=0;
    
    /* Check I/O number */
    if (nlhs!=1) {
        mexErrMsgTxt("Incorrect number of outputs");
    }
    if (nrhs!=2) {
        mexErrMsgTxt("Incorrect number of inputs");
    }
    
    /* Brief error checking */
    
    /*ncol1 = mxGetN(prhs[0]);
    ncol2 = mxGetN(prhs[1]);*/
    nrow1 = mxGetM(prhs[0]);
    nrow2 = mxGetM(prhs[1]);
    
    /*if ((ncol!=mxGetM(prhs[1])) || (mxGetN(prhs[1])!=1)) {
        mexErrMsgTxt("Wrong input dimensions");
    }
    if (!mxIsSparse(prhs[0])) {
        mexErrMsgTxt("Matrix must be sparse");
    }*/
    
    
    /* Allocate output */
    /*plhs[0] = mxCreateDoubleMatrix(mxGetM(prhs[0]), 1, mxREAL);*/

    
    /* I/O pointers */
    ir1 = mxGetIr(prhs[0]);      /* Row indexing      */
    ir2 = mxGetIr(prhs[1]);      /* Row indexing      */    
    h1  = mxGetPr(prhs[0]);      /* Non-zero elements */
    h2  = mxGetPr(prhs[1]);      /* Rhs vector        */
    maxc1 = mxGetJc(prhs[0])[1];
    maxc2 = mxGetJc(prhs[1])[1];

    
    i1=0;
    i2=0;

    while(i1<maxc1 && i2<maxc2) {            /* Loop through columns */
        if (ir1[i1]==ir2[i2]) {
            ret=ret+h1[i1]*h2[i2]/(h1[i1]+h2[i2]);
            i1++;
            i2++;
        } else {
            if (ir1[i1]>ir2[i2])
                i2++;
            else
                i1++;
        }
    }

    plhs[0] = mxCreateDoubleScalar(2-4*ret);
}
mxArray *sf_c8_AllPurposeModel_TyreRelaxation_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals", "postCodegenInfo" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1, 1, sizeof
    (autoinheritanceFields)/sizeof(autoinheritanceFields[0]),
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateString("yymzPjWWJIO6bqgeXReD6");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,2,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(13));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(13));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  {
    mxArray* mxPostCodegenInfo =
      sf_c8_AllPurposeModel_TyreRelaxation_get_post_codegen_info();
    mxSetField(mxAutoinheritanceInfo,0,"postCodegenInfo",mxPostCodegenInfo);
  }

  return(mxAutoinheritanceInfo);
}
Ejemplo n.º 10
0
/*
 *	o b t a i n O u t p u t s S B
 */
returnValue obtainOutputsSB(	int k, QProblemB* qp, returnValue returnvalue, int _nWSRout, double _cpuTime,
								int nlhs, mxArray* plhs[], int nV, int handle
								)
{
	double *x=0, *obj=0, *status=0, *nWSRout=0, *y=0, *workingSetB=0, *workingSetC=0, *cpuTime;
	mxArray *auxOutput=0, *curField=0;

	/* Create output vectors and assign pointers to them. */
	int curIdx = 0;

	/* handle */
	if ( handle >= 0 )
		plhs[curIdx++] = mxCreateDoubleScalar( handle );

	/* x */
	x = mxGetPr( plhs[curIdx++] );
	QProblemB_getPrimalSolution( qp,&(x[k*nV]) );

	if ( nlhs > curIdx )
	{
		/* fval */
		obj = mxGetPr( plhs[curIdx++] );
		obj[k] = QProblemB_getObjVal( qp );

		if ( nlhs > curIdx )
		{
			/* exitflag */
			status = mxGetPr( plhs[curIdx++] );
			status[k] = (double)qpOASES_getSimpleStatus( returnvalue,0 );

			if ( nlhs > curIdx )
			{
				/* iter */
				nWSRout = mxGetPr( plhs[curIdx++] );
				nWSRout[k] = (double) _nWSRout;

				if ( nlhs > curIdx )
				{
					/* lambda */
					y = mxGetPr( plhs[curIdx++] );
					QProblemB_getDualSolution( qp,&(y[k*nV]) );

					/* auxOutput */
					if ( nlhs > curIdx )
					{
						auxOutput = plhs[curIdx];
						curField = 0;

						/* working set bounds */
						if ( nV > 0 )
						{
							curField = mxGetField( auxOutput,0,"workingSetB" );
							workingSetB = mxGetPr(curField);
							QProblemB_getWorkingSetBounds( qp,&(workingSetB[k*nV]) );
						}

						/* cpu time */
						curField = mxGetField( auxOutput,0,"cpuTime" );
						cpuTime = mxGetPr(curField);
						cpuTime[0] = (double) _cpuTime;
					}
				}
			}
		}
	}
	
	return SUCCESSFUL_RETURN;
}
mxArray *sf_c2_DSHMHittingSecondORder_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateString("CA8SwQL6JonaLH0nyQxer");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,3,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,2,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,2,"type",mxType);
    }

    mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  return(mxAutoinheritanceInfo);
}
Ejemplo n.º 12
0
mxArray *message_constructor(const MessagePtr& message, int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
  mxArray *result = 0;

  // parse inputs
  if (nrhs > 0 && Options::isString(prhs[0])) {
    std::string option = Options::getString(prhs[0]);
    if (nrhs == 1 && boost::algorithm::iequals(option, "definition")) {
      result = mxCreateString(message->getDefinition());
      return result;
    }
    if (nrhs == 1 && boost::algorithm::iequals(option, "md5sum")) {
      result = mxCreateString(message->getMD5Sum());
      return result;
    }
    if (nrhs == 1 && boost::algorithm::iequals(option, "fields")) {
      result = mxCreateCellMatrix(1, message->getFieldNames().size());
      for(std::size_t i = 0; i < message->getFieldNames().size(); ++i) {
        mxSetCell(result, i, mxCreateString(message->getFieldNames().at(i)));
      }
      return result;
    }
    if ((nrhs == 1 || nrhs == 2) && boost::algorithm::iequals(option, "default")) {
      if (nrhs == 2) {
        const mxArray *default_options = prhs[1];
        Conversion::perMessageOptions(message).merge(ConversionOptions(1, &default_options));
      }
      return Conversion::perMessageOptions(message).toMatlab();
    }
  }

  // Check if a numeric argument (message count) has been given
  std::size_t count = 1;
  if (nrhs > 0 && (Options::isIntegerScalar(prhs[0]) || Options::isDoubleScalar(prhs[0]))) {
    count = Options::getIntegerScalar(prhs[0]);
    nrhs--; prhs++;
  }

  // Get conversion options
  ConversionOptions options;
  if (nrhs % 2 == 0) {
    options.init(nrhs, prhs);
  } else {
    options.init(nrhs - 1, prhs + 1);
  }

  // Is this a copy constructor?
  if (nrhs % 2 != 0) {
    Conversion conversion(message, options);
    V_Message copy(conversion.numberOfInstances(prhs[0]));

    for(std::size_t j = 0; j < copy.size(); j++) {
      copy[j] = conversion.fromMatlab(prhs[0], j);
      // std::cout << "Constructed a new " << copy[j]->getDataType() << " message: " << *boost::shared_static_cast<MessageType const>(copy[j]->getConstInstance()) << std::endl;
      result = Conversion(conversion, copy[j]).toMatlab(result, j, copy.size());
    }

  // otherwise construct a new message
  } else {
    MessagePtr m = message->introspect(message->createInstance());
    // std::cout << "Constructed a new " << m->getDataType() << " message: " << *boost::shared_static_cast<MessageType const>(m->getConstInstance()) << std::endl;
    Conversion conversion(m, options);
    result = conversion.toMatlab();
  }

  // copy the contents of result if count > 1
  if (count > 1) {
    // This seems to be a bit hacky. Is there a better solution?
    mxArray *repmatrhs[] = { result, mxCreateDoubleScalar(1), mxCreateDoubleScalar(count) };
    mxArray *repmatlhs[] = { 0 };
    mexCallMATLAB(1, repmatlhs, 3, repmatrhs, "repmat");
    mxDestroyArray(repmatrhs[0]);
    mxDestroyArray(repmatrhs[1]);
    mxDestroyArray(repmatrhs[2]);
    result = repmatlhs[0];
  }

  return result;
}
Ejemplo n.º 13
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    double *wv, *nFeatures, *np, *ep, *Z, lambda;
    unsigned int nStates, nFeaturesTotal, maxSentenceLength;
    SubMatrix w, v, v_start, v_end, gw, gv, gv_start, gv_end, sentences, y, X, featureStart;
    double f = 0;
    
    wv = mxGetPr(prhs[0]);
    
    X.value_start =  mxGetPr(prhs[1]);
    X.numRows = mxGetM(prhs[1]);
    X.numColumns = mxGetN(prhs[1]);
    
    y.value_start = mxGetPr(prhs[2]);
    y.numRows = mxGetM(prhs[2]);
    y.numColumns = mxGetN(prhs[2]);
    
    nStates = mxGetScalar(prhs[3]);
    nFeatures = mxGetPr(prhs[4]);
    
    featureStart.value_start = mxGetPr(prhs[5]);
    featureStart.numRows = mxGetM(prhs[5]);
    featureStart.numColumns = mxGetN(prhs[5]);
    
    sentences.value_start = mxGetPr(prhs[6]);
    sentences.numRows = mxGetM(prhs[6]);
    sentences.numColumns = mxGetN(prhs[6]);
    
    maxSentenceLength = mxGetScalar(prhs[7]);
    
    lambda = mxGetScalar(prhs[8]);
    
    /*nFeaturesTotal = featureStart(end)-1;*/
    nFeaturesTotal = submat_value(featureStart, 1, featureStart.numColumns) - 1;
    int nSentences = mxGetM(prhs[6]);
    
    /*Set up the submatrices for node and edge parameters*/
    w.value_start = wv;
    w.numRows = nFeaturesTotal;
    w.numColumns = nStates;
    
    v_start.value_start = wv + nFeaturesTotal*nStates;
    v_start.numRows = nStates;
    v_start.numColumns = 1;
    
    v_end.value_start = wv + nFeaturesTotal*nStates + nStates;
    v_end.numRows = nStates;
    v_end.numColumns = 1;
    
    v.value_start = wv + nFeaturesTotal*nStates + 2*nStates;
    v.numRows = nStates;
    v.numColumns = nStates;
    
    mxArray *g = mxCreateDoubleMatrix(mxGetM(prhs[0]),mxGetN(prhs[0]),mxREAL);
    /*mxArray *g = prhs[7];*/
    
    gw.value_start = mxGetPr(g);
    gw.numRows = nFeaturesTotal;
    gw.numColumns = nStates;
    
    gv_start.value_start = mxGetPr(g) + nFeaturesTotal*nStates;
    gv_start.numRows = nStates;
    gv_start.numColumns = 1;
    
    gv_end.value_start = gv_start.value_start + nStates;
    gv_end.numRows = nStates;
    gv_end.numColumns = 1;
    
    gv.value_start = gv_end.value_start + nStates;
    gv.numRows = nStates;
    gv.numColumns = nStates;
    
    int i,j, s, n, k, feat, state, state1, state2;
    SubMatrix nodePot, edgePot, nodeBel, edgeBel, alpha, beta;
    nodePot.value_start = mxCalloc(maxSentenceLength*nStates,sizeof(double));
    edgePot.value_start = mxCalloc(nStates*nStates,sizeof(double));
        nodeBel.value_start = mxCalloc(maxSentenceLength*nStates,sizeof(double));
        edgeBel.value_start = mxCalloc(nStates*nStates*(maxSentenceLength-1),sizeof(double));
        alpha.value_start = mxCalloc(maxSentenceLength*nStates, sizeof(double));
        beta.value_start  = mxCalloc(maxSentenceLength*nStates, sizeof(double));
        Z = mxCalloc(maxSentenceLength,sizeof(double));
    for (s = 1; s <= nSentences; ++s) {
        int nNodes = submat_value(sentences, s, 2) - submat_value(sentences, s, 1) + 1;
        
        SubMatrix y_s;
        y_s.value_start = submat_pointer(y, (long)submat_value(sentences, s, 1), 1);
        y_s.numRows = submat_value(sentences, s, 2) - submat_value(sentences, s, 1) + 1;
        y_s.numColumns = 1;
        
        /*******************************************************************************/
        /* Make nodePot/edgePot */
        
        nodePot.numRows = nNodes;
        nodePot.numColumns = nStates;
        
        edgePot.numRows = v.numRows;
        edgePot.numColumns = v.numColumns;
        
        for (n = 1; n <= nNodes; ++n) {
            double features[X.numColumns];
            int k;
            for (k = 1; k <= X.numColumns; ++k) {
                features[k-1] = submat_value(X, (long)submat_value(sentences, s, 1)+(long)n-(long)1, (long)k);
            }
            
            
            int state;
            for (state = 1; state <= nStates; ++state) {
                double pot = 0;
                int f;
                for (f = 1; f <= mxGetN(prhs[4]); ++f) {
                    if (features[f-1] != 0) {
                        int featureParam = submat_value(featureStart, 1, f) + features[f-1] - 1;
                        pot += w.value_start[featureParam+nFeaturesTotal*(state-1)-1];
                    }
                }
                submat_value(nodePot, n, state) = pot;
            }
        }
        
        for (k = 1; k <= nodePot.numColumns; ++k) {
            submat_value(nodePot, 1, k) += submat_value(v_start, k, 1);
        }
        
        for (k = 1; k <= nodePot.numColumns; ++k) {
            submat_value(nodePot, nodePot.numRows, k) += submat_value(v_end, k, 1);
        }
        
        for (k = 0; k < nodePot.numRows*nodePot.numColumns; ++k) {
            nodePot.value_start[k] = exp(nodePot.value_start[k]);
        }
        
        for (k = 0; k < edgePot.numRows*edgePot.numColumns; ++k) {
            edgePot.value_start[k] = exp(v.value_start[k]);
        }
        
        
            
        /*******************************************************************************/
        
        /*******************************************************************************/
        /* Infer */
        
        nodeBel.numRows = nodePot.numRows;
        nodeBel.numColumns = nodePot.numColumns;
        
        edgeBel.numRows = nStates;
        edgeBel.numColumns = nStates;
        edgeBel.numMatrices = nNodes - 1;
        
        alpha.numRows = nNodes;
        alpha.numColumns = nStates;
        
        beta.numRows = nNodes;
        beta.numColumns = nStates;
        for (n=0; n< nNodes*nStates;n++)
            beta.value_start[n] = 0;
        
        for (n=0; n < nNodes;n++)
        Z[n]=0;;
        
        for (i = 1; i <= alpha.numColumns; ++i) {
            submat_value(alpha, 1, i) = submat_value(nodePot, 1, i);
        }
        
        for (i = 1; i <= alpha.numColumns; ++i) {
            Z[0] += submat_value(alpha, 1, i);
        }
        
        for (i = 1; i <= alpha.numColumns; ++i) {
            submat_value(alpha, 1, i) /= Z[0];
        }
        
        for (n = 2; n <= nNodes; ++n) {
            double tmp[edgePot.numColumns];
            for (i = 0; i < edgePot.numColumns; ++i) {
                tmp[i] = 0;
            }
            for (i = 1; i <= alpha.numColumns; ++i) {
                for (j = 1; j <= nStates; ++j) {
                    tmp[j-1] += submat_value(alpha, n-1, i)*submat_value(edgePot, i, j);
                }
            }
            
            for (i = 1; i <= alpha.numColumns; ++i) {
                submat_value(alpha, n, i) = submat_value(nodePot, n, i)*tmp[i-1];
            }
            
            for (i = 1; i <= alpha.numColumns; ++i) {
                Z[n-1] += submat_value(alpha, n, i);
            }
            
            for (i = 1; i <= alpha.numColumns; ++i) {
                submat_value(alpha, n, i) /= Z[n-1];
            }
        }
        
        for (i = 1; i<= nStates; ++i) {
            submat_value(beta, nNodes, i) = 1;
        }
        
        for (n = nNodes - 1; n >= 1; --n) {
            for (j = 1; j <= nodePot.numColumns; ++j) {
                for (i = 1; i <= nStates; ++i) {
                    submat_value(beta, n, i) += submat_value(nodePot, n+1, j)*submat_value(edgePot, i, j)*submat_value(beta, n+1, j);
                }
            }
            
            double tmp = 0;
            for (i = 1; i <= beta.numColumns; ++i) {
                tmp += submat_value(beta, n, i);
            }
            for (i = 1; i <= beta.numColumns; ++i) {
                submat_value(beta, n, i) /= tmp;
            }
        }
        
        for (n = 1; n <= nNodes; ++n) {
            double tmp[alpha.numColumns];
            for (i = 0; i < alpha.numColumns; ++i) {
                tmp[i] = 0;
            }
            
            double sumTmp = 0;
            for (i = 1; i <= alpha.numColumns; ++i) {
                tmp[i-1] += submat_value(alpha, n, i)*submat_value(beta, n, i);
                sumTmp += tmp[i-1];
            }
            
            for (i = 1; i <= alpha.numColumns; ++i) {
                submat_value(nodeBel, n, i) = tmp[i-1]/sumTmp;
            }
        }
        
        for (n = 1; n <= nNodes-1; ++n) {
            double sum = 0;
            for (i = 1; i <= nStates; ++i) {
                for (j = 1; j <= nStates; ++j) {
                    submat_value3(edgeBel, i, j, n) = submat_value(alpha, n, i)*submat_value(nodePot, n+1, j)*submat_value(beta, n+1, j)*submat_value(edgePot, i, j);
                    sum += submat_value3(edgeBel, i, j, n);
                }
            }
            
            for (i = 1; i <= nStates; ++i) {
                for (j = 1; j <= nStates; ++j) {
                    submat_value3(edgeBel, i, j, n) /= sum;
                }
            }
        }
        
        double logZ = 0;
        
        for (i = 0; i < nNodes; ++i) {
            logZ += log(Z[i]);
        }
        
        /*******************************************************************************/
        
        for (n = 1; n <= nNodes; ++n) {
            f += log(submat_value(nodePot, n, (long)submat_value(y_s, n, 1)));
        }
        
        for (n = 1; n <= nNodes - 1; ++n) {
            f += log(submat_value(edgePot, (long)submat_value(y_s, n, 1), (long)submat_value(y_s, n+1, 1)));
        }
        
        f -= logZ;
        
        /*Update gradient of node features*/
        for (n = 1; n <= nNodes; ++n) {
            double features[X.numColumns];
            int k;
            for (k = 1; k <= X.numColumns; ++k) {
                features[k-1] = submat_value(X, (long)submat_value(sentences, s, 1)+(long)n-(long)1, (long)k);
            }
            
            for (feat = 1; feat <= mxGetN(prhs[4]); ++feat) {
                if (features[feat-1] != 0) {
                    int featureParam = submat_value(featureStart, 1, feat) + features[feat-1] - 1;
                    for (state = 1; state <= nStates; ++state) {
                        int O = (state == submat_value(y_s, n, 1));
                        double E = submat_value(nodeBel, n, state);
                        submat_value(gw, featureParam, state) += O - E;
                    }
                }
            }
        }
        
        /*Update gradient of BoS and EoS transitions*/
        for (state = 1; state <= nStates; ++state) {
            int O = (state == submat_value(y_s, 1, 1));
            double E = submat_value(nodeBel, 1, state);
            submat_value(gv_start, state, 1) += O - E;
            
            O = (state == submat_value(y_s, y_s.numRows, 1));
            E = submat_value(nodeBel, nodeBel.numRows, state);
            submat_value(gv_end, state, 1) += O - E;
        }
        
        /*GOOD TO HERE*/
        /*Update gradient of transitions*/
        for (n = 1; n <= nNodes - 1; ++n) {
            for (state1 = 1; state1 <= nStates; ++state1) {
                for (state2 = 1; state2 <= nStates; ++state2) {
                    int O = ((state1 == submat_value(y_s, n, 1)) && (state2 == submat_value(y_s, n+1, 1)));
                    double E = edgeBel.value_start[(state1-1) + edgeBel.numRows*((state2-1) + edgeBel.numColumns*(n-1))];
                    submat_value(gv, state1, state2) += O - E;
                }
            }
        }
    }
    double* temp = mxGetPr(g);
    for (n = 1; n <= mxGetM(g); ++n) {
        *temp *= -1;
        temp += 1;
    }
    
    /* Add L2-penalty to Objective and Gradient*/
    double sumSquared = 0;
    temp = mxGetPr(g);
    for(i = 0; i < nFeaturesTotal*nStates + 2*nStates + nStates*nStates;i++)
    {
        sumSquared += wv[i]*wv[i];
        temp[i] += lambda*wv[i];
    }
    f = f - (lambda/2)*sumSquared;
    
    plhs[0] = mxCreateDoubleScalar(-f);
    plhs[1] = g;
    
        mxFree(nodePot.value_start);
        mxFree(edgePot.value_start);
        mxFree(nodeBel.value_start);
        mxFree(edgeBel.value_start);
        mxFree(alpha.value_start);
        mxFree(beta.value_start);
        mxFree(Z);
}
Ejemplo n.º 14
0
mxArray *sf_c2_Demo_Kinect_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateString("ytkMaZ3LJMwsAy7iUSYW1D");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,7,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,2,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,2,"type",mxType);
    }

    mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,3,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,3,"type",mxType);
    }

    mxSetField(mxData,3,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,4,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,4,"type",mxType);
    }

    mxSetField(mxData,4,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,5,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,5,"type",mxType);
    }

    mxSetField(mxData,5,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,6,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,6,"type",mxType);
    }

    mxSetField(mxData,6,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  return(mxAutoinheritanceInfo);
}
Ejemplo n.º 15
0
mxArray *sf_c12_ekffedepre_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateDoubleMatrix(4,1,mxREAL);
    double *pr = mxGetPr(mxChecksum);
    pr[0] = (double)(1571567285U);
    pr[1] = (double)(2463084369U);
    pr[2] = (double)(780662584U);
    pr[3] = (double)(3535259596U);
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(3);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(3);
      pr[1] = (double)(3);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  return(mxAutoinheritanceInfo);
}
mxArray *sf_c3_ARP_02_RPSsmile_Glove_atomicError_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateString("6ToljhSGzQbPoAkW7t0cfB");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  return(mxAutoinheritanceInfo);
}
Ejemplo n.º 17
0
mxArray *sf_c3_MPC_framework_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] =
  {"checksum","inputs","parameters","outputs"};
  mxArray *mxAutoinheritanceInfo =
  mxCreateStructMatrix(1,1,4,autoinheritanceFields);
  {
    mxArray *mxChecksum = mxCreateDoubleMatrix(4,1,mxREAL);
    double *pr = mxGetPr(mxChecksum);
    pr[0] = (double)(3468697740U);
    pr[1] = (double)(2591828673U);
    pr[2] = (double)(139957213U);
    pr[3] = (double)(1717524660U);
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }
  {
    const char *dataFields[] = {"size","type","complexity"};
    mxArray *mxData = mxCreateStructMatrix(1,8,3,dataFields);
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }
    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }
    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,2,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,2,"type",mxType);
    }
    mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,3,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,3,"type",mxType);
    }
    mxSetField(mxData,3,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,4,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,4,"type",mxType);
    }
    mxSetField(mxData,4,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,5,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,5,"type",mxType);
    }
    mxSetField(mxData,5,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,6,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,6,"type",mxType);
    }
    mxSetField(mxData,6,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,7,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,7,"type",mxType);
    }
    mxSetField(mxData,7,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }
  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,mxREAL));
  }
  {
    const char *dataFields[] = {"size","type","complexity"};
    mxArray *mxData = mxCreateStructMatrix(1,3,3,dataFields);
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }
    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }
    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));
    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,2,"size",mxSize);
    }
    {
      const char *typeFields[] = {"base","aliasId","fixpt"};
      mxArray *mxType = mxCreateStructMatrix(1,1,3,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"aliasId",mxCreateDoubleScalar(0));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,2,"type",mxType);
    }
    mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }
  return(mxAutoinheritanceInfo);
}
Ejemplo n.º 18
0
mxArray *sf_c2_hapticsSimBlk_pd_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateString("Im5RbwVXS12JBrAPRIrR4E");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(3);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(3);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  return(mxAutoinheritanceInfo);
}
Ejemplo n.º 19
0
void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
     
       mwSize n, m, nz; /* m- number of rows; n-number of col; */
       mxArray *v1,*v2;  /* used for pass the return value-- left hand values (plhs). */
       mwIndex i,j;
       double *pr, *Y, *r, *delta, *delta_beta, *beta, *beta2;
       mwIndex *ir, *jc;
       double Z, value, F,lamda; /* Z denotes the  denuminator*/
       mwIndex row;
       double a,b,f,e, betaj, s, deriv, delta_vj, delta_betaj,de,deltaj,intcpt, delta_BOUND_intcpt,delta_intcpt, delta_intcpt_cand,abs_d_beta,abs_beta, crit;
       double iter;
       
       
       if (! mxIsSparse (prhs[0]))
                mexErrMsgTxt ("expects sparse matrix");
     
     
     /* pass X */
       m = mxGetM (prhs [0]);
       n = mxGetN (prhs [0]);
       nz = mxGetNzmax (prhs [0]);
       pr = mxGetPr (prhs[0]);
       ir = mxGetIr (prhs[0]);
       jc = mxGetJc (prhs[0]);
           
       /* pass Y,r,delta,lambda,delta_beta,beta */
           
       Y =  mxGetPr(prhs[1]);
       r = mxGetPr(prhs[2]);
       delta = mxGetPr(prhs[3]);
       delta_beta = mxGetPr(prhs[4]);
       beta = mxGetPr(prhs[5]);
       lamda = mxGetScalar(prhs[6]);
       
       
       
       
       /*
       beta = zeros(1,p);
        
        intcpt = 0;
        delta = ones(1,p);
        delta_BOUND_intcpt = 1;
        r = zeros(n,1);
        delta_beta = zeros(1,p);
        %delta_vj = 0;
        delta_r = zeros(n,1);*/
        
        
        /*initialization
        for(j = 0; j < n; j ++)
        {       beta[j] = 0;
                delta[j] = 1;
                delta_beta[j] = 0;
                
        }
        
        for(i = 0; i < m; i ++)
        {
                r[i] = 0;
                /*delta_r[i] = 0;
        }
        */
        intcpt = 0;
        delta_BOUND_intcpt = 1;
        
        
        
        
        iter = 0;
        while(1)
        
        {
                iter = iter + 1;       
                while(1) {   
                        /*par2 = delta_BOUND_intcpt * ones(n,1);
                        de = sum(F(r,par2));
                        */
                        de = 0.0;
                        b = delta_BOUND_intcpt;
                        for(i = 0; i < m; i++){
                                a = r[i];                               
                                if (a <= b) F = 0.25;
                                else {
                                        e = exp(a - b);
                                        F = 1.0 / (2.0 + e + 1.0 / e);
                                }
                                de = de + F;
                        }
                        
                        delta_intcpt_cand = 0.0;
                        for(i = 0; i < m; i ++)
                        {
                                delta_intcpt_cand = delta_intcpt_cand + Y[i]/(1.0 + exp(r[i]));
                        }
                        
                        delta_intcpt_cand = delta_intcpt_cand / de;
                        
                        
                        /*delta_intcpt_cand =  sum(Y./(1+exp(r)))  / de;    */
                        delta_intcpt = min(max(delta_intcpt_cand,-delta_BOUND_intcpt),delta_BOUND_intcpt);   
                        
                        for(i = 0; i < m; i++)
                                r[i] = r[i] + delta_intcpt*Y[i];    
                        intcpt = intcpt + delta_intcpt;    
                        delta_BOUND_intcpt = max(2*fabs(delta_intcpt),delta_BOUND_intcpt/2.0);
                        if (fabs(delta_intcpt)/(1+fabs(intcpt)) < 5E-4)
                                break;    
                                
                }
       
       
  
          
      for(j = 0; j < n; j++){
           
                if( jc[j+1] == jc[j]) continue;  /*there is no nonzero elements in j-th column*/
                Z = 0;
                de = 0;
                
                for(i = jc[j]; i < jc[j+1]; i ++)  /* print the jth non-zero col*/
                        /*   the value is pr[i]; the row is ir[i] */                    
                                
                {       
                        row = ir[i];
                        value = pr[i];                  
                        Z = Z + value * Y[row] / (1+exp(r[row]));                                               a = fabs(r[row]);
                        b = fabs(delta[j] * value);
                       /*F; // = a<=b ? 0.25 : 1.0/( 2.0 + exp(a-b) + exp(b-a) );*/
                        if (a <= b) F = 0.25;
                        else {
                              e = exp(a - b);
                              F = 1.0 / (2.0 + e + 1.0 / e);
                        }

                        de += F * value * value;
                }
                
                betaj = beta[j];
                deltaj = delta[j];
                
                if (betaj)
                {
                         s = betaj / fabs(betaj);
                         deriv = lamda * s;
                         delta_vj = (Z - deriv) / de;
                         if (s*(betaj + delta_vj) < 0)
                                delta_vj = -betaj;
                }       
                else
                {       s = 1;
                        deriv = lamda * s;
                        delta_vj = (Z - deriv) / de;                         
                        if (delta_vj <= 0)
                        {       s = -1;
                                deriv = lamda * s;
                                delta_vj = (Z - deriv) / de;
                                if (delta_vj >= 0)
                                        delta_vj = 0;
                                
                        }
                }       
                delta_betaj = min(max(delta_vj,-deltaj),deltaj);
                for(i = jc[j]; i < jc[j+1]; i ++)  /* print the jth non-zero col*/
                        /*   the value is pr[i]; the row is ir[i] */                    
                
                        
                {       
                        row = ir[i];
                        value = pr[i];
                        r[row] = r[row] + delta_betaj * Y[row] * pr[i];
                        /*r(index) = rnow + delta_betaj * (Xnow.* Ynow);*/
                }
                        
                        
                beta[j] = betaj+delta_betaj; 
                delta[j] = max(2.0*fabs(delta_betaj),deltaj/2.0);
                delta_beta[j] = delta_betaj;      
      }  
                
        abs_d_beta = 0.0;
        abs_beta = 0.0;
        for(j = 0; j < n; j ++)
        {
                abs_d_beta = abs_d_beta + fabs(delta_beta[j]);
                abs_beta = abs_beta + fabs(beta[j]);
        }

        crit = 1.0* abs_d_beta / (1+abs_beta);

        /*crit = ( sum( abs(delta_beta) )  )/ (1+sum(abs(beta)) );  */
        if (crit < 5E-4 || iter > 2000)
                break;
        }



/*
v1 = mxCreateDoubleMatrix(m,1,mxREAL);
                r2  =  mxGetPr(v1);
                for(i = 0; i< m; i ++)
                        r2[i] = r[i];
                plhs[0] = v1;           
           
           
           
                v2 = mxCreateDoubleMatrix(1,n,mxREAL);
                delta2 = mxGetPr(v2);
                for(i = 0; i< n; i++)
                        delta2[i] = delta[i];
                plhs[1] = v2; /*plhs[1] = delta;
           
           
           
                v3 = mxCreateDoubleMatrix(1,n,mxREAL);
                delta_beta2 = mxGetPr(v3);
                for(i =0; i< n; i++)
                        delta_beta2[i] = delta_beta[i];
                plhs[2] = v3; /*plhs[2] = delta_beta;           */
           
         
           v1 = mxCreateDoubleScalar(intcpt);
                  /*intcpt2 = mxGetPr(v1);
                  intcpt2 = intcpt; */
                plhs[0] = v1; /*plhs[3] = beta;*/
           
           
                 v2 = mxCreateDoubleMatrix(1,n,mxREAL);
                  beta2 = mxGetPr(v2);
                for(i = 0; i< n; i++)
                        beta2[i] = beta[i];
                plhs[1] = v2; /*plhs[3] = beta;*/       
                
                
                
                

}
Ejemplo n.º 20
0
void mexFunction(int nlhs, mxArray *plhs[],
                 int nrhs, const mxArray *prhs[]) {
    mwSize N;
    double *x, *lb, *ub, fx;
    lbfgsb_options_t op;

    if (nrhs<4)
        mexErrMsgTxt("lbfgs_ requires exactly 4 input arguments.");
    if( mxGetClassID(prhs[0]) != mxFUNCTION_CLASS )
        mexErrMsgTxt("The first argument must be a function handle.");
    if (!mxIsDouble(prhs[1]))
        mexErrMsgTxt("The second argument must be a column vector.");
    if (!mxIsDouble(prhs[2]))
        mexErrMsgTxt("The third argument must be a column vector.");
    if (!mxIsDouble(prhs[3]))
        mexErrMsgTxt("The fourth argument must be a column vector.");

    if (!mxIsStruct(prhs[4]))
        mexErrMsgTxt("The fith argument must be a struct.");

    N = mxGetM(prhs[1])*mxGetN(prhs[1]);

    // Get function handle for use with mexCallMATLAB
    rhs[0] = mxDuplicateArray(prhs[0]);
    rhs[1] = mxCreateDoubleMatrix(N,1,mxREAL);

    op.m = (int) mxGetScalar(mxGetField(prhs[4],0,"m"));
    op.maxiter = (int) mxGetScalar(mxGetField(prhs[4],0,"maxiter"));
    op.pgtol = (double) mxGetScalar(mxGetField(prhs[4],0,"pgtol"));
    op.factr = (double) mxGetScalar(mxGetField(prhs[4],0,"factr"));
    op.iter = iter;

    // Allocate memory for solution vector and initialize it to x0
    // do the same for the lower and upper bounds
    x = (double*)mxMalloc(N*sizeof(double));
    lb = (double*)mxMalloc(N*sizeof(double));
    ub = (double*)mxMalloc(N*sizeof(double));
    memcpy(x, mxGetPr(prhs[1]),N*sizeof(double));
    memcpy(lb,mxGetPr(prhs[2]),N*sizeof(double));
    memcpy(ub,mxGetPr(prhs[3]),N*sizeof(double));

    LBFGSB lfbsgb(N, x, lb, ub, evaluate, &op);

    lbfgsb_res_t res = lfbsgb.solve(fx);
    mxArray *res_str;
    switch(res) {
    case CONVERGED:
        mexPrintf("L-BFGS-B converged\n");
        res_str = mxCreateString("converged");
        break;
    case ABNORMAL_TERMINATION:
        mexPrintf("L-BFGS-B abnormal termination\n");
        res_str = mxCreateString("abnormal termination");
        break;
    case ERROR:
        mexPrintf("L-BFGS-B error\n");
        res_str = mxCreateString("error");
        break;
    case MAX_ITER:
        mexPrintf("L-BFGS-B max iterations reached\n");
        res_str = mxCreateString("max iterations reached");
        break;
    case UNHANDLED:
    default:
        mexWarnMsgTxt("Unknown result state");
        res_str = mxCreateString("Unknown result state");
        break;
    }

    // Allocate outputs
    plhs[0] = mxCreateDoubleMatrix(N,1,mxREAL);
    if(nlhs > 1)
        plhs[1] = mxCreateDoubleScalar(fx);

    if(nlhs > 2)
        plhs[2] = mxCreateDoubleScalar(res);
    // Copy current iterate to output
    memcpy(mxGetPr(plhs[0]),x,N*sizeof(double));
}
Ejemplo n.º 21
0
/*
 *	o b t a i n O u t p u t s
 */
returnValue obtainOutputs(	int k, QProblemB* qp, returnValue returnvalue, int _nWSRout, double _cpuTime,
							int nlhs, mxArray* plhs[], int nV, int nC = 0, int handle = -1
							)
{
	/* Create output vectors and assign pointers to them. */
	int curIdx = 0;

	/* handle */
	if ( handle >= 0 )
		plhs[curIdx++] = mxCreateDoubleScalar( handle );

	/* x */
	double* x = mxGetPr( plhs[curIdx++] );
	qp->getPrimalSolution( &(x[k*nV]) );

	if ( nlhs > curIdx )
	{
		/* fval */
		double* obj = mxGetPr( plhs[curIdx++] );
		obj[k] = qp->getObjVal( );

		if ( nlhs > curIdx )
		{
			/* exitflag */
			double* status = mxGetPr( plhs[curIdx++] );
			status[k] = (double)getSimpleStatus( returnvalue );

			if ( nlhs > curIdx )
			{
				/* iter */
				double* nWSRout = mxGetPr( plhs[curIdx++] );
				nWSRout[k] = (double) _nWSRout;

				if ( nlhs > curIdx )
				{
					/* lambda */
					double* y = mxGetPr( plhs[curIdx++] );
					qp->getDualSolution( &(y[k*(nV+nC)]) );

					/* auxOutput */
					if ( nlhs > curIdx )
					{
						QProblem* problemPointer;
						problemPointer = dynamic_cast<QProblem*>(qp);

						mxArray* auxOutput = plhs[curIdx];
						mxArray* curField = 0;

						/* working set bounds */
						if ( nV > 0 )
						{
							curField = mxGetField( auxOutput,0,"workingSetB" );
							double* workingSetB = mxGetPr(curField);

							/* cast successful? */
							if (problemPointer != NULL) {
								problemPointer->getWorkingSetBounds( &(workingSetB[k*nV]) );
							} else {
								qp->getWorkingSetBounds( &(workingSetB[k*nV]) );
							}
						}

						/* working set constraints */
						if ( nC > 0 )
						{
							curField = mxGetField( auxOutput,0,"workingSetC" );
							double* workingSetC = mxGetPr(curField);

							/* cast successful? */
							if (problemPointer != NULL) {
								problemPointer->getWorkingSetConstraints( &(workingSetC[k*nC]) );
							} else {
								qp->getWorkingSetConstraints( &(workingSetC[k*nC]) );
							}
						}

						/* cpu time */
						curField = mxGetField( auxOutput,0,"cpuTime" );
						double* cpuTime = mxGetPr(curField);
						cpuTime[0] = (double) _cpuTime;
					}
				}
			}
		}
	}
	
	return SUCCESSFUL_RETURN;
}
Ejemplo n.º 22
0
/*
 * This ist the Entry Function of this Mex-DLL
 */
void mexFunction(int nlhs, mxArray*plhs[], int nrhs, const mxArray*prhs[])
{
    mexAtExit(CloseDBs);
    
    /*
     * Get the current Language
     */
    if (Language == -1)
    {
#ifdef _WIN32        
        switch(PRIMARYLANGID(GetUserDefaultLangID()))
        {
            case LANG_GERMAN:
                Language = 1;
                break;
                
            default:
                Language = 0;
        }
#else
        Language = 0;
#endif
    }
    
	/*
	 * Print Version Information
	 */
	if (! FirstStart)
    {
    	FirstStart = true;

        mexPrintf (MSG_HELLO, sqlite3_libversion());
    }
    
    int db_id = 0;
    int CommandPos = 0;
    int NumArgs = nrhs;
    int i;
    
    /*
     * Check if the first argument is a number, then we have to use
	 * this number as an database id.
     */
    if (nrhs >= 1 && mxIsNumeric(prhs[0]))
    {
        db_id = getinteger(prhs[0]);
        if (db_id < 0 || db_id > MaxNumOfDbs)
        {
            mexPrintf(MSG_INVALIDDBHANDLE);
            mexErrMsgTxt(MSG_IMPOSSIBLE);
        }
        db_id --;
        CommandPos ++;
        NumArgs --;
    }

    /*
     * no argument -> fail
     */
    if (NumArgs < 1)
    {
        mexPrintf(MSG_USAGE);
        mexErrMsgTxt(MSG_INVALIDARG);
    }
    
    /*
     * The next (or first if no db number available) is the command,
     * it has to be a string.
     * This fails also, if the first arg is a db-id and there is no 
     * further argument
     */
    if (! mxIsChar(prhs[CommandPos]))
    {
        mexPrintf(MSG_USAGE);
        mexErrMsgTxt(MSG_INVALIDARG);
    }
    
	/*
	 * Get the command string
	 */
    char *command = getstring(prhs[CommandPos]);
    
    /*
     * Adjust the Argument pointer and counter
     */
    int FirstArg = CommandPos +1;
    NumArgs --;
    
    if (! strcmp(command, "open"))
    {
		/*
		 * open a database. There has to be one string argument,
		 * the database filename
		 */
        if (NumArgs != 1 || !mxIsChar(prhs[FirstArg]))
        {
            mexPrintf(MSG_NOOPENARG, mexFunctionName());
			mxFree(command);
            mexErrMsgTxt(MSG_INVALIDARG);
        }
        
		// TODO: possible Memoryleak 'command not freed' when getstring fails
        char* dbname = getstring(prhs[FirstArg]);

		/*
		 * Is there an database ID? The close the database with the same id 
		 */
        if (db_id > 0 && g_dbs[db_id])
        {
            sqlite3_close(g_dbs[db_id]);
            g_dbs[db_id] = 0;
        }

		/*
		 * If there isn't an database id, then try to get one
		 */
        if (db_id < 0)
        {
            for (i = 0; i < MaxNumOfDbs; i++)
            {
                if (g_dbs[i] == 0)
                {
                    db_id = i;
                    break;
                }
            }
        }
		/*
		 * no database id? sorry, database id table full
		 */
        if (db_id < 0)
        {
            plhs[0] = mxCreateDoubleScalar((double) 0);
            mexPrintf(MSG_NOFREESLOT);
			mxFree(command);
        	mxFree(dbname);
            mexErrMsgTxt(MSG_IMPOSSIBLE);
        }
       
		/*
		 * Open the database
		 */
        int rc = sqlite3_open(dbname, &g_dbs[db_id]);
        
        if (rc)
        {
			/*
			 * Anything wrong? free the database id and inform the user
			 */
            mexPrintf(MSG_CANTOPEN, sqlite3_errmsg(g_dbs[db_id]));
            sqlite3_close(g_dbs[db_id]);

            g_dbs[db_id] = 0;
            plhs[0] = mxCreateDoubleScalar((double) 0);
            
			mxFree(command);
	        mxFree(dbname);
            mexErrMsgTxt(MSG_IMPOSSIBLE);
        }
        
        /*
         * Set Default Busytimeout
         */
        rc = sqlite3_busy_timeout(g_dbs[db_id], DEFAULT_BUSYTIMEOUT);
        if (rc)
        {
			/*
			 * Anything wrong? free the database id and inform the user
			 */
            mexPrintf(MSG_CANTOPEN, sqlite3_errmsg(g_dbs[db_id]));
            sqlite3_close(g_dbs[db_id]);

            g_dbs[db_id] = 0;
            plhs[0] = mxCreateDoubleScalar((double) 0);
            
			mxFree(command);
	        mxFree(dbname);
            mexErrMsgTxt(MSG_BUSYTIMEOUTFAIL);
        }
        
		/*
		 * return value will be the used database id
		 */
        plhs[0] = mxCreateDoubleScalar((double) db_id +1);
        mxFree(dbname);
    }
    else if (! strcmp(command, "close"))
    {
		/*
		 * close a database
		 */

        /*
         * There should be no Argument to close
         */
        if (NumArgs > 0)
        {
			mxFree(command);
            mexErrMsgTxt(MSG_INVALIDARG);
        }
        
		/*
		 * if the database id is < 0 than close all open databases
		 */
        if (db_id < 0)
        {
            for (i = 0; i < MaxNumOfDbs; i++)
            {
                if (g_dbs[i])
                {
                    sqlite3_close(g_dbs[i]);
                    g_dbs[i] = 0;
                }
            }
        }
        else
        {
			/*
			 * If the database is open, then close it. Otherwise
			 * inform the user
			 */
            if (! g_dbs[db_id])
            {
				mxFree(command);
                mexErrMsgTxt(MSG_DBNOTOPEN);
            }
            else
            {
                sqlite3_close(g_dbs[db_id]);
                g_dbs[db_id] = 0;
            }
        }
    }
    else if (! strcmp(command, "status"))
    {
        /*
         * There should be no Argument to status
         */
        if (NumArgs > 0)
        {
			mxFree(command);
            mexErrMsgTxt(MSG_INVALIDARG);
        }
        
    	for (i = 0; i < MaxNumOfDbs; i++)
        {
            mexPrintf("DB Handle %d: %s\n", i, g_dbs[i] ? "OPEN" : "CLOSED");
        }
    }
    else if (! _strcmpi(command, "setbusytimeout"))
    {
        /*
         * There should be one Argument, the Timeout in ms
         */
        if (NumArgs != 1 || !mxIsNumeric(prhs[FirstArg]))
        {
			mxFree(command);
            mexErrMsgTxt(MSG_INVALIDARG);
        }

        if (! g_dbs[db_id])
        {
            mxFree(command);
            mexErrMsgTxt(MSG_DBNOTOPEN);
        }
        else
        {
            /*
             * Set Busytimeout
             */
            int TimeoutValue = getinteger(prhs[FirstArg]);
    
            int rc = sqlite3_busy_timeout(g_dbs[db_id], TimeoutValue);
            if (rc)
            {
                /*
                 * Anything wrong? free the database id and inform the user
                 */
                mexPrintf(MSG_CANTOPEN, sqlite3_errmsg(g_dbs[db_id]));
                sqlite3_close(g_dbs[db_id]);

                g_dbs[db_id] = 0;
                plhs[0] = mxCreateDoubleScalar((double) 0);

                mxFree(command);
                mexErrMsgTxt(MSG_BUSYTIMEOUTFAIL);
            }
        }
    }
    else
    {
		/*
		 * database id < 0? Thats an error...
		 */
        if (db_id < 0)
        {
            mexPrintf(MSG_INVALIDDBHANDLE);
			mxFree(command);
            mexErrMsgTxt(MSG_IMPOSSIBLE);
        }
        
		/*
		 * database not open? -> error
		 */
        if (!g_dbs[db_id])
        {
			mxFree(command);
            mexErrMsgTxt(MSG_DBNOTOPEN);
        }
        
		/*
		 * Every unknown command is treated as an sql query string
		 */
		const char* query = command;

        /*
         * a query shuld have no arguments
         */
        if (NumArgs > 0)
        {
			mxFree(command);
            mexErrMsgTxt(MSG_INVALIDARG);
        }
        
		/*
		 * emulate the "show tables" sql query
		 */
        if (! _strcmpi(query, "show tables"))
        {
            query = "SELECT name as tablename FROM sqlite_master "
                    "WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%' "
                    "UNION ALL "
                    "SELECT name as tablename FROM sqlite_temp_master "
                    "WHERE type IN ('table','view') "
                    "ORDER BY 1";
        }

		/*
		 * complete the query
		 */
        if (sqlite3_complete(query))
        {
			mxFree(command);
            mexErrMsgTxt(MSG_INVQUERY);
        }
        
        sqlite3_stmt *st;
        
		/*
		 * and prepare it
		 * if anything is wrong with the query, than complain about it.
		 */
        if (sqlite3_prepare_v2(g_dbs[db_id], query, -1, &st, 0))
        {
            if (st)
                sqlite3_finalize(st);
            
			mxFree(command);
            mexErrMsgIdAndTxt(TransErrToIdent(g_dbs[db_id]), sqlite3_errmsg(g_dbs[db_id]));
        }

		/*
		 * Any results?
		 */
        int ncol = sqlite3_column_count(st);
        if (ncol > 0)
        {
            char **fieldnames = new char *[ncol];   /* Column names */
            Values* allrows = 0;                    /* All query results */
            Values* lastrow = 0;					/* pointer to the last result row */
            int rowcount = 0;						/* number of result rows */
            
			/*
			 * Get the column names of the result set
			 */
            for(i=0; i<ncol; i++)
            {
                const char *cname = sqlite3_column_name(st, i);
                
                fieldnames[i] = new char [strlen(cname) +1];
                strcpy (fieldnames[i], cname);
				/*
				 * replace invalid chars by '_', so we can build
				 * valid MATLAB structs
				 */
                char *mk_c = fieldnames[i];
                while (*mk_c)
                {
                	if ((*mk_c == ' ') || (*mk_c == '*') || (*mk_c == '?'))
                    	*mk_c = '_';
                    mk_c++;
                }
            }
            
            /*
			 * get the result rows from the engine
			 *
			 * We cannot get the number of result lines, so we must
			 * read them in a loop and save them into an temporary list.
			 * Later, we can transfer this List into an MATLAB array of structs.
			 * This way, we must allocate enough memory for two result sets,
			 * but we save time by allocating the MATLAB Array at once.
			 */
            for(;;)
            {
				/*
				 * Advance to teh next row
				 */
                int step_res = sqlite3_step(st);

				/*
				 * no row left? break out of the loop
				 */
                if (step_res != SQLITE_ROW)
                    break;

				/*
				 * get new memory for the result
				 */
                Values* RecordValues = new Values(ncol);
                
                Value *v = RecordValues->m_Values;
                for (int j = 0; j < ncol; j++, v++)
                {
                     int fieldtype = sqlite3_column_type(st,j);

                     v->m_Type = fieldtype;
                     v->m_Size = 0;
                     
                     switch (fieldtype)
                     {
                         case SQLITE_NULL:      v->m_NumericValue = g_NaN;                                   break;
                         case SQLITE_INTEGER:	v->m_NumericValue = (double) sqlite3_column_int(st, j);      break;
                         case SQLITE_FLOAT:     v->m_NumericValue = (double) sqlite3_column_double(st, j);	 break;
                         case SQLITE_TEXT:      v->m_StringValue  = strnewdup((const char*) sqlite3_column_text(st, j));   break;
                         case SQLITE_BLOB:      
                            {
                                v->m_Size = sqlite3_column_bytes(st,j);
                                if (v->m_Size > 0)
                                {
                                    v->m_StringValue = new char[v->m_Size];
                                    memcpy(v->m_StringValue, sqlite3_column_blob(st,j), v->m_Size);
                                }
                                else
                                {
                                    v->m_Size = 0;
                                }
                            }
                            break;
                         default:	
							mxFree(command);
							mexErrMsgTxt(MSG_UNKNWNDBTYPE);
                     }
                }
				/*
				 * and add this row to the list of all result rows
				 */
                if (! lastrow)
                {
                    allrows = lastrow = RecordValues;
                }
                else
                {
                    lastrow->m_NextValues = RecordValues;
                    lastrow = lastrow->m_NextValues;
                }
				/*
				 * we have one more...
				 */
                rowcount ++;
            }
            
			/*
			 * end the sql engine
			 */
            sqlite3_finalize(st);

			/*
			 * got nothing? return an empty result to MATLAB
			 */
            if (rowcount == 0 || ! allrows)
            {
                if (!( plhs[0] = mxCreateDoubleMatrix(0,0,mxREAL) ))
				{
					mxFree(command);
                    mexErrMsgTxt(MSG_CANTCREATEOUTPUT);
				}
            }
            else
            {
				/*
				 * Allocate an array of MATLAB structs to return as result
				 */
                int ndims[2];
                
                ndims[0] = rowcount;
                ndims[1] = 1;
                
                if (( plhs[0] = mxCreateStructArray (2, ndims, ncol, (const char**)fieldnames)) == 0)
                {
					mxFree(command);
                    mexErrMsgTxt(MSG_CANTCREATEOUTPUT);
                }
                
				/*
				 * transfer the result rows from the temporary list into the result array
				 */
                lastrow = allrows;
                i = 0;
                while(lastrow)
                {
                    Value* recordvalue = lastrow->m_Values;
                    
                    for (int j = 0; j < ncol; j++, recordvalue++)
                    {
                        if (recordvalue -> m_Type == SQLITE_TEXT)
                        {
                            mxArray* c = mxCreateString(recordvalue->m_StringValue);
                            mxSetFieldByNumber(plhs[0], i, j, c);
                        }
                        else if (recordvalue -> m_Type == SQLITE_NULL && !NULLasNaN)
                        {
                            mxArray* out_double = mxCreateDoubleMatrix(0,0,mxREAL);
                            mxSetFieldByNumber(plhs[0], i, j, out_double);
                        }
                        else if (recordvalue -> m_Type == SQLITE_BLOB)
                        {
                            if (recordvalue->m_Size > 0)
                            {
                                int BytePos;
                                int NumDims[2]={1,1};
                                NumDims[1]=recordvalue->m_Size;
                                mxArray*out_uchar8=mxCreateNumericArray(2, NumDims, mxUINT8_CLASS, mxREAL);
                                unsigned char *v = (unsigned char *) mxGetData(out_uchar8);
                                
                                memcpy(v, recordvalue->m_StringValue, recordvalue->m_Size);
                                    
                                mxSetFieldByNumber(plhs[0], i, j, out_uchar8);
                            }
                            else
                            {
                                // empty BLOB
                                mxArray* out_double = mxCreateDoubleMatrix(0,0,mxREAL);
                                mxSetFieldByNumber(plhs[0], i, j, out_double);
                            }
                        }
                        else
                        {
                            mxArray* out_double = mxCreateDoubleScalar(recordvalue->m_NumericValue);
                            mxSetFieldByNumber(plhs[0], i, j, out_double);
                        }
                    }
                    allrows = lastrow;
                    lastrow = lastrow->m_NextValues;
                    delete allrows;
                    i++;
                }
            }
            for(int i=0; i<ncol; i++)
                delete [] fieldnames[i];
            delete [] fieldnames;
        }
        else
        {
			/*
			 * no result, cleanup the sqlite engine
			 */
            int res = sqlite3_step(st);
            sqlite3_finalize(st);

			if (!( plhs[0] = mxCreateDoubleMatrix(0, 0, mxREAL) )) 
			{
                mexErrMsgTxt(MSG_CANTCREATEOUTPUT);
            }

            if (res != SQLITE_DONE)
            {
				mxFree(command);
                mexErrMsgIdAndTxt(TransErrToIdent(g_dbs[db_id]), sqlite3_errmsg(g_dbs[db_id]));
            }            
        }
    }
	mxFree(command);
}
Ejemplo n.º 23
0
mxArray *get_polarity(Miscellaneous *miscell, PMap *predMap, Node *phi)
{
    /* Peer reviewed on 2013.07.22 by Dokhanchi, Adel */
    const char *fields[] = {"polarity", "index"};
    mxArray *tmp, *Array;
	/*mwSize *dims;*/
    mwSize dims;
	double *pr;
	int temp_pol = 0;
	Polarity *p;
	int i = 0,ii;
	int iii=0;								/* used for check the index for subformula*/
	int jjj=0;								/* length-1 of the subformula array */
	int *qi;
	int temp = 1;
#define subMax 200							/*	biggest number of iterations the subformula could store*/
	Node *subformula[subMax];				/* subformula array as a cross-reference for the phi*/

	/* Initialize some variables for BFS */
	queue q;
	queue *Q = &q;
	init_queue(Q);							/*initial the queue*/
	qi = &temp;
	/*----------------------------------*/

	p = (Polarity *)emalloc(sizeof(Polarity));
	p->polar = UNDEFINED_POLAR;
	tmp = mxCreateStructMatrix(1, 1, 2, fields);

	/*-----BFS for formula--------------*/
	jjj = BreadthFirstTraversal(Q,phi,subformula,qi);
		for(iii=1; iii<jjj; iii++)			/*	check the index for subformula*/
		{
			if(iii != subformula[iii]->index)
				mexErrMsgTxt("mx_dp_taliro: subformula not in right index!");
		}


	make_predicate_list(miscell, p);

/* predicate list*/
	pr = mxCalloc(miscell->dp_taliro_param.nPred, sizeof(double));
	/*dims = &(miscell->dp_taliro_param.nPred);*/
    dims = (mwSize)(miscell->dp_taliro_param.nPred);
	Array = mxCreateDoubleMatrix (1, dims, mxREAL);
	for(i = 0;i<miscell->dp_taliro_param.nPred;i++)
	{
		pr[i] = miscell->pList.pindex[i];
		if(pr[i] == -1)
		{
			pr[i] = 0;
		}
	}
	mxSetPr(Array,pr);
/* predicate list ends*/
	/* polarity calculation*/
	i = jjj;
	while(i>0)
	{
		switch (subformula[i]->ntyp)
		{
			case TRUE:
				subformula[i]->pol = UNDEFINED_POLAR;
				break;	
			case FALSE:
				subformula[i]->pol = UNDEFINED_POLAR;
				break;	
			case VALUE:
				subformula[i]->pol = UNDEFINED_POLAR;
				break;	
			case PREDICATE:
              		/* match predicate index*/
        		for(ii = 0; ii < miscell->dp_taliro_param.nPred; ii++)
                {
                    if(miscell->predMap[ii].str != NULL)
                    {
                        if(strcmp(subformula[i]->sym->name,predMap[ii].str)==0)
                        {
                            if(predMap[ii].parameter!=NULL){
                                subformula[i]->pol = POSITIVE_POLAR;   
                            }
                            else{
                   				subformula[i]->pol = UNDEFINED_POLAR;
                           }
                    	}
                    }
                }
				break;
			case NOT:
				subformula[i]->pol = flip(subformula[i]->lft->pol);
				/*p->polar = flip(p->polar);*/
				break;
			case AND:
				subformula[i]->pol = mix(subformula[i]->lft->pol, subformula[i]->rgt->pol);
				break;
			case OR:
				subformula[i]->pol = mix(subformula[i]->lft->pol, subformula[i]->rgt->pol);
				break;
			case NEXT:
				subformula[i]->pol = subformula[i]->lft->pol;
				break;
			case WEAKNEXT:
				subformula[i]->pol = subformula[i]->lft->pol;
				break;
			case ALWAYS:
				if(subformula[i]->time.l_par == 1 && subformula[i]->time.u_par == 0)
				{
					subformula[i]->pol = pos(subformula[i]->rgt->pol);
				}
				else if(subformula[i]->time.l_par == 0 && subformula[i]->time.u_par == 1)
				{
					subformula[i]->pol = neg(subformula[i]->rgt->pol);
				}
				else if(subformula[i]->time.l_par == 1 && subformula[i]->time.u_par == 1)
				{
					subformula[i]->pol = MIXED_POLAR;
				}
				else
				{
					subformula[i]->pol = subformula[i]->rgt->pol;
				}
				break;
			case EVENTUALLY:
				if(subformula[i]->time.l_par == 1 && subformula[i]->time.u_par == 0)
				{
					subformula[i]->pol = neg(subformula[i]->rgt->pol);
				}
				else if(subformula[i]->time.l_par == 0 && subformula[i]->time.u_par == 1)
				{
					subformula[i]->pol = pos(subformula[i]->rgt->pol);
				}
				else if(subformula[i]->time.l_par == 1 && subformula[i]->time.u_par == 1)
				{
					subformula[i]->pol = MIXED_POLAR;
				}
				else
				{
					subformula[i]->pol = subformula[i]->rgt->pol;
				}
				break;
			case U_OPER:
				if(subformula[i]->time.l_par == 1 && subformula[i]->time.u_par == 0)
				{
					temp_pol = NEGATIVE_POLAR;
					subformula[i]->pol = mix(temp_pol,mix(subformula[i]->lft->pol,subformula[i]->rgt->pol));
				}
				else if(subformula[i]->time.l_par == 0 && subformula[i]->time.u_par == 1)
				{
					temp_pol = POSITIVE_POLAR;
					subformula[i]->pol = mix(temp_pol,mix(subformula[i]->lft->pol,subformula[i]->rgt->pol));
				}
				else if(subformula[i]->time.l_par == 1 && subformula[i]->time.u_par == 1)
				{
					subformula[i]->pol = MIXED_POLAR;
				}
				else
				{
					subformula[i]->pol = mix(subformula[i]->lft->pol,subformula[i]->rgt->pol);
				}
				break;
			case V_OPER:
				if(subformula[i]->time.l_par == 1 && subformula[i]->time.u_par == 0)
				{
/* 					temp_pol = POSITIVE_POLAR;
 					subformula[i]->pol = mix(temp_pol,mix(subformula[i]->lft->pol,subformula[i]->rgt->pol));*/
					temp_pol = NEGATIVE_POLAR;
					subformula[i]->pol = flip(mix(temp_pol,mix(flip(subformula[i]->lft->pol),flip(subformula[i]->rgt->pol))));
				}
				else if(subformula[i]->time.l_par == 0 && subformula[i]->time.u_par == 1)
				{
/* 					temp_pol = NEGATIVE_POLAR;
 					subformula[i]->pol = mix(temp_pol,mix(subformula[i]->lft->pol,subformula[i]->rgt->pol));*/
					temp_pol = POSITIVE_POLAR;
					subformula[i]->pol = flip(mix(temp_pol,mix(flip(subformula[i]->lft->pol),flip(subformula[i]->rgt->pol))));
				}
				else if(subformula[i]->time.l_par == 1 && subformula[i]->time.u_par == 1)
				{
					subformula[i]->pol = MIXED_POLAR;
				}
				else
				{
					subformula[i]->pol = mix(subformula[i]->lft->pol,subformula[i]->rgt->pol);
				}
				break;
			default:
				break;
		}
	i--;
	}
	/* polarity calculation ends*/


	mxSetField(tmp, 0, "polarity", mxCreateDoubleScalar(subformula[1]->pol));
	mxSetField(tmp, 0, "index", Array);

	return (tmp);
}
Ejemplo n.º 24
0
/* 
 * [type,num_constraint,constraint_val,dconstraint_val,constraint_name,lower_bound,upper_bound] = testSingleTimeKinCnstmex(kinCnst_ptr,q,t)
 * @param kinCnst_ptr           A pointer to a SingleTimeKinematicConstraint object
 * @param q                     A nqx1 double vector
 * @param t                     A double scalar, the time to evaluate constraint value, bounds and name. This is optional.
 * @retval type                 The type of the constraint
 * @retval num_constraint       The number of constraint active at time t
 * @retval constraint_val       The value of the constraint at time t
 * @retval dconstraint_val      The gradient of the constraint w.r.t q at time t
 * @retval constraint_name      The name of the constraint at time t
 * @retval lower_bound          The lower bound of the constraint at time t
 * @retval upper_bound          The upper bound of the constraint at time t
 * */
void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
{
  if((nrhs!=3 && nrhs != 2)||nlhs != 7)
  {
    mexErrMsgIdAndTxt("Drake:testSingleTimeKinCnstmex:BadInputs","Usage [type, num_cnst,cnst_val,dcnst_val,cnst_name,lb,ub] = testSingleTimeKinKinCnstmex(kinCnst,q,t)");
  }
  SingleTimeKinematicConstraint* cnst = (SingleTimeKinematicConstraint*) getDrakeMexPointer(prhs[0]);
  double* t_ptr;
  if(nrhs == 2)
  {
    t_ptr = nullptr;
  }
  else
  {
    int num_t = mxGetNumberOfElements(prhs[2]);
    if(num_t == 0)
    {
      t_ptr = nullptr;
    }
    if(num_t == 1)
    {
      t_ptr = mxGetPrSafe(prhs[2]);
    }
    if(num_t>1)
    {
      mexErrMsgIdAndTxt("Drake:testSingleTimeKinCnstmex:BadInputs","t must be either empty or a single number");
    }
  }
  int type = cnst->getType();
  int num_cnst = cnst->getNumConstraint(t_ptr);
  //mexPrintf("num_cnst = %d\n",num_cnst);
  int nq = cnst->getRobotPointer()->num_positions;
  Map<VectorXd> q(mxGetPrSafe(prhs[1]), nq);
  VectorXd v = VectorXd::Zero(0);
  cnst->getRobotPointer()->doKinematics(q, v);
  VectorXd c(num_cnst);
  MatrixXd dc(num_cnst,nq);
  cnst->eval(t_ptr,c,dc);
  //mexPrintf("get c,dc\n");
  VectorXd lb(num_cnst);
  VectorXd ub(num_cnst);
  cnst->bounds(t_ptr,lb,ub);
  //mexPrintf("get lb, ub\n");
  std::vector<std::string> cnst_names;
  cnst->name(t_ptr,cnst_names);
  //mexPrintf("get name\n");
  int retvec_size;
  if(num_cnst == 0)
  {
    retvec_size = 0;
  }
  else
  {
    retvec_size = 1;
  }
  plhs[0] = mxCreateDoubleScalar((double) type);
  plhs[1] = mxCreateDoubleScalar((double) num_cnst);
  plhs[2] = mxCreateDoubleMatrix(num_cnst,retvec_size,mxREAL);
  memcpy(mxGetPrSafe(plhs[2]),c.data(),sizeof(double)*num_cnst);
  plhs[3] = mxCreateDoubleMatrix(num_cnst,nq,mxREAL);
  memcpy(mxGetPrSafe(plhs[3]),dc.data(),sizeof(double)*num_cnst*nq);
  int name_ndim = 1;
  mwSize name_dims[] = {(mwSize) num_cnst};
  plhs[4] = mxCreateCellArray(name_ndim,name_dims);
  mxArray *name_ptr;
  for(int i = 0;i<num_cnst;i++)
  {
    name_ptr = mxCreateString(cnst_names[i].c_str());
    mxSetCell(plhs[4],i,name_ptr);
  }
  plhs[5] = mxCreateDoubleMatrix(num_cnst,retvec_size,mxREAL);
  plhs[6] = mxCreateDoubleMatrix(num_cnst,retvec_size,mxREAL);
  memcpy(mxGetPrSafe(plhs[5]),lb.data(),sizeof(double)*num_cnst);
  memcpy(mxGetPrSafe(plhs[6]),ub.data(),sizeof(double)*num_cnst);
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
	if (nrhs < 9)
	{
		mexErrMsgTxt("The number of arguments should be nine.\n");
	}
	double *C1, *C2;
	double w = 0;
	C1 = mxGetPr(prhs[0]);
	C2 = mxGetPr(prhs[1]);
	/* dimensions of input matrices */
	integer d, n, rotated, isclosed, onlyDP, skipm, autoselectC;
	n = mxGetM(prhs[0]);
	d = mxGetN(prhs[0]);

	std::cout << "(n, d):" << n << "," << d << std::endl;

	if (mxGetM(prhs[1]) != n || mxGetN(prhs[1]) != d)
	{
		mexErrMsgTxt("The size of matrix C2 does not match the size of C1.\n");
	}
	w = mxGetScalar(prhs[2]);
	rotated = static_cast<integer> (mxGetScalar(prhs[3]));
	isclosed = static_cast<integer> (mxGetScalar(prhs[4]));
	onlyDP = static_cast<integer> (mxGetScalar(prhs[5]));
	skipm = static_cast<integer> (mxGetScalar(prhs[6]));
	char methodname[30] = "";
	mxGetString(prhs[7], methodname, 30);
	autoselectC = static_cast<integer> (mxGetScalar(prhs[8]));

	init_genrand(0);

	CheckMemoryDeleted = new std::map<integer *, integer>;

	integer numofmanis = 3;
	integer numofmani1 = 1;
	integer numofmani2 = 1;
	integer numofmani3 = 1;
	L2SphereVariable FNSV(n);
	OrthGroupVariable OGV(d);
	EucVariable EucV(1);
	ProductElement *Xopt = new ProductElement(numofmanis, &FNSV, numofmani1, &OGV, numofmani2, &EucV, numofmani3);

    bool swap;
	plhs[2] = mxCreateDoubleMatrix(5, 1, mxREAL);
	plhs[3] = mxCreateDoubleMatrix(5, 1, mxREAL);
	double *fopts = mxGetPr(plhs[2]), *comtime = mxGetPr(plhs[3]);
	integer ns, lms;

	DriverElasticCurvesRO(C1, C2, d, n, w, rotated != 0, isclosed != 0, onlyDP != 0, skipm, methodname,
		autoselectC, Xopt, swap, fopts, comtime, ns, lms);

	/*create output matrix*/
	integer sizex = n + d * d + 1;
	plhs[0] = mxCreateDoubleMatrix(sizex, 1, mxREAL);
	double *opt = mxGetPr(plhs[0]);
	plhs[1] = mxCreateDoubleScalar(static_cast<double> (swap));
	plhs[4] = mxCreateDoubleScalar(static_cast<double> (ns));
	plhs[5] = mxCreateDoubleScalar(static_cast<double> (lms));

	const double *Xoptptr = Xopt->ObtainReadData();
	integer inc = 1;
	dcopy_(&sizex, const_cast<double *> (Xoptptr), &inc, opt, &inc);

	delete Xopt;
	
	std::map<integer *, integer>::iterator iter = CheckMemoryDeleted->begin();
	for (iter = CheckMemoryDeleted->begin(); iter != CheckMemoryDeleted->end(); iter++)
	{
		if (iter->second != 1)
			std::cout << "Global address:" << iter->first << ", sharedtimes:" << iter->second << std::endl;
	}
	delete CheckMemoryDeleted;
	return;
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{

#define B_OUT plhs[0]

#define X_IN prhs[0]
#define Y_IN prhs[1]
#define Kmax_IN prhs[2]
#define D_IN prhs[3]

int N,p,q;
int i,j;

//mexPrintf("n par %d\n",nrhs);

N = mxGetN(X_IN);
p = mxGetM(X_IN);
q = mxGetM(Y_IN);

double *x_single = mxGetPr(X_IN);
double *y_single = mxGetPr(Y_IN);

// compute the x and y to send in input
double** x = new double*[p];
double** y = new double*[q];

for(j=0;j<p;j++){
	x[j] = new double[N];
	for(i=0;i<N;i++)
		x[j][i] = x_single[j + p*i];
}
for(j=0;j<q;j++){
	y[j] = new double[N];
	for(i=0;i<N;i++)
		y[j][i] = y_single[j + q*i];
}

int Kmax = mxGetScalar(Kmax_IN);
int D = mxGetScalar(D_IN);

/*
mexPrintf("N %d\n",N);
mexPrintf("X[0] %f\n",*X);
mexPrintf("Y[0] %f\n",*Y);

mexPrintf("Kmax %d\n",Kmax);

mexPrintf("D %d",D);

*/

double res = RICrndFerns(x,y,N,p,q,Kmax,D);

B_OUT = mxCreateDoubleScalar(res);

for(j=0;j<p;j++)
	delete[] x[j];
delete[] x;
for(j=0;j<q;j++)
	delete[] y[j];
delete[] y;

return;

}
Ejemplo n.º 27
0
mxArray *sf_c7_ekffede_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateDoubleMatrix(4,1,mxREAL);
    double *pr = mxGetPr(mxChecksum);
    pr[0] = (double)(869705337U);
    pr[1] = (double)(4037793131U);
    pr[2] = (double)(919190404U);
    pr[3] = (double)(3945250788U);
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,5,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,2,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,2,"type",mxType);
    }

    mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,3,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,3,"type",mxType);
    }

    mxSetField(mxData,3,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,4,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,4,"type",mxType);
    }

    mxSetField(mxData,4,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  return(mxAutoinheritanceInfo);
}
Ejemplo n.º 28
0
mxArray *sf_c45_Expriment_Gaze_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateString("PBOOE2ONCJlr45MWsYJj7G");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,6,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,2,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,2,"type",mxType);
    }

    mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,3,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,3,"type",mxType);
    }

    mxSetField(mxData,3,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,4,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,4,"type",mxType);
    }

    mxSetField(mxData,4,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,5,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,5,"type",mxType);
    }

    mxSetField(mxData,5,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(6);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  return(mxAutoinheritanceInfo);
}
Ejemplo n.º 29
0
mxArray *sf_c3_controller1_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,4,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateDoubleMatrix(4,1,mxREAL);
    double *pr = mxGetPr(mxChecksum);
    pr[0] = (double)(3719275678U);
    pr[1] = (double)(4192044686U);
    pr[2] = (double)(4111541287U);
    pr[3] = (double)(4053187991U);
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  return(mxAutoinheritanceInfo);
}
Ejemplo n.º 30
0
mxArray *sf_c1_Qmod_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateString("Rk3PHQL8hwPgv0HChPhxjG");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,5,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(4);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,2,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,2,"type",mxType);
    }

    mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,3,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,3,"type",mxType);
    }

    mxSetField(mxData,3,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(3);
      pr[1] = (double)(3);
      mxSetField(mxData,4,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,4,"type",mxType);
    }

    mxSetField(mxData,4,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxCreateDoubleMatrix(0,0,
                mxREAL));
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(3);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  return(mxAutoinheritanceInfo);
}