[Numpy-svn] r4219 - in branches/numpy.scons/numpy/core: . include/numpy src tests

numpy-svn@scip... numpy-svn@scip...
Wed Oct 17 23:35:49 CDT 2007


Author: cdavid
Date: 2007-10-17 23:35:29 -0500 (Wed, 17 Oct 2007)
New Revision: 4219

Modified:
   branches/numpy.scons/numpy/core/include/numpy/ndarrayobject.h
   branches/numpy.scons/numpy/core/setup.py
   branches/numpy.scons/numpy/core/src/arraytypes.inc.src
   branches/numpy.scons/numpy/core/src/ufuncobject.c
   branches/numpy.scons/numpy/core/src/umathmodule.c.src
   branches/numpy.scons/numpy/core/tests/test_regression.py
Log:
Merging from cleanconfig branch

Modified: branches/numpy.scons/numpy/core/include/numpy/ndarrayobject.h
===================================================================
--- branches/numpy.scons/numpy/core/include/numpy/ndarrayobject.h	2007-10-18 04:02:24 UTC (rev 4218)
+++ branches/numpy.scons/numpy/core/include/numpy/ndarrayobject.h	2007-10-18 04:35:29 UTC (rev 4219)
@@ -13,8 +13,15 @@
        everything when you're typing */
 #endif
 /* This is auto-generated by the installer */
-#include "config.h"
+#include "numpyconfig.h"
 
+/* Only use thread if configured in config and python supports it */
+#if defined WITH_THREAD && !NPY_NOSMP
+        #define NPY_ALLOW_THREADS 1
+#else
+        #define NPY_ALLOW_THREADS 0
+#endif
+
 /* There are several places in the code where an array of dimensions is
  * allocated statically.  This is the size of that static allocation.
  *
@@ -80,7 +87,8 @@
 #define NPY_FALSE 0
 #define NPY_TRUE 1
 
-#if SIZEOF_LONG_DOUBLE==SIZEOF_DOUBLE
+
+#if NPY_SIZEOF_LONGDOUBLE == NPY_SIZEOF_DOUBLE
         typedef double npy_longdouble;
         #define NPY_LONGDOUBLE_FMT "g"
 #else
@@ -279,22 +287,15 @@
 #define NPY_MAX_ULONG  ULONG_MAX
 
 
-#define NPY_SIZEOF_LONG SIZEOF_LONG
-#define NPY_SIZEOF_INT SIZEOF_INT
-#define NPY_SIZEOF_SHORT SIZEOF_SHORT
-#define NPY_SIZEOF_FLOAT SIZEOF_FLOAT
-#define NPY_SIZEOF_DOUBLE SIZEOF_DOUBLE
-#define NPY_SIZEOF_LONGDOUBLE SIZEOF_LONG_DOUBLE
-#define NPY_SIZEOF_LONGLONG SIZEOF_LONG_LONG
 #define NPY_BITSOF_BOOL (sizeof(npy_bool)*CHAR_BIT)
 #define NPY_BITSOF_CHAR CHAR_BIT
-#define NPY_BITSOF_SHORT (SIZEOF_SHORT*CHAR_BIT)
-#define NPY_BITSOF_INT (SIZEOF_INT*CHAR_BIT)
-#define NPY_BITSOF_LONG (SIZEOF_LONG*CHAR_BIT)
-#define NPY_BITSOF_LONGLONG (NPY_SIZEOF_LONGLONG*CHAR_BIT)
-#define NPY_BITSOF_FLOAT (SIZEOF_FLOAT*CHAR_BIT)
-#define NPY_BITSOF_DOUBLE (SIZEOF_DOUBLE*CHAR_BIT)
-#define NPY_BITSOF_LONGDOUBLE (NPY_SIZEOF_LONGDOUBLE*CHAR_BIT)
+#define NPY_BITSOF_SHORT (NPY_SIZEOF_SHORT * CHAR_BIT)
+#define NPY_BITSOF_INT (NPY_SIZEOF_INT * CHAR_BIT)
+#define NPY_BITSOF_LONG (NPY_SIZEOF_LONG * CHAR_BIT)
+#define NPY_BITSOF_LONGLONG (NPY_SIZEOF_LONGLONG * CHAR_BIT)
+#define NPY_BITSOF_FLOAT (NPY_SIZEOF_FLOAT * CHAR_BIT)
+#define NPY_BITSOF_DOUBLE (NPY_SIZEOF_DOUBLE * CHAR_BIT)
+#define NPY_BITSOF_LONGDOUBLE (NPY_SIZEOF_LONGDOUBLE * CHAR_BIT)
 
 #if NPY_BITSOF_LONG == 8
 #define NPY_INT8 NPY_LONG
@@ -918,8 +919,8 @@
  * platform.  Py_intptr_t, Py_uintptr_t are defined in pyport.h. */
 typedef Py_intptr_t npy_intp;
 typedef Py_uintptr_t npy_uintp;
