This is an archival dump of old wiki content --- see scipy.org for current material.
Please see http://scipy-cookbook.readthedocs.org/

Attachment 'umfpack.i'

Download

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

New Attachment

File to upload
Rename to
Overwrite existing attachment of same name

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.