44 #define Long SuiteSparse_long 49 #define MIN(a,b) (((a) < (b)) ? (a) : (b)) 50 #define MAX(a,b) (((a) > (b)) ? (a) : (b)) 51 #define CCOLAMD_MIN_MEMORY(nnz,n_row,n_col) \ 52 (MAX (2 * nnz, 4 * n_col) + \ 53 8*n_col + 6*n_row + n_col + (nnz / 5) \ 54 + ((3 * n_col) + 1) + 5 * (n_col + 1) + n_row) 72 mexPrintf (
"dump matrix: nrow %d ncol %d Alen %d\n", n_row, n_col, Alen) ;
74 for (col = 0 ; col <
MIN (n_col, limit) ; col++)
76 mexPrintf (
"column %d, p[col] %d, p [col+1] %d, length %d\n",
77 col, p [col], p [col+1], p [col+1] - p [col]) ;
78 for (k = p [col] ; k < p [col+1] ; k++)
81 mexPrintf (
" %d", row) ;
98 const mxArray *pargin [ ]
125 if (nargin != 3 || nargout < 0 || nargout > 2)
128 "ccolamdtest: incorrect number of input and/or output arguments") ;
131 if (mxGetNumberOfElements (pargin [1]) != 7)
133 mexErrMsgTxt (
"ccolamdtest: must have all 7 knobs for testing") ;
141 in_knobs = mxGetPr (pargin [1]) ;
146 spumoni = (in_knobs [4] != 0) ;
151 mexPrintf (
"\nccolamd version %d.%d, %s:\nknobs(1): %g, order for %s\n",
154 (knobs [
CCOLAMD_LU] != 0) ?
"lu(A)" :
"chol(A'*A)") ;
157 mexPrintf (
"knobs(2): %g, rows with > max(16,%g*sqrt(size(A,2)))" 162 mexPrintf (
"knobs(2): %g, no dense rows removed\n", in_knobs [1]) ;
166 mexPrintf (
"knobs(3): %g, cols with > max(16,%g*sqrt(min(size(A)))" 171 mexPrintf (
"knobs(3): no dense columns removed\n", in_knobs [2]) ;
173 mexPrintf (
"knobs(4): %g, aggressive absorption: %s\n",
175 mexPrintf (
"knobs(5): %g, statistics and knobs printed\n",
177 mexPrintf (
"Testing: %g %g\n", in_knobs [5], in_knobs[6]) ;
182 Ainput = (mxArray *) pargin [0] ;
183 if (mxGetNumberOfDimensions (Ainput) != 2)
185 mexErrMsgTxt (
"ccolamd: input matrix must be 2-dimensional") ;
187 full = !mxIsSparse (Ainput) ;
190 mexCallMATLAB (1, &Ainput, 1, (mxArray **) pargin,
"sparse") ;
196 n_row = mxGetM (Ainput) ;
197 n_col = mxGetN (Ainput) ;
200 p = (
Long *) mxCalloc (n_col+1,
sizeof (
Long)) ;
201 (void) memcpy (p, mxGetJc (Ainput), (n_col+1)*
sizeof (
Long)) ;
206 mexErrMsgTxt (
"ccolamd: problem too large") ;
218 if (in_knobs [5] < 0)
222 else if (in_knobs [5] > 0)
231 A = (
Long *) mxCalloc (Alen,
sizeof (
Long)) ;
232 (void) memcpy (A, mxGetIr (Ainput), nnz*
sizeof (
Long)) ;
236 mxDestroyArray (Ainput) ;
262 switch ((
Long) in_knobs [6])
268 mexPrintf (
"ccolamdtest: no errors expected\n") ;
276 mexPrintf (
"ccolamdtest: nrow out of range\n") ;
285 mexPrintf (
"ccolamdtest: p [0] nonzero\n") ;
294 mexPrintf (
"colamdtest: negative length last column\n") ;
296 result = (n_col == 0) ;
303 mexPrintf (
"colamdtest: Alen too small\n") ;
312 mexPrintf (
"colamdtest: row index out of range (-1)\n") ;
323 mexPrintf (
"Note: no row indices to put out of range\n") ;
332 mexPrintf (
"ccolamdtest: row index out of range (n_row)\n") ;
338 mexPrintf (
"Changing A[nnz-1] from %d to %d\n",
348 mexPrintf (
"Note: no row indices to put out of range\n") ;
357 mexPrintf (
"ccolamdtest: A not present\n") ;
366 mexPrintf (
"ccolamdtest: p not present\n") ;
375 mexPrintf (
"ccolamdtest: duplicate row index\n") ;
379 for (col = 0 ; col < n_col ; col++)
381 length = p [col+1] - p [
col] ;
384 A [p [
col]] = A [p [
col] + 1] ;
387 mexPrintf (
"Made duplicate row %d in col %d\n",
388 A [p [col] + 1], col) ;
403 mexPrintf (
"ccolamdtest: unsorted column\n") ;
407 for (col = 0 ; col < n_col ; col++)
409 length = p [col+1] - p [
col] ;
413 A [p [
col]] = A[p [
col] + 1] ;
414 A [p [
col] + 1] =
i ;
417 mexPrintf (
"Unsorted column %d \n", col) ;
432 mexPrintf (
"ccolamdtest: massive jumbling\n") ;
436 for (i = 0 ; i < n_col ; i++)
439 cp_end = &A [p [i+1]] ;
442 *cp++ = rand() % n_row ;
454 mexPrintf (
"ccolamdtest: stats not present\n") ;
463 mexPrintf (
"ccolamdtest: ncol out of range\n") ;
474 ok =
ccolamd_l (n_row, n_col, Alen, A, p, knobs, stats,
NULL) ;
484 pargout [1] = mxCreateDoubleMatrix (1,
CCOLAMD_STATS, mxREAL) ;
485 out_stats = mxGetPr (pargout [1]) ;
488 out_stats [
i] = (stats ==
NULL) ? (-1) : (stats [
i]) ;
503 pargout [0] = mxCreateDoubleMatrix (1, n_col, mxREAL) ;
504 out_perm = mxGetPr (pargout [0]) ;
505 for (i = 0 ; i < n_col ; i++)
508 out_perm [
i] = p [
i] + 1 ;
513 mexErrMsgTxt (
"ccolamd should have returned TRUE\n") ;
520 pargout [0] = mxCreateDoubleMatrix (1, 1, mxREAL) ;
521 out_perm = mxGetPr (pargout [0]) ;
526 mexErrMsgTxt (
"ccolamd should have returned FALSE\n") ;
#define CCOLAMD_SUB_VERSION
void ccolamd_l_set_defaults(double knobs [CCOLAMD_KNOBS])
#define CCOLAMD_DENSE_ROW
void ccolamd_l_report(SuiteSparse_long stats [CCOLAMD_STATS])
void mexFunction(int nargout, mxArray *pargout [], int nargin, const mxArray *pargin [])
#define CCOLAMD_MAIN_VERSION
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
SuiteSparse_long ccolamd_l(SuiteSparse_long n_row, SuiteSparse_long n_col, SuiteSparse_long Alen, SuiteSparse_long A [], SuiteSparse_long p [], double knobs [CCOLAMD_KNOBS], SuiteSparse_long stats [CCOLAMD_STATS], SuiteSparse_long cmember [])
#define CCOLAMD_MIN_MEMORY(nnz, n_row, n_col)
#define CCOLAMD_DENSE_COL
static void dump_matrix(Long A [], Long p [], Long n_row, Long n_col, Long Alen, Long limit)
#define CCOLAMD_AGGRESSIVE
size_t ccolamd_l_recommended(SuiteSparse_long nnz, SuiteSparse_long n_row, SuiteSparse_long n_col)