-#define NPY_SIZEOF_INTP SIZEOF_PY_INTPTR_T
-#define NPY_SIZEOF_UINTP SIZEOF_PY_INTPTR_T
+#define NPY_SIZEOF_INTP NPY_SIZEOF_PY_INTPTR_T
+#define NPY_SIZEOF_UINTP NPY_SIZEOF_PY_INTPTR_T
 
 #ifdef constchar
 #undef constchar
@@ -940,7 +941,7 @@
 #define constchar char
 #endif
 
-#if SIZEOF_PY_INTPTR_T == SIZEOF_INT
+#if NPY_SIZEOF_PY_INTPTR_T == NPY_SIZEOF_INT
         #define NPY_INTP NPY_INT
         #define NPY_UINTP NPY_UINT
         #define PyIntpArrType_Type PyIntArrType_Type
@@ -949,7 +950,7 @@
         #define NPY_MIN_INTP NPY_MIN_INT
         #define NPY_MAX_UINTP NPY_MAX_UINT
         #define NPY_INTP_FMT "d"
-#elif SIZEOF_PY_INTPTR_T == SIZEOF_LONG
+#elif NPY_SIZEOF_PY_INTPTR_T == NPY_SIZEOF_LONG
         #define NPY_INTP NPY_LONG
         #define NPY_UINTP NPY_ULONG
         #define PyIntpArrType_Type PyLongArrType_Type
@@ -958,7 +959,7 @@
         #define NPY_MIN_INTP MIN_LONG
         #define NPY_MAX_UINTP NPY_MAX_ULONG
         #define NPY_INTP_FMT "ld"
-#elif defined(PY_LONG_LONG) && (SIZEOF_PY_INTPTR_T == SIZEOF_LONG_LONG)
+#elif defined(PY_LONG_LONG) && (NPY_SIZEOF_PY_INTPTR_T == NPY_SIZEOF_LONGLONG)
         #define NPY_INTP NPY_LONGLONG
         #define NPY_UINTP NPY_ULONGLONG
         #define PyIntpArrType_Type PyLongLongArrType_Type
@@ -1894,7 +1895,7 @@
 
 #define PyArray_REFCOUNT(obj) (((PyObject *)(obj))->ob_refcnt)
 #define NPY_REFCOUNT PyArray_REFCOUNT
-#define NPY_MAX_ELSIZE (2*SIZEOF_LONGDOUBLE)
+#define NPY_MAX_ELSIZE (2 * NPY_SIZEOF_LONGDOUBLE)
 
 #define PyArray_ContiguousFromAny(op, type, min_depth, max_depth)             \
         PyArray_FromAny(op, PyArray_DescrFromType(type), min_depth,           \

Modified: branches/numpy.scons/numpy/core/setup.py
===================================================================
--- branches/numpy.scons/numpy/core/setup.py	2007-10-18 04:02:24 UTC (rev 4218)
+++ branches/numpy.scons/numpy/core/setup.py	2007-10-18 04:35:29 UTC (rev 4219)
@@ -18,6 +18,11 @@
     ('rint', 'HAVE_RINT'),
     ]
 
+def is_npy_no_signal():
+    """Return True if the NPY_NO_SIGNAL symbol must be defined in configuration
+    header."""
+    return sys.platform == 'win32'
+
 def configuration(parent_package='',top_path=None):
     from numpy.distutils.misc_util import Configuration,dot_join
     from numpy.distutils.system_info import get_info, default_lib_dirs
@@ -73,8 +78,7 @@
                     nosmp = 1
                 except KeyError:
                     nosmp = 0
-            if nosmp: moredefs = [('NPY_ALLOW_THREADS', '0')]
-            else: moredefs = []
+            moredefs = []
             #
             mathlibs = []
             tc = testcode_mathlib()
@@ -102,7 +106,7 @@
                 if check_func(func_name):
                     moredefs.append(defsymbol)
 
-            if sys.platform == 'win32':
+            if is_npy_no_signal():
                 moredefs.append('NPY_NO_SIGNAL')
 
             if sys.platform=='win32' or os.name=='nt':
@@ -123,8 +127,12 @@
                     target_f.write('#define %s\n' % (d))
                 else:
                     target_f.write('#define %s %s\n' % (d[0],d[1]))
-            if not nosmp:  # default is to use WITH_THREAD
-                target_f.write('#ifdef WITH_THREAD\n#define NPY_ALLOW_THREADS 1\n#else\n#define NPY_ALLOW_THREADS 0\n#endif\n')
+            # Define NPY_NOSMP to 1 if explicitely requested, or if we cannot
+            # support thread support reliably
+            if nosmp:
+                target_f.write('#define NPY_NOSMP 1\n')
+            else:
+                target_f.write('#define NPY_NOSMP 0\n')
             target_f.close()
             print 'File:',target
             target_f = open(target)
