Hackfut Security File Manager
Current Path:
/opt/alt/python27/lib64/python2.7/site-packages/numpy/core/tests
opt
/
alt
/
python27
/
lib64
/
python2.7
/
site-packages
/
numpy
/
core
/
tests
/
📁
..
📁
data
📄
test_abc.py
(1.97 KB)
📄
test_abc.pyc
(2.69 KB)
📄
test_abc.pyo
(2.69 KB)
📄
test_api.py
(18.41 KB)
📄
test_api.pyc
(15.56 KB)
📄
test_api.pyo
(15.56 KB)
📄
test_arrayprint.py
(6.73 KB)
📄
test_arrayprint.pyc
(10.33 KB)
📄
test_arrayprint.pyo
(10.33 KB)
📄
test_datetime.py
(88.29 KB)
📄
test_datetime.pyc
(60.87 KB)
📄
test_datetime.pyo
(60.87 KB)
📄
test_defchararray.py
(26.28 KB)
📄
test_defchararray.pyc
(39.08 KB)
📄
test_defchararray.pyo
(39.08 KB)
📄
test_deprecations.py
(32.64 KB)
📄
test_deprecations.pyc
(47.97 KB)
📄
test_deprecations.pyo
(47.97 KB)
📄
test_dtype.py
(24.01 KB)
📄
test_dtype.pyc
(26.9 KB)
📄
test_dtype.pyo
(26.9 KB)
📄
test_einsum.py
(25.09 KB)
📄
test_einsum.pyc
(20.42 KB)
📄
test_einsum.pyo
(20.42 KB)
📄
test_errstate.py
(1.55 KB)
📄
test_errstate.pyc
(2.4 KB)
📄
test_errstate.pyo
(2.4 KB)
📄
test_extint128.py
(5.62 KB)
📄
test_extint128.pyc
(7.75 KB)
📄
test_extint128.pyo
(7.75 KB)
📄
test_function_base.py
(5.24 KB)
📄
test_function_base.pyc
(9.45 KB)
📄
test_function_base.pyo
(9.37 KB)
📄
test_getlimits.py
(2.22 KB)
📄
test_getlimits.pyc
(5.31 KB)
📄
test_getlimits.pyo
(5.31 KB)
📄
test_half.py
(18.1 KB)
📄
test_half.pyc
(18.32 KB)
📄
test_half.pyo
(18.32 KB)
📄
test_indexerrors.py
(4.82 KB)
📄
test_indexerrors.pyc
(11.62 KB)
📄
test_indexerrors.pyo
(11.62 KB)
📄
test_indexing.py
(39.93 KB)
📄
test_indexing.pyc
(36.73 KB)
📄
test_indexing.pyo
(36.73 KB)
📄
test_item_selection.py
(3.5 KB)
📄
test_item_selection.pyc
(4.38 KB)
📄
test_item_selection.pyo
(4.38 KB)
📄
test_longdouble.py
(5.71 KB)
📄
test_longdouble.pyc
(10.27 KB)
📄
test_longdouble.pyo
(10.27 KB)
📄
test_machar.py
(1014 B)
📄
test_machar.pyc
(1.71 KB)
📄
test_machar.pyo
(1.71 KB)
📄
test_mem_overlap.py
(15.4 KB)
📄
test_mem_overlap.pyc
(21.25 KB)
📄
test_mem_overlap.pyo
(21.25 KB)
📄
test_memmap.py
(4.2 KB)
📄
test_memmap.pyc
(6.35 KB)
📄
test_memmap.pyo
(6.35 KB)
📄
test_multiarray.py
(235.11 KB)
📄
test_multiarray.pyc
(271.28 KB)
📄
test_multiarray.pyo
(271.25 KB)
📄
test_nditer.py
(101.78 KB)
📄
test_nditer.pyc
(85.59 KB)
📄
test_nditer.pyo
(85.59 KB)
📄
test_numeric.py
(89.25 KB)
📄
test_numeric.pyc
(110.54 KB)
📄
test_numeric.pyo
(110.54 KB)
📄
test_numerictypes.py
(14.38 KB)
📄
test_numerictypes.pyc
(18.27 KB)
📄
test_numerictypes.pyo
(18.27 KB)
📄
test_print.py
(8 KB)
📄
test_print.pyc
(10.02 KB)
📄
test_print.pyo
(10.02 KB)
📄
test_records.py
(13.12 KB)
📄
test_records.pyc
(17.07 KB)
📄
test_records.pyo
(17.07 KB)
📄
test_regression.py
(77.01 KB)
📄
test_regression.pyc
(106.12 KB)
📄
test_regression.pyo
(106.12 KB)
📄
test_scalarinherit.py
(771 B)
📄
test_scalarinherit.pyc
(2.72 KB)
📄
test_scalarinherit.pyo
(2.72 KB)
📄
test_scalarmath.py
(18.65 KB)
📄
test_scalarmath.pyc
(20.1 KB)
📄
test_scalarmath.pyo
(20.1 KB)
📄
test_scalarprint.py
(917 B)
📄
test_scalarprint.pyc
(1.45 KB)
📄
test_scalarprint.pyo
(1.45 KB)
📄
test_shape_base.py
(11.23 KB)
📄
test_shape_base.pyc
(14.63 KB)
📄
test_shape_base.pyo
(14.63 KB)
📄
test_ufunc.py
(49.29 KB)
📄
test_ufunc.pyc
(50.63 KB)
📄
test_ufunc.pyo
(50.63 KB)
📄
test_umath.py
(73.33 KB)
📄
test_umath.pyc
(95.78 KB)
📄
test_umath.pyo
(95.72 KB)
📄
test_umath_complex.py
(19.34 KB)
📄
test_umath_complex.pyc
(19.11 KB)
📄
test_umath_complex.pyo
(19.11 KB)
📄
test_unicode.py
(12.34 KB)
📄
test_unicode.pyc
(16.09 KB)
📄
test_unicode.pyo
(16.09 KB)
Editing: test_unicode.py
from __future__ import division, absolute_import, print_function import sys import numpy as np from numpy.compat import asbytes, unicode, sixu from numpy.testing import TestCase, run_module_suite, assert_equal # Guess the UCS length for this python interpreter if sys.version_info[:2] >= (3, 3): # Python 3.3 uses a flexible string representation ucs4 = False def buffer_length(arr): if isinstance(arr, unicode): arr = str(arr) return (sys.getsizeof(arr+"a") - sys.getsizeof(arr)) * len(arr) v = memoryview(arr) if v.shape is None: return len(v) * v.itemsize else: return np.prod(v.shape) * v.itemsize elif sys.version_info[0] >= 3: import array as _array ucs4 = (_array.array('u').itemsize == 4) def buffer_length(arr): if isinstance(arr, unicode): return _array.array('u').itemsize * len(arr) v = memoryview(arr) if v.shape is None: return len(v) * v.itemsize else: return np.prod(v.shape) * v.itemsize else: if len(buffer(sixu('u'))) == 4: ucs4 = True else: ucs4 = False def buffer_length(arr): if isinstance(arr, np.ndarray): return len(arr.data) return len(buffer(arr)) # In both cases below we need to make sure that the byte swapped value (as # UCS4) is still a valid unicode: # Value that can be represented in UCS2 interpreters ucs2_value = sixu('\u0900') # Value that cannot be represented in UCS2 interpreters (but can in UCS4) ucs4_value = sixu('\U00100900') ############################################################ # Creation tests ############################################################ class create_zeros(object): """Check the creation of zero-valued arrays""" def content_check(self, ua, ua_scalar, nbytes): # Check the length of the unicode base type self.assertTrue(int(ua.dtype.str[2:]) == self.ulen) # Check the length of the data buffer self.assertTrue(buffer_length(ua) == nbytes) # Small check that data in array element is ok self.assertTrue(ua_scalar == sixu('')) # Encode to ascii and double check self.assertTrue(ua_scalar.encode('ascii') == asbytes('')) # Check buffer lengths for scalars if ucs4: self.assertTrue(buffer_length(ua_scalar) == 0) else: self.assertTrue(buffer_length(ua_scalar) == 0) def test_zeros0D(self): # Check creation of 0-dimensional objects ua = np.zeros((), dtype='U%s' % self.ulen) self.content_check(ua, ua[()], 4*self.ulen) def test_zerosSD(self): # Check creation of single-dimensional objects ua = np.zeros((2,), dtype='U%s' % self.ulen) self.content_check(ua, ua[0], 4*self.ulen*2) self.content_check(ua, ua[1], 4*self.ulen*2) def test_zerosMD(self): # Check creation of multi-dimensional objects ua = np.zeros((2, 3, 4), dtype='U%s' % self.ulen) self.content_check(ua, ua[0, 0, 0], 4*self.ulen*2*3*4) self.content_check(ua, ua[-1, -1, -1], 4*self.ulen*2*3*4) class test_create_zeros_1(create_zeros, TestCase): """Check the creation of zero-valued arrays (size 1)""" ulen = 1 class test_create_zeros_2(create_zeros, TestCase): """Check the creation of zero-valued arrays (size 2)""" ulen = 2 class test_create_zeros_1009(create_zeros, TestCase): """Check the creation of zero-valued arrays (size 1009)""" ulen = 1009 class create_values(object): """Check the creation of unicode arrays with values""" def content_check(self, ua, ua_scalar, nbytes): # Check the length of the unicode base type self.assertTrue(int(ua.dtype.str[2:]) == self.ulen) # Check the length of the data buffer self.assertTrue(buffer_length(ua) == nbytes) # Small check that data in array element is ok self.assertTrue(ua_scalar == self.ucs_value*self.ulen) # Encode to UTF-8 and double check self.assertTrue(ua_scalar.encode('utf-8') == (self.ucs_value*self.ulen).encode('utf-8')) # Check buffer lengths for scalars if ucs4: self.assertTrue(buffer_length(ua_scalar) == 4*self.ulen) else: if self.ucs_value == ucs4_value: # In UCS2, the \U0010FFFF will be represented using a # surrogate *pair* self.assertTrue(buffer_length(ua_scalar) == 2*2*self.ulen) else: # In UCS2, the \uFFFF will be represented using a # regular 2-byte word self.assertTrue(buffer_length(ua_scalar) == 2*self.ulen) def test_values0D(self): # Check creation of 0-dimensional objects with values ua = np.array(self.ucs_value*self.ulen, dtype='U%s' % self.ulen) self.content_check(ua, ua[()], 4*self.ulen) def test_valuesSD(self): # Check creation of single-dimensional objects with values ua = np.array([self.ucs_value*self.ulen]*2, dtype='U%s' % self.ulen) self.content_check(ua, ua[0], 4*self.ulen*2) self.content_check(ua, ua[1], 4*self.ulen*2) def test_valuesMD(self): # Check creation of multi-dimensional objects with values ua = np.array([[[self.ucs_value*self.ulen]*2]*3]*4, dtype='U%s' % self.ulen) self.content_check(ua, ua[0, 0, 0], 4*self.ulen*2*3*4) self.content_check(ua, ua[-1, -1, -1], 4*self.ulen*2*3*4) class test_create_values_1_ucs2(create_values, TestCase): """Check the creation of valued arrays (size 1, UCS2 values)""" ulen = 1 ucs_value = ucs2_value class test_create_values_1_ucs4(create_values, TestCase): """Check the creation of valued arrays (size 1, UCS4 values)""" ulen = 1 ucs_value = ucs4_value class test_create_values_2_ucs2(create_values, TestCase): """Check the creation of valued arrays (size 2, UCS2 values)""" ulen = 2 ucs_value = ucs2_value class test_create_values_2_ucs4(create_values, TestCase): """Check the creation of valued arrays (size 2, UCS4 values)""" ulen = 2 ucs_value = ucs4_value class test_create_values_1009_ucs2(create_values, TestCase): """Check the creation of valued arrays (size 1009, UCS2 values)""" ulen = 1009 ucs_value = ucs2_value class test_create_values_1009_ucs4(create_values, TestCase): """Check the creation of valued arrays (size 1009, UCS4 values)""" ulen = 1009 ucs_value = ucs4_value ############################################################ # Assignment tests ############################################################ class assign_values(object): """Check the assignment of unicode arrays with values""" def content_check(self, ua, ua_scalar, nbytes): # Check the length of the unicode base type self.assertTrue(int(ua.dtype.str[2:]) == self.ulen) # Check the length of the data buffer self.assertTrue(buffer_length(ua) == nbytes) # Small check that data in array element is ok self.assertTrue(ua_scalar == self.ucs_value*self.ulen) # Encode to UTF-8 and double check self.assertTrue(ua_scalar.encode('utf-8') == (self.ucs_value*self.ulen).encode('utf-8')) # Check buffer lengths for scalars if ucs4: self.assertTrue(buffer_length(ua_scalar) == 4*self.ulen) else: if self.ucs_value == ucs4_value: # In UCS2, the \U0010FFFF will be represented using a # surrogate *pair* self.assertTrue(buffer_length(ua_scalar) == 2*2*self.ulen) else: # In UCS2, the \uFFFF will be represented using a # regular 2-byte word self.assertTrue(buffer_length(ua_scalar) == 2*self.ulen) def test_values0D(self): # Check assignment of 0-dimensional objects with values ua = np.zeros((), dtype='U%s' % self.ulen) ua[()] = self.ucs_value*self.ulen self.content_check(ua, ua[()], 4*self.ulen) def test_valuesSD(self): # Check assignment of single-dimensional objects with values ua = np.zeros((2,), dtype='U%s' % self.ulen) ua[0] = self.ucs_value*self.ulen self.content_check(ua, ua[0], 4*self.ulen*2) ua[1] = self.ucs_value*self.ulen self.content_check(ua, ua[1], 4*self.ulen*2) def test_valuesMD(self): # Check assignment of multi-dimensional objects with values ua = np.zeros((2, 3, 4), dtype='U%s' % self.ulen) ua[0, 0, 0] = self.ucs_value*self.ulen self.content_check(ua, ua[0, 0, 0], 4*self.ulen*2*3*4) ua[-1, -1, -1] = self.ucs_value*self.ulen self.content_check(ua, ua[-1, -1, -1], 4*self.ulen*2*3*4) class test_assign_values_1_ucs2(assign_values, TestCase): """Check the assignment of valued arrays (size 1, UCS2 values)""" ulen = 1 ucs_value = ucs2_value class test_assign_values_1_ucs4(assign_values, TestCase): """Check the assignment of valued arrays (size 1, UCS4 values)""" ulen = 1 ucs_value = ucs4_value class test_assign_values_2_ucs2(assign_values, TestCase): """Check the assignment of valued arrays (size 2, UCS2 values)""" ulen = 2 ucs_value = ucs2_value class test_assign_values_2_ucs4(assign_values, TestCase): """Check the assignment of valued arrays (size 2, UCS4 values)""" ulen = 2 ucs_value = ucs4_value class test_assign_values_1009_ucs2(assign_values, TestCase): """Check the assignment of valued arrays (size 1009, UCS2 values)""" ulen = 1009 ucs_value = ucs2_value class test_assign_values_1009_ucs4(assign_values, TestCase): """Check the assignment of valued arrays (size 1009, UCS4 values)""" ulen = 1009 ucs_value = ucs4_value ############################################################ # Byteorder tests ############################################################ class byteorder_values: """Check the byteorder of unicode arrays in round-trip conversions""" def test_values0D(self): # Check byteorder of 0-dimensional objects ua = np.array(self.ucs_value*self.ulen, dtype='U%s' % self.ulen) ua2 = ua.newbyteorder() # This changes the interpretation of the data region (but not the # actual data), therefore the returned scalars are not # the same (they are byte-swapped versions of each other). self.assertTrue(ua[()] != ua2[()]) ua3 = ua2.newbyteorder() # Arrays must be equal after the round-trip assert_equal(ua, ua3) def test_valuesSD(self): # Check byteorder of single-dimensional objects ua = np.array([self.ucs_value*self.ulen]*2, dtype='U%s' % self.ulen) ua2 = ua.newbyteorder() self.assertTrue(ua[0] != ua2[0]) self.assertTrue(ua[-1] != ua2[-1]) ua3 = ua2.newbyteorder() # Arrays must be equal after the round-trip assert_equal(ua, ua3) def test_valuesMD(self): # Check byteorder of multi-dimensional objects ua = np.array([[[self.ucs_value*self.ulen]*2]*3]*4, dtype='U%s' % self.ulen) ua2 = ua.newbyteorder() self.assertTrue(ua[0, 0, 0] != ua2[0, 0, 0]) self.assertTrue(ua[-1, -1, -1] != ua2[-1, -1, -1]) ua3 = ua2.newbyteorder() # Arrays must be equal after the round-trip assert_equal(ua, ua3) class test_byteorder_1_ucs2(byteorder_values, TestCase): """Check the byteorder in unicode (size 1, UCS2 values)""" ulen = 1 ucs_value = ucs2_value class test_byteorder_1_ucs4(byteorder_values, TestCase): """Check the byteorder in unicode (size 1, UCS4 values)""" ulen = 1 ucs_value = ucs4_value class test_byteorder_2_ucs2(byteorder_values, TestCase): """Check the byteorder in unicode (size 2, UCS2 values)""" ulen = 2 ucs_value = ucs2_value class test_byteorder_2_ucs4(byteorder_values, TestCase): """Check the byteorder in unicode (size 2, UCS4 values)""" ulen = 2 ucs_value = ucs4_value class test_byteorder_1009_ucs2(byteorder_values, TestCase): """Check the byteorder in unicode (size 1009, UCS2 values)""" ulen = 1009 ucs_value = ucs2_value class test_byteorder_1009_ucs4(byteorder_values, TestCase): """Check the byteorder in unicode (size 1009, UCS4 values)""" ulen = 1009 ucs_value = ucs4_value if __name__ == "__main__": run_module_suite()
Upload File
Create Folder