1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
|
/* -*- C -*- */
#ifdef SWIGPYTHON
%module _umfpack
/*
See umfpack.py for more information.
Created by: Robert Cimrman
*/
%{
#include <umfpack.h>
#include "numpy/arrayobject.h"
%}
%feature("autodoc", "1");
#include <umfpack.h>
%init %{
import_array();
%}
%{
/*!
Appends @a what to @a where. On input, @a where need not to be a tuple, but on
return it always is.
@par Revision history:
- 17.02.2005, c
*/
PyObject *helper_appendToTuple( PyObject *where, PyObject *what ) {
PyObject *o2, *o3;
if ((!where) || (where == Py_None)) {
where = what;
} else {
if (!PyTuple_Check( where )) {
o2 = where;
where = PyTuple_New( 1 );
PyTuple_SetItem( where, 0, o2 );
}
o3 = PyTuple_New( 1 );
PyTuple_SetItem( o3, 0, what );
o2 = where;
where = PySequence_Concat( o2, o3 );
Py_DECREF( o2 );
Py_DECREF( o3 );
}
return where;
}
/*!
Gets PyArrayObject from a PyObject.
@par Revision history:
- 22.02.2005, c
- 03.03.2005
- 25.11.2005
- 30.11.2005
- 01.12.2005
*/
PyArrayObject *helper_getCArrayObject( PyObject *input, int type,
int minDim, int maxDim ) {
PyArrayObject *obj;
if (PyArray_Check( input )) {
obj = (PyArrayObject *) input;
if (!PyArray_ISCARRAY( obj )) {
PyErr_SetString( PyExc_TypeError, "not a C array" );
return NULL;
}
obj = (PyArrayObject *)
PyArray_ContiguousFromAny( input, type, minDim, maxDim );
if (!obj) return NULL;
} else {
PyErr_SetString( PyExc_TypeError, "not an array" );
return NULL;
}
return obj;
}
%}
/*!
Use for arrays as input arguments. Could be also used for changing an array
in place.
@a rtype ... return this C data type
@a ctype ... C data type of the C function
@a atype ... PyArray_* suffix
@par Revision history:
- 30.11.2005, c
*/
#define ARRAY_IN( rtype, ctype, atype ) \
%typemap( in ) (ctype *array) { \
PyArrayObject *obj; \
obj = helper_getCArrayObject( $input, PyArray_##atype, 1, 1 ); \
if (!obj) return NULL; \
$1 = (rtype *) obj->data; \
Py_DECREF( obj ); \
};
/*!
@par Revision history:
- 30.11.2005, c
*/
#define CONF_IN( arSize ) \
%typemap( in ) (double conf [arSize]) { \
PyArrayObject *obj; \
obj = helper_getCArrayObject( $input, PyArray_DOUBLE, 1, 1 ); \
if (!obj) return NULL; \
if ((obj->nd != 1) || (obj->dimensions[0] != arSize)) { \
PyErr_SetString( PyExc_ValueError, "wrong Control/Info array size" ); \
Py_DECREF( obj ); \
return NULL; \
} \
$1 = (double *) obj->data; \
Py_DECREF( obj ); \
};
/*!
@par Revision history:
- 01.12.2005, c
- 02.12.2005
*/
#define OPAQUE_ARGOUT( ttype ) \
%typemap( in, numinputs=0 ) ttype* opaque_argout( ttype tmp ) { \
$1 = &tmp; \
}; \
%typemap( argout ) ttype* opaque_argout { \
PyObject *obj; \
obj = SWIG_NewPointerObj( (ttype) (*$1), $*1_descriptor, 0 ); \
$result = helper_appendToTuple( $result, obj ); \
};
/*!
@par Revision history:
- 02.12.2005, c
*/
#define OPAQUE_ARGINOUT( ttype ) \
%typemap( in ) ttype* opaque_arginout( ttype tmp ) { \
if ((SWIG_ConvertPtr( $input,(void **) &tmp, $*1_descriptor, \
SWIG_POINTER_EXCEPTION)) == -1) return NULL; \
$1 = &tmp; \
}; \
%typemap( argout ) ttype* opaque_arginout { \
PyObject *obj; \
obj = SWIG_NewPointerObj( (ttype) (*$1), $*1_descriptor, 0 ); \
$result = helper_appendToTuple( $result, obj ); \
};
ARRAY_IN( int, const int, INT )
%apply const int *array {
const int Ap [ ],
const int Ai [ ]
};
ARRAY_IN( long, const long, LONG )
%apply const long *array {
const long Ap [ ],
const long Ai [ ]
};
ARRAY_IN( double, const double, DOUBLE )
%apply const double *array {
const double Ax [ ],
const double Az [ ],
const double B [ ],
const double Bx [ ],
const double Bz [ ]
};
ARRAY_IN( double, double, DOUBLE )
%apply double *array {
double X [ ],
double Xx [ ],
double Xz [ ]
};
CONF_IN( UMFPACK_CONTROL )
%apply (double conf [UMFPACK_CONTROL]) {
double Control [ANY]
};
CONF_IN( UMFPACK_INFO )
%apply double conf [UMFPACK_INFO] {
double Info [ANY]
};
%include <umfpack.h>
%include <umfpack_solve.h>
%include <umfpack_defaults.h>
%include <umfpack_triplet_to_col.h>
%include <umfpack_col_to_triplet.h>
%include <umfpack_transpose.h>
%include <umfpack_scale.h>
%include <umfpack_report_symbolic.h>
%include <umfpack_report_numeric.h>
%include <umfpack_report_info.h>
%include <umfpack_report_control.h>
/*
The order is important below!
*/
OPAQUE_ARGOUT( void * )
%apply void ** opaque_argout {
void **Symbolic,
void **Numeric
}
%include <umfpack_symbolic.h>
%include <umfpack_numeric.h>
OPAQUE_ARGINOUT( void * )
%apply void ** opaque_arginout {
void **Symbolic,
void **Numeric
}
%include <umfpack_free_symbolic.h>
%include <umfpack_free_numeric.h>
/*
* wnbell - attempt to get L,U,P,Q out
*/
%include "typemaps.i"
%apply int *OUTPUT {
int *lnz,
int *unz,
int *n_row,
int *n_col,
int *nz_udiag
};
%apply long *OUTPUT {
long *lnz,
long *unz,
long *n_row,
long *n_col,
long *nz_udiag
};
%include <umfpack_get_lunz.h>
ARRAY_IN( double, double, DOUBLE )
%apply double *array {
double Lx [ ],
double Lz [ ],
double Ux [ ],
double Uz [ ],
double Dx [ ],
double Dz [ ],
double Rs [ ]
};
ARRAY_IN( int, int, INT )
%apply int *array {
int Lp [ ],
int Lj [ ],
int Up [ ],
int Ui [ ],
int P [ ],
int Q [ ]
};
%apply int *OUTPUT { int *do_recip};
%include <umfpack_get_numeric.h>
#endif
|