@@ -151,6 +159,39 @@
         config.add_data_files((header_dir,target))
         return target
 
+    def generate_numpyconfig_h(ext, build_dir):
+        """Depends on config.h: generate_config_h has to be called before !"""
+        target = join(build_dir,'numpyconfig.h')
+        if newer(__file__,target):
+            config_cmd = config.get_config_cmd()
+            log.info('Generating %s',target)
+            testcode = generate_numpyconfig_code(target)
+
+            from distutils import sysconfig
+            python_include = sysconfig.get_python_inc()
+            python_h = join(python_include, 'Python.h')
+            if not os.path.isfile(python_h):
+                raise SystemError,\
+                      "Non-existing %s. Perhaps you need to install"\
+                      " python-dev|python-devel." % (python_h)
+
+            config.numpy_include_dirs
+            result = config_cmd.try_run(testcode, 
+                                include_dirs = [python_include] + \
+                                                       config.numpy_include_dirs,
+                                        library_dirs = default_lib_dirs)
+
+            if not result:
+                raise SystemError,"Failed to generate numpy configuration. "\
+                      "See previous error messages for more information."
+
+            print 'File: %s' % target
+            target_f = open(target)
+            print target_f.read()
+            target_f.close()
+            print 'EOF'
+        return target
+                                
     def generate_api_func(module_name):
         def generate_api(ext, build_dir):
             script = join(codegen_dir, module_name + '.py')
