[Scipy-svn] r6723 - in trunk: scipy/sparse/linalg/dsolve scipy/sparse/linalg/eigen/arpack scipy/sparse/linalg/isolve scipy/sparse/sparsetools tools

scipy-svn at scipy.org scipy-svn at scipy.org
Sat Sep 11 20:51:05 EDT 2010


Author: ptvirtan
Date: 2010-09-11 19:51:04 -0500 (Sat, 11 Sep 2010)
New Revision: 6723

Added:
   trunk/scipy/sparse/linalg/dsolve/py3k.h
   trunk/scipy/sparse/sparsetools/py3k.h
Modified:
   trunk/scipy/sparse/linalg/dsolve/_superlu_utils.c
   trunk/scipy/sparse/linalg/dsolve/_superlumodule.c
   trunk/scipy/sparse/linalg/dsolve/_superluobject.c
   trunk/scipy/sparse/linalg/eigen/arpack/setup.py
   trunk/scipy/sparse/linalg/isolve/setup.py
   trunk/scipy/sparse/sparsetools/sparsetools.i
   trunk/tools/py3tool.py
Log:
3K: scipy.sparse now compiles, most tests pass.

Modified: trunk/scipy/sparse/linalg/dsolve/_superlu_utils.c
===================================================================
--- trunk/scipy/sparse/linalg/dsolve/_superlu_utils.c	2010-09-12 00:50:39 UTC (rev 6722)
+++ trunk/scipy/sparse/linalg/dsolve/_superlu_utils.c	2010-09-12 00:51:04 UTC (rev 6723)
@@ -1,3 +1,5 @@
+/* Should be imported before Python.h */
+#include "py3k.h"
 
 #include "Python.h"
 #include <setjmp.h>

Modified: trunk/scipy/sparse/linalg/dsolve/_superlumodule.c
===================================================================
--- trunk/scipy/sparse/linalg/dsolve/_superlumodule.c	2010-09-12 00:50:39 UTC (rev 6722)
+++ trunk/scipy/sparse/linalg/dsolve/_superlumodule.c	2010-09-12 00:51:04 UTC (rev 6723)
@@ -240,6 +240,39 @@
     {NULL, NULL}
 };
 
+#if PY_VERSION_HEX >= 0x03000000
+
+static struct PyModuleDef moduledef = {
+    PyModuleDef_HEAD_INIT,
+    "_superlu",
+    NULL,
+    -1,
+    SuperLU_Methods,
+    NULL,
+    NULL,
+    NULL,
+    NULL
+};
+
+PyObject *PyInit__superlu(void)
+{
+    PyObject *m, *d;
+
+    m = PyModule_Create(&moduledef);
+    d = PyModule_GetDict(m);
+
+    PyDict_SetItemString(d, "SciPyLUType", (PyObject *)&SciPySuperLUType);
+
+    import_array();
+
+    if (PyErr_Occurred())
+        Py_FatalError("can't initialize module _superlu");
+
+    return m;
+}
+
+#else
+
 PyMODINIT_FUNC
 init_superlu(void)
 {
@@ -254,3 +287,5 @@
 
     import_array();
 }
+
+#endif

Modified: trunk/scipy/sparse/linalg/dsolve/_superluobject.c
===================================================================
--- trunk/scipy/sparse/linalg/dsolve/_superluobject.c	2010-09-12 00:50:39 UTC (rev 6722)
+++ trunk/scipy/sparse/linalg/dsolve/_superluobject.c	2010-09-12 00:51:04 UTC (rev 6723)
@@ -6,6 +6,7 @@
  */
 
 #include <Python.h>
+#include "py3k.h"
 
 #define NO_IMPORT_ARRAY
 #include "_superluobject.h"
@@ -157,7 +158,7 @@
     PyObject *list = PyList_New(sizeof(members)/sizeof(char *));
     if (list != NULL) {
       for (i = 0; i < sizeof(members)/sizeof(char *); i ++)
-	PyList_SetItem(list, i, PyString_FromString(members[i]));
+	PyList_SetItem(list, i, PyUstring_FromString(members[i]));
       if (PyErr_Occurred()) {
 	Py_DECREF(list);
 	list = NULL;
@@ -165,7 +166,17 @@
     }
     return list;
   }
+#if PY_VERSION_HEX >= 0x03000000
+  if (1) {
+      PyObject *str, *ret;
+      str = PyUnicode_FromString(name);
+      ret = PyObject_GenericGetAttr((PyObject *)self, str);
+      Py_DECREF(str);
+      return ret;
+  }
+#else
   return Py_FindMethod(SciPyLU_methods, (PyObject *)self, name);
+#endif
 }
 
 

Added: trunk/scipy/sparse/linalg/dsolve/py3k.h
===================================================================
--- trunk/scipy/sparse/linalg/dsolve/py3k.h	                        (rev 0)
+++ trunk/scipy/sparse/linalg/dsolve/py3k.h	2010-09-12 00:51:04 UTC (rev 6723)
@@ -0,0 +1,13 @@
+#ifndef __NPY_PY3H__
+#define __NPY_PY3H__
+
+#include <Python.h>
+
+#if PY_VERSION_HEX >= 0x03000000
+    #define PyUstring_FromString PyUnicode_FromString
+    #define PyInt_FromLong PyLong_FromLong
+#else
+    #define PyUstring_FromString PyString_FromString
+#endif
+
+#endif

