From numpy-svn at scipy.org Wed Jan 2 12:04:17 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Wed, 2 Jan 2008 11:04:17 -0600 (CST) Subject: [Numpy-svn] r4673 - in trunk/numpy: lib/tests testing Message-ID: <20080102170417.3EA3C39C31A@new.scipy.org> Author: oliphant Date: 2008-01-02 11:04:15 -0600 (Wed, 02 Jan 2008) New Revision: 4673 Modified: trunk/numpy/lib/tests/test_format.py trunk/numpy/testing/utils.py Log: Removed dependency on nose.tools. Ripped nose.tools.raise and placed it in numpy.testing Modified: trunk/numpy/lib/tests/test_format.py =================================================================== --- trunk/numpy/lib/tests/test_format.py 2007-12-30 17:57:53 UTC (rev 4672) +++ trunk/numpy/lib/tests/test_format.py 2008-01-02 17:04:15 UTC (rev 4673) @@ -280,10 +280,8 @@ import shutil import tempfile -from nose.tools import raises - import numpy as np -from numpy.testing import assert_array_equal +from numpy.testing import assert_array_equal, raises from numpy.lib import format Modified: trunk/numpy/testing/utils.py =================================================================== --- trunk/numpy/testing/utils.py 2007-12-30 17:57:53 UTC (rev 4672) +++ trunk/numpy/testing/utils.py 2008-01-02 17:04:15 UTC (rev 4673) @@ -11,7 +11,7 @@ __all__ = ['assert_equal', 'assert_almost_equal','assert_approx_equal', 'assert_array_equal', 'assert_array_less', 'assert_string_equal', 'assert_array_almost_equal', 'jiffies', 'memusage', 'rand', - 'runstring'] + 'runstring', 'raises'] def rand(*args): """Returns an array of random numbers with the given shape. @@ -270,3 +270,37 @@ if not diff_list: return msg = 'Differences in strings:\n%s' % (''.join(diff_list)).rstrip() assert actual==desired, msg + +# Ripped from nose.tools +def raises(*exceptions): + """Test must raise one of expected exceptions to pass. + + Example use:: + + @raises(TypeError, ValueError) + def test_raises_type_error(): + raise TypeError("This test passes") + + @raises(Exception): + def test_that_fails_by_passing(): + pass + + If you want to test many assertions about exceptions in a single test, + you may want to use `assert_raises` instead. + """ + valid = ' or '.join([e.__name__ for e in exceptions]) + def decorate(func): + name = func.__name__ + def newfunc(*arg, **kw): + try: + func(*arg, **kw) + except exceptions: + pass + except: + raise + else: + message = "%s() did not raise %s" % (name, valid) + raise AssertionError(message) + newfunc = make_decorator(func)(newfunc) + return newfunc + return decorate From numpy-svn at scipy.org Sat Jan 5 13:44:30 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 5 Jan 2008 12:44:30 -0600 (CST) Subject: [Numpy-svn] r4674 - trunk/numpy Message-ID: <20080105184430.A8D4E39C0DC@new.scipy.org> Author: cookedm Date: 2008-01-05 12:44:28 -0600 (Sat, 05 Jan 2008) New Revision: 4674 Modified: trunk/numpy/matlib.py Log: Fix regression in r4659; matlib.py should use from numpy import * Modified: trunk/numpy/matlib.py =================================================================== --- trunk/numpy/matlib.py 2008-01-02 17:04:15 UTC (rev 4673) +++ trunk/numpy/matlib.py 2008-01-05 18:44:28 UTC (rev 4674) @@ -1,6 +1,7 @@ import numpy as np -from numpy import ndarray, array from numpy.core.defmatrix import matrix, asmatrix +# need * as we're copying the numpy namespace +from numpy import * __version__ = np.__version__ From numpy-svn at scipy.org Sun Jan 6 04:28:40 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 03:28:40 -0600 (CST) Subject: [Numpy-svn] r4675 - branches/distutils_scons_command/numpy/distutils Message-ID: <20080106092840.1A30E39C10E@new.scipy.org> Author: cdavid Date: 2008-01-06 03:28:27 -0600 (Sun, 06 Jan 2008) New Revision: 4675 Modified: branches/distutils_scons_command/numpy/distutils/misc_util.py Log: Add scons_make_config function to numpy distutils Configuration Modified: branches/distutils_scons_command/numpy/distutils/misc_util.py =================================================================== --- branches/distutils_scons_command/numpy/distutils/misc_util.py 2008-01-05 18:44:28 UTC (rev 4674) +++ branches/distutils_scons_command/numpy/distutils/misc_util.py 2008-01-06 09:28:27 UTC (rev 4675) @@ -1441,6 +1441,12 @@ """ self.py_modules.append((self.name,name,generate_config_py)) + def scons_make_config_py(self, name = '__config__'): + """Generate package __config__.py file containing system_info + information used during building the package. + """ + self.py_modules.append((self.name, name, scons_generate_config_py)) + def get_info(self,*names): """Get resources information. """ From numpy-svn at scipy.org Sun Jan 6 04:38:52 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 03:38:52 -0600 (CST) Subject: [Numpy-svn] r4676 - branches Message-ID: <20080106093852.6643F39C139@new.scipy.org> Author: cdavid Date: 2008-01-06 03:38:40 -0600 (Sun, 06 Jan 2008) New Revision: 4676 Added: branches/build_with_scons/ Log: Create build_with_scons branch, which will make numpy buildable with numscons Copied: branches/build_with_scons (from rev 4675, trunk) From numpy-svn at scipy.org Sun Jan 6 04:39:39 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 03:39:39 -0600 (CST) Subject: [Numpy-svn] r4677 - trunk Message-ID: <20080106093939.3E03C39C114@new.scipy.org> Author: cdavid Date: 2008-01-06 03:39:33 -0600 (Sun, 06 Jan 2008) New Revision: 4677 Modified: trunk/ Log: Initialized merge tracking via "svnmerge" with revisions "1-4676" from http://svn.scipy.org/svn/numpy/branches/build_with_scons Property changes on: trunk ___________________________________________________________________ Name: svnmerge-integrated - /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 + /branches/build_with_scons:1-4676 /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 From numpy-svn at scipy.org Sun Jan 6 05:10:08 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 04:10:08 -0600 (CST) Subject: [Numpy-svn] r4678 - in branches/build_with_scons: . numpy/core numpy/core/include/numpy numpy/core/src numpy/distutils numpy/distutils/command Message-ID: <20080106101008.601CC39C1AC@new.scipy.org> Author: cdavid Date: 2008-01-06 04:09:33 -0600 (Sun, 06 Jan 2008) New Revision: 4678 Modified: branches/build_with_scons/ branches/build_with_scons/numpy/core/include/numpy/ndarrayobject.h branches/build_with_scons/numpy/core/setup.py branches/build_with_scons/numpy/core/src/arraytypes.inc.src branches/build_with_scons/numpy/core/src/umathmodule.c.src branches/build_with_scons/numpy/distutils/command/config.py branches/build_with_scons/numpy/distutils/misc_util.py Log: Merged revisions 4612-4617,4628-4631,4638 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. ........ ................ r4638 | cdavid | 2007-12-22 18:21:25 +0900 (Sat, 22 Dec 2007) | 1 line Get MATHLIB from numpyconfig.h, not from config.h anymore ................ Property changes on: branches/build_with_scons ___________________________________________________________________ Name: svnmerge-integrated - /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 + /branches/cleanconfig_rtm:1-4677 /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/build_with_scons/numpy/core/include/numpy/ndarrayobject.h =================================================================== --- branches/build_with_scons/numpy/core/include/numpy/ndarrayobject.h 2008-01-06 09:39:33 UTC (rev 4677) +++ branches/build_with_scons/numpy/core/include/numpy/ndarrayobject.h 2008-01-06 10:09:33 UTC (rev 4678) @@ -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/build_with_scons/numpy/core/setup.py =================================================================== --- branches/build_with_scons/numpy/core/setup.py 2008-01-06 09:39:33 UTC (rev 4677) +++ branches/build_with_scons/numpy/core/setup.py 2008-01-06 10:09:33 UTC (rev 4678) @@ -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 +#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/build_with_scons/numpy/core/src/arraytypes.inc.src =================================================================== --- branches/build_with_scons/numpy/core/src/arraytypes.inc.src 2008-01-06 09:39:33 UTC (rev 4677) +++ branches/build_with_scons/numpy/core/src/arraytypes.inc.src 2008-01-06 10:09:33 UTC (rev 4678) @@ -1,4 +1,5 @@ /* -*- c -*- */ +#include "config.h" static longlong MyPyLong_AsLongLong(PyObject *vv) Modified: branches/build_with_scons/numpy/core/src/umathmodule.c.src =================================================================== --- branches/build_with_scons/numpy/core/src/umathmodule.c.src 2008-01-06 09:39:33 UTC (rev 4677) +++ branches/build_with_scons/numpy/core/src/umathmodule.c.src 2008-01-06 10:09:33 UTC (rev 4678) @@ -5,6 +5,7 @@ #define _UMATHMODULE #include "numpy/ufuncobject.h" #include "abstract.h" +#include "config.h" #include /* A whole slew of basic math functions are provided originally Modified: branches/build_with_scons/numpy/distutils/command/config.py =================================================================== --- branches/build_with_scons/numpy/distutils/command/config.py 2008-01-06 09:39:33 UTC (rev 4677) +++ branches/build_with_scons/numpy/distutils/command/config.py 2008-01-06 10:09:33 UTC (rev 4678) @@ -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/build_with_scons/numpy/distutils/misc_util.py =================================================================== --- branches/build_with_scons/numpy/distutils/misc_util.py 2008-01-06 09:39:33 UTC (rev 4677) +++ branches/build_with_scons/numpy/distutils/misc_util.py 2008-01-06 10:09:33 UTC (rev 4678) @@ -112,11 +112,11 @@ return minrelpath(joined) def get_mathlibs(path=None): - """Return the MATHLIB line from config.h + """Return the MATHLIB line from numpyconfig.h """ if path is None: path = os.path.join(get_numpy_include_dirs()[0], 'numpy') - config_file = os.path.join(path,'config.h') + config_file = os.path.join(path,'numpyconfig.h') fid = open(config_file) mathlibs = [] s = '#define MATHLIB' From numpy-svn at scipy.org Sun Jan 6 05:31:12 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 04:31:12 -0600 (CST) Subject: [Numpy-svn] r4679 - branches/build_with_scons/numpy/distutils Message-ID: <20080106103112.7554139C060@new.scipy.org> Author: cdavid Date: 2008-01-06 04:31:05 -0600 (Sun, 06 Jan 2008) New Revision: 4679 Added: branches/build_with_scons/numpy/distutils/numpy_distribution.py Modified: branches/build_with_scons/numpy/distutils/core.py Log: Use a custom NumpyDistribution instead of distutils Distribution, to handle scons scripts. Modified: branches/build_with_scons/numpy/distutils/core.py =================================================================== --- branches/build_with_scons/numpy/distutils/core.py 2008-01-06 10:09:33 UTC (rev 4678) +++ branches/build_with_scons/numpy/distutils/core.py 2008-01-06 10:31:05 UTC (rev 4679) @@ -21,6 +21,7 @@ import distutils.dist from numpy.distutils.extension import Extension +from numpy.distutils.numpy_distribution import NumpyDistribution from numpy.distutils.command import config, config_compiler, \ build, build_py, build_ext, build_clib, build_src, build_scripts, \ sdist, install_data, install_headers, install, bdist_rpm @@ -95,9 +96,10 @@ # class is local to a function in setuptools.command.easy_install if dist is not None and \ 'DistributionWithoutHelpCommands' in repr(dist): + raise NotImplementedError("setuptools not supported yet for numpy.scons branch") dist = None if always and dist is None: - dist = distutils.dist.Distribution() + dist = NumpyDistribution() return dist def _exit_interactive_session(_cache=[]): @@ -175,6 +177,9 @@ and 'headers' not in new_attr: new_attr['headers'] = [] + # Use our custom NumpyDistribution class instead of distutils' one + new_attr['distclass'] = NumpyDistribution + return old_setup(**new_attr) def _check_append_library(libraries, item): Added: branches/build_with_scons/numpy/distutils/numpy_distribution.py =================================================================== --- branches/build_with_scons/numpy/distutils/numpy_distribution.py 2008-01-06 10:09:33 UTC (rev 4678) +++ branches/build_with_scons/numpy/distutils/numpy_distribution.py 2008-01-06 10:31:05 UTC (rev 4679) @@ -0,0 +1,28 @@ +# XXX: Handle setuptools ? +from distutils.core import Distribution + +# This class is used because we add new files (sconscripts, and so on) with the +# scons command +class NumpyDistribution(Distribution): + def __init__(self, attrs = None): + # A list of (sconscripts, pre_hook, post_hook, src, parent_names) + self.scons_data = [] + Distribution.__init__(self, attrs) + + def has_scons_scripts(self): + return bool(self.scons_data) + + def get_scons_scripts(self): + return [i[0] for i in self.scons_data] + + def get_scons_pre_hooks(self): + return [i[1] for i in self.scons_data] + + def get_scons_post_hooks(self): + return [i[2] for i in self.scons_data] + + def get_scons_sources(self): + return [i[3] for i in self.scons_data] + + def get_scons_parent_names(self): + return [i[4] for i in self.scons_data] From numpy-svn at scipy.org Sun Jan 6 05:32:20 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 04:32:20 -0600 (CST) Subject: [Numpy-svn] r4680 - in branches/build_with_scons/numpy/distutils: . command Message-ID: <20080106103220.C2C1F39C060@new.scipy.org> Author: cdavid Date: 2008-01-06 04:32:14 -0600 (Sun, 06 Jan 2008) New Revision: 4680 Added: branches/build_with_scons/numpy/distutils/command/scons.py Modified: branches/build_with_scons/numpy/distutils/core.py Log: Add scons command to numpy distutils. Added: branches/build_with_scons/numpy/distutils/command/scons.py =================================================================== --- branches/build_with_scons/numpy/distutils/command/scons.py 2008-01-06 10:31:05 UTC (rev 4679) +++ branches/build_with_scons/numpy/distutils/command/scons.py 2008-01-06 10:32:14 UTC (rev 4680) @@ -0,0 +1,322 @@ +import os +import os.path +from os.path import join as pjoin, dirname as pdirname + +from distutils.errors import DistutilsPlatformError +from distutils.errors import DistutilsExecError, DistutilsSetupError + +from numpy.distutils.command.build_ext import build_ext as old_build_ext +from numpy.distutils.ccompiler import CCompiler +from numpy.distutils.fcompiler import FCompiler +from numpy.distutils.exec_command import find_executable +from numpy.distutils import log +from numpy.distutils.misc_util import get_numpy_include_dirs + +def get_scons_build_dir(): + """Return the top path where everything produced by scons will be put. + + The path is relative to the top setup.py""" + return os.path.join('build', 'scons') + +def get_scons_configres_dir(): + """Return the top path where everything produced by scons will be put. + + The path is relative to the top setup.py""" + return os.path.join('build', 'scons-configres') + +def get_scons_configres_filename(): + """Return the top path where everything produced by scons will be put. + + The path is relative to the top setup.py""" + return '__configres.py' + +def get_scons_local_path(): + """This returns the full path where scons.py for scons-local is located.""" + import numpy.distutils + return pjoin(pdirname(numpy.distutils.__file__), 'scons-local') + +def get_python_exec_invoc(): + """This returns the python executable from which this file is invocated.""" + # Do we need to take into account the PYTHONPATH, in a cross platform way, + # that is the string returned can be executed directly on supported + # platforms, and the sys.path of the executed python should be the same + # than the caller ? This may not be necessary, since os.system is said to + # take into accound os.environ. This actually also works for my way of + # using "local python", using the alias facility of bash. + import sys + return sys.executable + +def dirl_to_str(dirlist): + """Given a list of directories, returns a string where the paths are + concatenated by the path separator. + + example: ['foo/bar', 'bar/foo'] will return 'foo/bar:bar/foo'.""" + return os.pathsep.join(dirlist) + +def dist2sconscc(compiler): + """This converts the name passed to distutils to scons name convention (C + compiler). compiler should be a CCompiler instance. + + Example: + --compiler=intel -> intelc""" + compiler_type = compiler.compiler_type + if compiler_type == 'msvc': + return 'msvc' + elif compiler_type == 'intel': + return 'intelc' + elif compiler_type == 'mingw32': + return 'mingw' + else: + return compiler.compiler[0] + +def dist2sconsfc(compiler): + """This converts the name passed to distutils to scons name convention + (Fortran compiler). The argument should be a FCompiler instance. + + Example: + --fcompiler=intel -> ifort on linux, ifl on windows""" + if compiler.compiler_type == 'intel': + #raise NotImplementedError('FIXME: intel fortran compiler name ?') + return 'ifort' + elif compiler.compiler_type == 'gnu': + return 'g77' + elif compiler.compiler_type == 'gnu95': + return 'gfortran' + else: + # XXX: Just give up for now, and use generic fortran compiler + return 'fortran' + +def dist2sconscxx(compiler): + """This converts the name passed to distutils to scons name convention + (C++ compiler). The argument should be a Compiler instance.""" + if compiler.compiler_type == 'gnu': + return 'g++' + else: + return 'c++' + return compiler.compiler_cxx[0] + +def get_compiler_executable(compiler): + """For any give CCompiler instance, this gives us the name of C compiler + (the actual executable). + + NOTE: does NOT work with FCompiler instances.""" + # Geez, why does distutils has no common way to get the compiler name... + if compiler.compiler_type == 'msvc': + # this is harcoded in distutils... A bit cleaner way would be to + # initialize the compiler instance and then get compiler.cc, but this + # may be costly: we really just want a string. + # XXX: we need to initialize the compiler anyway, so do not use + # hardcoded string + #compiler.initialize() + #print compiler.cc + return 'cl.exe' + else: + return compiler.compiler[0] + +def get_f77_compiler_executable(compiler): + """For any give FCompiler instance, this gives us the name of F77 compiler + (the actual executable).""" + return compiler.compiler_f77[0] + +def get_cxxcompiler_executable(compiler): + """For any give CCompiler instance, this gives us the name of CXX compiler + (the actual executable). + + NOTE: does NOT work with FCompiler instances.""" + # Geez, why does distutils has no common way to get the compiler name... + if compiler.compiler_type == 'msvc': + # this is harcoded in distutils... A bit cleaner way would be to + # initialize the compiler instance and then get compiler.cc, but this + # may be costly: we really just want a string. + # XXX: we need to initialize the compiler anyway, so do not use + # hardcoded string + #compiler.initialize() + #print compiler.cc + return 'cl.exe' + else: + return compiler.compiler_cxx[0] + +def get_tool_path(compiler): + """Given a distutils.ccompiler.CCompiler class, returns the path of the + toolset related to C compilation.""" + fullpath_exec = find_executable(get_compiler_executable(compiler)) + if fullpath_exec: + fullpath = pdirname(fullpath_exec) + else: + raise DistutilsSetupError("Could not find compiler executable info for scons") + return fullpath + +def get_f77_tool_path(compiler): + """Given a distutils.ccompiler.FCompiler class, returns the path of the + toolset related to F77 compilation.""" + fullpath_exec = find_executable(get_f77_compiler_executable(compiler)) + if fullpath_exec: + fullpath = pdirname(fullpath_exec) + else: + raise DistutilsSetupError("Could not find F77 compiler executable "\ + "info for scons") + return fullpath + +def get_cxx_tool_path(compiler): + """Given a distutils.ccompiler.CCompiler class, returns the path of the + toolset related to C compilation.""" + fullpath_exec = find_executable(get_cxxcompiler_executable(compiler)) + if fullpath_exec: + fullpath = pdirname(fullpath_exec) + else: + raise DistutilsSetupError("Could not find compiler executable info for scons") + return fullpath + +def protect_path(path): + """Convert path (given as a string) to something the shell will have no + problem to understand (space, etc... problems).""" + # XXX: to this correctly, this is totally bogus for now (does not check for + # already quoted path, for example). + return '"' + path + '"' + +class scons(old_build_ext): + # XXX: add an option to the scons command for configuration (auto/force/cache). + description = "Scons builder" + user_options = old_build_ext.user_options + \ + [('jobs=', None, + "specify number of worker threads when executing scons"), + ('scons-tool-path=', None, 'specify additional path '\ + '(absolute) to look for scons tools'), + ('silent=', None, 'specify whether scons output should be silent '\ + '(1), super silent (2) or not (0, default)')] + + def initialize_options(self): + old_build_ext.initialize_options(self) + self.jobs = None + self.silent = 0 + self.scons_tool_path = '' + # If true, we bypass distutils to find the c compiler altogether. This + # is to be used in desperate cases (like incompatible visual studio + # version). + self._bypass_distutils_cc = False + self.scons_compiler = None + self.scons_compiler_path = None + self.scons_fcompiler = None + + def finalize_options(self): + old_build_ext.finalize_options(self) + if self.distribution.has_scons_scripts(): + self.sconscripts = self.distribution.get_scons_scripts() + self.pre_hooks = self.distribution.get_scons_pre_hooks() + self.post_hooks = self.distribution.get_scons_post_hooks() + self.pkg_names = self.distribution.get_scons_parent_names() + else: + self.sconscripts = [] + self.pre_hooks = [] + self.post_hooks = [] + self.pkg_names = [] + + # Try to get the same compiler than the ones used by distutils: this is + # non trivial because distutils and scons have totally different + # conventions on this one (distutils uses PATH from user's environment, + # whereas scons uses standard locations). The way we do it is once we + # got the c compiler used, we use numpy.distutils function to get the + # full path, and add the path to the env['PATH'] variable in env + # instance (this is done in numpy.distutils.scons module). + + # XXX: The logic to bypass distutils is ... not so logic. + compiler_type = self.compiler + if compiler_type == 'msvc': + self._bypass_distutils_cc = True + from numpy.distutils.ccompiler import new_compiler + try: + distutils_compiler = new_compiler(compiler=compiler_type, + verbose=self.verbose, + dry_run=self.dry_run, + force=self.force) + distutils_compiler.customize(self.distribution) + # This initialization seems necessary, sometimes, for find_executable to work... + if hasattr(distutils_compiler, 'initialize'): + distutils_compiler.initialize() + self.scons_compiler = dist2sconscc(distutils_compiler) + self.scons_compiler_path = protect_path(get_tool_path(distutils_compiler)) + except DistutilsPlatformError, e: + if not self._bypass_distutils_cc: + raise e + else: + self.scons_compiler = compiler_type + + # We do the same for the fortran compiler ... + fcompiler_type = self.fcompiler + from numpy.distutils.fcompiler import new_fcompiler + self.fcompiler = new_fcompiler(compiler = fcompiler_type, + verbose = self.verbose, + dry_run = self.dry_run, + force = self.force) + if self.fcompiler is not None: + self.fcompiler.customize(self.distribution) + + # And the C++ compiler + cxxcompiler = new_compiler(compiler = compiler_type, + verbose = self.verbose, + dry_run = self.dry_run, + force = self.force) + if cxxcompiler is not None: + cxxcompiler.customize(self.distribution, need_cxx = 1) + cxxcompiler.customize_cmd(self) + self.cxxcompiler = cxxcompiler.cxx_compiler() + #print self.cxxcompiler.compiler_cxx[0] + + def run(self): + # XXX: when a scons script is missing, scons only prints warnings, and + # does not return a failure (status is 0). We have to detect this from + # distutils (this cannot work for recursive scons builds...) + + # XXX: passing everything at command line may cause some trouble where + # there is a size limitation ? What is the standard solution in thise + # case ? + + scons_exec = get_python_exec_invoc() + scons_exec += ' ' + protect_path(pjoin(get_scons_local_path(), 'scons.py')) + + for sconscript, pre_hook, post_hook, pkg_name in zip(self.sconscripts, + self.pre_hooks, self.post_hooks, + self.pkg_names): + if pre_hook: + pre_hook() + + cmd = [scons_exec, "-f", sconscript, '-I.'] + if self.jobs: + cmd.append(" --jobs=%d" % int(self.jobs)) + cmd.append('scons_tool_path="%s"' % self.scons_tool_path) + cmd.append('src_dir="%s"' % pdirname(sconscript)) + cmd.append('pkg_name="%s"' % pkg_name) + #cmd.append('distutils_libdir=%s' % protect_path(pjoin(self.build_lib, + # pdirname(sconscript)))) + cmd.append('distutils_libdir=%s' % protect_path(pjoin(self.build_lib))) + + if not self._bypass_distutils_cc: + cmd.append('cc_opt=%s' % self.scons_compiler) + cmd.append('cc_opt_path=%s' % self.scons_compiler_path) + else: + cmd.append('cc_opt=%s' % self.scons_compiler) + + + if self.fcompiler: + cmd.append('f77_opt=%s' % dist2sconsfc(self.fcompiler)) + cmd.append('f77_opt_path=%s' % protect_path(get_f77_tool_path(self.fcompiler))) + + if self.cxxcompiler: + cmd.append('cxx_opt=%s' % dist2sconscxx(self.cxxcompiler)) + cmd.append('cxx_opt_path=%s' % protect_path(get_cxx_tool_path(self.cxxcompiler))) + + cmd.append('include_bootstrap=%s' % dirl_to_str(get_numpy_include_dirs())) + if self.silent: + if int(self.silent) == 1: + cmd.append('-Q') + elif int(self.silent) == 2: + cmd.append('-s') + cmdstr = ' '.join(cmd) + log.info("Executing scons command: %s ", cmdstr) + st = os.system(cmdstr) + if st: + print "status is %d" % st + raise DistutilsExecError("Error while executing scons command "\ + "%s (see above)" % cmdstr) + if post_hook: + post_hook() Modified: branches/build_with_scons/numpy/distutils/core.py =================================================================== --- branches/build_with_scons/numpy/distutils/core.py 2008-01-06 10:31:05 UTC (rev 4679) +++ branches/build_with_scons/numpy/distutils/core.py 2008-01-06 10:32:14 UTC (rev 4680) @@ -24,7 +24,7 @@ from numpy.distutils.numpy_distribution import NumpyDistribution from numpy.distutils.command import config, config_compiler, \ build, build_py, build_ext, build_clib, build_src, build_scripts, \ - sdist, install_data, install_headers, install, bdist_rpm + sdist, install_data, install_headers, install, bdist_rpm, scons from numpy.distutils.misc_util import get_data_files, is_sequence, is_string numpy_cmdclass = {'build': build.build, @@ -37,6 +37,7 @@ 'build_py': build_py.build_py, 'build_clib': build_clib.build_clib, 'sdist': sdist.sdist, + 'scons': scons.scons, 'install_data': install_data.install_data, 'install_headers': install_headers.install_headers, 'install': install.install, From numpy-svn at scipy.org Sun Jan 6 05:33:04 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 04:33:04 -0600 (CST) Subject: [Numpy-svn] r4681 - branches/build_with_scons/numpy/distutils Message-ID: <20080106103304.30F1239C060@new.scipy.org> Author: cdavid Date: 2008-01-06 04:33:00 -0600 (Sun, 06 Jan 2008) New Revision: 4681 Modified: branches/build_with_scons/numpy/distutils/misc_util.py Log: Add the infrastructure to add SConstruct files in numpy.distutils.Configuration. Modified: branches/build_with_scons/numpy/distutils/misc_util.py =================================================================== --- branches/build_with_scons/numpy/distutils/misc_util.py 2008-01-06 10:32:14 UTC (rev 4680) +++ branches/build_with_scons/numpy/distutils/misc_util.py 2008-01-06 10:33:00 UTC (rev 4681) @@ -574,7 +574,7 @@ class Configuration(object): _list_keys = ['packages', 'ext_modules', 'data_files', 'include_dirs', - 'libraries', 'headers', 'scripts', 'py_modules'] + 'libraries', 'headers', 'scripts', 'py_modules', 'scons_data'] _dict_keys = ['package_dir'] _extra_keys = ['name', 'version'] @@ -1165,6 +1165,50 @@ self.warn('distutils distribution has been initialized,'\ ' it may be too late to add a library '+ name) + def add_sconscript(self, sconscript, subpackage_path=None, + standalone = False, pre_hook = None, + post_hook = None, source_files = None): + """Add a sconscript to configuration. + + pre_hook and post hook should be sequences of callable, which will be + use before and after executing scons. """ + if standalone: + parent_name = None + else: + parent_name = self.name + + dist = self.get_distribution() + # Convert the sconscript name to a relative filename (relative from top + # setup.py's directory) + fullsconsname = self.paths(sconscript)[0] + + # XXX: Think about a way to automatically register source files from + # scons... + full_source_files = [] + if source_files: + full_source_files.extend([self.paths(i)[0] for i in source_files]) + + if dist is not None: + dist.scons_data.append((fullsconsname, + pre_hook, + post_hook, + full_source_files, + parent_name)) + self.warn('distutils distribution has been initialized,'\ + ' it may be too late to add a subpackage '+ subpackage_name) + # XXX: we add a fake extension, to correctly initialize some + # options in distutils command. + dist.add_extension('', sources = []) + else: + self.scons_data.append((fullsconsname, + pre_hook, + post_hook, + full_source_files, + parent_name)) + # XXX: we add a fake extension, to correctly initialize some + # options in distutils command. + self.add_extension('', sources = []) + def add_scripts(self,*files): """Add scripts to configuration. """ From numpy-svn at scipy.org Sun Jan 6 05:34:44 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 04:34:44 -0600 (CST) Subject: [Numpy-svn] r4682 - branches/build_with_scons/numpy/distutils Message-ID: <20080106103444.99E9C39C00C@new.scipy.org> Author: cdavid Date: 2008-01-06 04:34:40 -0600 (Sun, 06 Jan 2008) New Revision: 4682 Modified: branches/build_with_scons/numpy/distutils/misc_util.py Log: add an option to change setup filenames to numpy.distutils.Configuration Modified: branches/build_with_scons/numpy/distutils/misc_util.py =================================================================== --- branches/build_with_scons/numpy/distutils/misc_util.py 2008-01-06 10:33:00 UTC (rev 4681) +++ branches/build_with_scons/numpy/distutils/misc_util.py 2008-01-06 10:34:40 UTC (rev 4682) @@ -586,6 +586,7 @@ top_path=None, package_path=None, caller_level=1, + setup_name='setup.py', **attrs): """Construct configuration instance of a package. @@ -674,6 +675,8 @@ if caller_instance.options['delegate_options_to_subpackages']: self.set_options(**caller_instance.options) + self.setup_name = setup_name + def todict(self): """Return configuration distionary suitable for passing to distutils.core.setup() function. @@ -795,7 +798,7 @@ else: subpackage_path = njoin([subpackage_path] + l[:-1]) subpackage_path = self.paths([subpackage_path])[0] - setup_py = njoin(subpackage_path, 'setup.py') + setup_py = njoin(subpackage_path, self.setup_name) if not self.options['ignore_setup_xxx_py']: if not os.path.isfile(setup_py): setup_py = njoin(subpackage_path, From numpy-svn at scipy.org Sun Jan 6 05:35:48 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 04:35:48 -0600 (CST) Subject: [Numpy-svn] r4683 - branches/build_with_scons/numpy/distutils Message-ID: <20080106103548.4218F39C00C@new.scipy.org> Author: cdavid Date: 2008-01-06 04:35:44 -0600 (Sun, 06 Jan 2008) New Revision: 4683 Modified: branches/build_with_scons/numpy/distutils/misc_util.py Log: Add facilities to generate config file for future sconsified modules. Modified: branches/build_with_scons/numpy/distutils/misc_util.py =================================================================== --- branches/build_with_scons/numpy/distutils/misc_util.py 2008-01-06 10:34:40 UTC (rev 4682) +++ branches/build_with_scons/numpy/distutils/misc_util.py 2008-01-06 10:35:44 UTC (rev 4683) @@ -1472,6 +1472,51 @@ # else running numpy/core/setup.py return include_dirs +def scons_generate_config_py(target): + """generate config.py file containing system_info information + used during building the package. + + usage: + config['py_modules'].append((packagename, '__config__',generate_config_py)) + """ + from distutils.dir_util import mkpath + import imp + d = {} + mkpath(os.path.dirname(target)) + f = open(target, 'w') + f.write('# this file is generated by %s\n' % (os.path.abspath(sys.argv[0]))) + f.write('# it contains system_info results at the time of building this package.\n') + f.write('__all__ = ["show"]\n\n') + confdir = get_scons_configres_dir() + confilename = get_scons_configres_filename() + for root, dirs, files in os.walk(confdir): + if files: + file = os.path.join(root, confilename) + assert root.startswith(confdir) + pkg_name = '.'.join(root[len(confdir)+1:].split(os.sep)) + fid = open(file, 'r') + try: + config_mod = imp.load_module(pkg_name, fid, confilename, + ('.py', 'U', 1)) + d[pkg_name] = config_mod.config + finally: + fid.close() + # d is a dictionary whose keys are package names, and values the + # corresponding configuration. Each configuration is itself a dictionary + # (lib : libinfo) + f.write('_config = %s\n' % d) + f.write(r''' +def show(): + for pkg, config in _config.items(): + print "package %s configuration:" % pkg + for lib, libc in config.items(): + print ' %s' % lib + for line in libc.split('\n'): + print '\t%s' % line + ''') + f.close() + return target + ######################### def default_config_dict(name = None, parent_name = None, local_path=None): From numpy-svn at scipy.org Sun Jan 6 05:42:29 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 04:42:29 -0600 (CST) Subject: [Numpy-svn] r4684 - branches/build_with_scons/numpy/distutils/command Message-ID: <20080106104229.C95C639C035@new.scipy.org> Author: cdavid Date: 2008-01-06 04:42:26 -0600 (Sun, 06 Jan 2008) New Revision: 4684 Modified: branches/build_with_scons/numpy/distutils/command/scons.py Log: Use separate numscons package instead of internal local copy Modified: branches/build_with_scons/numpy/distutils/command/scons.py =================================================================== --- branches/build_with_scons/numpy/distutils/command/scons.py 2008-01-06 10:35:44 UTC (rev 4683) +++ branches/build_with_scons/numpy/distutils/command/scons.py 2008-01-06 10:42:26 UTC (rev 4684) @@ -32,8 +32,8 @@ def get_scons_local_path(): """This returns the full path where scons.py for scons-local is located.""" - import numpy.distutils - return pjoin(pdirname(numpy.distutils.__file__), 'scons-local') + from numscons import get_scons_path + return get_scons_path() def get_python_exec_invoc(): """This returns the python executable from which this file is invocated.""" @@ -263,6 +263,13 @@ #print self.cxxcompiler.compiler_cxx[0] def run(self): + if len(self.sconscripts) > 0: + try: + import numscons + except ImportError, e: + raise RuntimeError("importing numscons failed (error was %s), using " \ + "scons within distutils is not possible without " + "this package " % str(e)) # XXX: when a scons script is missing, scons only prints warnings, and # does not return a failure (status is 0). We have to detect this from # distutils (this cannot work for recursive scons builds...) From numpy-svn at scipy.org Sun Jan 6 05:43:08 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 04:43:08 -0600 (CST) Subject: [Numpy-svn] r4685 - branches/build_with_scons/numpy/distutils Message-ID: <20080106104308.E8B0239C035@new.scipy.org> Author: cdavid Date: 2008-01-06 04:43:05 -0600 (Sun, 06 Jan 2008) New Revision: 4685 Modified: branches/build_with_scons/numpy/distutils/misc_util.py Log: Add scons_make_config function to numpy distutils Configuration. Modified: branches/build_with_scons/numpy/distutils/misc_util.py =================================================================== --- branches/build_with_scons/numpy/distutils/misc_util.py 2008-01-06 10:42:26 UTC (rev 4684) +++ branches/build_with_scons/numpy/distutils/misc_util.py 2008-01-06 10:43:05 UTC (rev 4685) @@ -1441,6 +1441,12 @@ """ self.py_modules.append((self.name,name,generate_config_py)) + def scons_make_config_py(self, name = '__config__'): + """Generate package __config__.py file containing system_info + information used during building the package. + """ + self.py_modules.append((self.name, name, scons_generate_config_py)) + def get_info(self,*names): """Get resources information. """ From numpy-svn at scipy.org Sun Jan 6 05:49:29 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 04:49:29 -0600 (CST) Subject: [Numpy-svn] r4686 - in branches/build_with_scons: . numpy Message-ID: <20080106104929.8AC8B39C109@new.scipy.org> Author: cdavid Date: 2008-01-06 04:49:23 -0600 (Sun, 06 Jan 2008) New Revision: 4686 Added: branches/build_with_scons/numpy/setupscons.py branches/build_with_scons/setupscons.py Log: Add root setupscons.py files, to start working on building numpy with numscons. Added: branches/build_with_scons/numpy/setupscons.py =================================================================== --- branches/build_with_scons/numpy/setupscons.py 2008-01-06 10:43:05 UTC (rev 4685) +++ branches/build_with_scons/numpy/setupscons.py 2008-01-06 10:49:23 UTC (rev 4686) @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('numpy',parent_package,top_path, setup_name = 'setupscons.py') + config.add_subpackage('distutils') + config.add_subpackage('testing') + config.add_subpackage('f2py') + config.add_subpackage('core') + config.add_subpackage('lib') + config.add_subpackage('oldnumeric') + config.add_subpackage('numarray') + config.add_subpackage('fft') + config.add_subpackage('linalg') + config.add_subpackage('random') + config.add_data_dir('doc') + config.add_data_dir('tests') + config.scons_make_config_py() # installs __config__.py + return config + +if __name__ == '__main__': + print 'This is the wrong setup.py file to run' Added: branches/build_with_scons/setupscons.py =================================================================== --- branches/build_with_scons/setupscons.py 2008-01-06 10:43:05 UTC (rev 4685) +++ branches/build_with_scons/setupscons.py 2008-01-06 10:49:23 UTC (rev 4686) @@ -0,0 +1,97 @@ +#!/usr/bin/env python +"""NumPy: array processing for numbers, strings, records, and objects. + +NumPy is a general-purpose array-processing package designed to +efficiently manipulate large multi-dimensional arrays of arbitrary +records without sacrificing too much speed for small multi-dimensional +arrays. NumPy is built on the Numeric code base and adds features +introduced by numarray as well as an extended C-API and the ability to +create arrays of arbitrary type which also makes NumPy suitable for +interfacing with general-purpose data-base applications. + +There are also basic facilities for discrete fourier transform, +basic linear algebra and random number generation. +""" + +DOCLINES = __doc__.split("\n") + +import __builtin__ +import os +import sys + +CLASSIFIERS = """\ +Development Status :: 4 - Beta +Intended Audience :: Science/Research +Intended Audience :: Developers +License :: OSI Approved +Programming Language :: C +Programming Language :: Python +Topic :: Software Development +Topic :: Scientific/Engineering +Operating System :: Microsoft :: Windows +Operating System :: POSIX +Operating System :: Unix +Operating System :: MacOS +""" + +# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly +# update it when the contents of directories change. +if os.path.exists('MANIFEST'): os.remove('MANIFEST') + +# This is a bit hackish: we are setting a global variable so that the main +# numpy __init__ can detect if it is being loaded by the setup routine, to +# avoid attempting to load components that aren't built yet. While ugly, it's +# a lot more robust than what was previously being used. +__builtin__.__NUMPY_SETUP__ = True + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + + config = Configuration(None, parent_package, top_path, setup_name = 'setupscons.py') + config.set_options(ignore_setup_xxx_py=True, + assume_default_configuration=True, + delegate_options_to_subpackages=True, + quiet=True) + + config.add_subpackage('numpy') + + config.add_data_files(('numpy','*.txt'), + ('numpy','COMPATIBILITY'), + ('numpy','site.cfg.example'), + ('numpy','setup.py')) + + config.get_version('numpy/version.py') # sets config.version + + return config + +def setup_package(): + + from numpy.distutils.core import setup + + old_path = os.getcwd() + local_path = os.path.dirname(os.path.abspath(sys.argv[0])) + os.chdir(local_path) + sys.path.insert(0,local_path) + + try: + setup( + name = 'numpy', + maintainer = "NumPy Developers", + maintainer_email = "numpy-discussion at lists.sourceforge.net", + description = DOCLINES[0], + long_description = "\n".join(DOCLINES[2:]), + url = "http://numeric.scipy.org", + download_url = "http://sourceforge.net/project/showfiles.php?group_id=1369&package_id=175103", + license = 'BSD', + classifiers=filter(None, CLASSIFIERS.split('\n')), + author = "Travis E. Oliphant, et.al.", + author_email = "oliphant at ee.byu.edu", + platforms = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"], + configuration=configuration ) + finally: + del sys.path[0] + os.chdir(old_path) + return + +if __name__ == '__main__': + setup_package() Property changes on: branches/build_with_scons/setupscons.py ___________________________________________________________________ Name: svn:executable + * From numpy-svn at scipy.org Sun Jan 6 07:11:54 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 06:11:54 -0600 (CST) Subject: [Numpy-svn] r4687 - branches/build_with_scons/numpy/distutils/command Message-ID: <20080106121154.5F17339C012@new.scipy.org> Author: cdavid Date: 2008-01-06 06:11:48 -0600 (Sun, 06 Jan 2008) New Revision: 4687 Modified: branches/build_with_scons/numpy/distutils/command/scons.py Log: Define various scons related functions to call numscons instead of being defined directly in numpy, for bootstrapping issues. Modified: branches/build_with_scons/numpy/distutils/command/scons.py =================================================================== --- branches/build_with_scons/numpy/distutils/command/scons.py 2008-01-06 10:49:23 UTC (rev 4686) +++ branches/build_with_scons/numpy/distutils/command/scons.py 2008-01-06 12:11:48 UTC (rev 4687) @@ -16,19 +16,22 @@ """Return the top path where everything produced by scons will be put. The path is relative to the top setup.py""" - return os.path.join('build', 'scons') + from numscons import get_scons_build_dir + return get_scons_build_dir() def get_scons_configres_dir(): """Return the top path where everything produced by scons will be put. The path is relative to the top setup.py""" - return os.path.join('build', 'scons-configres') + from numscons import get_scons_configres_dir + return get_scons_configres_dir() def get_scons_configres_filename(): """Return the top path where everything produced by scons will be put. The path is relative to the top setup.py""" - return '__configres.py' + from numscons import get_scons_configres_filename + return get_scons_configres_filename() def get_scons_local_path(): """This returns the full path where scons.py for scons-local is located.""" From numpy-svn at scipy.org Sun Jan 6 07:18:17 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 06:18:17 -0600 (CST) Subject: [Numpy-svn] r4688 - branches/build_with_scons/numpy/core/code_generators Message-ID: <20080106121817.2C63C39C00C@new.scipy.org> Author: cdavid Date: 2008-01-06 06:18:13 -0600 (Sun, 06 Jan 2008) New Revision: 4688 Modified: branches/build_with_scons/numpy/core/code_generators/generate_array_api.py Log: Modify array api generator to be compatible with scons builder Modified: branches/build_with_scons/numpy/core/code_generators/generate_array_api.py =================================================================== --- branches/build_with_scons/numpy/core/code_generators/generate_array_api.py 2008-01-06 12:11:48 UTC (rev 4687) +++ branches/build_with_scons/numpy/core/code_generators/generate_array_api.py 2008-01-06 12:18:13 UTC (rev 4688) @@ -1,9 +1,6 @@ import os import genapi -OBJECT_API_ORDER = 'array_api_order.txt' -MULTIARRAY_API_ORDER = 'multiarray_api_order.txt' - types = ['Generic','Number','Integer','SignedInteger','UnsignedInteger', 'Inexact', 'Floating', 'ComplexFloating', 'Flexible', 'Character', @@ -122,22 +119,30 @@ """ def generate_api(output_dir, force=False): - header_file = os.path.join(output_dir, '__multiarray_api.h') - c_file = os.path.join(output_dir,'__multiarray_api.c') - doc_file = os.path.join(output_dir, 'multiarray_api.txt') + basename = 'multiarray_api' - targets = (header_file, c_file, doc_file) - if (not force - and not genapi.should_rebuild(targets, - [OBJECT_API_ORDER, - MULTIARRAY_API_ORDER, - __file__])): + h_file = os.path.join(output_dir, '__%s.h' % basename) + c_file = os.path.join(output_dir, '__%s.c' % basename) + d_file = os.path.join(output_dir, '%s.txt' % basename) + targets = (h_file, c_file, d_file) + sources = ['array_api_order.txt', 'multiarray_api_order.txt'] + + if (not force and not genapi.should_rebuild(targets, sources + [__file__])): return targets + else: + do_generate_api(targets, sources) + return targets + +def do_generate_api(targets, sources): + header_file = targets[0] + c_file = targets[1] + doc_file = targets[2] + objectapi_list = genapi.get_api_functions('OBJECT_API', - OBJECT_API_ORDER) + sources[0]) multiapi_list = genapi.get_api_functions('MULTIARRAY_API', - MULTIARRAY_API_ORDER) + sources[1]) # API fixes for __arrayobject_api.h fixed = 10 From numpy-svn at scipy.org Sun Jan 6 07:19:42 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 06:19:42 -0600 (CST) Subject: [Numpy-svn] r4689 - branches/build_with_scons/numpy/core/code_generators Message-ID: <20080106121942.B728939C00C@new.scipy.org> Author: cdavid Date: 2008-01-06 06:19:35 -0600 (Sun, 06 Jan 2008) New Revision: 4689 Modified: branches/build_with_scons/numpy/core/code_generators/generate_ufunc_api.py Log: Modify ufunc api generator to be compatible with scons builder Modified: branches/build_with_scons/numpy/core/code_generators/generate_ufunc_api.py =================================================================== --- branches/build_with_scons/numpy/core/code_generators/generate_ufunc_api.py 2008-01-06 12:18:13 UTC (rev 4688) +++ branches/build_with_scons/numpy/core/code_generators/generate_ufunc_api.py 2008-01-06 12:19:35 UTC (rev 4689) @@ -1,8 +1,6 @@ import os import genapi -UFUNC_API_ORDER = 'ufunc_api_order.txt' - h_template = r""" #ifdef _UMATHMODULE @@ -72,18 +70,29 @@ """ def generate_api(output_dir, force=False): - header_file = os.path.join(output_dir, '__ufunc_api.h') - c_file = os.path.join(output_dir, '__ufunc_api.c') - doc_file = os.path.join(output_dir, 'ufunc_api.txt') + basename = 'ufunc_api' + + h_file = os.path.join(output_dir, '__%s.h' % basename) + c_file = os.path.join(output_dir, '__%s.c' % basename) + d_file = os.path.join(output_dir, '%s.txt' % basename) + targets = (h_file, c_file, d_file) - targets = (header_file, c_file, doc_file) - if (not force - and not genapi.should_rebuild(targets, - [UFUNC_API_ORDER, __file__])): + sources = ['ufunc_api_order.txt'] + + if (not force and not genapi.should_rebuild(targets, sources + [__file__])): return targets + else: + do_generate_api(targets, sources) - ufunc_api_list = genapi.get_api_functions('UFUNC_API', UFUNC_API_ORDER) + return targets +def do_generate_api(targets, sources): + header_file = targets[0] + c_file = targets[1] + doc_file = targets[2] + + ufunc_api_list = genapi.get_api_functions('UFUNC_API', sources[0]) + # API fixes for __arrayobject_api.h fixed = 1 From numpy-svn at scipy.org Sun Jan 6 09:08:25 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 08:08:25 -0600 (CST) Subject: [Numpy-svn] r4690 - branches/build_with_scons/numpy/core/code_generators Message-ID: <20080106140825.F2D4439C072@new.scipy.org> Author: cdavid Date: 2008-01-06 08:08:19 -0600 (Sun, 06 Jan 2008) New Revision: 4690 Added: branches/build_with_scons/numpy/core/code_generators/__init__.py Log: Make code_generators a package to import its functions Added: branches/build_with_scons/numpy/core/code_generators/__init__.py =================================================================== From numpy-svn at scipy.org Sun Jan 6 09:09:08 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 08:09:08 -0600 (CST) Subject: [Numpy-svn] r4691 - branches/build_with_scons/numpy/core Message-ID: <20080106140908.11B0B39C072@new.scipy.org> Author: cdavid Date: 2008-01-06 08:09:03 -0600 (Sun, 06 Jan 2008) New Revision: 4691 Added: branches/build_with_scons/numpy/core/SConstruct branches/build_with_scons/numpy/core/scons_support.py branches/build_with_scons/numpy/core/setupscons.py Log: Adding scons scripts + support for numpy.core (do not work yet) Added: branches/build_with_scons/numpy/core/SConstruct =================================================================== --- branches/build_with_scons/numpy/core/SConstruct 2008-01-06 14:08:19 UTC (rev 4690) +++ branches/build_with_scons/numpy/core/SConstruct 2008-01-06 14:09:03 UTC (rev 4691) @@ -0,0 +1,272 @@ +# Last Change: Sun Jan 06 07:00 PM 2008 J +# vim:syntax=python +import os +import sys +from os.path import join as pjoin, basename as pbasename, dirname as pdirname +from copy import deepcopy + +from numscons import get_python_inc, get_pythonlib_dir +from numscons import GetNumpyEnvironment +from numscons import CheckCBLAS +from numscons.configuration import write_info + +from scons_support import CheckBrokenMathlib, define_no_smp, \ + generate_config_header, generate_config_header_emitter + +env = GetNumpyEnvironment(ARGUMENTS) +env.Append(CPPPATH = [get_python_inc()]) +if os.name == 'nt': + # NT needs the pythonlib to run any code importing Python.h, including + # simple code using only typedef and so on, so we need it for configuration + # checks + env.AppendUnique(LIBPATH = [get_pythonlib_dir()]) + +#======================= +# Starting Configuration +#======================= +# XXX: separate env for configuration +config = env.NumpyConfigure(custom_tests = {'CheckBrokenMathlib' : CheckBrokenMathlib, + 'CheckCBLAS' : CheckCBLAS}) + +# Convention: list of tuples (definition, value). value: +# - 0: #undef definition +# - 1: #define definition +# - string: #define definition value +config_sym = [] + +#--------------- +# Checking Types +#--------------- +def check_type(type, include = None): + st = config.CheckTypeSize(type, includes = include) + type = type.replace(' ', '_') + if st: + config_sym.append(('SIZEOF_%s' % type.upper(), '%d' % st)) + else: + config_sym.append(('SIZEOF_%s' % type.upper(), 0)) + +check_type('short') +check_type('int') +check_type('long') +check_type('float') +check_type('double') +check_type('long double') +check_type('Py_intptr_t', include = "#include \n") +check_type('PY_LONG_LONG', include = "#include \n") + +# TODO: check python extension can be built (in root or here ?) + +#----------------------- +# Checking configuration +#----------------------- + +#---------------------- +# Checking signal stuff +#---------------------- +# TODO + +#------------------------------------------ +# Checking the mathlib and its capabilities +#------------------------------------------ +# Function to check: +mfuncs = [('expl', 'HAVE_LONGDOUBLE_FUNCS'), + ('expf', 'HAVE_FLOAT_FUNCS'), + ('log1p', 'HAVE_LOG1P'), + ('expm1', 'HAVE_EXPM1'), + ('asinh', 'HAVE_INVERSE_HYPERBOLIC'), + ('atanhf', 'HAVE_INVERSE_HYPERBOLIC_FLOAT'), + ('atanhl', 'HAVE_INVERSE_HYPERBOLIC_LONGDOUBLE'), + ('isnan', 'HAVE_ISNAN'), + ('isinf', 'HAVE_ISINF'), + ('rint', 'HAVE_RINT'), + ] + +# TODO: checklib vs checkfunc ? +mlibs = [[], ['m'], ['cpml']] +mathlib = os.environ.get('MATHLIB') +if mathlib: + mlibs.insert(0, mathlib) +for mlib in mlibs: + st = config.CheckBrokenMathlib(mlib) + if st: + break + +if not st: + import SCons + raise SCons.Errors.UserError("No usable mathlib was found: chose another "\ + "one using the MATHLIB env variable, eg "\ + "'MATHLIB=m python setup.py build'") +# XXX: this is ugly: mathlib has nothing to do in a public header file +config_sym.append(('MATHLIB', ','.join(mlib))) + +def check_lib(f, autoadd = 0): + """Check that f is available in mlib, and add the symbol appropriately. + + f is expected to be a tuble (symbol, cpp define).""" + st = config.CheckLibWithHeader(mlib, 'math.h', language = 'C', call = '%s;' % f[0], autoadd = autoadd) + if st: + config_sym.append((f[1], 1)) + else: + config_sym.append((f[1], 0)) + +check_lib(mfuncs[0], autoadd = 1) +for f in mfuncs[1:]: + check_lib(f) + +#------------------------------------------------------- +# Define the function PyOS_ascii_strod if not available +#------------------------------------------------------- +# XXX: would be better to check for PyOS_ascii_strod instead of version +if sys.version[:3] < '2.4': + if config.CheckFunc('strtod'): + config_sym.append(('PyOS_ascii_strtod', 'strtod')) + +if define_no_smp(): + config_sym.append(('NPY_NOSMP', '1')) +else: + config_sym.append(('NPY_NOSMP', '0')) + +# XXX: this is ugly +if sys.platform=='win32' or os.name=='nt': + from distutils.msvccompiler import get_build_architecture + a = get_build_architecture() + print 'BUILD_ARCHITECTURE: %r, os.name=%r, sys.platform=%r' % (a, os.name, sys.platform) + if a == 'AMD64': + moredefs.append(('DISTUTILS_USE_SDK', 1)) + +#-------------- +# Checking Blas +#-------------- +if config.CheckCBLAS(): + build_blasdot = 1 +else: + build_blasdot = 0 + +config.Finish() +write_info(env) + +#========== +# Build +#========== + +#--------------------------------------- +# Generate the public configuration file +#--------------------------------------- +config_dict = {} +# XXX: this is ugly, make the API for config.h and numpyconfig.h similar +for key, value in config_sym: + config_dict['@%s@' % key] = str(value) +env['SUBST_DICT'] = config_dict + +include_dir = 'include/numpy' +env.SubstInFile(pjoin(env['build_dir'], 'numpyconfig.h'), + pjoin(env['src_dir'], include_dir, 'numpyconfig.h.in')) + +env['CONFIG_H_GEN'] = config_sym + +#--------------------------- +# Builder for generated code +#--------------------------- +from scons_support import do_generate_array_api, do_generate_ufunc_api, \ + generate_api_emitter,\ + generate_from_template, generate_from_template_emitter, \ + generate_umath, generate_umath_emitter + +array_api_gen_bld = Builder(action = do_generate_array_api, + emitter = generate_api_emitter) + +ufunc_api_gen_bld = Builder(action = do_generate_ufunc_api, + emitter = generate_api_emitter) + +template_bld = Builder(action = generate_from_template, + emitter = generate_from_template_emitter) + +umath_bld = Builder(action = generate_umath, + emitter = generate_umath_emitter) + +config_h_bld = Builder(action = generate_config_header, + emitter = generate_config_header_emitter) + +env.Append(BUILDERS = {'GenerateMultiarrayApi' : array_api_gen_bld, + 'GenerateUfuncApi' : ufunc_api_gen_bld, + 'GenerateFromTemplate' : template_bld, + 'GenerateUmath' : umath_bld, + 'GenerateConfigHeader' : config_h_bld}) + +#------------------------ +# Generate generated code +#------------------------ +# XXX: the use of env['build_dir'] and env['src_dir'] are really ugly. Will +# have to think about how removing them (using hierarchical scons and dir +# option ?) +from os.path import join as pjoin + +config_header = env.GenerateConfigHeader(pjoin(env['build_dir'], 'config.h'), []) + +scalartypes_src = env.GenerateFromTemplate( + pjoin(env['build_dir'], 'src', 'scalartypes'), + pjoin(env['src_dir'], 'src', 'scalartypes.inc.src')) + +arraytypes_src = env.GenerateFromTemplate( + pjoin(env['build_dir'], 'src', 'arraytypes'), + pjoin(env['src_dir'], 'src', 'arraytypes.inc.src')) + +sortmodule_src = env.GenerateFromTemplate( + pjoin(env['build_dir'], 'src', '_sortmodule'), + pjoin(env['src_dir'], 'src', '_sortmodule.c.src')) + +umathmodule_src = env.GenerateFromTemplate( + pjoin(env['build_dir'], 'src', 'umathmodule'), + pjoin(env['src_dir'], 'src', 'umathmodule.c.src')) + +scalarmathmodule_src = env.GenerateFromTemplate( + pjoin(env['build_dir'], 'src', 'scalarmathmodule'), + pjoin(env['src_dir'], 'src', 'scalarmathmodule.c.src')) + +umath = env.GenerateUmath( + pjoin(env['build_dir'], '__umath_generated'), + pjoin(env['src_dir'], 'code_generators', 'generate_umath.py')) + +multiarray_api = env.GenerateMultiarrayApi( + pjoin(env['build_dir'], 'multiarray_api'), + [ pjoin(env['src_dir'], 'code_generators', + 'array_api_order.txt'), + pjoin(env['src_dir'], 'code_generators', + 'multiarray_api_order.txt')]) + +ufunc_api = env.GenerateUfuncApi( + pjoin(env['build_dir'], 'ufunc_api'), + pjoin(env['src_dir'], 'code_generators', 'ufunc_api_order.txt')) + +env.Append(CPPPATH = [pjoin(env['src_dir'], 'include'), env['build_dir']]) + +#----------------- +# Build multiarray +#----------------- +multiarray_src = [pjoin('src', 'multiarraymodule.c')] +multiarray = env.NumpyPythonExtension('multiarray', source = multiarray_src) + +#------------------ +# Build sort module +#------------------ +sort = env.NumpyPythonExtension('_sort', source = sortmodule_src) + +#------------------- +# Build umath module +#------------------- +umathmodule = env.NumpyPythonExtension('umath', source = umathmodule_src) + +#------------------------ +# Build scalarmath module +#------------------------ +scalarmathmodule = env.NumpyPythonExtension('scalarmath', + source = scalarmathmodule_src) + +#---------------------- +# Build _dotblas module +#---------------------- +if build_blasdot: + dotblas_src = [pjoin('blasdot', i) for i in ['_dotblas.c']] + blasenv = env.Copy() + blasenv.Append(CPPPATH = pjoin(env['src_dir'], 'blasdot')) + dotblas = blasenv.NumpyPythonExtension('_dotblas', source = dotblas_src) Added: branches/build_with_scons/numpy/core/scons_support.py =================================================================== --- branches/build_with_scons/numpy/core/scons_support.py 2008-01-06 14:08:19 UTC (rev 4690) +++ branches/build_with_scons/numpy/core/scons_support.py 2008-01-06 14:09:03 UTC (rev 4691) @@ -0,0 +1,189 @@ +#! Last Change: Sun Jan 06 09:00 PM 2008 J + +__docstring__ = """Code to support special facilities to scons which are only +useful for numpy.core, hence not put into numpy.distutils.scons""" + +import sys +import os + +from os.path import join as pjoin, dirname as pdirname, basename as pbasename +from copy import deepcopy + +from code_generators.generate_array_api import \ + do_generate_api as nowrap_do_generate_array_api +from code_generators.generate_ufunc_api import \ + do_generate_api as nowrap_do_generate_ufunc_api + +from numscons.numdist import process_c_str as process_str +from numscons.core.utils import rsplit, isstring + +import SCons.Node + +def split_ext(string): + sp = rsplit(string, '.', 1) + if len(sp) == 1: + return (sp[0], '') + else: + return sp +#------------------------------------ +# Ufunc and multiarray API generators +#------------------------------------ +def do_generate_array_api(target, source, env): + nowrap_do_generate_array_api([str(i) for i in target], + [str(i) for i in source]) + return 0 + +def do_generate_ufunc_api(target, source, env): + nowrap_do_generate_ufunc_api([str(i) for i in target], + [str(i) for i in source]) + return 0 + +def generate_api_emitter(target, source, env): + """Returns the list of targets generated by the code generator for array + api and ufunc api.""" + base, ext = split_ext(str(target[0])) + dir = pdirname(base) + ba = pbasename(base) + h = pjoin(dir, '__' + ba + '.h') + c = pjoin(dir, '__' + ba + '.c') + txt = base + '.txt' + #print h, c, txt + t = [h, c, txt] + return (t, source) + +#------------------------- +# From template generators +#------------------------- +# XXX: this is general and can be used outside numpy.core. +def do_generate_from_template(targetfile, sourcefile, env): + t = open(targetfile, 'w') + s = open(sourcefile, 'r') + allstr = s.read() + s.close() + writestr = process_str(allstr) + t.write(writestr) + t.close() + return 0 + +def generate_from_template(target, source, env): + for t, s in zip(target, source): + do_generate_from_template(str(t), str(s), env) + +def generate_from_template_emitter(target, source, env): + base, ext = split_ext(pbasename(str(source[0]))) + t = pjoin(pdirname(str(target[0])), base) + return ([t], source) + +#---------------- +# umath generator +#---------------- +def do_generate_umath(targetfile, sourcefile, env): + t = open(targetfile, 'w') + from code_generators import generate_umath + code = generate_umath.make_code(generate_umath.defdict, generate_umath.__file__) + t.write(code) + t.close() + +def generate_umath(target, source, env): + for t, s in zip(target, source): + do_generate_umath(str(t), str(s), env) + +def generate_umath_emitter(target, source, env): + t = str(target[0]) + '.c' + return ([t], source) + +#------------------- +# Generate config.h +#------------------- +def generate_config_header(target, source, env): + t = open(str(target[0]), 'w') + if not env.has_key('CONFIG_H_GEN'): + # XXX + assert 0 == 1 + sym = env['CONFIG_H_GEN'] + def write_symbol(define, value): + if value == 1: + return "#define %s\n\n" % define + elif value == 0: + return "/* #undef %s */\n\n" % define + elif isstring(value): + return "#define %s %s\n\n" % (define, value) + else: + return "#define %s %s\n\n" % (define, ','.join(value)) + t.writelines([write_symbol(i[0], i[1]) for i in sym]) + t.write('\n') + t.close() + + print 'File: %s' % target[0] + target_f = open(str(target[0])) + print target_f.read() + target_f.close() + print 'EOF' + return 0 + +def generate_config_header_emitter(target, source, env): + """Add dependency from config list CONFIG_H_GEN to target. Returns + original target, source tuple unchanged. """ + from SCons.Script import Depends + d = deepcopy(env['CONFIG_H_GEN']) # copy it + Depends(target, SCons.Node.Python.Value(d)) + return target, source + +#----------------------------------------- +# Other functions related to configuration +#----------------------------------------- +def CheckBrokenMathlib(context, mathlib): + src = """ +/* check whether libm is broken */ +#include +int main(int argc, char *argv[]) +{ + return exp(-720.) > 1.0; /* typically an IEEE denormal */ +} +""" + + try: + oldLIBS = deepcopy(context.env['LIBS']) + except: + oldLIBS = [] + + try: + context.Message("Checking if math lib %s is usable for numpy ... " % mathlib) + context.env.AppendUnique(LIBS = mathlib) + st = context.TryRun(src, '.c') + finally: + context.env['LIBS'] = oldLIBS + + if st[0]: + context.Result(' Yes !') + else: + context.Result(' No !') + return st[0] + +def define_no_smp(): + """Returns True if we should define NPY_NOSMP, False otherwise.""" + #-------------------------------- + # Checking SMP and thread options + #-------------------------------- + # 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: + # Perhaps a fancier check is in order here. + # so that threads are only enabled if there + # are actually multiple CPUS? -- but + # threaded code can be nice even on a single + # CPU so that long-calculating code doesn't + # block. + try: + nosmp = os.environ['NPY_NOSMP'] + nosmp = 1 + except KeyError: + nosmp = 0 + return nosmp == 1 + Added: branches/build_with_scons/numpy/core/setupscons.py =================================================================== --- branches/build_with_scons/numpy/core/setupscons.py 2008-01-06 14:08:19 UTC (rev 4690) +++ branches/build_with_scons/numpy/core/setupscons.py 2008-01-06 14:09:03 UTC (rev 4691) @@ -0,0 +1,103 @@ +import os +import sys +import glob +from os.path import join, basename +from numpy.distutils import log + +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 + + config = Configuration('core',parent_package,top_path) + local_dir = config.local_path + + header_dir = 'include/numpy' # this is relative to config.path_in_package + + config.add_subpackage('code_generators') + + # List of files to register to numpy.distutils + dot_blas_src = [join('blasdot', '_dotblas.c'), + join('blasdot', 'cblas.h')] + api_definition = [join('code_generators', 'array_api_order.txt'), + join('code_generators', 'multiarray_api_order.txt'), + join('code_generators', 'ufunc_api_order.txt')] + core_src = [join('src', basename(i)) for i in glob.glob(join(local_dir, + 'src', + '*.c'))] + core_src += [join('src', basename(i)) for i in glob.glob(join(local_dir, + 'src', + '*.src'))] + + source_files = dot_blas_src + api_definition + core_src + \ + [join(header_dir, 'numpyconfig.h.in')] + + # Add generated files to distutils... + def add_config_header(): + scons_build_dir = config.get_scons_build_dir() + # XXX: I really have to think about how to communicate path info + # between scons and distutils, and set the options at one single + # location. + target = join(scons_build_dir, local_dir, 'config.h') + incl_dir = os.path.dirname(target) + if incl_dir not in config.numpy_include_dirs: + config.numpy_include_dirs.append(incl_dir) + + def add_numpyconfig_header(): + scons_build_dir = config.get_scons_build_dir() + # XXX: I really have to think about how to communicate path info + # between scons and distutils, and set the options at one single + # location. + target = join(scons_build_dir, local_dir, 'numpyconfig.h') + incl_dir = os.path.dirname(target) + if incl_dir not in config.numpy_include_dirs: + config.numpy_include_dirs.append(incl_dir) + config.add_data_files((header_dir, target)) + + def add_array_api(): + scons_build_dir = config.get_scons_build_dir() + # XXX: I really have to think about how to communicate path info + # between scons and distutils, and set the options at one single + # location. + h_file = join(scons_build_dir, local_dir, '__multiarray_api.h') + t_file = join(scons_build_dir, local_dir, 'multiarray_api.txt') + config.add_data_files((header_dir, h_file), + (header_dir, t_file)) + + def add_ufunc_api(): + scons_build_dir = config.get_scons_build_dir() + # XXX: I really have to think about how to communicate path info + # between scons and distutils, and set the options at one single + # location. + h_file = join(scons_build_dir, local_dir, '__ufunc_api.h') + t_file = join(scons_build_dir, local_dir, 'ufunc_api.txt') + config.add_data_files((header_dir, h_file), + (header_dir, t_file)) + + def add_generated_files(): + add_config_header() + add_numpyconfig_header() + add_array_api() + add_ufunc_api() + config.add_configres() + + config.add_sconscript('SConstruct', + post_hook = add_generated_files, + source_files = source_files) + + config.add_data_files('include/numpy/*.h') + config.add_include_dirs('src') + + config.numpy_include_dirs.extend(config.paths('include')) + + # Don't install fenv unless we need them. + if sys.platform == 'cygwin': + config.add_data_dir('include/numpy/fenv') + + config.add_data_dir('tests') + config.make_svn_version_py() + + return config + +if __name__=='__main__': + from numpy.distutils.core import setup + setup(configuration=configuration) From numpy-svn at scipy.org Sun Jan 6 09:14:26 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 08:14:26 -0600 (CST) Subject: [Numpy-svn] r4692 - branches/build_with_scons/numpy/distutils Message-ID: <20080106141426.A17B839C072@new.scipy.org> Author: cdavid Date: 2008-01-06 08:14:23 -0600 (Sun, 06 Jan 2008) New Revision: 4692 Modified: branches/build_with_scons/numpy/distutils/misc_util.py Log: Add function add_configres for numpy.distutils.Configuration Modified: branches/build_with_scons/numpy/distutils/misc_util.py =================================================================== --- branches/build_with_scons/numpy/distutils/misc_util.py 2008-01-06 14:09:03 UTC (rev 4691) +++ branches/build_with_scons/numpy/distutils/misc_util.py 2008-01-06 14:14:23 UTC (rev 4692) @@ -1212,6 +1212,10 @@ # options in distutils command. self.add_extension('', sources = []) + def add_configres(self): + file = os.path.join(get_scons_configres_dir(), self.local_path, + get_scons_configres_filename()) + def add_scripts(self,*files): """Add scripts to configuration. """ From numpy-svn at scipy.org Sun Jan 6 09:18:06 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 08:18:06 -0600 (CST) Subject: [Numpy-svn] r4693 - branches/build_with_scons/numpy/distutils Message-ID: <20080106141806.68A2B39C072@new.scipy.org> Author: cdavid Date: 2008-01-06 08:18:02 -0600 (Sun, 06 Jan 2008) New Revision: 4693 Modified: branches/build_with_scons/numpy/distutils/misc_util.py Log: Import get_configres* functions from numscons Modified: branches/build_with_scons/numpy/distutils/misc_util.py =================================================================== --- branches/build_with_scons/numpy/distutils/misc_util.py 2008-01-06 14:14:23 UTC (rev 4692) +++ branches/build_with_scons/numpy/distutils/misc_util.py 2008-01-06 14:18:02 UTC (rev 4693) @@ -1213,6 +1213,7 @@ self.add_extension('', sources = []) def add_configres(self): + from numscons import get_scons_configres_dir, get_scons_configres_filename file = os.path.join(get_scons_configres_dir(), self.local_path, get_scons_configres_filename()) From numpy-svn at scipy.org Sun Jan 6 09:18:57 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 08:18:57 -0600 (CST) Subject: [Numpy-svn] r4694 - in branches/build_with_scons/numpy/core: . include/numpy Message-ID: <20080106141857.2B3A139C072@new.scipy.org> Author: cdavid Date: 2008-01-06 08:18:51 -0600 (Sun, 06 Jan 2008) New Revision: 4694 Added: branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in Modified: branches/build_with_scons/numpy/core/SConstruct branches/build_with_scons/numpy/core/setupscons.py Log: More work on building numpy.core with scons (still does not work) Modified: branches/build_with_scons/numpy/core/SConstruct =================================================================== --- branches/build_with_scons/numpy/core/SConstruct 2008-01-06 14:18:02 UTC (rev 4693) +++ branches/build_with_scons/numpy/core/SConstruct 2008-01-06 14:18:51 UTC (rev 4694) @@ -1,4 +1,4 @@ -# Last Change: Sun Jan 06 07:00 PM 2008 J +# Last Change: Sun Jan 06 10:00 PM 2008 J # vim:syntax=python import os import sys @@ -143,7 +143,7 @@ build_blasdot = 0 config.Finish() -write_info(env) +#write_info(env) #========== # Build Added: branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in =================================================================== --- branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in 2008-01-06 14:18:02 UTC (rev 4693) +++ branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in 2008-01-06 14:18:51 UTC (rev 4694) @@ -0,0 +1,23 @@ +#define NPY_SIZEOF_SHORT @SIZEOF_SHORT@ +#define NPY_SIZEOF_INT @SIZEOF_INT@ +#define NPY_SIZEOF_LONG @SIZEOF_LONG@ +#define NPY_SIZEOF_FLOAT @SIZEOF_FLOAT@ +#define NPY_SIZEOF_DOUBLE @SIZEOF_DOUBLE@ +#define NPY_SIZEOF_LONGDOUBLE @SIZEOF_LONG_DOUBLE@ +#define NPY_SIZEOF_PY_INTPTR_T @SIZEOF_PY_INTPTR_T@ + +#define NPY_NOSMP @NPY_NOSMP@ + +/* XXX: this has really nothing to do in a config file... */ +#define NPY_MATHLIB @MATHLIB@ + +/* XXX: this has to be done outside config files !!!! */ +#ifdef PY_LONG_LONG + #define NPY_SIZEOF_LONGLONG @SIZEOF_PY_LONG_LONG@ + #define NPY_SIZEOF_PY_LONG_LONG @SIZEOF_PY_LONG_LONG@ +#endif + +#ifndef CHAR_BIT + #error Configuration for undefined CHAR_BIT is not supported, contact the maintainter + #define CHAR_BIT @CHAR_BIT@ +#endif Modified: branches/build_with_scons/numpy/core/setupscons.py =================================================================== --- branches/build_with_scons/numpy/core/setupscons.py 2008-01-06 14:18:02 UTC (rev 4693) +++ branches/build_with_scons/numpy/core/setupscons.py 2008-01-06 14:18:51 UTC (rev 4694) @@ -2,8 +2,11 @@ import sys import glob from os.path import join, basename + from numpy.distutils import log +from numscons import get_scons_build_dir + 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 @@ -33,7 +36,7 @@ # Add generated files to distutils... def add_config_header(): - scons_build_dir = config.get_scons_build_dir() + scons_build_dir = get_scons_build_dir() # XXX: I really have to think about how to communicate path info # between scons and distutils, and set the options at one single # location. @@ -43,7 +46,7 @@ config.numpy_include_dirs.append(incl_dir) def add_numpyconfig_header(): - scons_build_dir = config.get_scons_build_dir() + scons_build_dir = get_scons_build_dir() # XXX: I really have to think about how to communicate path info # between scons and distutils, and set the options at one single # location. @@ -54,7 +57,7 @@ config.add_data_files((header_dir, target)) def add_array_api(): - scons_build_dir = config.get_scons_build_dir() + scons_build_dir = get_scons_build_dir() # XXX: I really have to think about how to communicate path info # between scons and distutils, and set the options at one single # location. @@ -64,7 +67,7 @@ (header_dir, t_file)) def add_ufunc_api(): - scons_build_dir = config.get_scons_build_dir() + scons_build_dir = get_scons_build_dir() # XXX: I really have to think about how to communicate path info # between scons and distutils, and set the options at one single # location. From numpy-svn at scipy.org Sun Jan 6 21:39:48 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 20:39:48 -0600 (CST) Subject: [Numpy-svn] r4695 - branches/build_with_scons/numpy/distutils Message-ID: <20080107023948.667CC39C098@new.scipy.org> Author: cdavid Date: 2008-01-06 20:39:35 -0600 (Sun, 06 Jan 2008) New Revision: 4695 Modified: branches/build_with_scons/numpy/distutils/misc_util.py Log: Fix missing import from numscons Modified: branches/build_with_scons/numpy/distutils/misc_util.py =================================================================== --- branches/build_with_scons/numpy/distutils/misc_util.py 2008-01-06 14:18:51 UTC (rev 4694) +++ branches/build_with_scons/numpy/distutils/misc_util.py 2008-01-07 02:39:35 UTC (rev 4695) @@ -1491,6 +1491,7 @@ config['py_modules'].append((packagename, '__config__',generate_config_py)) """ from distutils.dir_util import mkpath + from numscons import get_scons_configres_dir, get_scons_configres_filename import imp d = {} mkpath(os.path.dirname(target)) From numpy-svn at scipy.org Sun Jan 6 21:40:44 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 20:40:44 -0600 (CST) Subject: [Numpy-svn] r4696 - branches/build_with_scons/numpy/core Message-ID: <20080107024044.C876639C098@new.scipy.org> Author: cdavid Date: 2008-01-06 20:40:39 -0600 (Sun, 06 Jan 2008) New Revision: 4696 Modified: branches/build_with_scons/numpy/core/SConstruct Log: Re-enable write_info, since the related bug in numscons has been fixed Modified: branches/build_with_scons/numpy/core/SConstruct =================================================================== --- branches/build_with_scons/numpy/core/SConstruct 2008-01-07 02:39:35 UTC (rev 4695) +++ branches/build_with_scons/numpy/core/SConstruct 2008-01-07 02:40:39 UTC (rev 4696) @@ -143,7 +143,7 @@ build_blasdot = 0 config.Finish() -#write_info(env) +write_info(env) #========== # Build From numpy-svn at scipy.org Sun Jan 6 21:42:23 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 20:42:23 -0600 (CST) Subject: [Numpy-svn] r4697 - branches/build_with_scons/numpy/fft Message-ID: <20080107024223.BFB7939C098@new.scipy.org> Author: cdavid Date: 2008-01-06 20:42:16 -0600 (Sun, 06 Jan 2008) New Revision: 4697 Added: branches/build_with_scons/numpy/fft/SConstruct branches/build_with_scons/numpy/fft/setupscons.py Log: numpy.fft builds with scons Added: branches/build_with_scons/numpy/fft/SConstruct =================================================================== --- branches/build_with_scons/numpy/fft/SConstruct 2008-01-07 02:40:39 UTC (rev 4696) +++ branches/build_with_scons/numpy/fft/SConstruct 2008-01-07 02:42:16 UTC (rev 4697) @@ -0,0 +1,13 @@ +# Last Change: Thu Oct 18 09:00 PM 2007 J +# vim:syntax=python +import __builtin__ +__builtin__.__NUMPY_SETUP__ = True +from numpy.distutils.misc_util import get_numpy_include_dirs +from numscons import GetNumpyEnvironment, scons_get_paths + +env = GetNumpyEnvironment(ARGUMENTS) +env.Append(CPPPATH = scons_get_paths(env['include_bootstrap'])) + +fftpack_lite = env.NumpyPythonExtension('fftpack_lite', + source = ['fftpack_litemodule.c', + 'fftpack.c']) Added: branches/build_with_scons/numpy/fft/setupscons.py =================================================================== --- branches/build_with_scons/numpy/fft/setupscons.py 2008-01-07 02:40:39 UTC (rev 4696) +++ branches/build_with_scons/numpy/fft/setupscons.py 2008-01-07 02:42:16 UTC (rev 4697) @@ -0,0 +1,15 @@ +def configuration(parent_package = '', top_path = None): + from numpy.distutils.misc_util import Configuration, get_numpy_include_dirs + config = Configuration('fft', parent_package, top_path) + + config.add_data_dir('tests') + + config.add_sconscript('SConstruct', + source_files = ['fftpack_litemodule.c', 'fftpack.c', + 'fftpack.h']) + + return config + +if __name__ == '__main__': + from numpy.distutils.core import setup + setup(configuration=configuration) From numpy-svn at scipy.org Sun Jan 6 21:43:12 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 20:43:12 -0600 (CST) Subject: [Numpy-svn] r4698 - branches/build_with_scons/numpy/random Message-ID: <20080107024312.1860A39C2DF@new.scipy.org> Author: cdavid Date: 2008-01-06 20:43:05 -0600 (Sun, 06 Jan 2008) New Revision: 4698 Added: branches/build_with_scons/numpy/random/SConstruct branches/build_with_scons/numpy/random/setupscons.py Log: numpy.random now builds with scons Added: branches/build_with_scons/numpy/random/SConstruct =================================================================== --- branches/build_with_scons/numpy/random/SConstruct 2008-01-07 02:42:16 UTC (rev 4697) +++ branches/build_with_scons/numpy/random/SConstruct 2008-01-07 02:43:05 UTC (rev 4698) @@ -0,0 +1,50 @@ +# Last Change: Tue Nov 13 11:00 PM 2007 J +# vim:syntax=python +import os + +import __builtin__ +__builtin__.__NUMPY_SETUP__ = True + +from numpy.distutils.misc_util import get_numpy_include_dirs, get_mathlibs +from numscons import GetNumpyEnvironment, scons_get_paths, \ + scons_get_mathlib + +def CheckWincrypt(context): + from copy import deepcopy + src = """\ +/* check to see if _WIN32 is defined */ +int main(int argc, char *argv[]) +{ +#ifdef _WIN32 + return 0; +#else + return 1; +#endif +} +""" + + context.Message("Checking if using wincrypt ... ") + st = context.env.TryRun(src, '.C') + if st[0] == 0: + context.Result('No') + else: + context.Result('Yes') + return st[0] + +env = GetNumpyEnvironment(ARGUMENTS) +env.Append(CPPPATH = scons_get_paths(env['include_bootstrap'])) + +mlib = scons_get_mathlib(env) +env.AppendUnique(LIBS = mlib) + +# On windows, see if we should use Advapi32 +if os.name == 'nt': + config = env.NumpyConfigure(custom_tests = {'CheckWincrypt' : CheckWincrypt}) + if config.CheckWincrypt: + config.env.AppendUnique(LIBS = 'Advapi32') + +sources = [os.path.join('mtrand', x) for x in + ['mtrand.c', 'randomkit.c', 'initarray.c', 'distributions.c']] + +# XXX: Pyrex dependency +mtrand = env.NumpyPythonExtension('mtrand', source = sources) Added: branches/build_with_scons/numpy/random/setupscons.py =================================================================== --- branches/build_with_scons/numpy/random/setupscons.py 2008-01-07 02:42:16 UTC (rev 4697) +++ branches/build_with_scons/numpy/random/setupscons.py 2008-01-07 02:43:05 UTC (rev 4698) @@ -0,0 +1,40 @@ +import glob +from os.path import join, split + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration, get_mathlibs + config = Configuration('random',parent_package,top_path) + + source_files = [join('mtrand', i) for i in ['mtrand.c', + 'mtrand.pyx', + 'numpy.pxi', + 'randomkit.c', + 'randomkit.h', + 'Python.pxi', + 'initarray.c', + 'initarray.h', + 'distributions.c', + 'distributions.h', + ]] + config.add_sconscript('SConstruct', source_files = source_files) + config.add_data_files(('.', join('mtrand', 'randomkit.h'))) + config.add_data_dir('tests') + + return config + +def testcode_wincrypt(): + return """\ +/* check to see if _WIN32 is defined */ +int main(int argc, char *argv[]) +{ +#ifdef _WIN32 + return 0; +#else + return 1; +#endif +} +""" + +if __name__ == '__main__': + from numpy.distutils.core import setup + setup(configuration=configuration) From numpy-svn at scipy.org Sun Jan 6 21:45:12 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 20:45:12 -0600 (CST) Subject: [Numpy-svn] r4699 - in branches/build_with_scons/numpy: distutils f2py oldnumeric testing Message-ID: <20080107024512.9A62339C098@new.scipy.org> Author: cdavid Date: 2008-01-06 20:44:56 -0600 (Sun, 06 Jan 2008) New Revision: 4699 Added: branches/build_with_scons/numpy/distutils/setupscons.py branches/build_with_scons/numpy/f2py/setupscons.py branches/build_with_scons/numpy/oldnumeric/setupscons.py branches/build_with_scons/numpy/testing/setupscons.py Log: Add setupscons.py for pure python packages Added: branches/build_with_scons/numpy/distutils/setupscons.py =================================================================== --- branches/build_with_scons/numpy/distutils/setupscons.py 2008-01-07 02:43:05 UTC (rev 4698) +++ branches/build_with_scons/numpy/distutils/setupscons.py 2008-01-07 02:44:56 UTC (rev 4699) @@ -0,0 +1,15 @@ +#!/usr/bin/env python + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('distutils',parent_package,top_path) + config.add_subpackage('command') + config.add_subpackage('fcompiler') + config.add_data_dir('tests') + config.add_data_files('site.cfg') + config.make_config_py() + return config + +if __name__ == '__main__': + from numpy.distutils.core import setup + setup(configuration=configuration) Added: branches/build_with_scons/numpy/f2py/setupscons.py =================================================================== --- branches/build_with_scons/numpy/f2py/setupscons.py 2008-01-07 02:43:05 UTC (rev 4698) +++ branches/build_with_scons/numpy/f2py/setupscons.py 2008-01-07 02:44:56 UTC (rev 4699) @@ -0,0 +1,130 @@ +#!/usr/bin/env python +""" +setup.py for installing F2PY + +Usage: + python setup.py install + +Copyright 2001-2005 Pearu Peterson all rights reserved, +Pearu Peterson +Permission to use, modify, and distribute this software is given under the +terms of the NumPy License. + +NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. +$Revision: 1.32 $ +$Date: 2005/01/30 17:22:14 $ +Pearu Peterson +""" + +__version__ = "$Id: setup.py,v 1.32 2005/01/30 17:22:14 pearu Exp $" + +import os +import sys +from distutils.dep_util import newer +from numpy.distutils import log +from numpy.distutils.core import setup +from numpy.distutils.misc_util import Configuration + +from __version__ import version + +def configuration(parent_package='',top_path=None): + config = Configuration('f2py', parent_package, top_path) + + config.add_subpackage('lib') + + config.add_data_dir('docs') + + config.add_data_files('src/fortranobject.c', + 'src/fortranobject.h', + 'f2py.1' + ) + + config.make_svn_version_py() + + def generate_f2py_py(build_dir): + f2py_exe = 'f2py'+os.path.basename(sys.executable)[6:] + if f2py_exe[-4:]=='.exe': + f2py_exe = f2py_exe[:-4] + '.py' + if 'bdist_wininst' in sys.argv and f2py_exe[-3:] != '.py': + f2py_exe = f2py_exe + '.py' + target = os.path.join(build_dir,f2py_exe) + if newer(__file__,target): + log.info('Creating %s', target) + f = open(target,'w') + f.write('''\ +#!/usr/bin/env %s +# See http://cens.ioc.ee/projects/f2py2e/ +import os, sys +for mode in ["g3-numpy", "2e-numeric", "2e-numarray", "2e-numpy"]: + try: + i=sys.argv.index("--"+mode) + del sys.argv[i] + break + except ValueError: pass +os.environ["NO_SCIPY_IMPORT"]="f2py" +if mode=="g3-numpy": + try: + from main import main + except ImportError: + from numpy.f2py.lib.api import main +elif mode=="2e-numeric": + from f2py2e import main +elif mode=="2e-numarray": + sys.argv.append("-DNUMARRAY") + from f2py2e import main +elif mode=="2e-numpy": + from numpy.f2py import main +else: + print >> sys.stderr, "Unknown mode:",`mode` + sys.exit(1) +main() +'''%(os.path.basename(sys.executable))) + f.close() + return target + + config.add_scripts(generate_f2py_py) + + log.info('F2PY Version %s', config.get_version()) + + return config + +if __name__ == "__main__": + + config = configuration(top_path='') + version = config.get_version() + print 'F2PY Version',version + config = config.todict() + + if sys.version[:3]>='2.3': + config['download_url'] = "http://cens.ioc.ee/projects/f2py2e/2.x"\ + "/F2PY-2-latest.tar.gz" + config['classifiers'] = [ + 'Development Status :: 5 - Production/Stable', + 'Intended Audience :: Developers', + 'Intended Audience :: Science/Research', + 'License :: OSI Approved :: NumPy License', + 'Natural Language :: English', + 'Operating System :: OS Independent', + 'Programming Language :: C', + 'Programming Language :: Fortran', + 'Programming Language :: Python', + 'Topic :: Scientific/Engineering', + 'Topic :: Software Development :: Code Generators', + ] + setup(version=version, + description = "F2PY - Fortran to Python Interface Generaton", + author = "Pearu Peterson", + author_email = "pearu at cens.ioc.ee", + maintainer = "Pearu Peterson", + maintainer_email = "pearu at cens.ioc.ee", + license = "BSD", + platforms = "Unix, Windows (mingw|cygwin), Mac OSX", + long_description = """\ +The Fortran to Python Interface Generator, or F2PY for short, is a +command line tool (f2py) for generating Python C/API modules for +wrapping Fortran 77/90/95 subroutines, accessing common blocks from +Python, and calling Python functions from Fortran (call-backs). +Interfacing subroutines/data from Fortran 90/95 modules is supported.""", + url = "http://cens.ioc.ee/projects/f2py2e/", + keywords = ['Fortran','f2py'], + **config) Property changes on: branches/build_with_scons/numpy/f2py/setupscons.py ___________________________________________________________________ Name: svn:executable + * Added: branches/build_with_scons/numpy/oldnumeric/setupscons.py =================================================================== --- branches/build_with_scons/numpy/oldnumeric/setupscons.py 2008-01-07 02:43:05 UTC (rev 4698) +++ branches/build_with_scons/numpy/oldnumeric/setupscons.py 2008-01-07 02:44:56 UTC (rev 4699) @@ -0,0 +1,8 @@ + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + return Configuration('oldnumeric',parent_package,top_path) + +if __name__ == '__main__': + from numpy.distutils.core import setup + setup(configuration=configuration) Added: branches/build_with_scons/numpy/testing/setupscons.py =================================================================== --- branches/build_with_scons/numpy/testing/setupscons.py 2008-01-07 02:43:05 UTC (rev 4698) +++ branches/build_with_scons/numpy/testing/setupscons.py 2008-01-07 02:44:56 UTC (rev 4699) @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('testing',parent_package,top_path) + return config + +if __name__ == '__main__': + from numpy.distutils.core import setup + setup(maintainer = "NumPy Developers", + maintainer_email = "numpy-dev at numpy.org", + description = "NumPy test module", + url = "http://www.numpy.org", + license = "NumPy License (BSD Style)", + configuration = configuration, + ) Property changes on: branches/build_with_scons/numpy/testing/setupscons.py ___________________________________________________________________ Name: svn:executable + * From numpy-svn at scipy.org Sun Jan 6 21:46:57 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 20:46:57 -0600 (CST) Subject: [Numpy-svn] r4700 - branches/build_with_scons/numpy/numarray Message-ID: <20080107024657.5BC7239C098@new.scipy.org> Author: cdavid Date: 2008-01-06 20:46:49 -0600 (Sun, 06 Jan 2008) New Revision: 4700 Added: branches/build_with_scons/numpy/numarray/SConstruct branches/build_with_scons/numpy/numarray/setupscons.py Log: numarray now builds with scons Added: branches/build_with_scons/numpy/numarray/SConstruct =================================================================== --- branches/build_with_scons/numpy/numarray/SConstruct 2008-01-07 02:44:56 UTC (rev 4699) +++ branches/build_with_scons/numpy/numarray/SConstruct 2008-01-07 02:46:49 UTC (rev 4700) @@ -0,0 +1,12 @@ +# Last Change: Fri Oct 19 09:00 AM 2007 J +# vim:syntax=python +import __builtin__ +__builtin__.__NUMPY_SETUP__ = True +from numpy.distutils.misc_util import get_numpy_include_dirs +from numscons import GetNumpyEnvironment, scons_get_paths + +env = GetNumpyEnvironment(ARGUMENTS) +env.Append(CPPPATH = scons_get_paths(env['include_bootstrap'])) +env.Append(CPPPATH = env['src_dir']) + +_capi = env.NumpyPythonExtension('_capi', source = ['_capi.c']) Added: branches/build_with_scons/numpy/numarray/setupscons.py =================================================================== --- branches/build_with_scons/numpy/numarray/setupscons.py 2008-01-07 02:44:56 UTC (rev 4699) +++ branches/build_with_scons/numpy/numarray/setupscons.py 2008-01-07 02:46:49 UTC (rev 4700) @@ -0,0 +1,14 @@ +from os.path import join + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + config = Configuration('numarray',parent_package,top_path) + + config.add_data_files('numpy/') + config.add_sconscript('SConstruct', source_files = ['_capi.c']) + + return config + +if __name__ == '__main__': + from numpy.distutils.core import setup + setup(configuration=configuration) From numpy-svn at scipy.org Sun Jan 6 21:47:43 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 20:47:43 -0600 (CST) Subject: [Numpy-svn] r4701 - branches/build_with_scons/numpy/lib Message-ID: <20080107024743.529B539C098@new.scipy.org> Author: cdavid Date: 2008-01-06 20:47:36 -0600 (Sun, 06 Jan 2008) New Revision: 4701 Added: branches/build_with_scons/numpy/lib/SConstruct branches/build_with_scons/numpy/lib/setupscons.py Log: numpy.lib now builds with scons Added: branches/build_with_scons/numpy/lib/SConstruct =================================================================== --- branches/build_with_scons/numpy/lib/SConstruct 2008-01-07 02:46:49 UTC (rev 4700) +++ branches/build_with_scons/numpy/lib/SConstruct 2008-01-07 02:47:36 UTC (rev 4701) @@ -0,0 +1,12 @@ +# Last Change: Thu Oct 18 09:00 PM 2007 J +# vim:syntax=python +import __builtin__ +__builtin__.__NUMPY_SETUP__ = True +from numpy.distutils.misc_util import get_numpy_include_dirs +from numscons import GetNumpyEnvironment, scons_get_paths + +env = GetNumpyEnvironment(ARGUMENTS) +env.Append(CPPPATH = scons_get_paths(env['include_bootstrap'])) + +_compiled_base = env.NumpyPythonExtension('_compiled_base', + source = ['src/_compiled_base.c']) Added: branches/build_with_scons/numpy/lib/setupscons.py =================================================================== --- branches/build_with_scons/numpy/lib/setupscons.py 2008-01-07 02:46:49 UTC (rev 4700) +++ branches/build_with_scons/numpy/lib/setupscons.py 2008-01-07 02:47:36 UTC (rev 4701) @@ -0,0 +1,16 @@ +from os.path import join + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + + config = Configuration('lib',parent_package,top_path) + + config.add_sconscript('SConstruct', + source_files = [join('src', '_compiled_base.c')]) + config.add_data_dir('tests') + + return config + +if __name__=='__main__': + from numpy.distutils.core import setup + setup(configuration=configuration) From numpy-svn at scipy.org Sun Jan 6 21:48:35 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 6 Jan 2008 20:48:35 -0600 (CST) Subject: [Numpy-svn] r4702 - branches/build_with_scons/numpy/linalg Message-ID: <20080107024835.777F739C25D@new.scipy.org> Author: cdavid Date: 2008-01-06 20:48:27 -0600 (Sun, 06 Jan 2008) New Revision: 4702 Added: branches/build_with_scons/numpy/linalg/SConstruct branches/build_with_scons/numpy/linalg/setupscons.py Log: numpy.linalg now builds with scons Added: branches/build_with_scons/numpy/linalg/SConstruct =================================================================== --- branches/build_with_scons/numpy/linalg/SConstruct 2008-01-07 02:47:36 UTC (rev 4701) +++ branches/build_with_scons/numpy/linalg/SConstruct 2008-01-07 02:48:27 UTC (rev 4702) @@ -0,0 +1,33 @@ +# Last Change: Fri Nov 16 05:00 PM 2007 J +# vim:syntax=python +import os.path + +import __builtin__ +__builtin__.__NUMPY_SETUP__ = True + +from numpy.distutils.misc_util import get_numpy_include_dirs, get_mathlibs +from numscons import GetNumpyEnvironment, scons_get_paths, \ + scons_get_mathlib +from numscons import CheckF77LAPACK +from numscons.configuration import write_info + +env = GetNumpyEnvironment(ARGUMENTS) +env.Append(CPPPATH = scons_get_paths(env['include_bootstrap'])) + +config = env.NumpyConfigure(custom_tests = + {'CheckLAPACK' : CheckF77LAPACK}) + +use_lapack = config.CheckLAPACK() + +mlib = scons_get_mathlib(env) +env.AppendUnique(LIBS = mlib) + +config.Finish() +write_info(env) + +sources = ['lapack_litemodule.c'] +if not use_lapack: + sources.extend(['zlapack_lite.c', 'dlapack_lite.c', 'blas_lite.c', + 'dlamch.c', 'f2c_lite.c']) +lapack_lite = env.NumpyPythonExtension('lapack_lite', source = sources) + Added: branches/build_with_scons/numpy/linalg/setupscons.py =================================================================== --- branches/build_with_scons/numpy/linalg/setupscons.py 2008-01-07 02:47:36 UTC (rev 4701) +++ branches/build_with_scons/numpy/linalg/setupscons.py 2008-01-07 02:48:27 UTC (rev 4702) @@ -0,0 +1,20 @@ + +def configuration(parent_package='',top_path=None): + from numpy.distutils.misc_util import Configuration + from numpy.distutils.system_info import get_info + config = Configuration('linalg',parent_package,top_path) + + config.add_data_dir('tests') + + config.add_sconscript('SConstruct', + source_files = ['lapack_litemodule.c', + 'zlapack_lite.c', 'dlapack_lite.c', + 'blas_lite.c', 'dlamch.c', + 'f2c_lite.c','f2c.h'], + post_hook = config.add_configres) + + return config + +if __name__ == '__main__': + from numpy.distutils.core import setup + setup(configuration=configuration) From numpy-svn at scipy.org Mon Jan 7 09:59:31 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 7 Jan 2008 08:59:31 -0600 (CST) Subject: [Numpy-svn] r4703 - in branches/build_with_scons/numpy: core linalg Message-ID: <20080107145931.7458639C2AA@new.scipy.org> Author: cdavid Date: 2008-01-07 08:59:16 -0600 (Mon, 07 Jan 2008) New Revision: 4703 Modified: branches/build_with_scons/numpy/core/SConstruct branches/build_with_scons/numpy/linalg/SConstruct Log: Change write_info imports, put in top numscons namespace Modified: branches/build_with_scons/numpy/core/SConstruct =================================================================== --- branches/build_with_scons/numpy/core/SConstruct 2008-01-07 02:48:27 UTC (rev 4702) +++ branches/build_with_scons/numpy/core/SConstruct 2008-01-07 14:59:16 UTC (rev 4703) @@ -8,7 +8,7 @@ from numscons import get_python_inc, get_pythonlib_dir from numscons import GetNumpyEnvironment from numscons import CheckCBLAS -from numscons.configuration import write_info +from numscons import write_info from scons_support import CheckBrokenMathlib, define_no_smp, \ generate_config_header, generate_config_header_emitter Modified: branches/build_with_scons/numpy/linalg/SConstruct =================================================================== --- branches/build_with_scons/numpy/linalg/SConstruct 2008-01-07 02:48:27 UTC (rev 4702) +++ branches/build_with_scons/numpy/linalg/SConstruct 2008-01-07 14:59:16 UTC (rev 4703) @@ -9,7 +9,7 @@ from numscons import GetNumpyEnvironment, scons_get_paths, \ scons_get_mathlib from numscons import CheckF77LAPACK -from numscons.configuration import write_info +from numscons import write_info env = GetNumpyEnvironment(ARGUMENTS) env.Append(CPPPATH = scons_get_paths(env['include_bootstrap'])) From numpy-svn at scipy.org Mon Jan 7 16:20:09 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 7 Jan 2008 15:20:09 -0600 (CST) Subject: [Numpy-svn] r4704 - trunk/numpy/core/src Message-ID: <20080107212009.908AA39C0A4@new.scipy.org> Author: oliphant Date: 2008-01-07 15:20:06 -0600 (Mon, 07 Jan 2008) New Revision: 4704 Modified: trunk/numpy/core/src/scalartypes.inc.src Log: Fix scalar __array_interface__ by making sure to retain a reference the 0-d array created in the returned dictionary. Modified: trunk/numpy/core/src/scalartypes.inc.src =================================================================== --- trunk/numpy/core/src/scalartypes.inc.src 2008-01-07 14:59:16 UTC (rev 4703) +++ trunk/numpy/core/src/scalartypes.inc.src 2008-01-07 21:20:06 UTC (rev 4704) @@ -863,6 +863,7 @@ arr = (PyArrayObject *)PyArray_FromScalar(self, NULL); if (arr == NULL) return NULL; inter = PyObject_GetAttrString((PyObject *)arr, "__array_interface__"); + if (inter != NULL) PyDict_SetItemString(inter, "__ref", (PyObject *)arr); Py_DECREF(arr); return inter; } From numpy-svn at scipy.org Tue Jan 8 00:50:41 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 7 Jan 2008 23:50:41 -0600 (CST) Subject: [Numpy-svn] r4705 - branches/build_with_scons/numpy/core/src Message-ID: <20080108055041.44E4D39C102@new.scipy.org> Author: cdavid Date: 2008-01-07 23:50:36 -0600 (Mon, 07 Jan 2008) New Revision: 4705 Modified: branches/build_with_scons/numpy/core/src/scalartypes.inc.src Log: Merged revisions 4677-4704 from http://svn.scipy.org/svn/numpy/trunk Modified: branches/build_with_scons/numpy/core/src/scalartypes.inc.src =================================================================== --- branches/build_with_scons/numpy/core/src/scalartypes.inc.src 2008-01-07 21:20:06 UTC (rev 4704) +++ branches/build_with_scons/numpy/core/src/scalartypes.inc.src 2008-01-08 05:50:36 UTC (rev 4705) @@ -863,6 +863,7 @@ arr = (PyArrayObject *)PyArray_FromScalar(self, NULL); if (arr == NULL) return NULL; inter = PyObject_GetAttrString((PyObject *)arr, "__array_interface__"); + if (inter != NULL) PyDict_SetItemString(inter, "__ref", (PyObject *)arr); Py_DECREF(arr); return inter; } From numpy-svn at scipy.org Tue Jan 8 07:18:52 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 8 Jan 2008 06:18:52 -0600 (CST) Subject: [Numpy-svn] r4706 - branches/build_with_scons/numpy/core Message-ID: <20080108121852.3AA9439C15C@new.scipy.org> Author: cdavid Date: 2008-01-08 06:18:46 -0600 (Tue, 08 Jan 2008) New Revision: 4706 Modified: branches/build_with_scons/numpy/core/SConstruct branches/build_with_scons/numpy/core/scons_support.py Log: Refactor the check for m library + functions in numpy.core SConstruct Modified: branches/build_with_scons/numpy/core/SConstruct =================================================================== --- branches/build_with_scons/numpy/core/SConstruct 2008-01-08 05:50:36 UTC (rev 4705) +++ branches/build_with_scons/numpy/core/SConstruct 2008-01-08 12:18:46 UTC (rev 4706) @@ -1,4 +1,4 @@ -# Last Change: Sun Jan 06 10:00 PM 2008 J +# Last Change: Tue Jan 08 09:00 PM 2008 J # vim:syntax=python import os import sys @@ -11,7 +11,8 @@ from numscons import write_info from scons_support import CheckBrokenMathlib, define_no_smp, \ - generate_config_header, generate_config_header_emitter + generate_config_header, generate_config_header_emitter, \ + check_mlib, check_mlibs env = GetNumpyEnvironment(ARGUMENTS) env.Append(CPPPATH = [get_python_inc()]) @@ -26,7 +27,7 @@ #======================= # XXX: separate env for configuration config = env.NumpyConfigure(custom_tests = {'CheckBrokenMathlib' : CheckBrokenMathlib, - 'CheckCBLAS' : CheckCBLAS}) + 'CheckCBLAS' : CheckCBLAS}, config_h = 'scons_config.h') # Convention: list of tuples (definition, value). value: # - 0: #undef definition @@ -86,16 +87,9 @@ mathlib = os.environ.get('MATHLIB') if mathlib: mlibs.insert(0, mathlib) -for mlib in mlibs: - st = config.CheckBrokenMathlib(mlib) - if st: - break -if not st: - import SCons - raise SCons.Errors.UserError("No usable mathlib was found: chose another "\ - "one using the MATHLIB env variable, eg "\ - "'MATHLIB=m python setup.py build'") +mlib = check_mlibs(config, mlibs) + # XXX: this is ugly: mathlib has nothing to do in a public header file config_sym.append(('MATHLIB', ','.join(mlib))) @@ -103,7 +97,7 @@ """Check that f is available in mlib, and add the symbol appropriately. f is expected to be a tuble (symbol, cpp define).""" - st = config.CheckLibWithHeader(mlib, 'math.h', language = 'C', call = '%s;' % f[0], autoadd = autoadd) + st = config.CheckFunc(f[0], language = 'C') if st: config_sym.append((f[1], 1)) else: Modified: branches/build_with_scons/numpy/core/scons_support.py =================================================================== --- branches/build_with_scons/numpy/core/scons_support.py 2008-01-08 05:50:36 UTC (rev 4705) +++ branches/build_with_scons/numpy/core/scons_support.py 2008-01-08 12:18:46 UTC (rev 4706) @@ -1,4 +1,4 @@ -#! Last Change: Sun Jan 06 09:00 PM 2008 J +#! Last Change: Tue Jan 08 08:00 PM 2008 J __docstring__ = """Code to support special facilities to scons which are only useful for numpy.core, hence not put into numpy.distutils.scons""" @@ -18,6 +18,7 @@ from numscons.core.utils import rsplit, isstring import SCons.Node +import SCons def split_ext(string): sp = rsplit(string, '.', 1) @@ -160,6 +161,31 @@ context.Result(' No !') return st[0] +def check_mlib(config, mlib): + """Return 1 if mlib is available and usable by numpy, 0 otherwise. + + mlib can be a string (one library), or a list of libraries.""" + # Check the libraries in mlib are linkable + if len(mlib) > 0: + # XXX: put an autoadd argument to 0 here and add an autoadd argument to + # CheckBroekenMathlib (otherwise we may add bogus libraries, the ones + # which do not path the CheckBrokenMathlib test). + st = config.CheckLib(mlib) + if not st: + return 0 + # Check the mlib is usable by numpy + return config.CheckBrokenMathlib(mlib) + +def check_mlibs(config, mlibs): + for mlib in mlibs: + if check_mlib(config, mlib): + return mlib + + # No mlib was found. + raise SCons.Errors.UserError("No usable mathlib was found: chose another "\ + "one using the MATHLIB env variable, eg "\ + "'MATHLIB=m python setup.py build'") + def define_no_smp(): """Returns True if we should define NPY_NOSMP, False otherwise.""" #-------------------------------- From numpy-svn at scipy.org Tue Jan 8 07:45:16 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 8 Jan 2008 06:45:16 -0600 (CST) Subject: [Numpy-svn] r4707 - branches/build_with_scons/numpy/core Message-ID: <20080108124516.5D40439C046@new.scipy.org> Author: cdavid Date: 2008-01-08 06:45:12 -0600 (Tue, 08 Jan 2008) New Revision: 4707 Modified: branches/build_with_scons/numpy/core/SConstruct Log: Add PyOS_ascii_strtod test for automatic config header generation Modified: branches/build_with_scons/numpy/core/SConstruct =================================================================== --- branches/build_with_scons/numpy/core/SConstruct 2008-01-08 12:18:46 UTC (rev 4706) +++ branches/build_with_scons/numpy/core/SConstruct 2008-01-08 12:45:12 UTC (rev 4707) @@ -110,6 +110,13 @@ #------------------------------------------------------- # Define the function PyOS_ascii_strod if not available #------------------------------------------------------- +if not config.CheckDeclaration('PyOS_ascii_strtod', + includes = "#include "): + if config.CheckFunc('strtod'): + config.Define('PyOS_ascii_strtod', 'strtod', + "Define to a function to use as a replacement for "\ + "PyOS_ascii_strtod if not available in python header") + # XXX: would be better to check for PyOS_ascii_strod instead of version if sys.version[:3] < '2.4': if config.CheckFunc('strtod'): From numpy-svn at scipy.org Tue Jan 8 08:10:55 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 8 Jan 2008 07:10:55 -0600 (CST) Subject: [Numpy-svn] r4708 - branches/build_with_scons/numpy/core Message-ID: <20080108131055.C7362C7C023@new.scipy.org> Author: cdavid Date: 2008-01-08 07:10:52 -0600 (Tue, 08 Jan 2008) New Revision: 4708 Modified: branches/build_with_scons/numpy/core/SConstruct Log: More work on automatic generation of config.h (not ready yet) Modified: branches/build_with_scons/numpy/core/SConstruct =================================================================== --- branches/build_with_scons/numpy/core/SConstruct 2008-01-08 12:45:12 UTC (rev 4707) +++ branches/build_with_scons/numpy/core/SConstruct 2008-01-08 13:10:52 UTC (rev 4708) @@ -1,4 +1,4 @@ -# Last Change: Tue Jan 08 09:00 PM 2008 J +# Last Change: Tue Jan 08 10:00 PM 2008 J # vim:syntax=python import os import sys @@ -93,7 +93,7 @@ # XXX: this is ugly: mathlib has nothing to do in a public header file config_sym.append(('MATHLIB', ','.join(mlib))) -def check_lib(f, autoadd = 0): +def check_func(f): """Check that f is available in mlib, and add the symbol appropriately. f is expected to be a tuble (symbol, cpp define).""" @@ -103,9 +103,8 @@ else: config_sym.append((f[1], 0)) -check_lib(mfuncs[0], autoadd = 1) -for f in mfuncs[1:]: - check_lib(f) +for f in mfuncs: + check_func(f) #------------------------------------------------------- # Define the function PyOS_ascii_strod if not available @@ -124,16 +123,23 @@ if define_no_smp(): config_sym.append(('NPY_NOSMP', '1')) + config.Define('NPY_NOSMP', 1, "define to 1 to disable SMP support ") else: config_sym.append(('NPY_NOSMP', '0')) + config.Define('NPY_NOSMP', 0, "define to 1 to disable SMP support ") # XXX: this is ugly +distutils_use_sdk = 0 if sys.platform=='win32' or os.name=='nt': from distutils.msvccompiler import get_build_architecture a = get_build_architecture() print 'BUILD_ARCHITECTURE: %r, os.name=%r, sys.platform=%r' % (a, os.name, sys.platform) if a == 'AMD64': - moredefs.append(('DISTUTILS_USE_SDK', 1)) + distutils_use_sdk = 1 +if distutils_use_sdk: + moredefs.append(('DISTUTILS_USE_SDK', 1)) +config.Define('DISTUTILS_USE_SDK', distutils_use_sdk, + "define to 1 to disable SMP support ") #-------------- # Checking Blas From numpy-svn at scipy.org Tue Jan 8 08:31:25 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 8 Jan 2008 07:31:25 -0600 (CST) Subject: [Numpy-svn] r4709 - branches/build_with_scons/numpy/core Message-ID: <20080108133125.86D71C7C031@new.scipy.org> Author: cdavid Date: 2008-01-08 07:31:21 -0600 (Tue, 08 Jan 2008) New Revision: 4709 Modified: branches/build_with_scons/numpy/core/SConstruct Log: Add groupe of math functions availability in generated config header Modified: branches/build_with_scons/numpy/core/SConstruct =================================================================== --- branches/build_with_scons/numpy/core/SConstruct 2008-01-08 13:10:52 UTC (rev 4708) +++ branches/build_with_scons/numpy/core/SConstruct 2008-01-08 13:31:21 UTC (rev 4709) @@ -82,6 +82,9 @@ ('rint', 'HAVE_RINT'), ] +# Set value to 1 for each defined function (in math lib) +mfuncs_defined = dict([(f[0], 0) for f in mfuncs]) + # TODO: checklib vs checkfunc ? mlibs = [[], ['m'], ['cpml']] mathlib = os.environ.get('MATHLIB') @@ -102,10 +105,27 @@ config_sym.append((f[1], 1)) else: config_sym.append((f[1], 0)) + mfuncs_defined[f[0]] = 1 for f in mfuncs: check_func(f) +if mfuncs_defined['expl'] == 1: + config.Define('HAVE_LONGDOUBLE_FUNCS', 1, + 'Define to 1 if long double funcs are available') +if mfuncs_defined['expf'] == 1: + config.Define('HAVE_FLOAT_FUNCS', 1, + 'Define to 1 if long double funcs are available') +if mfuncs_defined['asinh'] == 1: + config.Define('HAVE_INVERSE_HYPERBOLIC', 1, + 'Define to 1 if inverse hyperbolic funcs are available') +if mfuncs_defined['atanhf'] == 1: + config.Define('HAVE_INVERSE_HYPERBOLIC_FLOAT', 1, + 'Define to 1 if inverse hyperbolic float funcs are available') +if mfuncs_defined['atanhl'] == 1: + config.Define('HAVE_INVERSE_HYPERBOLIC_LONGDOUBLE', 1, + 'Define to 1 if inverse hyperbolic long double funcs are available') + #------------------------------------------------------- # Define the function PyOS_ascii_strod if not available #------------------------------------------------------- From numpy-svn at scipy.org Tue Jan 8 08:46:51 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 8 Jan 2008 07:46:51 -0600 (CST) Subject: [Numpy-svn] r4710 - branches/build_with_scons/numpy/core Message-ID: <20080108134651.A557A39C112@new.scipy.org> Author: cdavid Date: 2008-01-08 07:46:46 -0600 (Tue, 08 Jan 2008) New Revision: 4710 Modified: branches/build_with_scons/numpy/core/SConstruct branches/build_with_scons/numpy/core/scons_support.py Log: Now we use automatically generated config header instead of old kludge taken from setup.py. Modified: branches/build_with_scons/numpy/core/SConstruct =================================================================== --- branches/build_with_scons/numpy/core/SConstruct 2008-01-08 13:31:21 UTC (rev 4709) +++ branches/build_with_scons/numpy/core/SConstruct 2008-01-08 13:46:46 UTC (rev 4710) @@ -12,7 +12,7 @@ from scons_support import CheckBrokenMathlib, define_no_smp, \ generate_config_header, generate_config_header_emitter, \ - check_mlib, check_mlibs + check_mlib, check_mlibs, is_npy_no_signal env = GetNumpyEnvironment(ARGUMENTS) env.Append(CPPPATH = [get_python_inc()]) @@ -27,7 +27,7 @@ #======================= # XXX: separate env for configuration config = env.NumpyConfigure(custom_tests = {'CheckBrokenMathlib' : CheckBrokenMathlib, - 'CheckCBLAS' : CheckCBLAS}, config_h = 'scons_config.h') + 'CheckCBLAS' : CheckCBLAS}, config_h = pjoin(env['build_dir'], 'config.h')) # Convention: list of tuples (definition, value). value: # - 0: #undef definition @@ -64,7 +64,9 @@ #---------------------- # Checking signal stuff #---------------------- -# TODO +if is_npy_no_signal(): + config_sym.append(('NPY_NOSMP', '1')) + config.Define('NPY_NOSMP', 1, "define to 1 to disable SMP support ") #------------------------------------------ # Checking the mathlib and its capabilities @@ -157,9 +159,9 @@ if a == 'AMD64': distutils_use_sdk = 1 if distutils_use_sdk: - moredefs.append(('DISTUTILS_USE_SDK', 1)) -config.Define('DISTUTILS_USE_SDK', distutils_use_sdk, - "define to 1 to disable SMP support ") + moredefs.append('DISTUTILS_USE_SDK') + config.Define('DISTUTILS_USE_SDK', distutils_use_sdk, + "define to 1 to disable SMP support ") #-------------- # Checking Blas @@ -228,7 +230,7 @@ # option ?) from os.path import join as pjoin -config_header = env.GenerateConfigHeader(pjoin(env['build_dir'], 'config.h'), []) +#config_header = env.GenerateConfigHeader(pjoin(env['build_dir'], 'config.h'), []) scalartypes_src = env.GenerateFromTemplate( pjoin(env['build_dir'], 'src', 'scalartypes'), Modified: branches/build_with_scons/numpy/core/scons_support.py =================================================================== --- branches/build_with_scons/numpy/core/scons_support.py 2008-01-08 13:31:21 UTC (rev 4709) +++ branches/build_with_scons/numpy/core/scons_support.py 2008-01-08 13:46:46 UTC (rev 4710) @@ -1,4 +1,4 @@ -#! Last Change: Tue Jan 08 08:00 PM 2008 J +#! Last Change: Tue Jan 08 10:00 PM 2008 J __docstring__ = """Code to support special facilities to scons which are only useful for numpy.core, hence not put into numpy.distutils.scons""" @@ -186,6 +186,12 @@ "one using the MATHLIB env variable, eg "\ "'MATHLIB=m python setup.py build'") + +def is_npy_no_signal(): + """Return True if the NPY_NO_SIGNAL symbol must be defined in configuration + header.""" + return sys.platform == 'win32' + def define_no_smp(): """Returns True if we should define NPY_NOSMP, False otherwise.""" #-------------------------------- From numpy-svn at scipy.org Tue Jan 8 08:49:43 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 8 Jan 2008 07:49:43 -0600 (CST) Subject: [Numpy-svn] r4711 - branches/build_with_scons/numpy/core Message-ID: <20080108134943.6819539C112@new.scipy.org> Author: cdavid Date: 2008-01-08 07:49:39 -0600 (Tue, 08 Jan 2008) New Revision: 4711 Modified: branches/build_with_scons/numpy/core/SConstruct branches/build_with_scons/numpy/core/scons_support.py Log: Remove deprecated builder for config.h Modified: branches/build_with_scons/numpy/core/SConstruct =================================================================== --- branches/build_with_scons/numpy/core/SConstruct 2008-01-08 13:46:46 UTC (rev 4710) +++ branches/build_with_scons/numpy/core/SConstruct 2008-01-08 13:49:39 UTC (rev 4711) @@ -11,7 +11,6 @@ from numscons import write_info from scons_support import CheckBrokenMathlib, define_no_smp, \ - generate_config_header, generate_config_header_emitter, \ check_mlib, check_mlibs, is_npy_no_signal env = GetNumpyEnvironment(ARGUMENTS) @@ -213,14 +212,10 @@ umath_bld = Builder(action = generate_umath, emitter = generate_umath_emitter) -config_h_bld = Builder(action = generate_config_header, - emitter = generate_config_header_emitter) - env.Append(BUILDERS = {'GenerateMultiarrayApi' : array_api_gen_bld, 'GenerateUfuncApi' : ufunc_api_gen_bld, 'GenerateFromTemplate' : template_bld, - 'GenerateUmath' : umath_bld, - 'GenerateConfigHeader' : config_h_bld}) + 'GenerateUmath' : umath_bld}) #------------------------ # Generate generated code @@ -230,8 +225,6 @@ # option ?) from os.path import join as pjoin -#config_header = env.GenerateConfigHeader(pjoin(env['build_dir'], 'config.h'), []) - scalartypes_src = env.GenerateFromTemplate( pjoin(env['build_dir'], 'src', 'scalartypes'), pjoin(env['src_dir'], 'src', 'scalartypes.inc.src')) Modified: branches/build_with_scons/numpy/core/scons_support.py =================================================================== --- branches/build_with_scons/numpy/core/scons_support.py 2008-01-08 13:46:46 UTC (rev 4710) +++ branches/build_with_scons/numpy/core/scons_support.py 2008-01-08 13:49:39 UTC (rev 4711) @@ -93,43 +93,6 @@ t = str(target[0]) + '.c' return ([t], source) -#------------------- -# Generate config.h -#------------------- -def generate_config_header(target, source, env): - t = open(str(target[0]), 'w') - if not env.has_key('CONFIG_H_GEN'): - # XXX - assert 0 == 1 - sym = env['CONFIG_H_GEN'] - def write_symbol(define, value): - if value == 1: - return "#define %s\n\n" % define - elif value == 0: - return "/* #undef %s */\n\n" % define - elif isstring(value): - return "#define %s %s\n\n" % (define, value) - else: - return "#define %s %s\n\n" % (define, ','.join(value)) - t.writelines([write_symbol(i[0], i[1]) for i in sym]) - t.write('\n') - t.close() - - print 'File: %s' % target[0] - target_f = open(str(target[0])) - print target_f.read() - target_f.close() - print 'EOF' - return 0 - -def generate_config_header_emitter(target, source, env): - """Add dependency from config list CONFIG_H_GEN to target. Returns - original target, source tuple unchanged. """ - from SCons.Script import Depends - d = deepcopy(env['CONFIG_H_GEN']) # copy it - Depends(target, SCons.Node.Python.Value(d)) - return target, source - #----------------------------------------- # Other functions related to configuration #----------------------------------------- From numpy-svn at scipy.org Tue Jan 8 08:54:17 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 8 Jan 2008 07:54:17 -0600 (CST) Subject: [Numpy-svn] r4712 - branches/build_with_scons/numpy/core Message-ID: <20080108135417.7D84A39C112@new.scipy.org> Author: cdavid Date: 2008-01-08 07:54:13 -0600 (Tue, 08 Jan 2008) New Revision: 4712 Modified: branches/build_with_scons/numpy/core/SConstruct Log: Simplify math funcs check in SConstruct Modified: branches/build_with_scons/numpy/core/SConstruct =================================================================== --- branches/build_with_scons/numpy/core/SConstruct 2008-01-08 13:49:39 UTC (rev 4711) +++ branches/build_with_scons/numpy/core/SConstruct 2008-01-08 13:54:13 UTC (rev 4712) @@ -71,20 +71,11 @@ # Checking the mathlib and its capabilities #------------------------------------------ # Function to check: -mfuncs = [('expl', 'HAVE_LONGDOUBLE_FUNCS'), - ('expf', 'HAVE_FLOAT_FUNCS'), - ('log1p', 'HAVE_LOG1P'), - ('expm1', 'HAVE_EXPM1'), - ('asinh', 'HAVE_INVERSE_HYPERBOLIC'), - ('atanhf', 'HAVE_INVERSE_HYPERBOLIC_FLOAT'), - ('atanhl', 'HAVE_INVERSE_HYPERBOLIC_LONGDOUBLE'), - ('isnan', 'HAVE_ISNAN'), - ('isinf', 'HAVE_ISINF'), - ('rint', 'HAVE_RINT'), - ] +mfuncs = ('expl', 'expf', 'log1p', 'expm1', 'asinh', 'atanhf', 'atanhl', + 'isnan', 'isinf', 'rint') # Set value to 1 for each defined function (in math lib) -mfuncs_defined = dict([(f[0], 0) for f in mfuncs]) +mfuncs_defined = dict([(f, 0) for f in mfuncs]) # TODO: checklib vs checkfunc ? mlibs = [[], ['m'], ['cpml']] @@ -101,12 +92,12 @@ """Check that f is available in mlib, and add the symbol appropriately. f is expected to be a tuble (symbol, cpp define).""" - st = config.CheckFunc(f[0], language = 'C') + st = config.CheckFunc(f, language = 'C') if st: - config_sym.append((f[1], 1)) + config_sym.append((f, 1)) else: - config_sym.append((f[1], 0)) - mfuncs_defined[f[0]] = 1 + config_sym.append((f, 0)) + mfuncs_defined[f] = 1 for f in mfuncs: check_func(f) From numpy-svn at scipy.org Tue Jan 8 09:02:10 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 8 Jan 2008 08:02:10 -0600 (CST) Subject: [Numpy-svn] r4713 - branches/build_with_scons/numpy/core Message-ID: <20080108140210.0A78239C046@new.scipy.org> Author: cdavid Date: 2008-01-08 08:02:05 -0600 (Tue, 08 Jan 2008) New Revision: 4713 Modified: branches/build_with_scons/numpy/core/SConstruct Log: More cleaning of numpy.core SConstruct Modified: branches/build_with_scons/numpy/core/SConstruct =================================================================== --- branches/build_with_scons/numpy/core/SConstruct 2008-01-08 13:54:13 UTC (rev 4712) +++ branches/build_with_scons/numpy/core/SConstruct 2008-01-08 14:02:05 UTC (rev 4713) @@ -32,7 +32,7 @@ # - 0: #undef definition # - 1: #define definition # - string: #define definition value -config_sym = [] +numpyconfig_sym = [] #--------------- # Checking Types @@ -41,25 +41,16 @@ st = config.CheckTypeSize(type, includes = include) type = type.replace(' ', '_') if st: - config_sym.append(('SIZEOF_%s' % type.upper(), '%d' % st)) + numpyconfig_sym.append(('SIZEOF_%s' % type.upper(), '%d' % st)) else: - config_sym.append(('SIZEOF_%s' % type.upper(), 0)) + numpyconfig_sym.append(('SIZEOF_%s' % type.upper(), 0)) -check_type('short') -check_type('int') -check_type('long') -check_type('float') -check_type('double') -check_type('long double') -check_type('Py_intptr_t', include = "#include \n") -check_type('PY_LONG_LONG', include = "#include \n") +for type in ('short', 'int', 'long', 'float', 'double', 'long double'): + check_type(type) -# TODO: check python extension can be built (in root or here ?) +for type in ('Py_intptr_t', 'PY_LONG_LONG'): + check_type(type, include = "#include \n") -#----------------------- -# Checking configuration -#----------------------- - #---------------------- # Checking signal stuff #---------------------- @@ -67,17 +58,19 @@ config_sym.append(('NPY_NOSMP', '1')) config.Define('NPY_NOSMP', 1, "define to 1 to disable SMP support ") -#------------------------------------------ -# Checking the mathlib and its capabilities -#------------------------------------------ -# Function to check: -mfuncs = ('expl', 'expf', 'log1p', 'expm1', 'asinh', 'atanhf', 'atanhl', - 'isnan', 'isinf', 'rint') +#--------------------- +# Checking SMP option +#--------------------- +if define_no_smp(): + config_sym.append(('NPY_NOSMP', '1')) + config.Define('NPY_NOSMP', 1, "define to 1 to disable SMP support ") +else: + config_sym.append(('NPY_NOSMP', '0')) + config.Define('NPY_NOSMP', 0, "define to 1 to disable SMP support ") -# Set value to 1 for each defined function (in math lib) -mfuncs_defined = dict([(f, 0) for f in mfuncs]) - -# TODO: checklib vs checkfunc ? +#---------------------- +# Checking the mathlib +#---------------------- mlibs = [[], ['m'], ['cpml']] mathlib = os.environ.get('MATHLIB') if mathlib: @@ -88,15 +81,22 @@ # XXX: this is ugly: mathlib has nothing to do in a public header file config_sym.append(('MATHLIB', ','.join(mlib))) +#---------------------------------- +# Checking the math funcs available +#---------------------------------- +# Function to check: +mfuncs = ('expl', 'expf', 'log1p', 'expm1', 'asinh', 'atanhf', 'atanhl', + 'isnan', 'isinf', 'rint') + +# Set value to 1 for each defined function (in math lib) +mfuncs_defined = dict([(f, 0) for f in mfuncs]) + +# TODO: checklib vs checkfunc ? def check_func(f): """Check that f is available in mlib, and add the symbol appropriately. f is expected to be a tuble (symbol, cpp define).""" st = config.CheckFunc(f, language = 'C') - if st: - config_sym.append((f, 1)) - else: - config_sym.append((f, 0)) mfuncs_defined[f] = 1 for f in mfuncs: @@ -128,30 +128,18 @@ "Define to a function to use as a replacement for "\ "PyOS_ascii_strtod if not available in python header") -# XXX: would be better to check for PyOS_ascii_strod instead of version -if sys.version[:3] < '2.4': - if config.CheckFunc('strtod'): - config_sym.append(('PyOS_ascii_strtod', 'strtod')) - -if define_no_smp(): - config_sym.append(('NPY_NOSMP', '1')) - config.Define('NPY_NOSMP', 1, "define to 1 to disable SMP support ") -else: - config_sym.append(('NPY_NOSMP', '0')) - config.Define('NPY_NOSMP', 0, "define to 1 to disable SMP support ") - +#------------------------------------ +# DISTUTILS Hack on AMD64 on windows +#------------------------------------ # XXX: this is ugly -distutils_use_sdk = 0 if sys.platform=='win32' or os.name=='nt': from distutils.msvccompiler import get_build_architecture a = get_build_architecture() print 'BUILD_ARCHITECTURE: %r, os.name=%r, sys.platform=%r' % (a, os.name, sys.platform) if a == 'AMD64': distutils_use_sdk = 1 -if distutils_use_sdk: - moredefs.append('DISTUTILS_USE_SDK') - config.Define('DISTUTILS_USE_SDK', distutils_use_sdk, - "define to 1 to disable SMP support ") + config.Define('DISTUTILS_USE_SDK', distutils_use_sdk, + "define to 1 to disable SMP support ") #-------------- # Checking Blas @@ -173,7 +161,7 @@ #--------------------------------------- config_dict = {} # XXX: this is ugly, make the API for config.h and numpyconfig.h similar -for key, value in config_sym: +for key, value in numpyconfig_sym: config_dict['@%s@' % key] = str(value) env['SUBST_DICT'] = config_dict @@ -181,7 +169,7 @@ env.SubstInFile(pjoin(env['build_dir'], 'numpyconfig.h'), pjoin(env['src_dir'], include_dir, 'numpyconfig.h.in')) -env['CONFIG_H_GEN'] = config_sym +env['CONFIG_H_GEN'] = numpyconfig_sym #--------------------------- # Builder for generated code From numpy-svn at scipy.org Tue Jan 8 09:11:58 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 8 Jan 2008 08:11:58 -0600 (CST) Subject: [Numpy-svn] r4714 - branches/build_with_scons/numpy/core Message-ID: <20080108141158.3A7CA39C046@new.scipy.org> Author: cdavid Date: 2008-01-08 08:11:53 -0600 (Tue, 08 Jan 2008) New Revision: 4714 Modified: branches/build_with_scons/numpy/core/SConstruct branches/build_with_scons/numpy/core/scons_support.py Log: Trivial cleanings in numpy.core SConstruct Modified: branches/build_with_scons/numpy/core/SConstruct =================================================================== --- branches/build_with_scons/numpy/core/SConstruct 2008-01-08 14:02:05 UTC (rev 4713) +++ branches/build_with_scons/numpy/core/SConstruct 2008-01-08 14:11:53 UTC (rev 4714) @@ -24,10 +24,12 @@ #======================= # Starting Configuration #======================= -# XXX: separate env for configuration config = env.NumpyConfigure(custom_tests = {'CheckBrokenMathlib' : CheckBrokenMathlib, 'CheckCBLAS' : CheckCBLAS}, config_h = pjoin(env['build_dir'], 'config.h')) +# numpyconfig_sym will keep the values of some configuration variables, the one +# needed for the public numpy API. + # Convention: list of tuples (definition, value). value: # - 0: #undef definition # - 1: #define definition Modified: branches/build_with_scons/numpy/core/scons_support.py =================================================================== --- branches/build_with_scons/numpy/core/scons_support.py 2008-01-08 14:02:05 UTC (rev 4713) +++ branches/build_with_scons/numpy/core/scons_support.py 2008-01-08 14:11:53 UTC (rev 4714) @@ -1,7 +1,7 @@ #! Last Change: Tue Jan 08 10:00 PM 2008 J -__docstring__ = """Code to support special facilities to scons which are only -useful for numpy.core, hence not put into numpy.distutils.scons""" +"""Code to support special facilities to scons which are only useful for +numpy.core, hence not put into numpy.distutils.scons""" import sys import os @@ -181,4 +181,3 @@ except KeyError: nosmp = 0 return nosmp == 1 - From numpy-svn at scipy.org Tue Jan 8 10:48:43 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 8 Jan 2008 09:48:43 -0600 (CST) Subject: [Numpy-svn] r4715 - branches/build_with_scons/numpy/core Message-ID: <20080108154843.49B9039C275@new.scipy.org> Author: cdavid Date: 2008-01-08 09:48:36 -0600 (Tue, 08 Jan 2008) New Revision: 4715 Modified: branches/build_with_scons/numpy/core/SConstruct Log: Fix typo in numpy.core SConstruct Modified: branches/build_with_scons/numpy/core/SConstruct =================================================================== --- branches/build_with_scons/numpy/core/SConstruct 2008-01-08 14:11:53 UTC (rev 4714) +++ branches/build_with_scons/numpy/core/SConstruct 2008-01-08 15:48:36 UTC (rev 4715) @@ -1,4 +1,4 @@ -# Last Change: Tue Jan 08 10:00 PM 2008 J +# Last Change: Wed Jan 09 12:00 AM 2008 J # vim:syntax=python import os import sys @@ -57,17 +57,17 @@ # Checking signal stuff #---------------------- if is_npy_no_signal(): - config_sym.append(('NPY_NOSMP', '1')) + numpyconfig_sym.append(('NPY_NOSMP', '1')) config.Define('NPY_NOSMP', 1, "define to 1 to disable SMP support ") #--------------------- # Checking SMP option #--------------------- if define_no_smp(): - config_sym.append(('NPY_NOSMP', '1')) + numpyconfig_sym.append(('NPY_NOSMP', '1')) config.Define('NPY_NOSMP', 1, "define to 1 to disable SMP support ") else: - config_sym.append(('NPY_NOSMP', '0')) + numpyconfig_sym.append(('NPY_NOSMP', '0')) config.Define('NPY_NOSMP', 0, "define to 1 to disable SMP support ") #---------------------- @@ -81,7 +81,7 @@ mlib = check_mlibs(config, mlibs) # XXX: this is ugly: mathlib has nothing to do in a public header file -config_sym.append(('MATHLIB', ','.join(mlib))) +numpyconfig_sym.append(('MATHLIB', ','.join(mlib))) #---------------------------------- # Checking the math funcs available From numpy-svn at scipy.org Tue Jan 8 10:56:51 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 8 Jan 2008 09:56:51 -0600 (CST) Subject: [Numpy-svn] r4716 - branches/build_with_scons/numpy/core Message-ID: <20080108155651.2A35D39C07F@new.scipy.org> Author: cdavid Date: 2008-01-08 09:56:46 -0600 (Tue, 08 Jan 2008) New Revision: 4716 Modified: branches/build_with_scons/numpy/core/SConstruct Log: Trivial cleaning of numpy.core SConstruct Modified: branches/build_with_scons/numpy/core/SConstruct =================================================================== --- branches/build_with_scons/numpy/core/SConstruct 2008-01-08 15:48:36 UTC (rev 4715) +++ branches/build_with_scons/numpy/core/SConstruct 2008-01-08 15:56:46 UTC (rev 4716) @@ -63,12 +63,9 @@ #--------------------- # Checking SMP option #--------------------- -if define_no_smp(): - numpyconfig_sym.append(('NPY_NOSMP', '1')) - config.Define('NPY_NOSMP', 1, "define to 1 to disable SMP support ") -else: - numpyconfig_sym.append(('NPY_NOSMP', '0')) - config.Define('NPY_NOSMP', 0, "define to 1 to disable SMP support ") +st = define_no_smp(): +numpyconfig_sym.append(('NPY_NOSMP', st)) +config.Define('NPY_NOSMP', st, "define to 1 to disable SMP support ") #---------------------- # Checking the mathlib From numpy-svn at scipy.org Tue Jan 8 18:59:57 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 8 Jan 2008 17:59:57 -0600 (CST) Subject: [Numpy-svn] r4717 - trunk/numpy/core Message-ID: <20080108235957.B4B6E39C062@new.scipy.org> Author: jarrod.millman Date: 2008-01-08 17:59:54 -0600 (Tue, 08 Jan 2008) New Revision: 4717 Modified: trunk/numpy/core/numeric.py Log: typo Modified: trunk/numpy/core/numeric.py =================================================================== --- trunk/numpy/core/numeric.py 2008-01-08 15:56:46 UTC (rev 4716) +++ trunk/numpy/core/numeric.py 2008-01-08 23:59:54 UTC (rev 4717) @@ -667,7 +667,7 @@ fname can be a filename or a file handle. Support for gzipped files is automatic, if the filename ends in .gz - See scipy.loadmat to read and write matfiles. + See scipy.io.loadmat to read and write matfiles. Example usage: From numpy-svn at scipy.org Thu Jan 10 10:52:42 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Thu, 10 Jan 2008 09:52:42 -0600 (CST) Subject: [Numpy-svn] r4718 - in branches/maskedarray/numpy/ma: . tests Message-ID: <20080110155242.EA8FD39C1B8@new.scipy.org> Author: stefan Date: 2008-01-10 09:52:25 -0600 (Thu, 10 Jan 2008) New Revision: 4718 Modified: branches/maskedarray/numpy/ma/core.py branches/maskedarray/numpy/ma/tests/test_core.py Log: Apply patch by Pierre. Move tests from __main__ to the tests directory. fix_invalid - change the default to copy=True _MaskedUnaryOperation - make sure the result gets updated from the input (for subclasses) _MaskedBinaryOperation - make sure the result gets updated from the inputs (for subclasses) _DomainedBinaryOperation - make sure the result gets updated from the inputs (for subclasses) MaskedArray.__new__ - added the ndmin keyword MaskedArray.__getitem__ - works with fields, using the global mask MaskedArray.__setitem__ - works with fields. The global mask is NOT updated MaskedArray.ids - fixed when nomask MaskedArray.min/.max - force masked to be returned when the whole array is masked array - added the ndmin keyword Modified: branches/maskedarray/numpy/ma/core.py =================================================================== --- branches/maskedarray/numpy/ma/core.py 2008-01-08 23:59:54 UTC (rev 4717) +++ branches/maskedarray/numpy/ma/core.py 2008-01-10 15:52:25 UTC (rev 4718) @@ -14,47 +14,42 @@ :author: Pierre Gerard-Marchant :contact: pierregm_at_uga_dot_edu -:version: $Id: core.py 3639 2007-12-13 03:39:17Z pierregm $ """ -__author__ = "Pierre GF Gerard-Marchant ($Author: pierregm $)" -__version__ = '1.0' -__revision__ = "$Revision: 3639 $" -__date__ = '$Date: 2007-12-13 05:39:17 +0200 (Thu, 13 Dec 2007) $' - +__author__ = "Pierre GF Gerard-Marchant" __docformat__ = "restructuredtext en" __all__ = ['MAError', 'MaskType', 'MaskedArray', 'bool_', 'complex_', 'float_', 'int_', 'object_', 'abs', 'absolute', 'add', 'all', 'allclose', 'allequal', 'alltrue', - 'amax', 'amin', 'anom', 'anomalies', 'any', 'arange', - 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctan2', - 'arctanh', 'argmax', 'argmin', 'argsort', 'around', - 'array', 'asarray','asanyarray', + 'amax', 'amin', 'anom', 'anomalies', 'any', 'arange', + 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctan2', + 'arctanh', 'argmax', 'argmin', 'argsort', 'around', + 'array', 'asarray','asanyarray', 'bitwise_and', 'bitwise_or', 'bitwise_xor', 'ceil', 'choose', 'compressed', 'concatenate', 'conjugate', - 'cos', 'cosh', 'count', + 'cos', 'cosh', 'count', 'default_fill_value', 'diagonal', 'divide', 'dump', 'dumps', 'empty', 'empty_like', 'equal', 'exp', 'fabs', 'fmod', 'filled', 'floor', 'floor_divide','fix_invalid', 'getmask', 'getmaskarray', 'greater', 'greater_equal', 'hypot', 'ids', 'inner', 'innerproduct', - 'isMA', 'isMaskedArray', 'is_mask', 'is_masked', 'isarray', + 'isMA', 'isMaskedArray', 'is_mask', 'is_masked', 'isarray', 'left_shift', 'less', 'less_equal', 'load', 'loads', 'log', 'log10', - 'logical_and', 'logical_not', 'logical_or', 'logical_xor', + 'logical_and', 'logical_not', 'logical_or', 'logical_xor', 'make_mask', 'make_mask_none', 'mask_or', 'masked', - 'masked_array', 'masked_equal', 'masked_greater', - 'masked_greater_equal', 'masked_inside', 'masked_less', - 'masked_less_equal', 'masked_not_equal', 'masked_object', - 'masked_outside', 'masked_print_option', 'masked_singleton', - 'masked_values', 'masked_where', 'max', 'maximum', 'mean', 'min', - 'minimum', 'multiply', + 'masked_array', 'masked_equal', 'masked_greater', + 'masked_greater_equal', 'masked_inside', 'masked_less', + 'masked_less_equal', 'masked_not_equal', 'masked_object', + 'masked_outside', 'masked_print_option', 'masked_singleton', + 'masked_values', 'masked_where', 'max', 'maximum', 'mean', 'min', + 'minimum', 'multiply', 'negative', 'nomask', 'nonzero', 'not_equal', 'ones', 'outer', 'outerproduct', 'power', 'product', 'ptp', 'put', 'putmask', 'rank', 'ravel', 'remainder', 'repeat', 'reshape', 'resize', - 'right_shift', 'round_', + 'right_shift', 'round_', 'shape', 'sin', 'sinh', 'size', 'sometrue', 'sort', 'sqrt', 'std', - 'subtract', 'sum', 'swapaxes', + 'subtract', 'sum', 'swapaxes', 'take', 'tan', 'tanh', 'transpose', 'true_divide', 'var', 'where', 'zeros'] @@ -63,7 +58,7 @@ import types import cPickle import operator -# + import numpy from numpy.core import bool_, complex_, float_, int_, object_, str_ @@ -76,22 +71,9 @@ from numpy import array as narray import warnings -class NoMask(ndarray): - def __new__(subtype): - narray(False) - return narray(False).view(subtype) - def no_op(self,*args,**kwargs): - return self - - def __array_finalize__(self,obj): - obj.flags['WRITEABLE'] = False - - def copy(self): - return self - MaskType = bool_ -nomask = NoMask() +nomask = MaskType(0) divide_tolerance = 1.e-35 numpy.seterr(all='ignore') @@ -417,8 +399,10 @@ # def __call__ (self, a, *args, **kwargs): "Execute the call behavior." + # m = getmask(a) d1 = get_data(a) + # if self.domain is not None: dm = narray(self.domain(d1), copy=False) m = numpy.logical_or(m, dm) @@ -429,14 +413,17 @@ # Take care of the masked singletong first ... if not m.ndim and m: return masked - # Get the result.............................. + # Get the result class ....................... if isinstance(a, MaskedArray): - result = self.f(d1, *args, **kwargs).view(type(a)) + subtype = type(a) else: - result = self.f(d1, *args, **kwargs).view(MaskedArray) + subtype = MaskedArray + # Get the result as a view of the subtype ... + result = self.f(d1, *args, **kwargs).view(subtype) # Fix the mask if we don't have a scalar if result.ndim > 0: result._mask = m + result._update_from(a) return result # def __str__ (self): @@ -475,6 +462,10 @@ if m is not nomask: result._mask = make_mask_none(result.shape) result._mask.flat = m + if isinstance(a,MaskedArray): + result._update_from(a) + if isinstance(b,MaskedArray): + result._update_from(b) elif m: return masked return result @@ -586,6 +577,10 @@ result = self.f(d1, d2).view(get_masked_subclass(a,b)) if result.ndim > 0: result._mask = m + if isinstance(a,MaskedArray): + result._update_from(a) + if isinstance(b,MaskedArray): + result._update_from(b) return result def __str__ (self): @@ -1020,7 +1015,6 @@ cls = type(self.obj) result = getattr(data, methodname)(*args, **params).view(cls) result._update_from(self.obj) - #result._shrinkmask = self.obj._shrinkmask if result.ndim: if not self._onmask: result.__setmask__(mask) @@ -1064,7 +1058,7 @@ Construction: x = MaskedArray(data, mask=nomask, dtype=None, copy=True, - fill_value=None, mask = nomask, fill_value=None, shrink=True) + fill_value=None, keep_mask=True, hard_mask=False, shrink=True) *Parameters*: data : {var} @@ -1080,6 +1074,11 @@ copy : {boolean} Whether to copy the input data (True), or to use a reference instead. Note: data are NOT copied by default. + subok : {True, boolean} + Whether to return a subclass of MaskedArray (if possible) + or a plain MaskedArray. + ndmin : {0, int} + Minimum number of dimensions fill_value : {var} Value used to fill in the masked values when necessary. If None, a default based on the datatype is used. @@ -1089,9 +1088,9 @@ hard_mask : {False, boolean} Whether to use a hard mask or not. With a hard mask, masked values cannot be unmasked. - subok : {True, boolean} - Whether or not to return a subclass of MaskedArray (if - possible) or a plain MaskedArray. + shrink : {True, boolean} + Whether to force compression of an empty mask. + """ @@ -1101,8 +1100,9 @@ _baseclass = numeric.ndarray def __new__(cls, data=None, mask=nomask, dtype=None, copy=False, - fill_value=None, keep_mask=True, hard_mask=False, flag=None, - subok=True, **options): + subok=True, ndmin=0, fill_value=None, + keep_mask=True, hard_mask=False, flag=None,shrink=True, + **options): """Create a new masked array from scratch. Note: you can also create an array with the .view(MaskedArray) @@ -1114,7 +1114,7 @@ DeprecationWarning) shrink = flag # Process data............ - _data = narray(data, dtype=dtype, copy=copy, subok=True) + _data = narray(data, dtype=dtype, copy=copy, subok=True, ndmin=ndmin) _baseclass = getattr(data, '_baseclass', type(_data)) _basedict = getattr(data, '_basedict', getattr(data, '__dict__', None)) if not isinstance(data, MaskedArray) or not subok: @@ -1128,7 +1128,10 @@ # Process mask ........... if mask is nomask: if not keep_mask: - _data._mask = nomask + if shrink: + _data._mask = nomask + else: + _data._mask = make_mask_none(_data) if copy: _data._mask = _data._mask.copy() _data._sharedmask = False @@ -1183,7 +1186,7 @@ return #........................ def __array_finalize__(self,obj): - """Finalize the masked array. + """Finalizes the masked array. """ # Get main attributes ......... self._mask = getattr(obj, '_mask', nomask) @@ -1195,7 +1198,6 @@ # Finalize the mask ........... if self._mask is not nomask: self._mask.shape = self.shape -# self._data = self.view(self._baseclass) return #.................................. def __array_wrap__(self, obj, context=None): @@ -1266,7 +1268,10 @@ dout._update_from(self) # Update the mask if needed if m is not nomask: - dout._mask = ndarray.__getitem__(m, indx).reshape(dout.shape) + if isinstance(indx, basestring): + dout._mask = m.reshape(dout.shape) + else: + dout._mask = ndarray.__getitem__(m, indx).reshape(dout.shape) # Note: Don't try to check for m.any(), that'll take too long... # mask = ndarray.__getitem__(m, indx).reshape(dout.shape) # if self._shrinkmask and not m.any(): @@ -1287,6 +1292,10 @@ # if getmask(indx) is not nomask: # msg = "Masked arrays must be filled before they can be used as indices!" # raise IndexError, msg + if isinstance(indx, basestring): + ndarray.__setitem__(self._data,indx, getdata(value)) + warnings.warn("The mask is NOT affected!") + return #.... if value is masked: m = self._mask @@ -1794,6 +1803,8 @@ #............................................ def ids (self): """Return the addresses of the data and mask areas.""" + if self._mask is nomask: + return (self.ctypes.data, id(nomask)) return (self.ctypes.data, self._mask.ctypes.data) #............................................ def all(self, axis=None, out=None): @@ -2282,7 +2293,10 @@ mask = umath.logical_and.reduce(mask.flat) else: mask = umath.logical_and.reduce(mask, axis=axis) - # Get the fil value ........... + # Skip if all masked .......... + if not mask.ndim and mask: + return masked + # Get the fill value ........... if fill_value is None: fill_value = minimum_fill_value(self) # Get the data ................ @@ -2290,6 +2304,13 @@ if result.ndim > 0: result._mask = mask return result + + def mini(self, axis=None): + if axis is None: + return minimum(self) + else: + return minimum.reduce(self, axis) + #........................ def max(self, axis=None, fill_value=None): """Return the maximum/a along the given axis. @@ -2315,6 +2336,9 @@ mask = umath.logical_and.reduce(mask.flat) else: mask = umath.logical_and.reduce(mask, axis=axis) + # Skip if all masked .......... + if not mask.ndim and mask: + return masked # Get the fill value .......... if fill_value is None: fill_value = maximum_fill_value(self) @@ -2469,10 +2493,13 @@ masked_array = MaskedArray -def array(data, dtype=None, copy=False, order=False, mask=nomask, subok=True, - keep_mask=True, hard_mask=False, fill_value=None, shrink=True): - """array(data, dtype=None, copy=True, order=False, mask=nomask, - keep_mask=True, shrink=True, fill_value=None) +def array(data, dtype=None, copy=False, order=False, + mask=nomask, fill_value=None, + keep_mask=True, hard_mask=False, shrink=True, subok=True, ndmin=0, + ): + """array(data, dtype=None, copy=False, order=False, mask=nomask, + fill_value=None, keep_mask=True, hard_mask=False, shrink=True, + subok=True, ndmin=0) Acts as shortcut to MaskedArray, with options in a different order for convenience. And backwards compatibility... @@ -2481,7 +2508,7 @@ #TODO: we should try to put 'order' somwehere return MaskedArray(data, mask=mask, dtype=dtype, copy=copy, subok=subok, keep_mask=keep_mask, hard_mask=hard_mask, - fill_value=fill_value) + fill_value=fill_value, ndmin=ndmin, shrink=shrink) array.__doc__ = masked_array.__doc__ def is_masked(x): @@ -2745,8 +2772,9 @@ return data # OK, so we have to concatenate the masks dm = numpy.concatenate([getmaskarray(a) for a in arrays], axis) - shrink = numpy.logical_or.reduce([getattr(a,'_shrinkmask',True) for a in arrays]) - if shrink and not dm.any(): +# shrink = numpy.logical_or.reduce([getattr(a,'_shrinkmask',True) for a in arrays]) +# if shrink and not dm.any(): + if not dm.any(): data._mask = nomask else: data._mask = dm.reshape(d.shape) @@ -3179,42 +3207,3 @@ "Load a pickle from the current string.""" return cPickle.loads(strg) - - - -############################################################################### -# -if __name__ == '__main__': - from maskedarray.testutils import assert_equal, assert_almost_equal - - if 1: - x = array([1,2,3,4,5,6]) - mx = array(x, mask=[0,0,0,1,1,1]) - mask = [0,0,1,0,0,1] - if 1: - # w/o mask, w/o masked values - xx = x.copy() - putmask(xx, mask, 99) - assert_equal(xx, [1,2,99,4,5,99]) - # w/ mask, w/o masked values - mxx = mx.copy() - putmask(mxx, mask, 99) - assert_equal(mxx._data, [1,2,99,4,5,99]) - assert_equal(mxx._mask, [0,0,0,1,1,0]) - # w/o mask, w/ masked values - values = array([10,20,30,40,50,60],mask=[1,1,1,0,0,0]) - xx = x.copy() - putmask(xx, mask, values) - assert_equal(xx._data, [1,2,30,4,5,60]) - assert_equal(xx._mask, [0,0,1,0,0,0]) - # w/ mask, w/ masked values - mxx = mx.copy() - putmask(mxx, mask, values) - assert_equal(mxx._data, [1,2,30,4,5,60]) - assert_equal(mxx._mask, [0,0,1,1,1,0]) - # w/ mask, w/ masked values + hardmask - mxx = mx.copy() - mxx.harden_mask() - putmask(mxx, mask, values) - assert_equal(mxx, [1,2,30,4,5,60]) - Modified: branches/maskedarray/numpy/ma/tests/test_core.py =================================================================== --- branches/maskedarray/numpy/ma/tests/test_core.py 2008-01-08 23:59:54 UTC (rev 4717) +++ branches/maskedarray/numpy/ma/tests/test_core.py 2008-01-10 15:52:25 UTC (rev 4718) @@ -16,6 +16,7 @@ import numpy import numpy.core.fromnumeric as fromnumeric from numpy.testing import NumpyTest, NumpyTestCase +from numpy.testing import set_local_path, restore_path from numpy.testing.utils import build_err_msg from numpy import array as narray @@ -27,7 +28,9 @@ pi = numpy.pi +set_local_path() from test_old_ma import * +restore_path() class TestNoMask(NumpyTestCase): def test_no_inplace(self): @@ -63,7 +66,7 @@ xm.set_fill_value(1.e+20) self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf) #........................ - def check_basic1d(self): + def test_basic1d(self): "Test of basic array creation and properties in 1 dimension." (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d assert(not isMaskedArray(x)) @@ -81,7 +84,7 @@ assert_array_equal(filled(xm, 1.e20), xf) assert_array_equal(x, xm) #........................ - def check_basic2d(self): + def test_basic2d(self): "Test of basic array creation and properties in 2 dimensions." (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d for s in [(4,3), (6,2)]: @@ -101,7 +104,7 @@ assert_equal(filled(xm, 1.e20), xf) assert_equal(x, xm) #........................ - def check_basic_arithmetic (self): + def test_basic_arithmetic (self): "Test of basic arithmetic." (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d a2d = array([[1,2],[0,4]]) @@ -136,14 +139,14 @@ assert_equal(numpy.multiply(x,y), multiply(xm, ym)) assert_equal(numpy.divide(x,y), divide(xm, ym)) #........................ - def check_mixed_arithmetic(self): + def test_mixed_arithmetic(self): "Tests mixed arithmetics." na = narray([1]) ma = array([1]) self.failUnless(isinstance(na + ma, MaskedArray)) self.failUnless(isinstance(ma + na, MaskedArray)) #........................ - def check_inplace_arithmetic(self): + def test_inplace_arithmetic(self): """Test of inplace operations and rich comparisons""" # addition x = arange(10) @@ -256,7 +259,7 @@ #.......................... - def check_scalararithmetic(self): + def test_scalararithmetic(self): "Tests some scalar arithmetics on MaskedArrays." xm = array(0, mask=1) assert((1/array(0)).mask) @@ -270,7 +273,7 @@ assert_equal(x.filled().ctypes.data, x.ctypes.data) assert_equal(str(xm), str(masked_print_option)) #......................... - def check_basic_ufuncs (self): + def test_basic_ufuncs (self): "Test various functions such as sin, cos." (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d assert_equal(numpy.cos(x), cos(xm)) @@ -296,7 +299,7 @@ assert_equal(numpy.greater_equal(x,y), greater_equal(xm, ym)) assert_equal(numpy.conjugate(x), conjugate(xm)) #........................ - def check_count_func (self): + def test_count_func (self): "Tests count" ott = array([0.,1.,2.,3.], mask=[1,0,0,0]) assert( isinstance(count(ott), int)) @@ -310,7 +313,7 @@ assert getmask(count(ott,0)) is nomask assert_equal([1,2],count(ott,0)) #........................ - def check_minmax_func (self): + def test_minmax_func (self): "Tests minimum and maximum." (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d xr = numpy.ravel(x) #max doesn't work if shaped @@ -333,7 +336,7 @@ x[-1,-1] = masked assert_equal(maximum(x), 2) - def check_minmax_methods(self): + def test_minmax_methods(self): "Additional tests on max/min" (_, _, _, _, _, xm, _, _, _, _) = self.d xm.shape = (xm.size,) @@ -350,7 +353,7 @@ assert(xm[0].ptp(0) is masked) assert(xm[0].ptp(-1) is masked) #........................ - def check_addsumprod (self): + def test_addsumprod (self): "Tests add, sum, product." (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d assert_equal(numpy.add.reduce(x), add.reduce(x)) @@ -371,7 +374,7 @@ assert_equal(numpy.sum(x,1), sum(x,1)) assert_equal(numpy.product(x,1), product(x,1)) #......................... - def check_concat(self): + def test_concat(self): "Tests concatenations." (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d # basic concatenation @@ -388,7 +391,7 @@ assert_equal(numpy.concatenate((x,y),1), xmym) assert_equal(numpy.concatenate((xm.mask,ym.mask),1), xmym._mask) #........................ - def check_indexing(self): + def test_indexing(self): "Tests conversions and indexing" x1 = numpy.array([1,2,4,3]) x2 = array(x1, mask=[1,0,0,0]) @@ -438,7 +441,7 @@ assert_equal(s1, s2) assert x1[1:1].shape == (0,) #........................ - def check_copy(self): + def test_copy(self): "Tests of some subtle points of copying and sizing." n = [0,0,1,0,0] m = make_mask(n) @@ -506,7 +509,7 @@ assert_not_equal(y._data.ctypes.data, x._data.ctypes.data) assert_not_equal(y._mask.ctypes.data, x._mask.ctypes.data) #........................ - def check_where(self): + def test_where(self): "Test the where function" (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d d = where(xm>2,xm,-9) @@ -547,7 +550,7 @@ assert z[9] is masked #........................ - def check_oddfeatures_1(self): + def test_oddfeatures_1(self): "Test of other odd features" x = arange(20) x = x.reshape(4,5) @@ -576,7 +579,7 @@ assert_equal(x,z) # #........................ - def check_oddfeatures_2(self): + def test_oddfeatures_2(self): "Tests some more features." x = array([1.,2.,3.,4.,5.]) c = array([1,1,1,0,0]) @@ -606,14 +609,14 @@ z = where(c, 1, masked) assert_equal(z, [99, 1, 1, 99, 99, 99]) #........................ - def check_oddfeatures_3(self): + def test_oddfeatures_3(self): """Tests some generic features.""" atest = ones((10,10,10), dtype=float_) btest = zeros(atest.shape, MaskType) ctest = masked_where(btest,atest) assert_equal(atest,ctest) #........................ - def check_maskingfunctions(self): + def test_maskingfunctions(self): "Tests masking functions." x = array([1.,2.,3.,4.,5.]) x[2] = masked @@ -632,7 +635,7 @@ assert_equal(masked_not_equal(array([2,2,1,2,1], mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,1]) assert_equal(masked_where([1,1,0,0,0], [1,2,3,4,5]), [99,99,3,4,5]) #........................ - def check_TakeTransposeInnerOuter(self): + def test_TakeTransposeInnerOuter(self): "Test of take, transpose, inner, outer products" x = arange(24) y = numpy.arange(24) @@ -652,7 +655,7 @@ assert t[1] == 2 assert t[2] == 3 #....................... - def check_maskedelement(self): + def test_maskedelement(self): "Test of masked element" x = arange(6) x[1] = masked @@ -665,7 +668,7 @@ #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, xx) #self.failUnlessRaises(Exception, lambda x,y: x+y, xx, masked) #........................ - def check_scalar(self): + def test_scalar(self): "Checks masking a scalar" x = masked_array(0) assert_equal(str(x), '0') @@ -674,7 +677,7 @@ x = masked_array(0, mask=False) assert_equal(str(x), '0') #........................ - def check_usingmasked(self): + def test_usingmasked(self): "Checks that there's no collapsing to masked" x = masked_array([1,2]) y = x * masked @@ -687,7 +690,7 @@ assert_equal(y._mask, [True, True]) #........................ - def check_topython(self): + def test_topython(self): "Tests some communication issues with Python." assert_equal(1, int(array(1))) assert_equal(1.0, float(array(1))) @@ -704,7 +707,7 @@ #TODO: self.failIf(bool(array([0,0]))) #TODO: self.failIf(bool(array([0,0],mask=[0,0]))) #........................ - def check_arraymethods(self): + def test_arraymethods(self): "Tests some MaskedArray methods." a = array([1,3,2]) b = array([1,3,2], mask=[1,0,1]) @@ -723,7 +726,7 @@ assert_equal(a.take([1,2]), a.data.take([1,2])) assert_equal(m.transpose(), m.data.transpose()) #........................ - def check_basicattributes(self): + def test_basicattributes(self): "Tests some basic array attributes." a = array([1,3,2]) b = array([1,3,2], mask=[1,0,1]) @@ -734,7 +737,7 @@ assert_equal(a.shape, (3,)) assert_equal(b.shape, (3,)) #........................ - def check_single_element_subscript(self): + def test_single_element_subscript(self): "Tests single element subscripts of Maskedarrays." a = array([1,3,2]) b = array([1,3,2], mask=[1,0,1]) @@ -742,7 +745,7 @@ assert_equal(b[0].shape, ()) assert_equal(b[1].shape, ()) #........................ - def check_maskcreation(self): + def test_maskcreation(self): "Tests how masks are initialized at the creation of Maskedarrays." data = arange(24, dtype=float_) data[[3,6,15]] = masked @@ -753,7 +756,7 @@ dma_3 = MaskedArray(dma_1, mask=[1,0,0,0]*6) fail_if_equal(dma_3.mask, dma_1.mask) - def check_pickling(self): + def test_pickling(self): "Tests pickling" import cPickle a = arange(10) @@ -770,26 +773,26 @@ assert_equal(a_pickled, a) assert(isinstance(a_pickled._data,numpy.matrix)) # - def check_fillvalue(self): + def test_fillvalue(self): "Check that we don't lose the fill_value" data = masked_array([1,2,3],fill_value=-999) series = data[[0,2,1]] assert_equal(series._fill_value, data._fill_value) # - def check_asarray(self): + def test_asarray(self): (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d xmm = asarray(xm) assert_equal(xmm._data, xm._data) assert_equal(xmm._mask, xm._mask) # - def check_fix_invalid(self): + def test_fix_invalid(self): "Checks fix_invalid." data = masked_array(numpy.sqrt([-1., 0., 1.]), mask=[0,0,1]) data_fixed = fix_invalid(data) assert_equal(data_fixed._data, [data.fill_value, 0., 1.]) assert_equal(data_fixed._mask, [1., 0., 1.]) # - def check_imag_real(self): + def test_imag_real(self): xx = array([1+10j,20+2j], mask=[1,0]) assert_equal(xx.imag,[10,2]) assert_equal(xx.imag.filled(), [1e+20,2]) @@ -807,7 +810,7 @@ self.d = (array([1.0, 0, -1, pi/2]*2, mask=[0,1]+[0]*6), array([1.0, 0, -1, pi/2]*2, mask=[1,0]+[0]*6),) - def check_testUfuncRegression(self): + def test_testUfuncRegression(self): "Tests new ufuncs on MaskedArrays." for f in ['sqrt', 'log', 'log10', 'exp', 'conjugate', 'sin', 'cos', 'tan', @@ -897,7 +900,7 @@ self.d = (x,X,XX,m,mx,mX,mXX,m2x,m2X,m2XX) #------------------------------------------------------ - def check_trace(self): + def test_trace(self): "Tests trace on MaskedArrays." (x,X,XX,m,mx,mX,mXX,m2x,m2X,m2XX) = self.d mXdiag = mX.diagonal() @@ -905,7 +908,7 @@ assert_almost_equal(mX.trace(), X.trace() - sum(mXdiag.mask*X.diagonal(),axis=0)) - def check_clip(self): + def test_clip(self): "Tests clip on MaskedArrays." (x,X,XX,m,mx,mX,mXX,m2x,m2X,m2XX) = self.d clipped = mx.clip(2,8) @@ -913,7 +916,7 @@ assert_equal(clipped.data,x.clip(2,8)) assert_equal(clipped.data,mx.data.clip(2,8)) - def check_ptp(self): + def test_ptp(self): "Tests ptp on MaskedArrays." (x,X,XX,m,mx,mX,mXX,m2x,m2X,m2XX) = self.d (n,m) = X.shape @@ -927,7 +930,7 @@ assert_equal(mX.ptp(0),cols) assert_equal(mX.ptp(1),rows) - def check_swapaxes(self): + def test_swapaxes(self): "Tests swapaxes on MaskedArrays." (x,X,XX,m,mx,mX,mXX,m2x,m2X,m2XX) = self.d mXswapped = mX.swapaxes(0,1) @@ -935,7 +938,7 @@ mXXswapped = mXX.swapaxes(0,2) assert_equal(mXXswapped.shape,(2,2,3,3)) - def check_cumsumprod(self): + def test_cumsumprod(self): "Tests cumsum & cumprod on MaskedArrays." (x,X,XX,m,mx,mX,mXX,m2x,m2X,m2XX) = self.d mXcp = mX.cumsum(0) @@ -948,7 +951,7 @@ mXcp = mX.cumprod(1) assert_equal(mXcp.data,mX.filled(1).cumprod(1)) - def check_varstd(self): + def test_varstd(self): "Tests var & std on MaskedArrays." (x,X,XX,m,mx,mX,mXX,m2x,m2X,m2XX) = self.d assert_almost_equal(mX.var(axis=None),mX.compressed().var()) @@ -961,7 +964,7 @@ assert_almost_equal(mXvar0[k],mX[:,k].compressed().var()) assert_almost_equal(numpy.sqrt(mXvar0[k]), mX[:,k].compressed().std()) - def check_argmin(self): + def test_argmin(self): "Tests argmin & argmax on MaskedArrays." (x,X,XX,m,mx,mX,mXX,m2x,m2X,m2XX) = self.d # @@ -984,7 +987,7 @@ assert_equal(mX.argmax(1), [2,4,1,1,4,1]) assert_equal(m2X.argmax(1), [2,4,1,1,1,1]) - def check_put(self): + def test_put(self): "Tests put." d = arange(5) n = [0,0,0,1,1] @@ -1015,7 +1018,7 @@ assert_array_equal(x, [0,1,2,3,4,5,6,7,8,9,]) assert_equal(x.mask, [1,0,0,0,1,1,0,0,0,0]) - def check_put_hardmask(self): + def test_put_hardmask(self): "Tests put on hardmask" d = arange(5) n = [0,0,0,1,1] @@ -1024,7 +1027,7 @@ xh.put([4,2,0,1,3],[1,2,3,4,5]) assert_equal(xh._data, [3,4,2,4,5]) - def check_take(self): + def test_take(self): "Tests take" x = masked_array([10,20,30,40],[0,1,0,1]) assert_equal(x.take([0,0,3]), masked_array([10, 10, 40], [0,0,1]) ) @@ -1038,7 +1041,7 @@ assert_equal(take(x, [0,2], axis=1), array([[10,30],[40,60]], mask=[[0,1],[1,0]])) #........................ - def check_anyall(self): + def test_anyall(self): """Checks the any/all methods/functions.""" x = numpy.array([[ 0.13, 0.26, 0.90], [ 0.28, 0.33, 0.63], @@ -1086,7 +1089,7 @@ assert_equal(mXsmall.any(0), numpy.matrix([True, True, False])) assert_equal(mXsmall.any(1), numpy.matrix([True, True, False]).T) - def check_keepmask(self): + def test_keepmask(self): "Tests the keep mask flag" x = masked_array([1,2,3], mask=[1,0,0]) mx = masked_array(x) @@ -1099,7 +1102,7 @@ mx = masked_array(x, mask=[0,1,0]) assert_equal(mx.mask, [1,1,0]) - def check_hardmask(self): + def test_hardmask(self): "Test hard_mask" d = arange(5) n = [0,0,0,1,1] @@ -1166,7 +1169,7 @@ xh[0:1] = 999 assert_equal(xh._data,[999,1,2,3,4]) - def check_smallmask(self): + def test_smallmask(self): "Checks the behaviour of _smallmask" a = arange(10) a[1] = masked @@ -1179,7 +1182,7 @@ assert_equal(a._mask, zeros(10)) - def check_sort(self): + def test_sort(self): "Test sort" x = array([1,4,2,3],mask=[0,1,0,0],dtype=numpy.uint8) # @@ -1212,7 +1215,7 @@ assert_equal(sortedx._data, [1,2,-2,-1,0]) assert_equal(sortedx._mask, [1,1,0,0,0]) - def check_sort_2d(self): + def test_sort_2d(self): "Check sort of 2D array." # 2D array w/o mask a = masked_array([[8,4,1],[2,0,9]]) @@ -1253,7 +1256,7 @@ assert_equal(am, an) - def check_ravel(self): + def test_ravel(self): "Tests ravel" a = array([[1,2,3,4,5]], mask=[[0,1,0,0,0]]) aravel = a.ravel() @@ -1269,7 +1272,7 @@ a = array([1,2,3,4],mask=[0,0,0,0],shrink=False) assert_equal(a.ravel()._mask, [0,0,0,0]) - def check_reshape(self): + def test_reshape(self): "Tests reshape" x = arange(4) x[0] = masked @@ -1279,7 +1282,7 @@ assert_equal(x.shape, (4,)) assert_equal(x._mask.shape, (4,)) - def check_compressed(self): + def test_compressed(self): "Tests compressed" a = array([1,2,3,4],mask=[0,0,0,0]) b = a.compressed() @@ -1290,7 +1293,7 @@ assert_equal(b._data, [2,3,4]) assert_equal(b._mask, nomask) - def check_tolist(self): + def test_tolist(self): "Tests to list" x = array(numpy.arange(12)) x[[1,-2]] = masked @@ -1305,7 +1308,7 @@ assert_equal(xlist[1],[4,5,6,7]) assert_equal(xlist[2],[8,9,None,11]) - def check_squeeze(self): + def test_squeeze(self): "Check squeeze" data = masked_array([[1,2,3]]) assert_equal(data.squeeze(), [1,2,3]) @@ -1315,7 +1318,7 @@ data = masked_array([[1]], mask=True) assert(data.squeeze() is masked) - def check_putmask(self): + def test_putmask(self): x = arange(6)+1 mx = array(x, mask=[0,0,0,1,1,1]) mask = [0,0,1,0,0,1] @@ -1345,7 +1348,25 @@ putmask(mxx, mask, values) assert_equal(mxx, [1,2,30,4,5,60]) + def test_ndmin(self): + x = array([1,2,3],mask=[1,0,0], ndmin=2) + assert_equal(x.shape,(1,3)) + assert_equal(x._data,[[1,2,3]]) + assert_equal(x._mask,[[1,0,0]]) + def test_sumprod_masked(self): + x = masked_array([1,2,3], mask=True) + z = x.min() + assert(x.sum() is masked) + assert(x.prod() is masked) + + def test_fancy_dtype(self): + mtype = [('f',float_),('s','|S3')] + x = array([(1,'a'),(2,'b'),(numpy.pi,'pi')], dtype=mtype) + x[1] = masked + x['f'] = 17 + + #.............................................................................. ############################################################################### From numpy-svn at scipy.org Thu Jan 10 14:09:51 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Thu, 10 Jan 2008 13:09:51 -0600 (CST) Subject: [Numpy-svn] r4719 - branches/maskedarray/numpy/ma/tests Message-ID: <20080110190951.DA5E439C04A@new.scipy.org> Author: stefan Date: 2008-01-10 13:09:35 -0600 (Thu, 10 Jan 2008) New Revision: 4719 Modified: branches/maskedarray/numpy/ma/tests/test_core.py Log: Fix inplace test. Modified: branches/maskedarray/numpy/ma/tests/test_core.py =================================================================== --- branches/maskedarray/numpy/ma/tests/test_core.py 2008-01-10 15:52:25 UTC (rev 4718) +++ branches/maskedarray/numpy/ma/tests/test_core.py 2008-01-10 19:09:35 UTC (rev 4719) @@ -35,9 +35,9 @@ class TestNoMask(NumpyTestCase): def test_no_inplace(self): x = nomask - def iadd(x): - x += 1 - self.failUnlessRaises(ValueError,iadd,x) + y = x + x += 1 + assert x != y def test_no_copy(self): x = nomask From numpy-svn at scipy.org Thu Jan 10 14:33:27 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Thu, 10 Jan 2008 13:33:27 -0600 (CST) Subject: [Numpy-svn] r4720 - in branches/maskedarray/numpy/ma: . tests Message-ID: <20080110193327.8633B39C260@new.scipy.org> Author: stefan Date: 2008-01-10 13:33:10 -0600 (Thu, 10 Jan 2008) New Revision: 4720 Modified: branches/maskedarray/numpy/ma/core.py branches/maskedarray/numpy/ma/tests/test_core.py Log: Fix concatenation. Closes ticket #642. Modified: branches/maskedarray/numpy/ma/core.py =================================================================== --- branches/maskedarray/numpy/ma/core.py 2008-01-10 19:09:35 UTC (rev 4719) +++ branches/maskedarray/numpy/ma/core.py 2008-01-10 19:33:10 UTC (rev 4720) @@ -2769,6 +2769,7 @@ for x in arrays: if getmask(x) is not nomask: break + else: return data # OK, so we have to concatenate the masks dm = numpy.concatenate([getmaskarray(a) for a in arrays], axis) Modified: branches/maskedarray/numpy/ma/tests/test_core.py =================================================================== --- branches/maskedarray/numpy/ma/tests/test_core.py 2008-01-10 19:09:35 UTC (rev 4719) +++ branches/maskedarray/numpy/ma/tests/test_core.py 2008-01-10 19:33:10 UTC (rev 4720) @@ -1366,7 +1366,19 @@ x[1] = masked x['f'] = 17 + def test_concat(self): + x=zeros(2) + y=array(ones(2),mask=[False,True]) + z = concatenate((x,y)) + assert_array_equal(z,[0,0,1,1]) + assert_array_equal(z.mask,[False,False,False,True]) + + z = concatenate((y,x)) + assert_array_equal(z,[1,1,0,0]) + assert_array_equal(z.mask,[False,True,False,False]) + + #.............................................................................. ############################################################################### From numpy-svn at scipy.org Sun Jan 13 02:42:06 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 13 Jan 2008 01:42:06 -0600 (CST) Subject: [Numpy-svn] r4721 - branches/build_with_scons/numpy/core Message-ID: <20080113074206.69CA6C7C00A@new.scipy.org> Author: cdavid Date: 2008-01-13 01:41:46 -0600 (Sun, 13 Jan 2008) New Revision: 4721 Modified: branches/build_with_scons/numpy/core/numeric.py Log: Merge revisions 4706:4720 from the trunk Modified: branches/build_with_scons/numpy/core/numeric.py =================================================================== --- branches/build_with_scons/numpy/core/numeric.py 2008-01-10 19:33:10 UTC (rev 4720) +++ branches/build_with_scons/numpy/core/numeric.py 2008-01-13 07:41:46 UTC (rev 4721) @@ -667,7 +667,7 @@ fname can be a filename or a file handle. Support for gzipped files is automatic, if the filename ends in .gz - See scipy.loadmat to read and write matfiles. + See scipy.io.loadmat to read and write matfiles. Example usage: From numpy-svn at scipy.org Sun Jan 13 02:44:57 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 13 Jan 2008 01:44:57 -0600 (CST) Subject: [Numpy-svn] r4722 - branches/build_with_scons/numpy/core Message-ID: <20080113074457.C251EC7C00A@new.scipy.org> Author: cdavid Date: 2008-01-13 01:44:53 -0600 (Sun, 13 Jan 2008) New Revision: 4722 Modified: branches/build_with_scons/numpy/core/SConstruct Log: Typo in numpy.core SConstruct Modified: branches/build_with_scons/numpy/core/SConstruct =================================================================== --- branches/build_with_scons/numpy/core/SConstruct 2008-01-13 07:41:46 UTC (rev 4721) +++ branches/build_with_scons/numpy/core/SConstruct 2008-01-13 07:44:53 UTC (rev 4722) @@ -1,4 +1,4 @@ -# Last Change: Wed Jan 09 12:00 AM 2008 J +# Last Change: Sun Jan 13 04:00 PM 2008 J # vim:syntax=python import os import sys @@ -63,7 +63,7 @@ #--------------------- # Checking SMP option #--------------------- -st = define_no_smp(): +st = define_no_smp() numpyconfig_sym.append(('NPY_NOSMP', st)) config.Define('NPY_NOSMP', st, "define to 1 to disable SMP support ") From numpy-svn at scipy.org Fri Jan 18 01:24:17 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 18 Jan 2008 00:24:17 -0600 (CST) Subject: [Numpy-svn] r4723 - branches/build_with_scons Message-ID: <20080118062417.606DAC7C062@new.scipy.org> Author: cdavid Date: 2008-01-18 00:24:13 -0600 (Fri, 18 Jan 2008) New Revision: 4723 Added: branches/build_with_scons/test.sh Log: Add simple test script to build/test numpy Added: branches/build_with_scons/test.sh =================================================================== --- branches/build_with_scons/test.sh 2008-01-13 07:44:53 UTC (rev 4722) +++ branches/build_with_scons/test.sh 2008-01-18 06:24:13 UTC (rev 4723) @@ -0,0 +1,18 @@ +# PREFIX=$PWD +# rm -rf $PREFIX/build +# rm -rf $PREFIX/tmp +# MKL=None python setupscons.py scons --jobs=4 install --prefix=$PREFIX/tmp +# (cd $PREFIX/tmp && PYTHONPATH=$PREFIX/tmp/lib/python2.5/site-packages python -c "import numpy; print numpy; numpy.test(level = 9999); numpy.show_config()") + +PREFIX=$PWD +rm -rf $PREFIX/build +rm -rf $PREFIX/tmp +python setupscons.py scons --jobs=4 install --prefix=$PREFIX/tmp +(cd $PREFIX/tmp && PYTHONPATH=$PREFIX/tmp/lib/python2.5/site-packages python -c "import numpy; print numpy; numpy.test(level = 9999); numpy.show_config()") + +# PREFIX=$PWD +# #rm -rf $PREFIX/build +# #rm -rf $PREFIX/tmp +# MKL=None python setupscons.py scons --jobs=4 --silent=2 install --prefix=$PREFIX/tmp +# (cd $PREFIX/tmp/lib/python2.5/site-packages/numpy/distutils/scons/tests/f2pyext/ && \ +# PYTHONPATH=$PREFIX/tmp/lib/python2.5/site-packages python setup.py scons) From numpy-svn at scipy.org Fri Jan 18 04:37:33 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 18 Jan 2008 03:37:33 -0600 (CST) Subject: [Numpy-svn] r4724 - in branches/cleanconfig_rtm/numpy/core: . src Message-ID: <20080118093733.1DD60C7C0E9@new.scipy.org> Author: cdavid Date: 2008-01-18 03:37:27 -0600 (Fri, 18 Jan 2008) New Revision: 4724 Modified: branches/cleanconfig_rtm/numpy/core/setup.py branches/cleanconfig_rtm/numpy/core/src/multiarraymodule.c Log: Replace NPY_NO_SIGNAL CPP symbol by __NPY_PRIVATE_NO_SIGNAL for internal code, to avoid clash between public and private config files Modified: branches/cleanconfig_rtm/numpy/core/setup.py =================================================================== --- branches/cleanconfig_rtm/numpy/core/setup.py 2008-01-18 06:24:13 UTC (rev 4723) +++ branches/cleanconfig_rtm/numpy/core/setup.py 2008-01-18 09:37:27 UTC (rev 4724) @@ -107,7 +107,7 @@ moredefs.append(defsymbol) if is_npy_no_signal(): - moredefs.append('NPY_NO_SIGNAL') + moredefs.append('__NPY_PRIVATE_NO_SIGNAL') if sys.platform=='win32' or os.name=='nt': from distutils.msvccompiler import get_build_architecture Modified: branches/cleanconfig_rtm/numpy/core/src/multiarraymodule.c =================================================================== --- branches/cleanconfig_rtm/numpy/core/src/multiarraymodule.c 2008-01-18 06:24:13 UTC (rev 4723) +++ branches/cleanconfig_rtm/numpy/core/src/multiarraymodule.c 2008-01-18 09:37:27 UTC (rev 4724) @@ -7268,7 +7268,7 @@ } -#ifndef NPY_NO_SIGNAL +#ifndef __NPY_PRIVATE_NO_SIGNAL SIGJMP_BUF _NPY_SIGINT_BUF; From numpy-svn at scipy.org Fri Jan 18 04:47:45 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 18 Jan 2008 03:47:45 -0600 (CST) Subject: [Numpy-svn] r4725 - in branches/cleanconfig_rtm/numpy/core: . include/numpy Message-ID: <20080118094745.ACA8239C145@new.scipy.org> Author: cdavid Date: 2008-01-18 03:47:38 -0600 (Fri, 18 Jan 2008) New Revision: 4725 Modified: branches/cleanconfig_rtm/numpy/core/include/numpy/ndarrayobject.h branches/cleanconfig_rtm/numpy/core/setup.py Log: numpy.core: nosmp logic is only needed in public header Modified: branches/cleanconfig_rtm/numpy/core/include/numpy/ndarrayobject.h =================================================================== --- branches/cleanconfig_rtm/numpy/core/include/numpy/ndarrayobject.h 2008-01-18 09:37:27 UTC (rev 4724) +++ branches/cleanconfig_rtm/numpy/core/include/numpy/ndarrayobject.h 2008-01-18 09:47:38 UTC (rev 4725) @@ -16,7 +16,7 @@ #include "numpyconfig.h" /* Only use thread if configured in config and python supports it */ -#if defined WITH_THREAD && !NPY_NOSMP +#if defined WITH_THREAD && !NPY_NO_SMP #define NPY_ALLOW_THREADS 1 #else #define NPY_ALLOW_THREADS 0 Modified: branches/cleanconfig_rtm/numpy/core/setup.py =================================================================== --- branches/cleanconfig_rtm/numpy/core/setup.py 2008-01-18 09:37:27 UTC (rev 4724) +++ branches/cleanconfig_rtm/numpy/core/setup.py 2008-01-18 09:47:38 UTC (rev 4725) @@ -23,6 +23,31 @@ header.""" return sys.platform == 'win32' +def is_npy_no_smp(): + """Return True if the NPY_NO_SMP symbol must be defined in public + header (when SMP support cannot be reliably enabled).""" + # 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: + # Perhaps a fancier check is in order here. + # so that threads are only enabled if there + # are actually multiple CPUS? -- but + # threaded code can be nice even on a single + # CPU so that long-calculating code doesn't + # block. + try: + nosmp = os.environ['NPY_NOSMP'] + nosmp = 1 + except KeyError: + nosmp = 0 + return nosmp == 1 + 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 @@ -58,26 +83,6 @@ 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. - if sys.version[:5] < '2.4.2': - nosmp = 1 - else: - # Perhaps a fancier check is in order here. - # so that threads are only enabled if there - # are actually multiple CPUS? -- but - # threaded code can be nice even on a single - # CPU so that long-calculating code doesn't - # block. - try: - nosmp = os.environ['NPY_NOSMP'] - nosmp = 1 - except KeyError: - nosmp = 0 moredefs = [] # mathlibs = [] @@ -127,12 +132,6 @@ target_f.write('#define %s\n' % (d)) else: target_f.write('#define %s %s\n' % (d[0],d[1])) - # 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) @@ -399,8 +398,7 @@ ('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'),] + ('NPY_SIZEOF_PY_INTPTR_T', 'SIZEOF_PY_INTPTR_T')] testcode = [""" #include @@ -427,6 +425,13 @@ if is_npy_no_signal(): testcode.append(r' fprintf(f, "\n#define NPY_NO_SIGNAL\n");') + # Define NPY_NOSMP to 1 if explicitely requested, or if we cannot + # support thread support reliably + if is_npy_no_smp(): + target_f.write('#define NPY_NO_SMP 1\n') + else: + target_f.write('#define NPY_NO_SMP 0\n') + tmpcode = r""" #ifdef PY_LONG_LONG fprintf(f, "\n#define %s %%d \n", %s); From numpy-svn at scipy.org Fri Jan 18 04:50:08 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 18 Jan 2008 03:50:08 -0600 (CST) Subject: [Numpy-svn] r4726 - branches/cleanconfig_rtm/numpy/core Message-ID: <20080118095008.2C51639C145@new.scipy.org> Author: cdavid Date: 2008-01-18 03:50:04 -0600 (Fri, 18 Jan 2008) New Revision: 4726 Modified: branches/cleanconfig_rtm/numpy/core/setup.py Log: Fix typo Modified: branches/cleanconfig_rtm/numpy/core/setup.py =================================================================== --- branches/cleanconfig_rtm/numpy/core/setup.py 2008-01-18 09:47:38 UTC (rev 4725) +++ branches/cleanconfig_rtm/numpy/core/setup.py 2008-01-18 09:50:04 UTC (rev 4726) @@ -428,9 +428,9 @@ # Define NPY_NOSMP to 1 if explicitely requested, or if we cannot # support thread support reliably if is_npy_no_smp(): - target_f.write('#define NPY_NO_SMP 1\n') + targetcode.append(r'#define NPY_NO_SMP 1') else: - target_f.write('#define NPY_NO_SMP 0\n') + targetcode.write(r'#define NPY_NO_SMP 0') tmpcode = r""" #ifdef PY_LONG_LONG From numpy-svn at scipy.org Fri Jan 18 04:51:30 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 18 Jan 2008 03:51:30 -0600 (CST) Subject: [Numpy-svn] r4727 - branches/cleanconfig_rtm/numpy/core Message-ID: <20080118095130.E0092C7C0F3@new.scipy.org> Author: cdavid Date: 2008-01-18 03:51:21 -0600 (Fri, 18 Jan 2008) New Revision: 4727 Modified: branches/cleanconfig_rtm/numpy/core/setup.py Log: Fix more typo Modified: branches/cleanconfig_rtm/numpy/core/setup.py =================================================================== --- branches/cleanconfig_rtm/numpy/core/setup.py 2008-01-18 09:50:04 UTC (rev 4726) +++ branches/cleanconfig_rtm/numpy/core/setup.py 2008-01-18 09:51:21 UTC (rev 4727) @@ -428,9 +428,9 @@ # Define NPY_NOSMP to 1 if explicitely requested, or if we cannot # support thread support reliably if is_npy_no_smp(): - targetcode.append(r'#define NPY_NO_SMP 1') + testcode.append(r'#define NPY_NO_SMP 1') else: - targetcode.write(r'#define NPY_NO_SMP 0') + testcode.write(r'#define NPY_NO_SMP 0') tmpcode = r""" #ifdef PY_LONG_LONG From numpy-svn at scipy.org Fri Jan 18 04:59:45 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 18 Jan 2008 03:59:45 -0600 (CST) Subject: [Numpy-svn] r4728 - branches/cleanconfig_rtm/numpy/core Message-ID: <20080118095945.3C4C939C145@new.scipy.org> Author: cdavid Date: 2008-01-18 03:59:41 -0600 (Fri, 18 Jan 2008) New Revision: 4728 Modified: branches/cleanconfig_rtm/numpy/core/setup.py Log: Correct logic to write NPY_NO_SMP symbol in config file Modified: branches/cleanconfig_rtm/numpy/core/setup.py =================================================================== --- branches/cleanconfig_rtm/numpy/core/setup.py 2008-01-18 09:51:21 UTC (rev 4727) +++ branches/cleanconfig_rtm/numpy/core/setup.py 2008-01-18 09:59:41 UTC (rev 4728) @@ -428,9 +428,9 @@ # Define NPY_NOSMP to 1 if explicitely requested, or if we cannot # support thread support reliably if is_npy_no_smp(): - testcode.append(r'#define NPY_NO_SMP 1') + testcode.append(r' fprintf(f, "#define NPY_NO_SMP 1\n");') else: - testcode.write(r'#define NPY_NO_SMP 0') + testcode.append(r' fprintf(f, "#define NPY_NO_SMP 0\n");') tmpcode = r""" #ifdef PY_LONG_LONG From numpy-svn at scipy.org Fri Jan 18 05:05:12 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 18 Jan 2008 04:05:12 -0600 (CST) Subject: [Numpy-svn] r4729 - in branches/build_with_scons/numpy/core: . include/numpy src Message-ID: <20080118100512.3348E39C145@new.scipy.org> Author: cdavid Date: 2008-01-18 04:04:48 -0600 (Fri, 18 Jan 2008) New Revision: 4729 Modified: branches/build_with_scons/numpy/core/include/numpy/ndarrayobject.h branches/build_with_scons/numpy/core/setup.py branches/build_with_scons/numpy/core/src/multiarraymodule.c Log: Merge changes in cleanconfig_rtm Modified: branches/build_with_scons/numpy/core/include/numpy/ndarrayobject.h =================================================================== --- branches/build_with_scons/numpy/core/include/numpy/ndarrayobject.h 2008-01-18 09:59:41 UTC (rev 4728) +++ branches/build_with_scons/numpy/core/include/numpy/ndarrayobject.h 2008-01-18 10:04:48 UTC (rev 4729) @@ -16,7 +16,7 @@ #include "numpyconfig.h" /* Only use thread if configured in config and python supports it */ -#if defined WITH_THREAD && !NPY_NOSMP +#if defined WITH_THREAD && !NPY_NO_SMP #define NPY_ALLOW_THREADS 1 #else #define NPY_ALLOW_THREADS 0 Modified: branches/build_with_scons/numpy/core/setup.py =================================================================== --- branches/build_with_scons/numpy/core/setup.py 2008-01-18 09:59:41 UTC (rev 4728) +++ branches/build_with_scons/numpy/core/setup.py 2008-01-18 10:04:48 UTC (rev 4729) @@ -23,6 +23,31 @@ header.""" return sys.platform == 'win32' +def is_npy_no_smp(): + """Return True if the NPY_NO_SMP symbol must be defined in public + header (when SMP support cannot be reliably enabled).""" + # 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: + # Perhaps a fancier check is in order here. + # so that threads are only enabled if there + # are actually multiple CPUS? -- but + # threaded code can be nice even on a single + # CPU so that long-calculating code doesn't + # block. + try: + nosmp = os.environ['NPY_NOSMP'] + nosmp = 1 + except KeyError: + nosmp = 0 + return nosmp == 1 + 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 @@ -58,26 +83,6 @@ 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. - if sys.version[:5] < '2.4.2': - nosmp = 1 - else: - # Perhaps a fancier check is in order here. - # so that threads are only enabled if there - # are actually multiple CPUS? -- but - # threaded code can be nice even on a single - # CPU so that long-calculating code doesn't - # block. - try: - nosmp = os.environ['NPY_NOSMP'] - nosmp = 1 - except KeyError: - nosmp = 0 moredefs = [] # mathlibs = [] @@ -107,7 +112,7 @@ moredefs.append(defsymbol) if is_npy_no_signal(): - moredefs.append('NPY_NO_SIGNAL') + moredefs.append('__NPY_PRIVATE_NO_SIGNAL') if sys.platform=='win32' or os.name=='nt': from distutils.msvccompiler import get_build_architecture @@ -127,12 +132,6 @@ target_f.write('#define %s\n' % (d)) else: target_f.write('#define %s %s\n' % (d[0],d[1])) - # 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) @@ -399,8 +398,7 @@ ('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'),] + ('NPY_SIZEOF_PY_INTPTR_T', 'SIZEOF_PY_INTPTR_T')] testcode = [""" #include @@ -427,6 +425,13 @@ if is_npy_no_signal(): testcode.append(r' fprintf(f, "\n#define NPY_NO_SIGNAL\n");') + # Define NPY_NOSMP to 1 if explicitely requested, or if we cannot + # support thread support reliably + if is_npy_no_smp(): + testcode.append(r' fprintf(f, "#define NPY_NO_SMP 1\n");') + else: + testcode.append(r' fprintf(f, "#define NPY_NO_SMP 0\n");') + tmpcode = r""" #ifdef PY_LONG_LONG fprintf(f, "\n#define %s %%d \n", %s); Modified: branches/build_with_scons/numpy/core/src/multiarraymodule.c =================================================================== --- branches/build_with_scons/numpy/core/src/multiarraymodule.c 2008-01-18 09:59:41 UTC (rev 4728) +++ branches/build_with_scons/numpy/core/src/multiarraymodule.c 2008-01-18 10:04:48 UTC (rev 4729) @@ -7267,7 +7267,7 @@ } -#ifndef NPY_NO_SIGNAL +#ifndef __NPY_PRIVATE_NO_SIGNAL SIGJMP_BUF _NPY_SIGINT_BUF; From numpy-svn at scipy.org Fri Jan 18 18:35:15 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 18 Jan 2008 17:35:15 -0600 (CST) Subject: [Numpy-svn] r4730 - in branches/maskedarray: . benchmarks numpy numpy/core numpy/core/code_generators numpy/core/src numpy/core/tests numpy/distutils numpy/distutils/command numpy/distutils/fcompiler numpy/doc numpy/doc/html numpy/doc/swig/test numpy/f2py numpy/f2py/lib/parser numpy/fft/tests numpy/lib numpy/lib/src numpy/lib/tests numpy/linalg numpy/numarray numpy/oldnumeric numpy/random/tests numpy/testing numpy/tests Message-ID: <20080118233515.D84B639C0BA@new.scipy.org> Author: stefan Date: 2008-01-18 17:25:32 -0600 (Fri, 18 Jan 2008) New Revision: 4730 Added: branches/maskedarray/numpy/lib/_datasource.py branches/maskedarray/numpy/lib/format.py branches/maskedarray/numpy/lib/io.py branches/maskedarray/numpy/lib/tests/test_format.py Modified: branches/maskedarray/ branches/maskedarray/benchmarks/benchmark.py branches/maskedarray/benchmarks/creating.py branches/maskedarray/benchmarks/simpleindex.py branches/maskedarray/benchmarks/sorting.py branches/maskedarray/numpy/__init__.py branches/maskedarray/numpy/_import_tools.py branches/maskedarray/numpy/add_newdocs.py branches/maskedarray/numpy/core/code_generators/generate_umath.py branches/maskedarray/numpy/core/code_generators/multiarray_api_order.txt branches/maskedarray/numpy/core/defmatrix.py branches/maskedarray/numpy/core/numeric.py branches/maskedarray/numpy/core/records.py branches/maskedarray/numpy/core/src/arrayobject.c branches/maskedarray/numpy/core/src/arraytypes.inc.src branches/maskedarray/numpy/core/src/multiarraymodule.c branches/maskedarray/numpy/core/src/scalartypes.inc.src branches/maskedarray/numpy/core/src/umathmodule.c.src branches/maskedarray/numpy/core/tests/test_multiarray.py branches/maskedarray/numpy/core/tests/test_regression.py branches/maskedarray/numpy/core/tests/test_scalarmath.py branches/maskedarray/numpy/core/tests/test_ufunc.py branches/maskedarray/numpy/core/tests/test_umath.py branches/maskedarray/numpy/distutils/command/build_src.py branches/maskedarray/numpy/distutils/exec_command.py branches/maskedarray/numpy/distutils/fcompiler/intel.py branches/maskedarray/numpy/distutils/interactive.py branches/maskedarray/numpy/distutils/log.py branches/maskedarray/numpy/doc/DISTUTILS.txt branches/maskedarray/numpy/doc/HOWTO_DOCUMENT.txt branches/maskedarray/numpy/doc/example.py branches/maskedarray/numpy/doc/html/epydoc.css branches/maskedarray/numpy/doc/html/epydoc.js branches/maskedarray/numpy/doc/html/example-module.html branches/maskedarray/numpy/doc/html/example-pysrc.html branches/maskedarray/numpy/doc/html/help.html branches/maskedarray/numpy/doc/html/identifier-index.html branches/maskedarray/numpy/doc/html/module-tree.html branches/maskedarray/numpy/doc/html/toc-everything.html branches/maskedarray/numpy/doc/html/toc-example-module.html branches/maskedarray/numpy/doc/html/toc.html branches/maskedarray/numpy/doc/swig/test/testArray.py branches/maskedarray/numpy/doc/swig/test/testFarray.py branches/maskedarray/numpy/doc/swig/test/testMatrix.py branches/maskedarray/numpy/doc/swig/test/testTensor.py branches/maskedarray/numpy/doc/swig/test/testVector.py branches/maskedarray/numpy/f2py/f90mod_rules.py branches/maskedarray/numpy/f2py/lib/parser/block_statements.py branches/maskedarray/numpy/fft/tests/test_fftpack.py branches/maskedarray/numpy/lib/__init__.py branches/maskedarray/numpy/lib/arraysetops.py branches/maskedarray/numpy/lib/getlimits.py branches/maskedarray/numpy/lib/index_tricks.py branches/maskedarray/numpy/lib/scimath.py branches/maskedarray/numpy/lib/src/_compiled_base.c branches/maskedarray/numpy/lib/tests/test_arraysetops.py branches/maskedarray/numpy/lib/tests/test_getlimits.py branches/maskedarray/numpy/lib/tests/test_polynomial.py branches/maskedarray/numpy/lib/utils.py branches/maskedarray/numpy/linalg/info.py branches/maskedarray/numpy/linalg/linalg.py branches/maskedarray/numpy/matlib.py branches/maskedarray/numpy/numarray/functions.py branches/maskedarray/numpy/oldnumeric/functions.py branches/maskedarray/numpy/oldnumeric/typeconv.py branches/maskedarray/numpy/random/tests/test_random.py branches/maskedarray/numpy/testing/numpytest.py branches/maskedarray/numpy/testing/utils.py branches/maskedarray/numpy/tests/test_ctypeslib.py branches/maskedarray/setup.py Log: Merge maskedarray branch up to r4729. Property changes on: branches/maskedarray ___________________________________________________________________ Name: svnmerge-integrated - /branches/distutils-revamp:1-2752 /branches/multicore:1-3687 /branches/numpy.scons:1-4484 /trunk:1-2871 + /branches/build_with_scons:1-4676 /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/maskedarray/benchmarks/benchmark.py =================================================================== --- branches/maskedarray/benchmarks/benchmark.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/benchmarks/benchmark.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -17,7 +17,7 @@ modules = [module] for m in modules: - setup_str = 'import %s; import %s as N; ' % (m,m) \ + setup_str = 'import %s; import %s as np; ' % (m,m) \ + setup_str self.module_test[m] = Timer(test_str, setup_str) Modified: branches/maskedarray/benchmarks/creating.py =================================================================== --- branches/maskedarray/benchmarks/creating.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/benchmarks/creating.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -7,8 +7,8 @@ title='Creating %s zeros.' % N, runs=3,reps=10000) -b['numpy'] = ('a=N.zeros(shape,type)', 'shape=%s;type=float' % N) -b['Numeric'] = ('a=N.zeros(shape,type)', 'shape=%s;type=N.Float' % N) -b['numarray'] = ('a=N.zeros(shape,type)', "shape=%s;type=N.Float" % N) +b['numpy'] = ('a=np.zeros(shape,type)', 'shape=%s;type=float' % N) +b['Numeric'] = ('a=np.zeros(shape,type)', 'shape=%s;type=np.Float' % N) +b['numarray'] = ('a=np.zeros(shape,type)', "shape=%s;type=np.Float" % N) b.run() Modified: branches/maskedarray/benchmarks/simpleindex.py =================================================================== --- branches/maskedarray/benchmarks/simpleindex.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/benchmarks/simpleindex.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -5,21 +5,25 @@ # in the first place. N = 30 + code2 = r""" for k in xrange(%d): for l in xrange(%d): res = a[k,l].item() + a[l,k].item() """ % (N,N) + code3 = r""" for k in xrange(%d): for l in xrange(%d): res = a[k][l] + a[l][k] """ % (N,N) + code = r""" for k in xrange(%d): for l in xrange(%d): res = a[k,l] + a[l,k] """ % (N,N) + setup3 = r""" import random a = [[None for k in xrange(%d)] for l in xrange(%d)] @@ -27,16 +31,19 @@ for l in xrange(%d): a[k][l] = random.random() """ % (N,N,N,N) -t1 = timeit.Timer(code, 'import numpy as N; a = N.random.rand(%d,%d)' % (N,N)) -t2 = timeit.Timer(code, 'import MLab as N; a=N.rand(%d,%d)' % (N,N)) -t3 = timeit.Timer(code, 'import numarray.mlab as N; a=N.rand(%d,%d)' % (N,N)) -t4 = timeit.Timer(code2, 'import numpy as N; a = N.random.rand(%d,%d)' % (N,N)) -t5 = timeit.Timer(code3, setup3) -t6 = timeit.Timer("res = a + a.transpose()","import numpy as N; a=N.random.rand(%d,%d)" % (N,N)) + +numpy_timer1 = timeit.Timer(code, 'import numpy as np; a = np.random.rand(%d,%d)' % (N,N)) +numeric_timer = timeit.Timer(code, 'import MLab as np; a=np.rand(%d,%d)' % (N,N)) +numarray_timer = timeit.Timer(code, 'import numarray.mlab as np; a=np.rand(%d,%d)' % (N,N)) +numpy_timer2 = timeit.Timer(code2, 'import numpy as np; a = np.random.rand(%d,%d)' % (N,N)) +python_timer = timeit.Timer(code3, setup3) +numpy_timer3 = timeit.Timer("res = a + a.transpose()","import numpy as np; a=np.random.rand(%d,%d)" % (N,N)) + print "shape = ", (N,N) -print "NumPy 1: ", t1.repeat(3,100) -print "NumPy 2: ", t4.repeat(3,100) -print "Numeric: ", t2.repeat(3,100) -print "Numarray: ", t3.repeat(3,100) -print "Python: ", t5.repeat(3,100) -print "Optimized: ", t6.repeat(3,100) +print "NumPy 1: ", numpy_timer1.repeat(3,100) +print "NumPy 2: ", numpy_timer2.repeat(3,100) +print "Numeric: ", numeric_timer.repeat(3,100) +print "Numarray: ", numarray_timer.repeat(3,100) +print "Python: ", python_timer.repeat(3,100) +print "Optimized: ", numpy_timer3.repeat(3,100) + Modified: branches/maskedarray/benchmarks/sorting.py =================================================================== --- branches/maskedarray/benchmarks/sorting.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/benchmarks/sorting.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -5,21 +5,21 @@ N = 10000 b.title = 'Sorting %d elements' % N -b['numarray'] = ('a=N.array(None,shape=%d,typecode="i");a.sort()'%N,'') -b['numpy'] = ('a=N.empty(shape=%d, dtype="i");a.sort()'%N,'') -b['Numeric'] = ('a=N.empty(shape=%d, typecode="i");N.sort(a)'%N,'') +b['numarray'] = ('a=np.array(None,shape=%d,typecode="i");a.sort()'%N,'') +b['numpy'] = ('a=np.empty(shape=%d, dtype="i");a.sort()'%N,'') +b['Numeric'] = ('a=np.empty(shape=%d, typecode="i");np.sort(a)'%N,'') b.run() N1,N2 = 100,100 b.title = 'Sorting (%d,%d) elements, last axis' % (N1,N2) -b['numarray'] = ('a=N.array(None,shape=(%d,%d),typecode="i");a.sort()'%(N1,N2),'') -b['numpy'] = ('a=N.empty(shape=(%d,%d), dtype="i");a.sort()'%(N1,N2),'') -b['Numeric'] = ('a=N.empty(shape=(%d,%d),typecode="i");N.sort(a)'%(N1,N2),'') +b['numarray'] = ('a=np.array(None,shape=(%d,%d),typecode="i");a.sort()'%(N1,N2),'') +b['numpy'] = ('a=np.empty(shape=(%d,%d), dtype="i");a.sort()'%(N1,N2),'') +b['Numeric'] = ('a=np.empty(shape=(%d,%d),typecode="i");np.sort(a)'%(N1,N2),'') b.run() N1,N2 = 100,100 b.title = 'Sorting (%d,%d) elements, first axis' % (N1,N2) -b['numarray'] = ('a=N.array(None,shape=(%d,%d), typecode="i");a.sort(0)'%(N1,N2),'') -b['numpy'] = ('a=N.empty(shape=(%d,%d),dtype="i");N.sort(a,0)'%(N1,N2),'') -b['Numeric'] = ('a=N.empty(shape=(%d,%d),typecode="i");N.sort(a,0)'%(N1,N2),'') +b['numarray'] = ('a=np.array(None,shape=(%d,%d), typecode="i");a.sort(0)'%(N1,N2),'') +b['numpy'] = ('a=np.empty(shape=(%d,%d),dtype="i");np.sort(a,0)'%(N1,N2),'') +b['Numeric'] = ('a=np.empty(shape=(%d,%d),typecode="i");np.sort(a,0)'%(N1,N2),'') b.run() Modified: branches/maskedarray/numpy/__init__.py =================================================================== --- branches/maskedarray/numpy/__init__.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/__init__.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -1,4 +1,4 @@ -"""\ +""" NumPy ========== @@ -7,25 +7,29 @@ http://www.trelgol.com -It is being distributed for a fee for only a few years to +It is being distributed for a fee until Oct. 2010 to cover some of the costs of development. After the restriction period it will also be freely available. -Additional documentation is available in the docstrings and at +Documentation is available in the docstrings and at http://www.scipy.org. """ +# We first need to detect if we're being called as part of the numpy setup +# procedure itself in a reliable manner. try: - from numpy.__config__ import show as show_config -except ImportError: - show_config = None + __NUMPY_SETUP__ +except NameError: + __NUMPY_SETUP__ = False -if show_config is None: + +if __NUMPY_SETUP__: import sys as _sys print >> _sys.stderr, 'Running from numpy source directory.' del _sys else: + from numpy.__config__ import show as show_config from version import version as __version__ from _import_tools import PackageLoader @@ -34,6 +38,7 @@ loader = PackageLoader(infunc=True) return loader(*packages, **options) + pkgload.__doc__ = PackageLoader.__call__.__doc__ import testing from testing import ScipyTest, NumpyTest import core @@ -80,8 +85,8 @@ Global symbols from subpackages ------------------------------- -core --> * -lib --> * +core --> * (use numpy.* not numpy.core.*) +lib --> * (use numpy.* not numpy.lib.*) testing --> NumpyTest """ @@ -95,7 +100,7 @@ import add_newdocs - __all__.extend(['add_newdocs','test']) + __all__.extend(['add_newdocs']) if __doc__ is not None: __doc__ += """ Modified: branches/maskedarray/numpy/_import_tools.py =================================================================== --- branches/maskedarray/numpy/_import_tools.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/_import_tools.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -131,8 +131,6 @@ def __call__(self,*packages, **options): """Load one or more packages into parent package top-level namespace. - Usage: - This function is intended to shorten the need to import many subpackages, say of scipy, constantly with statements such as @@ -152,22 +150,19 @@ If a name which doesn't exist in scipy's namespace is given, a warning is shown. - Inputs: + Parameters + ---------- + *packges : arg-tuple + the names (one or more strings) of all the modules one + wishes to load into the top-level namespace. + verbose= : integer + verbosity level [default: -1]. + verbose=-1 will suspend also warnings. + force= : bool + when True, force reloading loaded packages [default: False]. + postpone= : bool + when True, don't load packages [default: False] - - the names (one or more strings) of all the numpy modules one - wishes to load into the top-level namespace. - - Optional keyword inputs: - - - verbose - integer specifying verbosity level [default: -1]. - verbose=-1 will suspend also warnings. - - force - when True, force reloading loaded packages - [default: False]. - - postpone - when True, don't load packages [default: False] - - If no input arguments are given, then all of scipy's subpackages - are imported. - """ frame = self.parent_frame self.info_modules = {} Modified: branches/maskedarray/numpy/add_newdocs.py =================================================================== --- branches/maskedarray/numpy/add_newdocs.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/add_newdocs.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -1,3 +1,7 @@ +# This is only meant to add docs to +# objects defined in C-extension modules. +# The purpose is to allow easier editing of the +# docstrings without requiring a re-compile. from lib import add_newdoc add_newdoc('numpy.core','dtype', @@ -132,30 +136,37 @@ Return an array from object with the specified date-type. - Inputs: - object - an array, any object exposing the array interface, any - object whose __array__ method returns an array, or any - (nested) sequence. - dtype - The desired data-type for the array. If not given, then - the type will be determined as the minimum type required - to hold the objects in the sequence. This argument can only - be used to 'upcast' the array. For downcasting, use the - .astype(t) method. - copy - If true, then force a copy. Otherwise a copy will only occur - if __array__ returns a copy, obj is a nested sequence, or - a copy is needed to satisfy any of the other requirements - order - Specify the order of the array. If order is 'C', then the - array will be in C-contiguous order (last-index varies the - fastest). If order is 'FORTRAN', then the returned array - will be in Fortran-contiguous order (first-index varies the - fastest). If order is None, then the returned array may - be in either C-, or Fortran-contiguous order or even - discontiguous. - subok - If True, then sub-classes will be passed-through, otherwise - the returned array will be forced to be a base-class array - ndmin - Specifies the minimum number of dimensions that the resulting - array should have. 1's will be pre-pended to the shape as - needed to meet this requirement. + Parameters + ---------- + object : array-like + an array, any object exposing the array interface, any + object whose __array__ method returns an array, or any + (nested) sequence. + dtype : data-type + The desired data-type for the array. If not given, then + the type will be determined as the minimum type required + to hold the objects in the sequence. This argument can only + be used to 'upcast' the array. For downcasting, use the + .astype(t) method. + copy : bool + If true, then force a copy. Otherwise a copy will only occur + if __array__ returns a copy, obj is a nested sequence, or + a copy is needed to satisfy any of the other requirements + order : {'C', 'F', 'A' (None)} + Specify the order of the array. If order is 'C', then the + array will be in C-contiguous order (last-index varies the + fastest). If order is 'FORTRAN', then the returned array + will be in Fortran-contiguous order (first-index varies the + fastest). If order is None, then the returned array may + be in either C-, or Fortran-contiguous order or even + discontiguous. + subok : bool + If True, then sub-classes will be passed-through, otherwise + the returned array will be forced to be a base-class array + ndmin : int + Specifies the minimum number of dimensions that the resulting + array should have. 1's will be pre-pended to the shape as + needed to meet this requirement. """) @@ -220,14 +231,17 @@ add_newdoc('numpy.core.multiarray','fromfile', """fromfile(file=, dtype=float, count=-1, sep='') -> array. - Required arguments: - file -- open file object or string containing file name. + Parameters + ---------- + file : file or string + open file object or string containing file name. + dtype : data-type + data type of the returned array + count : int + number of items to read (-1 mean 'all') + sep : string + separater between items if file is a text file (default "") - Keyword arguments: - dtype -- type and order of the returned array (default float) - count -- number of items to input (default all) - sep -- separater between items if file is a text file (default "") - Return an array of the given data type from a text or binary file. The 'file' argument can be an open file or a string with the name of a file to read from. If 'count' == -1 the entire file is read, otherwise count is the @@ -236,7 +250,6 @@ the separator between elements in a text file. The 'dtype' value is also used to determine the size and order of the items in binary files. - Data written using the tofile() method can be conveniently recovered using this function. @@ -268,8 +281,8 @@ The tuple of sequences (a1, a2, ...) are joined along the given axis (default is the first one) into a single numpy array. - Example: - + Examples + -------- >>> concatenate( ([0,1,2], [5,6,7]) ) array([0, 1, 2, 5, 6, 7]) @@ -343,26 +356,29 @@ Return elements from `x` or `y`, depending on `condition`. - *Parameters*: - condition : array of bool - When True, yield x, otherwise yield y. - x,y : 1-dimensional arrays - Values from which to choose. + Parameters + ---------- + condition : array of bool + When True, yield x, otherwise yield y. + x,y : 1-dimensional arrays + Values from which to choose. - *Notes* - This is equivalent to + Notes + ----- + This is equivalent to - [xv if c else yv for (c,xv,yv) in zip(condition,x,y)] + [xv if c else yv for (c,xv,yv) in zip(condition,x,y)] - The result is shaped like `condition` and has elements of `x` - or `y` where `condition` is respectively True or False. + The result is shaped like `condition` and has elements of `x` + or `y` where `condition` is respectively True or False. - In the special case, where only `condition` is given, the - tuple condition.nonzero() is returned, instead. + In the special case, where only `condition` is given, the + tuple condition.nonzero() is returned, instead. - *Examples* - >>> where([True,False,True],[1,2,3],[4,5,6]) - array([1, 5, 3]) + Examples + -------- + >>> where([True,False,True],[1,2,3],[4,5,6]) + array([1, 5, 3]) """) @@ -379,36 +395,36 @@ sort order, and so on). The keys argument must be a sequence of things that can be converted to arrays of the same shape. - *Parameters*: + Parameters + ---------- + keys : (k,N) array or tuple of (N,) sequences + Array containing values that the returned indices should sort. - keys : (k,N) array or tuple of (N,) sequences - Array containing values that the returned indices should sort. + axis : integer + Axis to be indirectly sorted. Default is -1 (i.e. last axis). - axis : integer - Axis to be indirectly sorted. Default is -1 (i.e. last axis). + Returns + ------- + indices : (N,) integer array + Array of indices that sort the keys along the specified axis. - *Returns*: + See Also + -------- + argsort : indirect sort + sort : inplace sort - indices : (N,) integer array - Array of indices that sort the keys along the specified axis. + Examples + -------- + >>> a = [1,5,1,4,3,6,7] + >>> b = [9,4,0,4,0,4,3] + >>> ind = lexsort((b,a)) + >>> print ind + [2 0 4 3 1 5 6] + >>> print take(a,ind) + [1 1 3 4 5 6 7] + >>> print take(b,ind) + [0 9 0 4 4 4 3] - *See Also*: - - `argsort` : indirect sort - `sort` : inplace sort - - *Examples* - - >>> a = [1,5,1,4,3,6,7] - >>> b = [9,4,0,4,0,4,3] - >>> ind = lexsort((b,a)) - >>> print ind - [2 0 4 3 1 5 6] - >>> print take(a,ind) - [1 1 3 4 5 6 7] - >>> print take(b,ind) - [0 9 0 4 4 4 3] - """) add_newdoc('numpy.core.multiarray','can_cast', @@ -623,12 +639,13 @@ Return a copy of the array. - Argument: - order -- Order of returned copy (default 'C') - If order is 'C' (False) then the result is contiguous (default). - If order is 'Fortran' (True) then the result has fortran order. - If order is 'Any' (None) then the result has fortran order - only if m is already in fortran order.; + Parameters + ---------- + order : {'C', 'F', 'A'} + If order is 'C' (False) then the result is contiguous (default). + If order is 'Fortran' (True) then the result has fortran order. + If order is 'Any' (None) then the result has fortran order + only if m is already in fortran order.; """)) @@ -650,16 +667,19 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('__setstate__', - """a.__setstate__(version, shape, typecode, isfortran, rawdata) + """a.__setstate__(version, shape, dtype, isfortran, rawdata) For unpickling. - Arguments: - version -- optional pickle version. If omitted defaults to 0. - shape -- a tuple giving the shape - typecode -- a typecode - isFortran -- a bool stating if Fortran or no - rawdata -- a binary string with the data (or a list if Object array) + Parameters + ---------- + version : int + optional pickle version. If omitted defaults to 0. + shape : tuple + dtype : data-type + isFortran : bool + rawdata : string or list + a binary string with the data (or a list if 'a' is an object array) """)) @@ -695,34 +715,32 @@ by the kind keyword. It returns an array of indices of the same shape as 'a' that index data along the given axis in sorted order. - :Parameters: + Parameters + ---------- + axis : integer + Axis to be indirectly sorted. None indicates that the flattened + array should be used. Default is -1. + kind : string + Sorting algorithm to use. Possible values are 'quicksort', + 'mergesort', or 'heapsort'. Default is 'quicksort'. + order : list type or None + When a is an array with fields defined, this argument specifies + which fields to compare first, second, etc. Not all fields need be + specified. - axis : integer - Axis to be indirectly sorted. None indicates that the flattened - array should be used. Default is -1. + Returns + ------- + indices : integer array + Array of indices that sort 'a' along the specified axis. - kind : string - Sorting algorithm to use. Possible values are 'quicksort', - 'mergesort', or 'heapsort'. Default is 'quicksort'. + SeeAlso + ------- + lexsort : indirect stable sort with multiple keys + sort : inplace sort - order : list type or None - When a is an array with fields defined, this argument specifies - which fields to compare first, second, etc. Not all fields need be - specified. + Notes + ----- - :Returns: - - indices : integer array - Array of indices that sort 'a' along the specified axis. - - :SeeAlso: - - - lexsort : indirect stable sort with multiple keys - - sort : inplace sort - - :Notes: - ------ - The various sorts are characterized by average speed, worst case performance, need for work space, and whether they are stable. A stable sort keeps items with the same key in the same relative order. The three @@ -803,12 +821,13 @@ Return a copy of the array. - Argument: - order -- Order of returned copy (default 'C') - If order is 'C' (False) then the result is contiguous (default). - If order is 'Fortran' (True) then the result has fortran order. - If order is 'Any' (None) then the result has fortran order - only if m is already in fortran order.; + Parameters + ---------- + order : Order of returned copy (default 'C') + If order is 'C' (False) then the result is contiguous (default). + If order is 'Fortran' (True) then the result has fortran order. + If order is 'Any' (None) then the result has fortran order + only if m is already in fortran order.; """)) @@ -835,30 +854,32 @@ be determined by removing axis1 and axis2 and appending an index to the right equal to the size of the resulting diagonals. - :Parameters: - offset : integer - Offset of the diagonal from the main diagonal. Can be both positive - and negative. Defaults to main diagonal. - axis1 : integer - Axis to be used as the first axis of the 2-d subarrays from which - the diagonals should be taken. Defaults to first index. - axis2 : integer - Axis to be used as the second axis of the 2-d subarrays from which - the diagonals should be taken. Defaults to second index. + Parameters + ---------- + offset : integer + Offset of the diagonal from the main diagonal. Can be both positive + and negative. Defaults to main diagonal. + axis1 : integer + Axis to be used as the first axis of the 2-d subarrays from which + the diagonals should be taken. Defaults to first index. + axis2 : integer + Axis to be used as the second axis of the 2-d subarrays from which + the diagonals should be taken. Defaults to second index. - :Returns: - array_of_diagonals : same type as original array - If a is 2-d, then a 1-d array containing the diagonal is returned. - If a is n-d, n > 2, then an array of diagonals is returned. + Returns + ------- + array_of_diagonals : same type as original array + If a is 2-d, then a 1-d array containing the diagonal is returned. + If a is n-d, n > 2, then an array of diagonals is returned. - :SeeAlso: - - diag : matlab workalike for 1-d and 2-d arrays. - - diagflat : creates diagonal arrays - - trace : sum along diagonals + SeeAlso + ------- + diag : matlab workalike for 1-d and 2-d arrays. + diagflat : creates diagonal arrays + trace : sum along diagonals Examples -------- - >>> a = arange(4).reshape(2,2) >>> a array([[0, 1], @@ -943,39 +964,36 @@ Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis. - :Parameters: + Parameters + ---------- + axis : integer + Axis along which the means are computed. The default is + to compute the standard deviation of the flattened array. + dtype : type + Type to use in computing the means. For arrays of + integer type the default is float32, for arrays of float types it + is the same as the array type. + out : ndarray + Alternative output array in which to place the result. It must have + the same shape as the expected output but the type will be cast if + necessary. - axis : integer - Axis along which the means are computed. The default is - to compute the standard deviation of the flattened array. + Returns + ------- + mean : The return type varies, see above. + A new array holding the result is returned unless out is specified, + in which case a reference to out is returned. - dtype : type - Type to use in computing the means. For arrays of - integer type the default is float32, for arrays of float types it - is the same as the array type. + SeeAlso + ------- + var : variance + std : standard deviation - out : ndarray - Alternative output array in which to place the result. It must have - the same shape as the expected output but the type will be cast if - necessary. - - :Returns: - - mean : The return type varies, see above. - A new array holding the result is returned unless out is specified, - in which case a reference to out is returned. - - :SeeAlso: - - - var : variance - - std : standard deviation - Notes ----- + The mean is the sum of the elements along the axis divided by the + number of elements. - The mean is the sum of the elements along the axis divided by the - number of elements. - """)) @@ -1070,14 +1088,17 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('round', - """a.round(decimals=0, out=None) -> out (a). Rounds to 'decimals' places. + """a.round(decimals=0, out=None) -> out (new). Rounds to 'decimals' places. - Keyword arguments: - decimals -- number of decimals to round to (default 0). May be negative. - out -- existing array to use for output (default a). + Parameters + ---------- + decimals : integer + number of decimals to round to. May be negative. + out : existing array to use for output (default new array). - Return: - Reference to out, where None specifies the original array a. + Returns + ------- + Reference to out, where None specifies a new array. Round to the specified number of decimals. When 'decimals' is negative it specifies the number of positions to the left of the decimal point. The @@ -1085,9 +1106,10 @@ is done if the array is not of float type and 'decimals' is >= 0. The keyword 'out' may be used to specify a different array to hold the - result rather than the default 'a'. If the type of the array specified by - 'out' differs from that of 'a', the result is cast to the new type, - otherwise the original type is kept. Floats round to floats by default. + result rather than the default new array. If the type of the array + specified by 'out' differs from that of 'a', the result is cast to the + new type, otherwise the original type is kept. Floats round to floats + by default. Numpy rounds to even. Thus 1.5 and 2.5 round to 2.0, -0.5 and 0.5 round to 0.0, etc. Results may also be surprising due to the inexact representation @@ -1107,31 +1129,28 @@ is out of bounds, then the length of a is returned, i.e., the key would need to be appended. The returned index array has the same shape as v. - :Parameters: + Parameters + ---------- + v : array or list type + Array of keys to be searched for in a. + side : string + Possible values are : 'left', 'right'. Default is 'left'. Return + the first or last index where the key could be inserted. - v : array or list type - Array of keys to be searched for in a. + Returns + ------- + indices : integer array + The returned array has the same shape as v. - side : string - Possible values are : 'left', 'right'. Default is 'left'. Return - the first or last index where the key could be inserted. - - :Returns: - - indices : integer array - The returned array has the same shape as v. - - :SeeAlso: - - - sort - - histogram - - :Notes: + SeeAlso ------- + sort + histogram - The array a must be 1-d and is assumed to be sorted in ascending order. - Searchsorted uses binary search to find the required insertion points. - + Notes + ----- + The array a must be 1-d and is assumed to be sorted in ascending order. + Searchsorted uses binary search to find the required insertion points. """)) @@ -1154,34 +1173,28 @@ Perform an inplace sort along the given axis using the algorithm specified by the kind keyword. - :Parameters: + Parameters + ---------- + axis : integer + Axis to be sorted along. None indicates that the flattened array + should be used. Default is -1. + kind : string + Sorting algorithm to use. Possible values are 'quicksort', + 'mergesort', or 'heapsort'. Default is 'quicksort'. + order : list type or None + When a is an array with fields defined, this argument specifies + which fields to compare first, second, etc. Not all fields need be + specified. - axis : integer - Axis to be sorted along. None indicates that the flattened array - should be used. Default is -1. + SeeAlso + ------- + argsort : indirect sort + lexsort : indirect stable sort on multiple keys + searchsorted : find keys in sorted array - kind : string - Sorting algorithm to use. Possible values are 'quicksort', - 'mergesort', or 'heapsort'. Default is 'quicksort'. + Notes + ----- - order : list type or None - When a is an array with fields defined, this argument specifies - which fields to compare first, second, etc. Not all fields need be - specified. - - :Returns: - - None - - :SeeAlso: - - - argsort : indirect sort - - lexsort : indirect stable sort on multiple keys - - searchsorted : find keys in sorted array - - :Notes: - ------ - The various sorts are characterized by average speed, worst case performance, need for work space, and whether they are stable. A stable sort keeps items with the same key in the same relative order. The three @@ -1195,10 +1208,9 @@ |'heapsort' | 3 | O(n*log(n)) | 0 | no | |------------------------------------------------------| - All the sort algorithms make temporary copies of the data when the sort is not - along the last axis. Consequently, sorts along the last axis are faster and use - less space than sorts along other axis. - + All the sort algorithms make temporary copies of the data when the sort is + not along the last axis. Consequently, sorts along the last axis are faster + and use less space than sorts along other axis. """)) @@ -1215,41 +1227,38 @@ spread of a distribution. The standard deviation is computed for the flattened array by default, otherwise over the specified axis. - :Parameters: + Parameters + ---------- + axis : integer + Axis along which the standard deviation is computed. The default is + to compute the standard deviation of the flattened array. + dtype : type + Type to use in computing the standard deviation. For arrays of + integer type the default is float32, for arrays of float types it + is the same as the array type. + out : ndarray + Alternative output array in which to place the result. It must have + the same shape as the expected output but the type will be cast if + necessary. - axis : integer - Axis along which the standard deviation is computed. The default is - to compute the standard deviation of the flattened array. + Returns + ------- + standard deviation : The return type varies, see above. + A new array holding the result is returned unless out is specified, + in which case a reference to out is returned. - dtype : type - Type to use in computing the standard deviation. For arrays of - integer type the default is float32, for arrays of float types it - is the same as the array type. + SeeAlso + ------- + var : variance + mean : average - out : ndarray - Alternative output array in which to place the result. It must have - the same shape as the expected output but the type will be cast if - necessary. - - :Returns: - - standard deviation : The return type varies, see above. - A new array holding the result is returned unless out is specified, - in which case a reference to out is returned. - - :SeeAlso: - - - var : variance - - mean : average - Notes ----- + The standard deviation is the square root of the average of the squared + deviations from the mean, i.e. var = sqrt(mean((x - x.mean())**2)). The + computed standard deviation is biased, i.e., the mean is computed by + dividing by the number of elements, N, rather than by N-1. - The standard deviation is the square root of the average of the squared - deviations from the mean, i.e. var = sqrt(mean((x - x.mean())**2)). The - computed standard deviation is biased, i.e., the mean is computed by - dividing by the number of elements, N, rather than by N-1. - """)) @@ -1270,8 +1279,8 @@ Warning: The arithmetic is modular and no error is raised on overflow. - Examples: - + Examples + -------- >>> array([0.5, 1.5]).sum() 2.0 >>> array([0.5, 1.5]).sum(dtype=int32) @@ -1282,7 +1291,6 @@ array([1, 5]) >>> ones(128, dtype=int8).sum(dtype=int8) # overflow! -128 - """)) @@ -1304,13 +1312,15 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('tofile', """a.tofile(fid, sep="", format="%s") -> None. Write the data to a file. - Required arguments: - file -- an open file object or a string containing a filename + Parameters + ---------- + fid : file or string + an open file object or a string containing a filename + sep : string + separation for text output. Write binary if this is empty. + format : string + format string for text file output - Keyword arguments: - sep -- separator for text output. Write binary if empty (default "") - format -- format string for text file output (default "%s") - A convenience function for quick storage of array data. Information on endianess and precision is lost, so this method is not a good choice for files intended to archive data or transport data between machines with @@ -1341,8 +1351,10 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('tostring', """a.tostring(order='C') -> raw copy of array data as a Python string. - Keyword arguments: - order -- order of the data item in the copy {"C","F","A"} (default "C") + Parameters + ---------- + order : {'C', 'F', 'A', None} + order of the data item in the copy Construct a Python string containing the raw bytes in the array. The order of the data in arrays with ndim > 1 is specified by the 'order' keyword and @@ -1373,7 +1385,8 @@ array, this is the usual matrix transpose. If axes are given, they describe how the axes are permuted. - Example: + Examples + -------- >>> a = array([[1,2],[3,4]]) >>> a array([[1, 2], @@ -1398,41 +1411,38 @@ distribution. The variance is computed for the flattened array by default, otherwise over the specified axis. - :Parameters: + Parameters + ---------- + axis : integer + Axis along which the variance is computed. The default is to + compute the variance of the flattened array. + dtype : data-type + Type to use in computing the variance. For arrays of integer type + the default is float32, for arrays of float types it is the same as + the array type. + out : ndarray + Alternative output array in which to place the result. It must have + the same shape as the expected output but the type will be cast if + necessary. - axis : integer - Axis along which the variance is computed. The default is to - compute the variance of the flattened array. + Returns + ------- + variance : The return type varies, see above. + A new array holding the result is returned unless out is specified, + in which case a reference to out is returned. - dtype : type - Type to use in computing the variance. For arrays of integer type - the default is float32, for arrays of float types it is the same as - the array type. + SeeAlso + ------- + std : standard deviation + mean: average - out : ndarray - Alternative output array in which to place the result. It must have - the same shape as the expected output but the type will be cast if - necessary. - - :Returns: - - variance : The return type varies, see above. - A new array holding the result is returned unless out is specified, - in which case a reference to out is returned. - - :SeeAlso: - - - std : standard deviation - - mean: average - Notes ----- + The variance is the average of the squared deviations from the mean, i.e. + var = mean((x - x.mean())**2). The computed variance is biased, i.e., + the mean is computed by dividing by the number of elements, N, rather + than by N-1. - The variance is the average of the squared deviations from the mean, i.e. - var = mean((x - x.mean())**2). The computed variance is biased, i.e., - the mean is computed by dividing by the number of elements, N, rather - than by N-1. - """)) @@ -1442,3 +1452,31 @@ Type can be either a new sub-type object or a data-descriptor object """)) + +add_newdoc('numpy.core.umath','geterrobj', + """geterrobj() + + Used internally by `geterr`. + + Returns + ------- + errobj : list + Internal numpy buffer size, error mask, error callback function. + + """) + +add_newdoc('numpy.core.umath','seterrobj', + """seterrobj() + + Used internally by `seterr`. + + Parameters + ---------- + errobj : list + [buffer_size, error_mask, callback_func] + + See Also + -------- + seterrcall + + """) Modified: branches/maskedarray/numpy/core/code_generators/generate_umath.py =================================================================== --- branches/maskedarray/numpy/core/code_generators/generate_umath.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/core/code_generators/generate_umath.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -5,6 +5,16 @@ None_ = "PyUFunc_None" class TypeDescription(object): + """Type signature for a ufunc + + Attributes + ---------- + + type: character representing the type + func_data: + in_: + out: + """ def __init__(self, type, f=None, in_=None, out=None): self.type = type self.func_data = f @@ -55,6 +65,17 @@ return tds class Ufunc(object): + """Description of a ufunc. + + Attributes + ---------- + + nin: number of input arguments + nout: number of output arguments + identity: identity element for a two-argument function + docstring: docstring for the ufunc + type_descriptions: list of TypeDescription objects + """ def __init__(self, nin, nout, identity, docstring, *type_descriptions): self.nin = nin @@ -69,7 +90,7 @@ for td in self.type_descriptions: td.finish_signature(self.nin, self.nout) -#each entry in defdict is +#each entry in defdict is a Ufunc object. #name: [string of chars for which it is defined, # string of characters using func interface, @@ -304,6 +325,16 @@ TD(ints), TD(O, f='PyNumber_Rshift'), ), +'degrees' : + Ufunc(1, 1, None, + 'converts angle from radians to degrees', + TD(fltsM, f='degrees'), + ), +'radians' : + Ufunc(1, 1, None, + 'converts angle from degrees to radians', + TD(fltsM, f='radians'), + ), 'arccos' : Ufunc(1, 1, None, 'inverse cosine elementwise.', Modified: branches/maskedarray/numpy/core/code_generators/multiarray_api_order.txt =================================================================== --- branches/maskedarray/numpy/core/code_generators/multiarray_api_order.txt 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/core/code_generators/multiarray_api_order.txt 2008-01-18 23:25:32 UTC (rev 4730) @@ -81,3 +81,4 @@ PyArray_DescrAlignConverter PyArray_DescrAlignConverter2 PyArray_SearchsideConverter +PyArray_CheckAxis Modified: branches/maskedarray/numpy/core/defmatrix.py =================================================================== --- branches/maskedarray/numpy/core/defmatrix.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/core/defmatrix.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -49,6 +49,34 @@ class matrix(N.ndarray): + """mat = matrix(data, dtype=None, copy=True) + + Returns a matrix from an array-like object, or a string of + data. A matrix is a specialized 2-d array that retains + it's 2-d nature through operations and where '*' means matrix + multiplication and '**' means matrix power. + + Parameters + ---------- + data : array-like or string + If data is a string, then interpret the string as a matrix + with commas or spaces separating columns and semicolons + separating rows. + If data is array-like than convert the array to a matrix. + dtype : data-type + Anything that can be interpreted as a NumPy datatype. + copy : bool + If data is already an ndarray, then this flag determines whether + or not the data will be copied + + Examples + -------- + >>> import numpy as np + >>> a = np.matrix('1 2; 3 4') + >>> print a + [[1 2] + [3 4]] + """ __array_priority__ = 10.0 def __new__(subtype, data, dtype=None, copy=True): if isinstance(data, matrix): @@ -244,39 +272,37 @@ Returns the average of the array elements. The average is taken over the flattened array by default, otherwise over the specified axis. - :Parameters: + Parameters + ---------- + axis : integer + Axis along which the means are computed. The default is + to compute the standard deviation of the flattened array. - axis : integer - Axis along which the means are computed. The default is - to compute the standard deviation of the flattened array. + dtype : type + Type to use in computing the means. For arrays of integer type + the default is float32, for arrays of float types it is the + same as the array type. - dtype : type - Type to use in computing the means. For arrays of integer type - the default is float32, for arrays of float types it is the - same as the array type. + out : ndarray + Alternative output array in which to place the result. It must + have the same shape as the expected output but the type will be + cast if necessary. - out : ndarray - Alternative output array in which to place the result. It must - have the same shape as the expected output but the type will be - cast if necessary. + Returns + ------- + mean : The return type varies, see above. + A new array holding the result is returned unless out is + specified, in which case a reference to out is returned. - :Returns: + SeeAlso + ------- + var : variance + std : standard deviation - mean : The return type varies, see above. - A new array holding the result is returned unless out is - specified, in which case a reference to out is returned. - - :SeeAlso: - - - var : variance - - std : standard deviation - Notes ----- - - The mean is the sum of the elements along the axis divided by the - number of elements. - + The mean is the sum of the elements along the axis divided by the + number of elements. """ return N.ndarray.mean(self, axis, out)._align(axis) @@ -287,43 +313,41 @@ spread of a distribution. The standard deviation is computed for the flattened array by default, otherwise over the specified axis. - :Parameters: + Parameters + ---------- + axis : integer + Axis along which the standard deviation is computed. The + default is to compute the standard deviation of the flattened + array. - axis : integer - Axis along which the standard deviation is computed. The - default is to compute the standard deviation of the flattened - array. + dtype : type + Type to use in computing the standard deviation. For arrays of + integer type the default is float32, for arrays of float types + it is the same as the array type. - dtype : type - Type to use in computing the standard deviation. For arrays of - integer type the default is float32, for arrays of float types - it is the same as the array type. + out : ndarray + Alternative output array in which to place the result. It must + have the same shape as the expected output but the type will be + cast if necessary. - out : ndarray - Alternative output array in which to place the result. It must - have the same shape as the expected output but the type will be - cast if necessary. + Returns + ------- + standard deviation : The return type varies, see above. + A new array holding the result is returned unless out is + specified, in which case a reference to out is returned. - :Returns: + SeeAlso + ------- + var : variance + mean : average - standard deviation : The return type varies, see above. - A new array holding the result is returned unless out is - specified, in which case a reference to out is returned. - - :SeeAlso: - - - var : variance - - mean : average - Notes - ----- - - The standard deviation is the square root of the average of the - squared deviations from the mean, i.e. var = sqrt(mean((x - - x.mean())**2)). The computed standard deviation is biased, i.e., the - mean is computed by dividing by the number of elements, N, rather - than by N-1. - + ----- + The standard deviation is the square root of the + average of the squared deviations from the mean, i.e. var = + sqrt(mean((x - x.mean())**2)). The computed standard + deviation is biased, i.e., the mean is computed by dividing by + the number of elements, N, rather than by N-1. """ return N.ndarray.std(self, axis, dtype, out)._align(axis) @@ -334,41 +358,38 @@ a distribution. The variance is computed for the flattened array by default, otherwise over the specified axis. - :Parameters: + Parameters + ---------- + axis : integer + Axis along which the variance is computed. The default is to + compute the variance of the flattened array. + dtype : data-type + Type to use in computing the variance. For arrays of integer + type the default is float32, for arrays of float types it is + the same as the array type. + out : ndarray + Alternative output array in which to place the result. It must + have the same shape as the expected output but the type will be + cast if necessary. - axis : integer - Axis along which the variance is computed. The default is to - compute the variance of the flattened array. + Returns + ------- + variance : depends, see above + A new array holding the result is returned unless out is + specified, in which case a reference to out is returned. - dtype : type - Type to use in computing the variance. For arrays of integer - type the default is float32, for arrays of float types it is - the same as the array type. + SeeAlso + ------- + std : standard deviation + mean : average - out : ndarray - Alternative output array in which to place the result. It must - have the same shape as the expected output but the type will be - cast if necessary. - - :Returns: - - variance : depends, see above - A new array holding the result is returned unless out is - specified, in which case a reference to out is returned. - - :SeeAlso: - - - std : standard deviation - - mean : average - Notes ----- - The variance is the average of the squared deviations from the mean, - i.e. var = mean((x - x.mean())**2). The computed variance is - biased, i.e., the mean is computed by dividing by the number of - elements, N, rather than by N-1. - + The variance is the average of the squared deviations from the + mean, i.e. var = mean((x - x.mean())**2). The computed + variance is biased, i.e., the mean is computed by dividing by + the number of elements, N, rather than by N-1. """ return N.ndarray.var(self, axis, dtype, out)._align(axis) @@ -458,14 +479,16 @@ def bmat(obj, ldict=None, gdict=None): """Build a matrix object from string, nested sequence, or array. - Ex: F = bmat('A, B; C, D') - F = bmat([[A,B],[C,D]]) - F = bmat(r_[c_[A,B],c_[C,D]]) + Example + -------- + F = bmat('A, B; C, D') + F = bmat([[A,B],[C,D]]) + F = bmat(r_[c_[A,B],c_[C,D]]) - all produce the same Matrix Object [ A B ] - [ C D ] + all produce the same Matrix Object [ A B ] + [ C D ] - if A, B, C, and D are appropriately shaped 2-d arrays. + if A, B, C, and D are appropriately shaped 2-d arrays. """ if isinstance(obj, str): if gdict is None: Modified: branches/maskedarray/numpy/core/numeric.py =================================================================== --- branches/maskedarray/numpy/core/numeric.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/core/numeric.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -40,10 +40,11 @@ # from Fernando Perez's IPython def zeros_like(a): - """Return an array of zeros of the shape and typecode of a. + """Return an array of zeros of the shape and data-type of a. If you don't explicitly need the array to be zeroed, you should instead - use empty_like(), which is faster as it only allocates memory.""" + use empty_like(), which is faster as it only allocates memory. + """ try: return zeros(a.shape, a.dtype, a.flags.fnc) except AttributeError: @@ -58,7 +59,7 @@ return res def empty_like(a): - """Return an empty (uninitialized) array of the shape and typecode of a. + """Return an empty (uninitialized) array of the shape and data-type of a. Note that this does NOT initialize the returned array. If you require your array to be initialized, you should use zeros_like(). @@ -147,6 +148,29 @@ return array(a, dtype, copy=False, order='F', ndmin=1) def require(a, dtype=None, requirements=None): + """Return an ndarray of the provided type that satisfies requirements. + + This function is useful to be sure that an array with the correct flags + is returned for passing to compiled code (perhaps through ctypes). + + Parameters + ---------- + a : array-like + The object to be converted to a type-and-requirement satisfying array + dtype : data-type + The required data-type (None is the default data-type -- float64) + requirements : list of strings + The requirements list can be any of the + 'ENSUREARRAY' ('E') - ensure that a base-class ndarray + 'F_CONTIGUOUS' ('F') - ensure a Fortran-contiguous array + 'C_CONTIGUOUS' ('C') - ensure a C-contiguous array + 'ALIGNED' ('A') - ensure a data-type aligned array + 'WRITEABLE' ('W') - ensure a writeable array + 'OWNDATA' ('O') - ensure an array that owns its own data + + The returned array will be guaranteed to have the listed requirements + by making a copy if needed. + """ if requirements is None: requirements = [] else: @@ -252,11 +276,13 @@ try: # importing this changes the dot function for basic 4 types # to blas-optimized versions. - from _dotblas import dot, vdot, inner, alterdot, restoredot + from _dotblas import dot, vdot, inner, alterdot, restoredot except ImportError: def alterdot(): + "Does Nothing" pass def restoredot(): + "Does Nothing" pass @@ -641,7 +667,7 @@ fname can be a filename or a file handle. Support for gzipped files is automatic, if the filename ends in .gz - See scipy.loadmat to read and write matfiles. + See scipy.io.loadmat to read and write matfiles. Example usage: @@ -847,6 +873,9 @@ return all(less_equal(absolute(x-y), atol + rtol * absolute(y))) def array_equal(a1, a2): + """Returns True if a1 and a2 have identical shapes + and all elements equal and False otherwise. + """ try: a1, a2 = asarray(a1), asarray(a2) except: @@ -856,6 +885,10 @@ return logical_and.reduce(equal(a1,a2).ravel()) def array_equiv(a1, a2): + """Returns True if a1 and a2 are shape consistent + (mutually broadcastable) and have all elements equal and False + otherwise. + """ try: a1, a2 = asarray(a1), asarray(a2) except: Modified: branches/maskedarray/numpy/core/records.py =================================================================== --- branches/maskedarray/numpy/core/records.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/core/records.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -43,10 +43,40 @@ return dup class format_parser: + """Class to convert formats, names, titles description to a dtype + + After constructing the format_parser object, the dtype attribute is + the converted data-type. + + dtype = format_parser(formats, names, titles).dtype + + Parameters + ---------- + formats : string or list + comma-separated format descriptions --- 'f8, i4, a5' + list of format description strings --- ['f8', 'i4', 'a5'] + names : string or (list or tuple of strings) + comma-separated field names --- 'col1, col2, col3' + list or tuple of field names + titles : sequence + sequence of title strings or unicode + aligned : bool + align the fields by padding as the C-compiler would + byteorder : + If specified, all the fields will be changed to the + provided byteorder. Otherwise, the default byteorder is + used. + + Returns + ------- + object + A Python object whose dtype attribute is a data-type. + """ def __init__(self, formats, names, titles, aligned=False, byteorder=None): self._parseFormats(formats, aligned) self._setfieldnames(names, titles) self._createdescr(byteorder) + self.dtype = self._descr def _parseFormats(self, formats, aligned=0): """ Parse the field formats """ @@ -115,6 +145,8 @@ self._descr = descr class record(nt.void): + """A data-type scalar that allows field access as attribute lookup. + """ def __repr__(self): return self.__str__() @@ -182,6 +214,29 @@ # the fields (and any subfields) class recarray(ndarray): + """recarray(shape, dtype=None, buf=None, **kwds) + + Subclass of ndarray that allows field access using attribute lookup. + + Parameters + ---------- + shape : tuple + shape of record array + dtype : data-type or None + The desired data-type. If this is None, then the data-type is determined + by the *formats*, *names*, *titles*, *aligned*, and *byteorder* keywords. + buf : [buffer] or None + If this is None, then a new array is created of the given shape and data-type + If this is an object exposing the buffer interface, then the array will + use the memory from an existing buffer. In this case, the *offset* and + *strides* keywords can also be used. + + See Also + -------- + format_parser : determine a data-type from formats, names, titles + record : fundamental data-type for recarray + + """ def __new__(subtype, shape, dtype=None, buf=None, offset=0, strides=None, formats=None, names=None, titles=None, byteorder=None, aligned=False): Modified: branches/maskedarray/numpy/core/src/arrayobject.c =================================================================== --- branches/maskedarray/numpy/core/src/arrayobject.c 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/core/src/arrayobject.c 2008-01-18 23:25:32 UTC (rev 4730) @@ -1691,6 +1691,12 @@ return 0; } + +/* XXX: FIXME --- add ordering argument to + Allow Fortran ordering on write + This will need the addition of a Fortran-order iterator. + */ + /*OBJECT_API To File */ @@ -3139,16 +3145,7 @@ static Py_ssize_t array_getcharbuf(PyArrayObject *self, Py_ssize_t segment, constchar **ptrptr) { - if (self->descr->type_num == PyArray_STRING || \ - self->descr->type_num == PyArray_UNICODE || \ - self->descr->elsize == 1) - return array_getreadbuf(self, segment, (void **) ptrptr); - else { - PyErr_SetString(PyExc_TypeError, - "non-character (or 8-bit) array cannot be "\ - "interpreted as character buffer"); - return -1; - } + return array_getreadbuf(self, segment, (void **) ptrptr); } static PyBufferProcs array_as_buffer = { @@ -4835,8 +4832,12 @@ return result; } + +/*MULTIARRAY_API + PyArray_CheckAxis +*/ static PyObject * -_check_axis(PyArrayObject *arr, int *axis, int flags) +PyArray_CheckAxis(PyArrayObject *arr, int *axis, int flags) { PyObject *temp1, *temp2; int n = arr->nd; @@ -4878,6 +4879,8 @@ return temp2; } +#define _check_axis PyArray_CheckAxis + #include "arraymethods.c" /* Lifted from numarray */ Modified: branches/maskedarray/numpy/core/src/arraytypes.inc.src =================================================================== --- branches/maskedarray/numpy/core/src/arraytypes.inc.src 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/core/src/arraytypes.inc.src 2008-01-18 23:25:32 UTC (rev 4730) @@ -2059,7 +2059,7 @@ @name at _fastclip(@type@ *in, intp ni, @type@ *min, @type@ *max, @type@ *out) { register npy_intp i; - @type@ max_val, min_val; + @type@ max_val = 0, min_val = 0; if (max != NULL) max_val = *max; Modified: branches/maskedarray/numpy/core/src/multiarraymodule.c =================================================================== --- branches/maskedarray/numpy/core/src/multiarraymodule.c 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/core/src/multiarraymodule.c 2008-01-18 23:25:32 UTC (rev 4730) @@ -2231,7 +2231,6 @@ return NULL; } - /*MULTIARRAY_API */ static PyObject * Modified: branches/maskedarray/numpy/core/src/scalartypes.inc.src =================================================================== --- branches/maskedarray/numpy/core/src/scalartypes.inc.src 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/core/src/scalartypes.inc.src 2008-01-18 23:25:32 UTC (rev 4730) @@ -547,14 +547,19 @@ Py_DECREF(arr); return ret; } +/**begin repeat +#name=float, double, longdouble# +#NAME=FLOAT, DOUBLE, LONGDOUBLE# +#PREFIX=NPY_,NPY_,# +*/ static void -format_longdouble(char *buf, size_t buflen, longdouble val, +format_ at name@(char *buf, size_t buflen, @name@ val, unsigned int precision) { char *cp; - PyOS_snprintf(buf, buflen, "%.*" LONGDOUBLE_FMT, precision, val); + PyOS_snprintf(buf, buflen, "%.*" @PREFIX@@NAME at _FMT, precision, val); cp = buf; if (*cp == '-') cp++; @@ -568,6 +573,7 @@ *cp++ = '\0'; } } +/**end repeat**/ /* over-ride repr and str of array-scalar strings and unicode to remove NULL bytes and then call the corresponding functions @@ -602,43 +608,58 @@ } /**end repeat**/ +/* These values are finfo.precision + 2 */ +#define FLOATPREC_REPR 8 +#define DOUBLEPREC_REPR 17 - #if SIZEOF_LONGDOUBLE == SIZEOF_DOUBLE -#define PREC_REPR 17 -#define PREC_STR 17 -#else -#define PREC_REPR 21 -#define PREC_STR 21 +#define LONGDOUBLEPREC_REPR DOUBLEPREC_REPR +#define LONGDOUBLEPREC_STR DOUBLEPREC_REPR +#else /* More than probably needed on Intel FP */ +#define LONGDOUBLEPREC_REPR 22 +#define LONGDOUBLEPREC_STR 22 #endif +/* floattype_repr */ +/**begin repeat + +#name=float, double, longdouble# +#Name=Float, Double, LongDouble# +#NAME=FLOAT, DOUBLE, LONGDOUBLE# +*/ static PyObject * -longdoubletype_repr(PyObject *self) + at name@type_repr(PyObject *self) { static char buf[100]; - format_longdouble(buf, sizeof(buf), - ((PyLongDoubleScalarObject *)self)->obval, PREC_REPR); + format_ at name@(buf, sizeof(buf), + ((Py at Name@ScalarObject *)self)->obval, @NAME at PREC_REPR); return PyString_FromString(buf); } static PyObject * -clongdoubletype_repr(PyObject *self) +c at name@type_repr(PyObject *self) { static char buf1[100]; static char buf2[100]; static char buf3[202]; - clongdouble x; - x = ((PyCLongDoubleScalarObject *)self)->obval; - format_longdouble(buf1, sizeof(buf1), x.real, PREC_REPR); - format_longdouble(buf2, sizeof(buf2), x.imag, PREC_REPR); + c at name@ x; + x = ((PyC at Name@ScalarObject *)self)->obval; + format_ at name@(buf1, sizeof(buf1), x.real, @NAME at PREC_REPR); + format_ at name@(buf2, sizeof(buf2), x.imag, @NAME at PREC_REPR); snprintf(buf3, sizeof(buf3), "(%s+%sj)", buf1, buf2); return PyString_FromString(buf3); } +/**end repeat**/ -#define longdoubletype_str longdoubletype_repr -#define clongdoubletype_str clongdoubletype_repr +/**begin repeat +#name=float, double, longdouble# +*/ +#define @name at type_str @name at type_repr +#define c at name@type_str c at name@type_repr +/**end repeat**/ + /** Could improve this with a PyLong_FromLongDouble(longdouble ldval) but this would need some more work... **/ @@ -842,6 +863,7 @@ arr = (PyArrayObject *)PyArray_FromScalar(self, NULL); if (arr == NULL) return NULL; inter = PyObject_GetAttrString((PyObject *)arr, "__array_interface__"); + if (inter != NULL) PyDict_SetItemString(inter, "__ref", (PyObject *)arr); Py_DECREF(arr); return inter; } @@ -2537,6 +2559,16 @@ PyLongLongArrType_Type.tp_hash = longlong_arrtype_hash; #endif + /**begin repeat +#name=repr, str# + */ + PyFloatArrType_Type.tp_ at name@ = floattype_ at name@; + PyCFloatArrType_Type.tp_ at name@ = cfloattype_ at name@; + + PyDoubleArrType_Type.tp_ at name@ = doubletype_ at name@; + PyCDoubleArrType_Type.tp_ at name@ = cdoubletype_ at name@; + /**end repeat**/ + /* These need to be coded specially because getitem does not return a normal Python type */ Modified: branches/maskedarray/numpy/core/src/umathmodule.c.src =================================================================== --- branches/maskedarray/numpy/core/src/umathmodule.c.src 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/core/src/umathmodule.c.src 2008-01-18 23:25:32 UTC (rev 4730) @@ -413,7 +413,26 @@ #define isfinitef(x) (!(isinff((x)) || isnanf((x)))) #define isfinitel(x) (!(isinfl((x)) || isnanl((x)))) +float degreesf(float x) { + return x * (float)(180.0/M_PI); +} +double degrees(double x) { + return x * (180.0/M_PI); +} +longdouble degreesl(longdouble x) { + return x * (180.0L/M_PI); +} +float radiansf(float x) { + return x * (float)(M_PI/180.0); +} +double radians(double x) { + return x * (M_PI/180.0); +} +longdouble radiansl(longdouble x) { + return x * (M_PI/180.0L); +} + /* First, the C functions that do the real work */ /* if C99 extensions not available then define dummy functions that use the Modified: branches/maskedarray/numpy/core/tests/test_multiarray.py =================================================================== --- branches/maskedarray/numpy/core/tests/test_multiarray.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/core/tests/test_multiarray.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -1,10 +1,9 @@ +import tempfile + +import numpy as np from numpy.testing import * from numpy.core import * -from numpy import random -import numpy as N -import tempfile - class TestFlags(NumpyTestCase): def setUp(self): self.a = arange(10) @@ -357,7 +356,7 @@ class TestArgmax(NumpyTestCase): def check_all(self): - a = random.normal(0,1,(4,5,6,7,8)) + a = np.random.normal(0,1,(4,5,6,7,8)) for i in xrange(a.ndim): amax = a.max(i) aargmax = a.argmax(i) @@ -373,8 +372,8 @@ class TestClip(NumpyTestCase): def _check_range(self,x,cmin,cmax): - assert N.all(x >= cmin) - assert N.all(x <= cmax) + assert np.all(x >= cmin) + assert np.all(x <= cmax) def _clip_type(self,type_group,array_max, clip_min,clip_max,inplace=False, @@ -384,16 +383,16 @@ if expected_max is None: expected_max = clip_max - for T in N.sctypes[type_group]: + for T in np.sctypes[type_group]: if sys.byteorder == 'little': byte_orders = ['=','>'] else: byte_orders = ['<','='] for byteorder in byte_orders: - dtype = N.dtype(T).newbyteorder(byteorder) + dtype = np.dtype(T).newbyteorder(byteorder) - x = (N.random.random(1000) * array_max).astype(dtype) + x = (np.random.random(1000) * array_max).astype(dtype) if inplace: x.clip(clip_min,clip_max,x) else: @@ -417,46 +416,46 @@ x = self._clip_type('uint',1024,0,0, inplace=inplace) def check_record_array(self): - rec = N.array([(-5, 2.0, 3.0), (5.0, 4.0, 3.0)], + rec = np.array([(-5, 2.0, 3.0), (5.0, 4.0, 3.0)], dtype=[('x', '= 3) + assert np.all(x >= 3) x = val.clip(min=3) - assert N.all(x >= 3) + assert np.all(x >= 3) x = val.clip(max=4) - assert N.all(x <= 4) + assert np.all(x <= 4) class TestPutmask(ParametricTestCase): def tst_basic(self,x,T,mask,val): - N.putmask(x,mask,val) - assert N.all(x[mask] == T(val)) + np.putmask(x,mask,val) + assert np.all(x[mask] == T(val)) assert x.dtype == T def testip_types(self): - unchecked_types = [str,unicode,N.void,object] + unchecked_types = [str, unicode, np.void, object] - x = N.random.random(1000)*100 + x = np.random.random(1000)*100 mask = x < 40 tests = [] for val in [-100,0,15]: - for types in N.sctypes.itervalues(): + for types in np.sctypes.itervalues(): tests.extend([(self.tst_basic,x.copy().astype(T),T,mask,val) for T in types if T not in unchecked_types]) return tests def test_mask_size(self): - self.failUnlessRaises(ValueError,N.putmask, - N.array([1,2,3]),[True],5) + self.failUnlessRaises(ValueError, np.putmask, + np.array([1,2,3]), [True], 5) def tst_byteorder(self,dtype): - x = N.array([1,2,3],dtype) - N.putmask(x,[True,False,True],-1) + x = np.array([1,2,3],dtype) + np.putmask(x,[True,False,True],-1) assert_array_equal(x,[-1,2,-1]) def testip_byteorder(self): @@ -464,46 +463,54 @@ def test_record_array(self): # Note mixed byteorder. - rec = N.array([(-5, 2.0, 3.0), (5.0, 4.0, 3.0)], + rec = np.array([(-5, 2.0, 3.0), (5.0, 4.0, 3.0)], dtype=[('x', 'f8'), ('z', '']: - for dtype in [float,int,N.complex]: - dt = N.dtype(dtype).newbyteorder(byteorder) - x = (N.random.random((4,7))*5).astype(dt) + for dtype in [float,int,np.complex]: + dt = np.dtype(dtype).newbyteorder(byteorder) + x = (np.random.random((4,7))*5).astype(dt) buf = x.tostring() tests.append((self.tst_basic,buf,x.flat,{'dtype':dt})) return tests class TestResize(NumpyTestCase): def test_basic(self): - x = N.eye(3) + x = np.eye(3) x.resize((5,5)) - assert_array_equal(x.flat[:9],N.eye(3).flat) + assert_array_equal(x.flat[:9],np.eye(3).flat) assert_array_equal(x[9:].flat,0) def test_check_reference(self): - x = N.eye(3) + x = np.eye(3) y = x self.failUnlessRaises(ValueError,x.resize,(5,1)) Modified: branches/maskedarray/numpy/core/tests/test_regression.py =================================================================== --- branches/maskedarray/numpy/core/tests/test_regression.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/core/tests/test_regression.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -4,14 +4,14 @@ import sys set_local_path() -import numpy as N +import numpy as np restore_path() rlevel = 1 def assert_valid_refcount(op): - a = N.arange(100 * 100) - b = N.arange(100*100).reshape(100, 100) + a = np.arange(100 * 100) + b = np.arange(100*100).reshape(100, 100) c = b i = 1 @@ -26,15 +26,15 @@ def check_invalid_round(self,level=rlevel): """Ticket #3""" v = 4.7599999999999998 - assert_array_equal(N.array([v]),N.array(v)) + assert_array_equal(np.array([v]),np.array(v)) def check_mem_empty(self,level=rlevel): """Ticket #7""" - N.empty((1,),dtype=[('x',N.int64)]) + np.empty((1,),dtype=[('x',np.int64)]) def check_pickle_transposed(self,level=rlevel): """Ticket #16""" - a = N.transpose(N.array([[2,9],[7,0],[3,8]])) + a = np.transpose(np.array([[2,9],[7,0],[3,8]])) f = StringIO() pickle.dump(a,f) f.seek(0) @@ -44,45 +44,45 @@ def check_masked_array_create(self,level=rlevel): """Ticket #17""" - x = N.ma.masked_array([0,1,2,3,0,4,5,6],mask=[0,0,0,1,1,1,0,0]) - assert_array_equal(N.ma.nonzero(x),[[1,2,6,7]]) + x = np.ma.masked_array([0,1,2,3,0,4,5,6],mask=[0,0,0,1,1,1,0,0]) + assert_array_equal(np.ma.nonzero(x),[[1,2,6,7]]) def check_poly1d(self,level=rlevel): """Ticket #28""" - assert_equal(N.poly1d([1]) - N.poly1d([1,0]), - N.poly1d([-1,1])) + assert_equal(np.poly1d([1]) - np.poly1d([1,0]), + np.poly1d([-1,1])) def check_typeNA(self,level=rlevel): """Ticket #31""" - assert_equal(N.typeNA[N.int64],'Int64') - assert_equal(N.typeNA[N.uint64],'UInt64') + assert_equal(np.typeNA[np.int64],'Int64') + assert_equal(np.typeNA[np.uint64],'UInt64') def check_dtype_names(self,level=rlevel): """Ticket #35""" - dt = N.dtype([(('name','label'),N.int32,3)]) + dt = np.dtype([(('name','label'),np.int32,3)]) def check_reduce(self,level=rlevel): """Ticket #40""" - assert_almost_equal(N.add.reduce([1.,.5],dtype=None), 1.5) + assert_almost_equal(np.add.reduce([1.,.5],dtype=None), 1.5) def check_zeros_order(self,level=rlevel): """Ticket #43""" - N.zeros([3], int, 'C') - N.zeros([3], order='C') - N.zeros([3], int, order='C') + np.zeros([3], int, 'C') + np.zeros([3], order='C') + np.zeros([3], int, order='C') def check_sort_bigendian(self,level=rlevel): """Ticket #47""" - a = N.linspace(0, 10, 11) - c = a.astype(N.dtype('f8') - b = N.arange(10.,dtype='2) & (a<6)) - xb = N.where((b>2) & (b<6)) + a = np.arange(10.,dtype='>f8') + b = np.arange(10.,dtype='2) & (a<6)) + xb = np.where((b>2) & (b<6)) ya = ((a>2) & (a<6)) yb = ((b>2) & (b<6)) assert_array_almost_equal(xa,ya.nonzero()) assert_array_almost_equal(xb,yb.nonzero()) - assert(N.all(a[ya] > 0.5)) - assert(N.all(b[yb] > 0.5)) + assert(np.all(a[ya] > 0.5)) + assert(np.all(b[yb] > 0.5)) def check_mem_dot(self,level=rlevel): """Ticket #106""" - x = N.random.randn(0,1) - y = N.random.randn(10,1) - z = N.dot(x, N.transpose(y)) + x = np.random.randn(0,1) + y = np.random.randn(10,1) + z = np.dot(x, np.transpose(y)) def check_arange_endian(self,level=rlevel): """Ticket #111""" - ref = N.arange(10) - x = N.arange(10,dtype='f8') + x = np.arange(10,dtype='>f8') assert_array_equal(ref,x) # Longfloat support is not consistent enough across # platforms for this test to be meaningful. # def check_longfloat_repr(self,level=rlevel): # """Ticket #112""" -# if N.longfloat(0).itemsize > 8: -# a = N.exp(N.array([1000],dtype=N.longfloat)) +# if np.longfloat(0).itemsize > 8: +# a = np.exp(np.array([1000],dtype=np.longfloat)) # assert(str(a)[1:9] == str(a[0])[:8]) def check_argmax(self,level=rlevel): """Ticket #119""" - a = N.random.normal(0,1,(4,5,6,7,8)) + a = np.random.normal(0,1,(4,5,6,7,8)) for i in xrange(a.ndim): aargmax = a.argmax(i) def check_matrix_properties(self,level=rlevel): """Ticket #125""" - a = N.matrix([1.0],dtype=float) - assert(type(a.real) is N.matrix) - assert(type(a.imag) is N.matrix) - c,d = N.matrix([0.0]).nonzero() - assert(type(c) is N.matrix) - assert(type(d) is N.matrix) + a = np.matrix([1.0],dtype=float) + assert(type(a.real) is np.matrix) + assert(type(a.imag) is np.matrix) + c,d = np.matrix([0.0]).nonzero() + assert(type(c) is np.matrix) + assert(type(d) is np.matrix) def check_mem_divmod(self,level=rlevel): """Ticket #126""" for i in range(10): - divmod(N.array([i])[0],10) + divmod(np.array([i])[0],10) def check_hstack_invalid_dims(self,level=rlevel): """Ticket #128""" - x = N.arange(9).reshape((3,3)) - y = N.array([0,0,0]) - self.failUnlessRaises(ValueError,N.hstack,(x,y)) + x = np.arange(9).reshape((3,3)) + y = np.array([0,0,0]) + self.failUnlessRaises(ValueError,np.hstack,(x,y)) def check_squeeze_type(self,level=rlevel): """Ticket #133""" - a = N.array([3]) - b = N.array(3) - assert(type(a.squeeze()) is N.ndarray) - assert(type(b.squeeze()) is N.ndarray) + a = np.array([3]) + b = np.array(3) + assert(type(a.squeeze()) is np.ndarray) + assert(type(b.squeeze()) is np.ndarray) def check_add_identity(self,level=rlevel): """Ticket #143""" - assert_equal(0,N.add.identity) + assert_equal(0,np.add.identity) def check_binary_repr_0(self,level=rlevel): """Ticket #151""" - assert_equal('0',N.binary_repr(0)) + assert_equal('0',np.binary_repr(0)) def check_rec_iterate(self,level=rlevel): """Ticket #160""" - descr = N.dtype([('i',int),('f',float),('s','|S3')]) - x = N.rec.array([(1,1.1,'1.0'), + descr = np.dtype([('i',int),('f',float),('s','|S3')]) + x = np.rec.array([(1,1.1,'1.0'), (2,2.2,'2.0')],dtype=descr) x[0].tolist() [i for i in x[0]] def check_unicode_string_comparison(self,level=rlevel): """Ticket #190""" - a = N.array('hello',N.unicode_) - b = N.array('world') + a = np.array('hello',np.unicode_) + b = np.array('world') a == b def check_tostring_FORTRANORDER_discontiguous(self,level=rlevel): """Fix in r2836""" # Create discontiguous Fortran-ordered array - x = N.array(N.random.rand(3,3),order='F')[:,:2] - assert_array_almost_equal(x.ravel(),N.fromstring(x.tostring())) + x = np.array(np.random.rand(3,3),order='F')[:,:2] + assert_array_almost_equal(x.ravel(),np.fromstring(x.tostring())) def check_flat_assignment(self,level=rlevel): """Correct behaviour of ticket #194""" - x = N.empty((3,1)) - x.flat = N.arange(3) + x = np.empty((3,1)) + x.flat = np.arange(3) assert_array_almost_equal(x,[[0],[1],[2]]) - x.flat = N.arange(3,dtype=float) + x.flat = np.arange(3,dtype=float) assert_array_almost_equal(x,[[0],[1],[2]]) def check_broadcast_flat_assignment(self,level=rlevel): """Ticket #194""" - x = N.empty((3,1)) - def bfa(): x[:] = N.arange(3) - def bfb(): x[:] = N.arange(3,dtype=float) + x = np.empty((3,1)) + def bfa(): x[:] = np.arange(3) + def bfb(): x[:] = np.arange(3,dtype=float) self.failUnlessRaises(ValueError, bfa) self.failUnlessRaises(ValueError, bfb) def check_unpickle_dtype_with_object(self,level=rlevel): """Implemented in r2840""" - dt = N.dtype([('x',int),('y',N.object_),('z','O')]) + dt = np.dtype([('x',int),('y',np.object_),('z','O')]) f = StringIO() pickle.dump(dt,f) f.seek(0) @@ -325,107 +325,107 @@ def check_mem_array_creation_invalid_specification(self,level=rlevel): """Ticket #196""" - dt = N.dtype([('x',int),('y',N.object_)]) + dt = np.dtype([('x',int),('y',np.object_)]) # Wrong way - self.failUnlessRaises(ValueError, N.array, [1,'object'], dt) + self.failUnlessRaises(ValueError, np.array, [1,'object'], dt) # Correct way - N.array([(1,'object')],dt) + np.array([(1,'object')],dt) def check_recarray_single_element(self,level=rlevel): """Ticket #202""" - a = N.array([1,2,3],dtype=N.int32) + a = np.array([1,2,3],dtype=np.int32) b = a.copy() - r = N.rec.array(a,shape=1,formats=['3i4'],names=['d']) + r = np.rec.array(a,shape=1,formats=['3i4'],names=['d']) assert_array_equal(a,b) assert_equal(a,r[0][0]) def check_zero_sized_array_indexing(self,level=rlevel): """Ticket #205""" - tmp = N.array([]) - def index_tmp(): tmp[N.array(10)] + tmp = np.array([]) + def index_tmp(): tmp[np.array(10)] self.failUnlessRaises(IndexError, index_tmp) def check_unique_zero_sized(self,level=rlevel): """Ticket #205""" - assert_array_equal([], N.unique(N.array([]))) + assert_array_equal([], np.unique(np.array([]))) def check_chararray_rstrip(self,level=rlevel): """Ticket #222""" - x = N.chararray((1,),5) + x = np.chararray((1,),5) x[0] = 'a ' x = x.rstrip() assert_equal(x[0], 'a') def check_object_array_shape(self,level=rlevel): """Ticket #239""" - assert_equal(N.array([[1,2],3,4],dtype=object).shape, (3,)) - assert_equal(N.array([[1,2],[3,4]],dtype=object).shape, (2,2)) - assert_equal(N.array([(1,2),(3,4)],dtype=object).shape, (2,2)) - assert_equal(N.array([],dtype=object).shape, (0,)) - assert_equal(N.array([[],[],[]],dtype=object).shape, (3,0)) - assert_equal(N.array([[3,4],[5,6],None],dtype=object).shape, (3,)) + assert_equal(np.array([[1,2],3,4],dtype=object).shape, (3,)) + assert_equal(np.array([[1,2],[3,4]],dtype=object).shape, (2,2)) + assert_equal(np.array([(1,2),(3,4)],dtype=object).shape, (2,2)) + assert_equal(np.array([],dtype=object).shape, (0,)) + assert_equal(np.array([[],[],[]],dtype=object).shape, (3,0)) + assert_equal(np.array([[3,4],[5,6],None],dtype=object).shape, (3,)) def check_mem_around(self,level=rlevel): """Ticket #243""" - x = N.zeros((1,)) + x = np.zeros((1,)) y = [0] decimal = 6 - N.around(abs(x-y),decimal) <= 10.0**(-decimal) + np.around(abs(x-y),decimal) <= 10.0**(-decimal) def check_character_array_strip(self,level=rlevel): """Ticket #246""" - x = N.char.array(("x","x ","x ")) + x = np.char.array(("x","x ","x ")) for c in x: assert_equal(c,"x") def check_lexsort(self,level=rlevel): """Lexsort memory error""" - v = N.array([1,2,3,4,5,6,7,8,9,10]) - assert_equal(N.lexsort(v),0) + v = np.array([1,2,3,4,5,6,7,8,9,10]) + assert_equal(np.lexsort(v),0) def check_pickle_dtype(self,level=rlevel): """Ticket #251""" import pickle - pickle.dumps(N.float) + pickle.dumps(np.float) def check_masked_array_multiply(self,level=rlevel): """Ticket #254""" - a = N.ma.zeros((4,1)) - a[2,0] = N.ma.masked - b = N.zeros((4,2)) + a = np.ma.zeros((4,1)) + a[2,0] = np.ma.masked + b = np.zeros((4,2)) a*b b*a def check_swap_real(self, level=rlevel): """Ticket #265""" - assert_equal(N.arange(4,dtype='>c8').imag.max(),0.0) - assert_equal(N.arange(4,dtype=' 1 and x['two'] > 2) @@ -440,7 +440,7 @@ funcs2 = ['compress', 'take', 'repeat'] for func in funcs1: - arr = N.random.rand(8,7) + arr = np.random.rand(8,7) arr2 = arr.copy() if isinstance(func, tuple): func_meth = func[1] @@ -448,15 +448,15 @@ else: func_meth = func res1 = getattr(arr, func_meth)() - res2 = getattr(N, func)(arr2) + res2 = getattr(np, func)(arr2) if res1 is None: assert abs(arr-res2).max() < 1e-8, func else: assert abs(res1-res2).max() < 1e-8, func for func in funcs2: - arr1 = N.random.rand(8,7) - arr2 = N.random.rand(8,7) + arr1 = np.random.rand(8,7) + arr2 = np.random.rand(8,7) res1 = None if func == 'compress': arr1 = arr1.ravel() @@ -465,219 +465,219 @@ arr2 = (15*arr2).astype(int).ravel() if res1 is None: res1 = getattr(arr1, func)(arr2) - res2 = getattr(N, func)(arr1, arr2) + res2 = getattr(np, func)(arr1, arr2) assert abs(res1-res2).max() < 1e-8, func def check_mem_lexsort_strings(self, level=rlevel): """Ticket #298""" lst = ['abc','cde','fgh'] - N.lexsort((lst,)) + np.lexsort((lst,)) def check_fancy_index(self, level=rlevel): """Ticket #302""" - x = N.array([1,2])[N.array([0])] + x = np.array([1,2])[np.array([0])] assert_equal(x.shape,(1,)) def check_recarray_copy(self, level=rlevel): """Ticket #312""" - dt = [('x',N.int16),('y',N.float64)] - ra = N.array([(1,2.3)], dtype=dt) - rb = N.rec.array(ra, dtype=dt) + dt = [('x',np.int16),('y',np.float64)] + ra = np.array([(1,2.3)], dtype=dt) + rb = np.rec.array(ra, dtype=dt) rb['x'] = 2. assert ra['x'] != rb['x'] def check_rec_fromarray(self, level=rlevel): """Ticket #322""" - x1 = N.array([[1,2],[3,4],[5,6]]) - x2 = N.array(['a','dd','xyz']) - x3 = N.array([1.1,2,3]) - N.rec.fromarrays([x1,x2,x3], formats="(2,)i4,a3,f8") + x1 = np.array([[1,2],[3,4],[5,6]]) + x2 = np.array(['a','dd','xyz']) + x3 = np.array([1.1,2,3]) + np.rec.fromarrays([x1,x2,x3], formats="(2,)i4,a3,f8") def check_object_array_assign(self, level=rlevel): - x = N.empty((2,2),object) + x = np.empty((2,2),object) x.flat[2] = (1,2,3) assert_equal(x.flat[2],(1,2,3)) def check_ndmin_float64(self, level=rlevel): """Ticket #324""" - x = N.array([1,2,3],dtype=N.float64) - assert_equal(N.array(x,dtype=N.float32,ndmin=2).ndim,2) - assert_equal(N.array(x,dtype=N.float64,ndmin=2).ndim,2) + x = np.array([1,2,3],dtype=np.float64) + assert_equal(np.array(x,dtype=np.float32,ndmin=2).ndim,2) + assert_equal(np.array(x,dtype=np.float64,ndmin=2).ndim,2) def check_mem_vectorise(self, level=rlevel): """Ticket #325""" - vt = N.vectorize(lambda *args: args) - vt(N.zeros((1,2,1)), N.zeros((2,1,1)), N.zeros((1,1,2))) - vt(N.zeros((1,2,1)), N.zeros((2,1,1)), N.zeros((1,1,2)), N.zeros((2,2))) + vt = np.vectorize(lambda *args: args) + vt(np.zeros((1,2,1)), np.zeros((2,1,1)), np.zeros((1,1,2))) + vt(np.zeros((1,2,1)), np.zeros((2,1,1)), np.zeros((1,1,2)), np.zeros((2,2))) def check_mem_axis_minimization(self, level=rlevel): """Ticket #327""" - data = N.arange(5) - data = N.add.outer(data,data) + data = np.arange(5) + data = np.add.outer(data,data) def check_mem_float_imag(self, level=rlevel): """Ticket #330""" - N.float64(1.0).imag + np.float64(1.0).imag def check_dtype_tuple(self, level=rlevel): """Ticket #334""" - assert N.dtype('i4') == N.dtype(('i4',())) + assert np.dtype('i4') == np.dtype(('i4',())) def check_dtype_posttuple(self, level=rlevel): """Ticket #335""" - N.dtype([('col1', '()i4')]) + np.dtype([('col1', '()i4')]) def check_mgrid_single_element(self, level=rlevel): """Ticket #339""" - assert_array_equal(N.mgrid[0:0:1j],[0]) - assert_array_equal(N.mgrid[0:0],[]) + assert_array_equal(np.mgrid[0:0:1j],[0]) + assert_array_equal(np.mgrid[0:0],[]) def check_numeric_carray_compare(self, level=rlevel): """Ticket #341""" - assert_equal(N.array([ 'X' ], 'c'),'X') + assert_equal(np.array([ 'X' ], 'c'),'X') def check_string_array_size(self, level=rlevel): """Ticket #342""" self.failUnlessRaises(ValueError, - N.array,[['X'],['X','X','X']],'|S1') + np.array,[['X'],['X','X','X']],'|S1') def check_dtype_repr(self, level=rlevel): """Ticket #344""" - dt1=N.dtype(('uint32', 2)) - dt2=N.dtype(('uint32', (2,))) + dt1=np.dtype(('uint32', 2)) + dt2=np.dtype(('uint32', (2,))) assert_equal(dt1.__repr__(), dt2.__repr__()) def check_reshape_order(self, level=rlevel): """Make sure reshape order works.""" - a = N.arange(6).reshape(2,3,order='F') + a = np.arange(6).reshape(2,3,order='F') assert_equal(a,[[0,2,4],[1,3,5]]) - a = N.array([[1,2],[3,4],[5,6],[7,8]]) + a = np.array([[1,2],[3,4],[5,6],[7,8]]) b = a[:,1] assert_equal(b.reshape(2,2,order='F'), [[2,6],[4,8]]) def check_repeat_discont(self, level=rlevel): """Ticket #352""" - a = N.arange(12).reshape(4,3)[:,2] + a = np.arange(12).reshape(4,3)[:,2] assert_equal(a.repeat(3), [2,2,2,5,5,5,8,8,8,11,11,11]) def check_array_index(self, level=rlevel): """Make sure optimization is not called in this case.""" - a = N.array([1,2,3]) - a2 = N.array([[1,2,3]]) - assert_equal(a[N.where(a==3)], a2[N.where(a2==3)]) + a = np.array([1,2,3]) + a2 = np.array([[1,2,3]]) + assert_equal(a[np.where(a==3)], a2[np.where(a2==3)]) def check_object_argmax(self, level=rlevel): - a = N.array([1,2,3],dtype=object) + a = np.array([1,2,3],dtype=object) assert a.argmax() == 2 def check_recarray_fields(self, level=rlevel): """Ticket #372""" - dt0 = N.dtype([('f0','i4'),('f1','i4')]) - dt1 = N.dtype([('f0','i8'),('f1','i8')]) - for a in [N.array([(1,2),(3,4)],"i4,i4"), - N.rec.array([(1,2),(3,4)],"i4,i4"), - N.rec.array([(1,2),(3,4)]), - N.rec.fromarrays([(1,2),(3,4)],"i4,i4"), - N.rec.fromarrays([(1,2),(3,4)])]: + dt0 = np.dtype([('f0','i4'),('f1','i4')]) + dt1 = np.dtype([('f0','i8'),('f1','i8')]) + for a in [np.array([(1,2),(3,4)],"i4,i4"), + np.rec.array([(1,2),(3,4)],"i4,i4"), + np.rec.array([(1,2),(3,4)]), + np.rec.fromarrays([(1,2),(3,4)],"i4,i4"), + np.rec.fromarrays([(1,2),(3,4)])]: assert(a.dtype in [dt0,dt1]) def check_random_shuffle(self, level=rlevel): """Ticket #374""" - a = N.arange(5).reshape((5,1)) + a = np.arange(5).reshape((5,1)) b = a.copy() - N.random.shuffle(b) - assert_equal(N.sort(b, axis=0),a) + np.random.shuffle(b) + assert_equal(np.sort(b, axis=0),a) def check_refcount_vectorize(self, level=rlevel): """Ticket #378""" def p(x,y): return 123 - v = N.vectorize(p) + v = np.vectorize(p) assert_valid_refcount(v) def check_poly1d_nan_roots(self, level=rlevel): """Ticket #396""" - p = N.poly1d([N.nan,N.nan,1], r=0) - self.failUnlessRaises(N.linalg.LinAlgError,getattr,p,"r") + p = np.poly1d([np.nan,np.nan,1], r=0) + self.failUnlessRaises(np.linalg.LinAlgError,getattr,p,"r") def check_refcount_vdot(self, level=rlevel): """Changeset #3443""" - assert_valid_refcount(N.vdot) + assert_valid_refcount(np.vdot) def check_startswith(self, level=rlevel): - ca = N.char.array(['Hi','There']) + ca = np.char.array(['Hi','There']) assert_equal(ca.startswith('H'),[True,False]) def check_noncommutative_reduce_accumulate(self, level=rlevel): """Ticket #413""" - tosubtract = N.arange(5) - todivide = N.array([2.0, 0.5, 0.25]) - assert_equal(N.subtract.reduce(tosubtract), -10) - assert_equal(N.divide.reduce(todivide), 16.0) - assert_array_equal(N.subtract.accumulate(tosubtract), - N.array([0, -1, -3, -6, -10])) - assert_array_equal(N.divide.accumulate(todivide), - N.array([2., 4., 16.])) + tosubtract = np.arange(5) + todivide = np.array([2.0, 0.5, 0.25]) + assert_equal(np.subtract.reduce(tosubtract), -10) + assert_equal(np.divide.reduce(todivide), 16.0) + assert_array_equal(np.subtract.accumulate(tosubtract), + np.array([0, -1, -3, -6, -10])) + assert_array_equal(np.divide.accumulate(todivide), + np.array([2., 4., 16.])) def check_mem_polymul(self, level=rlevel): """Ticket #448""" - N.polymul([],[1.]) + np.polymul([],[1.]) def check_convolve_empty(self, level=rlevel): """Convolve should raise an error for empty input array.""" - self.failUnlessRaises(AssertionError,N.convolve,[],[1]) - self.failUnlessRaises(AssertionError,N.convolve,[1],[]) + self.failUnlessRaises(AssertionError,np.convolve,[],[1]) + self.failUnlessRaises(AssertionError,np.convolve,[1],[]) def check_multidim_byteswap(self, level=rlevel): """Ticket #449""" - r=N.array([(1,(0,1,2))], dtype="i2,3i2") + r=np.array([(1,(0,1,2))], dtype="i2,3i2") assert_array_equal(r.byteswap(), - N.array([(256,(0,256,512))],r.dtype)) + np.array([(256,(0,256,512))],r.dtype)) def check_string_NULL(self, level=rlevel): """Changeset 3557""" - assert_equal(N.array("a\x00\x0b\x0c\x00").item(), + assert_equal(np.array("a\x00\x0b\x0c\x00").item(), 'a\x00\x0b\x0c') def check_mem_string_concat(self, level=rlevel): """Ticket #469""" - x = N.array([]) - N.append(x,'asdasd\tasdasd') + x = np.array([]) + np.append(x,'asdasd\tasdasd') def check_matrix_multiply_by_1d_vector(self, level=rlevel) : """Ticket #473""" def mul() : - N.mat(N.eye(2))*N.ones(2) + np.mat(np.eye(2))*np.ones(2) self.failUnlessRaises(ValueError,mul) def check_junk_in_string_fields_of_recarray(self, level=rlevel): """Ticket #483""" - r = N.array([['abc']], dtype=[('var1', '|S20')]) + r = np.array([['abc']], dtype=[('var1', '|S20')]) assert str(r['var1'][0][0]) == 'abc' def check_take_output(self, level=rlevel): """Ensure that 'take' honours output parameter.""" - x = N.arange(12).reshape((3,4)) - a = N.take(x,[0,2],axis=1) - b = N.zeros_like(a) - N.take(x,[0,2],axis=1,out=b) + x = np.arange(12).reshape((3,4)) + a = np.take(x,[0,2],axis=1) + b = np.zeros_like(a) + np.take(x,[0,2],axis=1,out=b) assert_array_equal(a,b) def check_array_str_64bit(self, level=rlevel): """Ticket #501""" - s = N.array([1, N.nan],dtype=N.float64) - errstate = N.seterr(all='raise') + s = np.array([1, np.nan],dtype=np.float64) + errstate = np.seterr(all='raise') try: - sstr = N.array_str(s) + sstr = np.array_str(s) finally: - N.seterr(**errstate) + np.seterr(**errstate) def check_frompyfunc_endian(self, level=rlevel): """Ticket #503""" from math import radians - uradians = N.frompyfunc(radians, 1, 1) - big_endian = N.array([83.4, 83.5], dtype='>f8') - little_endian = N.array([83.4, 83.5], dtype='f4','0)]=1.0 self.failUnlessRaises(ValueError,ia,x,s) def check_mem_scalar_indexing(self, level=rlevel): """Ticket #603""" - x = N.array([0],dtype=float) - index = N.array(0,dtype=N.int32) + x = np.array([0],dtype=float) + index = np.array(0,dtype=np.int32) x[index] + def check_binary_repr_0_width(self, level=rlevel): + assert_equal(np.binary_repr(0,width=3),'000') if __name__ == "__main__": NumpyTest().run() Modified: branches/maskedarray/numpy/core/tests/test_scalarmath.py =================================================================== --- branches/maskedarray/numpy/core/tests/test_scalarmath.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/core/tests/test_scalarmath.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -1,14 +1,12 @@ from numpy.testing import * -set_package_path() import numpy.core.umath as ncu from numpy import array -import numpy as N -restore_path() +import numpy as np -types = [N.bool_, N.byte, N.ubyte, N.short, N.ushort, N.intc, N.uintc, - N.int_, N.uint, N.longlong, N.ulonglong, - N.single, N.double, N.longdouble, N.csingle, - N.cdouble, N.clongdouble] +types = [np.bool_, np.byte, np.ubyte, np.short, np.ushort, np.intc, np.uintc, + np.int_, np.uint, np.longlong, np.ulonglong, + np.single, np.double, np.longdouble, np.csingle, + np.cdouble, np.clongdouble] # This compares scalarmath against ufuncs. @@ -40,13 +38,13 @@ class TestPower(NumpyTestCase): def check_small_types(self): - for t in [N.int8, N.int16]: + for t in [np.int8, np.int16]: a = t(3) b = a ** 4 assert b == 81, "error with %r: got %r" % (t,b) def check_large_types(self): - for t in [N.int32, N.int64, N.float32, N.float64, N.longdouble]: + for t in [np.int32, np.int64, np.float32, np.float64, np.longdouble]: a = t(51) b = a ** 4 assert b == 6765201, "error with %r: got %r" % (t,b) @@ -55,12 +53,20 @@ def test_int_from_long(self): l = [1e6, 1e12, 1e18, -1e6, -1e12, -1e18] li = [10**6, 10**12, 10**18, -10**6, -10**12, -10**18] - for T in [None,N.float64,N.int64]: - a = N.array(l,dtype=T) + for T in [None, np.float64, np.int64]: + a = np.array(l,dtype=T) assert_equal(map(int,a), li) - a = N.array(l[:3],dtype=N.uint64) + a = np.array(l[:3], dtype=np.uint64) assert_equal(map(int,a), li[:3]) +#class TestRepr(NumpyTestCase): +# def check_repr(self): +# for t in types: +# val = t(1197346475.0137341) +# val_repr = repr(val) +# val2 = eval(val_repr) +# assert_equal( val, val2 ) + if __name__ == "__main__": NumpyTest().run() Modified: branches/maskedarray/numpy/core/tests/test_ufunc.py =================================================================== --- branches/maskedarray/numpy/core/tests/test_ufunc.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/core/tests/test_ufunc.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -1,15 +1,12 @@ +import numpy as np from numpy.testing import * -set_package_path() -import numpy as N -restore_path() - class TestUfunc(NumpyTestCase): def test_reduceat_shifting_sum(self): L = 6 - x = N.arange(L) - idx = N.array(zip(N.arange(L-2),N.arange(L-2)+2)).ravel() - assert_array_equal(N.add.reduceat(x,idx)[::2], + x = np.arange(L) + idx = np.array(zip(np.arange(L-2), np.arange(L-2)+2)).ravel() + assert_array_equal(np.add.reduceat(x,idx)[::2], [1,3,5,7]) if __name__ == "__main__": Modified: branches/maskedarray/numpy/core/tests/test_umath.py =================================================================== --- branches/maskedarray/numpy/core/tests/test_umath.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/core/tests/test_umath.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -2,7 +2,7 @@ set_package_path() from numpy.core.umath import minimum, maximum, exp import numpy.core.umath as ncu -from numpy import zeros, ndarray, array, choose +from numpy import zeros, ndarray, array, choose, pi restore_path() class TestDivision(NumpyTestCase): @@ -61,6 +61,16 @@ def check_floating_point(self): assert_equal(ncu.FLOATING_POINT_SUPPORT, 1) +def TestDegrees(NumpyTestCase): + def check_degrees(self): + assert_almost_equal(ncu.degrees(pi), 180.0) + assert_almost_equal(ncu.degrees(-0.5*pi), -90.0) + +def TestRadians(NumpyTestCase): + def check_radians(self): + assert_almost_equal(ncu.radians(180.0), pi) + assert_almost_equal(ncu.degrees(-90.0), -0.5*pi) + class TestSpecialMethods(NumpyTestCase): def test_wrap(self): class with_wrap(object): Modified: branches/maskedarray/numpy/distutils/command/build_src.py =================================================================== --- branches/maskedarray/numpy/distutils/command/build_src.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/distutils/command/build_src.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -4,6 +4,7 @@ import os import re import sys +import shlex from distutils.command import build_ext from distutils.dep_util import newer_group, newer @@ -24,7 +25,6 @@ appendpath, is_string, is_sequence from numpy.distutils.from_template import process_file as process_f_file from numpy.distutils.conv_template import process_file as process_c_file -from numpy.distutils.exec_command import splitcmdline class build_src(build_ext.build_ext): @@ -94,7 +94,7 @@ if self.f2py_opts is None: self.f2py_opts = [] else: - self.f2py_opts = splitcmdline(self.f2py_opts) + self.f2py_opts = shlex.split(self.f2py_opts) if self.swigflags: if self.swig_opts: @@ -106,7 +106,7 @@ if self.swig_opts is None: self.swig_opts = [] else: - self.swig_opts = splitcmdline(self.swig_opts) + self.swig_opts = shlex.split(self.swig_opts) # use options from build_ext command build_ext = self.get_finalized_command('build_ext') Modified: branches/maskedarray/numpy/distutils/exec_command.py =================================================================== --- branches/maskedarray/numpy/distutils/exec_command.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/distutils/exec_command.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -11,7 +11,6 @@ Provides functions: exec_command --- execute command in a specified directory and in the modified environment. - splitcmdline --- inverse of ' '.join(argv) find_executable --- locate a command using info from environment variable PATH. Equivalent to posix `which` command. @@ -50,6 +49,7 @@ import os import sys +import shlex from numpy.distutils.misc_util import is_sequence, make_temp_file from numpy.distutils import log @@ -59,8 +59,6 @@ fo.close() return name -############################################################ - def get_pythonexe(): pythonexe = sys.executable if os.name in ['nt','dos']: @@ -70,58 +68,12 @@ assert os.path.isfile(pythonexe), '%r is not a file' % (pythonexe,) return pythonexe -############################################################ - def splitcmdline(line): - """ Inverse of ' '.join(sys.argv). - """ - log.debug('splitcmdline(%r)' % (line)) - lst = [] - flag = 0 - s,pc,cc = '','','' - for nc in line+' ': - if flag==0: - flag = (pc != '\\' and \ - ((cc=='"' and 1) or (cc=="'" and 2) or \ - (cc==' ' and pc!=' ' and -2))) or flag - elif flag==1: - flag = (cc=='"' and pc!='\\' and nc==' ' and -1) or flag - elif flag==2: - flag = (cc=="'" and pc!='\\' and nc==' ' and -1) or flag - if flag!=-2: - s += cc - if flag<0: - flag = 0 - s = s.strip() - if s: - lst.append(s) - s = '' - pc,cc = cc,nc - else: - s = s.strip() - if s: - lst.append(s) - log.debug('splitcmdline -> %r' % (lst)) - return lst + import warnings + warnings.warn('splitcmdline is deprecated; use shlex.split', + DeprecationWarning) + return shlex.split(line) -def test_splitcmdline(): - l = splitcmdline('a b cc') - assert l==['a','b','cc'], repr(l) - l = splitcmdline('a') - assert l==['a'], repr(l) - l = splitcmdline('a " b cc"') - assert l==['a','" b cc"'], repr(l) - l = splitcmdline('"a bcc" -h') - assert l==['"a bcc"','-h'], repr(l) - l = splitcmdline(r'"\"a \" bcc" -h') - assert l==[r'"\"a \" bcc"','-h'], repr(l) - l = splitcmdline(" 'a bcc' -h") - assert l==["'a bcc'",'-h'], repr(l) - l = splitcmdline(r"'\'a \' bcc' -h") - assert l==[r"'\'a \' bcc'",'-h'], repr(l) - -############################################################ - def find_executable(exe, path=None, _cache={}): """Return full path of a executable or None. @@ -379,7 +331,7 @@ if is_sequence(command): argv = command[:] else: - argv = splitcmdline(command) + argv = shlex.split(command) if hasattr(os,'spawnvpe'): spawn_command = os.spawnvpe @@ -632,7 +584,6 @@ if __name__ == "__main__": - test_splitcmdline() test(use_tee=0) test(use_tee=1) test_execute_in(use_tee=0) Modified: branches/maskedarray/numpy/distutils/fcompiler/intel.py =================================================================== --- branches/maskedarray/numpy/distutils/fcompiler/intel.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/distutils/fcompiler/intel.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -114,7 +114,7 @@ opt.remove('-shared') except ValueError: idx = 0 - opt[idx:idx] = ['-dynamiclib', '-Wl,-undefined,dynamic_lookup'] + opt[idx:idx] = ['-dynamiclib', '-Wl,-undefined,dynamic_lookup', '-Wl,-framework,Python'] return opt class IntelItaniumFCompiler(IntelFCompiler): Modified: branches/maskedarray/numpy/distutils/interactive.py =================================================================== --- branches/maskedarray/numpy/distutils/interactive.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/distutils/interactive.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -50,7 +50,7 @@ """ % (ccompiler, fcompiler, argv) -from exec_command import splitcmdline +import shlex def edit_argv(*args): argv = args[0] @@ -62,7 +62,7 @@ except EOFError: return if s: - argv[1:] = splitcmdline(s) + argv[1:] = shlex.split(s) return def interactive_sys_argv(argv): Modified: branches/maskedarray/numpy/distutils/log.py =================================================================== --- branches/maskedarray/numpy/distutils/log.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/distutils/log.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -18,9 +18,13 @@ def _log(self, level, msg, args): if level >= self.threshold: if args: - print _global_color_map[level](msg % _fix_args(args)) - else: - print _global_color_map[level](msg) + msg = msg % _fix_args(args) + if 0: + if msg.startswith('copying ') and msg.find(' -> ') != -1: + return + if msg.startswith('byte-compiling '): + return + print _global_color_map[level](msg) sys.stdout.flush() def good(self, msg, *args): Modified: branches/maskedarray/numpy/doc/DISTUTILS.txt =================================================================== --- branches/maskedarray/numpy/doc/DISTUTILS.txt 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/doc/DISTUTILS.txt 2008-01-18 23:25:32 UTC (rev 4730) @@ -399,7 +399,6 @@ --------------------------------------- + ``get_pythonexe()`` -+ ``splitcmdline(line)`` + ``find_executable(exe, path=None)`` + ``exec_command( command, execute_in='', use_shell=None, use_tee=None, **env )`` Modified: branches/maskedarray/numpy/doc/HOWTO_DOCUMENT.txt =================================================================== --- branches/maskedarray/numpy/doc/HOWTO_DOCUMENT.txt 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/doc/HOWTO_DOCUMENT.txt 2008-01-18 23:25:32 UTC (rev 4730) @@ -17,8 +17,14 @@ Use a code checker: * `pylint `__ + * `pyflakes` easy_install pyflakes * `pep8.py `__ +Common import standards:: + + import numpy as np + import scipy as sp + Docstring Standard ------------------ @@ -27,7 +33,8 @@ of the object (``object.__doc__``) and, for consistency, is surrounded by triple double quotes. -It is highly desireable that both NumPy and SciPy_ follow a common +It is highly desireable that both NumPy and SciPy_ and scikits to +follow a common convention for docstrings that provide for consistency while also allowing epydoc_ to produce nicely-formatted reference guides. This document describes the current community consensus for this standard. @@ -36,30 +43,28 @@ Our docstring standard uses `reST `__ syntax and is rendered -using epydoc_. The markup in this proposal is as basic as possible -and, in particular, avoids the use of epydoc consolidated fields. This -is both because there are a limited number of such fields, inadequate -to our current needs, and because epydoc moves the fields to the end -of the documentation, messing up the ordering. Standard definition -lists are used instead. Likewise, epydoc moves headings and have an -unwelcome size in the default style sheet, therefore they are also -avoided. +using something like epydoc_ (+ a pre-processor which understands the +particular documentation style we are using). The markup in this +proposal is as basic as possible which still looks reasonable when the +text is just printed. In particular, it avoids too much cruft in the +reST syntax and other epydoc_-isms. +The guiding principle is that human readers of the text itself are +given precedence over contorting the docstring so that epydoc_ +produces nice output. In order to improve the rendered output we +should work on making pre-processor tools to assist epydoc_ or another +similar tool, rather than making human readers conform to a particular +computer-imposed style. Status ------ -We are currently trying to: +We are currently trying to convert existing docstrings to the new +format and write them for those that currently lack docstrings. -1. Agree on docstring standards. +We are also trying to improve the rendered output either using a +pre-processor to epydoc or another tool similar to epydoc. -2. Work with Ed loper to ensure that epydoc_ provides the functionality - we need. - -3. Convert existing docstrings to the new format and write them for - those that currently lack docstrings. - - Sections -------- @@ -84,7 +89,11 @@ functions with a large number of keyword argument can still be well documented without cluttering the main parameters' list. -6. **See also:** +6. **Raises:** + An optional section detailing which errors get raised under what + conditions. + +7. **See also:** An optional section used to refer to related code. This section can be very useful, but should be used judiciously. The goal is to direct users to other functions they may not be aware of, or have @@ -92,17 +101,17 @@ example). Routines whose docstrings further explain parameters used by this function are good candidates. -7. **Notes:** +8. **Notes:** An optional section that provides additional information about the code, possibly including a discussion of the algorithm. This section may include mathematical equations, possibly written in `LaTeX `__. -8. **Examples:** +9. **Examples:** An optional section for examples, using the `doctest `__ format. It can provide an inline mini-tutorial as well as additional - regression testing. While optional, this section is strongly + regression testing. While optional, this section is very strongly encouraged. You can run the tests by doing:: >>> import doctest @@ -123,15 +132,6 @@ Common reST concepts -------------------- -A reST-documented module should define:: - - __docformat__ = 'restructuredtext en' - -at the top level in accordance with `PEP 258 -`__. Note that the -``__docformat__`` variable in a package's ``__init__.py`` file does -not apply to objects defined in subpackages and submodules. - For paragraphs, indentation is significant and indicates indentation in the output. New paragraphs are marked with blank line. @@ -159,8 +159,9 @@ sudo python setup.py install The appearance of some elements can be changed in the epydoc.css -style sheet. The list headings, i.e. *Parameters*:, are emphasized text, so -their appearance is controlled by the definition of the +style sheet. + +Emphasized text appearance can be controlled by the definition of the tag. For instance, to make them bold, insert:: em {font-weight: bold;} @@ -201,10 +202,10 @@ Then, run epydoc:: - $ epydoc example.txt + $ epydoc example.py The output is placed in ``./html``, and may be viewed by loading the -``index.html`` file into your browser. +``index.html`` file into your browser. This document itself was written in ReStructuredText, and may be converted to HTML using:: Modified: branches/maskedarray/numpy/doc/example.py =================================================================== --- branches/maskedarray/numpy/doc/example.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/doc/example.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -15,64 +15,59 @@ import scipy as sp # imports should be at the top of the module import matplotlib as mpl # imports should usually be on separate lines - -__docformat__ = "restructuredtext en" - - def foo(var1, var2, long_var_name='hi') : """One-line summary or signature. Several sentences providing an extended description. You can put text in mono-spaced type like so: ``var``. - *Parameters*: + Parameters + ---------- + var1 : array_like + Array_like means all those objects -- lists, nested lists, etc. -- + that can be converted to an array. + var2 : integer + Write out the full type + long_variable_name : {'hi', 'ho'}, optional + Choices in brackets, default first when optional. - var1 : {array_like} - Array_like means all those objects -- lists, nested lists, etc. -- - that can be converted to an array. - var2 : {integer} - Write out the full type - long_variable_name : {'hi', 'ho'}, optional - Choices in brackets, default first when optional. + Returns + ------- + named : type + Explanation + list + Explanation + of + Explanation + outputs + even more explaining - *Returns*: + Other Parameters + ---------------- + only_seldom_used_keywords : type + Explanation + common_parametrs_listed_above : type + Explanation - named : {type} - Explanation - list - Explanation - of - Explanation - outputs - even more explaining + See Also + -------- + otherfunc : relationship (optional) + newfunc : relationship (optional) - *Other Parameters*: + Notes + ----- + Notes about the implementation algorithm (if needed). - only_seldom_used_keywords : type - Explanation - common_parametrs_listed_above : type - Explanation + This can have multiple paragraphs as can all sections. - *See Also*: + Examples + -------- + examples in doctest format - `otherfunc` : relationship (optional) + >>> a=[1,2,3] + >>> [x + 3 for x in a] + [4, 5, 6] - `newfunc` : relationship (optional) - - *Notes* - - Notes about the implementation algorithm (if needed). - - This can have multiple paragraphs as can all sections. - - *Examples* - - examples in doctest format - - >>> a=[1,2,3] - >>> [x + 3 for x in a] - [4, 5, 6] - """ pass Modified: branches/maskedarray/numpy/doc/html/epydoc.css =================================================================== --- branches/maskedarray/numpy/doc/html/epydoc.css 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/doc/html/epydoc.css 2008-01-18 23:25:32 UTC (rev 4730) @@ -28,6 +28,8 @@ h3 { font-size: +110%; font-style: italic; font-weight: normal; } code { font-size: 100%; } +/* N.B.: class, not pseudoclass */ +a.link { font-family: monospace; } /* Page Header & Footer * - The standard page header consists of a navigation bar (with @@ -158,6 +160,11 @@ .summary-sig-arg { color: #006040; } .summary-sig-default { color: #501800; } +/* Subclass list + */ +ul.subclass-list { display: inline; } +ul.subclass-list li { display: inline; } + /* To render variables, classes etc. like functions */ table.summary .summary-name { color: #006080; font-weight: bold; font-family: monospace; } Modified: branches/maskedarray/numpy/doc/html/epydoc.js =================================================================== --- branches/maskedarray/numpy/doc/html/epydoc.js 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/doc/html/epydoc.js 2008-01-18 23:25:32 UTC (rev 4730) @@ -17,8 +17,11 @@ if (elts[i].className == "private") { elts[i].style.display = ((cmd && cmd.substr(0,4)=="hide")?"none":"block"); } + else if (elts[i].className == "public") { + elts[i].style.display = ((cmd && cmd.substr(0,4)=="hide")?"block":"none"); + } } - // Update all table rowss containing private objects. Note, we + // Update all table rows containing private objects. Note, we // use "" instead of "block" becaue IE & firefox disagree on what // this should be (block vs table-row), and "" just gives the // default for both browsers. @@ -33,7 +36,7 @@ for(var i=0; iModule example

source code

This is the docstring for the example.py module. Modules names should -have short, all-lowercase names. The module name may have underscores if -this improves readability.

-

Every module should have a docstring at the very top of the file. The -module's docstring may extend over multiple lines. If your docstring does -extend over multiple lines, the closing three quotation marks must be on -a line by itself, preferably preceeded by a blank line.

+ have short, all-lowercase names. The module name may have underscores if + this improves readability.

+

Every module should have a docstring at the very top of the file. The + module's docstring may extend over multiple lines. If your docstring + does extend over multiple lines, the closing three quotation marks must + be on a line by itself, preferably preceeded by a blank line.

@@ -166,63 +166,63 @@ source code  - + -

One-line summary or signature.

-

Several sentences providing an extended description. You can put -text in mono-spaced type like so: var.

-

Parameters:

-
-
-
var1 : {array_like}
-
Array_like means all those objects -- lists, nested lists, etc. -- -that can be converted to an array.
-
var2 : {integer}
-
Write out the full type
-
long_variable_name : {'hi', 'ho'}, optional
-
Choices in brackets, default first when optional.
-
-
-

Returns:

-
-
-
named : {type}
-
Explanation
-
list
-
Explanation
-
of
-
Explanation
-
outputs
-
even more explaining
-
-
-

Other Parameters:

-
-
-
only_seldom_used_keywords : type
-
Explanation
-
common_parametrs_listed_above : type
-
Explanation
-
-
-

See Also:

-
-

otherfunc : relationship (optional)

-

newfunc : relationship (optional)

-
-

Notes

-
-

Notes about the implementation algorithm (if needed).

-

This can have multiple paragraphs as can all sections.

-
-

Examples

-
-

examples in doctest format

-
->>> a=[1,2,3]
->>> [x + 3 for x in a]
-[4, 5, 6]
-
+
+One-line summary or signature.
+
+Several sentences providing an extended description. You can put
+text in mono-spaced type like so: ``var``.
+
+Parameters
+----------
+var1 : array_like
+    Array_like means all those objects -- lists, nested lists, etc. --
+    that can be converted to an array.
+var2 : integer
+    Write out the full type
+long_variable_name : {'hi', 'ho'}, optional
+    Choices in brackets, default first when optional.
+
+Returns
+-------
+named : type
+    Explanation
+list
+    Explanation
+of
+    Explanation
+outputs
+    even more explaining
+
+Other Parameters
+----------------
+only_seldom_used_keywords : type
+    Explanation
+common_parametrs_listed_above : type
+    Explanation
+
+See Also
+--------    
+otherfunc : relationship (optional)
+newfunc : relationship (optional)
+
+Notes
+-----
+Notes about the implementation algorithm (if needed).
+
+This can have multiple paragraphs as can all sections.
+
+Examples
+--------
+
+examples in doctest format
+
+>>> a=[1,2,3]
+>>> [x + 3 for x in a]
+[4, 5, 6]
+
+
@@ -239,10 +239,10 @@ source code  - +

Do nothing.

-

I never saw a purple cow.

+

I never saw a purple cow.

@@ -259,10 +259,10 @@ source code  - +

Do nothing.

-

I never hope to see one.

+

I never hope to see one.

@@ -294,10 +294,11 @@
@@ -308,9 +309,8 @@ // javascript is turned off then we want them to be // visible); but by default, we want to hide them. So hide // them unless we have a cookie that says to show them. - checkCookie() + checkCookie(); // --> - Modified: branches/maskedarray/numpy/doc/html/example-pysrc.html =================================================================== --- branches/maskedarray/numpy/doc/html/example-pysrc.html 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/doc/html/example-pysrc.html 2008-01-18 23:25:32 UTC (rev 4730) @@ -55,105 +55,101 @@

Source Code for Module example

-  1  """This is the docstring for the example.py module.  Modules names should 
-  2  have short, all-lowercase names.  The module name may have underscores if 
-  3  this improves readability. 
-  4   
-  5  Every module should have a docstring at the very top of the file.  The 
-  6  module's docstring may extend over multiple lines.  If your docstring does 
-  7  extend over multiple lines, the closing three quotation marks must be on 
-  8  a line by itself, preferably preceeded by a blank line. 
-  9   
- 10  """ 
- 11   
- 12  import os                      # standard library imports first 
- 13   
- 14  import numpy as np             # related third party imports next 
- 15  import scipy as sp             # imports should be at the top of the module 
- 16  import matplotlib as mpl       # imports should usually be on separate lines 
- 17   
- 18   
- 19  __docformat__ = "restructuredtext en" 
- 20   
- 21   
-
22 -def foo(var1, var2, long_var_name='hi') : -
23 """One-line summary or signature. - 24 - 25 Several sentences providing an extended description. You can put - 26 text in mono-spaced type like so: ``var``. - 27 - 28 *Parameters*: - 29 - 30 var1 : {array_like} - 31 Array_like means all those objects -- lists, nested lists, etc. -- - 32 that can be converted to an array. - 33 var2 : {integer} - 34 Write out the full type - 35 long_variable_name : {'hi', 'ho'}, optional - 36 Choices in brackets, default first when optional. - 37 - 38 *Returns*: - 39 - 40 named : {type} - 41 Explanation - 42 list - 43 Explanation - 44 of - 45 Explanation - 46 outputs - 47 even more explaining - 48 - 49 *Other Parameters*: - 50 - 51 only_seldom_used_keywords : type - 52 Explanation - 53 common_parametrs_listed_above : type - 54 Explanation - 55 - 56 *See Also*: - 57 - 58 `otherfunc` : relationship (optional) - 59 - 60 `newfunc` : relationship (optional) - 61 - 62 *Notes* - 63 - 64 Notes about the implementation algorithm (if needed). - 65 - 66 This can have multiple paragraphs as can all sections. - 67 - 68 *Examples* - 69 - 70 examples in doctest format - 71 - 72 >>> a=[1,2,3] - 73 >>> [x + 3 for x in a] - 74 [4, 5, 6] - 75 - 76 """ - 77 - 78 pass -
79 - 80 -
81 -def newfunc() : -
82 """Do nothing. - 83 - 84 I never saw a purple cow. - 85 - 86 """ - 87 - 88 pass -
89 - 90 -
91 -def otherfunc() : -
92 """Do nothing. - 93 - 94 I never hope to see one. - 95 - 96 """ - 97 - 98 pass -
99 - Modified: branches/maskedarray/numpy/doc/html/help.html =================================================================== --- branches/maskedarray/numpy/doc/html/help.html 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/doc/html/help.html 2008-01-18 23:25:32 UTC (rev 4730) @@ -246,10 +246,11 @@
@@ -260,9 +261,8 @@ // javascript is turned off then we want them to be // visible); but by default, we want to hide them. So hide // them unless we have a cookie that says to show them. - checkCookie() + checkCookie(); // --> - Modified: branches/maskedarray/numpy/doc/html/identifier-index.html =================================================================== --- branches/maskedarray/numpy/doc/html/identifier-index.html 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/doc/html/identifier-index.html 2008-01-18 23:25:32 UTC (rev 4730) @@ -158,10 +158,11 @@
@@ -172,9 +173,8 @@ // javascript is turned off then we want them to be // visible); but by default, we want to hide them. So hide // them unless we have a cookie that says to show them. - checkCookie() + checkCookie(); // --> - Modified: branches/maskedarray/numpy/doc/html/module-tree.html =================================================================== --- branches/maskedarray/numpy/doc/html/module-tree.html 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/doc/html/module-tree.html 2008-01-18 23:25:32 UTC (rev 4730) @@ -79,10 +79,11 @@
@@ -93,9 +94,8 @@ // javascript is turned off then we want them to be // visible); but by default, we want to hide them. So hide // them unless we have a cookie that says to show them. - checkCookie() + checkCookie(); // --> - Modified: branches/maskedarray/numpy/doc/html/toc-everything.html =================================================================== --- branches/maskedarray/numpy/doc/html/toc-everything.html 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/doc/html/toc-everything.html 2008-01-18 23:25:32 UTC (rev 4730) @@ -26,9 +26,8 @@ // javascript is turned off then we want them to be // visible); but by default, we want to hide them. So hide // them unless we have a cookie that says to show them. - checkCookie() + checkCookie(); // --> - Modified: branches/maskedarray/numpy/doc/html/toc-example-module.html =================================================================== --- branches/maskedarray/numpy/doc/html/toc-example-module.html 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/doc/html/toc-example-module.html 2008-01-18 23:25:32 UTC (rev 4730) @@ -26,9 +26,8 @@ // javascript is turned off then we want them to be // visible); but by default, we want to hide them. So hide // them unless we have a cookie that says to show them. - checkCookie() + checkCookie(); // --> - Modified: branches/maskedarray/numpy/doc/html/toc.html =================================================================== --- branches/maskedarray/numpy/doc/html/toc.html 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/doc/html/toc.html 2008-01-18 23:25:32 UTC (rev 4730) @@ -26,9 +26,8 @@ // javascript is turned off then we want them to be // visible); but by default, we want to hide them. So hide // them unless we have a cookie that says to show them. - checkCookie() + checkCookie(); // --> - Modified: branches/maskedarray/numpy/doc/swig/test/testArray.py =================================================================== --- branches/maskedarray/numpy/doc/swig/test/testArray.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/doc/swig/test/testArray.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -7,10 +7,12 @@ import unittest # Import NumPy -import numpy as N -major, minor = [ int(d) for d in N.__version__.split(".")[:2] ] -if major == 0: BadListError = TypeError -else: BadListError = ValueError +import numpy as np +major, minor = [ int(d) for d in np.__version__.split(".")[:2] ] +if major == 0: + BadListError = TypeError +else: + BadListError = ValueError # Add the distutils-generated build directory to the python search path and then # import the extension module @@ -38,7 +40,7 @@ def testConstructor2(self): "Test Array1 array constructor" - na = N.arange(self.length) + na = np.arange(self.length) aa = Array.Array1(na) self.failUnless(isinstance(aa, Array.Array1)) @@ -68,7 +70,7 @@ def testResize1(self): "Test Array1 resize method, array" - a = N.zeros((2*self.length,), dtype='l') + a = np.zeros((2*self.length,), dtype='l') self.array1.resize(a) self.failUnless(len(self.array1) == len(a)) @@ -114,7 +116,7 @@ "Test Array1 view method" for i in range(self.array1.length()): self.array1[i] = i+1 a = self.array1.view() - self.failUnless(isinstance(a, N.ndarray)) + self.failUnless(isinstance(a, np.ndarray)) self.failUnless(len(a) == self.length) self.failUnless((a == [1,2,3,4,5]).all()) @@ -139,7 +141,7 @@ def testConstructor2(self): "Test Array2 array constructor" - na = N.zeros((3,4), dtype="l") + na = np.zeros((3,4), dtype="l") aa = Array.Array2(na) self.failUnless(isinstance(aa, Array.Array2)) @@ -180,7 +182,7 @@ #def testResize1(self): # "Test Array2 resize method, array" - # a = N.zeros((2*self.nrows, 2*self.ncols), dtype='l') + # a = np.zeros((2*self.nrows, 2*self.ncols), dtype='l') # self.array2.resize(a) # self.failUnless(len(self.array2) == len(a)) @@ -197,7 +199,7 @@ m = self.nrows n = self.ncols array1 = [ ] - a = N.arange(n, dtype="l") + a = np.arange(n, dtype="l") for i in range(m): array1.append(Array.Array1(i*a)) for i in range(m): @@ -265,7 +267,7 @@ def testView(self): "Test Array2 view method" a = self.array2.view() - self.failUnless(isinstance(a, N.ndarray)) + self.failUnless(isinstance(a, np.ndarray)) self.failUnless(len(a) == self.nrows) ###################################################################### @@ -279,7 +281,7 @@ # Execute the test suite print "Testing Classes of Module Array" - print "NumPy version", N.__version__ + print "NumPy version", np.__version__ print result = unittest.TextTestRunner(verbosity=2).run(suite) sys.exit(len(result.errors) + len(result.failures)) Modified: branches/maskedarray/numpy/doc/swig/test/testFarray.py =================================================================== --- branches/maskedarray/numpy/doc/swig/test/testFarray.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/doc/swig/test/testFarray.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -7,8 +7,8 @@ import unittest # Import NumPy -import numpy as N -major, minor = [ int(d) for d in N.__version__.split(".")[:2] ] +import numpy as np +major, minor = [ int(d) for d in np.__version__.split(".")[:2] ] if major == 0: BadListError = TypeError else: BadListError = ValueError @@ -136,7 +136,7 @@ for j in range(self.ncols): self.array[i,j] = i+j a = self.array.view() - self.failUnless(isinstance(a, N.ndarray)) + self.failUnless(isinstance(a, np.ndarray)) self.failUnless(a.flags.f_contiguous) for i in range(self.nrows): for j in range(self.ncols): @@ -152,7 +152,7 @@ # Execute the test suite print "Testing Classes of Module Farray" - print "NumPy version", N.__version__ + print "NumPy version", np.__version__ print result = unittest.TextTestRunner(verbosity=2).run(suite) sys.exit(len(result.errors) + len(result.failures)) Modified: branches/maskedarray/numpy/doc/swig/test/testMatrix.py =================================================================== --- branches/maskedarray/numpy/doc/swig/test/testMatrix.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/doc/swig/test/testMatrix.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -7,8 +7,8 @@ import unittest # Import NumPy -import numpy as N -major, minor = [ int(d) for d in N.__version__.split(".")[:2] ] +import numpy as np +major, minor = [ int(d) for d in np.__version__.split(".")[:2] ] if major == 0: BadListError = TypeError else: BadListError = ValueError @@ -131,7 +131,7 @@ "Test scale function" print >>sys.stderr, self.typeStr, "... ", scale = Matrix.__dict__[self.typeStr + "Scale"] - matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],self.typeCode) + matrix = np.array([[1,2,3],[2,1,2],[3,2,1]],self.typeCode) scale(matrix,4) self.assertEquals((matrix == [[4,8,12],[8,4,8],[12,8,4]]).all(), True) @@ -140,7 +140,7 @@ "Test scale function with wrong dimensions" print >>sys.stderr, self.typeStr, "... ", scale = Matrix.__dict__[self.typeStr + "Scale"] - matrix = N.array([1,2,2,1],self.typeCode) + matrix = np.array([1,2,2,1],self.typeCode) self.assertRaises(TypeError, scale, matrix) # Test (type INPLACE_ARRAY2[ANY][ANY]) typemap @@ -148,7 +148,7 @@ "Test scale function with wrong size" print >>sys.stderr, self.typeStr, "... ", scale = Matrix.__dict__[self.typeStr + "Scale"] - matrix = N.array([[1,2],[2,1]],self.typeCode) + matrix = np.array([[1,2],[2,1]],self.typeCode) self.assertRaises(TypeError, scale, matrix) # Test (type INPLACE_ARRAY2[ANY][ANY]) typemap @@ -156,7 +156,7 @@ "Test scale function with wrong type" print >>sys.stderr, self.typeStr, "... ", scale = Matrix.__dict__[self.typeStr + "Scale"] - matrix = N.array([[1,2,3],[2,1,2],[3,2,1]],'c') + matrix = np.array([[1,2,3],[2,1,2],[3,2,1]],'c') self.assertRaises(TypeError, scale, matrix) # Test (type INPLACE_ARRAY2[ANY][ANY]) typemap @@ -172,16 +172,16 @@ "Test floor function" print >>sys.stderr, self.typeStr, "... ", floor = Matrix.__dict__[self.typeStr + "Floor"] - matrix = N.array([[6,7],[8,9]],self.typeCode) + matrix = np.array([[6,7],[8,9]],self.typeCode) floor(matrix,7) - N.testing.assert_array_equal(matrix, N.array([[7,7],[8,9]])) + np.testing.assert_array_equal(matrix, np.array([[7,7],[8,9]])) # Test (type* INPLACE_ARRAY2, int DIM1, int DIM2) typemap def testFloorWrongDim(self): "Test floor function with wrong dimensions" print >>sys.stderr, self.typeStr, "... ", floor = Matrix.__dict__[self.typeStr + "Floor"] - matrix = N.array([6,7,8,9],self.typeCode) + matrix = np.array([6,7,8,9],self.typeCode) self.assertRaises(TypeError, floor, matrix) # Test (type* INPLACE_ARRAY2, int DIM1, int DIM2) typemap @@ -189,7 +189,7 @@ "Test floor function with wrong type" print >>sys.stderr, self.typeStr, "... ", floor = Matrix.__dict__[self.typeStr + "Floor"] - matrix = N.array([[6,7], [8,9]],'c') + matrix = np.array([[6,7], [8,9]],'c') self.assertRaises(TypeError, floor, matrix) # Test (type* INPLACE_ARRAY2, int DIM1, int DIM2) typemap @@ -205,16 +205,16 @@ "Test ceil function" print >>sys.stderr, self.typeStr, "... ", ceil = Matrix.__dict__[self.typeStr + "Ceil"] - matrix = N.array([[1,2],[3,4]],self.typeCode) + matrix = np.array([[1,2],[3,4]],self.typeCode) ceil(matrix,3) - N.testing.assert_array_equal(matrix, N.array([[1,2],[3,3]])) + np.testing.assert_array_equal(matrix, np.array([[1,2],[3,3]])) # Test (int DIM1, int DIM2, type* INPLACE_ARRAY2) typemap def testCeilWrongDim(self): "Test ceil function with wrong dimensions" print >>sys.stderr, self.typeStr, "... ", ceil = Matrix.__dict__[self.typeStr + "Ceil"] - matrix = N.array([1,2,3,4],self.typeCode) + matrix = np.array([1,2,3,4],self.typeCode) self.assertRaises(TypeError, ceil, matrix) # Test (int DIM1, int DIM2, type* INPLACE_ARRAY2) typemap @@ -222,7 +222,7 @@ "Test ceil function with wrong dimensions" print >>sys.stderr, self.typeStr, "... ", ceil = Matrix.__dict__[self.typeStr + "Ceil"] - matrix = N.array([[1,2], [3,4]],'c') + matrix = np.array([[1,2], [3,4]],'c') self.assertRaises(TypeError, ceil, matrix) # Test (int DIM1, int DIM2, type* INPLACE_ARRAY2) typemap @@ -359,7 +359,7 @@ # Execute the test suite print "Testing 2D Functions of Module Matrix" - print "NumPy version", N.__version__ + print "NumPy version", np.__version__ print result = unittest.TextTestRunner(verbosity=2).run(suite) sys.exit(len(result.errors) + len(result.failures)) Modified: branches/maskedarray/numpy/doc/swig/test/testTensor.py =================================================================== --- branches/maskedarray/numpy/doc/swig/test/testTensor.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/doc/swig/test/testTensor.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -8,8 +8,8 @@ import unittest # Import NumPy -import numpy as N -major, minor = [ int(d) for d in N.__version__.split(".")[:2] ] +import numpy as np +major, minor = [ int(d) for d in np.__version__.split(".")[:2] ] if major == 0: BadListError = TypeError else: BadListError = ValueError @@ -144,7 +144,7 @@ "Test scale function" print >>sys.stderr, self.typeStr, "... ", scale = Tensor.__dict__[self.typeStr + "Scale"] - tensor = N.array([[[1,0,1], [0,1,0], [1,0,1]], + tensor = np.array([[[1,0,1], [0,1,0], [1,0,1]], [[0,1,0], [1,0,1], [0,1,0]], [[1,0,1], [0,1,0], [1,0,1]]],self.typeCode) scale(tensor,4) @@ -157,7 +157,7 @@ "Test scale function with wrong type" print >>sys.stderr, self.typeStr, "... ", scale = Tensor.__dict__[self.typeStr + "Scale"] - tensor = N.array([[[1,0,1], [0,1,0], [1,0,1]], + tensor = np.array([[[1,0,1], [0,1,0], [1,0,1]], [[0,1,0], [1,0,1], [0,1,0]], [[1,0,1], [0,1,0], [1,0,1]]],'c') self.assertRaises(TypeError, scale, tensor) @@ -167,7 +167,7 @@ "Test scale function with wrong dimensions" print >>sys.stderr, self.typeStr, "... ", scale = Tensor.__dict__[self.typeStr + "Scale"] - tensor = N.array([[1,0,1], [0,1,0], [1,0,1], + tensor = np.array([[1,0,1], [0,1,0], [1,0,1], [0,1,0], [1,0,1], [0,1,0]],self.typeCode) self.assertRaises(TypeError, scale, tensor) @@ -176,7 +176,7 @@ "Test scale function with wrong size" print >>sys.stderr, self.typeStr, "... ", scale = Tensor.__dict__[self.typeStr + "Scale"] - tensor = N.array([[[1,0], [0,1], [1,0]], + tensor = np.array([[[1,0], [0,1], [1,0]], [[0,1], [1,0], [0,1]], [[1,0], [0,1], [1,0]]],self.typeCode) self.assertRaises(TypeError, scale, tensor) @@ -193,10 +193,10 @@ "Test floor function" print >>sys.stderr, self.typeStr, "... ", floor = Tensor.__dict__[self.typeStr + "Floor"] - tensor = N.array([[[1,2], [3,4]], + tensor = np.array([[[1,2], [3,4]], [[5,6], [7,8]]],self.typeCode) floor(tensor,4) - N.testing.assert_array_equal(tensor, N.array([[[4,4], [4,4]], + np.testing.assert_array_equal(tensor, np.array([[[4,4], [4,4]], [[5,6], [7,8]]])) # Test (type* INPLACE_ARRAY3, int DIM1, int DIM2, int DIM3) typemap @@ -204,7 +204,7 @@ "Test floor function with wrong type" print >>sys.stderr, self.typeStr, "... ", floor = Tensor.__dict__[self.typeStr + "Floor"] - tensor = N.array([[[1,2], [3,4]], + tensor = np.array([[[1,2], [3,4]], [[5,6], [7,8]]],'c') self.assertRaises(TypeError, floor, tensor) @@ -213,7 +213,7 @@ "Test floor function with wrong type" print >>sys.stderr, self.typeStr, "... ", floor = Tensor.__dict__[self.typeStr + "Floor"] - tensor = N.array([[1,2], [3,4], [5,6], [7,8]],self.typeCode) + tensor = np.array([[1,2], [3,4], [5,6], [7,8]],self.typeCode) self.assertRaises(TypeError, floor, tensor) # Test (type* INPLACE_ARRAY3, int DIM1, int DIM2, int DIM3) typemap @@ -228,10 +228,10 @@ "Test ceil function" print >>sys.stderr, self.typeStr, "... ", ceil = Tensor.__dict__[self.typeStr + "Ceil"] - tensor = N.array([[[9,8], [7,6]], + tensor = np.array([[[9,8], [7,6]], [[5,4], [3,2]]],self.typeCode) ceil(tensor,5) - N.testing.assert_array_equal(tensor, N.array([[[5,5], [5,5]], + np.testing.assert_array_equal(tensor, np.array([[[5,5], [5,5]], [[5,4], [3,2]]])) # Test (int DIM1, int DIM2, int DIM3, type* INPLACE_ARRAY3) typemap @@ -239,7 +239,7 @@ "Test ceil function with wrong type" print >>sys.stderr, self.typeStr, "... ", ceil = Tensor.__dict__[self.typeStr + "Ceil"] - tensor = N.array([[[9,8], [7,6]], + tensor = np.array([[[9,8], [7,6]], [[5,4], [3,2]]],'c') self.assertRaises(TypeError, ceil, tensor) @@ -248,7 +248,7 @@ "Test ceil function with wrong dimensions" print >>sys.stderr, self.typeStr, "... ", ceil = Tensor.__dict__[self.typeStr + "Ceil"] - tensor = N.array([[9,8], [7,6], [5,4], [3,2]], self.typeCode) + tensor = np.array([[9,8], [7,6], [5,4], [3,2]], self.typeCode) self.assertRaises(TypeError, ceil, tensor) # Test (int DIM1, int DIM2, int DIM3, type* INPLACE_ARRAY3) typemap @@ -399,7 +399,7 @@ # Execute the test suite print "Testing 3D Functions of Module Tensor" - print "NumPy version", N.__version__ + print "NumPy version", np.__version__ print result = unittest.TextTestRunner(verbosity=2).run(suite) sys.exit(len(result.errors) + len(result.failures)) Modified: branches/maskedarray/numpy/doc/swig/test/testVector.py =================================================================== --- branches/maskedarray/numpy/doc/swig/test/testVector.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/doc/swig/test/testVector.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -7,8 +7,8 @@ import unittest # Import NumPy -import numpy as N -major, minor = [ int(d) for d in N.__version__.split(".")[:2] ] +import numpy as np +major, minor = [ int(d) for d in np.__version__.split(".")[:2] ] if major == 0: BadListError = TypeError else: BadListError = ValueError @@ -123,7 +123,7 @@ "Test reverse function" print >>sys.stderr, self.typeStr, "... ", reverse = Vector.__dict__[self.typeStr + "Reverse"] - vector = N.array([1,2,4],self.typeCode) + vector = np.array([1,2,4],self.typeCode) reverse(vector) self.assertEquals((vector == [4,2,1]).all(), True) @@ -132,7 +132,7 @@ "Test reverse function with wrong dimensions" print >>sys.stderr, self.typeStr, "... ", reverse = Vector.__dict__[self.typeStr + "Reverse"] - vector = N.array([[1,2], [3,4]],self.typeCode) + vector = np.array([[1,2], [3,4]],self.typeCode) self.assertRaises(TypeError, reverse, vector) # Test the (type INPLACE_ARRAY1[ANY]) typemap @@ -140,7 +140,7 @@ "Test reverse function with wrong size" print >>sys.stderr, self.typeStr, "... ", reverse = Vector.__dict__[self.typeStr + "Reverse"] - vector = N.array([9,8,7,6,5,4],self.typeCode) + vector = np.array([9,8,7,6,5,4],self.typeCode) self.assertRaises(TypeError, reverse, vector) # Test the (type INPLACE_ARRAY1[ANY]) typemap @@ -148,7 +148,7 @@ "Test reverse function with wrong type" print >>sys.stderr, self.typeStr, "... ", reverse = Vector.__dict__[self.typeStr + "Reverse"] - vector = N.array([1,2,4],'c') + vector = np.array([1,2,4],'c') self.assertRaises(TypeError, reverse, vector) # Test the (type INPLACE_ARRAY1[ANY]) typemap @@ -163,16 +163,16 @@ "Test ones function" print >>sys.stderr, self.typeStr, "... ", ones = Vector.__dict__[self.typeStr + "Ones"] - vector = N.zeros(5,self.typeCode) + vector = np.zeros(5,self.typeCode) ones(vector) - N.testing.assert_array_equal(vector, N.array([1,1,1,1,1])) + np.testing.assert_array_equal(vector, np.array([1,1,1,1,1])) # Test the (type* INPLACE_ARRAY1, int DIM1) typemap def testOnesWrongDim(self): "Test ones function with wrong dimensions" print >>sys.stderr, self.typeStr, "... ", ones = Vector.__dict__[self.typeStr + "Ones"] - vector = N.zeros((5,5),self.typeCode) + vector = np.zeros((5,5),self.typeCode) self.assertRaises(TypeError, ones, vector) # Test the (type* INPLACE_ARRAY1, int DIM1) typemap @@ -180,7 +180,7 @@ "Test ones function with wrong type" print >>sys.stderr, self.typeStr, "... ", ones = Vector.__dict__[self.typeStr + "Ones"] - vector = N.zeros((5,5),'c') + vector = np.zeros((5,5),'c') self.assertRaises(TypeError, ones, vector) # Test the (type* INPLACE_ARRAY1, int DIM1) typemap @@ -195,16 +195,16 @@ "Test zeros function" print >>sys.stderr, self.typeStr, "... ", zeros = Vector.__dict__[self.typeStr + "Zeros"] - vector = N.ones(5,self.typeCode) + vector = np.ones(5,self.typeCode) zeros(vector) - N.testing.assert_array_equal(vector, N.array([0,0,0,0,0])) + np.testing.assert_array_equal(vector, np.array([0,0,0,0,0])) # Test the (int DIM1, type* INPLACE_ARRAY1) typemap def testZerosWrongDim(self): "Test zeros function with wrong dimensions" print >>sys.stderr, self.typeStr, "... ", zeros = Vector.__dict__[self.typeStr + "Zeros"] - vector = N.ones((5,5),self.typeCode) + vector = np.ones((5,5),self.typeCode) self.assertRaises(TypeError, zeros, vector) # Test the (int DIM1, type* INPLACE_ARRAY1) typemap @@ -212,7 +212,7 @@ "Test zeros function with wrong type" print >>sys.stderr, self.typeStr, "... ", zeros = Vector.__dict__[self.typeStr + "Zeros"] - vector = N.ones(6,'c') + vector = np.ones(6,'c') self.assertRaises(TypeError, zeros, vector) # Test the (int DIM1, type* INPLACE_ARRAY1) typemap @@ -378,7 +378,7 @@ # Execute the test suite print "Testing 1D Functions of Module Vector" - print "NumPy version", N.__version__ + print "NumPy version", np.__version__ print result = unittest.TextTestRunner(verbosity=2).run(suite) sys.exit(len(result.errors) + len(result.failures)) Modified: branches/maskedarray/numpy/f2py/f90mod_rules.py =================================================================== --- branches/maskedarray/numpy/f2py/f90mod_rules.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/f2py/f90mod_rules.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -17,17 +17,17 @@ f2py_version='See `f2py -v`' +import copy import pprint import sys import time import types -import copy errmess=sys.stderr.write outmess=sys.stdout.write show=pprint.pprint from auxfuncs import * -import numpy as N +import numpy as np import capi_maps import cfuncs import rules @@ -61,7 +61,7 @@ deallocate(d) end if end if - if ((.not.allocated(d)).and.(s(1).ge.1)) then""" % N.intp().itemsize + if ((.not.allocated(d)).and.(s(1).ge.1)) then""" % np.intp().itemsize fgetdims2="""\ end if Modified: branches/maskedarray/numpy/f2py/lib/parser/block_statements.py =================================================================== --- branches/maskedarray/numpy/f2py/lib/parser/block_statements.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/f2py/lib/parser/block_statements.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -417,7 +417,7 @@ match = re.compile(r'end\s*interface\s*\w*\Z', re.I).match blocktype = 'interface' -class Interface(BeginStatement, HasImplicitStmt, HasUseStmt, +class Interface(BeginStatement, HasAttributes, HasImplicitStmt, HasUseStmt, HasModuleProcedures, AccessSpecs ): """ Modified: branches/maskedarray/numpy/fft/tests/test_fftpack.py =================================================================== --- branches/maskedarray/numpy/fft/tests/test_fftpack.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/fft/tests/test_fftpack.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -1,24 +1,24 @@ import sys from numpy.testing import * set_package_path() -import numpy as N +import numpy as np restore_path() def fft1(x): L = len(x) - phase = -2j*N.pi*(N.arange(L)/float(L)) - phase = N.arange(L).reshape(-1,1) * phase - return N.sum(x*N.exp(phase),axis=1) + phase = -2j*np.pi*(np.arange(L)/float(L)) + phase = np.arange(L).reshape(-1,1) * phase + return np.sum(x*np.exp(phase),axis=1) class TestFFTShift(NumpyTestCase): def check_fft_n(self): - self.failUnlessRaises(ValueError,N.fft.fft,[1,2,3],0) + self.failUnlessRaises(ValueError,np.fft.fft,[1,2,3],0) class TestFFT1D(NumpyTestCase): def check_basic(self): - rand = N.random.random + rand = np.random.random x = rand(30) + 1j*rand(30) - assert_array_almost_equal(fft1(x), N.fft.fft(x)) + assert_array_almost_equal(fft1(x), np.fft.fft(x)) if __name__ == "__main__": NumpyTest().run() Modified: branches/maskedarray/numpy/lib/__init__.py =================================================================== --- branches/maskedarray/numpy/lib/__init__.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/lib/__init__.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -15,6 +15,7 @@ #import convertcode from utils import * from arraysetops import * +from io import * import math __all__ = ['emath','math'] @@ -29,6 +30,7 @@ __all__ += getlimits.__all__ __all__ += utils.__all__ __all__ += arraysetops.__all__ +__all__ += io.__all__ def test(level=1, verbosity=1): from numpy.testing import NumpyTest Copied: branches/maskedarray/numpy/lib/_datasource.py (from rev 4729, trunk/numpy/lib/_datasource.py) Modified: branches/maskedarray/numpy/lib/arraysetops.py =================================================================== --- branches/maskedarray/numpy/lib/arraysetops.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/lib/arraysetops.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -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] Copied: branches/maskedarray/numpy/lib/format.py (from rev 4729, trunk/numpy/lib/format.py) Modified: branches/maskedarray/numpy/lib/getlimits.py =================================================================== --- branches/maskedarray/numpy/lib/getlimits.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/lib/getlimits.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -7,7 +7,7 @@ import numpy.core.numeric as numeric import numpy.core.numerictypes as ntypes from numpy.core.numeric import array -import numpy as N +import numpy as np def _frz(a): """fix rank-0 --> rank-1""" @@ -128,7 +128,7 @@ _max_vals = {} def __init__(self, type): - self.dtype = N.dtype(type) + self.dtype = np.dtype(type) self.kind = self.dtype.kind self.bits = self.dtype.itemsize * 8 self.key = "%s%d" % (self.kind, self.bits) Modified: branches/maskedarray/numpy/lib/index_tricks.py =================================================================== --- branches/maskedarray/numpy/lib/index_tricks.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/lib/index_tricks.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -1,5 +1,3 @@ -## Automatically adapted for numpy Sep 19, 2005 by convertcode.py - __all__ = ['unravel_index', 'mgrid', 'ogrid', @@ -48,7 +46,7 @@ # Reverse # [dcb,dc,d,1] dim_prod = _nx.cumprod([1] + list(dims)[:0:-1])[::-1] - # Indeces become [x/dcb % a, x/dc % b, x/d % c, x/1 % d] + # Indices become [x/dcb % a, x/dc % b, x/d % c, x/1 % d] return tuple(x/dim_prod % dims) def ix_(*args): @@ -193,7 +191,7 @@ mgrid = nd_grid(sparse=False) ogrid = nd_grid(sparse=True) -class concatenator(object): +class AxisConcatenator(object): """Translates slice objects to concatenation along an axis. """ def _retval(self, res): @@ -313,26 +311,30 @@ # etc. because otherwise we couldn't get the doc string to come out right # in help(r_) -class r_class(concatenator): +class RClass(AxisConcatenator): """Translates slice objects to concatenation along the first axis. - For example: - >>> r_[array([1,2,3]), 0, 0, array([4,5,6])] - array([1, 2, 3, 0, 0, 4, 5, 6]) + For example: + >>> r_[array([1,2,3]), 0, 0, array([4,5,6])] + array([1, 2, 3, 0, 0, 4, 5, 6]) """ def __init__(self): - concatenator.__init__(self, 0) + AxisConcatenator.__init__(self, 0) -r_ = r_class() +r_ = RClass() -class c_class(concatenator): +class CClass(AxisConcatenator): """Translates slice objects to concatenation along the second axis. + + For example: + >>> c_[array([[1,2,3]]), 0, 0, array([[4,5,6]])] + array([1, 2, 3, 0, 0, 4, 5, 6]) """ def __init__(self): - concatenator.__init__(self, -1, ndmin=2, trans1d=0) + AxisConcatenator.__init__(self, -1, ndmin=2, trans1d=0) -c_ = c_class() +c_ = CClass() class ndenumerate(object): """ @@ -423,7 +425,7 @@ # # -class _index_expression_class(object): +class IndexExpression(object): """ A nicer way to build up index tuples for arrays. @@ -451,7 +453,7 @@ stop = None return self[start:stop:None] -index_exp = _index_expression_class(1) -s_ = _index_expression_class(0) +index_exp = IndexExpression(maketuple=True) +s_ = IndexExpression(maketuple=False) # End contribution from Konrad. Copied: branches/maskedarray/numpy/lib/io.py (from rev 4729, trunk/numpy/lib/io.py) Modified: branches/maskedarray/numpy/lib/scimath.py =================================================================== --- branches/maskedarray/numpy/lib/scimath.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/lib/scimath.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -2,6 +2,17 @@ Wrapper functions to more user-friendly calling of certain math functions whose output data-type is different than the input data-type in certain domains of the input. + +For example, for functions like log() with branch cuts, the versions in this +module provide the mathematically valid answers in the complex plane: + +>>> import math +>>> from numpy.lib import scimath +>>> scimath.log(-math.exp(1)) == (1+1j*math.pi) +True + +Similarly, sqrt(), other base logarithms, power() and trig functions are +correctly handled. See their respective docstrings for specific examples. """ __all__ = ['sqrt', 'log', 'log2', 'logn','log10', 'power', 'arccos', @@ -12,51 +23,266 @@ from numpy.core.numeric import asarray, any from numpy.lib.type_check import isreal +_ln2 = nx.log(2.0) -#__all__.extend([key for key in dir(nx.umath) -# if key[0] != '_' and key not in __all__]) +def _tocomplex(arr): + """Convert its input `arr` to a complex array. -_ln2 = nx.log(2.0) + The input is returned as a complex array of the smallest type that will fit + the original data: types like single, byte, short, etc. become csingle, + while others become cdouble. -def _tocomplex(arr): - if isinstance(arr.dtype, (nt.single, nt.byte, nt.short, nt.ubyte, - nt.ushort)): + A copy of the input is always made. + + Parameters + ---------- + arr : array + + Returns + ------- + array + An array with the same input data as the input but in complex form. + + Examples + -------- + + >>> import numpy as np + + First, consider an input of type short: + + >>> a = np.array([1,2,3],np.short) + + >>> ac = _tocomplex(a); ac + array([ 1.+0.j, 2.+0.j, 3.+0.j], dtype=complex64) + + >>> ac.dtype + dtype('complex64') + + If the input is of type double, the output is correspondingly of the + complex double type as well: + + >>> b = np.array([1,2,3],np.double) + + >>> bc = _tocomplex(b); bc + array([ 1.+0.j, 2.+0.j, 3.+0.j]) + + >>> bc.dtype + dtype('complex128') + + Note that even if the input was complex to begin with, a copy is still + made, since the astype() method always copies: + + >>> c = np.array([1,2,3],np.csingle) + + >>> cc = _tocomplex(c); cc + array([ 1.+0.j, 2.+0.j, 3.+0.j], dtype=complex64) + + >>> c *= 2; c + array([ 2.+0.j, 4.+0.j, 6.+0.j], dtype=complex64) + + >>> cc + array([ 1.+0.j, 2.+0.j, 3.+0.j], dtype=complex64) + """ + if issubclass(arr.dtype.type, (nt.single, nt.byte, nt.short, nt.ubyte, + nt.ushort,nt.csingle)): return arr.astype(nt.csingle) else: return arr.astype(nt.cdouble) def _fix_real_lt_zero(x): + """Convert `x` to complex if it has real, negative components. + + Otherwise, output is just the array version of the input (via asarray). + + Parameters + ---------- + x : array_like + + Returns + ------- + array + + Examples + -------- + >>> _fix_real_lt_zero([1,2]) + array([1, 2]) + + >>> _fix_real_lt_zero([-1,2]) + array([-1.+0.j, 2.+0.j]) + """ x = asarray(x) if any(isreal(x) & (x<0)): x = _tocomplex(x) return x def _fix_int_lt_zero(x): + """Convert `x` to double if it has real, negative components. + + Otherwise, output is just the array version of the input (via asarray). + + Parameters + ---------- + x : array_like + + Returns + ------- + array + + Examples + -------- + >>> _fix_int_lt_zero([1,2]) + array([1, 2]) + + >>> _fix_int_lt_zero([-1,2]) + array([-1., 2.]) + """ x = asarray(x) if any(isreal(x) & (x < 0)): x = x * 1.0 return x def _fix_real_abs_gt_1(x): + """Convert `x` to complex if it has real components x_i with abs(x_i)>1. + + Otherwise, output is just the array version of the input (via asarray). + + Parameters + ---------- + x : array_like + + Returns + ------- + array + + Examples + -------- + >>> _fix_real_abs_gt_1([0,1]) + array([0, 1]) + + >>> _fix_real_abs_gt_1([0,2]) + array([ 0.+0.j, 2.+0.j]) + """ x = asarray(x) if any(isreal(x) & (abs(x)>1)): x = _tocomplex(x) return x def sqrt(x): + """Return the square root of x. + + Parameters + ---------- + x : array_like + + Returns + ------- + array_like output. + + Examples + -------- + + For real, non-negative inputs this works just like numpy.sqrt(): + >>> sqrt(1) + 1.0 + + >>> sqrt([1,4]) + array([ 1., 2.]) + + But it automatically handles negative inputs: + >>> sqrt(-1) + (0.0+1.0j) + + >>> sqrt([-1,4]) + array([ 0.+1.j, 2.+0.j]) + """ x = _fix_real_lt_zero(x) return nx.sqrt(x) def log(x): + """Return the natural logarithm of x. + + If x contains negative inputs, the answer is computed and returned in the + complex domain. + + Parameters + ---------- + x : array_like + + Returns + ------- + array_like + + Examples + -------- + >>> import math + + >>> log(math.exp(1)) + 1.0 + + Negative arguments are correctly handled (recall that for negative + arguments, the identity exp(log(z))==z does not hold anymore): + + >>> log(-math.exp(1)) == (1+1j*math.pi) + True + """ x = _fix_real_lt_zero(x) return nx.log(x) def log10(x): + """Return the base 10 logarithm of x. + + If x contains negative inputs, the answer is computed and returned in the + complex domain. + + Parameters + ---------- + x : array_like + + Returns + ------- + array_like + + Examples + -------- + + (We set the printing precision so the example can be auto-tested) + >>> import numpy as np; np.set_printoptions(precision=4) + + >>> log10([10**1,10**2]) + array([ 1., 2.]) + + + >>> log10([-10**1,-10**2,10**2]) + array([ 1.+1.3644j, 2.+1.3644j, 2.+0.j ]) + """ x = _fix_real_lt_zero(x) return nx.log10(x) def logn(n, x): - """ Take log base n of x. + """Take log base n of x. + + If x contains negative inputs, the answer is computed and returned in the + complex domain. + + Parameters + ---------- + x : array_like + + Returns + ------- + array_like + + Examples + -------- + + (We set the printing precision so the example can be auto-tested) + >>> import numpy as np; np.set_printoptions(precision=4) + + >>> logn(2,[4,8]) + array([ 2., 3.]) + + >>> logn(2,[-4,-8,8]) + array([ 2.+4.5324j, 3.+4.5324j, 3.+0.j ]) """ x = _fix_real_lt_zero(x) n = _fix_real_lt_zero(n) @@ -64,23 +290,149 @@ def log2(x): """ Take log base 2 of x. + + If x contains negative inputs, the answer is computed and returned in the + complex domain. + + Parameters + ---------- + x : array_like + + Returns + ------- + array_like + + Examples + -------- + + (We set the printing precision so the example can be auto-tested) + >>> import numpy as np; np.set_printoptions(precision=4) + + >>> log2([4,8]) + array([ 2., 3.]) + + >>> log2([-4,-8,8]) + array([ 2.+4.5324j, 3.+4.5324j, 3.+0.j ]) """ x = _fix_real_lt_zero(x) return nx.log(x)/_ln2 def power(x, p): + """Return x**p. + + If x contains negative values, it is converted to the complex domain. + + If p contains negative values, it is converted to floating point. + + Parameters + ---------- + x : array_like + p : array_like of integers + + Returns + ------- + array_like + + Examples + -------- + (We set the printing precision so the example can be auto-tested) + >>> import numpy as np; np.set_printoptions(precision=4) + + >>> power([2,4],2) + array([ 4, 16]) + + >>> power([2,4],-2) + array([ 0.25 , 0.0625]) + + >>> power([-2,4],2) + array([ 4.+0.j, 16.+0.j]) + """ x = _fix_real_lt_zero(x) p = _fix_int_lt_zero(p) return nx.power(x, p) def arccos(x): + """Compute the inverse cosine of x. + + For real x with abs(x)<=1, this returns the principal value. + + If abs(x)>1, the complex arccos() is computed. + + Parameters + ---------- + x : array_like + + Returns + ------- + array_like + + Examples + -------- + >>> import numpy as np; np.set_printoptions(precision=4) + + >>> arccos(1) + 0.0 + + >>> arccos([1,2]) + array([ 0.-0.j , 0.+1.317j]) + """ x = _fix_real_abs_gt_1(x) return nx.arccos(x) def arcsin(x): + """Compute the inverse sine of x. + + For real x with abs(x)<=1, this returns the principal value. + + If abs(x)>1, the complex arcsin() is computed. + + Parameters + ---------- + x : array_like + + Returns + ------- + array_like + + Examples + -------- + (We set the printing precision so the example can be auto-tested) + >>> import numpy as np; np.set_printoptions(precision=4) + + >>> arcsin(0) + 0.0 + + >>> arcsin([0,1]) + array([ 0. , 1.5708]) + """ x = _fix_real_abs_gt_1(x) return nx.arcsin(x) def arctanh(x): + """Compute the inverse hyperbolic tangent of x. + + For real x with abs(x)<=1, this returns the principal value. + + If abs(x)>1, the complex arctanh() is computed. + + Parameters + ---------- + x : array_like + + Returns + ------- + array_like + + Examples + -------- + (We set the printing precision so the example can be auto-tested) + >>> import numpy as np; np.set_printoptions(precision=4) + + >>> arctanh(0) + 0.0 + + >>> arctanh([0,2]) + array([ 0.0000+0.j , 0.5493-1.5708j]) + """ x = _fix_real_abs_gt_1(x) return nx.arctanh(x) Modified: branches/maskedarray/numpy/lib/src/_compiled_base.c =================================================================== --- branches/maskedarray/numpy/lib/src/_compiled_base.c 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/lib/src/_compiled_base.c 2008-01-18 23:25:32 UTC (rev 4730) @@ -9,6 +9,9 @@ goto fail;} \ } +#define PYSETERROR(message) \ +{ PyErr_SetString(ErrorObject, message); goto fail; } + static intp incr_slot_ (double x, double *bins, intp lbins) { @@ -526,6 +529,269 @@ return Py_None; } + +static char packbits_doc[] = + "out = numpy.packbits(myarray, axis=None)\n\n" + " myarray : an integer type array whose elements should be packed to bits\n\n" + " This routine packs the elements of a binary-valued dataset into a\n" + " NumPy array of type uint8 ('B') whose bits correspond to\n" + " the logical (0 or nonzero) value of the input elements.\n" + " The dimension over-which bit-packing is done is given by axis.\n" + " The shape of the output has the same number of dimensions as the input\n" + " (unless axis is None, in which case the output is 1-d).\n" + "\n" + " Example:\n" + " >>> a = array([[[1,0,1],\n" + " ... [0,1,0]],\n" + " ... [[1,1,0],\n" + " ... [0,0,1]]])\n" + " >>> b = numpy.packbits(a,axis=-1)\n" + " >>> b\n" + " array([[[160],[64]],[[192],[32]]], dtype=uint8)\n\n" + " Note that 160 = 128 + 32\n" + " 192 = 128 + 64\n"; + +static char unpackbits_doc[] = + "out = numpy.unpackbits(myarray, axis=None)\n\n" + " myarray - array of uint8 type where each element represents a bit-field\n" + " that should be unpacked into a boolean output array\n\n" + " The shape of the output array is either 1-d (if axis is None) or\n" + " the same shape as the input array with unpacking done along the\n" + " axis specified."; + +/* PACKBITS + + This function packs binary (0 or 1) 1-bit per pixel arrays + into contiguous bytes. + +*/ + +static void +_packbits( + void *In, + int element_size, /* in bytes */ + npy_intp in_N, + npy_intp in_stride, + void *Out, + npy_intp out_N, + npy_intp out_stride + ) +{ + char build; + int i, index; + npy_intp out_Nm1; + int maxi, remain, nonzero, j; + char *outptr,*inptr; + + outptr = Out; /* pointer to output buffer */ + inptr = In; /* pointer to input buffer */ + + /* Loop through the elements of In */ + /* Determine whether or not it is nonzero. + Yes: set correspdoning bit (and adjust build value) + No: move on + /* Every 8th value, set the value of build and increment the outptr */ + + remain = in_N % 8; /* uneven bits */ + if (remain == 0) remain = 8; + out_Nm1 = out_N - 1; + for (index = 0; index < out_N; index++) { + build = 0; + maxi = (index != out_Nm1 ? 8 : remain); + for (i = 0; i < maxi ; i++) { + build <<= 1; /* shift bits left one bit */ + nonzero = 0; + for (j = 0; j < element_size; j++) /* determine if this number is non-zero */ + nonzero += (*(inptr++) != 0); + inptr += (in_stride - element_size); /* advance to next input */ + build += (nonzero != 0); /* add to this bit if the input value is non-zero */ + } + if (index == out_Nm1) build <<= (8-remain); + /* printf("Here: %d %d %d %d\n",build,slice,index,maxi); + */ + *outptr = build; + outptr += out_stride; + } + return; +} + + +static void +_unpackbits( + void *In, + int el_size, /* unused */ + npy_intp in_N, + npy_intp in_stride, + void *Out, + npy_intp out_N, + npy_intp out_stride + ) +{ + unsigned char mask; + int i,index; + char *inptr, *outptr; + + /* Loop through the elements of out + */ + outptr = Out; + inptr = In; + for (index = 0; index < in_N; index++) { + mask = 128; + for (i = 0; i < 8 ; i++) { + *outptr = ((mask & (unsigned char)(*inptr)) != 0); + outptr += out_stride; + mask >>= 1; + } + inptr += in_stride; + } + return; +} + +static PyObject * +pack_or_unpack_bits(PyObject *input, int axis, int unpack) +{ + PyArrayObject *inp; + PyObject *new=NULL; + PyObject *out=NULL; + npy_intp outdims[MAX_DIMS]; + int i; + void (*thefunc)(void *, int, npy_intp, npy_intp, void *, npy_intp, npy_intp); + PyArrayIterObject *it, *ot; + + inp = (PyArrayObject *)PyArray_FROM_O(input); + + if (inp == NULL) return NULL; + + if (unpack) { + if (PyArray_TYPE(inp) != NPY_UBYTE) + PYSETERROR("Expecting an input array of unsigned byte data type"); + } + else { + if (!PyArray_ISINTEGER(inp)) + PYSETERROR("Expecting an input array of integer data type"); + } + + new = PyArray_CheckAxis(inp, &axis, 0); + Py_DECREF(inp); + if (new == NULL) return NULL; + + /* Handle zero-dim array separately */ + if (PyArray_SIZE(new) == 0) { + return PyArray_Copy((PyArrayObject *)new); + } + + if (PyArray_NDIM(new) == 0) { + if (unpack) { + /* Handle 0-d array by converting it to a 1-d array */ + PyObject *temp; + PyArray_Dims newdim = {NULL, 1}; + npy_intp shape=1; + newdim.ptr = &shape; + temp = PyArray_Newshape((PyArrayObject *)new, &newdim, NPY_CORDER); + if (temp == NULL) goto fail; + Py_DECREF(new); + new = temp; + } + else { + ubyte *optr, *iptr; + out = PyArray_New(new->ob_type, 0, NULL, NPY_UBYTE, + NULL, NULL, 0, 0, NULL); + if (out == NULL) goto fail; + optr = PyArray_DATA(out); + iptr = PyArray_DATA(new); + *optr = 0; + for (i=0; i 1, 9 -> 2, 16 -> 2, 17 -> 3 etc.. */ + outdims[axis] = ((outdims[axis] - 1) >> 3) + 1; + thefunc = _packbits; + } + + /* Create output array */ + out = PyArray_New(new->ob_type, PyArray_NDIM(new), outdims, PyArray_UBYTE, + NULL, NULL, 0, PyArray_ISFORTRAN(new), NULL); + if (out == NULL) goto fail; + + /* Setup iterators to iterate over all but given axis */ + it = (PyArrayIterObject *)PyArray_IterAllButAxis((PyObject *)new, &axis); + ot = (PyArrayIterObject *)PyArray_IterAllButAxis((PyObject *)out, &axis); + if (it == NULL || ot == NULL) { + Py_XDECREF(it); + Py_XDECREF(ot); + goto fail; + } + + while(PyArray_ITER_NOTDONE(it)) { + thefunc(PyArray_ITER_DATA(it), PyArray_ITEMSIZE(new), + PyArray_DIM(new, axis), PyArray_STRIDE(new, axis), + PyArray_ITER_DATA(ot), PyArray_DIM(out, axis), + PyArray_STRIDE(out, axis)); + PyArray_ITER_NEXT(it); + PyArray_ITER_NEXT(ot); + } + Py_DECREF(it); + Py_DECREF(ot); + + finish: + Py_DECREF(new); + return out; + + fail: + Py_XDECREF(new); + Py_XDECREF(out); + return NULL; +} + + + +static PyObject * +io_pack(PyObject *self, PyObject *args, PyObject *kwds) +{ + PyObject *obj; + int axis=NPY_MAXDIMS; + static char *kwlist[] = {"in", "axis", NULL}; + + if (!PyArg_ParseTupleAndKeywords( args, kwds, "O|O&" , kwlist, + &obj, PyArray_AxisConverter, &axis)) + return NULL; + return pack_or_unpack_bits(obj, axis, 0); +} + +static PyObject * +io_unpack(PyObject *self, PyObject *args, PyObject *kwds) +{ + PyObject *obj; + int axis=NPY_MAXDIMS; + static char *kwlist[] = {"in", "axis", NULL}; + + if (!PyArg_ParseTupleAndKeywords( args, kwds, "O|O&" , kwlist, + &obj, PyArray_AxisConverter, &axis)) + return NULL; + return pack_or_unpack_bits(obj, axis, 1); +} + static struct PyMethodDef methods[] = { {"_insert", (PyCFunction)arr_insert, METH_VARARGS | METH_KEYWORDS, arr_insert__doc__}, @@ -537,6 +803,10 @@ NULL}, {"add_docstring", (PyCFunction)arr_add_docstring, METH_VARARGS, NULL}, + {"packbits", (PyCFunction)io_pack, METH_VARARGS | METH_KEYWORDS, + packbits_doc}, + {"unpackbits", (PyCFunction)io_unpack, METH_VARARGS | METH_KEYWORDS, + unpackbits_doc}, {NULL, NULL} /* sentinel */ }; @@ -578,7 +848,7 @@ PyDict_SetItemString(d, "__version__", s); Py_DECREF(s); - ErrorObject = PyString_FromString("numpy.lib._compiled_base.error"); + ErrorObject = PyString_FromString("numpy.lib.error"); PyDict_SetItemString(d, "error", ErrorObject); Py_DECREF(ErrorObject); Modified: branches/maskedarray/numpy/lib/tests/test_arraysetops.py =================================================================== --- branches/maskedarray/numpy/lib/tests/test_arraysetops.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/lib/tests/test_arraysetops.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -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 Copied: branches/maskedarray/numpy/lib/tests/test_format.py (from rev 4729, trunk/numpy/lib/tests/test_format.py) Modified: branches/maskedarray/numpy/lib/tests/test_getlimits.py =================================================================== --- branches/maskedarray/numpy/lib/tests/test_getlimits.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/lib/tests/test_getlimits.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -2,12 +2,10 @@ """ from numpy.testing import * -set_package_path() import numpy.lib;reload(numpy.lib) from numpy.lib.getlimits import finfo, iinfo from numpy import single,double,longdouble -import numpy as N -restore_path() +import numpy as np ################################################## @@ -39,15 +37,15 @@ def check_basic(self): dts = zip(['i1', 'i2', 'i4', 'i8', 'u1', 'u2', 'u4', 'u8'], - [N.int8, N.int16, N.int32, N.int64, - N.uint8, N.uint16, N.uint32, N.uint64]) + [np.int8, np.int16, np.int32, np.int64, + np.uint8, np.uint16, np.uint32, np.uint64]) for dt1, dt2 in dts: assert_equal(iinfo(dt1).min, iinfo(dt2).min) assert_equal(iinfo(dt1).max, iinfo(dt2).max) self.assertRaises(ValueError, iinfo, 'f4') def check_unsigned_max(self): - types = N.sctypes['uint'] + types = np.sctypes['uint'] for T in types: assert_equal(iinfo(T).max, T(-1)) Modified: branches/maskedarray/numpy/lib/tests/test_polynomial.py =================================================================== --- branches/maskedarray/numpy/lib/tests/test_polynomial.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/lib/tests/test_polynomial.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -74,22 +74,22 @@ """ from numpy.testing import * -import numpy as N +import numpy as np class TestDocs(NumpyTestCase): def check_doctests(self): return self.rundocs() def check_roots(self): - assert_array_equal(N.roots([1,0,0]), [0,0]) + assert_array_equal(np.roots([1,0,0]), [0,0]) def check_str_leading_zeros(self): - p = N.poly1d([4,3,2,1]) + p = np.poly1d([4,3,2,1]) p[3] = 0 assert_equal(str(p), " 2\n" "3 x + 2 x + 1") - p = N.poly1d([1,2]) + p = np.poly1d([1,2]) p[0] = 0 p[1] = 0 assert_equal(str(p), " \n0") Modified: branches/maskedarray/numpy/lib/utils.py =================================================================== --- branches/maskedarray/numpy/lib/utils.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/lib/utils.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -1,3 +1,4 @@ +import compiler import os import sys import inspect @@ -7,9 +8,10 @@ from numpy.core import product, ndarray __all__ = ['issubclass_', 'get_numpy_include', 'issubsctype', - 'issubdtype', 'deprecate', 'get_numarray_include', + 'issubdtype', 'deprecate', 'deprecate_with_doc', + 'get_numarray_include', 'get_include', 'info', 'source', 'who', - 'byte_bounds', 'may_share_memory'] + 'byte_bounds', 'may_share_memory', 'safe_eval'] def issubclass_(arg1, arg2): try: @@ -82,19 +84,39 @@ func.__name__ = name return func -def deprecate(func, oldname, newname): +def deprecate(func, oldname=None, newname=None): + """Deprecate old functions. + Issues a DeprecationWarning, adds warning to oldname's docstring, + rebinds oldname.__name__ and returns new function object. + + Example: + oldfunc = deprecate(newfunc, 'oldfunc', 'newfunc') + + """ + import warnings + if oldname is None: + try: + oldname = func.func_name + except AttributeError: + oldname = func.__name__ + if newname is None: + str1 = "%s is deprecated" % (oldname,) + depdoc = "%s is DEPRECATED!!" % (oldname,) + else: + str1 = "%s is deprecated, use %s" % (oldname, newname), + depdoc = '%s is DEPRECATED!! -- use %s instead' % (oldname, newname,) + def newfunc(*args,**kwds): - warnings.warn("%s is deprecated, use %s" % (oldname, newname), - DeprecationWarning) + warnings.warn(str1, DeprecationWarning) return func(*args, **kwds) + newfunc = _set_function_name(newfunc, oldname) doc = func.__doc__ - depdoc = '%s is DEPRECATED in numpy: use %s instead' % (oldname, newname,) if doc is None: doc = depdoc else: - doc = '\n'.join([depdoc, doc]) + doc = '\n\n'.join([depdoc, doc]) newfunc.__doc__ = doc try: d = func.__dict__ @@ -104,6 +126,24 @@ newfunc.__dict__.update(d) return newfunc +def deprecate_with_doc(somestr): + """Decorator to deprecate functions and provide detailed documentation + with 'somestr' that is added to the functions docstring. + + Example: + depmsg = 'function scipy.foo has been merged into numpy.foobar' + @deprecate_with_doc(depmsg) + def foo(): + pass + + """ + + def _decorator(func): + newfunc = deprecate(func) + newfunc.__doc__ += "\n" + somestr + return newfunc + return _decorator + get_numpy_include = deprecate(get_include, 'get_numpy_include', 'get_include') @@ -430,3 +470,113 @@ print >> output, inspect.getsource(object) except: print >> output, "Not available for this object." + +#----------------------------------------------------------------------------- + +# The following SafeEval class and company are adapted from Michael Spencer's +# ASPN Python Cookbook recipe: +# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469 +# Accordingly it is mostly Copyright 2006 by Michael Spencer. +# The recipe, like most of the other ASPN Python Cookbook recipes was made +# available under the Python license. +# http://www.python.org/license + +# It has been modified to: +# * handle unary -/+ +# * support True/False/None +# * raise SyntaxError instead of a custom exception. + +class SafeEval(object): + + def visit(self, node, **kw): + cls = node.__class__ + meth = getattr(self,'visit'+cls.__name__,self.default) + return meth(node, **kw) + + def default(self, node, **kw): + raise SyntaxError("Unsupported source construct: %s" % node.__class__) + + def visitExpression(self, node, **kw): + for child in node.getChildNodes(): + return self.visit(child, **kw) + + def visitConst(self, node, **kw): + return node.value + + def visitDict(self, node,**kw): + return dict([(self.visit(k),self.visit(v)) for k,v in node.items]) + + def visitTuple(self, node, **kw): + return tuple([self.visit(i) for i in node.nodes]) + + def visitList(self, node, **kw): + return [self.visit(i) for i in node.nodes] + + def visitUnaryAdd(self, node, **kw): + return +self.visit(node.getChildNodes()[0]) + + def visitUnarySub(self, node, **kw): + return -self.visit(node.getChildNodes()[0]) + + def visitName(self, node, **kw): + if node.name == 'False': + return False + elif node.name == 'True': + return True + elif node.name == 'None': + return None + else: + raise SyntaxError("Unknown name: %s" % node.name) + +def safe_eval(source): + """ Evaluate a string containing a Python literal expression without + allowing the execution of arbitrary non-literal code. + + Parameters + ---------- + source : str + + Returns + ------- + obj : object + + Raises + ------ + SyntaxError if the code is invalid Python expression syntax or if it + contains non-literal code. + + Examples + -------- + >>> from numpy.lib.utils import safe_eval + >>> safe_eval('1') + 1 + >>> safe_eval('[1, 2, 3]') + [1, 2, 3] + >>> safe_eval('{"foo": ("bar", 10.0)}') + {'foo': ('bar', 10.0)} + >>> safe_eval('import os') + Traceback (most recent call last): + ... + SyntaxError: invalid syntax + >>> safe_eval('open("/home/user/.ssh/id_dsa").read()') + Traceback (most recent call last): + ... + SyntaxError: Unsupported source construct: compiler.ast.CallFunc + >>> safe_eval('dict') + Traceback (most recent call last): + ... + SyntaxError: Unknown name: dict + """ + walker = SafeEval() + try: + ast = compiler.parse(source, "eval") + except SyntaxError, err: + raise + try: + return walker.visit(ast) + except SyntaxError, err: + raise + +#----------------------------------------------------------------------------- + + Modified: branches/maskedarray/numpy/linalg/info.py =================================================================== --- branches/maskedarray/numpy/linalg/info.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/linalg/info.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -1,25 +1,34 @@ """\ Core Linear Algebra Tools -=========== +------------------------- +Linear algebra basics: - Linear Algebra Basics: +- norm Vector or matrix norm +- inv Inverse of a square matrix +- solve Solve a linear system of equations +- det Determinant of a square matrix +- lstsq Solve linear least-squares problem +- pinv Pseudo-inverse (Moore-Penrose) using lstsq - norm --- Vector or matrix norm - inv --- Inverse of a square matrix - solve --- Solve a linear system of equations - det --- Determinant of a square matrix - lstsq --- Solve linear least-squares problem - pinv --- Pseudo-inverse (Moore-Penrose) using lstsq +Eigenvalues and decompositions: - Eigenvalues and Decompositions: +- eig Eigenvalues and vectors of a square matrix +- eigh Eigenvalues and eigenvectors of a Hermitian matrix +- eigvals Eigenvalues of a square matrix +- eigvalsh Eigenvalues of a Hermitian matrix +- qr QR decomposition of a matrix +- svd Singular value decomposition of a matrix +- cholesky Cholesky decomposition of a matrix - eig --- Eigenvalues and vectors of a square matrix - eigh --- Eigenvalues and eigenvectors of a Hermitian matrix - eigvals --- Eigenvalues of a square matrix - eigvalsh --- Eigenvalues of a Hermitian matrix. - svd --- Singular value decomposition of a matrix - cholesky --- Cholesky decomposition of a matrix +Tensor operations: +- tensorsolve Solve a linear tensor equation +- tensorinv Calculate an inverse of a tensor + +Exceptions: + +- LinAlgError Indicates a failed linear algebra operation + """ depends = ['core'] Modified: branches/maskedarray/numpy/linalg/linalg.py =================================================================== --- branches/maskedarray/numpy/linalg/linalg.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/linalg/linalg.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -1,9 +1,12 @@ """Lite version of scipy.linalg. -This module is a lite version of the linalg.py module in SciPy which contains -high-level Python interface to the LAPACK library. The lite version -only accesses the following LAPACK functions: dgesv, zgesv, dgeev, -zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, dpotrf. +Notes +----- +This module is a lite version of the linalg.py module in SciPy which +contains high-level Python interface to the LAPACK library. The lite +version only accesses the following LAPACK functions: dgesv, zgesv, +dgeev, zgeev, dgesdd, zgesdd, dgelsd, zgelsd, dsyevd, zheevd, dgetrf, +zgetrf, dpotrf, zpotrf, dgeqrf, zgeqrf, zungqr, dorgqr. """ __all__ = ['solve', 'tensorsolve', 'tensorinv', @@ -134,13 +137,39 @@ # Linear equations def tensorsolve(a, b, axes=None): - """Solves the tensor equation a x = b for x - - where it is assumed that all the indices of x are summed over in - the product. - - a can be N-dimensional. x will have the dimensions of A subtracted from - the dimensions of b. + """Solve the tensor equation a x = b for x + + It is assumed that all indices of x are summed over in the product, + together with the rightmost indices of a, similarly as in + tensordot(a, x, axes=len(b.shape)). + + Parameters + ---------- + a : array, shape b.shape+Q + Coefficient tensor. Shape Q of the rightmost indices of a must + be such that a is 'square', ie., prod(Q) == prod(b.shape). + b : array, any shape + Right-hand tensor. + axes : tuple of integers + Axes in a to reorder to the right, before inversion. + If None (default), no reordering is done. + + Returns + ------- + x : array, shape Q + + Examples + -------- + >>> from numpy import * + >>> a = eye(2*3*4) + >>> a.shape = (2*3,4, 2,3,4) + >>> b = random.randn(2*3,4) + >>> x = linalg.tensorsolve(a, b) + >>> x.shape + (2, 3, 4) + >>> allclose(tensordot(a, x, axes=3), b) + True + """ a = asarray(a) b = asarray(b) @@ -165,7 +194,19 @@ return res def solve(a, b): - """Return the solution of a*x = b + """Solve the equation a x = b + + Parameters + ---------- + a : array, shape (M, M) + b : array, shape (M,) + + Returns + ------- + x : array, shape (M,) + + Raises LinAlgError if a is singular or not square + """ one_eq = len(b.shape) == 1 if one_eq: @@ -196,34 +237,48 @@ def tensorinv(a, ind=2): """Find the 'inverse' of a N-d array - ind must be a positive integer specifying - how many indices at the front of the array are involved - in the inverse sum. + The result is an inverse corresponding to the operation + tensordot(a, b, ind), ie., + + x == tensordot(tensordot(tensorinv(a), a, ind), x, ind) + == tensordot(tensordot(a, tensorinv(a), ind), x, ind) + + for all x (up to floating-point accuracy). - the result is ainv with shape a.shape[ind:] + a.shape[:ind] + Parameters + ---------- + a : array + Tensor to 'invert'. Its shape must 'square', ie., + prod(a.shape[:ind]) == prod(a.shape[ind:]) + ind : integer > 0 + How many of the first indices are involved in the inverse sum. - tensordot(ainv, a, ind) is an identity operator + Returns + ------- + b : array, shape a.shape[:ind]+a.shape[ind:] - and so is + Raises LinAlgError if a is singular or not square - tensordot(a, ainv, a.shape-newind) + Examples + -------- + >>> from numpy import * + >>> a = eye(4*6) + >>> a.shape = (4,6,8,3) + >>> ainv = linalg.tensorinv(a, ind=2) + >>> ainv.shape + (8, 3, 4, 6) + >>> b = random.randn(4,6) + >>> allclose(tensordot(ainv, b), linalg.tensorsolve(a, b)) + True - Example: - - a = rand(4,6,8,3) - ainv = tensorinv(a) - # ainv.shape is (8,3,4,6) - # suppose b has shape (4,6) - tensordot(ainv, b) # produces same (8,3)-shaped output as - tensorsolve(a, b) - - a = rand(24,8,3) - ainv = tensorinv(a,1) - # ainv.shape is (8,3,24) - # suppose b has shape (24,) - tensordot(ainv, b, 1) # produces the same (8,3)-shaped output as - tensorsolve(a, b) - + >>> a = eye(4*6) + >>> a.shape = (24,8,3) + >>> ainv = linalg.tensorinv(a, ind=1) + >>> ainv.shape + (8, 3, 24) + >>> b = random.randn(24) + >>> allclose(tensordot(ainv, b, 1), linalg.tensorsolve(a, b)) + True """ a = asarray(a) oldshape = a.shape @@ -242,12 +297,68 @@ # Matrix inversion def inv(a): + """Compute the inverse of a matrix. + + Parameters + ---------- + a : array-like, shape (M, M) + Matrix to be inverted + + Returns + ------- + ainv : array-like, shape (M, M) + Inverse of the matrix a + + Raises LinAlgError if a is singular or not square + + Examples + -------- + >>> from numpy import array, inv, dot + >>> a = array([[1., 2.], [3., 4.]]) + >>> inv(a) + array([[-2. , 1. ], + [ 1.5, -0.5]]) + >>> dot(a, inv(a)) + array([[ 1., 0.], + [ 0., 1.]]) + + """ a, wrap = _makearray(a) return wrap(solve(a, identity(a.shape[0], dtype=a.dtype))) # Cholesky decomposition def cholesky(a): + """Compute the Cholesky decomposition of a matrix. + + Returns the Cholesky decomposition, :lm:`A = L L^*` of a Hermitian + positive-definite matrix :lm:`A`. + + Parameters + ---------- + a : array, shape (M, M) + Matrix to be decomposed + + Returns + ------- + L : array, shape (M, M) + Lower-triangular Cholesky factor of A + + Raises LinAlgError if decomposition fails + + Examples + -------- + >>> from numpy import array, linalg + >>> a = array([[1,-2j],[2j,5]]) + >>> L = linalg.cholesky(a) + >>> L + array([[ 1.+0.j, 0.+0.j], + [ 0.+2.j, 1.+0.j]]) + >>> dot(L, L.T.conj()) + array([[ 1.+0.j, 0.-2.j], + [ 0.+2.j, 5.+0.j]]) + + """ _assertRank2(a) _assertSquareness(a) t, result_t = _commonType(a) @@ -270,12 +381,55 @@ # QR decompostion def qr(a, mode='full'): - """cacluates A=QR, Q orthonormal, R upper triangular + """Compute QR decomposition of a matrix. - mode: 'full' --> (Q,R) - 'r' --> R - 'economic' --> A2 where the diagonal + upper triangle - part of A2 is R. This is faster if you only need R + Calculate the decomposition :lm:`A = Q R` where Q is orthonormal + and R upper triangular. + + Parameters + ---------- + a : array, shape (M, N) + Matrix to be decomposed + mode : {'full', 'r', 'economic'} + Determines what information is to be returned. 'full' is the default. + Economic mode is slightly faster if only R is needed. + + Returns + ------- + mode = 'full' + Q : double or complex array, shape (M, K) + R : double or complex array, shape (K, N) + Size K = min(M, N) + + mode = 'r' + R : double or complex array, shape (K, N) + + mode = 'economic' + A2 : double or complex array, shape (M, N) + The diagonal and the upper triangle of A2 contains R, + while the rest of the matrix is undefined. + + Raises LinAlgError if decomposition fails + + Notes + ----- + This is an interface to the LAPACK routines dgeqrf, zgeqrf, + dorgqr, and zungqr. + + Examples + -------- + >>> from numpy import * + >>> a = random.randn(9, 6) + >>> q, r = linalg.qr(a) + >>> allclose(a, dot(q, r)) + True + >>> r2 = linalg.qr(a, mode='r') + >>> r3 = linalg.qr(a, mode='economic') + >>> allclose(r, r2) + True + >>> allclose(r, triu(r3[:6,:6], k=0)) + True + """ _assertRank2(a) m, n = a.shape @@ -352,38 +506,40 @@ def eigvals(a): - """Compute the eigenvalues of the general 2-d array a. + """Compute the eigenvalues of a general matrix. + + Parameters + ---------- + a : array, shape (M, M) + A complex or real matrix whose eigenvalues and eigenvectors + will be computed. - A simple interface to the LAPACK routines dgeev and zgeev that sets the - flags to return only the eigenvalues of general real and complex arrays - respectively. + Returns + ------- + w : double or complex array, shape (M,) + The eigenvalues, each repeated according to its multiplicity. + They are not necessarily ordered, nor are they necessarily + real for real matrices. + + Raises LinAlgError if eigenvalue computation does not converge - :Parameters: + See Also + -------- + eig : eigenvalues and right eigenvectors of general arrays + eigvalsh : eigenvalues of symmetric or Hemitiean arrays. + eigh : eigenvalues and eigenvectors of symmetric/Hermitean arrays. - a : 2-d array - A complex or real 2-d array whose eigenvalues and eigenvectors - will be computed. + Notes + ----- + This is a simple interface to the LAPACK routines dgeev and zgeev + that sets the flags to return only the eigenvalues of general real + and complex arrays respectively. + + The number w is an eigenvalue of a if there exists a vector v + satisfying the equation dot(a,v) = w*v. Alternately, if w is a root of + the characteristic equation det(a - w[i]*I) = 0, where det is the + determinant and I is the identity matrix. - :Returns: - - w : 1-d double or complex array - The eigenvalues. The eigenvalues are not necessarily ordered, nor - are they necessarily real for real matrices. - - :SeeAlso: - - - eig : eigenvalues and right eigenvectors of general arrays - - eigvalsh : eigenvalues of symmetric or Hemitiean arrays. - - eigh : eigenvalues and eigenvectors of symmetric/Hermitean arrays. - - :Notes: - ------- - - The number w is an eigenvalue of a if there exists a vector v - satisfying the equation dot(a,v) = w*v. Alternately, if w is a root of - the characteristic equation det(a - w[i]*I) = 0, where det is the - determinant and I is the identity matrix. - """ _assertRank2(a) _assertSquareness(a) @@ -429,43 +585,43 @@ def eigvalsh(a, UPLO='L'): - """Compute the eigenvalues of the symmetric or Hermitean 2-d array a. + """Compute the eigenvalues of a Hermitean or real symmetric matrix. + + Parameters + ---------- + a : array, shape (M, M) + A complex or real matrix whose eigenvalues and eigenvectors + will be computed. + UPLO : {'L', 'U'} + Specifies whether the pertinent array data is taken from the upper + or lower triangular part of a. Possible values are 'L', and 'U' for + upper and lower respectively. Default is 'L'. + + Returns + ------- + w : double array, shape (M,) + The eigenvalues, each repeated according to its multiplicity. + They are not necessarily ordered. - A simple interface to the LAPACK routines dsyevd and zheevd that sets the - flags to return only the eigenvalues of real symmetric and complex - Hermetian arrays respectively. + Raises LinAlgError if eigenvalue computation does not converge - :Parameters: + See Also + -------- + eigh : eigenvalues and eigenvectors of symmetric/Hermitean arrays. + eigvals : eigenvalues of general real or complex arrays. + eig : eigenvalues and eigenvectors of general real or complex arrays. - a : 2-d array - A complex or real 2-d array whose eigenvalues and eigenvectors - will be computed. + Notes + ----- + This is a simple interface to the LAPACK routines dsyevd and + zheevd that sets the flags to return only the eigenvalues of real + symmetric and complex Hermetian arrays respectively. + + The number w is an eigenvalue of a if there exists a vector v + satisfying the equation dot(a,v) = w*v. Alternately, if w is a root of + the characteristic equation det(a - w[i]*I) = 0, where det is the + determinant and I is the identity matrix. - UPLO : string - Specifies whether the pertinent array date is taken from the upper - or lower triangular part of a. Possible values are 'L', and 'U' for - upper and lower respectively. Default is 'L'. - - :Returns: - - w : 1-d double array - The eigenvalues. The eigenvalues are not necessarily ordered. - - :SeeAlso: - - - eigh : eigenvalues and eigenvectors of symmetric/Hermitean arrays. - - eigvals : eigenvalues of general real or complex arrays. - - eig : eigenvalues and eigenvectors of general real or complex arrays. - - :Notes: - ------- - - The number w is an eigenvalue of a if there exists a vector v - satisfying the equation dot(a,v) = w*v. Alternately, if w is a root of - the characteristic equation det(a - w[i]*I) = 0, where det is the - determinant and I is the identity matrix. The eigenvalues of real - symmetric or complex Hermitean matrices are always real. - """ _assertRank2(a) _assertSquareness(a) @@ -515,52 +671,53 @@ def eig(a): - """Eigenvalues and right eigenvectors of a general matrix. + """Compute eigenvalues and right eigenvectors of a general matrix. - A simple interface to the LAPACK routines dgeev and zgeev that compute the - eigenvalues and eigenvectors of general real and complex arrays - respectively. + Parameters + ---------- + a : array, shape (M, M) + A complex or real 2-d array whose eigenvalues and eigenvectors + will be computed. - :Parameters: + Returns + ------- + w : double or complex array, shape (M,) + The eigenvalues, each repeated according to its multiplicity. + The eigenvalues are not necessarily ordered, nor are they + necessarily real for real matrices. + v : double or complex array, shape (M, M) + The normalized eigenvector corresponding to the eigenvalue w[i] is + the column v[:,i]. - a : 2-d array - A complex or real 2-d array whose eigenvalues and eigenvectors - will be computed. + Raises LinAlgError if eigenvalue computation does not converge - :Returns: + See Also + -------- + eigvalsh : eigenvalues of symmetric or Hemitiean arrays. + eig : eigenvalues and right eigenvectors for non-symmetric arrays + eigvals : eigenvalues of non-symmetric array. - w : 1-d double or complex array - The eigenvalues. The eigenvalues are not necessarily ordered, nor - are they necessarily real for real matrices. + Notes + ----- + This is a simple interface to the LAPACK routines dgeev and zgeev + that compute the eigenvalues and eigenvectors of general real and + complex arrays respectively. - v : 2-d double or complex double array. - The normalized eigenvector corresponding to the eigenvalue w[i] is - the column v[:,i]. + The number w is an eigenvalue of a if there exists a vector v + satisfying the equation dot(a,v) = w*v. Alternately, if w is a root of + the characteristic equation det(a - w[i]*I) = 0, where det is the + determinant and I is the identity matrix. The arrays a, w, and v + satisfy the equation dot(a,v[i]) = w[i]*v[:,i]. - :SeeAlso: - - - eigvalsh : eigenvalues of symmetric or Hemitiean arrays. - - eig : eigenvalues and right eigenvectors for non-symmetric arrays - - eigvals : eigenvalues of non-symmetric array. - - :Notes: - ------- - - The number w is an eigenvalue of a if there exists a vector v - satisfying the equation dot(a,v) = w*v. Alternately, if w is a root of - the characteristic equation det(a - w[i]*I) = 0, where det is the - determinant and I is the identity matrix. The arrays a, w, and v - satisfy the equation dot(a,v[i]) = w[i]*v[:,i]. - - The array v of eigenvectors may not be of maximum rank, that is, some - of the columns may be dependent, although roundoff error may obscure - that fact. If the eigenvalues are all different, then theoretically the - eigenvectors are independent. Likewise, the matrix of eigenvectors is - unitary if the matrix a is normal, i.e., if dot(a, a.H) = dot(a.H, a). - - The left and right eigenvectors are not necessarily the (Hemitian) - transposes of each other. - + The array v of eigenvectors may not be of maximum rank, that is, some + of the columns may be dependent, although roundoff error may obscure + that fact. If the eigenvalues are all different, then theoretically the + eigenvectors are independent. Likewise, the matrix of eigenvectors is + unitary if the matrix a is normal, i.e., if dot(a, a.H) = dot(a.H, a). + + The left and right eigenvectors are not necessarily the (Hermitian) + transposes of each other. + """ a, wrap = _makearray(a) _assertRank2(a) @@ -617,49 +774,47 @@ def eigh(a, UPLO='L'): - """Compute eigenvalues for a Hermitian-symmetric matrix. + """Compute eigenvalues for a Hermitian or real symmetric matrix. + + Parameters + ---------- + a : array, shape (M, M) + A complex Hermitian or symmetric real matrix whose eigenvalues + and eigenvectors will be computed. + UPLO : {'L', 'U'} + Specifies whether the pertinent array date is taken from the upper + or lower triangular part of a. Possible values are 'L', and 'U'. + Default is 'L'. + + Returns + ------- + w : double array, shape (M,) + The eigenvalues. The eigenvalues are not necessarily ordered. + v : double or complex double array, shape (M, M) + The normalized eigenvector corresponding to the eigenvalue w[i] is + the column v[:,i]. + + Raises LinAlgError if eigenvalue computation does not converge + See Also + -------- + eigvalsh : eigenvalues of symmetric or Hemitiean arrays. + eig : eigenvalues and right eigenvectors for non-symmetric arrays + eigvals : eigenvalues of non-symmetric array. + + Notes + ----- A simple interface to the LAPACK routines dsyevd and zheevd that compute the eigenvalues and eigenvectors of real symmetric and complex Hermitian arrays respectively. - - :Parameters: - - a : 2-d array - A complex Hermitian or symmetric real 2-d array whose eigenvalues - and eigenvectors will be computed. - - UPLO : string - Specifies whether the pertinent array date is taken from the upper - or lower triangular part of a. Possible values are 'L', and 'U'. - Default is 'L'. - - :Returns: - - w : 1-d double array - The eigenvalues. The eigenvalues are not necessarily ordered. - - v : 2-d double or complex double array, depending on input array type - The normalized eigenvector corresponding to the eigenvalue w[i] is - the column v[:,i]. - - :SeeAlso: - - - eigvalsh : eigenvalues of symmetric or Hemitiean arrays. - - eig : eigenvalues and right eigenvectors for non-symmetric arrays - - eigvals : eigenvalues of non-symmetric array. - - :Notes: - ------- - - The number w is an eigenvalue of a if there exists a vector v - satisfying the equation dot(a,v) = w*v. Alternately, if w is a root of - the characteristic equation det(a - w[i]*I) = 0, where det is the - determinant and I is the identity matrix. The eigenvalues of real - symmetric or complex Hermitean matrices are always real. The array v - of eigenvectors is unitary and a, w, and v satisfy the equation - dot(a,v[i]) = w[i]*v[:,i]. - + + The number w is an eigenvalue of a if there exists a vector v + satisfying the equation dot(a,v) = w*v. Alternately, if w is a root of + the characteristic equation det(a - w[i]*I) = 0, where det is the + determinant and I is the identity matrix. The eigenvalues of real + symmetric or complex Hermitean matrices are always real. The array v + of eigenvectors is unitary and a, w, and v satisfy the equation + dot(a,v[i]) = w[i]*v[:,i]. """ a, wrap = _makearray(a) _assertRank2(a) @@ -707,19 +862,50 @@ def svd(a, full_matrices=1, compute_uv=1): """Singular Value Decomposition. - u,s,vh = svd(a) + Factorizes the matrix a into two unitary matrices U and Vh and + an 1d-array s of singular values (real, non-negative) such that + a == U S Vh if S is an suitably shaped matrix of zeros whose + main diagonal is s. + + Parameters + ---------- + a : array, shape (M, N) + Matrix to decompose + full_matrices : boolean + If true, U, Vh are shaped (M,M), (N,N) + If false, the shapes are (M,K), (K,N) where K = min(M,N) + compute_uv : boolean + Whether to compute also U, Vh in addition to s + + Returns + ------- + U: array, shape (M,M) or (M,K) depending on full_matrices + s: array, shape (K,) + The singular values, sorted so that s[i] >= s[i+1] + K = min(M, N) + Vh: array, shape (N,N) or (K,N) depending on full_matrices + + For compute_uv = False, only s is returned. - If a is an M x N array, then the svd produces a factoring of the array - into two unitary (orthogonal) 2-d arrays u (MxM) and vh (NxN) and a - min(M,N)-length array of singular values such that + Raises LinAlgError if SVD computation does not converge - a == dot(u,dot(S,vh)) - - where S is an MxN array of zeros whose main diagonal is s. - - if compute_uv == 0, then return only the singular values - if full_matrices == 0, then only part of either u or vh is - returned so that it is MxN + Examples + -------- + >>> a = random.randn(9, 6) + 1j*random.randn(9, 6) + >>> U, s, Vh = linalg.svd(a) + >>> U.shape, Vh.shape, s.shape + ((9, 9), (6, 6), (6,)) + + >>> U, s, Vh = linalg.svd(a, full_matrices=False) + >>> U.shape, Vh.shape, s.shape + ((9, 6), (6, 6), (6,)) + >>> S = diag(s) + >>> allclose(a, dot(U, dot(S, Vh))) + True + + >>> s2 = linalg.svd(a, compute_uv=False) + >>> allclose(s, s2) + True """ a, wrap = _makearray(a) _assertRank2(a) @@ -782,11 +968,37 @@ # Generalized inverse def pinv(a, rcond=1e-15 ): - """Return the (Moore-Penrose) pseudo-inverse of a 2-d array + """Compute the (Moore-Penrose) pseudo-inverse of a matrix. + + Calculate a generalized inverse of a matrix using its + singular-value decomposition and including all 'large' singular + values. + + Parameters + ---------- + a : array, shape (M, N) + Matrix to be pseudo-inverted + rcond : float + Cutoff for 'small' singular values. + Singular values smaller than rcond*largest_singular_value are + considered zero. + + Returns + ------- + B : array, shape (N, M) + + Raises LinAlgError if SVD computation does not converge - This method computes the generalized inverse using the - singular-value decomposition and all singular values larger than - rcond of the largest. + Examples + -------- + >>> from numpy import * + >>> a = random.randn(9, 6) + >>> B = linalg.pinv(a) + >>> allclose(a, dot(a, dot(B, a))) + True + >>> allclose(B, dot(B, dot(a, B))) + True + """ a, wrap = _makearray(a) _assertNonEmpty(a) @@ -806,7 +1018,21 @@ # Determinant def det(a): - "The determinant of the 2-d array a" + """Compute the determinant of a matrix + + Parameters + ---------- + a : array, shape (M, M) + + Returns + ------- + det : float or complex + Determinant of a + + Notes + ----- + The determinant is computed via LU factorization, LAPACK routine z/dgetrf. + """ a = asarray(a) _assertRank2(a) _assertSquareness(a) @@ -830,18 +1056,34 @@ # Linear Least Squares def lstsq(a, b, rcond=-1): - """returns x,resids,rank,s - where x minimizes 2-norm(|b - Ax|) - resids is the sum square residuals - rank is the rank of A - s is the rank of the singular values of A in descending order - - If b is a matrix then x is also a matrix with corresponding columns. - If the rank of A is less than the number of columns of A or greater than - the number of rows, then residuals will be returned as an empty array - otherwise resids = sum((b-dot(A,x)**2). - Singular values less than s[0]*rcond are treated as zero. -""" + """Compute least-squares solution to equation :m:`a x = b` + + Compute a vector x such that the 2-norm :m:`|b - a x|` is minimised. + + Parameters + ---------- + a : array, shape (M, N) + b : array, shape (M,) or (M, K) + rcond : float + Cutoff for 'small' singular values. + Singular values smaller than rcond*largest_singular_value are + considered zero. + + Raises LinAlgError if computation does not converge + + Returns + ------- + x : array, shape (N,) or (N, K) depending on shape of b + Least-squares solution + residues : array, shape () or (1,) or (K,) + Sums of residues, squared 2-norm for each column in :m:`b - a x` + If rank of matrix a is < N or > M this is an empty array. + If b was 1-d, this is an (1,) shape array, otherwise the shape is (K,) + rank : integer + Rank of matrix a + s : array, shape (min(M,N),) + Singular values of a + """ import math a = asarray(a) b, wrap = _makearray(b) @@ -907,36 +1149,38 @@ return wrap(x), resids, results['rank'], st def norm(x, ord=None): - """ norm(x, ord=None) -> n + """Matrix or vector norm. - Matrix or vector norm. + Parameters + ---------- + x : array, shape (M,) or (M, N) + ord : number, or {None, 1, -1, 2, -2, inf, -inf, 'fro'} + Order of the norm: - Inputs: + ord norm for matrices norm for vectors + ===== ============================ ========================== + None Frobenius norm 2-norm + 'fro' Frobenius norm - + inf max(sum(abs(x), axis=1)) max(abs(x)) + -inf min(sum(abs(x), axis=1)) min(abs(x)) + 1 max(sum(abs(x), axis=0)) as below + -1 min(sum(abs(x), axis=0)) as below + 2 2-norm (largest sing. value) as below + -2 smallest singular value as below + other - sum(abs(x)**ord)**(1./ord) + ===== ============================ ========================== + + Returns + ------- + n : float + Norm of the matrix or vector - x -- a rank-1 (vector) or rank-2 (matrix) array - ord -- the order of the norm. - - Comments: - For arrays of any rank, if ord is None: - calculate the square norm (Euclidean norm for vectors, - Frobenius norm for matrices) - - For vectors ord can be any real number including Inf or -Inf. - ord = Inf, computes the maximum of the magnitudes - ord = -Inf, computes minimum of the magnitudes - ord is finite, computes sum(abs(x)**ord,axis=0)**(1.0/ord) - - For matrices ord can only be one of the following values: - ord = 2 computes the largest singular value - ord = -2 computes the smallest singular value - ord = 1 computes the largest column sum of absolute values - ord = -1 computes the smallest column sum of absolute values - ord = Inf computes the largest row sum of absolute values - ord = -Inf computes the smallest row sum of absolute values - ord = 'fro' computes the frobenius norm sqrt(sum(diag(X.H * X),axis=0)) - - For values ord < 0, the result is, strictly speaking, not a - mathematical 'norm', but it may still be useful for numerical purposes. + Notes + ----- + For values ord < 0, the result is, strictly speaking, not a + mathematical 'norm', but it may still be useful for numerical + purposes. + """ x = asarray(x) nd = len(x.shape) Modified: branches/maskedarray/numpy/matlib.py =================================================================== --- branches/maskedarray/numpy/matlib.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/matlib.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -1,11 +1,11 @@ +import numpy as np from numpy.core.defmatrix import matrix, asmatrix -from numpy import ndarray, array -import numpy as N +# need * as we're copying the numpy namespace from numpy import * -__version__ = N.__version__ +__version__ = np.__version__ -__all__ = N.__all__[:] # copy numpy namespace +__all__ = np.__all__[:] # copy numpy namespace __all__ += ['rand', 'randn', 'repmat'] def empty(shape, dtype=None, order='C'): @@ -36,17 +36,17 @@ return b def eye(n,M=None, k=0, dtype=float): - return asmatrix(N.eye(n,M,k,dtype)) + return asmatrix(np.eye(n,M,k,dtype)) def rand(*args): if isinstance(args[0], tuple): args = args[0] - return asmatrix(N.random.rand(*args)) + return asmatrix(np.random.rand(*args)) def randn(*args): if isinstance(args[0], tuple): args = args[0] - return asmatrix(N.random.randn(*args)) + return asmatrix(np.random.randn(*args)) def repmat(a, m, n): """Repeat a 0-d to 2-d array mxn times Modified: branches/maskedarray/numpy/numarray/functions.py =================================================================== --- branches/maskedarray/numpy/numarray/functions.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/numarray/functions.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -36,8 +36,13 @@ 'togglebyteorder' ] -import copy, copy_reg, types -import os, sys, math, operator +import copy +import copy_reg +import types +import os +import sys +import math +import operator from numpy import dot as matrixmultiply, dot, vdot, ravel, concatenate, all,\ allclose, any, around, argsort, array_equal, array_equiv,\ @@ -45,7 +50,7 @@ diagonal, e, pi, indices, inner as innerproduct, nonzero, \ outer as outerproduct, kron as kroneckerproduct, lexsort, putmask, rank, \ resize, searchsorted, shape, size, sort, swapaxes, trace, transpose -import numpy as N +import numpy as np from numerictypes import typefrom @@ -62,46 +67,46 @@ if dtype is None: if type is None: if use_default or typecode is not None: - dtype = N.dtype(typecode) + dtype = np.dtype(typecode) else: - dtype = N.dtype(type) + dtype = np.dtype(type) if use_default and dtype is None: - dtype = N.dtype('int') + dtype = np.dtype('int') return dtype def fromfunction(shape, dimensions, type=None, typecode=None, dtype=None): dtype = type2dtype(typecode, type, dtype, 1) - return N.fromfunction(shape, dimensions, dtype=dtype) + return np.fromfunction(shape, dimensions, dtype=dtype) def ones(shape, type=None, typecode=None, dtype=None): dtype = type2dtype(typecode, type, dtype, 1) - return N.ones(shape, dtype) + return np.ones(shape, dtype) def zeros(shape, type=None, typecode=None, dtype=None): dtype = type2dtype(typecode, type, dtype, 1) - return N.zeros(shape, dtype) + return np.zeros(shape, dtype) def where(condition, x=None, y=None, out=None): if x is None and y is None: - arr = N.where(condition) + arr = np.where(condition) else: - arr = N.where(condition, x, y) + arr = np.where(condition, x, y) if out is not None: out[...] = arr return out return arr def indices(shape, type=None): - return N.indices(shape, type) + return np.indices(shape, type) def arange(a1, a2=None, stride=1, type=None, shape=None, typecode=None, dtype=None): dtype = type2dtype(typecode, type, dtype, 0) - return N.arange(a1, a2, stride, dtype) + return np.arange(a1, a2, stride, dtype) arrayrange = arange def alltrue(x, axis=0): - return N.alltrue(x, axis) + return np.alltrue(x, axis) def and_(a, b): """Same as a & b @@ -113,7 +118,7 @@ return (a/b,a%b) def around(array, digits=0, output=None): - ret = N.around(array, digits, output) + ret = np.around(array, digits, output) if output is None: return ret return @@ -123,14 +128,14 @@ def choose(selector, population, outarr=None, clipmode=RAISE): - a = N.asarray(selector) + a = np.asarray(selector) ret = a.choose(population, out=outarr, mode=clipmode) if outarr is None: return ret return def compress(condition, a, axis=0): - return N.compress(condition, a, axis) + return np.compress(condition, a, axis) # only returns a view def explicit_type(a): @@ -180,7 +185,7 @@ if -1 not in shape: if sizing != STRICT: raise ValueError("sizing must be STRICT if size complete") - arr = N.empty(shape, dtype) + arr = np.empty(shape, dtype) bytesleft=arr.nbytes bytesread=0 while(bytesleft > _BLOCKSIZE): @@ -208,7 +213,7 @@ ##file whose size may be determined before allocation, should be ##quick -- only one allocation will be needed. - recsize = dtype.itemsize * N.product([i for i in shape if i != -1]) + recsize = dtype.itemsize * np.product([i for i in shape if i != -1]) blocksize = max(_BLOCKSIZE/recsize, 1)*recsize ##try to estimate file size @@ -222,7 +227,7 @@ else: initsize=max(1,(endpos-curpos)/recsize)*recsize - buf = N.newbuffer(initsize) + buf = np.newbuffer(initsize) bytesread=0 while 1: @@ -260,9 +265,9 @@ uidx = shape.index(-1) shape[uidx]=len(buf) / recsize - a = N.ndarray(shape=shape, dtype=type, buffer=buf) + a = np.ndarray(shape=shape, dtype=type, buffer=buf) if a.dtype.char == '?': - N.not_equal(a, 0, a) + np.not_equal(a, 0, a) return a def fromstring(datastring, type=None, shape=None, typecode=None, dtype=None): @@ -270,8 +275,8 @@ if shape is None: count = -1 else: - count = N.product(shape) - res = N.fromstring(datastring, dtype=dtype, count=count) + count = np.product(shape) + res = np.fromstring(datastring, dtype=dtype, count=count) if shape is not None: res.shape = shape return res @@ -280,7 +285,7 @@ # check_overflow is ignored def fromlist(seq, type=None, shape=None, check_overflow=0, typecode=None, dtype=None): dtype = type2dtype(typecode, type, dtype, False) - return N.array(seq, dtype) + return np.array(seq, dtype) def array(sequence=None, typecode=None, copy=1, savespace=0, type=None, shape=None, dtype=None): @@ -290,21 +295,21 @@ return None if dtype is None: dtype = 'l' - return N.empty(shape, dtype) + return np.empty(shape, dtype) if isinstance(sequence, file): return fromfile(sequence, dtype=dtype, shape=shape) if isinstance(sequence, str): return fromstring(sequence, dtype=dtype, shape=shape) if isinstance(sequence, buffer): - arr = N.frombuffer(sequence, dtype=dtype) + arr = np.frombuffer(sequence, dtype=dtype) else: - arr = N.array(sequence, dtype, copy=copy) + arr = np.array(sequence, dtype, copy=copy) if shape is not None: arr.shape = shape return arr def asarray(seq, type=None, typecode=None, dtype=None): - if isinstance(seq, N.ndarray) and type is None and \ + if isinstance(seq, np.ndarray) and type is None and \ typecode is None and dtype is None: return seq return array(seq, type=type, typecode=typecode, copy=0, dtype=dtype) @@ -328,10 +333,10 @@ shape = (shape, ) + args else: shape = tuple(shape) - dummy = N.array(shape) - if not issubclass(dummy.dtype.type, N.integer): + dummy = np.array(shape) + if not issubclass(dummy.dtype.type, np.integer): raise TypeError - if len(dummy) > N.MAXDIMS: + if len(dummy) > np.MAXDIMS: raise TypeError except: raise TypeError("Shape must be a sequence of integers") @@ -340,7 +345,7 @@ def identity(n, type=None, typecode=None, dtype=None): dtype = type2dtype(typecode, type, dtype, True) - return N.identity(n, dtype) + return np.identity(n, dtype) def info(obj, output=sys.stdout, numpy=0): if numpy: @@ -396,7 +401,7 @@ #clipmode is ignored if axis is not 0 and array is not 1d def put(array, indices, values, axis=0, clipmode=RAISE): - if not isinstance(array, N.ndarray): + if not isinstance(array, np.ndarray): raise TypeError("put only works on subclass of ndarray") work = asarray(array) if axis == 0: @@ -404,7 +409,7 @@ work.put(indices, values, clipmode) else: work[indices] = values - elif isinstance(axis, (int, long, N.integer)): + elif isinstance(axis, (int, long, np.integer)): work = work.swapaxes(0, axis) work[indices] = values work = work.swapaxes(0, axis) @@ -418,13 +423,13 @@ work = work.transpose(axis) def repeat(array, repeats, axis=0): - return N.repeat(array, repeats, axis) + return np.repeat(array, repeats, axis) def reshape(array, shape, *args): if len(args) > 0: shape = (shape,) + args - return N.reshape(array, shape) + return np.reshape(array, shape) import warnings as _warnings @@ -434,12 +439,12 @@ return around(*args, **keys) def sometrue(array, axis=0): - return N.sometrue(array, axis) + return np.sometrue(array, axis) #clipmode is ignored if axis is not an integer def take(array, indices, axis=0, outarr=None, clipmode=RAISE): - array = N.asarray(array) - if isinstance(axis, (int, long, N.integer)): + array = np.asarray(array) + if isinstance(axis, (int, long, np.integer)): res = array.take(indices, axis, outarr, clipmode) if outarr is None: return res @@ -457,34 +462,34 @@ return def tensormultiply(a1, a2): - a1, a2 = N.asarray(a1), N.asarray(a2) + a1, a2 = np.asarray(a1), np.asarray(a2) if (a1.shape[-1] != a2.shape[0]): raise ValueError("Unmatched dimensions") shape = a1.shape[:-1] + a2.shape[1:] - return N.reshape(dot(N.reshape(a1, (-1, a1.shape[-1])), - N.reshape(a2, (a2.shape[0],-1))), + return np.reshape(dot(N.reshape(a1, (-1, a1.shape[-1])), + np.reshape(a2, (a2.shape[0],-1))), shape) def cumsum(a1, axis=0, out=None, type=None, dim=0): - return N.asarray(a1).cumsum(axis,dtype=type,out=out) + return np.asarray(a1).cumsum(axis,dtype=type,out=out) def cumproduct(a1, axis=0, out=None, type=None, dim=0): - return N.asarray(a1).cumprod(axis,dtype=type,out=out) + return np.asarray(a1).cumprod(axis,dtype=type,out=out) def argmax(x, axis=-1): - return N.argmax(x, axis) + return np.argmax(x, axis) def argmin(x, axis=-1): - return N.argmin(x, axis) + return np.argmin(x, axis) def newobj(self, type): if type is None: - return N.empty_like(self) + return np.empty_like(self) else: - return N.empty(self.shape, type) + return np.empty(self.shape, type) def togglebyteorder(self): self.dtype=self.dtype.newbyteorder() def average(a, axis=0, weights=None, returned=0): - return N.average(a, axis, weights, returned) + return np.average(a, axis, weights, returned) Modified: branches/maskedarray/numpy/oldnumeric/functions.py =================================================================== --- branches/maskedarray/numpy/oldnumeric/functions.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/oldnumeric/functions.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -1,6 +1,6 @@ # Functions that should behave the same as Numeric and need changing -import numpy as N +import numpy as np import numpy.core.multiarray as mu import numpy.core.numeric as nn from typeconv import convtypecode, convtypecode2 @@ -13,40 +13,40 @@ 'average'] def take(a, indicies, axis=0): - return N.take(a, indicies, axis) + return np.take(a, indicies, axis) def repeat(a, repeats, axis=0): - return N.repeat(a, repeats, axis) + return np.repeat(a, repeats, axis) def sum(x, axis=0): - return N.sum(x, axis) + return np.sum(x, axis) def product(x, axis=0): - return N.product(x, axis) + return np.product(x, axis) def sometrue(x, axis=0): - return N.sometrue(x, axis) + return np.sometrue(x, axis) def alltrue(x, axis=0): - return N.alltrue(x, axis) + return np.alltrue(x, axis) def cumsum(x, axis=0): - return N.cumsum(x, axis) + return np.cumsum(x, axis) def cumproduct(x, axis=0): - return N.cumproduct(x, axis) + return np.cumproduct(x, axis) def argmax(x, axis=-1): - return N.argmax(x, axis) + return np.argmax(x, axis) def argmin(x, axis=-1): - return N.argmin(x, axis) + return np.argmin(x, axis) def compress(condition, m, axis=-1): - return N.compress(condition, m, axis) + return np.compress(condition, m, axis) def fromfunction(args, dimensions): - return N.fromfunction(args, dimensions, dtype=int) + return np.fromfunction(args, dimensions, dtype=int) def ones(shape, typecode='l', savespace=0, dtype=None): """ones(shape, dtype=int) returns an array of the given @@ -87,14 +87,14 @@ return mu.array(a, dtype, copy=0) def nonzero(a): - res = N.nonzero(a) + res = np.nonzero(a) if len(res) == 1: return res[0] else: raise ValueError, "Input argument must be 1d" def reshape(a, shape): - return N.reshape(a, shape) + return np.reshape(a, shape) def arange(start, stop=None, step=1, typecode=None, dtype=None): dtype = convtypecode2(typecode, dtype) @@ -105,20 +105,20 @@ return mu.fromstring(string, dtype, count=count) def ravel(m): - return N.ravel(m) + return np.ravel(m) def trace(a, offset=0, axis1=0, axis2=1): - return N.trace(a, offset=0, axis1=0, axis2=1) + return np.trace(a, offset=0, axis1=0, axis2=1) def indices(dimensions, typecode=None, dtype=None): dtype = convtypecode(typecode, dtype) - return N.indices(dimensions, dtype) + return np.indices(dimensions, dtype) def where(condition, x, y): - return N.where(condition, x, y) + return np.where(condition, x, y) def cross_product(a, b, axis1=-1, axis2=-1): - return N.cross(a, b, axis1, axis2) + return np.cross(a, b, axis1, axis2) def average(a, axis=0, weights=None, returned=False): - return N.average(a, axis, weights, returned) + return np.average(a, axis, weights, returned) Modified: branches/maskedarray/numpy/oldnumeric/typeconv.py =================================================================== --- branches/maskedarray/numpy/oldnumeric/typeconv.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/oldnumeric/typeconv.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -1,21 +1,21 @@ __all__ = ['oldtype2dtype', 'convtypecode', 'convtypecode2', 'oldtypecodes'] -import numpy as N +import numpy as np -oldtype2dtype = {'1': N.dtype(N.byte), - 's': N.dtype(N.short), -# 'i': N.dtype(N.intc), -# 'l': N.dtype(int), -# 'b': N.dtype(N.ubyte), - 'w': N.dtype(N.ushort), - 'u': N.dtype(N.uintc), -# 'f': N.dtype(N.single), -# 'd': N.dtype(float), -# 'F': N.dtype(N.csingle), -# 'D': N.dtype(complex), -# 'O': N.dtype(object), -# 'c': N.dtype('c'), - None:N.dtype(int) +oldtype2dtype = {'1': np.dtype(np.byte), + 's': np.dtype(np.short), +# 'i': np.dtype(np.intc), +# 'l': np.dtype(int), +# 'b': np.dtype(np.ubyte), + 'w': np.dtype(np.ushort), + 'u': np.dtype(np.uintc), +# 'f': np.dtype(np.single), +# 'd': np.dtype(float), +# 'F': np.dtype(np.csingle), +# 'D': np.dtype(complex), +# 'O': np.dtype(object), +# 'c': np.dtype('c'), + None: np.dtype(int) } # converts typecode=None to int @@ -24,7 +24,7 @@ try: return oldtype2dtype[typecode] except: - return N.dtype(typecode) + return np.dtype(typecode) else: return dtype @@ -38,7 +38,7 @@ try: return oldtype2dtype[typecode] except: - return N.dtype(typecode) + return np.dtype(typecode) else: return dtype @@ -50,7 +50,7 @@ class _oldtypecodes(dict): def __getitem__(self, obj): - char = N.dtype(obj).char + char = np.dtype(obj).char try: return _changedtypes[char] except KeyError: Modified: branches/maskedarray/numpy/random/tests/test_random.py =================================================================== --- branches/maskedarray/numpy/random/tests/test_random.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/random/tests/test_random.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -1,6 +1,6 @@ from numpy.testing import * from numpy import random -import numpy as N +import numpy as np class TestMultinomial(NumpyTestCase): def test_basic(self): @@ -12,8 +12,8 @@ def test_int_negative_interval(self): assert -5 <= random.randint(-5,-1) < -1 x = random.randint(-5,-1,5) - assert N.all(-5 <= x) - assert N.all(x < -1) + assert np.all(-5 <= x) + assert np.all(x < -1) if __name__ == "__main__": NumpyTest().run() Modified: branches/maskedarray/numpy/testing/numpytest.py =================================================================== --- branches/maskedarray/numpy/testing/numpytest.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/testing/numpytest.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -4,6 +4,7 @@ import imp import glob import types +import shlex import unittest import traceback import warnings @@ -16,7 +17,6 @@ DEBUG=0 from numpy.testing.utils import jiffies -from numpy.distutils.exec_command import splitcmdline get_frame = sys._getframe class IgnoreException(Exception): @@ -131,7 +131,8 @@ return 0.01*elapsed def __call__(self, result=None): - if result is None: + if result is None or not hasattr(result, 'errors') \ + or not hasattr(result, 'stream'): return unittest.TestCase.__call__(self, result) nof_errors = len(result.errors) @@ -648,7 +649,7 @@ type='string') (options, args) = parser.parse_args() return self.test(options.level,options.verbosity, - sys_argv=splitcmdline(options.sys_argv or ''), + sys_argv=shlex.split(options.sys_argv or ''), testcase_pattern=options.testcase_pattern) def warn(self, message): Modified: branches/maskedarray/numpy/testing/utils.py =================================================================== --- branches/maskedarray/numpy/testing/utils.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/testing/utils.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -11,7 +11,7 @@ __all__ = ['assert_equal', 'assert_almost_equal','assert_approx_equal', 'assert_array_equal', 'assert_array_less', 'assert_string_equal', 'assert_array_almost_equal', 'jiffies', 'memusage', 'rand', - 'runstring'] + 'runstring', 'raises'] def rand(*args): """Returns an array of random numbers with the given shape. @@ -270,3 +270,37 @@ if not diff_list: return msg = 'Differences in strings:\n%s' % (''.join(diff_list)).rstrip() assert actual==desired, msg + +# Ripped from nose.tools +def raises(*exceptions): + """Test must raise one of expected exceptions to pass. + + Example use:: + + @raises(TypeError, ValueError) + def test_raises_type_error(): + raise TypeError("This test passes") + + @raises(Exception): + def test_that_fails_by_passing(): + pass + + If you want to test many assertions about exceptions in a single test, + you may want to use `assert_raises` instead. + """ + valid = ' or '.join([e.__name__ for e in exceptions]) + def decorate(func): + name = func.__name__ + def newfunc(*arg, **kw): + try: + func(*arg, **kw) + except exceptions: + pass + except: + raise + else: + message = "%s() did not raise %s" % (name, valid) + raise AssertionError(message) + newfunc = make_decorator(func)(newfunc) + return newfunc + return decorate Modified: branches/maskedarray/numpy/tests/test_ctypeslib.py =================================================================== --- branches/maskedarray/numpy/tests/test_ctypeslib.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/numpy/tests/test_ctypeslib.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -1,63 +1,61 @@ -from numpy.testing import * -set_package_path() -import numpy as N +import numpy as np from numpy.ctypeslib import ndpointer -restore_path() +from numpy.testing import * class TestNdpointer(NumpyTestCase): def check_dtype(self): - dt = N.intc + dt = np.intc p = ndpointer(dtype=dt) - self.assert_(p.from_param(N.array([1], dt))) + self.assert_(p.from_param(np.array([1], dt))) dt = 'i4') + self.assert_(p.from_param(np.array([1], dt))) + dt = np.dtype('>i4') p = ndpointer(dtype=dt) - p.from_param(N.array([1], dt)) + p.from_param(np.array([1], dt)) self.assertRaises(TypeError, p.from_param, - N.array([1], dt.newbyteorder('swap'))) + np.array([1], dt.newbyteorder('swap'))) dtnames = ['x', 'y'] - dtformats = [N.intc, N.float64] + dtformats = [np.intc, np.float64] dtdescr = {'names' : dtnames, 'formats' : dtformats} - dt = N.dtype(dtdescr) + dt = np.dtype(dtdescr) p = ndpointer(dtype=dt) - self.assert_(p.from_param(N.zeros((10,), dt))) - samedt = N.dtype(dtdescr) + self.assert_(p.from_param(np.zeros((10,), dt))) + samedt = np.dtype(dtdescr) p = ndpointer(dtype=samedt) - self.assert_(p.from_param(N.zeros((10,), dt))) - dt2 = N.dtype(dtdescr, align=True) + self.assert_(p.from_param(np.zeros((10,), dt))) + dt2 = np.dtype(dtdescr, align=True) if dt.itemsize != dt2.itemsize: - self.assertRaises(TypeError, p.from_param, N.zeros((10,), dt2)) + self.assertRaises(TypeError, p.from_param, np.zeros((10,), dt2)) else: - self.assert_(p.from_param(N.zeros((10,), dt2))) + self.assert_(p.from_param(np.zeros((10,), dt2))) def check_ndim(self): p = ndpointer(ndim=0) - self.assert_(p.from_param(N.array(1))) - self.assertRaises(TypeError, p.from_param, N.array([1])) + self.assert_(p.from_param(np.array(1))) + self.assertRaises(TypeError, p.from_param, np.array([1])) p = ndpointer(ndim=1) - self.assertRaises(TypeError, p.from_param, N.array(1)) - self.assert_(p.from_param(N.array([1]))) + self.assertRaises(TypeError, p.from_param, np.array(1)) + self.assert_(p.from_param(np.array([1]))) p = ndpointer(ndim=2) - self.assert_(p.from_param(N.array([[1]]))) + self.assert_(p.from_param(np.array([[1]]))) def check_shape(self): p = ndpointer(shape=(1,2)) - self.assert_(p.from_param(N.array([[1,2]]))) - self.assertRaises(TypeError, p.from_param, N.array([[1],[2]])) + self.assert_(p.from_param(np.array([[1,2]]))) + self.assertRaises(TypeError, p.from_param, np.array([[1],[2]])) p = ndpointer(shape=()) - self.assert_(p.from_param(N.array(1))) + self.assert_(p.from_param(np.array(1))) def check_flags(self): - x = N.array([[1,2,3]], order='F') + x = np.array([[1,2,3]], order='F') p = ndpointer(flags='FORTRAN') self.assert_(p.from_param(x)) p = ndpointer(flags='CONTIGUOUS') self.assertRaises(TypeError, p.from_param, x) p = ndpointer(flags=x.flags.num) self.assert_(p.from_param(x)) - self.assertRaises(TypeError, p.from_param, N.array([[1,2,3]])) + self.assertRaises(TypeError, p.from_param, np.array([[1,2,3]])) if __name__ == "__main__": NumpyTest().run() Modified: branches/maskedarray/setup.py =================================================================== --- branches/maskedarray/setup.py 2008-01-18 10:04:48 UTC (rev 4729) +++ branches/maskedarray/setup.py 2008-01-18 23:25:32 UTC (rev 4730) @@ -15,6 +15,7 @@ DOCLINES = __doc__.split("\n") +import __builtin__ import os import sys @@ -37,6 +38,12 @@ # update it when the contents of directories change. if os.path.exists('MANIFEST'): os.remove('MANIFEST') +# This is a bit hackish: we are setting a global variable so that the main +# numpy __init__ can detect if it is being loaded by the setup routine, to +# avoid attempting to load components that aren't built yet. While ugly, it's +# a lot more robust than what was previously being used. +__builtin__.__NUMPY_SETUP__ = True + def configuration(parent_package='',top_path=None): from numpy.distutils.misc_util import Configuration From numpy-svn at scipy.org Sun Jan 20 15:42:27 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 20 Jan 2008 14:42:27 -0600 (CST) Subject: [Numpy-svn] r4731 - in branches/maskedarray/numpy: core/tests ma Message-ID: <20080120204227.BDCAA39C0A9@new.scipy.org> Author: stefan Date: 2008-01-20 14:42:07 -0600 (Sun, 20 Jan 2008) New Revision: 4731 Modified: branches/maskedarray/numpy/core/tests/test_regression.py branches/maskedarray/numpy/ma/extras.py Log: Fix concatenator usage (patch by Pierre). Change N to np in regression test. Modified: branches/maskedarray/numpy/core/tests/test_regression.py =================================================================== --- branches/maskedarray/numpy/core/tests/test_regression.py 2008-01-18 23:25:32 UTC (rev 4730) +++ branches/maskedarray/numpy/core/tests/test_regression.py 2008-01-20 20:42:07 UTC (rev 4731) @@ -110,7 +110,7 @@ def check_masked_array(self,level=rlevel): """Ticket #61""" - x = N.ma.array(1,mask=[1]) + x = np.ma.array(1,mask=[1]) def check_mem_masked_where(self,level=rlevel): """Ticket #62""" Modified: branches/maskedarray/numpy/ma/extras.py =================================================================== --- branches/maskedarray/numpy/ma/extras.py 2008-01-18 23:25:32 UTC (rev 4730) +++ branches/maskedarray/numpy/ma/extras.py 2008-01-20 20:42:07 UTC (rev 4731) @@ -35,7 +35,7 @@ from numpy.core.numeric import array as nxarray from numpy.core.fromnumeric import asarray as nxasarray -from numpy.lib.index_tricks import concatenator +from numpy.lib.index_tricks import AxisConcatenator import numpy.lib.function_base as function_base #............................................................................... @@ -595,13 +595,13 @@ #---- --- Concatenation helpers --- #####-------------------------------------------------------------------------- -class mconcatenator(concatenator): +class MAxisConcatenator(AxisConcatenator): """Translate slice objects to concatenation along an axis. """ def __init__(self, axis=0): - concatenator.__init__(self, axis, matrix=False) + AxisConcatenator.__init__(self, axis, matrix=False) def __getitem__(self,key): if isinstance(key, str): @@ -654,7 +654,7 @@ res = concatenate(tuple(objs),axis=self.axis) return self._retval(res) -class mr_class(mconcatenator): +class mr_class(MAxisConcatenator): """Translate slice objects to concatenation along the first axis. For example: @@ -663,7 +663,7 @@ """ def __init__(self): - mconcatenator.__init__(self, 0) + MAxisConcatenator.__init__(self, 0) mr_ = mr_class() From numpy-svn at scipy.org Mon Jan 21 00:29:43 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 20 Jan 2008 23:29:43 -0600 (CST) Subject: [Numpy-svn] r4732 - in branches/build_with_scons/numpy/core: . include/numpy Message-ID: <20080121052943.5E11439C1D5@new.scipy.org> Author: cdavid Date: 2008-01-20 23:29:36 -0600 (Sun, 20 Jan 2008) New Revision: 4732 Modified: branches/build_with_scons/numpy/core/SConstruct branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in Log: Fixes for config and numpyconfig header generation: - signal stuff test result was wrongly put in NPY_NOSMP variable in numpyconfig.h header: replaced by correct NPY_NO_SIGNAL - Replace NPY_NO_SIGNAL by a private __NPY_PRIVATE_NO_SIGNAL in config.h, to avoid clash between config.h and numpyconfig.h Modified: branches/build_with_scons/numpy/core/SConstruct =================================================================== --- branches/build_with_scons/numpy/core/SConstruct 2008-01-20 20:42:07 UTC (rev 4731) +++ branches/build_with_scons/numpy/core/SConstruct 2008-01-21 05:29:36 UTC (rev 4732) @@ -57,8 +57,8 @@ # Checking signal stuff #---------------------- if is_npy_no_signal(): - numpyconfig_sym.append(('NPY_NOSMP', '1')) - config.Define('NPY_NOSMP', 1, "define to 1 to disable SMP support ") + numpyconfig_sym.append(('NPY_NO_SIGNAL', '')) + config.Define('__NPY_PRIVATE_NO_SIGNAL', comment = "define to 1 to disable SMP support ") #--------------------- # Checking SMP option Modified: branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in =================================================================== --- branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in 2008-01-20 20:42:07 UTC (rev 4731) +++ branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in 2008-01-21 05:29:36 UTC (rev 4732) @@ -6,6 +6,7 @@ #define NPY_SIZEOF_LONGDOUBLE @SIZEOF_LONG_DOUBLE@ #define NPY_SIZEOF_PY_INTPTR_T @SIZEOF_PY_INTPTR_T@ +#define NPY_NO_SIGNAL @NPY_NO_SIGNAL@ #define NPY_NOSMP @NPY_NOSMP@ /* XXX: this has really nothing to do in a config file... */ From numpy-svn at scipy.org Mon Jan 21 00:35:29 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 20 Jan 2008 23:35:29 -0600 (CST) Subject: [Numpy-svn] r4733 - in branches/build_with_scons/numpy/core: . include/numpy Message-ID: <20080121053529.E272C39C017@new.scipy.org> Author: cdavid Date: 2008-01-20 23:35:20 -0600 (Sun, 20 Jan 2008) New Revision: 4733 Modified: branches/build_with_scons/numpy/core/SConstruct branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in Log: Fixes for config and numpyconfig header generation: - Replace NPY_NOSMP by NPY_NO_SMP in numpyconfig.h, and remove the NPY_NO_SMP define in config.h, because it is not needed. Modified: branches/build_with_scons/numpy/core/SConstruct =================================================================== --- branches/build_with_scons/numpy/core/SConstruct 2008-01-21 05:29:36 UTC (rev 4732) +++ branches/build_with_scons/numpy/core/SConstruct 2008-01-21 05:35:20 UTC (rev 4733) @@ -63,9 +63,11 @@ #--------------------- # Checking SMP option #--------------------- -st = define_no_smp() -numpyconfig_sym.append(('NPY_NOSMP', st)) -config.Define('NPY_NOSMP', st, "define to 1 to disable SMP support ") +if define_no_smp(): + nosmp = 1 +else: + nosmp = 0 +numpyconfig_sym.append(('NPY_NO_SMP', nosmp)) #---------------------- # Checking the mathlib Modified: branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in =================================================================== --- branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in 2008-01-21 05:29:36 UTC (rev 4732) +++ branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in 2008-01-21 05:35:20 UTC (rev 4733) @@ -7,7 +7,7 @@ #define NPY_SIZEOF_PY_INTPTR_T @SIZEOF_PY_INTPTR_T@ #define NPY_NO_SIGNAL @NPY_NO_SIGNAL@ -#define NPY_NOSMP @NPY_NOSMP@ +#define NPY_NO_SMP @NPY_NO_SMP@ /* XXX: this has really nothing to do in a config file... */ #define NPY_MATHLIB @MATHLIB@ From numpy-svn at scipy.org Mon Jan 21 00:53:03 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 20 Jan 2008 23:53:03 -0600 (CST) Subject: [Numpy-svn] r4734 - in branches/build_with_scons/numpy/core: . include/numpy Message-ID: <20080121055303.77D8D39C017@new.scipy.org> Author: cdavid Date: 2008-01-20 23:52:58 -0600 (Sun, 20 Jan 2008) New Revision: 4734 Modified: branches/build_with_scons/numpy/core/SConstruct branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in Log: Fixes for config and numpyconfig header generation: - Replace #ifdef PY_LONG_LONG logic in numpyconfig.h by a declaration check in scons, and uses the result directly in the generated header. Modified: branches/build_with_scons/numpy/core/SConstruct =================================================================== --- branches/build_with_scons/numpy/core/SConstruct 2008-01-21 05:35:20 UTC (rev 4733) +++ branches/build_with_scons/numpy/core/SConstruct 2008-01-21 05:52:58 UTC (rev 4734) @@ -50,9 +50,18 @@ for type in ('short', 'int', 'long', 'float', 'double', 'long double'): check_type(type) -for type in ('Py_intptr_t', 'PY_LONG_LONG'): +for type in ('Py_intptr_t',): check_type(type, include = "#include \n") +# We check declaration AND type because that's how distutils does it. +if config.CheckDeclaration('PY_LONG_LONG', includes = '#include \n'): + st = config.CheckTypeSize('PY_LONG_LONG', includes = '#include \n') + assert not st == 0 + numpyconfig_sym.append(('DEFINE_NPY_SIZEOF_LONGLONG', '#define NPY_SIZEOF_LONGLONG %d' % st)) + numpyconfig_sym.append(('DEFINE_NPY_SIZEOF_PY_LONG_LONG', '#define NPY_SIZEOF_PY_LONG_LONG %d' % st)) +else: + numpyconfig_sym.append(('DEFINE_NPY_SIZEOF_LONGLONG', '')) + numpyconfig_sym.append(('DEFINE_NPY_SIZEOF_PY_LONG_LONG', '')) #---------------------- # Checking signal stuff #---------------------- Modified: branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in =================================================================== --- branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in 2008-01-21 05:35:20 UTC (rev 4733) +++ branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in 2008-01-21 05:52:58 UTC (rev 4734) @@ -13,10 +13,8 @@ #define NPY_MATHLIB @MATHLIB@ /* XXX: this has to be done outside config files !!!! */ -#ifdef PY_LONG_LONG - #define NPY_SIZEOF_LONGLONG @SIZEOF_PY_LONG_LONG@ - #define NPY_SIZEOF_PY_LONG_LONG @SIZEOF_PY_LONG_LONG@ -#endif + at DEFINE_NPY_SIZEOF_LONGLONG@ + at DEFINE_NPY_SIZEOF_PY_LONG_LONG@ #ifndef CHAR_BIT #error Configuration for undefined CHAR_BIT is not supported, contact the maintainter From numpy-svn at scipy.org Mon Jan 21 01:05:29 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 21 Jan 2008 00:05:29 -0600 (CST) Subject: [Numpy-svn] r4735 - in branches/build_with_scons/numpy/core: . include/numpy Message-ID: <20080121060529.AAB1339C19D@new.scipy.org> Author: cdavid Date: 2008-01-21 00:05:24 -0600 (Mon, 21 Jan 2008) New Revision: 4735 Modified: branches/build_with_scons/numpy/core/SConstruct branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in Log: Fixes for config and numpyconfig header generation: - Replace #ifdef CHAR_BIT by a scons declaration check. Modified: branches/build_with_scons/numpy/core/SConstruct =================================================================== --- branches/build_with_scons/numpy/core/SConstruct 2008-01-21 05:52:58 UTC (rev 4734) +++ branches/build_with_scons/numpy/core/SConstruct 2008-01-21 06:05:24 UTC (rev 4735) @@ -62,6 +62,9 @@ else: numpyconfig_sym.append(('DEFINE_NPY_SIZEOF_LONGLONG', '')) numpyconfig_sym.append(('DEFINE_NPY_SIZEOF_PY_LONG_LONG', '')) + +if not config.CheckDeclaration('CHAR_BIT', includes= '#include \n'): + raise RuntimeError("Config wo CHAR_BIT is not supported with scons: please contact the maintainer (cdavid)") #---------------------- # Checking signal stuff #---------------------- Modified: branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in =================================================================== --- branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in 2008-01-21 05:52:58 UTC (rev 4734) +++ branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in 2008-01-21 06:05:24 UTC (rev 4735) @@ -15,8 +15,3 @@ /* XXX: this has to be done outside config files !!!! */ @DEFINE_NPY_SIZEOF_LONGLONG@ @DEFINE_NPY_SIZEOF_PY_LONG_LONG@ - -#ifndef CHAR_BIT - #error Configuration for undefined CHAR_BIT is not supported, contact the maintainter - #define CHAR_BIT @CHAR_BIT@ -#endif From numpy-svn at scipy.org Mon Jan 21 01:07:55 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 21 Jan 2008 00:07:55 -0600 (CST) Subject: [Numpy-svn] r4736 - branches/build_with_scons/numpy/core/include/numpy Message-ID: <20080121060755.6FF3439C592@new.scipy.org> Author: cdavid Date: 2008-01-21 00:07:50 -0600 (Mon, 21 Jan 2008) New Revision: 4736 Modified: branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in Log: Remove unneeded comment in numpyconfig.h template Modified: branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in =================================================================== --- branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in 2008-01-21 06:05:24 UTC (rev 4735) +++ branches/build_with_scons/numpy/core/include/numpy/numpyconfig.h.in 2008-01-21 06:07:50 UTC (rev 4736) @@ -12,6 +12,5 @@ /* XXX: this has really nothing to do in a config file... */ #define NPY_MATHLIB @MATHLIB@ -/* XXX: this has to be done outside config files !!!! */ @DEFINE_NPY_SIZEOF_LONGLONG@ @DEFINE_NPY_SIZEOF_PY_LONG_LONG@ From numpy-svn at scipy.org Mon Jan 21 12:02:19 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 21 Jan 2008 11:02:19 -0600 (CST) Subject: [Numpy-svn] r4737 - branches/build_with_scons/numpy/core Message-ID: <20080121170219.1C14639C0E3@new.scipy.org> Author: cdavid Date: 2008-01-21 11:02:06 -0600 (Mon, 21 Jan 2008) New Revision: 4737 Modified: branches/build_with_scons/numpy/core/SConstruct Log: Fixes for config and numpyconfig header generation: - Replace CheckFunc by CheckDeclaration + CheckFunc for math functions, to stay compatible with numpy.distutils. Modified: branches/build_with_scons/numpy/core/SConstruct =================================================================== --- branches/build_with_scons/numpy/core/SConstruct 2008-01-21 06:07:50 UTC (rev 4736) +++ branches/build_with_scons/numpy/core/SConstruct 2008-01-21 17:02:06 UTC (rev 4737) @@ -65,6 +65,7 @@ if not config.CheckDeclaration('CHAR_BIT', includes= '#include \n'): raise RuntimeError("Config wo CHAR_BIT is not supported with scons: please contact the maintainer (cdavid)") + #---------------------- # Checking signal stuff #---------------------- @@ -106,30 +107,33 @@ # TODO: checklib vs checkfunc ? def check_func(f): - """Check that f is available in mlib, and add the symbol appropriately. + """Check that f is available in mlib, and add the symbol appropriately. """ + st = config.CheckDeclaration(f, language = 'C', includes = "#include ") + if st: + st = config.CheckFunc(f, language = 'C') + if st: + mfuncs_defined[f] = 1 + else: + mfuncs_defined[f] = 0 - f is expected to be a tuble (symbol, cpp define).""" - st = config.CheckFunc(f, language = 'C') - mfuncs_defined[f] = 1 - for f in mfuncs: check_func(f) if mfuncs_defined['expl'] == 1: - config.Define('HAVE_LONGDOUBLE_FUNCS', 1, - 'Define to 1 if long double funcs are available') + config.Define('HAVE_LONGDOUBLE_FUNCS', + comment = 'Define to 1 if long double funcs are available') if mfuncs_defined['expf'] == 1: - config.Define('HAVE_FLOAT_FUNCS', 1, - 'Define to 1 if long double funcs are available') + config.Define('HAVE_FLOAT_FUNCS', + comment = 'Define to 1 if long double funcs are available') if mfuncs_defined['asinh'] == 1: - config.Define('HAVE_INVERSE_HYPERBOLIC', 1, - 'Define to 1 if inverse hyperbolic funcs are available') + config.Define('HAVE_INVERSE_HYPERBOLIC', + comment = 'Define to 1 if inverse hyperbolic funcs are available') if mfuncs_defined['atanhf'] == 1: - config.Define('HAVE_INVERSE_HYPERBOLIC_FLOAT', 1, - 'Define to 1 if inverse hyperbolic float funcs are available') + config.Define('HAVE_INVERSE_HYPERBOLIC_FLOAT', + comment = 'Define to 1 if inverse hyperbolic float funcs are available') if mfuncs_defined['atanhl'] == 1: - config.Define('HAVE_INVERSE_HYPERBOLIC_LONGDOUBLE', 1, - 'Define to 1 if inverse hyperbolic long double funcs are available') + config.Define('HAVE_INVERSE_HYPERBOLIC_LONGDOUBLE', + comment = 'Define to 1 if inverse hyperbolic long double funcs are available') #------------------------------------------------------- # Define the function PyOS_ascii_strod if not available From numpy-svn at scipy.org Tue Jan 22 00:19:45 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 21 Jan 2008 23:19:45 -0600 (CST) Subject: [Numpy-svn] r4738 - trunk/numpy/doc Message-ID: <20080122051945.1333C39C26A@new.scipy.org> Author: jarrod.millman Date: 2008-01-21 23:19:42 -0600 (Mon, 21 Jan 2008) New Revision: 4738 Modified: trunk/numpy/doc/HOWTO_DOCUMENT.txt Log: explanation of current situation Modified: trunk/numpy/doc/HOWTO_DOCUMENT.txt =================================================================== --- trunk/numpy/doc/HOWTO_DOCUMENT.txt 2008-01-21 17:02:06 UTC (rev 4737) +++ trunk/numpy/doc/HOWTO_DOCUMENT.txt 2008-01-22 05:19:42 UTC (rev 4738) @@ -4,6 +4,15 @@ .. Contents:: +.. Attention:: This document is slightly out of date. During the December +2007 sprint, Travis Oliphant made some changes to the NumPy/SciPy docstring +standard. The changes are relatively minor, but it no longer follows the +epydoc/restructured text standards. This means that currently it isn't +possible to render the docstrings as desired. Travis has committed to writing +something to render the docstrings. At that point, we will update this +document to correspond with the new standard. For now, just refer to: +`example.py `__ + Overview -------- In general, we follow the standard Python style conventions as described here: From numpy-svn at scipy.org Tue Jan 22 00:22:03 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 21 Jan 2008 23:22:03 -0600 (CST) Subject: [Numpy-svn] r4739 - trunk/numpy/doc Message-ID: <20080122052203.B37F039C01B@new.scipy.org> Author: jarrod.millman Date: 2008-01-21 23:22:01 -0600 (Mon, 21 Jan 2008) New Revision: 4739 Modified: trunk/numpy/doc/HOWTO_DOCUMENT.txt Log: typo Modified: trunk/numpy/doc/HOWTO_DOCUMENT.txt =================================================================== --- trunk/numpy/doc/HOWTO_DOCUMENT.txt 2008-01-22 05:19:42 UTC (rev 4738) +++ trunk/numpy/doc/HOWTO_DOCUMENT.txt 2008-01-22 05:22:01 UTC (rev 4739) @@ -4,13 +4,8 @@ .. Contents:: -.. Attention:: This document is slightly out of date. During the December -2007 sprint, Travis Oliphant made some changes to the NumPy/SciPy docstring -standard. The changes are relatively minor, but it no longer follows the -epydoc/restructured text standards. This means that currently it isn't -possible to render the docstrings as desired. Travis has committed to writing -something to render the docstrings. At that point, we will update this -document to correspond with the new standard. For now, just refer to: +.. Attention:: This document is slightly out of date. During the December 2007 sprint, Travis Oliphant made some changes to the NumPy/SciPy docstring standard. The changes are relatively minor, but it no longer follows the epydoc/restructured text standards. This means that currently it isn't possible to render the docstrings as desired. Travis has committed to writing something to render the docstrings. At that point, we will update this document to correspond with the new standard. For now, just refer to: + `example.py `__ Overview From numpy-svn at scipy.org Tue Jan 22 01:14:09 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 22 Jan 2008 00:14:09 -0600 (CST) Subject: [Numpy-svn] r4740 - trunk/numpy/doc Message-ID: <20080122061409.6225239C34F@new.scipy.org> Author: jarrod.millman Date: 2008-01-22 00:14:05 -0600 (Tue, 22 Jan 2008) New Revision: 4740 Modified: trunk/numpy/doc/HOWTO_DOCUMENT.txt Log: add more explanation for new standard Modified: trunk/numpy/doc/HOWTO_DOCUMENT.txt =================================================================== --- trunk/numpy/doc/HOWTO_DOCUMENT.txt 2008-01-22 05:22:01 UTC (rev 4739) +++ trunk/numpy/doc/HOWTO_DOCUMENT.txt 2008-01-22 06:14:05 UTC (rev 4740) @@ -4,10 +4,8 @@ .. Contents:: -.. Attention:: This document is slightly out of date. During the December 2007 sprint, Travis Oliphant made some changes to the NumPy/SciPy docstring standard. The changes are relatively minor, but it no longer follows the epydoc/restructured text standards. This means that currently it isn't possible to render the docstrings as desired. Travis has committed to writing something to render the docstrings. At that point, we will update this document to correspond with the new standard. For now, just refer to: +.. Attention:: This document is slightly out of date. During the December 2007 sprint, Travis Oliphant made some changes to the NumPy/SciPy docstring standard. The changes are relatively minor, but the standard no longer follows the epydoc/restructured text standards. The changes brings our docstring standard more in line with the ETS standard; in addition, it also conserves horizontal real-estate and arguably looks better when printed as plain text. Unfortunately, these changes mean that currently it isn't possible to render the docstrings as desired. Travis has committed to writing something to render the docstrings. At that point, we will update this document to correspond with the new standard. For now, just refer to: `example.py `__ -`example.py `__ - Overview -------- In general, we follow the standard Python style conventions as described here: From numpy-svn at scipy.org Tue Jan 22 01:31:05 2008 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 22 Jan 2008 00:31:05 -0600 (CST) Subject: [Numpy-svn] r4741 - in trunk/numpy/doc: . html Message-ID: <20080122063105.4218E39C35C@new.scipy.org> Author: rkern Date: 2008-01-22 00:31:01 -0600 (Tue, 22 Jan 2008) New Revision: 4741 Modified: trunk/numpy/doc/HOWTO_DOCUMENT.txt trunk/numpy/doc/example.py trunk/numpy/doc/html/example-module.html trunk/numpy/doc/html/example-pysrc.html trunk/numpy/doc/html/help.html trunk/numpy/doc/html/identifier-index.html trunk/numpy/doc/html/module-tree.html Log: Set __docformat__ such that epydoc knows it's looking at reST instead of epytext. Modified: trunk/numpy/doc/HOWTO_DOCUMENT.txt =================================================================== --- trunk/numpy/doc/HOWTO_DOCUMENT.txt 2008-01-22 06:14:05 UTC (rev 4740) +++ trunk/numpy/doc/HOWTO_DOCUMENT.txt 2008-01-22 06:31:01 UTC (rev 4741) @@ -160,6 +160,11 @@ cd epydoc/src sudo python setup.py install +Since we use reST-formatted docstrings instead of the epytext markup, you will +need to include the following line near the top of your module:: + + __docformat__ = "restructuredtext en" + The appearance of some elements can be changed in the epydoc.css style sheet. Modified: trunk/numpy/doc/example.py =================================================================== --- trunk/numpy/doc/example.py 2008-01-22 06:14:05 UTC (rev 4740) +++ trunk/numpy/doc/example.py 2008-01-22 06:31:01 UTC (rev 4741) @@ -8,6 +8,9 @@ a line by itself, preferably preceeded by a blank line. """ +# Make sure this line is here such that epydoc 3 can parse the docstrings for +# auto-generated documentation. +__docformat__ = "restructuredtext en" import os # standard library imports first Modified: trunk/numpy/doc/html/example-module.html =================================================================== --- trunk/numpy/doc/html/example-module.html 2008-01-22 06:14:05 UTC (rev 4740) +++ trunk/numpy/doc/html/example-module.html 2008-01-22 06:31:01 UTC (rev 4741) @@ -56,12 +56,12 @@

Module example

source code

This is the docstring for the example.py module. Modules names should - have short, all-lowercase names. The module name may have underscores if - this improves readability.

-

Every module should have a docstring at the very top of the file. The - module's docstring may extend over multiple lines. If your docstring - does extend over multiple lines, the closing three quotation marks must - be on a line by itself, preferably preceeded by a blank line.

+have short, all-lowercase names. The module name may have underscores if +this improves readability.

+

Every module should have a docstring at the very top of the file. The +module's docstring may extend over multiple lines. If your docstring does +extend over multiple lines, the closing three quotation marks must be on +a line by itself, preferably preceeded by a blank line.

@@ -168,61 +168,61 @@ -
-One-line summary or signature.
-
-Several sentences providing an extended description. You can put
-text in mono-spaced type like so: ``var``.
-
-Parameters
-----------
-var1 : array_like
-    Array_like means all those objects -- lists, nested lists, etc. --
-    that can be converted to an array.
-var2 : integer
-    Write out the full type
-long_variable_name : {'hi', 'ho'}, optional
-    Choices in brackets, default first when optional.
-
-Returns
--------
-named : type
-    Explanation
-list
-    Explanation
-of
-    Explanation
-outputs
-    even more explaining
-
-Other Parameters
-----------------
-only_seldom_used_keywords : type
-    Explanation
-common_parametrs_listed_above : type
-    Explanation
-
-See Also
---------    
-otherfunc : relationship (optional)
-newfunc : relationship (optional)
-
-Notes
------
-Notes about the implementation algorithm (if needed).
-
-This can have multiple paragraphs as can all sections.
-
-Examples
---------
-
-examples in doctest format
-
->>> a=[1,2,3]
->>> [x + 3 for x in a]
-[4, 5, 6]
-
-
+

One-line summary or signature.

+

Several sentences providing an extended description. You can put +text in mono-spaced type like so: var.

+
+

Parameters

+
+
var1 : array_like
+
Array_like means all those objects -- lists, nested lists, etc. -- +that can be converted to an array.
+
var2 : integer
+
Write out the full type
+
long_variable_name : {'hi', 'ho'}, optional
+
Choices in brackets, default first when optional.
+
+
+
+

Returns

+
+
named : type
+
Explanation
+
list
+
Explanation
+
of
+
Explanation
+
outputs
+
even more explaining
+
+
+
+

Other Parameters

+
+
only_seldom_used_keywords : type
+
Explanation
+
common_parametrs_listed_above : type
+
Explanation
+
+
+
+

See Also

+

otherfunc : relationship (optional) +newfunc : relationship (optional)

+
+
+

Notes

+

Notes about the implementation algorithm (if needed).

+

This can have multiple paragraphs as can all sections.

+
+
+

Examples

+

examples in doctest format

+
+>>> a=[1,2,3]
+>>> [x + 3 for x in a]
+[4, 5, 6]
+
@@ -242,7 +242,7 @@

Do nothing.

-

I never saw a purple cow.

+

I never saw a purple cow.

@@ -262,7 +262,7 @@

Do nothing.

-

I never hope to see one.

+

I never hope to see one.

@@ -294,7 +294,7 @@
@@ -242,7 +242,7 @@

Do nothing.

-

I never saw a purple cow.

+

I never saw a purple cow.

@@ -262,7 +262,7 @@

Do nothing.

-

I never hope to see one.

+

I never hope to see one.

@@ -294,7 +294,7 @@