From numpy-svn at scipy.org Sun Apr 4 11:34:49 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 4 Apr 2010 10:34:49 -0500 (CDT) Subject: [Numpy-svn] r8314 - in trunk/numpy: core/src core/src/multiarray lib/src numarray Message-ID: <20100404153449.8636B39CAE7@scipy.org> Author: ptvirtan Date: 2010-04-04 10:34:49 -0500 (Sun, 04 Apr 2010) New Revision: 8314 Modified: trunk/numpy/core/src/multiarray/buffer.c trunk/numpy/core/src/multiarray/common.c trunk/numpy/core/src/multiarray/ctors.c trunk/numpy/core/src/multiarray/scalartypes.c.src trunk/numpy/core/src/scalarmathmodule.c.src trunk/numpy/lib/src/_compiled_base.c trunk/numpy/numarray/_capi.c Log: ENH: get rid of #warning directives, either by fixing the issue or changing them to comments Modified: trunk/numpy/core/src/multiarray/buffer.c =================================================================== --- trunk/numpy/core/src/multiarray/buffer.c 2010-03-31 03:45:36 UTC (rev 8313) +++ trunk/numpy/core/src/multiarray/buffer.c 2010-04-04 15:34:49 UTC (rev 8314) @@ -248,7 +248,7 @@ /* Insert field name */ #if defined(NPY_PY3K) -#warning XXX -- should it use UTF-8 here? + /* FIXME: XXX -- should it use UTF-8 here? */ tmp = PyUnicode_AsUTF8String(name); #else tmp = name; Modified: trunk/numpy/core/src/multiarray/common.c =================================================================== --- trunk/numpy/core/src/multiarray/common.c 2010-03-31 03:45:36 UTC (rev 8313) +++ trunk/numpy/core/src/multiarray/common.c 2010-04-04 15:34:49 UTC (rev 8314) @@ -308,7 +308,7 @@ } #if defined(NPY_PY3K) -#warning XXX -- what is the correct thing to do here? + /* FIXME: XXX -- what is the correct thing to do here? */ #else if (PyInstance_Check(op)) { goto deflt; Modified: trunk/numpy/core/src/multiarray/ctors.c =================================================================== --- trunk/numpy/core/src/multiarray/ctors.c 2010-03-31 03:45:36 UTC (rev 8313) +++ trunk/numpy/core/src/multiarray/ctors.c 2010-04-04 15:34:49 UTC (rev 8314) @@ -1096,7 +1096,7 @@ } if(!PySequence_Check(s) || #if defined(NPY_PY3K) -#warning XXX -- what is the correct thing to do here? + /* FIXME: XXX -- what is the correct thing to do here? */ #else PyInstance_Check(s) || #endif Modified: trunk/numpy/core/src/multiarray/scalartypes.c.src =================================================================== --- trunk/numpy/core/src/multiarray/scalartypes.c.src 2010-03-31 03:45:36 UTC (rev 8313) +++ trunk/numpy/core/src/multiarray/scalartypes.c.src 2010-04-04 15:34:49 UTC (rev 8314) @@ -1962,7 +1962,7 @@ Py_ssize_t len; void *buf; -#warning XXX: the format is not implemented! -- this needs more work + /* FIXME: XXX: the format is not implemented! -- this needs more work */ len = gentype_getreadbuf(self, 0, &buf); return PyBuffer_FillInfo(view, self, buf, len, 1, flags); Modified: trunk/numpy/core/src/scalarmathmodule.c.src =================================================================== --- trunk/numpy/core/src/scalarmathmodule.c.src 2010-03-31 03:45:36 UTC (rev 8313) +++ trunk/numpy/core/src/scalarmathmodule.c.src 2010-04-04 15:34:49 UTC (rev 8314) @@ -1306,8 +1306,6 @@ PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare; } else -#else -#warning XXX -- is it important to do something with the integers here? #endif if (obj == (PyObject *)(&PyFloat_Type)) { PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number; @@ -1350,8 +1348,6 @@ PyInt_Type.tp_richcompare = saved_tables[2]; } else -#else -#warning XXX -- is it important to do something with the integers here? #endif if (obj == (PyObject *)(&PyFloat_Type)) { PyFloat_Type.tp_as_number = saved_tables[3]; @@ -1393,8 +1389,6 @@ PyLongArrType_Type.tp_richcompare = saved_tables[2]; } else -#else -#warning XXX -- is it important to do something with the integers here? #endif if (obj == (PyObject *)(&PyFloat_Type)) { PyDoubleArrType_Type.tp_as_number = saved_tables[3]; @@ -1436,8 +1430,6 @@ PyLongArrType_Type.tp_richcompare = saved_tables_arrtype[2]; } else -#else -#warning XXX -- is it important to do something with the integers here? #endif if (obj == (PyObject *)(&PyFloat_Type)) { PyDoubleArrType_Type.tp_as_number = saved_tables_arrtype[3]; @@ -1520,8 +1512,6 @@ saved_tables[0] = PyInt_Type.tp_as_number; saved_tables[1] = PyInt_Type.tp_compare; saved_tables[2] = PyInt_Type.tp_richcompare; -#else -#warning XXX -- is it important to do something with the integers here? #endif saved_tables[3] = PyFloat_Type.tp_as_number; #if !defined(NPY_PY3K) Modified: trunk/numpy/lib/src/_compiled_base.c =================================================================== --- trunk/numpy/lib/src/_compiled_base.c 2010-03-31 03:45:36 UTC (rev 8313) +++ trunk/numpy/lib/src/_compiled_base.c 2010-04-04 15:34:49 UTC (rev 8314) @@ -559,7 +559,7 @@ arr_add_docstring(PyObject *NPY_UNUSED(dummy), PyObject *args) { PyObject *obj; - PyObject *str; + PyObject *str, *tmp; char *docstr; static char *msg = "already has a docstring"; @@ -573,8 +573,8 @@ return NULL; } - docstr = PyUnicode_AS_DATA(str); -#warning XXX -- is this correct at all!? + tmp = PyUnicode_AsUTF8String(str); + docstr = PyBytes_AS_STRING(tmp); #else if (!PyArg_ParseTuple(args, "OO!", &obj, &PyString_Type, &str)) { return NULL; Modified: trunk/numpy/numarray/_capi.c =================================================================== --- trunk/numpy/numarray/_capi.c 2010-03-31 03:45:36 UTC (rev 8313) +++ trunk/numpy/numarray/_capi.c 2010-04-04 15:34:49 UTC (rev 8314) @@ -90,7 +90,7 @@ getWriteBufferDataPtr(PyObject *buffobj, void **buff) { #if defined(NPY_PY3K) -#warning XXX - needs implementation + /* FIXME: XXX - needs implementation */ PyErr_SetString(PyExc_RuntimeError, "XXX: getWriteBufferDataPtr is not implemented"); return -1; @@ -127,7 +127,7 @@ getReadBufferDataPtr(PyObject *buffobj, void **buff) { #if defined(NPY_PY3K) -#warning XXX - needs implementation + /* FIXME: XXX - needs implementation */ PyErr_SetString(PyExc_RuntimeError, "XXX: getWriteBufferDataPtr is not implemented"); return -1; @@ -150,7 +150,7 @@ getBufferSize(PyObject *buffobj) { #if defined(NPY_PY3K) -#warning XXX - needs implementation + /* FIXME: XXX - needs implementation */ PyErr_SetString(PyExc_RuntimeError, "XXX: getWriteBufferDataPtr is not implemented"); return -1; From numpy-svn at scipy.org Sun Apr 4 16:20:40 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 4 Apr 2010 15:20:40 -0500 (CDT) Subject: [Numpy-svn] r8315 - in trunk/numpy/core: . tests Message-ID: <20100404202040.7583639CAE7@scipy.org> Author: ptvirtan Date: 2010-04-04 15:20:40 -0500 (Sun, 04 Apr 2010) New Revision: 8315 Modified: trunk/numpy/core/_internal.py trunk/numpy/core/tests/test_multiarray.py Log: BUG: core: fix bugs in PEP 3118 format string parsing - Handle consecutive characters (eg. 'xxxx') properly - Compute native padding correctly Modified: trunk/numpy/core/_internal.py =================================================================== --- trunk/numpy/core/_internal.py 2010-04-04 15:34:49 UTC (rev 8314) +++ trunk/numpy/core/_internal.py 2010-04-04 20:20:40 UTC (rev 8315) @@ -454,10 +454,10 @@ # Not supported raise ValueError("Non item-size 1 structures not supported") elif spec[0] in type_map_chars: - j = 1 - for j in xrange(1, len(spec)): - if spec[j] not in type_map_chars: - break + if spec[0] == 'Z': + j = 2 + else: + j = 1 typechar = spec[:j] spec = spec[j:] is_padding = (typechar == 'x') @@ -476,8 +476,8 @@ # that the start of the array is *also* aligned. extra_offset = 0 if byteorder == '@': - start_padding = offset % value.alignment - intra_padding = value.itemsize % value.alignment + start_padding = (-offset) % value.alignment + intra_padding = (-value.itemsize) % value.alignment offset += start_padding Modified: trunk/numpy/core/tests/test_multiarray.py =================================================================== --- trunk/numpy/core/tests/test_multiarray.py 2010-04-04 15:34:49 UTC (rev 8314) +++ trunk/numpy/core/tests/test_multiarray.py 2010-04-04 20:20:40 UTC (rev 8315) @@ -1624,5 +1624,10 @@ else: assert_equal(y.format, ' Author: ptvirtan Date: 2010-04-04 15:20:48 -0500 (Sun, 04 Apr 2010) New Revision: 8316 Modified: trunk/numpy/core/_internal.py trunk/numpy/core/tests/test_multiarray.py Log: ENH: core: improve PEP 3118 parser's alignment handling Now, padding will be more forcefully inserted for native-aligned items. Modified: trunk/numpy/core/_internal.py =================================================================== --- trunk/numpy/core/_internal.py 2010-04-04 20:20:40 UTC (rev 8315) +++ trunk/numpy/core/_internal.py 2010-04-04 20:20:48 UTC (rev 8316) @@ -403,9 +403,23 @@ fields = {} offset = 0 - findex = 0 explicit_name = False + this_explicit_name = False + common_alignment = 1 + is_padding = False + last_offset = 0 + dummy_name_index = [0] + def next_dummy_name(): + dummy_name_index[0] += 1 + def get_dummy_name(): + while True: + name = 'f%d' % dummy_name_index[0] + if name not in fields: + return name + next_dummy_name() + + # Parse spec while spec: value = None @@ -448,11 +462,9 @@ is_padding = False if spec[:2] == 'T{': - value, spec = _dtype_from_pep3118(spec[2:], byteorder=byteorder, - is_subdtype=True) - if itemsize != 1: - # Not supported - raise ValueError("Non item-size 1 structures not supported") + value, spec, align = _dtype_from_pep3118(spec[2:], + byteorder=byteorder, + is_subdtype=True) elif spec[0] in type_map_chars: if spec[0] == 'Z': j = 2 @@ -467,6 +479,7 @@ itemsize = 1 numpy_byteorder = {'@': '=', '^': '='}.get(byteorder, byteorder) value = dtype(numpy_byteorder + dtypechar) + align = value.alignment else: raise ValueError("Unknown PEP 3118 data type specifier %r" % spec) @@ -476,8 +489,8 @@ # that the start of the array is *also* aligned. extra_offset = 0 if byteorder == '@': - start_padding = (-offset) % value.alignment - intra_padding = (-value.itemsize) % value.alignment + start_padding = (-offset) % align + intra_padding = (-value.itemsize) % align offset += start_padding @@ -488,6 +501,10 @@ else: extra_offset += intra_padding + # Update common alignment + common_alignment = (align*common_alignment + / _gcd(align, common_alignment)) + # Convert itemsize to sub-array if itemsize != 1: value = dtype((value, (itemsize,))) @@ -505,20 +522,37 @@ explicit_name = True this_explicit_name = True else: - name = 'f%d' % findex - findex += 1 + name = get_dummy_name() if not is_padding or this_explicit_name: + if name in fields: + raise RuntimeError("Duplicate field name '%s' in PEP3118 format" + % name) fields[name] = (value, offset) + if not this_explicit_name: + next_dummy_name() + + last_offset = offset offset += value.itemsize offset += extra_offset + if is_padding and not this_explicit_name: + # Trailing padding must be made explicit + name = get_dummy_name() + fields[name] = ('V%d' % (offset - last_offset), last_offset) + if len(fields.keys()) == 1 and not explicit_name and fields['f0'][1] == 0: ret = fields['f0'][0] else: ret = dtype(fields) if is_subdtype: - return ret, spec + return ret, spec, common_alignment else: return ret + +def _gcd(a, b): + """Calculate the greatest common divisor of a and b""" + while b: + a, b = b, a%b + return a Modified: trunk/numpy/core/tests/test_multiarray.py =================================================================== --- trunk/numpy/core/tests/test_multiarray.py 2010-04-04 20:20:40 UTC (rev 8315) +++ trunk/numpy/core/tests/test_multiarray.py 2010-04-04 20:20:48 UTC (rev 8316) @@ -1456,6 +1456,32 @@ if sys.version_info[:2] == (2, 6): from numpy.core.multiarray import memorysimpleview as memoryview + from numpy.core._internal import _dtype_from_pep3118 + + class TestPEP3118Dtype(object): + def _check(self, spec, wanted): + assert_equal(_dtype_from_pep3118(spec), np.dtype(wanted), + err_msg="spec %r != dtype %r" % (spec, wanted)) + + def test_native_padding(self): + align = np.dtype('i').alignment + for j in xrange(8): + if j == 0: + s = 'bi' + else: + s = 'b%dxi' % j + self._check('@'+s, {'f0': ('i1', 0), + 'f1': ('i', align*(1 + j//align))}) + self._check('='+s, {'f0': ('i1', 0), + 'f1': ('i', 1+j)}) + + def test_native_padding_2(self): + self._check('x3T{xi}', {'f0': (({'f0': ('i', 4)}, (3,)), 4)}) + self._check('=x3T{xi}', {'f0': (({'f0': ('i', 1)}, (3,)), 1)}) + + def test_trailing_padding(self): + self._check('ix', [('f0', 'i'), ('f1', 'V1')]) + class TestNewBufferProtocol(object): def _check_roundtrip(self, obj): obj = np.asarray(obj) From numpy-svn at scipy.org Sun Apr 4 16:20:56 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 4 Apr 2010 15:20:56 -0500 (CDT) Subject: [Numpy-svn] r8317 - in trunk/numpy/core: . tests Message-ID: <20100404202056.1FB6939CAE7@scipy.org> Author: ptvirtan Date: 2010-04-04 15:20:56 -0500 (Sun, 04 Apr 2010) New Revision: 8317 Modified: trunk/numpy/core/_internal.py trunk/numpy/core/tests/test_multiarray.py Log: ENH: core: improve parsing of byte order from PEP 3118 format strings Modified: trunk/numpy/core/_internal.py =================================================================== --- trunk/numpy/core/_internal.py 2010-04-04 20:20:48 UTC (rev 8316) +++ trunk/numpy/core/_internal.py 2010-04-04 20:20:56 UTC (rev 8317) @@ -436,8 +436,10 @@ spec = spec[j+1:] # Byte order - if spec[0] in ('@', '=', '<', '>', '^'): + if spec[0] in ('@', '=', '<', '>', '^', '!'): byteorder = spec[0] + if byteorder == '!': + byteorder = '>' spec = spec[1:] # Byte order characters also control native vs. standard type sizes @@ -462,10 +464,10 @@ is_padding = False if spec[:2] == 'T{': - value, spec, align = _dtype_from_pep3118(spec[2:], - byteorder=byteorder, - is_subdtype=True) + value, spec, align, next_byteorder = _dtype_from_pep3118( + spec[2:], byteorder=byteorder, is_subdtype=True) elif spec[0] in type_map_chars: + next_byteorder = byteorder if spec[0] == 'Z': j = 2 else: @@ -533,6 +535,8 @@ next_dummy_name() last_offset = offset + byteorder = next_byteorder + offset += value.itemsize offset += extra_offset @@ -541,13 +545,14 @@ name = get_dummy_name() fields[name] = ('V%d' % (offset - last_offset), last_offset) - if len(fields.keys()) == 1 and not explicit_name and fields['f0'][1] == 0: + if len(fields.keys()) == 1 and not explicit_name and fields['f0'][1] == 0 \ + and not is_subdtype: ret = fields['f0'][0] else: ret = dtype(fields) if is_subdtype: - return ret, spec, common_alignment + return ret, spec, common_alignment, byteorder else: return ret Modified: trunk/numpy/core/tests/test_multiarray.py =================================================================== --- trunk/numpy/core/tests/test_multiarray.py 2010-04-04 20:20:48 UTC (rev 8316) +++ trunk/numpy/core/tests/test_multiarray.py 2010-04-04 20:20:56 UTC (rev 8317) @@ -1476,12 +1476,20 @@ 'f1': ('i', 1+j)}) def test_native_padding_2(self): + # Native padding should work also for structs and sub-arrays self._check('x3T{xi}', {'f0': (({'f0': ('i', 4)}, (3,)), 4)}) - self._check('=x3T{xi}', {'f0': (({'f0': ('i', 1)}, (3,)), 1)}) + self._check('^x3T{xi}', {'f0': (({'f0': ('i', 1)}, (3,)), 1)}) def test_trailing_padding(self): + # Trailing padding should be included self._check('ix', [('f0', 'i'), ('f1', 'V1')]) + def test_byteorder_inside_struct(self): + # The byte order after @T{=i} should be '=', not '@'. + # Check this by noting the absence of native alignment. + self._check('@T{^i}xi', {'f0': ({'f0': (np.int32, 0)}, 0), + 'f1': (np.int32, 5)}) + class TestNewBufferProtocol(object): def _check_roundtrip(self, obj): obj = np.asarray(obj) From numpy-svn at scipy.org Sun Apr 4 16:21:03 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 4 Apr 2010 15:21:03 -0500 (CDT) Subject: [Numpy-svn] r8318 - in trunk/numpy/core: . tests Message-ID: <20100404202103.AC65B39CAE7@scipy.org> Author: ptvirtan Date: 2010-04-04 15:21:03 -0500 (Sun, 04 Apr 2010) New Revision: 8318 Modified: trunk/numpy/core/_internal.py trunk/numpy/core/tests/test_multiarray.py Log: ENH: core: improve the way trailing padding is dealed with in PEP 3118 format strings Modified: trunk/numpy/core/_internal.py =================================================================== --- trunk/numpy/core/_internal.py 2010-04-04 20:20:56 UTC (rev 8317) +++ trunk/numpy/core/_internal.py 2010-04-04 20:21:03 UTC (rev 8318) @@ -485,10 +485,12 @@ else: raise ValueError("Unknown PEP 3118 data type specifier %r" % spec) + # # Native alignment may require padding # - # XXX: here we assume that the presence of a '@' character implies - # that the start of the array is *also* aligned. + # Here we assume that the presence of a '@' character implicitly implies + # that the start of the array is *already* aligned. + # extra_offset = 0 if byteorder == '@': start_padding = (-offset) % align @@ -497,10 +499,12 @@ offset += start_padding if intra_padding != 0: - if itemsize > 1 or shape is not None: - value = dtype([('f0', value), - ('pad', '%dV' % intra_padding)]) + if itemsize > 1 or (shape is not None and _prod(shape) > 1): + # Inject internal padding to the end of the sub-item + value = _add_trailing_padding(value, intra_padding) else: + # We can postpone the injection of internal padding, + # as the item appears at most once extra_offset += intra_padding # Update common alignment @@ -531,31 +535,74 @@ raise RuntimeError("Duplicate field name '%s' in PEP3118 format" % name) fields[name] = (value, offset) + last_offset = offset if not this_explicit_name: next_dummy_name() - last_offset = offset byteorder = next_byteorder offset += value.itemsize offset += extra_offset - if is_padding and not this_explicit_name: - # Trailing padding must be made explicit - name = get_dummy_name() - fields[name] = ('V%d' % (offset - last_offset), last_offset) - + # Check if this was a simple 1-item type if len(fields.keys()) == 1 and not explicit_name and fields['f0'][1] == 0 \ and not is_subdtype: ret = fields['f0'][0] else: ret = dtype(fields) + # Trailing padding must be explicitly added + padding = offset - ret.itemsize + if byteorder == '@': + padding += (-offset) % common_alignment + if is_padding and not this_explicit_name: + ret = _add_trailing_padding(ret, padding) + + # Finished if is_subdtype: return ret, spec, common_alignment, byteorder else: return ret +def _add_trailing_padding(value, padding): + """Inject the specified number of padding bytes at the end of a dtype""" + from numpy.core.multiarray import dtype + + if value.fields is None: + vfields = {'f0': (value, 0)} + else: + vfields = dict(value.fields) + + if value.names and value.names[-1] == '' and \ + value[''].char == 'V': + # A trailing padding field is already present + vfields[''] = ('V%d' % (vfields[''][0].itemsize + padding), + vfields[''][1]) + value = dtype(vfields) + else: + # Get a free name for the padding field + j = 0 + while True: + name = 'pad%d' % j + if name not in vfields: + vfields[name] = ('V%d' % padding, value.itemsize) + break + j += 1 + + value = dtype(vfields) + if '' not in vfields: + # Strip out the name of the padding field + names = list(value.names) + names[-1] = '' + value.names = tuple(names) + return value + +def _prod(a): + p = 1 + for x in a: + p *= x + return p + def _gcd(a, b): """Calculate the greatest common divisor of a and b""" while b: Modified: trunk/numpy/core/tests/test_multiarray.py =================================================================== --- trunk/numpy/core/tests/test_multiarray.py 2010-04-04 20:20:56 UTC (rev 8317) +++ trunk/numpy/core/tests/test_multiarray.py 2010-04-04 20:21:03 UTC (rev 8318) @@ -1460,7 +1460,13 @@ class TestPEP3118Dtype(object): def _check(self, spec, wanted): - assert_equal(_dtype_from_pep3118(spec), np.dtype(wanted), + dt = np.dtype(wanted) + if isinstance(wanted, list) and isinstance(wanted[-1], tuple): + if wanted[-1][0] == '': + names = list(dt.names) + names[-1] = '' + dt.names = tuple(names) + assert_equal(_dtype_from_pep3118(spec), dt, err_msg="spec %r != dtype %r" % (spec, wanted)) def test_native_padding(self): @@ -1481,15 +1487,38 @@ self._check('^x3T{xi}', {'f0': (({'f0': ('i', 1)}, (3,)), 1)}) def test_trailing_padding(self): - # Trailing padding should be included - self._check('ix', [('f0', 'i'), ('f1', 'V1')]) + # Trailing padding should be included, *and*, the item size + # should match the alignment if in aligned mode + align = np.dtype('i').alignment + def VV(n): + return 'V%d' % (align*(1 + (n-1)//align)) + self._check('ix', [('f0', 'i'), ('', VV(1))]) + self._check('ixx', [('f0', 'i'), ('', VV(2))]) + self._check('ixxx', [('f0', 'i'), ('', VV(3))]) + self._check('ixxxx', [('f0', 'i'), ('', VV(4))]) + self._check('i7x', [('f0', 'i'), ('', VV(7))]) + + self._check('^ix', [('f0', 'i'), ('', 'V1')]) + self._check('^ixx', [('f0', 'i'), ('', 'V2')]) + self._check('^ixxx', [('f0', 'i'), ('', 'V3')]) + self._check('^ixxxx', [('f0', 'i'), ('', 'V4')]) + self._check('^i7x', [('f0', 'i'), ('', 'V7')]) + def test_byteorder_inside_struct(self): # The byte order after @T{=i} should be '=', not '@'. # Check this by noting the absence of native alignment. - self._check('@T{^i}xi', {'f0': ({'f0': (np.int32, 0)}, 0), - 'f1': (np.int32, 5)}) + self._check('@T{^i}xi', {'f0': ({'f0': ('i', 0)}, 0), + 'f1': ('i', 5)}) + def test_intra_padding(self): + # Natively aligned sub-arrays may require some internal padding + align = np.dtype('i').alignment + def VV(n): + return 'V%d' % (align*(1 + (n-1)//align)) + + self._check('(3)T{ix}', ({'f0': ('i', 0), '': (VV(1), 4)}, (3,))) + class TestNewBufferProtocol(object): def _check_roundtrip(self, obj): obj = np.asarray(obj) From numpy-svn at scipy.org Sun Apr 4 16:47:49 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 4 Apr 2010 15:47:49 -0500 (CDT) Subject: [Numpy-svn] r8319 - trunk/numpy/core/src/multiarray Message-ID: <20100404204749.208DF39CAE7@scipy.org> Author: ptvirtan Date: 2010-04-04 15:47:48 -0500 (Sun, 04 Apr 2010) New Revision: 8319 Modified: trunk/numpy/core/src/multiarray/ctors.c Log: ENH: core: add sanity checks and warnings to PEP3118 -> ndarray conversion Modified: trunk/numpy/core/src/multiarray/ctors.c =================================================================== --- trunk/numpy/core/src/multiarray/ctors.c 2010-04-04 20:21:03 UTC (rev 8318) +++ trunk/numpy/core/src/multiarray/ctors.c 2010-04-04 20:47:48 UTC (rev 8319) @@ -1674,8 +1674,22 @@ if (view->format != NULL) { descr = (PyObject*)_descriptor_from_pep3118_format(view->format); if (descr == NULL) { + PyObject *msg; + msg = PyBytes_FromFormat("Invalid PEP 3118 format string: '%s'", + view->format); + PyErr_WarnEx(PyExc_RuntimeWarning, PyBytes_AS_STRING(msg), 0); + Py_DECREF(msg); goto fail; } + + /* Sanity check */ + if (descr->elsize != view->itemsize) { + PyErr_WarnEx(PyExc_RuntimeWarning, + "Item size computed from the PEP 3118 buffer format " + "string does not match the actual item size.", + 0); + goto fail; + } } else { descr = PyArray_DescrNewFromType(PyArray_STRING); From numpy-svn at scipy.org Mon Apr 5 00:03:19 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 4 Apr 2010 23:03:19 -0500 (CDT) Subject: [Numpy-svn] r8320 - trunk/numpy/core/src/npymath Message-ID: <20100405040319.B4AA139CAE6@scipy.org> Author: charris Date: 2010-04-04 23:03:19 -0500 (Sun, 04 Apr 2010) New Revision: 8320 Modified: trunk/numpy/core/src/npymath/npy_math.c.src Log: ENH: Make npy_log2_1p and npy_exp2_1m use standard functions. This avoids some problems with gcc optimizations on 32 intel systems. In any case, the problem is pushed back to location single functions. Modified: trunk/numpy/core/src/npymath/npy_math.c.src =================================================================== --- trunk/numpy/core/src/npymath/npy_math.c.src 2010-04-04 20:47:48 UTC (rev 8319) +++ trunk/numpy/core/src/npymath/npy_math.c.src 2010-04-05 04:03:19 UTC (rev 8320) @@ -370,7 +370,54 @@ /**end repeat**/ + /* + * Decorate all the math functions which are available on the current platform + */ + +/**begin repeat + * #type = npy_longdouble,double,float# + * #c = l,,f# + * #C = L,,F# + */ +/**begin repeat1 + * #kind = sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,rint,trunc,sqrt,log10, + * log,exp,expm1,asin,acos,atan,asinh,acosh,atanh,log1p,exp2,log2# + * #KIND = SIN,COS,TAN,SINH,COSH,TANH,FABS,FLOOR,CEIL,RINT,TRUNC,SQRT,LOG10, + * LOG,EXP,EXPM1,ASIN,ACOS,ATAN,ASINH,ACOSH,ATANH,LOG1P,EXP2,LOG2# + */ +#ifdef HAVE_ at KIND@@C@ + at type@ npy_ at kind@@c@(@type@ x) +{ + return @kind@@c@(x); +} +#endif + +/**end repeat1**/ + +/**begin repeat1 + * #kind = atan2,hypot,pow,fmod,copysign# + * #KIND = ATAN2,HYPOT,POW,FMOD,COPYSIGN# + */ +#ifdef HAVE_ at KIND@@C@ + at type@ npy_ at kind@@c@(@type@ x, @type@ y) +{ + return @kind@@c@(x, y); +} +#endif +/**end repeat1**/ + +#ifdef HAVE_MODF at C@ + at type@ npy_modf at c@(@type@ x, @type@ *iptr) +{ + return modf at c@(x, iptr); +} +#endif + +/**end repeat**/ + + +/* * Non standard functions */ @@ -397,24 +444,12 @@ @type@ npy_log2_1p at c@(@type@ x) { - @type@ u = 1 + x; - if (u == 1) { - return LOG2E*x; - } else { - return npy_log2 at c@(u) * x / (u - 1); - } + return LOG2E*npy_log1p at c@(x); } @type@ npy_exp2_1m at c@(@type@ x) { - @type@ u = npy_exp at c@(x); - if (u == 1.0) { - return LOGE2*x; - } else if (u - 1 == -1) { - return -LOGE2; - } else { - return (u - 1) * x/npy_log2 at c@(u); - } + return npy_exp1m at c@(LOGE2*x); } @type@ npy_logaddexp at c@(@type@ x, @type@ y) @@ -453,48 +488,3 @@ #undef DEG2RAD /**end repeat**/ - -/* - * Decorate all the math functions which are available on the current platform - */ - -/**begin repeat - * #type = npy_longdouble,double,float# - * #c = l,,f# - * #C = L,,F# - */ -/**begin repeat1 - * #kind = sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,rint,trunc,sqrt,log10, - * log,exp,expm1,asin,acos,atan,asinh,acosh,atanh,log1p,exp2,log2# - * #KIND = SIN,COS,TAN,SINH,COSH,TANH,FABS,FLOOR,CEIL,RINT,TRUNC,SQRT,LOG10, - * LOG,EXP,EXPM1,ASIN,ACOS,ATAN,ASINH,ACOSH,ATANH,LOG1P,EXP2,LOG2# - */ -#ifdef HAVE_ at KIND@@C@ - at type@ npy_ at kind@@c@(@type@ x) -{ - return @kind@@c@(x); -} -#endif - -/**end repeat1**/ - -/**begin repeat1 - * #kind = atan2,hypot,pow,fmod,copysign# - * #KIND = ATAN2,HYPOT,POW,FMOD,COPYSIGN# - */ -#ifdef HAVE_ at KIND@@C@ - at type@ npy_ at kind@@c@(@type@ x, @type@ y) -{ - return @kind@@c@(x, y); -} -#endif -/**end repeat1**/ - -#ifdef HAVE_MODF at C@ - at type@ npy_modf at c@(@type@ x, @type@ *iptr) -{ - return modf at c@(x, iptr); -} -#endif - -/**end repeat**/ From numpy-svn at scipy.org Mon Apr 5 00:03:22 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 4 Apr 2010 23:03:22 -0500 (CDT) Subject: [Numpy-svn] r8321 - trunk/numpy/core/src/npymath Message-ID: <20100405040322.A119939CAE6@scipy.org> Author: charris Date: 2010-04-04 23:03:22 -0500 (Sun, 04 Apr 2010) New Revision: 8321 Modified: trunk/numpy/core/src/npymath/npy_math.c.src Log: ENH: Use standard npy constant definitions in log2, exp2 functions. STY: Some cleanups, fix goto into if statement. BUG: Use proper name for expm1, not exp1m. Modified: trunk/numpy/core/src/npymath/npy_math.c.src =================================================================== --- trunk/numpy/core/src/npymath/npy_math.c.src 2010-04-05 04:03:19 UTC (rev 8320) +++ trunk/numpy/core/src/npymath/npy_math.c.src 2010-04-05 04:03:22 UTC (rev 8321) @@ -154,11 +154,11 @@ } /* compute y/x */ - k = (iy - ix)>>20; - if(k > 60) { /* |y/x| > 2**60 */ + k = (iy - ix) >> 20; + if (k > 60) { /* |y/x| > 2**60 */ z = NPY_PI_2 + 0.5 * NPY_DBL_EPSILON; m &= 1; - } else if(hx < 0 && k < -60) { + } else if (hx < 0 && k < -60) { z = 0.0; /* 0 > |y|/x > -2**-60 */ } else { z = npy_atan(npy_fabs(y/x)); /* safe to do y/x */ @@ -209,7 +209,7 @@ #ifndef HAVE_ACOSH double npy_acosh(double x) { - return 2*npy_log(npy_sqrt((x+1.0)/2)+npy_sqrt((x-1.0)/2)); + return 2*npy_log(npy_sqrt((x + 1.0)/2) + npy_sqrt((x - 1.0)/2)); } #endif @@ -255,14 +255,15 @@ y = npy_floor(x); r = x - y; - if (r > 0.5) goto rndup; + if (r > 0.5) { + y += 1.0; + } /* Round to nearest even */ - if (r==0.5) { + if (r == 0.5) { r = y - 2.0*npy_floor(0.5*y); - if (r==1.0) { - rndup: - y+=1.0; + if (r == 1.0) { + y += 1.0; } } return y; @@ -277,21 +278,17 @@ #endif #ifndef HAVE_EXP2 -#define LOG2 0.69314718055994530943 double npy_exp2(double x) { - return npy_exp(LOG2*x); + return npy_exp(NPY_LOGE2*x); } -#undef LOG2 #endif #ifndef HAVE_LOG2 -#define INVLOG2 1.4426950408889634074 double npy_log2(double x) { - return INVLOG2*npy_log(x); + return NPY_LOG2E*npy_log(x); } -#undef INVLOG2 #endif /* @@ -447,9 +444,9 @@ return LOG2E*npy_log1p at c@(x); } - at type@ npy_exp2_1m at c@(@type@ x) + at type@ npy_exp2_m1 at c@(@type@ x) { - return npy_exp1m at c@(LOGE2*x); + return npy_expm1 at c@(LOGE2*x); } @type@ npy_logaddexp at c@(@type@ x, @type@ y) From numpy-svn at scipy.org Mon Apr 5 00:03:25 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 4 Apr 2010 23:03:25 -0500 (CDT) Subject: [Numpy-svn] r8322 - trunk/numpy/core/src/npymath Message-ID: <20100405040325.DB36E39CAEB@scipy.org> Author: charris Date: 2010-04-04 23:03:25 -0500 (Sun, 04 Apr 2010) New Revision: 8322 Modified: trunk/numpy/core/src/npymath/npy_math.c.src Log: ENH: Try to make log1p a bit more resistant to compiler shenanigans. STY: Couple of style fixups. Modified: trunk/numpy/core/src/npymath/npy_math.c.src =================================================================== --- trunk/numpy/core/src/npymath/npy_math.c.src 2010-04-05 04:03:22 UTC (rev 8321) +++ trunk/numpy/core/src/npymath/npy_math.c.src 2010-04-05 04:03:25 UTC (rev 8322) @@ -65,13 +65,14 @@ #ifndef HAVE_EXPM1 double npy_expm1(double x) { - double u = npy_exp(x); + const double u = npy_exp(x); + if (u == 1.0) { return x; - } else if (u-1.0 == -1.0) { + } else if (u - 1.0 == -1.0) { return -1; } else { - return (u-1.0) * x/npy_log(u); + return (u - 1.0) * x/npy_log(u); } } #endif @@ -79,11 +80,13 @@ #ifndef HAVE_LOG1P double npy_log1p(double x) { - double u = 1. + x; - if (u == 1.0) { + const double u = 1. + x; + const double d = u - 1.; + + if (d == 0) { return x; } else { - return npy_log(u) * x / (u - 1); + return npy_log(u) * x / d; } } #endif From numpy-svn at scipy.org Mon Apr 5 00:38:49 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 4 Apr 2010 23:38:49 -0500 (CDT) Subject: [Numpy-svn] r8323 - trunk/numpy/core/tests Message-ID: <20100405043849.96FDE39CAE6@scipy.org> Author: charris Date: 2010-04-04 23:38:49 -0500 (Sun, 04 Apr 2010) New Revision: 8323 Modified: trunk/numpy/core/tests/test_regression.py Log: ENH: Add test for log1p on intel 32 bits for certain small values of p. Modified: trunk/numpy/core/tests/test_regression.py =================================================================== --- trunk/numpy/core/tests/test_regression.py 2010-04-05 04:03:25 UTC (rev 8322) +++ trunk/numpy/core/tests/test_regression.py 2010-04-05 04:38:49 UTC (rev 8323) @@ -1283,5 +1283,9 @@ # Bug #1436; the following should succeed np.asarray('x', '>c') + def test_log1p_compiler_shenanigans(self): + # Check if log1p is behaving on 32 bit intel systems. + assert_(np.isfinite(np.log1p(np.exp2(-53)))) + if __name__ == "__main__": run_module_suite() From numpy-svn at scipy.org Mon Apr 5 00:51:33 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 4 Apr 2010 23:51:33 -0500 (CDT) Subject: [Numpy-svn] r8324 - in branches/1.4.x/numpy/core: src/npymath tests Message-ID: <20100405045133.A03FF39CAE6@scipy.org> Author: charris Date: 2010-04-04 23:51:33 -0500 (Sun, 04 Apr 2010) New Revision: 8324 Modified: branches/1.4.x/numpy/core/src/npymath/npy_math.c.src branches/1.4.x/numpy/core/tests/test_regression.py Log: BUG: Backport r8320-r8223 from trunk. Modified: branches/1.4.x/numpy/core/src/npymath/npy_math.c.src =================================================================== --- branches/1.4.x/numpy/core/src/npymath/npy_math.c.src 2010-04-05 04:38:49 UTC (rev 8323) +++ branches/1.4.x/numpy/core/src/npymath/npy_math.c.src 2010-04-05 04:51:33 UTC (rev 8324) @@ -65,13 +65,14 @@ #ifndef HAVE_EXPM1 double npy_expm1(double x) { - double u = npy_exp(x); + const double u = npy_exp(x); + if (u == 1.0) { return x; - } else if (u-1.0 == -1.0) { + } else if (u - 1.0 == -1.0) { return -1; } else { - return (u-1.0) * x/npy_log(u); + return (u - 1.0) * x/npy_log(u); } } #endif @@ -79,11 +80,13 @@ #ifndef HAVE_LOG1P double npy_log1p(double x) { - double u = 1. + x; - if (u == 1.0) { + const double u = 1. + x; + const double d = u - 1.; + + if (d == 0) { return x; } else { - return npy_log(u) * x / (u - 1); + return npy_log(u) * x / d; } } #endif @@ -154,11 +157,11 @@ } /* compute y/x */ - k = (iy - ix)>>20; - if(k > 60) { /* |y/x| > 2**60 */ + k = (iy - ix) >> 20; + if (k > 60) { /* |y/x| > 2**60 */ z = NPY_PI_2 + 0.5 * NPY_DBL_EPSILON; m &= 1; - } else if(hx < 0 && k < -60) { + } else if (hx < 0 && k < -60) { z = 0.0; /* 0 > |y|/x > -2**-60 */ } else { z = npy_atan(npy_fabs(y/x)); /* safe to do y/x */ @@ -209,7 +212,7 @@ #ifndef HAVE_ACOSH double npy_acosh(double x) { - return 2*npy_log(npy_sqrt((x+1.0)/2)+npy_sqrt((x-1.0)/2)); + return 2*npy_log(npy_sqrt((x + 1.0)/2) + npy_sqrt((x - 1.0)/2)); } #endif @@ -255,14 +258,15 @@ y = npy_floor(x); r = x - y; - if (r > 0.5) goto rndup; + if (r > 0.5) { + y += 1.0; + } /* Round to nearest even */ - if (r==0.5) { + if (r == 0.5) { r = y - 2.0*npy_floor(0.5*y); - if (r==1.0) { - rndup: - y+=1.0; + if (r == 1.0) { + y += 1.0; } } return y; @@ -277,21 +281,17 @@ #endif #ifndef HAVE_EXP2 -#define LOG2 0.69314718055994530943 double npy_exp2(double x) { - return npy_exp(LOG2*x); + return npy_exp(NPY_LOGE2*x); } -#undef LOG2 #endif #ifndef HAVE_LOG2 -#define INVLOG2 1.4426950408889634074 double npy_log2(double x) { - return INVLOG2*npy_log(x); + return NPY_LOG2E*npy_log(x); } -#undef INVLOG2 #endif /* @@ -370,7 +370,54 @@ /**end repeat**/ + /* + * Decorate all the math functions which are available on the current platform + */ + +/**begin repeat + * #type = npy_longdouble,double,float# + * #c = l,,f# + * #C = L,,F# + */ +/**begin repeat1 + * #kind = sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,rint,trunc,sqrt,log10, + * log,exp,expm1,asin,acos,atan,asinh,acosh,atanh,log1p,exp2,log2# + * #KIND = SIN,COS,TAN,SINH,COSH,TANH,FABS,FLOOR,CEIL,RINT,TRUNC,SQRT,LOG10, + * LOG,EXP,EXPM1,ASIN,ACOS,ATAN,ASINH,ACOSH,ATANH,LOG1P,EXP2,LOG2# + */ +#ifdef HAVE_ at KIND@@C@ + at type@ npy_ at kind@@c@(@type@ x) +{ + return @kind@@c@(x); +} +#endif + +/**end repeat1**/ + +/**begin repeat1 + * #kind = atan2,hypot,pow,fmod,copysign# + * #KIND = ATAN2,HYPOT,POW,FMOD,COPYSIGN# + */ +#ifdef HAVE_ at KIND@@C@ + at type@ npy_ at kind@@c@(@type@ x, @type@ y) +{ + return @kind@@c@(x, y); +} +#endif +/**end repeat1**/ + +#ifdef HAVE_MODF at C@ + at type@ npy_modf at c@(@type@ x, @type@ *iptr) +{ + return modf at c@(x, iptr); +} +#endif + +/**end repeat**/ + + +/* * Non standard functions */ @@ -397,24 +444,12 @@ @type@ npy_log2_1p at c@(@type@ x) { - @type@ u = 1 + x; - if (u == 1) { - return LOG2E*x; - } else { - return npy_log2 at c@(u) * x / (u - 1); - } + return LOG2E*npy_log1p at c@(x); } - at type@ npy_exp2_1m at c@(@type@ x) + at type@ npy_exp2_m1 at c@(@type@ x) { - @type@ u = npy_exp at c@(x); - if (u == 1.0) { - return LOGE2*x; - } else if (u - 1 == -1) { - return -LOGE2; - } else { - return (u - 1) * x/npy_log2 at c@(u); - } + return npy_expm1 at c@(LOGE2*x); } @type@ npy_logaddexp at c@(@type@ x, @type@ y) @@ -453,48 +488,3 @@ #undef DEG2RAD /**end repeat**/ - -/* - * Decorate all the math functions which are available on the current platform - */ - -/**begin repeat - * #type = npy_longdouble,double,float# - * #c = l,,f# - * #C = L,,F# - */ -/**begin repeat1 - * #kind = sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,rint,trunc,sqrt,log10, - * log,exp,expm1,asin,acos,atan,asinh,acosh,atanh,log1p,exp2,log2# - * #KIND = SIN,COS,TAN,SINH,COSH,TANH,FABS,FLOOR,CEIL,RINT,TRUNC,SQRT,LOG10, - * LOG,EXP,EXPM1,ASIN,ACOS,ATAN,ASINH,ACOSH,ATANH,LOG1P,EXP2,LOG2# - */ -#ifdef HAVE_ at KIND@@C@ - at type@ npy_ at kind@@c@(@type@ x) -{ - return @kind@@c@(x); -} -#endif - -/**end repeat1**/ - -/**begin repeat1 - * #kind = atan2,hypot,pow,fmod,copysign# - * #KIND = ATAN2,HYPOT,POW,FMOD,COPYSIGN# - */ -#ifdef HAVE_ at KIND@@C@ - at type@ npy_ at kind@@c@(@type@ x, @type@ y) -{ - return @kind@@c@(x, y); -} -#endif -/**end repeat1**/ - -#ifdef HAVE_MODF at C@ - at type@ npy_modf at c@(@type@ x, @type@ *iptr) -{ - return modf at c@(x, iptr); -} -#endif - -/**end repeat**/ Modified: branches/1.4.x/numpy/core/tests/test_regression.py =================================================================== --- branches/1.4.x/numpy/core/tests/test_regression.py 2010-04-05 04:38:49 UTC (rev 8323) +++ branches/1.4.x/numpy/core/tests/test_regression.py 2010-04-05 04:51:33 UTC (rev 8324) @@ -1220,7 +1220,7 @@ x[x.nonzero()] = x.ravel()[:1] assert sys.getrefcount(strb) == numb assert sys.getrefcount(stra) == numa + 2 - + def test_signed_integer_division_overflow(self): """Ticket #1317.""" def test_type(t): @@ -1230,7 +1230,11 @@ for t in (np.int8, np.int16, np.int32, np.int64, np.int, np.long): test_type(t) + def test_log1p_compiler_shenanigans(self): + # Check if log1p is behaving on 32 bit intel systems. + assert_(np.isfinite(np.log1p(np.exp2(-53)))) + if __name__ == "__main__": run_module_suite() def test_duplicate_title_and_name(self): From numpy-svn at scipy.org Mon Apr 12 16:35:59 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 12 Apr 2010 15:35:59 -0500 (CDT) Subject: [Numpy-svn] r8325 - in trunk/numpy/core: . tests Message-ID: <20100412203559.718F939CB12@scipy.org> Author: charris Date: 2010-04-12 15:35:59 -0500 (Mon, 12 Apr 2010) New Revision: 8325 Modified: trunk/numpy/core/memmap.py trunk/numpy/core/tests/test_memmap.py Log: ENH: Add filename attribute to memmap. Modified: trunk/numpy/core/memmap.py =================================================================== --- trunk/numpy/core/memmap.py 2010-04-05 04:51:33 UTC (rev 8324) +++ trunk/numpy/core/memmap.py 2010-04-12 20:35:59 UTC (rev 8325) @@ -227,11 +227,13 @@ self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm, offset=offset, order=order) self._mmap = mm + self.filename = filename return self def __array_finalize__(self, obj): if hasattr(obj, '_mmap'): self._mmap = obj._mmap + self.filename = obj.filename else: self._mmap = None Modified: trunk/numpy/core/tests/test_memmap.py =================================================================== --- trunk/numpy/core/tests/test_memmap.py 2010-04-05 04:51:33 UTC (rev 8324) +++ trunk/numpy/core/tests/test_memmap.py 2010-04-12 20:35:59 UTC (rev 8325) @@ -38,6 +38,18 @@ del fp os.unlink(tmpname) + def test_filename(self): + tmpname = mktemp('','mmap') + fp = memmap(tmpname, dtype=self.dtype, mode='w+', + shape=self.shape) + fp[:] = self.data[:] + self.assertEquals(tmpname, fp.filename) + b = fp[:1] + self.assertEquals(tmpname, b.filename) + del fp + os.unlink(tmpname) + + def test_flush(self): fp = memmap(self.tmpfp, dtype=self.dtype, mode='w+', shape=self.shape) From numpy-svn at scipy.org Mon Apr 12 19:11:40 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 12 Apr 2010 18:11:40 -0500 (CDT) Subject: [Numpy-svn] r8326 - trunk/numpy/core Message-ID: <20100412231140.A226939CB3E@scipy.org> Author: charris Date: 2010-04-12 18:11:40 -0500 (Mon, 12 Apr 2010) New Revision: 8326 Modified: trunk/numpy/core/memmap.py Log: ENH: Make the new memmap filename attribute store the full path to the file. Add offset and mode attributes to the memmap class. Modified: trunk/numpy/core/memmap.py =================================================================== --- trunk/numpy/core/memmap.py 2010-04-12 20:35:59 UTC (rev 8325) +++ trunk/numpy/core/memmap.py 2010-04-12 23:11:40 UTC (rev 8326) @@ -109,6 +109,9 @@ [ 4., 5., 6., 7.], [ 8., 9., 10., 11.]], dtype=float32) + >>> fp.filename == path.abspath(filename) + True + Deletion flushes memory changes to disk before removing the object: >>> del fp @@ -166,6 +169,7 @@ shape=None, order='C'): # Import here to minimize 'import numpy' overhead import mmap + import os.path try: mode = mode_equivalents[mode] except KeyError: @@ -227,13 +231,22 @@ self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm, offset=offset, order=order) self._mmap = mm - self.filename = filename + self.offset = offset + self.mode = mode + + if isinstance(filename, basestring): + self.filename = os.path.abspath(filename) + elif hasattr(filename, "name"): + self.filename = filename.name + return self def __array_finalize__(self, obj): if hasattr(obj, '_mmap'): self._mmap = obj._mmap self.filename = obj.filename + self.offset = obj.offset + self.mode = obj.mode else: self._mmap = None From numpy-svn at scipy.org Mon Apr 12 19:34:55 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 12 Apr 2010 18:34:55 -0500 (CDT) Subject: [Numpy-svn] r8327 - trunk/numpy/core Message-ID: <20100412233455.3941739CAF1@scipy.org> Author: charris Date: 2010-04-12 18:34:55 -0500 (Mon, 12 Apr 2010) New Revision: 8327 Modified: trunk/numpy/core/memmap.py Log: BUG: Need to use os.path.abspath on file handle name also. Modified: trunk/numpy/core/memmap.py =================================================================== --- trunk/numpy/core/memmap.py 2010-04-12 23:11:40 UTC (rev 8326) +++ trunk/numpy/core/memmap.py 2010-04-12 23:34:55 UTC (rev 8327) @@ -237,7 +237,7 @@ if isinstance(filename, basestring): self.filename = os.path.abspath(filename) elif hasattr(filename, "name"): - self.filename = filename.name + self.filename = os.path.abspath(filename.name) return self From numpy-svn at scipy.org Mon Apr 12 20:38:49 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 12 Apr 2010 19:38:49 -0500 (CDT) Subject: [Numpy-svn] r8328 - trunk/numpy/core/tests Message-ID: <20100413003849.2C9C339CAF1@scipy.org> Author: charris Date: 2010-04-12 19:38:49 -0500 (Mon, 12 Apr 2010) New Revision: 8328 Modified: trunk/numpy/core/tests/test_memmap.py Log: ENH: Add more tests for new memmap object attributes. Modified: trunk/numpy/core/tests/test_memmap.py =================================================================== --- trunk/numpy/core/tests/test_memmap.py 2010-04-12 23:34:55 UTC (rev 8327) +++ trunk/numpy/core/tests/test_memmap.py 2010-04-13 00:38:49 UTC (rev 8328) @@ -38,17 +38,31 @@ del fp os.unlink(tmpname) + def test_attributes(self): + offset = 1 + mode = "w+" + fp = memmap(self.tmpfp, dtype=self.dtype, mode=mode, + shape=self.shape, offset=offset) + self.assertEquals(offset, fp.offset) + self.assertEquals(mode, fp.mode) + del fp + def test_filename(self): tmpname = mktemp('','mmap') fp = memmap(tmpname, dtype=self.dtype, mode='w+', shape=self.shape) + abspath = os.path.abspath(tmpname) fp[:] = self.data[:] - self.assertEquals(tmpname, fp.filename) + self.assertEquals(abspath, fp.filename) b = fp[:1] - self.assertEquals(tmpname, b.filename) + self.assertEquals(abspath, b.filename) del fp os.unlink(tmpname) + def test_filename_fileobj(self): + fp = memmap(self.tmpfp, dtype=self.dtype, mode="w+", + shape=self.shape) + self.assertEquals(fp.filename, self.tmpfp.name) def test_flush(self): fp = memmap(self.tmpfp, dtype=self.dtype, mode='w+', From numpy-svn at scipy.org Mon Apr 12 23:26:38 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 12 Apr 2010 22:26:38 -0500 (CDT) Subject: [Numpy-svn] r8329 - trunk/numpy/lib/tests Message-ID: <20100413032638.4AA9E39C4B4@scipy.org> Author: charris Date: 2010-04-12 22:26:38 -0500 (Mon, 12 Apr 2010) New Revision: 8329 Modified: trunk/numpy/lib/tests/test_ufunclike.py Log: ENH: Rewrite doctest in test_ufunclike.py as normal nose tests. Remove test of sign ufunc, it belongs elsewhere. Modified: trunk/numpy/lib/tests/test_ufunclike.py =================================================================== --- trunk/numpy/lib/tests/test_ufunclike.py 2010-04-13 00:38:49 UTC (rev 8328) +++ trunk/numpy/lib/tests/test_ufunclike.py 2010-04-13 03:26:38 UTC (rev 8329) @@ -1,85 +1,71 @@ -""" ->>> import numpy.core as nx ->>> import numpy.lib.ufunclike as U +from numpy.testing import * +import numpy.core as nx +import numpy.lib.ufunclike as ufl +import warnings -Test fix: ->>> a = nx.array([[1.0, 1.1, 1.5, 1.8], [-1.0, -1.1, -1.5, -1.8]]) ->>> U.fix(a) -array([[ 1., 1., 1., 1.], - [-1., -1., -1., -1.]]) ->>> y = nx.zeros(a.shape, float) ->>> U.fix(a, y) -array([[ 1., 1., 1., 1.], - [-1., -1., -1., -1.]]) ->>> y -array([[ 1., 1., 1., 1.], - [-1., -1., -1., -1.]]) +class TestUfunclike(TestCase): -Test isposinf, isneginf, sign ->>> a = nx.array([nx.Inf, -nx.Inf, nx.NaN, 0.0, 3.0, -3.0]) ->>> U.isposinf(a) -array([ True, False, False, False, False, False], dtype=bool) ->>> U.isneginf(a) -array([False, True, False, False, False, False], dtype=bool) ->>> olderr = nx.seterr(invalid='ignore') ->>> nx.sign(a) -array([ 1., -1., NaN, 0., 1., -1.]) ->>> olderr = nx.seterr(**olderr) + def test_isposinf(self): + a = nx.array([nx.inf, -nx.inf, nx.nan, 0.0, 3.0, -3.0]) + out = nx.zeros(a.shape, bool) + tgt = nx.array([True, False, False, False, False, False]) -Same thing with an output array: ->>> y = nx.zeros(a.shape, bool) ->>> U.isposinf(a, y) -array([ True, False, False, False, False, False], dtype=bool) ->>> y -array([ True, False, False, False, False, False], dtype=bool) ->>> U.isneginf(a, y) -array([False, True, False, False, False, False], dtype=bool) ->>> y -array([False, True, False, False, False, False], dtype=bool) ->>> olderr = nx.seterr(invalid='ignore') ->>> nx.sign(a, y) -array([ True, True, True, False, True, True], dtype=bool) ->>> olderr = nx.seterr(**olderr) ->>> y -array([ True, True, True, False, True, True], dtype=bool) + res = ufl.isposinf(a) + assert_equal(res, tgt) + res = ufl.isposinf(a, out) + assert_equal(res, tgt) + assert_equal(out, tgt) -Now log2: ->>> a = nx.array([4.5, 2.3, 6.5]) ->>> U.log2(a) -array([ 2.169925 , 1.20163386, 2.70043972]) ->>> 2**_ -array([ 4.5, 2.3, 6.5]) ->>> y = nx.zeros(a.shape, float) ->>> U.log2(a, y) -array([ 2.169925 , 1.20163386, 2.70043972]) ->>> y -array([ 2.169925 , 1.20163386, 2.70043972]) + def test_isneginf(self): + a = nx.array([nx.inf, -nx.inf, nx.nan, 0.0, 3.0, -3.0]) + out = nx.zeros(a.shape, bool) + tgt = nx.array([False, True, False, False, False, False]) -""" + res = ufl.isneginf(a) + assert_equal(res, tgt) + res = ufl.isneginf(a, out) + assert_equal(res, tgt) + assert_equal(out, tgt) -from numpy.testing import * -import numpy.core as nx -import numpy.lib.ufunclike as ufl + def test_log2(self): + a = nx.array([4.5, 2.3, 6.5]) + out = nx.zeros(a.shape, float) + tgt = nx.array([2.169925, 1.20163386, 2.70043972]) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore",category=DeprecationWarning) + res = ufl.log2(a) + assert_almost_equal(res, tgt) + res = ufl.log2(a, out) + assert_almost_equal(res, tgt) + assert_almost_equal(out, tgt) -def test(): - return rundocs() + def test_fix(self): + a = nx.array([[1.0, 1.1, 1.5, 1.8], [-1.0, -1.1, -1.5, -1.8]]) + out = nx.zeros(a.shape, float) + tgt = nx.array([[ 1., 1., 1., 1.], [-1., -1., -1., -1.]]) -def test_fix_with_subclass(): - class MyArray(nx.ndarray): - def __new__(cls, data, metadata=None): - res = nx.array(data, copy=True).view(cls) - res.metadata = metadata - return res - def __array_wrap__(self, obj, context=None): - obj.metadata = self.metadata - return obj - - a = nx.array([1.1, -1.1]) - m = MyArray(a, metadata='foo') - f = ufl.fix(m) - assert_array_equal(f, nx.array([1,-1])) - assert isinstance(f, MyArray) - assert_equal(f.metadata, 'foo') + res = ufl.fix(a) + assert_equal(res, tgt) + res = ufl.fix(a, out) + assert_equal(res, tgt) + assert_equal(out, tgt) + def test_fix_with_subclass(self): + class MyArray(nx.ndarray): + def __new__(cls, data, metadata=None): + res = nx.array(data, copy=True).view(cls) + res.metadata = metadata + return res + def __array_wrap__(self, obj, context=None): + obj.metadata = self.metadata + return obj + + a = nx.array([1.1, -1.1]) + m = MyArray(a, metadata='foo') + f = ufl.fix(m) + assert_array_equal(f, nx.array([1,-1])) + assert isinstance(f, MyArray) + assert_equal(f.metadata, 'foo') + if __name__ == "__main__": run_module_suite() From numpy-svn at scipy.org Mon Apr 12 23:26:41 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 12 Apr 2010 22:26:41 -0500 (CDT) Subject: [Numpy-svn] r8330 - trunk/numpy/core/tests Message-ID: <20100413032641.5ACF039CB26@scipy.org> Author: charris Date: 2010-04-12 22:26:41 -0500 (Mon, 12 Apr 2010) New Revision: 8330 Modified: trunk/numpy/core/tests/test_umath.py Log: ENH: Add test of sign ufunc removed from test_ufunclike. Modified: trunk/numpy/core/tests/test_umath.py =================================================================== --- trunk/numpy/core/tests/test_umath.py 2010-04-13 03:26:38 UTC (rev 8329) +++ trunk/numpy/core/tests/test_umath.py 2010-04-13 03:26:41 UTC (rev 8330) @@ -4,6 +4,7 @@ import numpy.core.umath as ncu import numpy as np + class TestDivision(TestCase): def test_division_int(self): # int division should follow Python @@ -39,6 +40,7 @@ y = np.floor_divide(x**2, x) assert_equal(y, [1.e+110, 0], err_msg=msg) + class TestPower(TestCase): def test_power_float(self): x = np.array([1., 2., 3.]) @@ -84,6 +86,7 @@ finally: np.seterr(**err) + class TestLog2(TestCase): def test_log2_values(self) : x = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024] @@ -93,6 +96,7 @@ yf = np.array(y, dtype=dt) assert_almost_equal(np.log2(xf), yf) + class TestExp2(TestCase): def test_exp2_values(self) : x = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024] @@ -102,6 +106,7 @@ yf = np.array(y, dtype=dt) assert_almost_equal(np.exp2(yf), xf) + class TestLogAddExp2(object): # Need test for intermediate precisions def test_logaddexp2_values(self) : @@ -146,6 +151,7 @@ assert np.isnan(np.logaddexp2(0, np.nan)) assert np.isnan(np.logaddexp2(np.nan, np.nan)) + class TestLog(TestCase): def test_log_values(self) : x = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024] @@ -156,6 +162,7 @@ yf = np.array(y, dtype=dt)*log2_ assert_almost_equal(np.log(xf), yf) + class TestExp(TestCase): def test_exp_values(self) : x = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024] @@ -166,6 +173,7 @@ yf = np.array(y, dtype=dt)*log2_ assert_almost_equal(np.exp(yf), xf) + class TestLogAddExp(object): def test_logaddexp_values(self) : x = [1, 2, 3, 4, 5] @@ -209,21 +217,25 @@ assert np.isnan(np.logaddexp(0, np.nan)) assert np.isnan(np.logaddexp(np.nan, np.nan)) + class TestLog1p(TestCase): def test_log1p(self): assert_almost_equal(ncu.log1p(0.2), ncu.log(1.2)) assert_almost_equal(ncu.log1p(1e-6), ncu.log(1+1e-6)) + class TestExpm1(TestCase): def test_expm1(self): assert_almost_equal(ncu.expm1(0.2), ncu.exp(0.2)-1) assert_almost_equal(ncu.expm1(1e-6), ncu.exp(1e-6)-1) + class TestHypot(TestCase, object): def test_simple(self): assert_almost_equal(ncu.hypot(1, 1), ncu.sqrt(2)) assert_almost_equal(ncu.hypot(0, 0), 0) + def assert_hypot_isnan(x, y): err = np.seterr(invalid='ignore') try: @@ -231,6 +243,7 @@ finally: np.seterr(**err) + def assert_hypot_isinf(x, y): err = np.seterr(invalid='ignore') try: @@ -238,6 +251,7 @@ finally: np.seterr(**err) + class TestHypotSpecialValues(TestCase): def test_nan_outputs(self): assert_hypot_isnan(np.nan, np.nan) @@ -249,21 +263,27 @@ assert_hypot_isinf(np.inf, 0) assert_hypot_isinf(0, np.inf) + def assert_arctan2_isnan(x, y): assert np.isnan(ncu.arctan2(x, y)), "arctan(%s, %s) is %s, not nan" % (x, y, ncu.arctan2(x, y)) + def assert_arctan2_ispinf(x, y): assert (np.isinf(ncu.arctan2(x, y)) and ncu.arctan2(x, y) > 0), "arctan(%s, %s) is %s, not +inf" % (x, y, ncu.arctan2(x, y)) + def assert_arctan2_isninf(x, y): assert (np.isinf(ncu.arctan2(x, y)) and ncu.arctan2(x, y) < 0), "arctan(%s, %s) is %s, not -inf" % (x, y, ncu.arctan2(x, y)) + def assert_arctan2_ispzero(x, y): assert (ncu.arctan2(x, y) == 0 and not np.signbit(ncu.arctan2(x, y))), "arctan(%s, %s) is %s, not +0" % (x, y, ncu.arctan2(x, y)) + def assert_arctan2_isnzero(x, y): assert (ncu.arctan2(x, y) == 0 and np.signbit(ncu.arctan2(x, y))), "arctan(%s, %s) is %s, not -0" % (x, y, ncu.arctan2(x, y)) + class TestArctan2SpecialValues(TestCase): def test_one_one(self): # atan2(1, 1) returns pi/4. @@ -332,6 +352,7 @@ assert_arctan2_isnan(np.inf, np.nan) assert_arctan2_isnan(np.nan, np.nan) + class TestMaximum(TestCase): def test_reduce_complex(self): assert_equal(np.maximum.reduce([1,2j]),1) @@ -352,6 +373,7 @@ out = np.array([nan, nan, nan], dtype=np.complex) assert_equal(np.maximum(arg1, arg2), out) + class TestMinimum(TestCase): def test_reduce_complex(self): assert_equal(np.minimum.reduce([1,2j]),2j) @@ -372,6 +394,7 @@ out = np.array([nan, nan, nan], dtype=np.complex) assert_equal(np.minimum(arg1, arg2), out) + class TestFmax(TestCase): def test_reduce_complex(self): assert_equal(np.fmax.reduce([1,2j]),1) @@ -392,6 +415,7 @@ out = np.array([0, 0, nan], dtype=np.complex) assert_equal(np.fmax(arg1, arg2), out) + class TestFmin(TestCase): def test_reduce_complex(self): assert_equal(np.fmin.reduce([1,2j]),2j) @@ -412,20 +436,41 @@ out = np.array([0, 0, nan], dtype=np.complex) assert_equal(np.fmin(arg1, arg2), out) + class TestFloatingPoint(TestCase): def test_floating_point(self): assert_equal(ncu.FLOATING_POINT_SUPPORT, 1) + class TestDegrees(TestCase): def test_degrees(self): assert_almost_equal(ncu.degrees(np.pi), 180.0) assert_almost_equal(ncu.degrees(-0.5*np.pi), -90.0) + class TestRadians(TestCase): def test_radians(self): assert_almost_equal(ncu.radians(180.0), np.pi) assert_almost_equal(ncu.radians(-90.0), -0.5*np.pi) + +class TestSign(TestCase): + def test_sign(self): + a = np.array([np.inf, -np.inf, np.nan, 0.0, 3.0, -3.0]) + out = np.zeros(a.shape) + tgt = np.array([1., -1., np.nan, 0.0, 1.0, -1.0]) + + olderr = np.seterr(invalid='ignore') + try: + res = ncu.sign(a) + assert_equal(res, tgt) + res = ncu.sign(a, out) + assert_equal(res, tgt) + assert_equal(out, tgt) + finally: + np.seterr(**olderr) + + class TestSpecialMethods(TestCase): def test_wrap(self): class with_wrap(object): @@ -596,6 +641,7 @@ info = np.finfo(np.longcomplex) return not np.isfinite(np.log10(info.tiny/info.eps)) + class TestComplexFunctions(object): funcs = [np.arcsin, np.arccos, np.arctan, np.arcsinh, np.arccosh, np.arctanh, np.sin, np.cos, np.tan, np.exp, @@ -786,6 +832,7 @@ def test_loss_of_precision_longcomplex(self): self.check_loss_of_precision(np.longcomplex) + class TestAttributes(TestCase): def test_attributes(self): add = ncu.add @@ -797,6 +844,7 @@ assert_equal(add.nout, 1) assert_equal(add.identity, 0) + class TestSubclass(TestCase): def test_subclass_op(self): class simple(np.ndarray): From numpy-svn at scipy.org Mon Apr 12 23:26:45 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 12 Apr 2010 22:26:45 -0500 (CDT) Subject: [Numpy-svn] r8331 - trunk/numpy/lib Message-ID: <20100413032645.7B9F839CB29@scipy.org> Author: charris Date: 2010-04-12 22:26:45 -0500 (Mon, 12 Apr 2010) New Revision: 8331 Modified: trunk/numpy/lib/ufunclike.py Log: BUG: Deprecate ufunclike.log2 and take it off the __all__ list. It was shadowing the ufunc of the same name. Modified: trunk/numpy/lib/ufunclike.py =================================================================== --- trunk/numpy/lib/ufunclike.py 2010-04-13 03:26:41 UTC (rev 8330) +++ trunk/numpy/lib/ufunclike.py 2010-04-13 03:26:45 UTC (rev 8331) @@ -2,9 +2,10 @@ Module of functions that are like ufuncs in acting on arrays and optionally storing results in an output array. """ -__all__ = ['fix', 'isneginf', 'isposinf', 'log2'] +__all__ = ['fix', 'isneginf', 'isposinf'] import numpy.core.numeric as nx +import warnings def fix(x, y=None): """ @@ -177,6 +178,7 @@ def log2(x, y=None): """ Return the base 2 logarithm of the input array, element-wise. + This function is now deprecated, use the np.log2 ufunc instead. Parameters ---------- @@ -201,6 +203,9 @@ array([ NaN, 1., 2.]) """ + msg = "numpy.lib.log2 is deprecated, use np.log2 instead." + warnings.warn(msg, DeprecationWarning) + x = nx.asanyarray(x) if y is None: y = nx.log(x) From numpy-svn at scipy.org Tue Apr 13 12:25:36 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 13 Apr 2010 11:25:36 -0500 (CDT) Subject: [Numpy-svn] r8332 - trunk/numpy/lib/tests Message-ID: <20100413162536.E829839CB3A@scipy.org> Author: charris Date: 2010-04-13 11:25:36 -0500 (Tue, 13 Apr 2010) New Revision: 8332 Modified: trunk/numpy/lib/tests/test_ufunclike.py Log: BUG: Python 2.4 doesn't support "with" statement, use try instead. Modified: trunk/numpy/lib/tests/test_ufunclike.py =================================================================== --- trunk/numpy/lib/tests/test_ufunclike.py 2010-04-13 03:26:45 UTC (rev 8331) +++ trunk/numpy/lib/tests/test_ufunclike.py 2010-04-13 16:25:36 UTC (rev 8332) @@ -31,13 +31,15 @@ a = nx.array([4.5, 2.3, 6.5]) out = nx.zeros(a.shape, float) tgt = nx.array([2.169925, 1.20163386, 2.70043972]) - with warnings.catch_warnings(): + try: warnings.filterwarnings("ignore",category=DeprecationWarning) res = ufl.log2(a) assert_almost_equal(res, tgt) res = ufl.log2(a, out) assert_almost_equal(res, tgt) assert_almost_equal(out, tgt) + except DeprecationWarning: + pass def test_fix(self): a = nx.array([[1.0, 1.1, 1.5, 1.8], [-1.0, -1.1, -1.5, -1.8]]) From numpy-svn at scipy.org Wed Apr 14 13:17:53 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Wed, 14 Apr 2010 12:17:53 -0500 (CDT) Subject: [Numpy-svn] r8333 - trunk/doc/sphinxext Message-ID: <20100414171753.9792C39CB40@scipy.org> Author: fperez Date: 2010-04-14 12:17:53 -0500 (Wed, 14 Apr 2010) New Revision: 8333 Modified: trunk/doc/sphinxext/numpydoc.py Log: Fix bug where __init__ was accessed for objects that might not have it. Modified: trunk/doc/sphinxext/numpydoc.py =================================================================== --- trunk/doc/sphinxext/numpydoc.py 2010-04-13 16:25:36 UTC (rev 8332) +++ trunk/doc/sphinxext/numpydoc.py 2010-04-14 17:17:53 UTC (rev 8333) @@ -73,7 +73,8 @@ def mangle_signature(app, what, name, obj, options, sig, retann): # Do not try to inspect classes that don't define `__init__` if (inspect.isclass(obj) and - 'initializes x; see ' in pydoc.getdoc(obj.__init__)): + (not hasattr(obj, '__init__') or + 'initializes x; see ' in pydoc.getdoc(obj.__init__))): return '', '' if not (callable(obj) or hasattr(obj, '__argspec_is_invalid_')): return From numpy-svn at scipy.org Wed Apr 14 13:24:50 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Wed, 14 Apr 2010 12:24:50 -0500 (CDT) Subject: [Numpy-svn] r8334 - in trunk/numpy/lib: . tests Message-ID: <20100414172450.AE9D639CB4F@scipy.org> Author: charris Date: 2010-04-14 12:24:50 -0500 (Wed, 14 Apr 2010) New Revision: 8334 Modified: trunk/numpy/lib/tests/test_ufunclike.py trunk/numpy/lib/ufunclike.py Log: BUG: Use deprecated decorator in testing ufunclike.log2. Modified: trunk/numpy/lib/tests/test_ufunclike.py =================================================================== --- trunk/numpy/lib/tests/test_ufunclike.py 2010-04-14 17:17:53 UTC (rev 8333) +++ trunk/numpy/lib/tests/test_ufunclike.py 2010-04-14 17:24:50 UTC (rev 8334) @@ -1,7 +1,7 @@ from numpy.testing import * import numpy.core as nx import numpy.lib.ufunclike as ufl -import warnings +from numpy.testing.decorators import deprecated class TestUfunclike(TestCase): @@ -27,19 +27,16 @@ assert_equal(res, tgt) assert_equal(out, tgt) + @deprecated() def test_log2(self): a = nx.array([4.5, 2.3, 6.5]) out = nx.zeros(a.shape, float) tgt = nx.array([2.169925, 1.20163386, 2.70043972]) - try: - warnings.filterwarnings("ignore",category=DeprecationWarning) - res = ufl.log2(a) - assert_almost_equal(res, tgt) - res = ufl.log2(a, out) - assert_almost_equal(res, tgt) - assert_almost_equal(out, tgt) - except DeprecationWarning: - pass + res = ufl.log2(a) + assert_almost_equal(res, tgt) + res = ufl.log2(a, out) + assert_almost_equal(res, tgt) + assert_almost_equal(out, tgt) def test_fix(self): a = nx.array([[1.0, 1.1, 1.5, 1.8], [-1.0, -1.1, -1.5, -1.8]]) Modified: trunk/numpy/lib/ufunclike.py =================================================================== --- trunk/numpy/lib/ufunclike.py 2010-04-14 17:17:53 UTC (rev 8333) +++ trunk/numpy/lib/ufunclike.py 2010-04-14 17:24:50 UTC (rev 8334) @@ -5,7 +5,6 @@ __all__ = ['fix', 'isneginf', 'isposinf'] import numpy.core.numeric as nx -import warnings def fix(x, y=None): """ @@ -174,6 +173,7 @@ nx.logical_and(nx.isinf(x), nx.signbit(x), y) return y + _log2 = nx.log(2) def log2(x, y=None): """ @@ -203,6 +203,7 @@ array([ NaN, 1., 2.]) """ + import warnings msg = "numpy.lib.log2 is deprecated, use np.log2 instead." warnings.warn(msg, DeprecationWarning) From numpy-svn at scipy.org Sun Apr 18 04:46:39 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 18 Apr 2010 03:46:39 -0500 (CDT) Subject: [Numpy-svn] r8335 - branches/1.4.x Message-ID: <20100418084639.AC15439C4B4@scipy.org> Author: rgommers Date: 2010-04-18 03:46:39 -0500 (Sun, 18 Apr 2010) New Revision: 8335 Modified: branches/1.4.x/pavement.py Log: BUG: doc build needs access to site-packages to find MPL. Modified: branches/1.4.x/pavement.py =================================================================== --- branches/1.4.x/pavement.py 2010-04-14 17:24:50 UTC (rev 8334) +++ branches/1.4.x/pavement.py 2010-04-18 08:46:39 UTC (rev 8335) @@ -88,12 +88,13 @@ SUPERPACK_BINDIR = os.path.join(SUPERPACK_BUILD, 'binaries') options(bootstrap=Bunch(bootstrap_dir="bootstrap"), - virtualenv=Bunch(packages_to_install=["sphinx", "numpydoc"], no_site_packages=True), + virtualenv=Bunch(packages_to_install=["sphinx", "numpydoc"], + no_site_packages=False), sphinx=Bunch(builddir="build", sourcedir="source", docroot='doc'), superpack=Bunch(builddir="build-superpack"), installers=Bunch(releasedir="release", installersdir=os.path.join("release", "installers")), - doc=Bunch(doc_root="doc", + doc=Bunch(doc_root="doc", sdir=os.path.join("doc", "source"), bdir=os.path.join("doc", "build"), bdir_latex=os.path.join("doc", "build", "latex"), @@ -208,7 +209,7 @@ copy_bdist("sse2") bdist_wininst_arch(pyver, 'sse3') copy_bdist("sse3") - + idirs = options.installers.installersdir pyver = options.python_version prepare_nsis_script(pyver, FULLVERSION) @@ -275,8 +276,8 @@ options.virtualenv.script_name = os.path.join(options.bootstrap_dir, bscript) - options.virtualenv.no_site_packages = True - options.bootstrap.no_site_packages = True + options.virtualenv.no_site_packages = False + options.bootstrap.no_site_packages = False call_task('paver.virtual.bootstrap') sh('cd %s; %s %s' % (bdir, sys.executable, bscript)) From numpy-svn at scipy.org Sun Apr 18 04:46:52 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 18 Apr 2010 03:46:52 -0500 (CDT) Subject: [Numpy-svn] r8336 - branches/1.4.x Message-ID: <20100418084652.DBCDB39C4B4@scipy.org> Author: rgommers Date: 2010-04-18 03:46:52 -0500 (Sun, 18 Apr 2010) New Revision: 8336 Modified: branches/1.4.x/pavement.py Log: Make Wine paths a little less hardcoded. Modified: branches/1.4.x/pavement.py =================================================================== --- branches/1.4.x/pavement.py 2010-04-18 08:46:39 UTC (rev 8335) +++ branches/1.4.x/pavement.py 2010-04-18 08:46:52 UTC (rev 8336) @@ -118,8 +118,8 @@ if sys.platform =="darwin": WINDOWS_PYTHON = { - "2.6": ["wine", "/Users/david/.wine/drive_c/Python26/python.exe"], - "2.5": ["wine", "/Users/david/.wine/drive_c/Python25/python.exe"] + "2.6": ["wine", os.environ['HOME'] + "/.wine/drive_c/Python26/python.exe"], + "2.5": ["wine", os.environ['HOME'] + "/.wine/drive_c/Python25/python.exe"] } WINDOWS_ENV = os.environ WINDOWS_ENV["DYLD_FALLBACK_LIBRARY_PATH"] = "/usr/X11/lib:/usr/lib" @@ -135,8 +135,8 @@ MAKENSIS = ["makensis"] else: WINDOWS_PYTHON = { - "2.6": ["wine", "/home/david/.wine/drive_c/Python26/python.exe"], - "2.5": ["wine", "/home/david/.wine/drive_c/Python25/python.exe"] + "2.6": ["wine", os.environ['HOME'] + "/.wine/drive_c/Python26/python.exe"], + "2.5": ["wine", os.environ['HOME'] + "/.wine/drive_c/Python25/python.exe"] } WINDOWS_ENV = os.environ MAKENSIS = ["wine", "makensis"] From numpy-svn at scipy.org Sun Apr 18 04:47:06 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 18 Apr 2010 03:47:06 -0500 (CDT) Subject: [Numpy-svn] r8337 - branches/1.4.x Message-ID: <20100418084706.E44BE39C4B4@scipy.org> Author: rgommers Date: 2010-04-18 03:47:06 -0500 (Sun, 18 Apr 2010) New Revision: 8337 Modified: branches/1.4.x/pavement.py Log: REL: Change path to Atlas libs. Modified: branches/1.4.x/pavement.py =================================================================== --- branches/1.4.x/pavement.py 2010-04-18 08:46:52 UTC (rev 8336) +++ branches/1.4.x/pavement.py 2010-04-18 08:47:06 UTC (rev 8337) @@ -110,9 +110,9 @@ "2.6": ["/Library/Frameworks/Python.framework/Versions/2.6/bin/python"] } -SSE3_CFG = {'ATLAS': r'C:\local\lib\yop\sse3'} -SSE2_CFG = {'ATLAS': r'C:\local\lib\yop\sse2'} -NOSSE_CFG = {'BLAS': r'C:\local\lib\yop\nosse', 'LAPACK': r'C:\local\lib\yop\nosse'} +SSE3_CFG = {'ATLAS': r'C:\local\lib\sse3'} +SSE2_CFG = {'ATLAS': r'C:\local\lib\sse2'} +NOSSE_CFG = {'BLAS': r'C:\local\lib\nosse', 'LAPACK': r'C:\local\lib\nosse'} SITECFG = {"sse2" : SSE2_CFG, "sse3" : SSE3_CFG, "nosse" : NOSSE_CFG} From numpy-svn at scipy.org Sun Apr 18 04:47:19 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 18 Apr 2010 03:47:19 -0500 (CDT) Subject: [Numpy-svn] r8338 - branches/1.4.x Message-ID: <20100418084719.9338839C4B4@scipy.org> Author: rgommers Date: 2010-04-18 03:47:19 -0500 (Sun, 18 Apr 2010) New Revision: 8338 Modified: branches/1.4.x/setup.py Log: REL: Set version number to 1.4.1rc1 Modified: branches/1.4.x/setup.py =================================================================== --- branches/1.4.x/setup.py 2010-04-18 08:47:06 UTC (rev 8337) +++ branches/1.4.x/setup.py 2010-04-18 08:47:19 UTC (rev 8338) @@ -50,9 +50,9 @@ PLATFORMS = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"] MAJOR = 1 MINOR = 4 -MICRO = 0 +MICRO = 1 ISRELEASED = True -VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO) +VERSION = '%d.%d.%drc1' % (MAJOR, MINOR, MICRO) # Return the svn version as a string, raise a ValueError otherwise def svn_version(): From numpy-svn at scipy.org Sun Apr 18 05:23:21 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 18 Apr 2010 04:23:21 -0500 (CDT) Subject: [Numpy-svn] r8339 - tags Message-ID: <20100418092321.85DBC39C4B4@scipy.org> Author: rgommers Date: 2010-04-18 04:23:21 -0500 (Sun, 18 Apr 2010) New Revision: 8339 Added: tags/1.4.1rc1/ Log: Create tag 1.4.1rc1 Copied: tags/1.4.1rc1 (from rev 8338, branches/1.4.x) From numpy-svn at scipy.org Sun Apr 18 05:31:44 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 18 Apr 2010 04:31:44 -0500 (CDT) Subject: [Numpy-svn] r8340 - branches/1.4.x Message-ID: <20100418093144.6A95D39C4B4@scipy.org> Author: rgommers Date: 2010-04-18 04:31:44 -0500 (Sun, 18 Apr 2010) New Revision: 8340 Modified: branches/1.4.x/pavement.py Log: Fix typo. Modified: branches/1.4.x/pavement.py =================================================================== --- branches/1.4.x/pavement.py 2010-04-18 09:23:21 UTC (rev 8339) +++ branches/1.4.x/pavement.py 2010-04-18 09:31:44 UTC (rev 8340) @@ -15,7 +15,7 @@ # remove build dir, and everything generated by previous paver calls # (included generated installers). Use with care ! paver nuke - paver bootstrap && source boostrap/bin/activate + paver bootstrap && source bootstrap/bin/activate # Installing numpy is necessary to build the correct documentation (because # of autodoc) python setupegg.py install From numpy-svn at scipy.org Sun Apr 18 05:34:58 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 18 Apr 2010 04:34:58 -0500 (CDT) Subject: [Numpy-svn] r8341 - branches/1.4.x/numpy/lib Message-ID: <20100418093458.2782939C4B4@scipy.org> Author: rgommers Date: 2010-04-18 04:34:57 -0500 (Sun, 18 Apr 2010) New Revision: 8341 Modified: branches/1.4.x/numpy/lib/function_base.py Log: Update the histogram warning - the 'new' keyword will be removed in 2.0. Rationale: It was not removed in 1.4.0, so should not be removed now. Modified: branches/1.4.x/numpy/lib/function_base.py =================================================================== --- branches/1.4.x/numpy/lib/function_base.py 2010-04-18 09:31:44 UTC (rev 8340) +++ branches/1.4.x/numpy/lib/function_base.py 2010-04-18 09:34:57 UTC (rev 8341) @@ -78,7 +78,7 @@ * False : the old behaviour is used and a DeprecationWarning is raised. As of NumPy 1.3, this keyword should not be used explicitly since it - will disappear in NumPy 1.4. + will disappear in NumPy 2.0. Returns ------- @@ -128,7 +128,7 @@ if new == False: warnings.warn(""" The histogram semantics being used is now deprecated and - will disappear in NumPy 1.4. Please update your code to + will disappear in NumPy 2.0. Please update your code to use the default semantics. """, DeprecationWarning) @@ -181,7 +181,7 @@ if new is True: warnings.warn(""" The new semantics of histogram is now the default and the `new` - keyword will be removed in NumPy 1.4. + keyword will be removed in NumPy 2.0. """, Warning) a = asarray(a) if weights is not None: @@ -2051,7 +2051,7 @@ >>> plt.ylabel("Amplitude") >>> plt.xlabel("Sample") >>> plt.show() - + >>> plt.figure() >>> A = fft(window, 2048) / 25.5 >>> mag = abs(fftshift(A)) @@ -2150,7 +2150,7 @@ >>> plt.ylabel("Amplitude") >>> plt.xlabel("Sample") >>> plt.show() - + >>> plt.figure() >>> A = fft(window, 2048) / 25.5 >>> mag = abs(fftshift(A)) From numpy-svn at scipy.org Sun Apr 18 05:36:31 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 18 Apr 2010 04:36:31 -0500 (CDT) Subject: [Numpy-svn] r8342 - branches/1.4.x Message-ID: <20100418093631.421C639C4B4@scipy.org> Author: rgommers Date: 2010-04-18 04:36:28 -0500 (Sun, 18 Apr 2010) New Revision: 8342 Modified: branches/1.4.x/release.sh Log: REL: Remove 64-bit flags from release script. Modified: branches/1.4.x/release.sh =================================================================== --- branches/1.4.x/release.sh 2010-04-18 09:34:57 UTC (rev 8341) +++ branches/1.4.x/release.sh 2010-04-18 09:36:28 UTC (rev 8342) @@ -2,7 +2,7 @@ # script to build tarballs, mac os x and windows installers on mac os x paver bootstrap source bootstrap/bin/activate -CFLAGS="-arch x86_64" FFLAGS="-arch x86_64" python setupsconsegg.py install +python setupegg.py install paver sdist paver dmg -p 2.5 paver dmg -p 2.6 From numpy-svn at scipy.org Sun Apr 18 05:37:30 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 18 Apr 2010 04:37:30 -0500 (CDT) Subject: [Numpy-svn] r8343 - branches/1.4.x Message-ID: <20100418093730.ED8ED39C4B4@scipy.org> Author: rgommers Date: 2010-04-18 04:37:30 -0500 (Sun, 18 Apr 2010) New Revision: 8343 Modified: branches/1.4.x/setup.py Log: REL: Change version number to 1.4.1rc2. Modified: branches/1.4.x/setup.py =================================================================== --- branches/1.4.x/setup.py 2010-04-18 09:36:28 UTC (rev 8342) +++ branches/1.4.x/setup.py 2010-04-18 09:37:30 UTC (rev 8343) @@ -52,7 +52,7 @@ MINOR = 4 MICRO = 1 ISRELEASED = True -VERSION = '%d.%d.%drc1' % (MAJOR, MINOR, MICRO) +VERSION = '%d.%d.%drc2' % (MAJOR, MINOR, MICRO) # Return the svn version as a string, raise a ValueError otherwise def svn_version(): From numpy-svn at scipy.org Sun Apr 18 05:39:42 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 18 Apr 2010 04:39:42 -0500 (CDT) Subject: [Numpy-svn] r8344 - in branches/1.4.x: . doc/release Message-ID: <20100418093942.88F8939C4B4@scipy.org> Author: rgommers Date: 2010-04-18 04:39:42 -0500 (Sun, 18 Apr 2010) New Revision: 8344 Added: branches/1.4.x/doc/release/1.4.1-notes.rst Modified: branches/1.4.x/pavement.py Log: Add 1.4.1 release notes. Added: branches/1.4.x/doc/release/1.4.1-notes.rst =================================================================== --- branches/1.4.x/doc/release/1.4.1-notes.rst (rev 0) +++ branches/1.4.x/doc/release/1.4.1-notes.rst 2010-04-18 09:39:42 UTC (rev 8344) @@ -0,0 +1,17 @@ +========================= +NumPy 1.4.1 Release Notes +========================= + +This minor release removes datetime support, which fixes the binary +incompatibility issues with SciPy and other packages. It also includes several +bug fixes. No new features are introduced. + +Bugs fixed +---------- +- #1336: Fix for 1299 exposes Bus error on Sparc +- #1379: CPU ID not set correctly on PARISC +- #1388: frombuffer calls PyErr_Format without throwing an error +- log1p +- kaiser for M=1 +- paver execution on Windows 7 for Python 2.6 +- several fixes to Chebyshev and Polynomial Modified: branches/1.4.x/pavement.py =================================================================== --- branches/1.4.x/pavement.py 2010-04-18 09:37:30 UTC (rev 8343) +++ branches/1.4.x/pavement.py 2010-04-18 09:39:42 UTC (rev 8344) @@ -144,7 +144,7 @@ # Start/end of the log (from git) LOG_START = 'svn/tags/1.3.0' LOG_END = '1.4.x' -RELEASE_NOTES = 'doc/release/1.4.0-notes.rst' +RELEASE_NOTES = 'doc/release/1.4.1-notes.rst' #------------------- # Windows installers From numpy-svn at scipy.org Sun Apr 18 05:40:57 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 18 Apr 2010 04:40:57 -0500 (CDT) Subject: [Numpy-svn] r8345 - tags Message-ID: <20100418094057.EC93839C4B4@scipy.org> Author: rgommers Date: 2010-04-18 04:40:57 -0500 (Sun, 18 Apr 2010) New Revision: 8345 Added: tags/1.4.1rc2/ Log: Create tag 1.4.1rc2 Copied: tags/1.4.1rc2 (from rev 8344, branches/1.4.x) From numpy-svn at scipy.org Sun Apr 18 06:48:14 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 18 Apr 2010 05:48:14 -0500 (CDT) Subject: [Numpy-svn] r8346 - branches/1.4.x/numpy/core/tests Message-ID: <20100418104814.90D6D39C4B4@scipy.org> Author: rgommers Date: 2010-04-18 05:48:14 -0500 (Sun, 18 Apr 2010) New Revision: 8346 Modified: branches/1.4.x/numpy/core/tests/test_umath_complex.py Log: TST: Mark TestClog as known failure. Has been failing on Windows for a while. Modified: branches/1.4.x/numpy/core/tests/test_umath_complex.py =================================================================== --- branches/1.4.x/numpy/core/tests/test_umath_complex.py 2010-04-18 09:40:57 UTC (rev 8345) +++ branches/1.4.x/numpy/core/tests/test_umath_complex.py 2010-04-18 10:48:14 UTC (rev 8346) @@ -8,7 +8,7 @@ class TestCexp(object): def test_simple(self): - check = check_complex_value + check = check_complex_value f = np.exp yield check, f, 1, 0, np.exp(1), 0, False @@ -20,7 +20,7 @@ def test_special_values(self): # C99: Section G 6.3.1 - check = check_complex_value + check = check_complex_value f = np.exp # cexp(+-0 + 0i) is 1 + 0i @@ -111,6 +111,7 @@ for i in range(len(x)): assert_almost_equal(y[i], y_r[i]) + @dec.knownfailureif(True, "clog(- inf + i inf) fails on Windows.") def test_special_values(self): xl = [] yl = [] @@ -248,7 +249,7 @@ # _check_branch_cut(f, -1, 0, 1, -1) def test_special_values(self): - check = check_complex_value + check = check_complex_value f = np.sqrt # C99: Sec G 6.4.2 From numpy-svn at scipy.org Sun Apr 18 06:48:30 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 18 Apr 2010 05:48:30 -0500 (CDT) Subject: [Numpy-svn] r8347 - branches/1.4.x/numpy/distutils Message-ID: <20100418104830.446AF39C4B4@scipy.org> Author: rgommers Date: 2010-04-18 05:48:30 -0500 (Sun, 18 Apr 2010) New Revision: 8347 Modified: branches/1.4.x/numpy/distutils/ccompiler.py Log: Backport r8260. Fix to make distutils work with Python 2.7b1. Modified: branches/1.4.x/numpy/distutils/ccompiler.py =================================================================== --- branches/1.4.x/numpy/distutils/ccompiler.py 2010-04-18 10:48:14 UTC (rev 8346) +++ branches/1.4.x/numpy/distutils/ccompiler.py 2010-04-18 10:48:30 UTC (rev 8347) @@ -2,15 +2,20 @@ import os import sys import new +from copy import copy from distutils.ccompiler import * from distutils import ccompiler +from distutils.errors import DistutilsExecError, DistutilsModuleError, \ + DistutilsPlatformError + from distutils.sysconfig import customize_compiler from distutils.version import LooseVersion from numpy.distutils import log from numpy.distutils.exec_command import exec_command -from numpy.distutils.misc_util import cyg2win32, is_sequence, mingw32, quote_args, msvc_on_amd64 +from numpy.distutils.misc_util import cyg2win32, is_sequence, mingw32, \ + quote_args, msvc_on_amd64 # hack to set compiler optimizing options. Needs to integrated with something. import distutils.sysconfig From numpy-svn at scipy.org Sun Apr 18 06:48:42 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 18 Apr 2010 05:48:42 -0500 (CDT) Subject: [Numpy-svn] r8348 - branches/1.4.x Message-ID: <20100418104842.9B96C39C4B4@scipy.org> Author: rgommers Date: 2010-04-18 05:48:42 -0500 (Sun, 18 Apr 2010) New Revision: 8348 Modified: branches/1.4.x/setup.py Log: Update version number to 1.4.1rc3. Modified: branches/1.4.x/setup.py =================================================================== --- branches/1.4.x/setup.py 2010-04-18 10:48:30 UTC (rev 8347) +++ branches/1.4.x/setup.py 2010-04-18 10:48:42 UTC (rev 8348) @@ -52,7 +52,7 @@ MINOR = 4 MICRO = 1 ISRELEASED = True -VERSION = '%d.%d.%drc2' % (MAJOR, MINOR, MICRO) +VERSION = '%d.%d.%drc3' % (MAJOR, MINOR, MICRO) # Return the svn version as a string, raise a ValueError otherwise def svn_version(): From numpy-svn at scipy.org Sun Apr 18 08:42:11 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 18 Apr 2010 07:42:11 -0500 (CDT) Subject: [Numpy-svn] r8349 - branches/1.4.x Message-ID: <20100418124211.2793A39CB0E@scipy.org> Author: rgommers Date: 2010-04-18 07:42:10 -0500 (Sun, 18 Apr 2010) New Revision: 8349 Modified: branches/1.4.x/pavement.py Log: REL: update Changelog start and end points. Modified: branches/1.4.x/pavement.py =================================================================== --- branches/1.4.x/pavement.py 2010-04-18 10:48:42 UTC (rev 8348) +++ branches/1.4.x/pavement.py 2010-04-18 12:42:10 UTC (rev 8349) @@ -142,8 +142,8 @@ MAKENSIS = ["wine", "makensis"] # Start/end of the log (from git) -LOG_START = 'svn/tags/1.3.0' -LOG_END = '1.4.x' +LOG_START = 'svn/tags/1.4.0' +LOG_END = 'svn/1.4.x' RELEASE_NOTES = 'doc/release/1.4.1-notes.rst' #------------------- From numpy-svn at scipy.org Sun Apr 18 08:52:07 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 18 Apr 2010 07:52:07 -0500 (CDT) Subject: [Numpy-svn] r8350 - tags Message-ID: <20100418125207.E646B39CB0E@scipy.org> Author: rgommers Date: 2010-04-18 07:52:07 -0500 (Sun, 18 Apr 2010) New Revision: 8350 Added: tags/1.4.1rc3/ Log: Create tag 1.4.1rc3 Copied: tags/1.4.1rc3 (from rev 8349, branches/1.4.x) From numpy-svn at scipy.org Sun Apr 18 10:02:31 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 18 Apr 2010 09:02:31 -0500 (CDT) Subject: [Numpy-svn] r8351 - in trunk/numpy/lib: . tests Message-ID: <20100418140231.9A6BB39CAF7@scipy.org> Author: darren.dale Date: 2010-04-18 09:02:31 -0500 (Sun, 18 Apr 2010) New Revision: 8351 Modified: trunk/numpy/lib/tests/test_ufunclike.py trunk/numpy/lib/ufunclike.py Log: correct a bug in fix() that was introduced in r8293 Modified: trunk/numpy/lib/tests/test_ufunclike.py =================================================================== --- trunk/numpy/lib/tests/test_ufunclike.py 2010-04-18 12:52:07 UTC (rev 8350) +++ trunk/numpy/lib/tests/test_ufunclike.py 2010-04-18 14:02:31 UTC (rev 8351) @@ -48,6 +48,7 @@ res = ufl.fix(a, out) assert_equal(res, tgt) assert_equal(out, tgt) + assert_equal(ufl.fix(3.14), 3) def test_fix_with_subclass(self): class MyArray(nx.ndarray): Modified: trunk/numpy/lib/ufunclike.py =================================================================== --- trunk/numpy/lib/ufunclike.py 2010-04-18 12:52:07 UTC (rev 8350) +++ trunk/numpy/lib/ufunclike.py 2010-04-18 14:02:31 UTC (rev 8351) @@ -44,7 +44,7 @@ y1 = nx.floor(x) y2 = nx.ceil(x) if y is None: - y = y1 + y = nx.asanyarray(y1) y[...] = nx.where(x >= 0, y1, y2) return y From numpy-svn at scipy.org Thu Apr 22 06:35:16 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Thu, 22 Apr 2010 05:35:16 -0500 (CDT) Subject: [Numpy-svn] r8352 - branches/1.4.x Message-ID: <20100422103516.DFC7A39CAE6@scipy.org> Author: rgommers Date: 2010-04-22 05:35:16 -0500 (Thu, 22 Apr 2010) New Revision: 8352 Modified: branches/1.4.x/setup.py Log: REL: Set version to 1.4.1. Modified: branches/1.4.x/setup.py =================================================================== --- branches/1.4.x/setup.py 2010-04-18 14:02:31 UTC (rev 8351) +++ branches/1.4.x/setup.py 2010-04-22 10:35:16 UTC (rev 8352) @@ -52,7 +52,7 @@ MINOR = 4 MICRO = 1 ISRELEASED = True -VERSION = '%d.%d.%drc3' % (MAJOR, MINOR, MICRO) +VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO) # Return the svn version as a string, raise a ValueError otherwise def svn_version(): From numpy-svn at scipy.org Thu Apr 22 06:39:32 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Thu, 22 Apr 2010 05:39:32 -0500 (CDT) Subject: [Numpy-svn] r8353 - tags Message-ID: <20100422103932.7EA8239CAE6@scipy.org> Author: rgommers Date: 2010-04-22 05:39:32 -0500 (Thu, 22 Apr 2010) New Revision: 8353 Added: tags/1.4.1/ Log: Create tag 1.4.1 Copied: tags/1.4.1 (from rev 8352, branches/1.4.x) From numpy-svn at scipy.org Thu Apr 22 11:55:48 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Thu, 22 Apr 2010 10:55:48 -0500 (CDT) Subject: [Numpy-svn] r8354 - branches Message-ID: <20100422155548.D468539CAE6@scipy.org> Author: oliphant Date: 2010-04-22 10:55:48 -0500 (Thu, 22 Apr 2010) New Revision: 8354 Added: branches/refactor/ Log: Branch to re-factor NumPy to separte out CPython interface Copied: branches/refactor (from rev 8353, trunk) From numpy-svn at scipy.org Sat Apr 24 21:29:20 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 24 Apr 2010 20:29:20 -0500 (CDT) Subject: [Numpy-svn] r8355 - trunk/numpy/core/tests Message-ID: <20100425012920.0ADDF39CAF3@scipy.org> Author: charris Date: 2010-04-24 20:29:19 -0500 (Sat, 24 Apr 2010) New Revision: 8355 Modified: trunk/numpy/core/tests/test_regression.py Log: ENH: Apply old patch hanging around in my directory. I don't recall where it came from, but it seems appropriate. Modified: trunk/numpy/core/tests/test_regression.py =================================================================== --- trunk/numpy/core/tests/test_regression.py 2010-04-22 15:55:48 UTC (rev 8354) +++ trunk/numpy/core/tests/test_regression.py 2010-04-25 01:29:19 UTC (rev 8355) @@ -1287,5 +1287,11 @@ # Check if log1p is behaving on 32 bit intel systems. assert_(np.isfinite(np.log1p(np.exp2(-53)))) + def test_fromiter_comparison(self, level=rlevel): + a = np.fromiter(range(10), dtype='b') + b = np.fromiter(range(10), dtype='B') + assert np.alltrue(a == np.array([0,1,2,3,4,5,6,7,8,9])) + assert np.alltrue(b == np.array([0,1,2,3,4,5,6,7,8,9])) + if __name__ == "__main__": run_module_suite() From numpy-svn at scipy.org Sun Apr 25 00:30:54 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 24 Apr 2010 23:30:54 -0500 (CDT) Subject: [Numpy-svn] r8356 - trunk/numpy/lib Message-ID: <20100425043054.798FF39CAED@scipy.org> Author: charris Date: 2010-04-24 23:30:54 -0500 (Sat, 24 Apr 2010) New Revision: 8356 Modified: trunk/numpy/lib/utils.py Log: FIX: Workaround python3.1 callable not working with PyCapsule. Modified: trunk/numpy/lib/utils.py =================================================================== --- trunk/numpy/lib/utils.py 2010-04-25 01:29:19 UTC (rev 8355) +++ trunk/numpy/lib/utils.py 2010-04-25 04:30:54 UTC (rev 8356) @@ -940,7 +940,10 @@ kind = "class" for n, v in _getmembers(item): stack.append(("%s.%s" % (name, n), v)) - elif callable(item): + # FIXME later: workaround python3.1 capsule callable bug + # by using old version of callable. + # elif callable(item): + elif hasattr(item, "__call__"): kind = "func" doc = inspect.getdoc(item) From numpy-svn at scipy.org Sun Apr 25 00:30:57 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 24 Apr 2010 23:30:57 -0500 (CDT) Subject: [Numpy-svn] r8357 - trunk/numpy/core/src/private Message-ID: <20100425043057.6021939CAED@scipy.org> Author: charris Date: 2010-04-24 23:30:57 -0500 (Sat, 24 Apr 2010) New Revision: 8357 Modified: trunk/numpy/core/src/private/npy_3kcompat.h Log: BUG: Fix wrong destructor type in NpyCapsule_FromVoidPtrAndDesc. Modified: trunk/numpy/core/src/private/npy_3kcompat.h =================================================================== --- trunk/numpy/core/src/private/npy_3kcompat.h 2010-04-25 04:30:54 UTC (rev 8356) +++ trunk/numpy/core/src/private/npy_3kcompat.h 2010-04-25 04:30:57 UTC (rev 8357) @@ -274,7 +274,8 @@ } static NPY_INLINE PyObject * -NpyCapsule_FromVoidPtrAndDesc(void *ptr, void* context, void (*dtor)(void *)) +NpyCapsule_FromVoidPtrAndDesc(void *ptr, void* context, + void (*dtor)(void *, void *)) { return PyCObject_FromVoidPtrAndDesc(ptr, context, dtor); } From numpy-svn at scipy.org Sun Apr 25 00:31:00 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 24 Apr 2010 23:31:00 -0500 (CDT) Subject: [Numpy-svn] r8358 - trunk/numpy/core/src/multiarray Message-ID: <20100425043100.2FE3039CAED@scipy.org> Author: charris Date: 2010-04-24 23:31:00 -0500 (Sat, 24 Apr 2010) New Revision: 8358 Modified: trunk/numpy/core/src/multiarray/buffer.c Log: BUG: Fix missing "%s" in error message format. Remove unused variable. Modified: trunk/numpy/core/src/multiarray/buffer.c =================================================================== --- trunk/numpy/core/src/multiarray/buffer.c 2010-04-25 04:30:57 UTC (rev 8357) +++ trunk/numpy/core/src/multiarray/buffer.c 2010-04-25 04:31:00 UTC (rev 8358) @@ -193,7 +193,7 @@ } if (descr->subarray) { - PyObject *item, *repr; + PyObject *item; Py_ssize_t total_count = 1; Py_ssize_t dim_size; char buf[128]; @@ -758,7 +758,7 @@ if (!PyArray_DescrCheck(descr)) { PyErr_Format(PyExc_RuntimeError, "internal error: numpy.core._internal._dtype_from_pep3118 " - "did not return a valid dtype", buf); + "did not return a valid dtype, got %s", buf); return NULL; } return (PyArray_Descr*)descr; From numpy-svn at scipy.org Sun Apr 25 00:31:03 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sat, 24 Apr 2010 23:31:03 -0500 (CDT) Subject: [Numpy-svn] r8359 - in trunk/numpy: core/src core/src/multiarray lib/src Message-ID: <20100425043103.A885E39CAED@scipy.org> Author: charris Date: 2010-04-24 23:31:03 -0500 (Sat, 24 Apr 2010) New Revision: 8359 Modified: trunk/numpy/core/src/multiarray/descriptor.c trunk/numpy/core/src/scalarmathmodule.c.src trunk/numpy/lib/src/_compiled_base.c Log: ENH: Remove some unused variable warnings. Modified: trunk/numpy/core/src/multiarray/descriptor.c =================================================================== --- trunk/numpy/core/src/multiarray/descriptor.c 2010-04-25 04:31:00 UTC (rev 8358) +++ trunk/numpy/core/src/multiarray/descriptor.c 2010-04-25 04:31:03 UTC (rev 8359) @@ -1629,7 +1629,7 @@ { int len; PyTypeObject *typeobj = self->typeobj; - PyObject *res, *tmp; + PyObject *res; char *s; /* fixme: not reentrant */ static int prefix_len = 0; @@ -2800,10 +2800,9 @@ PyObject *retval; if (!self->names) { - PyObject *astr, *bstr; - astr = arraydescr_str(self); + PyObject *astr = arraydescr_str(self); #if defined(NPY_PY3K) - bstr = PyUnicode_AsUnicodeEscapeString(astr); + PyObject *bstr = PyUnicode_AsUnicodeEscapeString(astr); Py_DECREF(astr); astr = bstr; #endif Modified: trunk/numpy/core/src/scalarmathmodule.c.src =================================================================== --- trunk/numpy/core/src/scalarmathmodule.c.src 2010-04-25 04:31:00 UTC (rev 8358) +++ trunk/numpy/core/src/scalarmathmodule.c.src 2010-04-25 04:31:03 UTC (rev 8359) @@ -1490,10 +1490,8 @@ initscalarmath(void) #endif { - PyObject *m; - #if defined(NPY_PY3K) - m = PyModule_Create(&moduledef); + PyObject *m = PyModule_Create(&moduledef); if (!m) { return NULL; } Modified: trunk/numpy/lib/src/_compiled_base.c =================================================================== --- trunk/numpy/lib/src/_compiled_base.c 2010-04-25 04:31:00 UTC (rev 8358) +++ trunk/numpy/lib/src/_compiled_base.c 2010-04-25 04:31:03 UTC (rev 8359) @@ -559,7 +559,7 @@ arr_add_docstring(PyObject *NPY_UNUSED(dummy), PyObject *args) { PyObject *obj; - PyObject *str, *tmp; + PyObject *str; char *docstr; static char *msg = "already has a docstring"; @@ -573,8 +573,7 @@ return NULL; } - tmp = PyUnicode_AsUTF8String(str); - docstr = PyBytes_AS_STRING(tmp); + docstr = PyBytes_AS_STRING(PyUnicode_AsUTF8String(str)); #else if (!PyArg_ParseTuple(args, "OO!", &obj, &PyString_Type, &str)) { return NULL; @@ -956,7 +955,7 @@ init_compiled_base(void) #endif { - PyObject *m, *d, *s; + PyObject *m, *d; #if defined(NPY_PY3K) m = PyModule_Create(&moduledef); From numpy-svn at scipy.org Sun Apr 25 05:57:19 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 25 Apr 2010 04:57:19 -0500 (CDT) Subject: [Numpy-svn] r8360 - in trunk/numpy: . core/src/multiarray core/tests Message-ID: <20100425095719.3397D39CBEE@scipy.org> Author: charris Date: 2010-04-25 04:57:19 -0500 (Sun, 25 Apr 2010) New Revision: 8360 Modified: trunk/numpy/add_newdocs.py trunk/numpy/core/src/multiarray/methods.c trunk/numpy/core/src/multiarray/shape.c trunk/numpy/core/tests/test_multiarray.py trunk/numpy/core/tests/test_regression.py Log: ENH: Remove order keyword from ndarray.resize. This is pretty much Scott Sinclair's patch from ticket #840. Modified: trunk/numpy/add_newdocs.py =================================================================== --- trunk/numpy/add_newdocs.py 2010-04-25 04:31:03 UTC (rev 8359) +++ trunk/numpy/add_newdocs.py 2010-04-25 09:57:19 UTC (rev 8360) @@ -2851,7 +2851,7 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('resize', """ - a.resize(new_shape, refcheck=True, order=False) + a.resize(new_shape, refcheck=True) Change shape and size of array in-place. @@ -2861,8 +2861,6 @@ Shape of resized array. refcheck : bool, optional If False, reference count will not be checked. Default is True. - order : bool, do not use. - A SystemError is raised when this parameter is specified. Returns ------- @@ -2901,27 +2899,13 @@ Shrinking an array: array is flattened (in the order that the data are stored in memory), resized, and reshaped: - >>> a = np.array([[0, 1], [2, 3]]) - >>> print a.flags - C_CONTIGUOUS : True - F_CONTIGUOUS : False - OWNDATA : True - WRITEABLE : True - ALIGNED : True - UPDATEIFCOPY : False + >>> a = np.array([[0, 1], [2, 3]], order='C') >>> a.resize((2, 1)) >>> a array([[0], [1]]) >>> a = np.array([[0, 1], [2, 3]], order='F') - >>> print a.flags - C_CONTIGUOUS : False - F_CONTIGUOUS : True - OWNDATA : True - WRITEABLE : True - ALIGNED : True - UPDATEIFCOPY : False >>> a.resize((2, 1)) >>> a array([[0], Modified: trunk/numpy/core/src/multiarray/methods.c =================================================================== --- trunk/numpy/core/src/multiarray/methods.c 2010-04-25 04:31:03 UTC (rev 8359) +++ trunk/numpy/core/src/multiarray/methods.c 2010-04-25 09:57:19 UTC (rev 8360) @@ -908,48 +908,20 @@ static PyObject * array_resize(PyArrayObject *self, PyObject *args, PyObject *kwds) { + static char *kwlist[] = {"refcheck", NULL}; PyArray_Dims newshape; PyObject *ret; - int n; int refcheck = 1; - PyArray_ORDER fortran = PyArray_ANYORDER; - if (kwds != NULL) { - PyObject *ref; - ref = PyDict_GetItemString(kwds, "refcheck"); - if (ref) { - refcheck = PyInt_AsLong(ref); - if (refcheck==-1 && PyErr_Occurred()) { - return NULL; - } - } - ref = PyDict_GetItemString(kwds, "order"); - if (ref != NULL || - (PyArray_OrderConverter(ref, &fortran) == PY_FAIL)) { - return NULL; - } + if (PyTuple_GET_ITEM(args, 0) == Py_None) { + Py_INCREF(Py_None); + return Py_None; } - n = PyTuple_Size(args); - if (n <= 1) { - if (PyTuple_GET_ITEM(args, 0) == Py_None) { - Py_INCREF(Py_None); - return Py_None; - } - if (!PyArg_ParseTuple(args, "O&", PyArray_IntpConverter, - &newshape)) { - return NULL; - } + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|i", kwlist, + PyArray_IntpConverter, &newshape, &refcheck)) { + return NULL; } - else { - if (!PyArray_IntpConverter(args, &newshape)) { - if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_TypeError, - "invalid shape"); - } - return NULL; - } - } - ret = PyArray_Resize(self, &newshape, refcheck, fortran); + ret = PyArray_Resize(self, &newshape, refcheck, PyArray_CORDER); PyDimMem_FREE(newshape.ptr); if (ret == NULL) { return NULL; Modified: trunk/numpy/core/src/multiarray/shape.c =================================================================== --- trunk/numpy/core/src/multiarray/shape.c 2010-04-25 04:31:03 UTC (rev 8359) +++ trunk/numpy/core/src/multiarray/shape.c 2010-04-25 09:57:19 UTC (rev 8360) @@ -54,30 +54,28 @@ if (!PyArray_ISONESEGMENT(self)) { PyErr_SetString(PyExc_ValueError, - "resize only works on single-segment arrays"); + "resize only works on single-segment arrays"); return NULL; } - if (fortran == PyArray_ANYORDER) { - fortran = PyArray_CORDER; - } if (self->descr->elsize == 0) { - PyErr_SetString(PyExc_ValueError, "Bad data-type size."); + PyErr_SetString(PyExc_ValueError, + "Bad data-type size."); return NULL; } newsize = 1; largest = MAX_INTP / self->descr->elsize; - for(k=0; k largest) { + if (newsize <= 0 || newsize > largest) { return PyErr_NoMemory(); } } @@ -86,8 +84,7 @@ if (oldsize != newsize) { if (!(self->flags & OWNDATA)) { PyErr_SetString(PyExc_ValueError, - "cannot resize this array: " \ - "it does not own its data"); + "cannot resize this array: it does not own its data"); return NULL; } @@ -97,13 +94,12 @@ else { refcnt = 1; } - if ((refcnt > 2) || (self->base != NULL) || - (self->weakreflist != NULL)) { + if ((refcnt > 2) + || (self->base != NULL) + || (self->weakreflist != NULL)) { PyErr_SetString(PyExc_ValueError, - "cannot resize an array that has "\ - "been referenced or is referencing\n"\ - "another array in this way. Use the "\ - "resize function"); + "cannot resize an array references or is referenced\n"\ + "by another array in this way. Use the resize function"); return NULL; } @@ -117,7 +113,7 @@ new_data = PyDataMem_RENEW(self->data, sd); if (new_data == NULL) { PyErr_SetString(PyExc_MemoryError, - "cannot allocate memory for array"); + "cannot allocate memory for array"); return NULL; } self->data = new_data; @@ -149,8 +145,7 @@ dimptr = PyDimMem_RENEW(self->dimensions, 2*new_nd); if (dimptr == NULL) { PyErr_SetString(PyExc_MemoryError, - "cannot allocate memory for array " \ - "(array may be corrupted)"); + "cannot allocate memory for array"); return NULL; } self->dimensions = dimptr; @@ -160,7 +155,7 @@ /* make new_strides variable */ sd = (size_t) self->descr->elsize; sd = (size_t) _array_fill_strides(new_strides, new_dimensions, new_nd, sd, - self->flags, &(self->flags)); + self->flags, &(self->flags)); memmove(self->dimensions, new_dimensions, new_nd*sizeof(intp)); memmove(self->strides, new_strides, new_nd*sizeof(intp)); Py_INCREF(Py_None); Modified: trunk/numpy/core/tests/test_multiarray.py =================================================================== --- trunk/numpy/core/tests/test_multiarray.py 2010-04-25 04:31:03 UTC (rev 8359) +++ trunk/numpy/core/tests/test_multiarray.py 2010-04-25 09:57:19 UTC (rev 8360) @@ -1050,7 +1050,17 @@ y = x self.assertRaises(ValueError,x.resize,(5,1)) + def test_int_shape(self): + x = np.eye(3) + x.resize(3) + assert_array_equal(x, np.eye(3)[0,:]) + def test_none_shape(self): + x = np.eye(3) + x.resize(None) + assert_array_equal(x, np.eye(3)) + + class TestRecord(TestCase): def test_field_rename(self): dt = np.dtype([('f',float),('i',int)]) Modified: trunk/numpy/core/tests/test_regression.py =================================================================== --- trunk/numpy/core/tests/test_regression.py 2010-04-25 04:31:03 UTC (rev 8359) +++ trunk/numpy/core/tests/test_regression.py 2010-04-25 09:57:19 UTC (rev 8360) @@ -1036,6 +1036,11 @@ assert c.dtype == object assert d.dtype == object + def test_array_resize_method_system_error(self): + """Ticket #840 - order should be an invalid keyword.""" + x = np.array([[0,1],[2,3]]) + self.assertRaises(TypeError, x.resize, (2,2), order='C') + def test_for_zero_length_in_choose(self, level=rlevel): "Ticket #882" a = np.array(1) From numpy-svn at scipy.org Sun Apr 25 10:50:14 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 25 Apr 2010 09:50:14 -0500 (CDT) Subject: [Numpy-svn] r8361 - trunk/numpy/core/src/multiarray Message-ID: <20100425145014.71E1139CB14@scipy.org> Author: charris Date: 2010-04-25 09:50:14 -0500 (Sun, 25 Apr 2010) New Revision: 8361 Modified: trunk/numpy/core/src/multiarray/methods.c Log: BUG: Fix the fix so resize works like it is supposed to. Modified: trunk/numpy/core/src/multiarray/methods.c =================================================================== --- trunk/numpy/core/src/multiarray/methods.c 2010-04-25 09:57:19 UTC (rev 8360) +++ trunk/numpy/core/src/multiarray/methods.c 2010-04-25 14:50:14 UTC (rev 8361) @@ -904,23 +904,42 @@ return PyArray_NewCopy(self, fortran); } - +#include static PyObject * array_resize(PyArrayObject *self, PyObject *args, PyObject *kwds) { static char *kwlist[] = {"refcheck", NULL}; + intp size = PyTuple_Size(args); + int refcheck = 1; PyArray_Dims newshape; PyObject *ret; - int refcheck = 1; - if (PyTuple_GET_ITEM(args, 0) == Py_None) { + + if (kwds != NULL) { + PyObject *tmp = PyTuple_New(0); + if (!PyArg_ParseTupleAndKeywords(tmp, kwds, "|i", kwlist, &refcheck)) { + Py_XDECREF(tmp); + return NULL; + } + Py_DECREF(tmp); + } + + if (size == 0) { Py_INCREF(Py_None); return Py_None; } - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|i", kwlist, - PyArray_IntpConverter, &newshape, &refcheck)) { - return NULL; + else if (size == 1) { + PyObject *obj = PyTuple_GET_ITEM(args, 0); + if (obj == Py_None) { + Py_INCREF(Py_None); + return Py_None; + } + PyArray_IntpConverter(obj, &newshape); } + else { + PyArray_IntpConverter(args, &newshape); + } + ret = PyArray_Resize(self, &newshape, refcheck, PyArray_CORDER); PyDimMem_FREE(newshape.ptr); if (ret == NULL) { From numpy-svn at scipy.org Sun Apr 25 11:11:01 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 25 Apr 2010 10:11:01 -0500 (CDT) Subject: [Numpy-svn] r8362 - trunk/numpy/core/src/multiarray Message-ID: <20100425151101.0B34E39CB28@scipy.org> Author: charris Date: 2010-04-25 10:11:00 -0500 (Sun, 25 Apr 2010) New Revision: 8362 Modified: trunk/numpy/core/src/multiarray/methods.c Log: BUG: Catch resize shape conversion errors. Modified: trunk/numpy/core/src/multiarray/methods.c =================================================================== --- trunk/numpy/core/src/multiarray/methods.c 2010-04-25 14:50:14 UTC (rev 8361) +++ trunk/numpy/core/src/multiarray/methods.c 2010-04-25 15:11:00 UTC (rev 8362) @@ -912,7 +912,7 @@ intp size = PyTuple_Size(args); int refcheck = 1; PyArray_Dims newshape; - PyObject *ret; + PyObject *ret, *obj; if (kwds != NULL) { @@ -929,15 +929,18 @@ return Py_None; } else if (size == 1) { - PyObject *obj = PyTuple_GET_ITEM(args, 0); + obj = PyTuple_GET_ITEM(args, 0); if (obj == Py_None) { Py_INCREF(Py_None); return Py_None; } - PyArray_IntpConverter(obj, &newshape); + args = obj; } - else { - PyArray_IntpConverter(args, &newshape); + if (!PyArray_IntpConverter(args, &newshape)) { + if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, "invalid shape"); + } + return NULL; } ret = PyArray_Resize(self, &newshape, refcheck, PyArray_CORDER); From numpy-svn at scipy.org Sun Apr 25 11:57:47 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 25 Apr 2010 10:57:47 -0500 (CDT) Subject: [Numpy-svn] r8363 - trunk/numpy/core/tests Message-ID: <20100425155747.64E3D39CAED@scipy.org> Author: charris Date: 2010-04-25 10:57:47 -0500 (Sun, 25 Apr 2010) New Revision: 8363 Modified: trunk/numpy/core/tests/test_multiarray.py Log: ENH: Add some tests for ndarray.resize. Modified: trunk/numpy/core/tests/test_multiarray.py =================================================================== --- trunk/numpy/core/tests/test_multiarray.py 2010-04-25 15:11:00 UTC (rev 8362) +++ trunk/numpy/core/tests/test_multiarray.py 2010-04-25 15:57:47 UTC (rev 8363) @@ -1059,8 +1059,27 @@ x = np.eye(3) x.resize(None) assert_array_equal(x, np.eye(3)) + x.resize() + assert_array_equal(x, np.eye(3)) + def test_invalid_arguements(self): + self.assertRaises(TypeError, np.eye(3).resize, 'hi') + self.assertRaises(ValueError, np.eye(3).resize, -1) + self.assertRaises(TypeError, np.eye(3).resize, order=1) + self.assertRaises(TypeError, np.eye(3).resize, refcheck='hi') + def test_freeform_shape(self): + x = np.eye(3) + x.resize(3,2,1) + assert_(x.shape == (3,2,1)) + + def test_zeros_appended(self): + x = np.eye(3) + x.resize(2,3,3) + assert_array_equal(x[0], np.eye(3)) + assert_array_equal(x[1], np.zeros((3,3))) + + class TestRecord(TestCase): def test_field_rename(self): dt = np.dtype([('f',float),('i',int)]) From numpy-svn at scipy.org Sun Apr 25 13:26:08 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 25 Apr 2010 12:26:08 -0500 (CDT) Subject: [Numpy-svn] r8364 - trunk/numpy/core/src/multiarray Message-ID: <20100425172608.654D839CAFA@scipy.org> Author: ptvirtan Date: 2010-04-25 12:26:08 -0500 (Sun, 25 Apr 2010) New Revision: 8364 Modified: trunk/numpy/core/src/multiarray/number.c Log: BUG: fix reference count bug in set_numeric_ops (fixes #1464, #1462) Modified: trunk/numpy/core/src/multiarray/number.c =================================================================== --- trunk/numpy/core/src/multiarray/number.c 2010-04-25 15:57:47 UTC (rev 8363) +++ trunk/numpy/core/src/multiarray/number.c 2010-04-25 17:26:08 UTC (rev 8364) @@ -30,6 +30,7 @@ if (!(PyCallable_Check(temp))) { \ return -1; \ } \ + Py_INCREF(temp); \ Py_XDECREF(n_ops.op); \ n_ops.op = temp; \ } From numpy-svn at scipy.org Sun Apr 25 21:02:04 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 25 Apr 2010 20:02:04 -0500 (CDT) Subject: [Numpy-svn] r8365 - trunk/numpy/core/src/multiarray Message-ID: <20100426010204.562E639CB03@scipy.org> Author: charris Date: 2010-04-25 20:02:04 -0500 (Sun, 25 Apr 2010) New Revision: 8365 Modified: trunk/numpy/core/src/multiarray/methods.c Log: ENH: Add NpyArg_ParseKeywords helper function. Modified: trunk/numpy/core/src/multiarray/methods.c =================================================================== --- trunk/numpy/core/src/multiarray/methods.c 2010-04-25 17:26:08 UTC (rev 8364) +++ trunk/numpy/core/src/multiarray/methods.c 2010-04-26 01:02:04 UTC (rev 8365) @@ -1,4 +1,5 @@ #define PY_SSIZE_T_CLEAN +#include #include #include "structmember.h" @@ -17,6 +18,32 @@ #include "methods.h" + +/* NpyArg_ParseKeywords + * + * Utility function that provides the keyword parsing functionality of + * PyArg_ParseTupleAndKeywords without having to have an args argument. + * + */ +static int +NpyArg_ParseKeywords(PyObject *keys, const char *format, char **kwlist, ...) +{ + PyObject *args = PyTuple_New(0); + int ret; + va_list va; + + if (args == NULL) { + PyErr_SetString(PyExc_RuntimeError, + "Failed to allocate new tuple"); + return 0; + } + va_start(va, kwlist); + ret = PyArg_VaParseTupleAndKeywords(args, keys, format, kwlist, va); + va_end(va); + Py_DECREF(args); + return ret; +} + /* Should only be used if x is known to be an nd-array */ #define _ARET(x) PyArray_Return((PyArrayObject *)(x)) From numpy-svn at scipy.org Sun Apr 25 21:02:07 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Sun, 25 Apr 2010 20:02:07 -0500 (CDT) Subject: [Numpy-svn] r8366 - trunk/numpy/core/src/multiarray Message-ID: <20100426010207.713B739CB65@scipy.org> Author: charris Date: 2010-04-25 20:02:07 -0500 (Sun, 25 Apr 2010) New Revision: 8366 Modified: trunk/numpy/core/src/multiarray/methods.c Log: ENH: Simplify some functions using NpyArg_ParseKeywords. Modified: trunk/numpy/core/src/multiarray/methods.c =================================================================== --- trunk/numpy/core/src/multiarray/methods.c 2010-04-26 01:02:04 UTC (rev 8365) +++ trunk/numpy/core/src/multiarray/methods.c 2010-04-26 01:02:07 UTC (rev 8366) @@ -100,22 +100,15 @@ static PyObject * array_reshape(PyArrayObject *self, PyObject *args, PyObject *kwds) { + static char *keywords[] = {"order", NULL}; PyArray_Dims newshape; PyObject *ret; PyArray_ORDER order = PyArray_CORDER; int n; - if (kwds != NULL) { - PyObject *ref; - ref = PyDict_GetItemString(kwds, "order"); - if (ref == NULL) { - PyErr_SetString(PyExc_TypeError, - "invalid keyword argument"); - return NULL; - } - if ((PyArray_OrderConverter(ref, &order) == PY_FAIL)) { - return NULL; - } + if (!NpyArg_ParseKeywords(kwds, "|O&", keywords, + PyArray_OrderConverter, &order)) { + return NULL; } n = PyTuple_Size(args); @@ -942,13 +935,8 @@ PyObject *ret, *obj; - if (kwds != NULL) { - PyObject *tmp = PyTuple_New(0); - if (!PyArg_ParseTupleAndKeywords(tmp, kwds, "|i", kwlist, &refcheck)) { - Py_XDECREF(tmp); - return NULL; - } - Py_DECREF(tmp); + if (!NpyArg_ParseKeywords(kwds, "|i", kwlist, &refcheck)) { + return NULL; } if (size == 0) { From numpy-svn at scipy.org Mon Apr 26 04:16:44 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 26 Apr 2010 03:16:44 -0500 (CDT) Subject: [Numpy-svn] r8367 - trunk/numpy/core/src/umath Message-ID: <20100426081644.A624239CB1B@scipy.org> Author: ptvirtan Date: 2010-04-26 03:16:44 -0500 (Mon, 26 Apr 2010) New Revision: 8367 Modified: trunk/numpy/core/src/umath/umathmodule.c.src Log: BUG: core: fix a reference count bug in umath:InitOtherOperators (cf #1464) Thanks to mras Modified: trunk/numpy/core/src/umath/umathmodule.c.src =================================================================== --- trunk/numpy/core/src/umath/umathmodule.c.src 2010-04-26 01:02:07 UTC (rev 8366) +++ trunk/numpy/core/src/umath/umathmodule.c.src 2010-04-26 08:16:44 UTC (rev 8367) @@ -229,7 +229,6 @@ #if defined(NPY_PY3K) f = PyDict_GetItemString(dictionary, "true_divide"); PyDict_SetItemString(dictionary, "divide", f); - Py_DECREF(f); #endif return; } From numpy-svn at scipy.org Mon Apr 26 23:35:31 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 26 Apr 2010 22:35:31 -0500 (CDT) Subject: [Numpy-svn] r8368 - trunk/numpy/core/src/multiarray Message-ID: <20100427033531.9D5F739C4B4@scipy.org> Author: charris Date: 2010-04-26 22:35:31 -0500 (Mon, 26 Apr 2010) New Revision: 8368 Modified: trunk/numpy/core/src/multiarray/methods.c Log: Add fixme note. Modified: trunk/numpy/core/src/multiarray/methods.c =================================================================== --- trunk/numpy/core/src/multiarray/methods.c 2010-04-26 08:16:44 UTC (rev 8367) +++ trunk/numpy/core/src/multiarray/methods.c 2010-04-27 03:35:31 UTC (rev 8368) @@ -999,6 +999,7 @@ else { choices = args; } + /*FIXME: use NpyArg_ParseKeywords*/ if (kwds && PyDict_Check(kwds)) { if (PyArray_OutputConverter(PyDict_GetItemString(kwds, "out"), &out) == PY_FAIL) { From numpy-svn at scipy.org Mon Apr 26 23:35:37 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Mon, 26 Apr 2010 22:35:37 -0500 (CDT) Subject: [Numpy-svn] r8369 - trunk/doc/release Message-ID: <20100427033537.AF4F639C4B4@scipy.org> Author: charris Date: 2010-04-26 22:35:37 -0500 (Mon, 26 Apr 2010) New Revision: 8369 Added: trunk/doc/release/2.0.0-notes.rst Removed: trunk/doc/release/1.5.0-notes.rst Log: Move 1.5.0 release notes to 2.0.0. Deleted: trunk/doc/release/1.5.0-notes.rst =================================================================== --- trunk/doc/release/1.5.0-notes.rst 2010-04-27 03:35:31 UTC (rev 8368) +++ trunk/doc/release/1.5.0-notes.rst 2010-04-27 03:35:37 UTC (rev 8369) @@ -1,37 +0,0 @@ -========================= -NumPy 1.5.0 Release Notes -========================= - - -Plans -===== - -This release has the following aims: - -* Python 3 compatibility -* :pep:`3118` compatibility - - -Highlights -========== - - -New features -============ - -Warning on casting complex to real -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Numpy now emits a `numpy.ComplexWarning` when a complex number is cast -into a real number. For example: - - >>> x = np.array([1,2,3]) - >>> x[:2] = np.array([1+2j, 1-2j]) - ComplexWarning: Casting complex values to real discards the imaginary part - -The cast indeed discards the imaginary part, and this may not be the -intended behavior in all cases, hence the warning. This warning can be -turned off in the standard way: - - >>> import warnings - >>> warnings.simplefilter("ignore", np.ComplexWarning) Copied: trunk/doc/release/2.0.0-notes.rst (from rev 8368, trunk/doc/release/1.5.0-notes.rst) =================================================================== --- trunk/doc/release/2.0.0-notes.rst (rev 0) +++ trunk/doc/release/2.0.0-notes.rst 2010-04-27 03:35:37 UTC (rev 8369) @@ -0,0 +1,37 @@ +========================= +NumPy 2.0.0 Release Notes +========================= + + +Plans +===== + +This release has the following aims: + +* Python 3 compatibility +* :pep:`3118` compatibility + + +Highlights +========== + + +New features +============ + +Warning on casting complex to real +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Numpy now emits a `numpy.ComplexWarning` when a complex number is cast +into a real number. For example: + + >>> x = np.array([1,2,3]) + >>> x[:2] = np.array([1+2j, 1-2j]) + ComplexWarning: Casting complex values to real discards the imaginary part + +The cast indeed discards the imaginary part, and this may not be the +intended behavior in all cases, hence the warning. This warning can be +turned off in the standard way: + + >>> import warnings + >>> warnings.simplefilter("ignore", np.ComplexWarning) From numpy-svn at scipy.org Tue Apr 27 12:55:10 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 27 Apr 2010 11:55:10 -0500 (CDT) Subject: [Numpy-svn] r8370 - in trunk/numpy/ma: . tests Message-ID: <20100427165510.4AD2D39CB26@scipy.org> Author: pierregm Date: 2010-04-27 11:55:09 -0500 (Tue, 27 Apr 2010) New Revision: 8370 Modified: trunk/numpy/ma/core.py trunk/numpy/ma/tests/test_core.py Log: Fixed .var for arrays with 1 more valid value than ddofs Modified: trunk/numpy/ma/core.py =================================================================== --- trunk/numpy/ma/core.py 2010-04-27 03:35:37 UTC (rev 8369) +++ trunk/numpy/ma/core.py 2010-04-27 16:55:09 UTC (rev 8370) @@ -4743,7 +4743,7 @@ dvar = divide(danom.sum(axis), cnt).view(type(self)) # Apply the mask if it's not a scalar if dvar.ndim: - dvar._mask = mask_or(self._mask.all(axis), (cnt <= ddof)) + dvar._mask = mask_or(self._mask.all(axis), (cnt <= 0)) dvar._update_from(self) elif getattr(dvar, '_mask', False): # Make sure that masked is returned when the scalar is masked. Modified: trunk/numpy/ma/tests/test_core.py =================================================================== --- trunk/numpy/ma/tests/test_core.py 2010-04-27 03:35:37 UTC (rev 8369) +++ trunk/numpy/ma/tests/test_core.py 2010-04-27 16:55:09 UTC (rev 8370) @@ -199,7 +199,7 @@ err_status_ini = np.geterr() try: np.seterr(invalid='ignore') - data = masked_array(np.sqrt([-1., 0., 1.]), mask=[0, 0, 1]) + data = masked_array([np.nan, 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.]) @@ -2707,6 +2707,19 @@ self.assertTrue(np.isnan(nout)) + def test_varstd_ddof(self): + a = array([[1, 1, 0], [1, 1, 0]], mask=[[0, 0, 1], [0, 0, 1]]) + test = a.std(axis=0, ddof=0) + assert_equal(test.filled(0), [0, 0, 0]) + assert_equal(test.mask, [0, 0, 1]) + test = a.std(axis=0, ddof=1) + assert_equal(test.filled(0), [0, 0, 0]) + assert_equal(test.mask, [0, 0, 1]) + test = a.std(axis=0, ddof=2) + assert_equal(test.filled(0), [0, 0, 0]) + assert_equal(test.mask, [1, 1, 1]) + + def test_diag(self): "Test diag" x = arange(9).reshape((3, 3)) From numpy-svn at scipy.org Tue Apr 27 16:54:09 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 27 Apr 2010 15:54:09 -0500 (CDT) Subject: [Numpy-svn] r8371 - in trunk/numpy/lib: . tests Message-ID: <20100427205409.2C04839CAE7@scipy.org> Author: stefan Date: 2010-04-27 15:54:08 -0500 (Tue, 27 Apr 2010) New Revision: 8371 Modified: trunk/numpy/lib/tests/test_type_check.py trunk/numpy/lib/type_check.py Log: BUG: Fix missing import for datatime_data. Modified: trunk/numpy/lib/tests/test_type_check.py =================================================================== --- trunk/numpy/lib/tests/test_type_check.py 2010-04-27 16:55:09 UTC (rev 8370) +++ trunk/numpy/lib/tests/test_type_check.py 2010-04-27 20:54:08 UTC (rev 8371) @@ -375,5 +375,12 @@ assert issubdtype(a.dtype,float) +class TestDateTimeData: + + def test_basic(self): + a = array(['1980-03-23'], dtype=datetime64) + assert_equal(datetime_data(a.dtype), ('us', 1, 1, 1)) + + if __name__ == "__main__": run_module_suite() Modified: trunk/numpy/lib/type_check.py =================================================================== --- trunk/numpy/lib/type_check.py 2010-04-27 16:55:09 UTC (rev 8370) +++ trunk/numpy/lib/type_check.py 2010-04-27 20:54:08 UTC (rev 8371) @@ -619,6 +619,7 @@ ('den', ctypes.c_int), ('events', ctypes.c_int)] + import sys if sys.version_info[:2] >= (3,1): func = ctypes.pythonapi.PyCapsule_GetPointer func.argtypes = [ctypes.py_object, ctypes.c_char_p] From numpy-svn at scipy.org Tue Apr 27 19:48:16 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Tue, 27 Apr 2010 18:48:16 -0500 (CDT) Subject: [Numpy-svn] r8372 - in trunk/numpy/core: src/multiarray tests Message-ID: <20100427234816.59B2039CAFC@scipy.org> Author: stefan Date: 2010-04-27 18:48:16 -0500 (Tue, 27 Apr 2010) New Revision: 8372 Modified: trunk/numpy/core/src/multiarray/arraytypes.c.src trunk/numpy/core/src/multiarray/datetime.c trunk/numpy/core/tests/test_datetime.py Log: BUG: In datetime, avoid overflow by casting multipliers to npy_int64. Modified: trunk/numpy/core/src/multiarray/arraytypes.c.src =================================================================== --- trunk/numpy/core/src/multiarray/arraytypes.c.src 2010-04-27 20:54:08 UTC (rev 8371) +++ trunk/numpy/core/src/multiarray/arraytypes.c.src 2010-04-27 23:48:16 UTC (rev 8372) @@ -762,7 +762,7 @@ } /* - * Acknowledgment: Example code contributed by Marty Fuhr sponsored by + * Acknowledgement: Example code contributed by Marty Fuhr sponsored by * Google Summer of Code 2009 was used to integrate and adapt the mxDateTime * parser */ Modified: trunk/numpy/core/src/multiarray/datetime.c =================================================================== --- trunk/numpy/core/src/multiarray/datetime.c 2010-04-27 20:54:08 UTC (rev 8371) +++ trunk/numpy/core/src/multiarray/datetime.c 2010-04-27 23:48:16 UTC (rev 8372) @@ -153,7 +153,9 @@ /* Returns absolute seconds from an hour, minute, and second */ -#define secs_from_hms(hour, min, sec) ((hour)*3600 + (min)*60 + (sec)) +#define secs_from_hms(hour, min, sec, multiplier) (\ + ((hour)*3600 + (min)*60 + (sec)) * (npy_int64)(multiplier)\ +) /* * Takes a number of days since Jan 1, 1970 (positive or negative) @@ -314,55 +316,58 @@ ret = days * 1440 + d->hour * 60 + d->min; } else if (fr == NPY_FR_s) { - ret = days * 86400 + secs_from_hms(d->hour, d->min, d->sec); + ret = days * (npy_int64)(86400) + + secs_from_hms(d->hour, d->min, d->sec, 1); } else if (fr == NPY_FR_ms) { - ret = days * 86400000 + secs_from_hms(d->hour, d->min, d->sec) * 1000 + ret = days * (npy_int64)(86400000) + + secs_from_hms(d->hour, d->min, d->sec, 1000) + (d->us / 1000); } else if (fr == NPY_FR_us) { npy_int64 num = 86400 * 1000; - num *= 1000; - ret = days * num + secs_from_hms(d->hour, d->min, d->sec) * 1000000 + num *= (npy_int64)(1000); + ret = days * num + secs_from_hms(d->hour, d->min, d->sec, 1000000) + d->us; } else if (fr == NPY_FR_ns) { npy_int64 num = 86400 * 1000; - num *= 1000 * 1000; - ret = days * num + secs_from_hms(d->hour, d->min, d->sec) * 1000000000 - + d->us * 1000 + (d->ps / 1000); + num *= (npy_int64)(1000 * 1000); + ret = days * num + secs_from_hms(d->hour, d->min, d->sec, 1000000000) + + d->us * (npy_int64)(1000) + (d->ps / 1000); } else if (fr == NPY_FR_ps) { npy_int64 num2 = 1000 * 1000; npy_int64 num1; - num2 *= 1000 * 1000; - num1 = 86400 * num2; - ret = days * num1 + secs_from_hms(d->hour, d->min, d->sec) * num2 - + d->us * 1000000 + d->ps; + num2 *= (npy_int64)(1000 * 1000); + num1 = (npy_int64)(86400) * num2; + ret = days * num1 + secs_from_hms(d->hour, d->min, d->sec, num2) + + d->us * (npy_int64)(1000000) + d->ps; } else if (fr == NPY_FR_fs) { /* only 2.6 hours */ npy_int64 num2 = 1000000; - num2 *= 1000000; - num2 *= 1000; + num2 *= (npy_int64)(1000000); + num2 *= (npy_int64)(1000); /* get number of seconds as a postive or negative number */ if (days >= 0) { - ret = secs_from_hms(d->hour, d->min, d->sec); + ret = secs_from_hms(d->hour, d->min, d->sec, 1); } else { ret = ((d->hour - 24)*3600 + d->min*60 + d->sec); } - ret = ret * num2 + d->us * 1000000000 + d->ps * 1000 + (d->as / 1000); + ret = ret * num2 + d->us * (npy_int64)(1000000000) + + d->ps * (npy_int64)(1000) + (d->as / 1000); } else if (fr == NPY_FR_as) { /* only 9.2 secs */ npy_int64 num1, num2; num1 = 1000000; - num1 *= 1000000; - num2 = num1 * 1000000; + num1 *= (npy_int64)(1000000); + num2 = num1 * (npy_int64)(1000000); if (days >= 0) { ret = d->sec; @@ -370,7 +375,8 @@ else { ret = d->sec - 60; } - ret = ret * num2 + d->us * num1 + d->ps * 1000000 + d->as; + ret = ret * num2 + d->us * num1 + d->ps * (npy_int64)(1000000) + + d->as; } else { /* Shouldn't get here */ @@ -425,47 +431,51 @@ ret = d->day + d->sec / 3600; } else if (fr == NPY_FR_m) { - ret = d->day * 1440 + d->sec / 60; + ret = d->day * (npy_int64)(1440) + d->sec / 60; } else if (fr == NPY_FR_s) { - ret = d->day * 86400 + d->sec; + ret = d->day * (npy_int64)(86400) + d->sec; } else if (fr == NPY_FR_ms) { - ret = d->day * 86400000 + d->sec * 1000 + d->us / 1000; + ret = d->day * (npy_int64)(86400000) + d->sec * 1000 + d->us / 1000; } else if (fr == NPY_FR_us) { npy_int64 num = 86400000; - num *= 1000; - ret = d->day * num + d->sec * 1000000 + d->us; + num *= (npy_int64)(1000); + ret = d->day * num + d->sec * (npy_int64)(1000000) + d->us; } else if (fr == NPY_FR_ns) { npy_int64 num = 86400000; - num *= 1000000; - ret = d->day * num + d->sec * 1000000000 + d->us * 1000 + (d->ps / 1000); + num *= (npy_int64)(1000000); + ret = d->day * num + d->sec * (npy_int64)(1000000000) + + d->us * (npy_int64)(1000) + (d->ps / 1000); } else if (fr == NPY_FR_ps) { npy_int64 num2, num1; num2 = 1000000; - num2 *= 1000000; - num1 = 86400 * num2; + num2 *= (npy_int64)(1000000); + num1 = (npy_int64)(86400) * num2; - ret = d->day * num1 + d->sec * num2 + d->us * 1000000 + d->ps; + ret = d->day * num1 + d->sec * num2 + d->us * (npy_int64)(1000000) + + d->ps; } else if (fr == NPY_FR_fs) { /* only 2.6 hours */ npy_int64 num2 = 1000000000; - num2 *= 1000000; - ret = d->sec * num2 + d->us * 1000000000 + d->ps * 1000 + (d->as / 1000); + num2 *= (npy_int64)(1000000); + ret = d->sec * num2 + d->us * (npy_int64)(1000000000) + + d->ps * (npy_int64)(1000) + (d->as / 1000); } else if (fr == NPY_FR_as) { /* only 9.2 secs */ npy_int64 num1, num2; num1 = 1000000; - num1 *= 1000000; - num2 = num1 * 1000000; - ret = d->sec * num2 + d->us * num1 + d->ps * 1000000 + d->as; + num1 *= (npy_int64)(1000000); + num2 = num1 * (npy_int64)(1000000); + ret = d->sec * num2 + d->us * num1 + d->ps * (npy_int64)(1000000) + + d->as; } else { /* Shouldn't get here */ @@ -652,7 +662,7 @@ hms = seconds_to_hmsstruct(tmp / 1000000000); tmp = tmp % 1000000000; us = tmp / 1000; - ps = (tmp % 1000) * 1000; + ps = (tmp % 1000) * (npy_int64)(1000); year = ymd.year; month = ymd.month; day = ymd.day; @@ -663,8 +673,8 @@ else if (fr == NPY_FR_ps) { npy_int64 num1, num2, num3; num3 = 1000000000; - num3 *= 1000; - num1 = 86400 * num3; + num3 *= (npy_int64)(1000); + num1 = (npy_int64)(86400) * num3; num2 = num1 - 1; if (val >= 0) { @@ -672,7 +682,7 @@ tmp = val % num1; } else { - ymd = days_to_ymdstruct((val - num2)/ num1); + ymd = days_to_ymdstruct((val - num2) / num1); tmp = num2 + (val + 1) % num1; } hms = seconds_to_hmsstruct(tmp / num3); @@ -690,8 +700,8 @@ /* entire range is only += 2.6 hours */ npy_int64 num1, num2; num1 = 1000000000; - num1 *= 1000; - num2 = num1 * 1000; + num1 *= (npy_int64)(1000); + num2 = num1 * (npy_int64)(1000); if (val >= 0) { sec = val / num2; @@ -724,14 +734,14 @@ us = tmp / 1000000000; tmp = tmp % 1000000000; ps = tmp / 1000; - as = (tmp % 1000) * 1000; + as = (tmp % 1000) * (npy_int64)(1000); } else if (fr == NPY_FR_as) { /* entire range is only += 9.2 seconds */ npy_int64 num1, num2, num3; num1 = 1000000; - num2 = num1 * 1000000; - num3 = num2 * 1000000; + num2 = num1 * (npy_int64)(1000000); + num3 = num2 * (npy_int64)(1000000); if (val >= 0) { hour = 0; min = 0; @@ -820,7 +830,7 @@ sec = (val % 1440)*60; } else if (fr == NPY_FR_s) { - day = val / 86400; + day = val / (86400); sec = val % 86400; } else if (fr == NPY_FR_ms) { @@ -847,13 +857,13 @@ sec = val / 1000000000; val = val % 1000000000; us = val / 1000; - ps = (val % 1000) * 1000; + ps = (val % 1000) * (npy_int64)(1000); } else if (fr == NPY_FR_ps) { npy_int64 num1, num2; num2 = 1000000000; - num2 *= 1000; - num1 = 86400 * num2; + num2 *= (npy_int64)(1000); + num1 = (npy_int64)(86400) * num2; day = val / num1; ps = val % num1; @@ -866,7 +876,7 @@ /* entire range is only += 9.2 hours */ npy_int64 num1, num2; num1 = 1000000000; - num2 = num1 * 1000000; + num2 = num1 * (npy_int64)(1000000); day = 0; sec = val / num2; @@ -874,14 +884,14 @@ us = val / num1; val = val % num1; ps = val / 1000; - as = (val % 1000) * 1000; + as = (val % 1000) * (npy_int64)(1000); } else if (fr == NPY_FR_as) { /* entire range is only += 2.6 seconds */ npy_int64 num1, num2, num3; num1 = 1000000; - num2 = num1 * 1000000; - num3 = num2 * 1000000; + num2 = num1 * (npy_int64)(1000000); + num3 = num2 * (npy_int64)(1000000); day = 0; sec = val / num3; as = val % num3; Modified: trunk/numpy/core/tests/test_datetime.py =================================================================== --- trunk/numpy/core/tests/test_datetime.py 2010-04-27 20:54:08 UTC (rev 8371) +++ trunk/numpy/core/tests/test_datetime.py 2010-04-27 23:48:16 UTC (rev 8372) @@ -56,3 +56,18 @@ def test_divisor_conversion_as(self): self.assertRaises(ValueError, lambda : np.dtype('M8[as/10]')) + + def test_creation_overflow(self): + date = '1980-03-23 20:00:00' + timesteps = np.array([date], dtype='datetime64[s]')[0].astype(int) + for unit in ['ms', 'us', 'ns']: + timesteps *= 1000 + x = np.array([date], dtype='datetime64[%s]' % unit) + + assert_equal(timesteps, x[0].astype(np.int64), + err_msg='Datetime conversion error for unit %s' % unit) + + assert_equal(x[0].astype(int), 322689600000000000) + +if __name__ == "__main__": + run_module_suite() From numpy-svn at scipy.org Thu Apr 29 19:57:39 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Thu, 29 Apr 2010 18:57:39 -0500 (CDT) Subject: [Numpy-svn] r8373 - trunk/doc/neps Message-ID: <20100429235739.8592639CB62@scipy.org> Author: oliphant Date: 2010-04-29 18:57:39 -0500 (Thu, 29 Apr 2010) New Revision: 8373 Added: trunk/doc/neps/groupby_additions.rst Log: Add NEP for group-by additions to NumPy: reduceby, reducein, segment, and edges. Added: trunk/doc/neps/groupby_additions.rst =================================================================== --- trunk/doc/neps/groupby_additions.rst (rev 0) +++ trunk/doc/neps/groupby_additions.rst 2010-04-29 23:57:39 UTC (rev 8373) @@ -0,0 +1,112 @@ +==================================================================== + A proposal for adding groupby functionality to NumPy +==================================================================== + +:Author: Travis Oliphant +:Contact: oliphant at enthought.com +:Date: 2010-04-27 + + +Executive summary +================= + +NumPy provides tools for handling data and doing calculations in much +the same way as relational algebra allows. However, the common group-by +functionality is not easily handled. The reduce methods of NumPy's +ufuncs are a natural place to put this groupby behavior. This NEP +describes two additional methods for ufuncs (reduceby and reducein) and +two additional functions (segment and edges) which can help add this +functionality. + +Example Use Case +================ +Suppose you have a NumPy structured array containing information about +the number of purchases at several stores over multiple days. To be clear, the +structured array data-type is: + +dt = [('year', i2), ('month', i1), ('day', i1), ('time', float), + ('store', i4), ('SKU', 'S6'), ('number', i4)] + +Suppose there is a 1-d NumPy array of this data-type and you would like +to compute various statistics (max, min, mean, sum, etc.) on the number +of products sold, by product, by month, by store, etc. + +Currently, this could be done by using reduce methods on the number +field of the array, coupled with in-place sorting, unique with +return_inverse=True and bincount, etc. However, for such a common +data-analysis need, it would be nice to have standard and more direct +ways to get the results. + + +Ufunc methods proposed +====================== + +It is proposed to add two new reduce-style methods to the ufuncs: +reduceby and reducein. The reducein method is intended to be a simpler +to use version of reduceat, while the reduceby method is intended to +provide group-by capability on reductions. + +reducein:: + + .reducein(arr, indices, axis=0, dtype=None, out=None) + + Perform a local reduce with slices specified by pairs of indices. + + The reduction occurs along the provided axis, using the provided + data-type to calculate intermediate results, storing the result into + the array out (if provided). + + The indices array provides the start and end indices for the + reduction. If the length of the indices array is odd, then the + final index provides the beginning point for the final reduction + and the ending point is the end of arr. + + This generalizes along the given axis, the behavior: + + [.reduce(arr[indices[2*i]:indices[2*i+1]]) + for i in range(len(indices)/2)] + + This assumes indices is of even length + + Example: + >>> a = [0,1,2,4,5,6,9,10] + >>> add.reducein(a,[0,3,2,5,-2]) + [3, 11, 19] + + Notice that sum(a[0:3]) = 3; sum(a[2:5]) = 11; and sum(a[-2:]) = 19 + +reduceby:: + + .reduceby(arr, by, dtype=None, out=None) + + Perform a reduction in arr over unique non-negative integers in by. + + + Let N=arr.ndim and M=by.ndim. Then, by.shape[:N] == arr.shape. + In addition, let I be an N-length index tuple, then by[I] + contains the location in the output array for the reduction to + be stored. Notice that if N == M, then by[I] is a non-negative + integer, while if N < M, then by[I] is an array of indices into + the output array. + + The reduction is computed on groups specified by unique indices + into the output array. The index is either the single + non-negative integer if N == M or if N < M, the entire + (M-N+1)-length index by[I] considered as a whole. + + +Functions proposed +================== + +segment:: + + +edges:: + + +.. Local Variables: +.. mode: rst +.. coding: utf-8 +.. fill-column: 72 +.. End: + From numpy-svn at scipy.org Fri Apr 30 03:06:02 2010 From: numpy-svn at scipy.org (numpy-svn at scipy.org) Date: Fri, 30 Apr 2010 02:06:02 -0500 (CDT) Subject: [Numpy-svn] r8374 - in trunk: doc/release numpy/core/src/multiarray numpy/core/tests numpy/matrixlib/tests Message-ID: <20100430070602.2BB7339CB07@scipy.org> Author: ptvirtan Date: 2010-04-30 02:06:02 -0500 (Fri, 30 Apr 2010) New Revision: 8374 Modified: trunk/doc/release/2.0.0-notes.rst trunk/numpy/core/src/multiarray/methods.c trunk/numpy/core/tests/test_multiarray.py trunk/numpy/matrixlib/tests/test_defmatrix.py Log: ENH: core: add .dot() method to ndarrays; a.dot(b) == np.dot(a, b) Modified: trunk/doc/release/2.0.0-notes.rst =================================================================== --- trunk/doc/release/2.0.0-notes.rst 2010-04-29 23:57:39 UTC (rev 8373) +++ trunk/doc/release/2.0.0-notes.rst 2010-04-30 07:06:02 UTC (rev 8374) @@ -35,3 +35,16 @@ >>> import warnings >>> warnings.simplefilter("ignore", np.ComplexWarning) + +Dot method for ndarrays +~~~~~~~~~~~~~~~~~~~~~~~ + +Ndarrays now have the dot product also as a method, which allows writing +chains of matrix products as + + >>> a.dot(b).dot(c) + +instead of the longer alternative + + >>> np.dot(a, np.dot(b, c)) + Modified: trunk/numpy/core/src/multiarray/methods.c =================================================================== --- trunk/numpy/core/src/multiarray/methods.c 2010-04-29 23:57:39 UTC (rev 8373) +++ trunk/numpy/core/src/multiarray/methods.c 2010-04-30 07:06:02 UTC (rev 8374) @@ -1793,6 +1793,29 @@ static PyObject * +array_dot(PyArrayObject *self, PyObject *args, PyObject *kwds) +{ + PyObject *b; + static PyObject *numpycore = NULL; + + if (!PyArg_ParseTuple(args, "O", &b)) { + return NULL; + } + + /* Since blas-dot is exposed only on the Python side, we need to grab it + * from there */ + if (numpycore == NULL) { + numpycore = PyImport_ImportModule("numpy.core"); + if (numpycore == NULL) { + return NULL; + } + } + + return PyObject_CallMethod(numpycore, "dot", "OO", self, b); +} + + +static PyObject * array_any(PyArrayObject *self, PyObject *args, PyObject *kwds) { int axis = MAX_DIMS; @@ -2192,6 +2215,9 @@ {"diagonal", (PyCFunction)array_diagonal, METH_VARARGS | METH_KEYWORDS, NULL}, + {"dot", + (PyCFunction)array_dot, + METH_VARARGS, NULL}, {"fill", (PyCFunction)array_fill, METH_VARARGS, NULL}, Modified: trunk/numpy/core/tests/test_multiarray.py =================================================================== --- trunk/numpy/core/tests/test_multiarray.py 2010-04-29 23:57:39 UTC (rev 8373) +++ trunk/numpy/core/tests/test_multiarray.py 2010-04-30 07:06:02 UTC (rev 8374) @@ -541,7 +541,14 @@ assert_equal(x1.flatten('F'), y1f) assert_equal(x1.flatten('F'), x1.T.flatten()) + def test_dot(self): + a = np.array([[1, 0], [0, 1]]) + b = np.array([[0, 1], [1, 0]]) + c = np.array([[9, 1], [1, -9]]) + assert_equal(np.dot(a, b), a.dot(b)) + assert_equal(np.dot(np.dot(a, b), c), a.dot(b).dot(c)) + class TestSubscripting(TestCase): def test_test_zero_rank(self): x = array([1,2,3]) Modified: trunk/numpy/matrixlib/tests/test_defmatrix.py =================================================================== --- trunk/numpy/matrixlib/tests/test_defmatrix.py 2010-04-29 23:57:39 UTC (rev 8373) +++ trunk/numpy/matrixlib/tests/test_defmatrix.py 2010-04-30 07:06:02 UTC (rev 8374) @@ -254,7 +254,8 @@ 'compress' : ([1],), 'repeat' : (1,), 'reshape' : (1,), - 'swapaxes' : (0,0) + 'swapaxes' : (0,0), + 'dot': np.array([1.0]), } excluded_methods = [ 'argmin', 'choose', 'dump', 'dumps', 'fill', 'getfield', @@ -267,7 +268,7 @@ for attrib in dir(a): if attrib.startswith('_') or attrib in excluded_methods: continue - f = eval('a.%s' % attrib) + f = getattr(a, attrib) if callable(f): # reset contents of a a.astype('f8')