From e76b5fa6896c09257181675bbf4cf47789d32927 Mon Sep 17 00:00:00 2001 From: Travis Oliphant Date: Sat, 15 Dec 2007 18:54:52 +0000 Subject: Create a branch for io work in NumPy --- numpy/lib/tests/test_arraysetops.py | 171 ------------- numpy/lib/tests/test_function_base.py | 454 ---------------------------------- numpy/lib/tests/test_getlimits.py | 55 ---- numpy/lib/tests/test_index_tricks.py | 51 ---- numpy/lib/tests/test_polynomial.py | 98 -------- numpy/lib/tests/test_shape_base.py | 412 ------------------------------ numpy/lib/tests/test_twodim_base.py | 200 --------------- numpy/lib/tests/test_type_check.py | 280 --------------------- numpy/lib/tests/test_ufunclike.py | 66 ----- 9 files changed, 1787 deletions(-) delete mode 100644 numpy/lib/tests/test_arraysetops.py delete mode 100644 numpy/lib/tests/test_function_base.py delete mode 100644 numpy/lib/tests/test_getlimits.py delete mode 100644 numpy/lib/tests/test_index_tricks.py delete mode 100644 numpy/lib/tests/test_polynomial.py delete mode 100644 numpy/lib/tests/test_shape_base.py delete mode 100644 numpy/lib/tests/test_twodim_base.py delete mode 100644 numpy/lib/tests/test_type_check.py delete mode 100644 numpy/lib/tests/test_ufunclike.py (limited to 'numpy/lib/tests') diff --git a/numpy/lib/tests/test_arraysetops.py b/numpy/lib/tests/test_arraysetops.py deleted file mode 100644 index e2e703b9a..000000000 --- a/numpy/lib/tests/test_arraysetops.py +++ /dev/null @@ -1,171 +0,0 @@ -""" Test functions for 1D array set operations. - -""" - -from numpy.testing import * -set_package_path() -import numpy -from numpy.lib.arraysetops import * -from numpy.lib.arraysetops import ediff1d -restore_path() - -################################################## - -class TestAso(NumpyTestCase): - ## - # 03.11.2005, c - def check_unique1d( self ): - - a = numpy.array( [5, 7, 1, 2, 1, 5, 7] ) - - ec = numpy.array( [1, 2, 5, 7] ) - c = unique1d( a ) - assert_array_equal( c, ec ) - - assert_array_equal([], unique1d([])) - - ## - # 03.11.2005, c - def check_intersect1d( self ): - - a = numpy.array( [5, 7, 1, 2] ) - b = numpy.array( [2, 4, 3, 1, 5] ) - - ec = numpy.array( [1, 2, 5] ) - c = intersect1d( a, b ) - assert_array_equal( c, ec ) - - assert_array_equal([], intersect1d([],[])) - - ## - # 03.11.2005, c - def check_intersect1d_nu( self ): - - a = numpy.array( [5, 5, 7, 1, 2] ) - b = numpy.array( [2, 1, 4, 3, 3, 1, 5] ) - - ec = numpy.array( [1, 2, 5] ) - c = intersect1d_nu( a, b ) - assert_array_equal( c, ec ) - - assert_array_equal([], intersect1d_nu([],[])) - - ## - # 03.11.2005, c - def check_setxor1d( self ): - - a = numpy.array( [5, 7, 1, 2] ) - b = numpy.array( [2, 4, 3, 1, 5] ) - - ec = numpy.array( [3, 4, 7] ) - c = setxor1d( a, b ) - assert_array_equal( c, ec ) - - a = numpy.array( [1, 2, 3] ) - b = numpy.array( [6, 5, 4] ) - - ec = numpy.array( [1, 2, 3, 4, 5, 6] ) - c = setxor1d( a, b ) - assert_array_equal( c, ec ) - - a = numpy.array( [1, 8, 2, 3] ) - b = numpy.array( [6, 5, 4, 8] ) - - ec = numpy.array( [1, 2, 3, 4, 5, 6] ) - c = setxor1d( a, b ) - assert_array_equal( c, ec ) - - assert_array_equal([], setxor1d([],[])) - - def check_ediff1d(self): - zero_elem = numpy.array([]) - one_elem = numpy.array([1]) - two_elem = numpy.array([1,2]) - - assert_array_equal([],ediff1d(zero_elem)) - assert_array_equal([0],ediff1d(zero_elem,to_begin=0)) - assert_array_equal([0],ediff1d(zero_elem,to_end=0)) - assert_array_equal([-1,0],ediff1d(zero_elem,to_begin=-1,to_end=0)) - assert_array_equal([],ediff1d(one_elem)) - assert_array_equal([1],ediff1d(two_elem)) - - ## - # 03.11.2005, c - def check_setmember1d( self ): - - a = numpy.array( [5, 7, 1, 2] ) - b = numpy.array( [2, 4, 3, 1, 5] ) - - ec = numpy.array( [True, False, True, True] ) - c = setmember1d( a, b ) - assert_array_equal( c, ec ) - - a[0] = 8 - ec = numpy.array( [False, False, True, True] ) - c = setmember1d( a, b ) - assert_array_equal( c, ec ) - - a[0], a[3] = 4, 8 - ec = numpy.array( [True, False, True, False] ) - c = setmember1d( a, b ) - assert_array_equal( c, ec ) - - assert_array_equal([], setmember1d([],[])) - - ## - # 03.11.2005, c - def check_union1d( self ): - - a = numpy.array( [5, 4, 7, 1, 2] ) - b = numpy.array( [2, 4, 3, 3, 2, 1, 5] ) - - ec = numpy.array( [1, 2, 3, 4, 5, 7] ) - c = union1d( a, b ) - assert_array_equal( c, ec ) - - assert_array_equal([], union1d([],[])) - - ## - # 03.11.2005, c - # 09.01.2006 - def check_setdiff1d( self ): - - a = numpy.array( [6, 5, 4, 7, 1, 2] ) - b = numpy.array( [2, 4, 3, 3, 2, 1, 5] ) - - ec = numpy.array( [6, 7] ) - c = setdiff1d( a, b ) - assert_array_equal( c, ec ) - - a = numpy.arange( 21 ) - b = numpy.arange( 19 ) - ec = numpy.array( [19, 20] ) - c = setdiff1d( a, b ) - assert_array_equal( c, ec ) - - assert_array_equal([], setdiff1d([],[])) - - - ## - # 03.11.2005, c - def check_manyways( self ): - - nItem = 100 - a = numpy.fix( nItem / 10 * numpy.random.random( nItem ) ) - b = numpy.fix( nItem / 10 * numpy.random.random( nItem ) ) - - c1 = intersect1d_nu( a, b ) - c2 = unique1d( intersect1d( a, b ) ) - assert_array_equal( c1, c2 ) - - a = numpy.array( [5, 7, 1, 2, 8] ) - b = numpy.array( [9, 8, 2, 4, 3, 1, 5] ) - - c1 = setxor1d( a, b ) - aux1 = intersect1d( a, b ) - aux2 = union1d( a, b ) - c2 = setdiff1d( aux2, aux1 ) - assert_array_equal( c1, c2 ) - -if __name__ == "__main__": - NumpyTest().run() diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py deleted file mode 100644 index f1b64c8d5..000000000 --- a/numpy/lib/tests/test_function_base.py +++ /dev/null @@ -1,454 +0,0 @@ -import sys - -from numpy.testing import * -set_package_path() -import numpy.lib;reload(numpy.lib) -from numpy.lib import * -from numpy.core import * -del sys.path[0] - -class TestAny(NumpyTestCase): - def check_basic(self): - y1 = [0,0,1,0] - y2 = [0,0,0,0] - y3 = [1,0,1,0] - assert(any(y1)) - assert(any(y3)) - assert(not any(y2)) - - def check_nd(self): - y1 = [[0,0,0],[0,1,0],[1,1,0]] - assert(any(y1)) - assert_array_equal(sometrue(y1,axis=0),[1,1,0]) - assert_array_equal(sometrue(y1,axis=1),[0,1,1]) - -class TestAll(NumpyTestCase): - def check_basic(self): - y1 = [0,1,1,0] - y2 = [0,0,0,0] - y3 = [1,1,1,1] - assert(not all(y1)) - assert(all(y3)) - assert(not all(y2)) - assert(all(~array(y2))) - - def check_nd(self): - y1 = [[0,0,1],[0,1,1],[1,1,1]] - assert(not all(y1)) - assert_array_equal(alltrue(y1,axis=0),[0,0,1]) - assert_array_equal(alltrue(y1,axis=1),[0,0,1]) - -class TestAverage(NumpyTestCase): - def check_basic(self): - y1 = array([1,2,3]) - assert(average(y1,axis=0) == 2.) - y2 = array([1.,2.,3.]) - assert(average(y2,axis=0) == 2.) - y3 = [0.,0.,0.] - assert(average(y3,axis=0) == 0.) - - y4 = ones((4,4)) - y4[0,1] = 0 - y4[1,0] = 2 - assert_array_equal(y4.mean(0), average(y4, 0)) - assert_array_equal(y4.mean(1), average(y4, 1)) - - y5 = rand(5,5) - assert_array_equal(y5.mean(0), average(y5, 0)) - assert_array_equal(y5.mean(1), average(y5, 1)) - - def check_weighted(self): - y1 = array([[1,2,3], - [4,5,6]]) - actual = average(y1,weights=[1,2],axis=0) - desired = array([3.,4.,5.]) - assert_array_equal(actual, desired) - -class TestSelect(NumpyTestCase): - def _select(self,cond,values,default=0): - output = [] - for m in range(len(cond)): - output += [V[m] for V,C in zip(values,cond) if C[m]] or [default] - return output - - def check_basic(self): - choices = [array([1,2,3]), - array([4,5,6]), - array([7,8,9])] - conditions = [array([0,0,0]), - array([0,1,0]), - array([0,0,1])] - assert_array_equal(select(conditions,choices,default=15), - self._select(conditions,choices,default=15)) - - assert_equal(len(choices),3) - assert_equal(len(conditions),3) - -class TestLogspace(NumpyTestCase): - def check_basic(self): - y = logspace(0,6) - assert(len(y)==50) - y = logspace(0,6,num=100) - assert(y[-1] == 10**6) - y = logspace(0,6,endpoint=0) - assert(y[-1] < 10**6) - y = logspace(0,6,num=7) - assert_array_equal(y,[1,10,100,1e3,1e4,1e5,1e6]) - -class TestLinspace(NumpyTestCase): - def check_basic(self): - y = linspace(0,10) - assert(len(y)==50) - y = linspace(2,10,num=100) - assert(y[-1] == 10) - y = linspace(2,10,endpoint=0) - assert(y[-1] < 10) - y,st = linspace(2,10,retstep=1) - assert_almost_equal(st,8/49.0) - assert_array_almost_equal(y,mgrid[2:10:50j],13) - - def check_corner(self): - y = list(linspace(0,1,1)) - assert y == [0.0], y - y = list(linspace(0,1,2.5)) - assert y == [0.0, 1.0] - - def check_type(self): - t1 = linspace(0,1,0).dtype - t2 = linspace(0,1,1).dtype - t3 = linspace(0,1,2).dtype - assert_equal(t1, t2) - assert_equal(t2, t3) - -class TestInsert(NumpyTestCase): - def check_basic(self): - a = [1,2,3] - assert_equal(insert(a,0,1), [1,1,2,3]) - assert_equal(insert(a,3,1), [1,2,3,1]) - assert_equal(insert(a,[1,1,1],[1,2,3]), [1,1,2,3,2,3]) - -class TestAmax(NumpyTestCase): - def check_basic(self): - a = [3,4,5,10,-3,-5,6.0] - assert_equal(amax(a),10.0) - b = [[3,6.0, 9.0], - [4,10.0,5.0], - [8,3.0,2.0]] - assert_equal(amax(b,axis=0),[8.0,10.0,9.0]) - assert_equal(amax(b,axis=1),[9.0,10.0,8.0]) - -class TestAmin(NumpyTestCase): - def check_basic(self): - a = [3,4,5,10,-3,-5,6.0] - assert_equal(amin(a),-5.0) - b = [[3,6.0, 9.0], - [4,10.0,5.0], - [8,3.0,2.0]] - assert_equal(amin(b,axis=0),[3.0,3.0,2.0]) - assert_equal(amin(b,axis=1),[3.0,4.0,2.0]) - -class TestPtp(NumpyTestCase): - def check_basic(self): - a = [3,4,5,10,-3,-5,6.0] - assert_equal(ptp(a,axis=0),15.0) - b = [[3,6.0, 9.0], - [4,10.0,5.0], - [8,3.0,2.0]] - assert_equal(ptp(b,axis=0),[5.0,7.0,7.0]) - assert_equal(ptp(b,axis=-1),[6.0,6.0,6.0]) - -class TestCumsum(NumpyTestCase): - def check_basic(self): - ba = [1,2,10,11,6,5,4] - ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]] - for ctype in [int8,uint8,int16,uint16,int32,uint32, - float32,float64,complex64,complex128]: - a = array(ba,ctype) - a2 = array(ba2,ctype) - assert_array_equal(cumsum(a,axis=0), array([1,3,13,24,30,35,39],ctype)) - assert_array_equal(cumsum(a2,axis=0), array([[1,2,3,4],[6,8,10,13], - [16,11,14,18]],ctype)) - assert_array_equal(cumsum(a2,axis=1), - array([[1,3,6,10], - [5,11,18,27], - [10,13,17,22]],ctype)) - -class TestProd(NumpyTestCase): - def check_basic(self): - ba = [1,2,10,11,6,5,4] - ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]] - for ctype in [int16,uint16,int32,uint32, - float32,float64,complex64,complex128]: - a = array(ba,ctype) - a2 = array(ba2,ctype) - if ctype in ['1', 'b']: - self.failUnlessRaises(ArithmeticError, prod, a) - self.failUnlessRaises(ArithmeticError, prod, a2, 1) - self.failUnlessRaises(ArithmeticError, prod, a) - else: - assert_equal(prod(a,axis=0),26400) - assert_array_equal(prod(a2,axis=0), - array([50,36,84,180],ctype)) - assert_array_equal(prod(a2,axis=-1),array([24, 1890, 600],ctype)) - -class TestCumprod(NumpyTestCase): - def check_basic(self): - ba = [1,2,10,11,6,5,4] - ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]] - for ctype in [int16,uint16,int32,uint32, - float32,float64,complex64,complex128]: - a = array(ba,ctype) - a2 = array(ba2,ctype) - if ctype in ['1', 'b']: - self.failUnlessRaises(ArithmeticError, cumprod, a) - self.failUnlessRaises(ArithmeticError, cumprod, a2, 1) - self.failUnlessRaises(ArithmeticError, cumprod, a) - else: - assert_array_equal(cumprod(a,axis=-1), - array([1, 2, 20, 220, - 1320, 6600, 26400],ctype)) - assert_array_equal(cumprod(a2,axis=0), - array([[ 1, 2, 3, 4], - [ 5, 12, 21, 36], - [50, 36, 84, 180]],ctype)) - assert_array_equal(cumprod(a2,axis=-1), - array([[ 1, 2, 6, 24], - [ 5, 30, 210, 1890], - [10, 30, 120, 600]],ctype)) - -class TestDiff(NumpyTestCase): - def check_basic(self): - x = [1,4,6,7,12] - out = array([3,2,1,5]) - out2 = array([-1,-1,4]) - out3 = array([0,5]) - assert_array_equal(diff(x),out) - assert_array_equal(diff(x,n=2),out2) - assert_array_equal(diff(x,n=3),out3) - - def check_nd(self): - x = 20*rand(10,20,30) - out1 = x[:,:,1:] - x[:,:,:-1] - out2 = out1[:,:,1:] - out1[:,:,:-1] - out3 = x[1:,:,:] - x[:-1,:,:] - out4 = out3[1:,:,:] - out3[:-1,:,:] - assert_array_equal(diff(x),out1) - assert_array_equal(diff(x,n=2),out2) - assert_array_equal(diff(x,axis=0),out3) - assert_array_equal(diff(x,n=2,axis=0),out4) - -class TestAngle(NumpyTestCase): - def check_basic(self): - x = [1+3j,sqrt(2)/2.0+1j*sqrt(2)/2,1,1j,-1,-1j,1-3j,-1+3j] - y = angle(x) - yo = [arctan(3.0/1.0),arctan(1.0),0,pi/2,pi,-pi/2.0, - -arctan(3.0/1.0),pi-arctan(3.0/1.0)] - z = angle(x,deg=1) - zo = array(yo)*180/pi - assert_array_almost_equal(y,yo,11) - assert_array_almost_equal(z,zo,11) - -class TestTrimZeros(NumpyTestCase): - """ only testing for integer splits. - """ - def check_basic(self): - a= array([0,0,1,2,3,4,0]) - res = trim_zeros(a) - assert_array_equal(res,array([1,2,3,4])) - def check_leading_skip(self): - a= array([0,0,1,0,2,3,4,0]) - res = trim_zeros(a) - assert_array_equal(res,array([1,0,2,3,4])) - def check_trailing_skip(self): - a= array([0,0,1,0,2,3,0,4,0]) - res = trim_zeros(a) - assert_array_equal(res,array([1,0,2,3,0,4])) - - -class TestExtins(NumpyTestCase): - def check_basic(self): - a = array([1,3,2,1,2,3,3]) - b = extract(a>1,a) - assert_array_equal(b,[3,2,2,3,3]) - def check_place(self): - a = array([1,4,3,2,5,8,7]) - place(a,[0,1,0,1,0,1,0],[2,4,6]) - assert_array_equal(a,[1,2,3,4,5,6,7]) - def check_both(self): - a = rand(10) - mask = a > 0.5 - ac = a.copy() - c = extract(mask, a) - place(a,mask,0) - place(a,mask,c) - assert_array_equal(a,ac) - -class TestVectorize(NumpyTestCase): - def check_simple(self): - def addsubtract(a,b): - if a > b: - return a - b - else: - return a + b - f = vectorize(addsubtract) - r = f([0,3,6,9],[1,3,5,7]) - assert_array_equal(r,[1,6,1,2]) - def check_scalar(self): - def addsubtract(a,b): - if a > b: - return a - b - else: - return a + b - f = vectorize(addsubtract) - r = f([0,3,6,9],5) - assert_array_equal(r,[5,8,1,4]) - def check_large(self): - x = linspace(-3,2,10000) - f = vectorize(lambda x: x) - y = f(x) - assert_array_equal(y, x) - -class TestDigitize(NumpyTestCase): - def check_forward(self): - x = arange(-6,5) - bins = arange(-5,5) - assert_array_equal(digitize(x,bins),arange(11)) - - def check_reverse(self): - x = arange(5,-6,-1) - bins = arange(5,-5,-1) - assert_array_equal(digitize(x,bins),arange(11)) - - def check_random(self): - x = rand(10) - bin = linspace(x.min(), x.max(), 10) - assert all(digitize(x,bin) != 0) - -class TestUnwrap(NumpyTestCase): - def check_simple(self): - #check that unwrap removes jumps greather that 2*pi - assert_array_equal(unwrap([1,1+2*pi]),[1,1]) - #check that unwrap maintans continuity - assert(all(diff(unwrap(rand(10)*100))>> import numpy.core as nx ->>> from numpy.lib.polynomial import poly1d, polydiv - ->>> p = poly1d([1.,2,3]) ->>> p -poly1d([ 1., 2., 3.]) ->>> print p - 2 -1 x + 2 x + 3 ->>> q = poly1d([3.,2,1]) ->>> q -poly1d([ 3., 2., 1.]) ->>> print q - 2 -3 x + 2 x + 1 - ->>> p(0) -3.0 ->>> p(5) -38.0 ->>> q(0) -1.0 ->>> q(5) -86.0 - ->>> p * q -poly1d([ 3., 8., 14., 8., 3.]) ->>> p / q -(poly1d([ 0.33333333]), poly1d([ 1.33333333, 2.66666667])) ->>> p + q -poly1d([ 4., 4., 4.]) ->>> p - q -poly1d([-2., 0., 2.]) ->>> p ** 4 -poly1d([ 1., 8., 36., 104., 214., 312., 324., 216., 81.]) - ->>> p(q) -poly1d([ 9., 12., 16., 8., 6.]) ->>> q(p) -poly1d([ 3., 12., 32., 40., 34.]) - ->>> nx.asarray(p) -array([ 1., 2., 3.]) ->>> len(p) -2 - ->>> p[0], p[1], p[2], p[3] -(3.0, 2.0, 1.0, 0) - ->>> p.integ() -poly1d([ 0.33333333, 1. , 3. , 0. ]) ->>> p.integ(1) -poly1d([ 0.33333333, 1. , 3. , 0. ]) ->>> p.integ(5) -poly1d([ 0.00039683, 0.00277778, 0.025 , 0. , 0. , - 0. , 0. , 0. ]) ->>> p.deriv() -poly1d([ 2., 2.]) ->>> p.deriv(2) -poly1d([ 2.]) - ->>> q = poly1d([1.,2,3], variable='y') ->>> print q - 2 -1 y + 2 y + 3 ->>> q = poly1d([1.,2,3], variable='lambda') ->>> print q - 2 -1 lambda + 2 lambda + 3 - ->>> polydiv(poly1d([1,0,-1]), poly1d([1,1])) -(poly1d([ 1., -1.]), poly1d([ 0.])) -""" - -from numpy.testing import * -import numpy as N - -class TestDocs(NumpyTestCase): - def check_doctests(self): return self.rundocs() - - def check_roots(self): - assert_array_equal(N.roots([1,0,0]), [0,0]) - - def check_str_leading_zeros(self): - p = N.poly1d([4,3,2,1]) - p[3] = 0 - assert_equal(str(p), - " 2\n" - "3 x + 2 x + 1") - - p = N.poly1d([1,2]) - p[0] = 0 - p[1] = 0 - assert_equal(str(p), " \n0") - -if __name__ == "__main__": - NumpyTest().run() diff --git a/numpy/lib/tests/test_shape_base.py b/numpy/lib/tests/test_shape_base.py deleted file mode 100644 index 320871a95..000000000 --- a/numpy/lib/tests/test_shape_base.py +++ /dev/null @@ -1,412 +0,0 @@ -from numpy.testing import * -set_package_path() -import numpy.lib; -from numpy.lib import * -from numpy.core import * -restore_path() - -class TestApplyAlongAxis(NumpyTestCase): - def check_simple(self): - a = ones((20,10),'d') - assert_array_equal(apply_along_axis(len,0,a),len(a)*ones(shape(a)[1])) - def check_simple101(self,level=11): - a = ones((10,101),'d') - assert_array_equal(apply_along_axis(len,0,a),len(a)*ones(shape(a)[1])) - - def check_3d(self): - a = arange(27).reshape((3,3,3)) - assert_array_equal(apply_along_axis(sum,0,a), [[27,30,33],[36,39,42],[45,48,51]]) - -class TestArraySplit(NumpyTestCase): - def check_integer_0_split(self): - a = arange(10) - try: - res = array_split(a,0) - assert(0) # it should have thrown a value error - except ValueError: - pass - def check_integer_split(self): - a = arange(10) - res = array_split(a,1) - desired = [arange(10)] - compare_results(res,desired) - - res = array_split(a,2) - desired = [arange(5),arange(5,10)] - compare_results(res,desired) - - res = array_split(a,3) - desired = [arange(4),arange(4,7),arange(7,10)] - compare_results(res,desired) - - res = array_split(a,4) - desired = [arange(3),arange(3,6),arange(6,8),arange(8,10)] - compare_results(res,desired) - - res = array_split(a,5) - desired = [arange(2),arange(2,4),arange(4,6),arange(6,8),arange(8,10)] - compare_results(res,desired) - - res = array_split(a,6) - desired = [arange(2),arange(2,4),arange(4,6),arange(6,8),arange(8,9), - arange(9,10)] - compare_results(res,desired) - - res = array_split(a,7) - desired = [arange(2),arange(2,4),arange(4,6),arange(6,7),arange(7,8), - arange(8,9), arange(9,10)] - compare_results(res,desired) - - res = array_split(a,8) - desired = [arange(2),arange(2,4),arange(4,5),arange(5,6),arange(6,7), - arange(7,8), arange(8,9), arange(9,10)] - compare_results(res,desired) - - res = array_split(a,9) - desired = [arange(2),arange(2,3),arange(3,4),arange(4,5),arange(5,6), - arange(6,7), arange(7,8), arange(8,9), arange(9,10)] - compare_results(res,desired) - - res = array_split(a,10) - desired = [arange(1),arange(1,2),arange(2,3),arange(3,4), - arange(4,5),arange(5,6), arange(6,7), arange(7,8), - arange(8,9), arange(9,10)] - compare_results(res,desired) - - res = array_split(a,11) - desired = [arange(1),arange(1,2),arange(2,3),arange(3,4), - arange(4,5),arange(5,6), arange(6,7), arange(7,8), - arange(8,9), arange(9,10),array([])] - compare_results(res,desired) - def check_integer_split_2D_rows(self): - a = array([arange(10),arange(10)]) - res = array_split(a,3,axis=0) - desired = [array([arange(10)]),array([arange(10)]),array([])] - compare_results(res,desired) - def check_integer_split_2D_cols(self): - a = array([arange(10),arange(10)]) - res = array_split(a,3,axis=-1) - desired = [array([arange(4),arange(4)]), - array([arange(4,7),arange(4,7)]), - array([arange(7,10),arange(7,10)])] - compare_results(res,desired) - def check_integer_split_2D_default(self): - """ This will fail if we change default axis - """ - a = array([arange(10),arange(10)]) - res = array_split(a,3) - desired = [array([arange(10)]),array([arange(10)]),array([])] - compare_results(res,desired) - #perhaps should check higher dimensions - - def check_index_split_simple(self): - a = arange(10) - indices = [1,5,7] - res = array_split(a,indices,axis=-1) - desired = [arange(0,1),arange(1,5),arange(5,7),arange(7,10)] - compare_results(res,desired) - - def check_index_split_low_bound(self): - a = arange(10) - indices = [0,5,7] - res = array_split(a,indices,axis=-1) - desired = [array([]),arange(0,5),arange(5,7),arange(7,10)] - compare_results(res,desired) - def check_index_split_high_bound(self): - a = arange(10) - indices = [0,5,7,10,12] - res = array_split(a,indices,axis=-1) - desired = [array([]),arange(0,5),arange(5,7),arange(7,10), - array([]),array([])] - compare_results(res,desired) - -class TestSplit(NumpyTestCase): - """* This function is essentially the same as array_split, - except that it test if splitting will result in an - equal split. Only test for this case. - *""" - def check_equal_split(self): - a = arange(10) - res = split(a,2) - desired = [arange(5),arange(5,10)] - compare_results(res,desired) - - def check_unequal_split(self): - a = arange(10) - try: - res = split(a,3) - assert(0) # should raise an error - except ValueError: - pass - -class TestAtleast1d(NumpyTestCase): - def check_0D_array(self): - a = array(1); b = array(2); - res=map(atleast_1d,[a,b]) - desired = [array([1]),array([2])] - assert_array_equal(res,desired) - def check_1D_array(self): - a = array([1,2]); b = array([2,3]); - res=map(atleast_1d,[a,b]) - desired = [array([1,2]),array([2,3])] - assert_array_equal(res,desired) - def check_2D_array(self): - a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]); - res=map(atleast_1d,[a,b]) - desired = [a,b] - assert_array_equal(res,desired) - def check_3D_array(self): - a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]); - a = array([a,a]);b = array([b,b]); - res=map(atleast_1d,[a,b]) - desired = [a,b] - assert_array_equal(res,desired) - def check_r1array(self): - """ Test to make sure equivalent Travis O's r1array function - """ - assert(atleast_1d(3).shape == (1,)) - assert(atleast_1d(3j).shape == (1,)) - assert(atleast_1d(3L).shape == (1,)) - assert(atleast_1d(3.0).shape == (1,)) - assert(atleast_1d([[2,3],[4,5]]).shape == (2,2)) - -class TestAtleast2d(NumpyTestCase): - def check_0D_array(self): - a = array(1); b = array(2); - res=map(atleast_2d,[a,b]) - desired = [array([[1]]),array([[2]])] - assert_array_equal(res,desired) - def check_1D_array(self): - a = array([1,2]); b = array([2,3]); - res=map(atleast_2d,[a,b]) - desired = [array([[1,2]]),array([[2,3]])] - assert_array_equal(res,desired) - def check_2D_array(self): - a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]); - res=map(atleast_2d,[a,b]) - desired = [a,b] - assert_array_equal(res,desired) - def check_3D_array(self): - a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]); - a = array([a,a]);b = array([b,b]); - res=map(atleast_2d,[a,b]) - desired = [a,b] - assert_array_equal(res,desired) - def check_r2array(self): - """ Test to make sure equivalent Travis O's r2array function - """ - assert(atleast_2d(3).shape == (1,1)) - assert(atleast_2d([3j,1]).shape == (1,2)) - assert(atleast_2d([[[3,1],[4,5]],[[3,5],[1,2]]]).shape == (2,2,2)) - -class TestAtleast3d(NumpyTestCase): - def check_0D_array(self): - a = array(1); b = array(2); - res=map(atleast_3d,[a,b]) - desired = [array([[[1]]]),array([[[2]]])] - assert_array_equal(res,desired) - def check_1D_array(self): - a = array([1,2]); b = array([2,3]); - res=map(atleast_3d,[a,b]) - desired = [array([[[1],[2]]]),array([[[2],[3]]])] - assert_array_equal(res,desired) - def check_2D_array(self): - a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]); - res=map(atleast_3d,[a,b]) - desired = [a[:,:,newaxis],b[:,:,newaxis]] - assert_array_equal(res,desired) - def check_3D_array(self): - a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]); - a = array([a,a]);b = array([b,b]); - res=map(atleast_3d,[a,b]) - desired = [a,b] - assert_array_equal(res,desired) - -class TestHstack(NumpyTestCase): - def check_0D_array(self): - a = array(1); b = array(2); - res=hstack([a,b]) - desired = array([1,2]) - assert_array_equal(res,desired) - def check_1D_array(self): - a = array([1]); b = array([2]); - res=hstack([a,b]) - desired = array([1,2]) - assert_array_equal(res,desired) - def check_2D_array(self): - a = array([[1],[2]]); b = array([[1],[2]]); - res=hstack([a,b]) - desired = array([[1,1],[2,2]]) - assert_array_equal(res,desired) - -class TestVstack(NumpyTestCase): - def check_0D_array(self): - a = array(1); b = array(2); - res=vstack([a,b]) - desired = array([[1],[2]]) - assert_array_equal(res,desired) - def check_1D_array(self): - a = array([1]); b = array([2]); - res=vstack([a,b]) - desired = array([[1],[2]]) - assert_array_equal(res,desired) - def check_2D_array(self): - a = array([[1],[2]]); b = array([[1],[2]]); - res=vstack([a,b]) - desired = array([[1],[2],[1],[2]]) - assert_array_equal(res,desired) - def check_2D_array2(self): - a = array([1,2]); b = array([1,2]); - res=vstack([a,b]) - desired = array([[1,2],[1,2]]) - assert_array_equal(res,desired) - -class TestDstack(NumpyTestCase): - def check_0D_array(self): - a = array(1); b = array(2); - res=dstack([a,b]) - desired = array([[[1,2]]]) - assert_array_equal(res,desired) - def check_1D_array(self): - a = array([1]); b = array([2]); - res=dstack([a,b]) - desired = array([[[1,2]]]) - assert_array_equal(res,desired) - def check_2D_array(self): - a = array([[1],[2]]); b = array([[1],[2]]); - res=dstack([a,b]) - desired = array([[[1,1]],[[2,2,]]]) - assert_array_equal(res,desired) - def check_2D_array2(self): - a = array([1,2]); b = array([1,2]); - res=dstack([a,b]) - desired = array([[[1,1],[2,2]]]) - assert_array_equal(res,desired) - -""" array_split has more comprehensive test of splitting. - only do simple test on hsplit, vsplit, and dsplit -""" -class TestHsplit(NumpyTestCase): - """ only testing for integer splits. - """ - def check_0D_array(self): - a= array(1) - try: - hsplit(a,2) - assert(0) - except ValueError: - pass - def check_1D_array(self): - a= array([1,2,3,4]) - res = hsplit(a,2) - desired = [array([1,2]),array([3,4])] - compare_results(res,desired) - def check_2D_array(self): - a= array([[1,2,3,4], - [1,2,3,4]]) - res = hsplit(a,2) - desired = [array([[1,2],[1,2]]),array([[3,4],[3,4]])] - compare_results(res,desired) - -class TestVsplit(NumpyTestCase): - """ only testing for integer splits. - """ - def check_1D_array(self): - a= array([1,2,3,4]) - try: - vsplit(a,2) - assert(0) - except ValueError: - pass - def check_2D_array(self): - a= array([[1,2,3,4], - [1,2,3,4]]) - res = vsplit(a,2) - desired = [array([[1,2,3,4]]),array([[1,2,3,4]])] - compare_results(res,desired) - -class TestDsplit(NumpyTestCase): - """ only testing for integer splits. - """ - def check_2D_array(self): - a= array([[1,2,3,4], - [1,2,3,4]]) - try: - dsplit(a,2) - assert(0) - except ValueError: - pass - def check_3D_array(self): - a= array([[[1,2,3,4], - [1,2,3,4]], - [[1,2,3,4], - [1,2,3,4]]]) - res = dsplit(a,2) - desired = [array([[[1,2],[1,2]],[[1,2],[1,2]]]), - array([[[3,4],[3,4]],[[3,4],[3,4]]])] - compare_results(res,desired) - -class TestSqueeze(NumpyTestCase): - def check_basic(self): - a = rand(20,10,10,1,1) - b = rand(20,1,10,1,20) - c = rand(1,1,20,10) - assert_array_equal(squeeze(a),reshape(a,(20,10,10))) - assert_array_equal(squeeze(b),reshape(b,(20,10,20))) - assert_array_equal(squeeze(c),reshape(c,(20,10))) - -class TestKron(NumpyTestCase): - def check_return_type(self): - a = ones([2,2]) - m = asmatrix(a) - assert_equal(type(kron(a,a)), ndarray) - assert_equal(type(kron(m,m)), matrix) - assert_equal(type(kron(a,m)), matrix) - assert_equal(type(kron(m,a)), matrix) - class myarray(ndarray): - __array_priority__ = 0.0 - ma = myarray(a.shape, a.dtype, a.data) - assert_equal(type(kron(a,a)), ndarray) - assert_equal(type(kron(ma,ma)), myarray) - assert_equal(type(kron(a,ma)), ndarray) - assert_equal(type(kron(ma,a)), myarray) - - -class TestTile(NumpyTestCase): - def check_basic(self): - a = array([0,1,2]) - b = [[1,2],[3,4]] - assert_equal(tile(a,2), [0,1,2,0,1,2]) - assert_equal(tile(a,(2,2)), [[0,1,2,0,1,2],[0,1,2,0,1,2]]) - assert_equal(tile(a,(1,2)), [[0,1,2,0,1,2]]) - assert_equal(tile(b, 2), [[1,2,1,2],[3,4,3,4]]) - assert_equal(tile(b,(2,1)),[[1,2],[3,4],[1,2],[3,4]]) - assert_equal(tile(b,(2,2)),[[1,2,1,2],[3,4,3,4], - [1,2,1,2],[3,4,3,4]]) - - def check_empty(self): - a = array([[[]]]) - d = tile(a,(3,2,5)).shape - assert_equal(d,(3,2,0)) - - def check_kroncompare(self): - import numpy.random as nr - reps=[(2,),(1,2),(2,1),(2,2),(2,3,2),(3,2)] - shape=[(3,),(2,3),(3,4,3),(3,2,3),(4,3,2,4),(2,2)] - for s in shape: - b = nr.randint(0,10,size=s) - for r in reps: - a = ones(r, b.dtype) - large = tile(b, r) - klarge = kron(a, b) - assert_equal(large, klarge) - -# Utility - -def compare_results(res,desired): - for i in range(len(desired)): - assert_array_equal(res[i],desired[i]) - - -if __name__ == "__main__": - NumpyTest().run() diff --git a/numpy/lib/tests/test_twodim_base.py b/numpy/lib/tests/test_twodim_base.py deleted file mode 100644 index 3a9e8df80..000000000 --- a/numpy/lib/tests/test_twodim_base.py +++ /dev/null @@ -1,200 +0,0 @@ -""" Test functions for matrix module - -""" - -from numpy.testing import * -set_package_path() -from numpy import arange, rot90, add, fliplr, flipud, zeros, ones, eye, \ - array, diag, histogram2d, tri -import numpy as np -restore_path() - -################################################## - - -def get_mat(n): - data = arange(n) - data = add.outer(data,data) - return data - -class TestEye(NumpyTestCase): - def check_basic(self): - assert_equal(eye(4),array([[1,0,0,0], - [0,1,0,0], - [0,0,1,0], - [0,0,0,1]])) - assert_equal(eye(4,dtype='f'),array([[1,0,0,0], - [0,1,0,0], - [0,0,1,0], - [0,0,0,1]],'f')) - assert_equal(eye(3) == 1, eye(3,dtype=bool)) - - def check_diag(self): - assert_equal(eye(4,k=1),array([[0,1,0,0], - [0,0,1,0], - [0,0,0,1], - [0,0,0,0]])) - assert_equal(eye(4,k=-1),array([[0,0,0,0], - [1,0,0,0], - [0,1,0,0], - [0,0,1,0]])) - def check_2d(self): - assert_equal(eye(4,3),array([[1,0,0], - [0,1,0], - [0,0,1], - [0,0,0]])) - assert_equal(eye(3,4),array([[1,0,0,0], - [0,1,0,0], - [0,0,1,0]])) - def check_diag2d(self): - assert_equal(eye(3,4,k=2),array([[0,0,1,0], - [0,0,0,1], - [0,0,0,0]])) - assert_equal(eye(4,3,k=-2),array([[0,0,0], - [0,0,0], - [1,0,0], - [0,1,0]])) - -class TestDiag(NumpyTestCase): - def check_vector(self): - vals = (100*arange(5)).astype('l') - b = zeros((5,5)) - for k in range(5): - b[k,k] = vals[k] - assert_equal(diag(vals),b) - b = zeros((7,7)) - c = b.copy() - for k in range(5): - b[k,k+2] = vals[k] - c[k+2,k] = vals[k] - assert_equal(diag(vals,k=2), b) - assert_equal(diag(vals,k=-2), c) - - def check_matrix(self): - vals = (100*get_mat(5)+1).astype('l') - b = zeros((5,)) - for k in range(5): - b[k] = vals[k,k] - assert_equal(diag(vals),b) - b = b*0 - for k in range(3): - b[k] = vals[k,k+2] - assert_equal(diag(vals,2),b[:3]) - for k in range(3): - b[k] = vals[k+2,k] - assert_equal(diag(vals,-2),b[:3]) - -class TestFliplr(NumpyTestCase): - def check_basic(self): - self.failUnlessRaises(ValueError, fliplr, ones(4)) - a = get_mat(4) - b = a[:,::-1] - assert_equal(fliplr(a),b) - a = [[0,1,2], - [3,4,5]] - b = [[2,1,0], - [5,4,3]] - assert_equal(fliplr(a),b) - -class TestFlipud(NumpyTestCase): - def check_basic(self): - a = get_mat(4) - b = a[::-1,:] - assert_equal(flipud(a),b) - a = [[0,1,2], - [3,4,5]] - b = [[3,4,5], - [0,1,2]] - assert_equal(flipud(a),b) - -class TestRot90(NumpyTestCase): - def check_basic(self): - self.failUnlessRaises(ValueError, rot90, ones(4)) - - a = [[0,1,2], - [3,4,5]] - b1 = [[2,5], - [1,4], - [0,3]] - b2 = [[5,4,3], - [2,1,0]] - b3 = [[3,0], - [4,1], - [5,2]] - b4 = [[0,1,2], - [3,4,5]] - - for k in range(-3,13,4): - assert_equal(rot90(a,k=k),b1) - for k in range(-2,13,4): - assert_equal(rot90(a,k=k),b2) - for k in range(-1,13,4): - assert_equal(rot90(a,k=k),b3) - for k in range(0,13,4): - assert_equal(rot90(a,k=k),b4) - - def check_axes(self): - a = ones((50,40,3)) - assert_equal(rot90(a).shape,(40,50,3)) - -class TestHistogram2d(NumpyTestCase): - def check_simple(self): - x = array([ 0.41702200, 0.72032449, 0.00011437481, 0.302332573, 0.146755891]) - y = array([ 0.09233859, 0.18626021, 0.34556073, 0.39676747, 0.53881673]) - xedges = np.linspace(0,1,10) - yedges = np.linspace(0,1,10) - H = histogram2d(x, y, (xedges, yedges))[0] - answer = array([[0, 0, 0, 1, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 1, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0], - [1, 0, 1, 0, 0, 0, 0, 0, 0], - [0, 1, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0], - [0, 0, 0, 0, 0, 0, 0, 0, 0]]) - assert_array_equal(H.T, answer) - H = histogram2d(x, y, xedges)[0] - assert_array_equal(H.T, answer) - H,xedges,yedges = histogram2d(range(10),range(10)) - assert_array_equal(H, eye(10,10)) - assert_array_equal(xedges, np.linspace(0,9,11)) - assert_array_equal(yedges, np.linspace(0,9,11)) - - def check_asym(self): - x = array([1, 1, 2, 3, 4, 4, 4, 5]) - y = array([1, 3, 2, 0, 1, 2, 3, 4]) - H, xed, yed = histogram2d(x,y, (6, 5), range = [[0,6],[0,5]], normed=True) - answer = array([[0.,0,0,0,0], - [0,1,0,1,0], - [0,0,1,0,0], - [1,0,0,0,0], - [0,1,1,1,0], - [0,0,0,0,1]]) - assert_array_almost_equal(H, answer/8., 3) - assert_array_equal(xed, np.linspace(0,6,7)) - assert_array_equal(yed, np.linspace(0,5,6)) - def check_norm(self): - x = array([1,2,3,1,2,3,1,2,3]) - y = array([1,1,1,2,2,2,3,3,3]) - H, xed, yed = histogram2d(x,y,[[1,2,3,5], [1,2,3,5]], normed=True) - answer=array([[1,1,.5], - [1,1,.5], - [.5,.5,.25]])/9. - assert_array_almost_equal(H, answer, 3) - - def check_all_outliers(self): - r = rand(100)+1. - H, xed, yed = histogram2d(r, r, (4, 5), range=([0,1], [0,1])) - assert_array_equal(H, 0) - -class TestTri(NumpyTestCase): - def test_dtype(self): - out = array([[1,0,0], - [1,1,0], - [1,1,1]]) - assert_array_equal(tri(3),out) - assert_array_equal(tri(3,dtype=bool),out.astype(bool)) - -if __name__ == "__main__": - NumpyTest().run() diff --git a/numpy/lib/tests/test_type_check.py b/numpy/lib/tests/test_type_check.py deleted file mode 100644 index 633c34dc8..000000000 --- a/numpy/lib/tests/test_type_check.py +++ /dev/null @@ -1,280 +0,0 @@ -import sys - -from numpy.testing import * -set_package_path() -import numpy.lib;reload(numpy.lib);reload(numpy.lib.type_check) -from numpy.lib import * -from numpy.core import * -restore_path() - -def assert_all(x): - assert(all(x)), x - -class TestMintypecode(NumpyTestCase): - - def check_default_1(self): - for itype in '1bcsuwil': - assert_equal(mintypecode(itype),'d') - assert_equal(mintypecode('f'),'f') - assert_equal(mintypecode('d'),'d') - assert_equal(mintypecode('F'),'F') - assert_equal(mintypecode('D'),'D') - - def check_default_2(self): - for itype in '1bcsuwil': - assert_equal(mintypecode(itype+'f'),'f') - assert_equal(mintypecode(itype+'d'),'d') - assert_equal(mintypecode(itype+'F'),'F') - assert_equal(mintypecode(itype+'D'),'D') - assert_equal(mintypecode('ff'),'f') - assert_equal(mintypecode('fd'),'d') - assert_equal(mintypecode('fF'),'F') - assert_equal(mintypecode('fD'),'D') - assert_equal(mintypecode('df'),'d') - assert_equal(mintypecode('dd'),'d') - #assert_equal(mintypecode('dF',savespace=1),'F') - assert_equal(mintypecode('dF'),'D') - assert_equal(mintypecode('dD'),'D') - assert_equal(mintypecode('Ff'),'F') - #assert_equal(mintypecode('Fd',savespace=1),'F') - assert_equal(mintypecode('Fd'),'D') - assert_equal(mintypecode('FF'),'F') - assert_equal(mintypecode('FD'),'D') - assert_equal(mintypecode('Df'),'D') - assert_equal(mintypecode('Dd'),'D') - assert_equal(mintypecode('DF'),'D') - assert_equal(mintypecode('DD'),'D') - - def check_default_3(self): - assert_equal(mintypecode('fdF'),'D') - #assert_equal(mintypecode('fdF',savespace=1),'F') - assert_equal(mintypecode('fdD'),'D') - assert_equal(mintypecode('fFD'),'D') - assert_equal(mintypecode('dFD'),'D') - - assert_equal(mintypecode('ifd'),'d') - assert_equal(mintypecode('ifF'),'F') - assert_equal(mintypecode('ifD'),'D') - assert_equal(mintypecode('idF'),'D') - #assert_equal(mintypecode('idF',savespace=1),'F') - assert_equal(mintypecode('idD'),'D') - -class TestIsscalar(NumpyTestCase): - def check_basic(self): - assert(isscalar(3)) - assert(not isscalar([3])) - assert(not isscalar((3,))) - assert(isscalar(3j)) - assert(isscalar(10L)) - assert(isscalar(4.0)) - -class TestReal(NumpyTestCase): - def check_real(self): - y = rand(10,) - assert_array_equal(y,real(y)) - - def check_cmplx(self): - y = rand(10,)+1j*rand(10,) - assert_array_equal(y.real,real(y)) - -class TestImag(NumpyTestCase): - def check_real(self): - y = rand(10,) - assert_array_equal(0,imag(y)) - - def check_cmplx(self): - y = rand(10,)+1j*rand(10,) - assert_array_equal(y.imag,imag(y)) - -class TestIscomplex(NumpyTestCase): - def check_fail(self): - z = array([-1,0,1]) - res = iscomplex(z) - assert(not sometrue(res,axis=0)) - def check_pass(self): - z = array([-1j,1,0]) - res = iscomplex(z) - assert_array_equal(res,[1,0,0]) - -class TestIsreal(NumpyTestCase): - def check_pass(self): - z = array([-1,0,1j]) - res = isreal(z) - assert_array_equal(res,[1,1,0]) - def check_fail(self): - z = array([-1j,1,0]) - res = isreal(z) - assert_array_equal(res,[0,1,1]) - -class TestIscomplexobj(NumpyTestCase): - def check_basic(self): - z = array([-1,0,1]) - assert(not iscomplexobj(z)) - z = array([-1j,0,-1]) - assert(iscomplexobj(z)) - -class TestIsrealobj(NumpyTestCase): - def check_basic(self): - z = array([-1,0,1]) - assert(isrealobj(z)) - z = array([-1j,0,-1]) - assert(not isrealobj(z)) - -class TestIsnan(NumpyTestCase): - def check_goodvalues(self): - z = array((-1.,0.,1.)) - res = isnan(z) == 0 - assert_all(alltrue(res,axis=0)) - def check_posinf(self): - olderr = seterr(divide='ignore') - assert_all(isnan(array((1.,))/0.) == 0) - seterr(**olderr) - def check_neginf(self): - olderr = seterr(divide='ignore') - assert_all(isnan(array((-1.,))/0.) == 0) - seterr(**olderr) - def check_ind(self): - olderr = seterr(divide='ignore', invalid='ignore') - assert_all(isnan(array((0.,))/0.) == 1) - seterr(**olderr) - #def check_qnan(self): log(-1) return pi*j now - # assert_all(isnan(log(-1.)) == 1) - def check_integer(self): - assert_all(isnan(1) == 0) - def check_complex(self): - assert_all(isnan(1+1j) == 0) - def check_complex1(self): - olderr = seterr(divide='ignore', invalid='ignore') - assert_all(isnan(array(0+0j)/0.) == 1) - seterr(**olderr) - -class TestIsfinite(NumpyTestCase): - def check_goodvalues(self): - z = array((-1.,0.,1.)) - res = isfinite(z) == 1 - assert_all(alltrue(res,axis=0)) - def check_posinf(self): - olderr = seterr(divide='ignore') - assert_all(isfinite(array((1.,))/0.) == 0) - seterr(**olderr) - def check_neginf(self): - olderr = seterr(divide='ignore') - assert_all(isfinite(array((-1.,))/0.) == 0) - seterr(**olderr) - def check_ind(self): - olderr = seterr(divide='ignore', invalid='ignore') - assert_all(isfinite(array((0.,))/0.) == 0) - seterr(**olderr) - #def check_qnan(self): - # assert_all(isfinite(log(-1.)) == 0) - def check_integer(self): - assert_all(isfinite(1) == 1) - def check_complex(self): - assert_all(isfinite(1+1j) == 1) - def check_complex1(self): - olderr = seterr(divide='ignore', invalid='ignore') - assert_all(isfinite(array(1+1j)/0.) == 0) - seterr(**olderr) - -class TestIsinf(NumpyTestCase): - def check_goodvalues(self): - z = array((-1.,0.,1.)) - res = isinf(z) == 0 - assert_all(alltrue(res,axis=0)) - def check_posinf(self): - olderr = seterr(divide='ignore') - assert_all(isinf(array((1.,))/0.) == 1) - seterr(**olderr) - def check_posinf_scalar(self): - olderr = seterr(divide='ignore') - assert_all(isinf(array(1.,)/0.) == 1) - seterr(**olderr) - def check_neginf(self): - olderr = seterr(divide='ignore') - assert_all(isinf(array((-1.,))/0.) == 1) - seterr(**olderr) - def check_neginf_scalar(self): - olderr = seterr(divide='ignore') - assert_all(isinf(array(-1.)/0.) == 1) - seterr(**olderr) - def check_ind(self): - olderr = seterr(divide='ignore', invalid='ignore') - assert_all(isinf(array((0.,))/0.) == 0) - seterr(**olderr) - #def check_qnan(self): - # assert_all(isinf(log(-1.)) == 0) - # assert_all(isnan(log(-1.)) == 1) - -class TestIsposinf(NumpyTestCase): - def check_generic(self): - olderr = seterr(divide='ignore', invalid='ignore') - vals = isposinf(array((-1.,0,1))/0.) - seterr(**olderr) - assert(vals[0] == 0) - assert(vals[1] == 0) - assert(vals[2] == 1) - -class TestIsneginf(NumpyTestCase): - def check_generic(self): - olderr = seterr(divide='ignore', invalid='ignore') - vals = isneginf(array((-1.,0,1))/0.) - seterr(**olderr) - assert(vals[0] == 1) - assert(vals[1] == 0) - assert(vals[2] == 0) - -class TestNanToNum(NumpyTestCase): - def check_generic(self): - olderr = seterr(divide='ignore', invalid='ignore') - vals = nan_to_num(array((-1.,0,1))/0.) - seterr(**olderr) - assert_all(vals[0] < -1e10) and assert_all(isfinite(vals[0])) - assert(vals[1] == 0) - assert_all(vals[2] > 1e10) and assert_all(isfinite(vals[2])) - def check_integer(self): - vals = nan_to_num(1) - assert_all(vals == 1) - def check_complex_good(self): - vals = nan_to_num(1+1j) - assert_all(vals == 1+1j) - def check_complex_bad(self): - v = 1+1j - olderr = seterr(divide='ignore', invalid='ignore') - v += array(0+1.j)/0. - seterr(**olderr) - vals = nan_to_num(v) - # !! This is actually (unexpectedly) zero - assert_all(isfinite(vals)) - def check_complex_bad2(self): - v = 1+1j - olderr = seterr(divide='ignore', invalid='ignore') - v += array(-1+1.j)/0. - seterr(**olderr) - vals = nan_to_num(v) - assert_all(isfinite(vals)) - #assert_all(vals.imag > 1e10) and assert_all(isfinite(vals)) - # !! This is actually (unexpectedly) positive - # !! inf. Comment out for now, and see if it - # !! changes - #assert_all(vals.real < -1e10) and assert_all(isfinite(vals)) - - -class TestRealIfClose(NumpyTestCase): - def check_basic(self): - a = rand(10) - b = real_if_close(a+1e-15j) - assert_all(isrealobj(b)) - assert_array_equal(a,b) - b = real_if_close(a+1e-7j) - assert_all(iscomplexobj(b)) - b = real_if_close(a+1e-7j,tol=1e-6) - assert_all(isrealobj(b)) - -class TestArrayConversion(NumpyTestCase): - def check_asfarray(self): - a = asfarray(array([1,2,3])) - assert_equal(a.__class__,ndarray) - assert issubdtype(a.dtype,float) - -if __name__ == "__main__": - NumpyTest().run() diff --git a/numpy/lib/tests/test_ufunclike.py b/numpy/lib/tests/test_ufunclike.py deleted file mode 100644 index 926439fb4..000000000 --- a/numpy/lib/tests/test_ufunclike.py +++ /dev/null @@ -1,66 +0,0 @@ -""" ->>> import numpy.core as nx ->>> import numpy.lib.ufunclike as U - -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.], - [ 0., -1., -1., -1.]]) ->>> y = nx.zeros(a.shape, float) ->>> U.fix(a, y) -array([[ 1., 1., 1., 1.], - [ 0., -1., -1., -1.]]) ->>> y -array([[ 1., 1., 1., 1.], - [ 0., -1., -1., -1.]]) - -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., 0., 0., 1., -1.]) ->>> olderr = nx.seterr(**olderr) - -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, False, False, True, True], dtype=bool) ->>> olderr = nx.seterr(**olderr) ->>> y -array([ True, True, False, False, True, True], dtype=bool) - -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]) - -""" - -from numpy.testing import * - -class TestDocs(NumpyTestCase): - def check_doctests(self): return self.rundocs() - -if __name__ == "__main__": - NumpyTest().run() -- cgit v1.2.1