Modified: trunk/scipy/sparse/linalg/eigen/arpack/setup.py
===================================================================
--- trunk/scipy/sparse/linalg/eigen/arpack/setup.py	2010-09-12 00:50:39 UTC (rev 6722)
+++ trunk/scipy/sparse/linalg/eigen/arpack/setup.py	2010-09-12 00:51:04 UTC (rev 6723)
@@ -27,7 +27,7 @@
     lapack_opt = get_info('lapack_opt')
 
     if not lapack_opt:
-        raise NotFoundError,'no lapack/blas resources found'
+        raise NotFoundError('no lapack/blas resources found')
 
     config = Configuration('arpack', parent_package, top_path)
 

Modified: trunk/scipy/sparse/linalg/isolve/setup.py
===================================================================
--- trunk/scipy/sparse/linalg/isolve/setup.py	2010-09-12 00:50:39 UTC (rev 6722)
+++ trunk/scipy/sparse/linalg/isolve/setup.py	2010-09-12 00:51:04 UTC (rev 6723)
@@ -17,7 +17,7 @@
     lapack_opt = get_info('lapack_opt')
 
     if not lapack_opt:
-        raise NotFoundError,'no lapack/blas resources found'
+        raise NotFoundError('no lapack/blas resources found')
 
     # iterative methods
     methods = ['BiCGREVCOM.f.src',

Added: trunk/scipy/sparse/sparsetools/py3k.h
===================================================================
--- trunk/scipy/sparse/sparsetools/py3k.h	                        (rev 0)
+++ trunk/scipy/sparse/sparsetools/py3k.h	2010-09-12 00:51:04 UTC (rev 6723)
@@ -0,0 +1,22 @@
+#ifndef __STDC_FORMAT_MACROS
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
+#error YOYOYO
+#endif
+#include <Python.h>
+
+#if PY_VERSION_HEX >= 0x03000000
+	#define PyString_Check PyUnicode_Check
+	static int __pyfile_check_guard(PyObject *x)
+	{
+		fprintf(stderr, "PY3K error: PyFile_Check called !\n");
+		return 0;
+	}
+	#define PyFile_Check(x) __pyfile_check_guard((x))
+	static int __pyinstance_check_guard(PyObject *x)
+	{
+		fprintf(stderr, "PY3K error: PyInstance_Check calleed !\n");
+		return 0;
+	}
+	#define PyInstance_Check(x) __pyinstance_check_guard((x))
+#endif

Modified: trunk/scipy/sparse/sparsetools/sparsetools.i
===================================================================
--- trunk/scipy/sparse/sparsetools/sparsetools.i	2010-09-12 00:50:39 UTC (rev 6722)
+++ trunk/scipy/sparse/sparsetools/sparsetools.i	2010-09-12 00:51:04 UTC (rev 6723)
@@ -5,6 +5,7 @@
 #pragma SWIG nowarn=467
 
 %{
+#include "py3k.h"
 #define SWIG_FILE_WITH_INIT
 #include "Python.h"
 #include "numpy/arrayobject.h"

Modified: trunk/tools/py3tool.py
===================================================================
--- trunk/tools/py3tool.py	2010-09-12 00:50:39 UTC (rev 6722)
+++ trunk/tools/py3tool.py	2010-09-12 00:51:04 UTC (rev 6723)
@@ -153,6 +153,7 @@
         os.path.join('linalg', 'decomp.py'),
         os.path.join('linalg', 'lapack.py'),
         os.path.join('linalg', 'flinalg.py'),
+        os.path.join('linalg', 'iterative.py'),
         os.path.join('lib', 'blas', '__init__.py'),
         os.path.join('lib', 'lapack', '__init__.py'),
         os.path.join('ndimage', 'filters.py'),
@@ -173,9 +174,15 @@
         os.path.join('special', 'orthogonal.py'),
         os.path.join('spatial', '__init__.py'),
         os.path.join('spatial', 'distance.py'),
+        os.path.join('sparse', 'linalg', 'isolve', 'iterative.py'),
+        os.path.join('sparse', 'linalg', 'dsolve', '_superlu.py'),
+        os.path.join('sparse', 'linalg', 'eigen', 'arpack', 'arpack.py'),
+        os.path.join('sparse', 'linalg', 'eigen', 'arpack', 'speigs.py'),
+        os.path.join('sparse', 'linalg', 'iterative', 'isolve', 'iterative.py'),
     ]
 
     if any(filename.endswith(x) for x in import_mangling):
+        print(filename)
         f = open(filename, 'r')
         text = f.read()
         f.close()
@@ -192,6 +199,8 @@
                     'futil', 'mvn',
                     '_nd_image',
                     'numpyio',
+                    '_zsuperlu', '_ssuperlu', '_dsuperlu', '_csuperlu',
+                    '_arpack', '_iterative',
                     ]:
             text = re.sub(r'^(\s*)import %s' % mod,
                           r'\1from . import %s' % mod,




More information about the Scipy-svn mailing list