@@ -205,6 +246,7 @@
     config.add_extension('multiarray',
                          sources = [join('src','multiarraymodule.c'),
                                     generate_config_h,
+                                    generate_numpyconfig_h,
                                     generate_array_api,
                                     join('src','scalartypes.inc.src'),
                                     join('src','arraytypes.inc.src'),
@@ -216,6 +258,7 @@
 
     config.add_extension('umath',
                          sources = [generate_config_h,
+                                    generate_numpyconfig_h,
                                     join('src','umathmodule.c.src'),
                                     generate_umath_c,
                                     generate_ufunc_api,
@@ -231,6 +274,7 @@
     config.add_extension('_sort',
                          sources=[join('src','_sortmodule.c.src'),
                                   generate_config_h,
+                                  generate_numpyconfig_h,
                                   generate_array_api,
                                   ],
                          )
@@ -238,6 +282,7 @@
     config.add_extension('scalarmath',
                          sources=[join('src','scalarmathmodule.c.src'),
                                   generate_config_h,
+                                  generate_numpyconfig_h,
                                   generate_array_api,
                                   generate_ufunc_api],
                          )
@@ -342,6 +387,77 @@
     testcode = '\n'.join(testcode)
     return testcode
 
+def generate_numpyconfig_code(target):
+    """Return the source code as a string of the code to generate the
+    numpyconfig header file."""
+    # Config symbols to prepend
+    prepends = [('NPY_SIZEOF_SHORT', 'SIZEOF_SHORT'),
+            ('NPY_SIZEOF_INT', 'SIZEOF_INT'),
+            ('NPY_SIZEOF_LONG', 'SIZEOF_LONG'),
+            ('NPY_SIZEOF_FLOAT', 'SIZEOF_FLOAT'),
+            ('NPY_SIZEOF_DOUBLE', 'SIZEOF_DOUBLE'),
+            ('NPY_SIZEOF_LONGDOUBLE', 'SIZEOF_LONG_DOUBLE'),
+            ('NPY_SIZEOF_PY_INTPTR_T', 'SIZEOF_PY_INTPTR_T'),
+            ('NPY_NOSMP', 'NPY_NOSMP'),]
+
+    testcode = ["""
+#include <Python.h>
+#include "config.h"
+
+int main()
+{   
+    FILE* f;
+   
+    f = fopen("%s", "w");
+    if (f == NULL) {
+        return -1;
+    }
+""" % target]
+
+    testcode.append(r"""
+    fprintf(f, "/*\n * This file is generated by %s. DO NOT EDIT \n */\n");
+""" % __file__)
+
+    # Prepend NPY_ to any SIZEOF defines
+    testcode.extend([r'    fprintf(f, "#define ' + i + r' %%d \n", %s);' % j for i, j in prepends])
+
+    # Conditionally define NPY_NO_SIGNAL
+    if is_npy_no_signal():
+        testcode.append(r'    fprintf(f, "\n#define NPY_NO_SIGNAL\n");')
+
+    tmpcode = r"""
+    #ifdef PY_LONG_LONG
+        fprintf(f, "\n#define %s %%d \n", %s);
+        fprintf(f, "#define %s %%d \n", %s);
+    #else
+        fprintf(f, "/* PY_LONG_LONG not defined  */ \n");
+    #endif"""
+    testcode.append(tmpcode % ('NPY_SIZEOF_LONGLONG', 'SIZEOF_LONG_LONG',
+                               'NPY_SIZEOF_PY_LONG_LONG', 'SIZEOF_PY_LONG_LONG'))
+
+    testcode.append(r"""
+#ifndef CHAR_BIT
+          {
+             unsigned char var = 2;
+             int i = 0;
+             while (var >= 2) {
+                     var = var << 1;
+                     i++;
+             }
+             fprintf(f,"#define CHAR_BIT %d\n", i+1);
+          }
+#else
+          fprintf(f, "/* #define CHAR_BIT %d */\n", CHAR_BIT);
+#endif""")
+
+    testcode.append("""
+    fclose(f);
+
+    return 0;
+}
+""")
+    return "\n".join(testcode)
+
 if __name__=='__main__':
     from numpy.distutils.core import setup
     setup(configuration=configuration)

Modified: branches/numpy.scons/numpy/core/src/arraytypes.inc.src
===================================================================
--- branches/numpy.scons/numpy/core/src/arraytypes.inc.src	2007-10-18 04:02:24 UTC (rev 4218)
+++ branches/numpy.scons/numpy/core/src/arraytypes.inc.src	2007-10-18 04:35:29 UTC (rev 4219)
@@ -1,4 +1,5 @@
 /* -*- c -*- */
+#include "config.h"
 
 static longlong
 MyPyLong_AsLongLong(PyObject *vv)

Modified: branches/numpy.scons/numpy/core/src/ufuncobject.c
===================================================================
--- branches/numpy.scons/numpy/core/src/ufuncobject.c	2007-10-18 04:02:24 UTC (rev 4218)
+++ branches/numpy.scons/numpy/core/src/ufuncobject.c	2007-10-18 04:35:29 UTC (rev 4219)
@@ -1344,7 +1344,8 @@
             loop->meth = BUFFER_UFUNCLOOP;
             loop->needbuffer[i] = 1;
         }
-        if (!loop->obj && mps[i]->descr->type_num == PyArray_OBJECT) {
+        if (!loop->obj && ((mps[i]->descr->type_num == PyArray_OBJECT) ||
+			   (arg_types[i] == PyArray_OBJECT))) {
             loop->obj = 1;
         }
     }
@@ -1486,7 +1487,7 @@
 
         /* compute the element size */
         for (i=0; i<self->nargs;i++) {
-            if (!loop->needbuffer) continue;
+            if (!loop->needbuffer[i]) continue;
             if (arg_types[i] != mps[i]->descr->type_num) {
                 descr = PyArray_DescrFromType(arg_types[i]);
                 if (loop->steps[i])
@@ -1913,6 +1914,7 @@
                         }
                         /* cast to the other buffer if necessary */
                         if (loop->cast[i]) {
+			    /* fprintf(stderr, "casting... %d, %p %p\n", i, buffer[i]); */
                             loop->cast[i](buffer[i],
                                           castbuf[i],
                                           (intp) datasize[i],
@@ -1926,6 +1928,7 @@
                     for (i=self->nin; i<self->nargs; i++) {
                         if (!needbuffer[i]) continue;
                         if (loop->cast[i]) {
+			    /* fprintf(stderr, "casting back... %d, %p", i, castbuf[i]); */
                             loop->cast[i](castbuf[i],
                                           buffer[i],
                                           (intp) datasize[i],

Modified: branches/numpy.scons/numpy/core/src/umathmodule.c.src
===================================================================
--- branches/numpy.scons/numpy/core/src/umathmodule.c.src	2007-10-18 04:02:24 UTC (rev 4218)
+++ branches/numpy.scons/numpy/core/src/umathmodule.c.src	2007-10-18 04:35:29 UTC (rev 4219)
@@ -5,6 +5,7 @@
 #define _UMATHMODULE
 #include "numpy/ufuncobject.h"
 #include "abstract.h"
+#include "config.h"
 #include <math.h>
 
 /* A whole slew of basic math functions are provided originally

Modified: branches/numpy.scons/numpy/core/tests/test_regression.py
===================================================================
--- branches/numpy.scons/numpy/core/tests/test_regression.py	2007-10-18 04:02:24 UTC (rev 4218)
+++ branches/numpy.scons/numpy/core/tests/test_regression.py	2007-10-18 04:35:29 UTC (rev 4219)
@@ -726,5 +726,12 @@
         N.lib.place(1,1,1)
 
 
+    def check_object_casting(self, level=rlevel):
+        def rs():
+            x = N.ones([484,286])
+            y = N.zeros([484,286])
+            x |= y
+        self.failUnlessRaises(TypeError,rs)
+
 if __name__ == "__main__":
     NumpyTest().run()



More information about the Numpy-svn mailing list