1 /* ========================================================================== */ 2 /* === MATLAB/cholmod_matlab.h ============================================== */ 3 /* ========================================================================== */ 4 5 /* Shared prototypes and definitions for CHOLMOD mexFunctions */ 6 7 #include "SuiteSparse_config.h" 8 #ifndef DLONG 9 #define DLONG 10 #endif 11 #define Long SuiteSparse_long 12 #define Long_max SuiteSparse_long_max 13 14 /* Ensure cholmod_read_* and cholmod_write_* work for large files. This 15 * requires MATLAB 7.0 or later. If you are using MATLAB 6.5 or earlier, 16 * you must delete the following line, or compile CHOLMOD with -DNLARGEFILE */ 17 #include "cholmod_io64.h" 18 19 #ifndef NPARTITION 20 #include "metis.h" 21 #endif 22 #undef ASSERT 23 24 #include "cholmod.h" 25 #include <limits.h> 26 #include <string.h> 27 #include <ctype.h> 28 #include <float.h> 29 #include "mex.h" 30 #define EMPTY (-1) 31 #define TRUE 1 32 #define FALSE 0 33 #define MAX(a,b) (((a) > (b)) ? (a) : (b)) 34 #define LEN 16 35 36 #define MXFREE(a) { \ 37 void *ptr ; \ 38 ptr = (void *) (a) ; \ 39 if (ptr != NULL) mxFree (ptr) ; \ 40 } 41 42 #define ERROR_TOO_SMALL 0 43 #define ERROR_HUGE 1 44 #define ERROR_NOT_INTEGER 2 45 #define ERROR_TOO_LARGE 3 46 #define ERROR_USAGE 4 47 #define ERROR_LENGTH 5 48 #define ERROR_INVALID_TYPE 6 49 #define ERROR_OUT_OF_MEMORY 7 50 51 /* getting spumoni at run-time takes way too much time */ 52 #ifndef SPUMONI 53 #define SPUMONI 0 54 #endif 55 56 /* closed by sputil_error_handler if not NULL */ 57 extern FILE *sputil_file ; 58 59 void sputil_error /* reports an error */ 60 ( 61 Long error, /* kind of error */ 62 Long is_index /* TRUE if a matrix index, FALSE if a matrix dimension */ 63 ) ; 64 65 Long sputil_double_to_int /* returns integer value of x */ 66 ( 67 double x, /* double value to convert */ 68 Long is_index, /* TRUE if a matrix index, FALSE if a matrix dimension */ 69 Long n /* if a matrix index, x cannot exceed this dimension */ 70 ) ; 71 72 double sputil_get_double (const mxArray *arg) ; /* like mxGetScalar */ 73 74 Long sputil_get_integer /* returns the integer value of a MATLAB argument */ 75 ( 76 const mxArray *arg, /* MATLAB argument to convert */ 77 Long is_index, /* TRUE if an index, FALSE if a matrix dimension */ 78 Long n /* maximum value, if an index */ 79 ) ; 80 81 82 Long sputil_copy_ij /* returns the dimension, n */ 83 ( 84 Long is_scalar, /* TRUE if argument is a scalar, FALSE otherwise */ 85 Long scalar, /* scalar value of the argument */ 86 void *vector, /* vector value of the argument */ 87 mxClassID category, /* type of vector */ 88 Long nz, /* length of output vector I */ 89 Long n, /* maximum dimension, EMPTY if not yet known */ 90 Long *I /* vector of length nz to copy into */ 91 ) ; 92 93 /* converts a triplet matrix to a compressed-column matrix */ 94 cholmod_sparse *sputil_triplet_to_sparse 95 ( 96 Long nrow, Long ncol, Long nz, Long nzmax, 97 Long i_is_scalar, Long i, void *i_vector, mxClassID i_class, 98 Long j_is_scalar, Long j, void *j_vector, mxClassID j_class, 99 Long s_is_scalar, double x, double z, void *x_vector, double *z_vector, 100 mxClassID s_class, Long s_complex, 101 cholmod_common *cm 102 ) ; 103 104 mxArray *sputil_copy_sparse (const mxArray *A) ; /* copy a sparse matrix */ 105 106 Long sputil_nelements (const mxArray *arg) ; /* like mxGetNumberOfElements */ 107 108 void sputil_sparse /* top-level wrapper for "sparse" function */ 109 ( 110 int nargout, 111 mxArray *pargout [ ], 112 int nargin, 113 const mxArray *pargin [ ] 114 ) ; 115 116 void sputil_error_handler (int status, const char *file, int line, 117 const char *message) ; 118 119 void sputil_config (Long spumoni, cholmod_common *cm) ; 120 121 mxArray *sputil_sparse_to_dense (const mxArray *S) ; 122 123 cholmod_sparse *sputil_get_sparse 124 ( 125 const mxArray *Amatlab, /* MATLAB version of the matrix */ 126 cholmod_sparse *A, /* CHOLMOD version of the matrix */ 127 double *dummy, /* a pointer to a valid scalar double */ 128 Long stype /* -1: lower, 0: unsymmetric, 1: upper */ 129 ) ; 130 131 cholmod_dense *sputil_get_dense 132 ( 133 const mxArray *Amatlab, /* MATLAB version of the matrix */ 134 cholmod_dense *A, /* CHOLMOD version of the matrix */ 135 double *dummy /* a pointer to a valid scalar double */ 136 ) ; 137 138 mxArray *sputil_put_dense /* returns the MATLAB version */ 139 ( 140 cholmod_dense **Ahandle, /* CHOLMOD version of the matrix */ 141 cholmod_common *cm 142 ) ; 143 144 mxArray *sputil_put_sparse 145 ( 146 cholmod_sparse **Ahandle, /* CHOLMOD version of the matrix */ 147 cholmod_common *cm 148 ) ; 149 150 Long sputil_drop_zeros /* drop numerical zeros from a CHOLMOD matrix */ 151 ( 152 cholmod_sparse *S 153 ) ; 154 155 mxArray *sputil_put_int /* copy Long vector to mxArray */ 156 ( 157 Long *P, /* vector to convert */ 158 Long n, /* length of P */ 159 Long one_based /* 1 if convert from 0-based to 1-based, else 0 */ 160 ) ; 161 162 mxArray *sputil_dense_to_sparse (const mxArray *arg) ; 163 164 void sputil_check_ijvector (const mxArray *arg) ; 165 166 void sputil_trim 167 ( 168 cholmod_sparse *S, 169 Long k, 170 cholmod_common *cm 171 ) ; 172 173 cholmod_sparse *sputil_get_sparse_pattern 174 ( 175 const mxArray *Amatlab, /* MATLAB version of the matrix */ 176 cholmod_sparse *Ashallow, /* shallow CHOLMOD version of the matrix */ 177 double *dummy, /* a pointer to a valid scalar double */ 178 cholmod_common *cm 179 ) ; 180 181 cholmod_sparse *sputil_extract_zeros 182 ( 183 cholmod_sparse *A, 184 cholmod_common *cm 185 ) ; 186