/apps/autodock_mgl.bak/autodock_mgl_1.125_i686-pc-linux-gnu/test/lib/python2.5/site-packages/numpy/lib/tests/test_arraysetops.py

https://github.com/jackygrahamez/DrugDiscovery-Home · Python · 171 lines · 104 code · 46 blank · 21 comment · 1 complexity · 033d8b22c92a143b345bf914c499c9bc MD5 · raw file

  1. """ Test functions for 1D array set operations.
  2. """
  3. from numpy.testing import *
  4. set_package_path()
  5. import numpy
  6. from numpy.lib.arraysetops import *
  7. from numpy.lib.arraysetops import ediff1d
  8. restore_path()
  9. ##################################################
  10. class test_aso(NumpyTestCase):
  11. ##
  12. # 03.11.2005, c
  13. def check_unique1d( self ):
  14. a = numpy.array( [5, 7, 1, 2, 1, 5, 7] )
  15. ec = numpy.array( [1, 2, 5, 7] )
  16. c = unique1d( a )
  17. assert_array_equal( c, ec )
  18. assert_array_equal([], unique1d([]))
  19. ##
  20. # 03.11.2005, c
  21. def check_intersect1d( self ):
  22. a = numpy.array( [5, 7, 1, 2] )
  23. b = numpy.array( [2, 4, 3, 1, 5] )
  24. ec = numpy.array( [1, 2, 5] )
  25. c = intersect1d( a, b )
  26. assert_array_equal( c, ec )
  27. assert_array_equal([], intersect1d([],[]))
  28. ##
  29. # 03.11.2005, c
  30. def check_intersect1d_nu( self ):
  31. a = numpy.array( [5, 5, 7, 1, 2] )
  32. b = numpy.array( [2, 1, 4, 3, 3, 1, 5] )
  33. ec = numpy.array( [1, 2, 5] )
  34. c = intersect1d_nu( a, b )
  35. assert_array_equal( c, ec )
  36. assert_array_equal([], intersect1d_nu([],[]))
  37. ##
  38. # 03.11.2005, c
  39. def check_setxor1d( self ):
  40. a = numpy.array( [5, 7, 1, 2] )
  41. b = numpy.array( [2, 4, 3, 1, 5] )
  42. ec = numpy.array( [3, 4, 7] )
  43. c = setxor1d( a, b )
  44. assert_array_equal( c, ec )
  45. a = numpy.array( [1, 2, 3] )
  46. b = numpy.array( [6, 5, 4] )
  47. ec = numpy.array( [1, 2, 3, 4, 5, 6] )
  48. c = setxor1d( a, b )
  49. assert_array_equal( c, ec )
  50. a = numpy.array( [1, 8, 2, 3] )
  51. b = numpy.array( [6, 5, 4, 8] )
  52. ec = numpy.array( [1, 2, 3, 4, 5, 6] )
  53. c = setxor1d( a, b )
  54. assert_array_equal( c, ec )
  55. assert_array_equal([], setxor1d([],[]))
  56. def check_ediff1d(self):
  57. zero_elem = numpy.array([])
  58. one_elem = numpy.array([1])
  59. two_elem = numpy.array([1,2])
  60. assert_array_equal([],ediff1d(zero_elem))
  61. assert_array_equal([0],ediff1d(zero_elem,to_begin=0))
  62. assert_array_equal([0],ediff1d(zero_elem,to_end=0))
  63. assert_array_equal([-1,0],ediff1d(zero_elem,to_begin=-1,to_end=0))
  64. assert_array_equal([],ediff1d(one_elem))
  65. assert_array_equal([1],ediff1d(two_elem))
  66. ##
  67. # 03.11.2005, c
  68. def check_setmember1d( self ):
  69. a = numpy.array( [5, 7, 1, 2] )
  70. b = numpy.array( [2, 4, 3, 1, 5] )
  71. ec = numpy.array( [True, False, True, True] )
  72. c = setmember1d( a, b )
  73. assert_array_equal( c, ec )
  74. a[0] = 8
  75. ec = numpy.array( [False, False, True, True] )
  76. c = setmember1d( a, b )
  77. assert_array_equal( c, ec )
  78. a[0], a[3] = 4, 8
  79. ec = numpy.array( [True, False, True, False] )
  80. c = setmember1d( a, b )
  81. assert_array_equal( c, ec )
  82. assert_array_equal([], setmember1d([],[]))
  83. ##
  84. # 03.11.2005, c
  85. def check_union1d( self ):
  86. a = numpy.array( [5, 4, 7, 1, 2] )
  87. b = numpy.array( [2, 4, 3, 3, 2, 1, 5] )
  88. ec = numpy.array( [1, 2, 3, 4, 5, 7] )
  89. c = union1d( a, b )
  90. assert_array_equal( c, ec )
  91. assert_array_equal([], union1d([],[]))
  92. ##
  93. # 03.11.2005, c
  94. # 09.01.2006
  95. def check_setdiff1d( self ):
  96. a = numpy.array( [6, 5, 4, 7, 1, 2] )
  97. b = numpy.array( [2, 4, 3, 3, 2, 1, 5] )
  98. ec = numpy.array( [6, 7] )
  99. c = setdiff1d( a, b )
  100. assert_array_equal( c, ec )
  101. a = numpy.arange( 21 )
  102. b = numpy.arange( 19 )
  103. ec = numpy.array( [19, 20] )
  104. c = setdiff1d( a, b )
  105. assert_array_equal( c, ec )
  106. assert_array_equal([], setdiff1d([],[]))
  107. ##
  108. # 03.11.2005, c
  109. def check_manyways( self ):
  110. nItem = 100
  111. a = numpy.fix( nItem / 10 * numpy.random.random( nItem ) )
  112. b = numpy.fix( nItem / 10 * numpy.random.random( nItem ) )
  113. c1 = intersect1d_nu( a, b )
  114. c2 = unique1d( intersect1d( a, b ) )
  115. assert_array_equal( c1, c2 )
  116. a = numpy.array( [5, 7, 1, 2, 8] )
  117. b = numpy.array( [9, 8, 2, 4, 3, 1, 5] )
  118. c1 = setxor1d( a, b )
  119. aux1 = intersect1d( a, b )
  120. aux2 = union1d( a, b )
  121. c2 = setdiff1d( aux2, aux1 )
  122. assert_array_equal( c1, c2 )
  123. if __name__ == "__main__":
  124. NumpyTest().run()