diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/lib/arraysetops.py | 78 | ||||
-rw-r--r-- | numpy/lib/benchmarks/bench_arraysetops.py | 65 | ||||
-rw-r--r-- | numpy/lib/tests/test_arraysetops.py | 45 | ||||
-rw-r--r-- | numpy/ma/extras.py | 10 |
4 files changed, 10 insertions, 188 deletions
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py index 042866f30..721039238 100644 --- a/numpy/lib/arraysetops.py +++ b/numpy/lib/arraysetops.py @@ -10,11 +10,6 @@ Set operations for 1D numeric arrays based on sorting. union1d, setdiff1d -:Deprecated: - unique1d, - intersect1d_nu, - setmember1d - :Notes: For floating point arrays, inaccurate results may appear due to usual round-off @@ -28,8 +23,8 @@ To do: Optionally return indices analogously to unique for all functions. :Author: Robert Cimrman """ -__all__ = ['ediff1d', 'unique1d', 'intersect1d', 'intersect1d_nu', 'setxor1d', - 'setmember1d', 'union1d', 'setdiff1d', 'unique', 'in1d'] +__all__ = ['ediff1d', 'intersect1d', 'setxor1d', 'union1d', 'setdiff1d', + 'unique', 'in1d'] import numpy as np from numpy.lib.utils import deprecate @@ -417,72 +412,3 @@ def setdiff1d(ar1, ar2, assume_unique=False): return aux else: return np.asarray(ar1)[aux == 0] - -@deprecate -def unique1d(ar1, return_index=False, return_inverse=False): - """ - This function is deprecated. Use unique() instead. - """ - if return_index: - import warnings - warnings.warn("The order of the output arguments for " - "`return_index` has changed. Before, " - "the output was (indices, unique_arr), but " - "has now been reversed to be more consistent.") - - ar = np.asanyarray(ar1).flatten() - if ar.size == 0: - if return_inverse and return_index: - return ar, np.empty(0, np.bool), np.empty(0, np.bool) - elif return_inverse or return_index: - return ar, np.empty(0, np.bool) - else: - return ar - - if return_inverse or return_index: - perm = ar.argsort() - aux = ar[perm] - flag = np.concatenate(([True], aux[1:] != aux[:-1])) - if return_inverse: - iflag = np.cumsum(flag) - 1 - iperm = perm.argsort() - if return_index: - return aux[flag], perm[flag], iflag[iperm] - else: - return aux[flag], iflag[iperm] - else: - return aux[flag], perm[flag] - - else: - ar.sort() - flag = np.concatenate(([True], ar[1:] != ar[:-1])) - return ar[flag] - -@deprecate -def intersect1d_nu(ar1, ar2): - """ - This function is deprecated. Use intersect1d() - instead. - """ - # Might be faster than unique1d( intersect1d( ar1, ar2 ) )? - aux = np.concatenate((unique1d(ar1), unique1d(ar2))) - aux.sort() - return aux[aux[1:] == aux[:-1]] - -@deprecate -def setmember1d(ar1, ar2): - """ - This function is deprecated. Use in1d(assume_unique=True) - instead. - """ - # We need this to be a stable sort, so always use 'mergesort' here. The - # values from the first array should always come before the values from the - # second array. - ar = np.concatenate( (ar1, ar2 ) ) - order = ar.argsort(kind='mergesort') - sar = ar[order] - equal_adj = (sar[1:] == sar[:-1]) - flag = np.concatenate( (equal_adj, [False] ) ) - - indx = order.argsort(kind='mergesort')[:len( ar1 )] - return flag[indx] diff --git a/numpy/lib/benchmarks/bench_arraysetops.py b/numpy/lib/benchmarks/bench_arraysetops.py deleted file mode 100644 index 2c77fb758..000000000 --- a/numpy/lib/benchmarks/bench_arraysetops.py +++ /dev/null @@ -1,65 +0,0 @@ -import numpy as np -import time -from numpy.lib.arraysetops import * - -def bench_unique1d( plot_results = False ): - exponents = np.linspace( 2, 7, 9 ) - ratios = [] - nItems = [] - dt1s = [] - dt2s = [] - for ii in exponents: - - nItem = 10 ** ii - print 'using %d items:' % nItem - a = np.fix( nItem / 10 * np.random.random( nItem ) ) - - print 'unique:' - tt = time.clock() - b = np.unique( a ) - dt1 = time.clock() - tt - print dt1 - - print 'unique1d:' - tt = time.clock() - c = unique1d( a ) - dt2 = time.clock() - tt - print dt2 - - - if dt1 < 1e-8: - ratio = 'ND' - else: - ratio = dt2 / dt1 - print 'ratio:', ratio - print 'nUnique: %d == %d\n' % (len( b ), len( c )) - - nItems.append( nItem ) - ratios.append( ratio ) - dt1s.append( dt1 ) - dt2s.append( dt2 ) - - assert np.alltrue( b == c ) - - print nItems - print dt1s - print dt2s - print ratios - - if plot_results: - import pylab - - def plotMe( fig, fun, nItems, dt1s, dt2s ): - pylab.figure( fig ) - fun( nItems, dt1s, 'g-o', linewidth = 2, markersize = 8 ) - fun( nItems, dt2s, 'b-x', linewidth = 2, markersize = 8 ) - pylab.legend( ('unique', 'unique1d' ) ) - pylab.xlabel( 'nItem' ) - pylab.ylabel( 'time [s]' ) - - plotMe( 1, pylab.loglog, nItems, dt1s, dt2s ) - plotMe( 2, pylab.plot, nItems, dt1s, dt2s ) - pylab.show() - -if __name__ == '__main__': - bench_unique1d( plot_results = True ) diff --git a/numpy/lib/tests/test_arraysetops.py b/numpy/lib/tests/test_arraysetops.py index dac39cd50..907a27a8c 100644 --- a/numpy/lib/tests/test_arraysetops.py +++ b/numpy/lib/tests/test_arraysetops.py @@ -17,7 +17,7 @@ class TestAso(TestCase): assert_array_equal( c, ec ) vals, indices = unique( a, return_index=True ) - + ed = np.array( [2, 3, 0, 1] ) assert_array_equal(vals, ec) @@ -25,7 +25,7 @@ class TestAso(TestCase): vals, ind0, ind1 = unique( a, return_index=True, return_inverse=True ) - + ee = np.array( [2, 3, 0, 1, 0, 2, 3] ) assert_array_equal(vals, ec) @@ -53,21 +53,6 @@ class TestAso(TestCase): assert_array_equal([], intersect1d([],[])) - def test_intersect1d_nu( self ): - # This should be removed when intersect1d_nu is removed. - a = np.array( [5, 5, 7, 1, 2] ) - b = np.array( [2, 1, 4, 3, 3, 1, 5] ) - - ec = np.array( [1, 2, 5] ) - warnings.filterwarnings('ignore', message='\s*`intersect1d_nu` is deprecated!') - warnings.filterwarnings('ignore', message='\s*`unique1d` is deprecated!') - c = intersect1d_nu( a, b ) - assert_array_equal( c, ec ) - assert_array_equal([], intersect1d_nu([],[])) - warnings.filters.pop(0) - warnings.filters.pop(0) - - def test_setxor1d( self ): a = np.array( [5, 7, 1, 2] ) b = np.array( [2, 4, 3, 1, 5] ) @@ -104,30 +89,6 @@ class TestAso(TestCase): assert_array_equal([],ediff1d(one_elem)) assert_array_equal([1],ediff1d(two_elem)) - def test_setmember1d( self ): - # This should be removed when setmember1d is removed. - a = np.array( [5, 7, 1, 2] ) - b = np.array( [2, 4, 3, 1, 5] ) - - ec = np.array( [True, False, True, True] ) - warnings.filterwarnings('ignore', '\s*`setmember1d` is deprecated!') - c = setmember1d( a, b ) - - assert_array_equal( c, ec ) - - a[0] = 8 - ec = np.array( [False, False, True, True] ) - c = setmember1d( a, b ) - assert_array_equal( c, ec ) - - a[0], a[3] = 4, 8 - ec = np.array( [True, False, True, False] ) - c = setmember1d( a, b ) - assert_array_equal( c, ec ) - - assert_array_equal([], setmember1d([],[])) - warnings.filters.pop(0) - def test_in1d(self): a = np.array( [5, 7, 1, 2] ) b = np.array( [2, 4, 3, 1, 5] ) @@ -145,7 +106,7 @@ class TestAso(TestCase): ec = np.array( [True, False, True, False] ) c = in1d( a, b, assume_unique=True ) assert_array_equal( c, ec ) - + a = np.array([5,4,5,3,4,4,3,4,3,5,2,1,5,5]) b = [2,3,4] diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py index 5ca1e3d1b..1c28eadb8 100644 --- a/numpy/ma/extras.py +++ b/numpy/ma/extras.py @@ -1087,7 +1087,7 @@ def intersect1d(ar1, ar2, assume_unique=False): if assume_unique: aux = ma.concatenate((ar1, ar2)) else: - # Might be faster than unique1d( intersect1d( ar1, ar2 ) )? + # Might be faster than unique( intersect1d( ar1, ar2 ) )? aux = ma.concatenate((unique(ar1), unique(ar2))) aux.sort() return aux[aux[1:] == aux[:-1]] @@ -1522,7 +1522,7 @@ def flatnotmasked_edges(a): See Also -------- - flatnotmasked_contiguous, notmasked_contiguous, notmasked_edges, + flatnotmasked_contiguous, notmasked_contiguous, notmasked_edges, clump_masked, clump_unmasked Notes @@ -1637,7 +1637,7 @@ def flatnotmasked_contiguous(a): >>> a = np.ma.arange(10) >>> np.ma.extras.flatnotmasked_contiguous(a) slice(0, 10, None) - + >>> mask = (a < 3) | (a > 8) | (a == 5) >>> a[mask] = np.ma.masked >>> np.array(a[~a.mask]) @@ -1761,7 +1761,7 @@ def clump_unmasked(a): See Also -------- - flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges, + flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges, notmasked_contiguous, clump_masked Examples @@ -1805,7 +1805,7 @@ def clump_masked(a): See Also -------- - flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges, + flatnotmasked_edges, flatnotmasked_contiguous, notmasked_edges, notmasked_contiguous, clump_unmasked Examples |