[Numpy-svn] r4632 - in branches/distutils_scons_command: . numpy/core numpy/core/include/numpy numpy/core/src numpy/distutils/command numpy/lib numpy/lib/tests
numpy-svn at scipy.org
numpy-svn at scipy.org
Sat Dec 22 03:10:22 EST 2007
Author: cdavid
Date: 2007-12-22 02:10:00 -0600 (Sat, 22 Dec 2007)
New Revision: 4632
Modified:
branches/distutils_scons_command/
branches/distutils_scons_command/numpy/core/include/numpy/ndarrayobject.h
branches/distutils_scons_command/numpy/core/setup.py
branches/distutils_scons_command/numpy/core/src/arraytypes.inc.src
branches/distutils_scons_command/numpy/core/src/umathmodule.c.src
branches/distutils_scons_command/numpy/distutils/command/config.py
branches/distutils_scons_command/numpy/lib/arraysetops.py
branches/distutils_scons_command/numpy/lib/tests/test_arraysetops.py
Log:
Merged revisions 4611-4631 via svnmerge from
http://svn.scipy.org/svn/numpy/branches/cleanconfig_rtm
................
r4612 | cdavid | 2007-12-18 17:58:13 +0900 (Tue, 18 Dec 2007) | 3 lines
Initialized merge tracking via "svnmerge" with revisions "1-4611" from
http://svn.scipy.org/svn/numpy/trunk
................
r4613 | cdavid | 2007-12-18 18:26:38 +0900 (Tue, 18 Dec 2007) | 1 line
Clean ndarrayobject.h headers: do not use SIZEOF_*, but NPY_SIZEOF...
................
r4614 | cdavid | 2007-12-18 18:33:11 +0900 (Tue, 18 Dec 2007) | 1 line
Refactor the NPY_ALLOW_THREAD logic outside config.h generation, and put it inside numpy headers
................
r4615 | cdavid | 2007-12-18 18:46:34 +0900 (Tue, 18 Dec 2007) | 1 line
separate config.h (private header) and numpyconfig.h (public header)
................
r4616 | cdavid | 2007-12-18 18:57:21 +0900 (Tue, 18 Dec 2007) | 2 lines
Add CHAR_BITS as a public symbol in numpyconfig header
................
r4617 | cdavid | 2007-12-18 19:05:38 +0900 (Tue, 18 Dec 2007) | 1 line
Fix escaping problem when generating numpyconfig.h on win32
................
r4628 | cdavid | 2007-12-22 12:20:08 +0900 (Sat, 22 Dec 2007) | 1 line
Add code to test for a declaration in header
................
r4629 | cdavid | 2007-12-22 14:52:38 +0900 (Sat, 22 Dec 2007) | 1 line
Add a check_decl function to check for declaration
................
r4630 | cdavid | 2007-12-22 15:28:11 +0900 (Sat, 22 Dec 2007) | 1 line
Remove distutils test for C declaration from numpy.core, since it is put in distutils now
................
r4631 | cdavid | 2007-12-22 15:58:15 +0900 (Sat, 22 Dec 2007) | 18 lines
Merged revisions 4612-4630 via svnmerge from
http://svn.scipy.org/svn/numpy/trunk
........
r4620 | cdavid | 2007-12-18 19:41:22 +0900 (Tue, 18 Dec 2007) | 3 lines
Initialized merge tracking via "svnmerge" with revisions "1-4619" from
http://svn.scipy.org/svn/numpy/branches/distutils_scons_command
........
r4624 | rc | 2007-12-20 19:30:45 +0900 (Thu, 20 Dec 2007) | 2 lines
fixed setmember1d for string arrays
........
r4626 | stefan | 2007-12-21 18:00:24 +0900 (Fri, 21 Dec 2007) | 2 lines
Add test for setdiff1d on character arrays.
........
................
Property changes on: branches/distutils_scons_command
___________________________________________________________________
Name: svnmerge-integrated
- /branches/cleanconfig_rtm:1-4610 /branches/distutils-revamp:1-2752 /branches/multicore:1-3687 /branches/numpy.scons:1-4484 /trunk:1-4620
+ /branches/cleanconfig_rtm:1-4610 /branches/distutils-revamp:1-2752 /branches/distutils_scons_command:1-4619 /branches/multicore:1-3687 /branches/numpy.scons:1-4484 /trunk:1-2871
Modified: branches/distutils_scons_command/numpy/core/include/numpy/ndarrayobject.h
===================================================================
--- branches/distutils_scons_command/numpy/core/include/numpy/ndarrayobject.h 2007-12-22 06:58:15 UTC (rev 4631)
+++ branches/distutils_scons_command/numpy/core/include/numpy/ndarrayobject.h 2007-12-22 08:10:00 UTC (rev 4632)
@@ -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/distutils_scons_command/numpy/core/setup.py
===================================================================
--- branches/distutils_scons_command/numpy/core/setup.py 2007-12-22 06:58:15 UTC (rev 4631)
+++ branches/distutils_scons_command/numpy/core/setup.py 2007-12-22 08:10:00 UTC (rev 4632)
@@ -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
@@ -53,12 +58,12 @@
raise SystemError,"Failed to test configuration. "\
"See previous error messages for more information."
- # Python 2.3 causes a segfault when
- # trying to re-acquire the thread-state
- # which is done in error-handling
- # ufunc code. NPY_ALLOW_C_API and friends
- # cause the segfault. So, we disable threading
- # for now.
+ # Python 2.3 causes a segfault when
+ # trying to re-acquire the thread-state
+ # which is done in error-handling
+ # ufunc code. NPY_ALLOW_C_API and friends
+ # cause the segfault. So, we disable threading
+ # for now.
if sys.version[:5] < '2.4.2':
nosmp = 1
else:
@@ -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,79 @@
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."""
+ if sys.platform == 'win32':
+ target = target.replace('\\','\\\\')
+ # 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/distutils_scons_command/numpy/core/src/arraytypes.inc.src
===================================================================
--- branches/distutils_scons_command/numpy/core/src/arraytypes.inc.src 2007-12-22 06:58:15 UTC (rev 4631)
+++ branches/distutils_scons_command/numpy/core/src/arraytypes.inc.src 2007-12-22 08:10:00 UTC (rev 4632)
@@ -1,4 +1,5 @@
/* -*- c -*- */
+#include "config.h"
static longlong
MyPyLong_AsLongLong(PyObject *vv)
Modified: branches/distutils_scons_command/numpy/core/src/umathmodule.c.src
===================================================================
--- branches/distutils_scons_command/numpy/core/src/umathmodule.c.src 2007-12-22 06:58:15 UTC (rev 4631)
+++ branches/distutils_scons_command/numpy/core/src/umathmodule.c.src 2007-12-22 08:10:00 UTC (rev 4632)
@@ -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/distutils_scons_command/numpy/distutils/command/config.py
===================================================================
--- branches/distutils_scons_command/numpy/distutils/command/config.py 2007-12-22 06:58:15 UTC (rev 4631)
+++ branches/distutils_scons_command/numpy/distutils/command/config.py 2007-12-22 08:10:00 UTC (rev 4632)
@@ -101,6 +101,21 @@
(body, headers, include_dirs,
libraries, library_dirs, lang))
+ def check_decl(self, symbol,
+ headers=None, include_dirs=None):
+ self._check_compiler()
+ body = """
+int main()
+{
+#ifndef %s
+ (void) %s;
+#endif
+ ;
+ return 0;
+}""" % (symbol, symbol)
+
+ return self.try_compile(body, headers, include_dirs)
+
def check_func(self, func,
headers=None, include_dirs=None,
libraries=None, library_dirs=None,
Modified: branches/distutils_scons_command/numpy/lib/arraysetops.py
===================================================================
--- branches/distutils_scons_command/numpy/lib/arraysetops.py 2007-12-22 06:58:15 UTC (rev 4631)
+++ branches/distutils_scons_command/numpy/lib/arraysetops.py 2007-12-22 08:10:00 UTC (rev 4632)
@@ -201,9 +201,13 @@
numpy.lib.arraysetops has a number of other functions for performing set
operations on arrays.
"""
- zlike = nm.zeros_like
+ ar1 = nm.asarray( ar1 )
+ ar2 = nm.asarray( ar2 )
ar = nm.concatenate( (ar1, ar2 ) )
- tt = nm.concatenate( (zlike( ar1 ), zlike( ar2 ) + 1) )
+ b1 = nm.zeros( ar1.shape, dtype = nm.int8 )
+ b2 = nm.ones( ar2.shape, dtype = nm.int8 )
+ tt = nm.concatenate( (b1, b2) )
+
# We need this to be a stable sort, so always use 'mergesort' here. The
# values from the first array should always come before the values from the
# second array.
@@ -212,7 +216,6 @@
aux2 = tt[perm]
# flag = ediff1d( aux, 1 ) == 0
flag = nm.concatenate( (aux[1:] == aux[:-1], [False] ) )
-
ii = nm.where( flag * aux2 )[0]
aux = perm[ii+1]
perm[ii+1] = perm[ii]
Modified: branches/distutils_scons_command/numpy/lib/tests/test_arraysetops.py
===================================================================
--- branches/distutils_scons_command/numpy/lib/tests/test_arraysetops.py 2007-12-22 06:58:15 UTC (rev 4631)
+++ branches/distutils_scons_command/numpy/lib/tests/test_arraysetops.py 2007-12-22 08:10:00 UTC (rev 4632)
@@ -145,6 +145,10 @@
assert_array_equal([], setdiff1d([],[]))
+ def check_setdiff1d_char_array(self):
+ a = numpy.array(['a','b','c'])
+ b = numpy.array(['a','b','s'])
+ assert_array_equal(setdiff1d(a,b),numpy.array(['c']))
##
# 03.11.2005, c
More information about the Numpy-svn
mailing list