Skip to content

Commit

Permalink
3K: sparse: fix superlu module build on Py3
Browse files Browse the repository at this point in the history
  • Loading branch information
pv committed Sep 12, 2010
1 parent ee7bd71 commit 6807076
Show file tree
Hide file tree
Showing 7 changed files with 370 additions and 29 deletions.
9 changes: 7 additions & 2 deletions scipy/sparse/linalg/dsolve/_superlu_utils.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/* Should be imported before Python.h */
#include "py3k.h"

#include "Python.h"
#include <Python.h>

#define NO_IMPORT_ARRAY
#define PY_ARRAY_UNIQUE_SYMBOL _scipy_sparse_superlu_ARRAY_API

#include "_superluobject.h"
#include "npy_3kcompat.h"
#include <setjmp.h>

jmp_buf _superlu_py_jmpbuf;
Expand Down
21 changes: 17 additions & 4 deletions scipy/sparse/linalg/dsolve/_superlumodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
#include <Python.h>
#include <setjmp.h>

#define PY_ARRAY_UNIQUE_SYMBOL _scipy_sparse_superlu_ARRAY_API
#include <numpy/arrayobject.h>

#include "_superluobject.h"
#include "npy_3kcompat.h"

extern jmp_buf _superlu_py_jmpbuf;

Expand Down Expand Up @@ -258,13 +262,18 @@ PyObject *PyInit__superlu(void)
{
PyObject *m, *d;

import_array();

if (PyType_Ready(&SciPySuperLUType) < 0) {
return;
}

m = PyModule_Create(&moduledef);
d = PyModule_GetDict(m);

Py_INCREF(&PyArrayFlags_Type);
PyDict_SetItemString(d, "SciPyLUType", (PyObject *)&SciPySuperLUType);

import_array();

if (PyErr_Occurred())
Py_FatalError("can't initialize module _superlu");

Expand All @@ -278,14 +287,18 @@ init_superlu(void)
{
PyObject *m, *d;

import_array();

SciPySuperLUType.ob_type = &PyType_Type;
if (PyType_Ready(&SciPySuperLUType) < 0) {
return;
}

m = Py_InitModule("_superlu", SuperLU_Methods);
d = PyModule_GetDict(m);

Py_INCREF(&PyArrayFlags_Type);
PyDict_SetItemString(d, "SciPyLUType", (PyObject *)&SciPySuperLUType);

import_array();
}

#endif
42 changes: 38 additions & 4 deletions scipy/sparse/linalg/dsolve/_superluobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
*/

#include <Python.h>
#include "py3k.h"

#define NO_IMPORT_ARRAY
#define PY_ARRAY_UNIQUE_SYMBOL _scipy_sparse_superlu_ARRAY_API

#include "_superluobject.h"
#include "npy_3kcompat.h"
#include <setjmp.h>
#include <ctype.h>

Expand Down Expand Up @@ -158,7 +160,7 @@ SciPyLU_getattr(SciPyLUObject *self, char *name)
PyObject *list = PyList_New(sizeof(members)/sizeof(char *));
if (list != NULL) {
for (i = 0; i < sizeof(members)/sizeof(char *); i ++)
PyList_SetItem(list, i, PyUstring_FromString(members[i]));
PyList_SetItem(list, i, PyUString_FromString(members[i]));
if (PyErr_Occurred()) {
Py_DECREF(list);
list = NULL;
Expand Down Expand Up @@ -206,16 +208,20 @@ solve\n\
";

PyTypeObject SciPySuperLUType = {
#if defined(NPY_PY3K)
PyVarObject_HEAD_INIT(NULL, 0)
#else
PyObject_HEAD_INIT(NULL)
0,
#endif
"factored_lu",
sizeof(SciPyLUObject),
0,
(destructor)SciPyLU_dealloc, /* tp_dealloc */
0, /* tp_print */
(getattrfunc)SciPyLU_getattr, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_compare / tp_reserved */
0, /* tp_repr */
0, /* tp_as_number*/
0, /* tp_as_sequence*/
Expand All @@ -226,8 +232,36 @@ PyTypeObject SciPySuperLUType = {
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
0, /* tp_flags */
Py_TPFLAGS_DEFAULT, /* tp_flags */
factored_lu_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
SciPyLU_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
0, /* tp_free */
0, /* tp_is_gc */
0, /* tp_bases */
0, /* tp_mro */
0, /* tp_cache */
0, /* tp_subclasses */
0, /* tp_weaklist */
0, /* tp_del */
#if PY_VERSION_HEX >= 0x02060000
0, /* tp_version_tag */
#endif
};


Expand Down
3 changes: 1 addition & 2 deletions scipy/sparse/linalg/dsolve/_superluobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "Python.h"
#include "SuperLU/SRC/slu_zdefs.h"
#define PY_ARRAY_UNIQUE_SYMBOL _scipy_sparse_superlu_ARRAY_API
#include "numpy/arrayobject.h"
#include "SuperLU/SRC/slu_util.h"
#include "SuperLU/SRC/slu_dcomplex.h"
Expand All @@ -23,7 +22,7 @@
* SuperLUObject definition
*/
typedef struct {
PyObject_VAR_HEAD
PyObject_HEAD
npy_intp m,n;
SuperMatrix L;
SuperMatrix U;
Expand Down
Loading

0 comments on commit 6807076

Please sign in to comment.