Changeset 22671
- Timestamp:
- 04/04/18 08:04:37 (7 years ago)
- Location:
- issm/trunk-jpl/src/wrappers
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/wrappers/Chaco/Chaco.cpp
r20877 r22671 23 23 /*Inputs: */ 24 24 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 */ 27 27 int *vwgts = NULL; /* weights for all vertices */ 28 int nedges;29 28 float *ewgts = NULL; /* weights for all edges */ 30 29 float *x = NULL; 31 30 float *y = NULL; 32 31 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 */ 34 33 double *in_options = NULL; 35 int *nparts = NULL; /* number of parts options */36 34 int npart; 37 35 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 */46 36 47 37 #ifndef _HAVE_CHACO_ //only works if dakota library has been compiled in. … … 53 43 54 44 /*checks on arguments on the matlab side: */ 55 C heckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&ChacoUsage);45 CHECKARGUMENTS(NLHS,NRHS,&ChacoUsage); 56 46 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); 76 49 FetchData(&vwgts,&nterms,VWGTS_IN); 77 50 FetchData(&x,&nterms,X_IN); … … 81 54 for (i=0;i<(nterms<10?nterms:10);i++) options[i]=in_options[i]; //copy in_options into default options 82 55 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? 84 57 FetchData(&goal,&nterms,GOAL_IN); 85 58 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 #endif107 /*}}}*/108 109 59 /*Allocate output: */ 110 assignment = xNewZeroInit<short>(nvtxs);60 short* assignment = xNewZeroInit<short>(nvtxs); 111 61 112 62 /*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); 114 64 115 65 /*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); 119 67 120 68 /*Free ressources:*/ 121 69 xDelete<short>(assignment); 122 70 xDelete<double>(goal); 123 xDelete<int>(nparts);71 //xDelete<int>(nparts); 124 72 xDelete<float>(z); 125 73 xDelete<float>(y); … … 129 77 xDelete<int>(adjacency); 130 78 xDelete<int>(start); 131 xDelete<double>(doubleassignment);132 79 133 80 /*end module: */ -
issm/trunk-jpl/src/wrappers/matlab/io/FetchMatlabData.cpp
r22367 r22671 642 642 } 643 643 /*}}}*/ 644 void 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 /*}}}*/ 644 674 645 675 /*Toolkit*/ -
issm/trunk-jpl/src/wrappers/matlab/io/WriteMatlabData.cpp
r21624 r22671 88 88 /*FUNCTION WriteData(mxArray** pdataref,int* vector, int M){{{*/ 89 89 void 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){{{*/ 112 void WriteData(mxArray** pdataref,short* vector, int M){ 90 113 91 114 mxArray* dataref = NULL; -
issm/trunk-jpl/src/wrappers/matlab/io/matlabio.h
r22076 r22671 23 23 void WriteData(mxArray** pdataref,IssmSeqVec<double>* vector); 24 24 void WriteData(mxArray** pdataref,double* vector, int M); 25 void WriteData(mxArray** pdataref,short* vector, int M); 25 26 void WriteData(mxArray** pdataref,int* vector, int M); 26 27 void WriteData(mxArray** pdataref,int integer); … … 53 54 void FetchData(Options** poptions,int istart, int nrhs,const mxArray** pdataref); 54 55 void FetchData(Contours** pcontours,const mxArray* dataref); 56 void FetchChacoData(int* pnvtxs,int** padjacency,int** pstart,float** pewgts,const mxArray* A_IN, const mxArray* EWGTS_IN); 55 57 56 58 Option* OptionParse(char* name, const mxArray* prhs[]);
Note:
See TracChangeset
for help on using the changeset viewer.