diff options
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/__init__.py | 4 | ||||
-rw-r--r-- | numpy/core/arrayprint.py | 2 | ||||
-rw-r--r-- | numpy/core/fromnumeric.py (renamed from numpy/core/oldnumeric.py) | 138 | ||||
-rw-r--r-- | numpy/core/ma.py | 68 | ||||
-rw-r--r-- | numpy/core/numeric.py | 6 | ||||
-rw-r--r-- | numpy/core/numerictypes.py | 11 | ||||
-rw-r--r-- | numpy/core/tests/test_ma.py | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_oldnumeric.py | 29 |
8 files changed, 52 insertions, 208 deletions
diff --git a/numpy/core/__init__.py b/numpy/core/__init__.py index b8c5f962e..56f89b114 100644 --- a/numpy/core/__init__.py +++ b/numpy/core/__init__.py @@ -8,7 +8,7 @@ import numerictypes as nt multiarray.set_typeDict(nt.typeDict) import _sort from numeric import * -from oldnumeric import * +from fromnumeric import * from defmatrix import * import ma import defchararray as char @@ -22,7 +22,7 @@ del nt __all__ = ['char','rec','memmap','ma'] __all__ += numeric.__all__ -__all__ += oldnumeric.__all__ +__all__ += fromnumeric.__all__ __all__ += defmatrix.__all__ __all__ += rec.__all__ __all__ += char.__all__ diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index 613f89ed9..136b58c92 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -17,7 +17,7 @@ import numeric as _gen import numerictypes as _nt import umath as _uf from multiarray import format_longfloat -from oldnumeric import ravel +from fromnumeric import ravel _nc = _gen # The following functions are emergency substitutes for numeric functions diff --git a/numpy/core/oldnumeric.py b/numpy/core/fromnumeric.py index ddec9439d..da8fe7f3c 100644 --- a/numpy/core/oldnumeric.py +++ b/numpy/core/fromnumeric.py @@ -1,21 +1,6 @@ -# Compatibility module containing deprecated names +# Module containing non-deprecated functions borrowed from Numeric. __all__ = ['asarray', 'array', 'concatenate', - 'NewAxis', - 'UFuncType', 'UfuncType', 'ArrayType', 'arraytype', - 'LittleEndian', 'Bool', - 'Character', 'UnsignedInt8', 'UnsignedInt16', 'UnsignedInt', - 'UInt8','UInt16','UInt32', 'UnsignedInt32', 'UnsignedInteger', - # UnsignedInt64 and Unsigned128 added below if possible - # same for Int64 and Int128, Float128, and Complex128 - 'Int8', 'Int16', 'Int32', - 'Int0', 'Int', 'Float0', 'Float', 'Complex0', 'Complex', - 'PyObject', 'Float32', 'Float64', 'Float16', 'Float8', - 'Complex32', 'Complex64', 'Complex8', 'Complex16', - 'typecodes', 'sarray', 'arrayrange', 'cross_correlate', - 'matrixmultiply', 'outerproduct', 'innerproduct', - # from cPickle - 'dump', 'dumps', # functions that are now methods 'take', 'reshape', 'choose', 'repeat', 'put', 'putmask', 'swapaxes', 'transpose', 'sort', 'argsort', 'argmax', 'argmin', @@ -42,132 +27,11 @@ try: _gentype = types.GeneratorType except AttributeError: _gentype = types.NoneType -#Use this to add a new axis to an array -#compatibility only -NewAxis = None - -#deprecated -UFuncType = type(um.sin) -UfuncType = type(um.sin) -ArrayType = mu.ndarray -arraytype = mu.ndarray - -LittleEndian = (sys.byteorder == 'little') # save away Python sum _sum_ = sum -# backward compatible names from old Precision.py - -Character = 'S1' -UnsignedInt8 = _dt_(nt.uint8) -UInt8 = UnsignedInt8 -UnsignedInt16 = _dt_(nt.uint16) -UInt16 = UnsignedInt16 -UnsignedInt32 = _dt_(nt.uint32) -UInt32 = UnsignedInt32 -UnsignedInt = _dt_(nt.uint) - -try: - UnsignedInt64 = _dt_(nt.uint64) -except AttributeError: - pass -else: - UInt64 = UnsignedInt64 - __all__ += ['UnsignedInt64', 'UInt64'] -try: - UnsignedInt128 = _dt_(nt.uint128) -except AttributeError: - pass -else: - UInt128 = UnsignedInt128 - __all__ += ['UnsignedInt128','UInt128'] - -Int8 = _dt_(nt.int8) -Int16 = _dt_(nt.int16) -Int32 = _dt_(nt.int32) - -try: - Int64 = _dt_(nt.int64) -except AttributeError: - pass -else: - __all__ += ['Int64'] - -try: - Int128 = _dt_(nt.int128) -except AttributeError: - pass -else: - __all__ += ['Int128'] - -Bool = _dt_(bool) -Int0 = _dt_(int) -Int = _dt_(int) -Float0 = _dt_(float) -Float = _dt_(float) -Complex0 = _dt_(complex) -Complex = _dt_(complex) -PyObject = _dt_(nt.object_) -Float32 = _dt_(nt.float32) -Float64 = _dt_(nt.float64) - -Float16='f' -Float8='f' -UnsignedInteger='L' -Complex8='F' -Complex16='F' - -try: - Float128 = _dt_(nt.float128) -except AttributeError: - pass -else: - __all__ += ['Float128'] - -Complex32 = _dt_(nt.complex64) -Complex64 = _dt_(nt.complex128) - -try: - Complex128 = _dt_(nt.complex256) -except AttributeError: - pass -else: - __all__ += ['Complex128'] - -typecodes = {'Character':'S1', - 'Integer':'bhilqp', - 'UnsignedInteger':'BHILQP', - 'Float':'fdg', - 'Complex':'FDG', - 'AllInteger':'bBhHiIlLqQpP', - 'AllFloat':'fdgFDG', - 'All':'?bhilqpBHILQPfdgFDGSUVO'} - -def sarray(a, dtype=None, copy=False): - return array(a, dtype, copy) - -def _deprecate(func, oldname, newname): - import warnings - def newfunc(*args,**kwds): - warnings.warn("%s is deprecated, use %s" % (oldname, newname), - DeprecationWarning) - return func(*args, **kwds) - return newfunc - -# backward compatibility -arrayrange = _deprecate(mu.arange, 'arrayrange', 'arange') -cross_correlate = _deprecate(correlate, 'cross_correlate', 'correlate') - -# deprecated names -matrixmultiply = _deprecate(mu.dot, 'matrixmultiply', 'dot') -outerproduct = _deprecate(outer, 'outerproduct', 'outer') -innerproduct = _deprecate(mu.inner, 'innerproduct', 'inner') - -from cPickle import dump, dumps - # functions that are now methods - def _wrapit(obj, method, *args, **kwds): try: wrap = obj.__array_wrap__ diff --git a/numpy/core/ma.py b/numpy/core/ma.py index b17c5d256..4fb7e59c0 100644 --- a/numpy/core/ma.py +++ b/numpy/core/ma.py @@ -10,10 +10,10 @@ Adapted for numpy_core 2005 by Travis Oliphant and import types, sys import umath -import oldnumeric +import fromnumeric from numeric import newaxis, ndarray, inf -from oldnumeric import typecodes, amax, amin -from numerictypes import bool_ +from fromnumeric import amax, amin +from numerictypes import bool_, typecodes import numeric import warnings @@ -186,7 +186,7 @@ def make_mask (m, copy=0, flag=0): else: result = filled(m, True).astype(MaskType) - if flag and not oldnumeric.sometrue(oldnumeric.ravel(result)): + if flag and not fromnumeric.sometrue(fromnumeric.ravel(result)): return nomask else: return result @@ -348,7 +348,7 @@ class domained_binary_operation: d2 = filled(b, self.filly) t = self.domain(d1, d2) - if oldnumeric.sometrue(t, None): + if fromnumeric.sometrue(t, None): d2 = where(t, self.filly, d2) mb = mask_or(mb, t) m = mask_or(ma, mb) @@ -451,7 +451,7 @@ def nonzero(a): """ return asarray(filled(a, 0).nonzero()) -around = masked_unary_operation(oldnumeric.round_) +around = masked_unary_operation(fromnumeric.round_) floor = masked_unary_operation(umath.floor) ceil = masked_unary_operation(umath.ceil) logical_not = masked_unary_operation(umath.logical_not) @@ -490,13 +490,13 @@ bitwise_or = masked_binary_operation(umath.bitwise_or) bitwise_xor = masked_binary_operation(umath.bitwise_xor) def rank (object): - return oldnumeric.rank(filled(object)) + return fromnumeric.rank(filled(object)) def shape (object): - return oldnumeric.shape(filled(object)) + return fromnumeric.shape(filled(object)) def size (object, axis=None): - return oldnumeric.size(filled(object), axis) + return fromnumeric.size(filled(object), axis) class MaskedArray (object): """Arrays with possibly masked values. @@ -580,10 +580,10 @@ class MaskedArray (object): nd = size(self._data) if nm != nd: if nm == 1: - self._mask = oldnumeric.resize(self._mask, self._data.shape) + self._mask = fromnumeric.resize(self._mask, self._data.shape) self._shared_mask = 0 elif nd == 1: - self._data = oldnumeric.resize(self._data, self._mask.shape) + self._data = fromnumeric.resize(self._data, self._mask.shape) self._data.shape = self._mask.shape else: raise MAError, "Mask and data not compatible." @@ -596,7 +596,7 @@ class MaskedArray (object): def __array__ (self, t=None, context=None): "Special hook for numeric. Converts to numeric if possible." if self._mask is not nomask: - if oldnumeric.ravel(self._mask).any(): + if fromnumeric.ravel(self._mask).any(): if context is None: warnings.warn("Cannot automatically convert masked array to "\ "numeric because data\n is masked in one or "\ @@ -1177,12 +1177,12 @@ array(data = %(data)s, def compressed (self): "A 1-D array of all the non-masked data." - d = oldnumeric.ravel(self._data) + d = fromnumeric.ravel(self._data) if self._mask is nomask: return array(d) else: - m = 1 - oldnumeric.ravel(self._mask) - c = oldnumeric.compress(m, d) + m = 1 - fromnumeric.ravel(self._mask) + c = fromnumeric.compress(m, d) return array(c, copy=0) def count (self, axis = None): @@ -1203,7 +1203,7 @@ array(data = %(data)s, del t[axis] return ones(t) * n if axis is None: - w = oldnumeric.ravel(m).astype(int) + w = fromnumeric.ravel(m).astype(int) n1 = size(w) if n1 == 1: n2 = w[0] @@ -1254,7 +1254,7 @@ array(data = %(data)s, #ok, can't put that value in here value = numeric.array(value, dtype=object) d = d.astype(object) - result = oldnumeric.choose(m, (d, value)) + result = fromnumeric.choose(m, (d, value)) except IndexError: #ok, if scalar if d.shape: @@ -1291,7 +1291,7 @@ array(data = %(data)s, if self._mask is nomask: ind = iota else: - ind = oldnumeric.compress(1 - self._mask, iota) + ind = fromnumeric.compress(1 - self._mask, iota) d[ind] = filled(values).astype(d.dtype) def putmask (self, values): @@ -1358,7 +1358,7 @@ array(data = %(data)s, def item(self): "Return Python scalar if possible." if self._mask is not nomask: - m = oldnumeric.ravel(self._mask) + m = fromnumeric.ravel(self._mask) try: if m[0]: return masked @@ -1428,7 +1428,7 @@ def allclose (a, b, fill_value=1, rtol=1.e-5, atol=1.e-8): x = filled(array(d1, copy=0, mask=m), fill_value).astype(float) y = filled(array(d2, copy=0, mask=m), 1).astype(float) d = umath.less_equal(umath.absolute(x-y), atol + rtol * umath.absolute(y)) - return oldnumeric.alltrue(oldnumeric.ravel(d)) + return fromnumeric.alltrue(fromnumeric.ravel(d)) def allequal (a, b, fill_value=1): """ @@ -1440,13 +1440,13 @@ def allequal (a, b, fill_value=1): x = filled(a) y = filled(b) d = umath.equal(x, y) - return oldnumeric.alltrue(oldnumeric.ravel(d)) + return fromnumeric.alltrue(fromnumeric.ravel(d)) elif fill_value: x = filled(a) y = filled(b) d = umath.equal(x, y) dm = array(d, mask=m, copy=0) - return oldnumeric.alltrue(oldnumeric.ravel(filled(dm, 1))) + return fromnumeric.alltrue(fromnumeric.ravel(filled(dm, 1))) else: return 0 @@ -1514,8 +1514,8 @@ def resize (a, new_shape): The original array's total size can be any size.""" m = getmask(a) if m is not nomask: - m = oldnumeric.resize(m, new_shape) - result = array(oldnumeric.resize(filled(a), new_shape), mask=m) + m = fromnumeric.resize(m, new_shape) + result = array(fromnumeric.resize(filled(a), new_shape), mask=m) result.set_fill_value(get_fill_value(a)) return result @@ -1530,8 +1530,8 @@ def repeat(a, repeats, axis=0): m = getmask(a) if m is not nomask: - m = oldnumeric.repeat(m, repeats, axis) - d = oldnumeric.repeat(af, repeats, axis) + m = fromnumeric.repeat(m, repeats, axis) + d = fromnumeric.repeat(af, repeats, axis) result = masked_array(d, m) result.set_fill_value(get_fill_value(a)) return result @@ -1624,7 +1624,7 @@ def average (a, axis=0, weights=None, returned = 0): else: if weights is None: n = add.reduce(a.ravel()) - w = oldnumeric.choose(mask, (1.0, 0.0)).ravel() + w = fromnumeric.choose(mask, (1.0, 0.0)).ravel() d = umath.add.reduce(w) del w else: @@ -1814,7 +1814,7 @@ def reshape (a, *newshape): def ravel (a): "a as one-dimensional, may share data and mask" m = getmask(a) - d = oldnumeric.ravel(filled(a)) + d = fromnumeric.ravel(filled(a)) if m is nomask: return masked_array(d) else: @@ -2053,19 +2053,19 @@ def sort (x, axis = -1, fill_value=None): if fill_value is None: fill_value = default_fill_value (x) d = filled(x, fill_value) - s = oldnumeric.sort(d, axis) + s = fromnumeric.sort(d, axis) if getmask(x) is nomask: return masked_array(s) return masked_values(s, fill_value, copy=0) def diagonal(a, k = 0, axis1=0, axis2=1): """diagonal(a,k=0,axis1=0, axis2=1) = the k'th diagonal of a""" - d = oldnumeric.diagonal(filled(a), k, axis1, axis2) + d = fromnumeric.diagonal(filled(a), k, axis1, axis2) m = getmask(a) if m is nomask: return masked_array(d, m) else: - return masked_array(d, oldnumeric.diagonal(m, k, axis1, axis2)) + return masked_array(d, fromnumeric.diagonal(m, k, axis1, axis2)) def trace (a, offset=0, axis1=0, axis2=1, dtype=None): """trace(a,offset=0, axis1=0, axis2=1) returns the sum along diagonals @@ -2080,7 +2080,7 @@ def argsort (x, axis = -1, fill_value=None): Returns a numpy array. """ d = filled(x, fill_value) - return oldnumeric.argsort(d, axis) + return fromnumeric.argsort(d, axis) def argmin (x, axis = -1, fill_value=None): """Treating masked values as if they have the value fill_value, @@ -2090,7 +2090,7 @@ def argmin (x, axis = -1, fill_value=None): Otherwise, returns a scalar index. """ d = filled(x, fill_value) - return oldnumeric.argmin(d, axis) + return fromnumeric.argmin(d, axis) def argmax (x, axis = -1, fill_value=None): """Treating masked values as if they have the value fill_value, @@ -2106,7 +2106,7 @@ def argmax (x, axis = -1, fill_value=None): except: pass d = filled(x, fill_value) - return oldnumeric.argmax(d, axis) + return fromnumeric.argmax(d, axis) def fromfunction (f, s): """apply f to s to create array as in umath.""" diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index 973307220..5673d8488 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -537,6 +537,6 @@ nan = NaN = NAN False_ = bool_(False) True_ = bool_(True) -import oldnumeric -from oldnumeric import * -extend_all(oldnumeric) +import fromnumeric +from fromnumeric import * +extend_all(fromnumeric) diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py index 32e0d1626..ae9dc0a27 100644 --- a/numpy/core/numerictypes.py +++ b/numpy/core/numerictypes.py @@ -77,7 +77,7 @@ $Id: numerictypes.py,v 1.17 2005/09/09 22:20:06 teoliphant Exp $ # we add more at the bottom __all__ = ['typeDict', 'typeNA', 'sctypes', 'ScalarType', 'obj2sctype', 'cast', 'nbytes', - 'sctype2char', 'maximum_sctype', 'issctype'] + 'sctype2char', 'maximum_sctype', 'issctype', 'typecodes'] from multiarray import typeinfo, ndarray, array, empty import types as _types @@ -421,3 +421,12 @@ for key in allTypes: __all__.append(key) del key + +typecodes = {'Character':'S1', + 'Integer':'bhilqp', + 'UnsignedInteger':'BHILQP', + 'Float':'fdg', + 'Complex':'FDG', + 'AllInteger':'bBhHiIlLqQpP', + 'AllFloat':'fdgFDG', + 'All':'?bhilqpBHILQPfdgFDGSUVO'} diff --git a/numpy/core/tests/test_ma.py b/numpy/core/tests/test_ma.py index fe8864e91..afdda90de 100644 --- a/numpy/core/tests/test_ma.py +++ b/numpy/core/tests/test_ma.py @@ -668,7 +668,7 @@ class test_ufuncs(ScipyTestCase): try: uf = getattr(umath, f) except AttributeError: - uf = getattr(oldnumeric, f) + uf = getattr(fromnumeric, f) mf = getattr(numpy.ma, f) args = self.d[:uf.nin] ur = uf(*args) diff --git a/numpy/core/tests/test_oldnumeric.py b/numpy/core/tests/test_oldnumeric.py deleted file mode 100644 index 0173bdcca..000000000 --- a/numpy/core/tests/test_oldnumeric.py +++ /dev/null @@ -1,29 +0,0 @@ -from numpy.testing import * - -from numpy import array, ndarray, arange, argmax -from numpy.core.oldnumeric import put - -class test_put(ScipyTestCase): - def check_bug_r2089(self, level=1): - a = array([0,0,0]) - put(a,[1],[1.2]) - assert_array_equal(a,[0,1,0]) - put(a,[1],array([2.2])) - assert_array_equal(a,[0,2,0]) - -class test_wrapit(ScipyTestCase): - def check_array_subclass(self, level=1): - class subarray(ndarray): - def get_argmax(self): - raise AttributeError - argmax = property(get_argmax) - a = subarray([3], int, arange(3)) - assert_equal(argmax(a), 2) - b = subarray([3, 3], int, arange(9)) - bmax = argmax(b) - assert_array_equal(bmax, [2,2,2]) - assert_equal(type(bmax), subarray) - - -if __name__ == "__main__": - ScipyTest().run() |