Changeset 22671


Ignore:
Timestamp:
04/04/18 08:04:37 (7 years ago)
Author:
Mathieu Morlighem
Message:

CHG: revising Chaco's interface to integrate python

Location:
issm/trunk-jpl/src/wrappers
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/wrappers/Chaco/Chaco.cpp

    r20877 r22671  
    2323        /*Inputs: */
    2424        int     nvtxs;               /* number of vertices in graph           */
    25         int    *start;               /* start of edge list for each vertex    */
    26         int    *adjacency;           /* edge list data                        */
     25        int    *start = NULL;        /* start of edge list for each vertex    */
     26        int    *adjacency = NULL;    /* edge list data                        */
    2727        int    *vwgts       = NULL;  /* weights for all vertices              */
    28         int     nedges;
    2928        float  *ewgts       = NULL;  /* weights for all edges                 */
    3029        float  *x           = NULL;
    3130        float  *y           = NULL;
    3231        float  *z           = NULL;  /* coordinates for inertial method       */
    33         double  options[10] = {1,1,0,0,1,1,50,0,.001,7654321}; /* architecture and partitioning options */
     32        double  options[10] = {1,1,0,0,1,1,50,0,0.001,7654321}; /* architecture and partitioning options */
    3433        double *in_options  = NULL;
    35         int    *nparts      = NULL;   /* number of parts options               */
    3634        int     npart;
    3735        double *goal        = NULL;   /* desired set sizes                     */
    38 
    39         /*intermediary pointers: */
    40         mwIndex *mwstart, *mwadjacency;
    41         double  *doublepointer;
    42 
    43         /*output: */
    44    short  *assignment       = NULL; /* set number of each vtx (length nvtxs+1)                */
    45    double *doubleassignment = NULL; /*holds assignment, in double format, to return to matlab */
    4636
    4737        #ifndef _HAVE_CHACO_ //only works if dakota library has been compiled in.
     
    5343
    5444        /*checks on arguments on the matlab side: */
    55         CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&ChacoUsage);
     45        CHECKARGUMENTS(NLHS,NRHS,&ChacoUsage);
    5646
    57         /*Fetch adjacency matrix: */
    58         nvtxs = mxGetN(A_IN);
    59         mwstart = mxGetJc(A_IN);
    60         start=xNew<int>((nvtxs+1));
    61         for (i=0; i<nvtxs+1;i++)start[i]=(int)mwstart[i];
    62 
    63         mwadjacency = mxGetIr(A_IN);
    64         adjacency = xNew<int>(mxGetNzmax(A_IN));
    65         for (i=0; i<mxGetNzmax(A_IN); i++) adjacency[i]= (int)mwadjacency[i];
    66 
    67         nedges = start[nvtxs];
    68         if(!mxIsEmpty(EWGTS_IN)){
    69                 ewgts = xNewZeroInit<float>(nedges);
    70                 doublepointer=mxGetPr(A_IN);
    71                 for (i = 0; i < nedges; i++)ewgts[i] = (float)doublepointer[i];
    72         }
    73         else ewgts=NULL;
    74 
    75         /*Fetch rest of data: */
     47        /*Fetch Data*/
     48        FetchChacoData(&nvtxs,&adjacency,&start,&ewgts,A_IN,EWGTS_IN);
    7649        FetchData(&vwgts,&nterms,VWGTS_IN);
    7750        FetchData(&x,&nterms,X_IN);
     
    8154        for (i=0;i<(nterms<10?nterms:10);i++) options[i]=in_options[i]; //copy in_options into default options
    8255        FetchData(&npart,NPARTS_IN);
    83         nparts=xNew<int>(1); nparts[0]=npart; //weird Chacox interface ain't it?
     56        //int * nparts=xNew<int>(1); nparts[0]=npart; //weird Chacox interface ain't it?
    8457        FetchData(&goal,&nterms,GOAL_IN);
    8558
    86         /*Some debugging print: {{{*/
    87         #ifdef _DEBUG_
    88         _printf_("nvtxs: " << nvtxs << "\n");
    89         _printf_("options: [");
    90         for(i=0;i<10;i++)_printf_(options[i] << "|");
    91         _printf_("]\n");
    92         _printf_("start: \n");
    93         for (i=0; i<nvtxs+1;i++)_printf_(start[i] << " ");
    94         _printf_("\n");
    95         _printf_("adjacency: \n");
    96         for (i=0; i<mxGetNzmax(A_IN);i++)_printf_("" <<adjacency[i]<< " ");i++)
    97         _printf_("\n");
    98         _printf_("nedges: " << nedges << " " << ewgts << "\n");
    99         if(ewgts) for (i = 0; i < nedges; i++)_printf_(ewgts[i] << " ");
    100         _printf_("\n");
    101         _printf_("vwgts:\n");
    102         for (i = 0; i < nvtxs; i++)_printf_(vwgts[i] << " ");
    103         _printf_("\n");
    104         _printf_("nparts: " << nparts[0] << "\n");
    105         _printf_("goal: " << goal << "\n");
    106         #endif
    107         /*}}}*/
    108 
    10959        /*Allocate output: */
    110         assignment = xNewZeroInit<short>(nvtxs);
     60        short* assignment = xNewZeroInit<short>(nvtxs);
    11161
    11262    /*Call core: */
    113         Chacox(nvtxs, start, adjacency, vwgts, ewgts, x, y, z, assignment, options, nparts, goal);
     63        Chacox(nvtxs, start, adjacency, vwgts, ewgts, x, y, z, assignment, options,&npart, goal);
    11464
    11565    /*Output data: */
    116         doubleassignment=xNew<double>(nvtxs);
    117         for(i=0;i<nvtxs;i++) doubleassignment[i]=(double)assignment[i];
    118         WriteData(ASSGN_OUT,doubleassignment,nvtxs);
     66        WriteData(ASSGN_OUT,assignment,nvtxs);
    11967
    12068        /*Free ressources:*/
    12169        xDelete<short>(assignment);
    12270        xDelete<double>(goal);
    123         xDelete<int>(nparts);
     71        //xDelete<int>(nparts);
    12472        xDelete<float>(z);
    12573        xDelete<float>(y);
     
    12977        xDelete<int>(adjacency);
    13078        xDelete<int>(start);
    131         xDelete<double>(doubleassignment);
    13279
    13380        /*end module: */
  • issm/trunk-jpl/src/wrappers/matlab/io/FetchMatlabData.cpp

    r22367 r22671  
    642642}
    643643/*}}}*/
     644void FetchChacoData(int* pnvtxs,int** padjacency,int** pstart,float** pewgts,const mxArray* A_IN, const mxArray* EWGTS_IN){/*{{{*/
     645
     646        /*Fetch adjacency matrix: */
     647        int      nvtxs       = mxGetN(A_IN);
     648        mwIndex* mwstart     = mxGetJc(A_IN);
     649        mwIndex* mwadjacency = mxGetIr(A_IN);
     650        int      nzmax       = mxGetNzmax(A_IN);
     651
     652        int* start = xNew<int>(nvtxs+1);
     653        for(int i=0;i<nvtxs+1;i++) start[i]=(int)mwstart[i];
     654
     655        int* adjacency = xNew<int>(nzmax);
     656        for(int i=0; i<nzmax; i++) adjacency[i]= (int)mwadjacency[i];
     657
     658        /*Get edges weights*/
     659        int nedges = start[nvtxs];
     660        float* ewgts = NULL;
     661        if(!mxIsEmpty(EWGTS_IN)){
     662                ewgts = xNewZeroInit<float>(nedges);
     663                double* doublepointer = mxGetPr(A_IN);
     664                for(int i = 0; i<nedges;i++) ewgts[i] = (float)doublepointer[i];
     665        }
     666
     667        /*Assign output pointers*/
     668        *pnvtxs     = nvtxs;
     669        *padjacency = adjacency;
     670        *pstart     = start;
     671        *pewgts     = ewgts;
     672}
     673/*}}}*/
    644674
    645675/*Toolkit*/
  • issm/trunk-jpl/src/wrappers/matlab/io/WriteMatlabData.cpp

    r21624 r22671  
    8888/*FUNCTION WriteData(mxArray** pdataref,int* vector, int M){{{*/
    8989void WriteData(mxArray** pdataref,int* vector, int M){
     90
     91        mxArray* dataref       = NULL;
     92        double*  vector_matlab = NULL;
     93
     94        if(vector){
     95
     96                /*create the matlab vector with Matlab's memory manager */
     97                vector_matlab=(double*)mxMalloc(M*sizeof(double));
     98                for(int i=0;i<M;i++) vector_matlab[i]=double(vector[i]);
     99                dataref = mxCreateDoubleMatrix(0,0,mxREAL);
     100                mxSetM(dataref,(mwSize)M);
     101                mxSetN(dataref,(mwSize)1);
     102                mxSetPr(dataref,vector_matlab);
     103        }
     104        else{
     105                dataref = mxCreateDoubleMatrix(0,0,mxREAL);
     106        }
     107
     108        *pdataref=dataref;
     109}
     110/*}}}*/
     111/*FUNCTION WriteData(mxArray** pdataref,short* vector, int M){{{*/
     112void WriteData(mxArray** pdataref,short* vector, int M){
    90113
    91114        mxArray* dataref       = NULL;
  • issm/trunk-jpl/src/wrappers/matlab/io/matlabio.h

    r22076 r22671  
    2323void WriteData(mxArray** pdataref,IssmSeqVec<double>* vector);
    2424void WriteData(mxArray** pdataref,double* vector, int M);
     25void WriteData(mxArray** pdataref,short* vector, int M);
    2526void WriteData(mxArray** pdataref,int* vector, int M);
    2627void WriteData(mxArray** pdataref,int integer);
     
    5354void FetchData(Options** poptions,int istart, int nrhs,const mxArray** pdataref);
    5455void FetchData(Contours** pcontours,const mxArray* dataref);
     56void FetchChacoData(int* pnvtxs,int** padjacency,int** pstart,float** pewgts,const mxArray* A_IN, const mxArray* EWGTS_IN);
    5557
    5658Option* OptionParse(char* name, const mxArray* prhs[]);
Note: See TracChangeset for help on using the changeset viewer.