SILENT KILLERPanel

Current Path: > > opt > cloudlinux > venv > lib64 > python3.11 > > site-packages > numpy > core > tests


Operation   : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
Software     : Apache
Server IP    : 162.0.232.56 | Your IP: 216.73.216.111
Domains      : 1034 Domain(s)
Permission   : [ 0755 ]

Files and Folders in: //opt/cloudlinux/venv/lib64/python3.11//site-packages/numpy/core/tests

NameTypeSizeLast ModifiedActions
__pycache__ Directory - -
data Directory - -
examples Directory - -
__init__.py File 0 bytes April 17 2025 13:10:58.
_locales.py File 2206 bytes April 17 2025 13:10:58.
test__exceptions.py File 2846 bytes April 17 2025 13:10:58.
test_abc.py File 2220 bytes April 17 2025 13:10:58.
test_api.py File 22995 bytes April 17 2025 13:10:58.
test_argparse.py File 1969 bytes April 17 2025 13:10:58.
test_array_coercion.py File 34379 bytes April 17 2025 13:10:58.
test_array_interface.py File 7596 bytes April 17 2025 13:10:58.
test_arraymethod.py File 3244 bytes April 17 2025 13:10:58.
test_arrayprint.py File 40462 bytes April 17 2025 13:10:58.
test_casting_floatingpoint_errors.py File 5063 bytes April 17 2025 13:10:58.
test_casting_unittests.py File 34298 bytes April 17 2025 13:10:58.
test_conversion_utils.py File 6559 bytes April 17 2025 13:10:58.
test_cpu_dispatcher.py File 1521 bytes April 17 2025 13:10:58.
test_cpu_features.py File 14858 bytes April 17 2025 13:10:58.
test_custom_dtypes.py File 9401 bytes April 17 2025 13:10:58.
test_cython.py File 3623 bytes April 17 2025 13:10:58.
test_datetime.py File 116211 bytes April 17 2025 13:10:58.
test_defchararray.py File 24997 bytes April 17 2025 13:10:58.
test_deprecations.py File 31076 bytes April 17 2025 13:10:58.
test_dlpack.py File 3522 bytes April 17 2025 13:10:58.
test_dtype.py File 75288 bytes April 17 2025 13:10:58.
test_einsum.py File 52960 bytes April 17 2025 13:10:58.
test_errstate.py File 2219 bytes April 17 2025 13:10:58.
test_extint128.py File 5643 bytes April 17 2025 13:10:58.
test_function_base.py File 15595 bytes April 17 2025 13:10:58.
test_getlimits.py File 6718 bytes April 17 2025 13:10:58.
test_half.py File 24226 bytes April 17 2025 13:10:58.
test_hashtable.py File 1011 bytes April 17 2025 13:10:58.
test_indexerrors.py File 5130 bytes April 17 2025 13:10:58.
test_indexing.py File 54314 bytes April 17 2025 13:10:58.
test_item_selection.py File 6458 bytes April 17 2025 13:10:58.
test_limited_api.py File 1172 bytes April 17 2025 13:10:58.
test_longdouble.py File 13905 bytes April 17 2025 13:10:58.
test_machar.py File 1067 bytes April 17 2025 13:10:58.
test_mem_overlap.py File 29086 bytes April 17 2025 13:10:58.
test_mem_policy.py File 16004 bytes April 17 2025 13:10:58.
test_memmap.py File 7477 bytes April 17 2025 13:10:58.
test_multiarray.py File 379320 bytes April 17 2025 13:10:58.
test_nditer.py File 130818 bytes April 17 2025 13:10:58.
test_nep50_promotions.py File 8840 bytes April 17 2025 13:10:58.
test_numeric.py File 136543 bytes April 17 2025 13:10:58.
test_numerictypes.py File 21687 bytes April 17 2025 13:10:58.
test_overrides.py File 26080 bytes April 17 2025 13:10:58.
test_print.py File 6837 bytes April 17 2025 13:10:58.
test_protocols.py File 1168 bytes April 17 2025 13:10:58.
test_records.py File 20269 bytes April 17 2025 13:10:58.
test_regression.py File 91447 bytes April 17 2025 13:10:58.
test_scalar_ctors.py File 6115 bytes April 17 2025 13:10:58.
test_scalar_methods.py File 7541 bytes April 17 2025 13:10:58.
test_scalarbuffer.py File 5580 bytes April 17 2025 13:10:58.
test_scalarinherit.py File 2368 bytes April 17 2025 13:10:58.
test_scalarmath.py File 42885 bytes April 17 2025 13:10:58.
test_scalarprint.py File 18771 bytes April 17 2025 13:10:58.
test_shape_base.py File 29723 bytes April 17 2025 13:10:58.
test_simd.py File 48696 bytes April 17 2025 13:10:58.
test_simd_module.py File 3805 bytes April 17 2025 13:10:58.
test_strings.py File 3835 bytes April 17 2025 13:10:58.
test_ufunc.py File 124145 bytes April 17 2025 13:10:58.
test_umath.py File 185129 bytes April 17 2025 13:10:58.
test_umath_accuracy.py File 3897 bytes April 17 2025 13:10:58.
test_umath_complex.py File 23243 bytes April 17 2025 13:10:58.
test_unicode.py File 12775 bytes April 17 2025 13:10:58.

Reading File: //opt/cloudlinux/venv/lib64/python3.11//site-packages/numpy/core/tests/test_unicode.py

import pytest

import numpy as np
from numpy.testing import assert_, assert_equal, assert_array_equal

def buffer_length(arr):
    if isinstance(arr, str):
        if not arr:
            charmax = 0
        else:
            charmax = max([ord(c) for c in arr])
        if charmax < 256:
            size = 1
        elif charmax < 65536:
            size = 2
        else:
            size = 4
        return size * len(arr)
    v = memoryview(arr)
    if v.shape is None:
        return len(v) * v.itemsize
    else:
        return np.prod(v.shape) * v.itemsize


# 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 = '\u0900'
# Value that cannot be represented in UCS2 interpreters (but can in UCS4)
ucs4_value = '\U00100900'


def test_string_cast():
    str_arr = np.array(["1234", "1234\0\0"], dtype='S')
    uni_arr1 = str_arr.astype('>U')
    uni_arr2 = str_arr.astype('<U')

    assert_array_equal(str_arr != uni_arr1, np.ones(2, dtype=bool))
    assert_array_equal(uni_arr1 != str_arr, np.ones(2, dtype=bool))
    assert_array_equal(str_arr == uni_arr1, np.zeros(2, dtype=bool))
    assert_array_equal(uni_arr1 == str_arr, np.zeros(2, dtype=bool))

    assert_array_equal(uni_arr1, uni_arr2)


############################################################
#    Creation tests
############################################################

class CreateZeros:
    """Check the creation of zero-valued arrays"""

    def content_check(self, ua, ua_scalar, nbytes):

        # Check the length of the unicode base type
        assert_(int(ua.dtype.str[2:]) == self.ulen)
        # Check the length of the data buffer
        assert_(buffer_length(ua) == nbytes)
        # Small check that data in array element is ok
        assert_(ua_scalar == '')
        # Encode to ascii and double check
        assert_(ua_scalar.encode('ascii') == b'')
        # Check buffer lengths for scalars
        assert_(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 TestCreateZeros_1(CreateZeros):
    """Check the creation of zero-valued arrays (size 1)"""
    ulen = 1


class TestCreateZeros_2(CreateZeros):
    """Check the creation of zero-valued arrays (size 2)"""
    ulen = 2


class TestCreateZeros_1009(CreateZeros):
    """Check the creation of zero-valued arrays (size 1009)"""
    ulen = 1009


class CreateValues:
    """Check the creation of unicode arrays with values"""

    def content_check(self, ua, ua_scalar, nbytes):

        # Check the length of the unicode base type
        assert_(int(ua.dtype.str[2:]) == self.ulen)
        # Check the length of the data buffer
        assert_(buffer_length(ua) == nbytes)
        # Small check that data in array element is ok
        assert_(ua_scalar == self.ucs_value*self.ulen)
        # Encode to UTF-8 and double check
        assert_(ua_scalar.encode('utf-8') ==
                        (self.ucs_value*self.ulen).encode('utf-8'))
        # Check buffer lengths for scalars
        if self.ucs_value == ucs4_value:
            # In UCS2, the \U0010FFFF will be represented using a
            # surrogate *pair*
            assert_(buffer_length(ua_scalar) == 2*2*self.ulen)
        else:
            # In UCS2, the \uFFFF will be represented using a
            # regular 2-byte word
            assert_(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 TestCreateValues_1_UCS2(CreateValues):
    """Check the creation of valued arrays (size 1, UCS2 values)"""
    ulen = 1
    ucs_value = ucs2_value


class TestCreateValues_1_UCS4(CreateValues):
    """Check the creation of valued arrays (size 1, UCS4 values)"""
    ulen = 1
    ucs_value = ucs4_value


class TestCreateValues_2_UCS2(CreateValues):
    """Check the creation of valued arrays (size 2, UCS2 values)"""
    ulen = 2
    ucs_value = ucs2_value


class TestCreateValues_2_UCS4(CreateValues):
    """Check the creation of valued arrays (size 2, UCS4 values)"""
    ulen = 2
    ucs_value = ucs4_value


class TestCreateValues_1009_UCS2(CreateValues):
    """Check the creation of valued arrays (size 1009, UCS2 values)"""
    ulen = 1009
    ucs_value = ucs2_value


class TestCreateValues_1009_UCS4(CreateValues):
    """Check the creation of valued arrays (size 1009, UCS4 values)"""
    ulen = 1009
    ucs_value = ucs4_value


############################################################
#    Assignment tests
############################################################

class AssignValues:
    """Check the assignment of unicode arrays with values"""

    def content_check(self, ua, ua_scalar, nbytes):

        # Check the length of the unicode base type
        assert_(int(ua.dtype.str[2:]) == self.ulen)
        # Check the length of the data buffer
        assert_(buffer_length(ua) == nbytes)
        # Small check that data in array element is ok
        assert_(ua_scalar == self.ucs_value*self.ulen)
        # Encode to UTF-8 and double check
        assert_(ua_scalar.encode('utf-8') ==
                        (self.ucs_value*self.ulen).encode('utf-8'))
        # Check buffer lengths for scalars
        if self.ucs_value == ucs4_value:
            # In UCS2, the \U0010FFFF will be represented using a
            # surrogate *pair*
            assert_(buffer_length(ua_scalar) == 2*2*self.ulen)
        else:
            # In UCS2, the \uFFFF will be represented using a
            # regular 2-byte word
            assert_(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 TestAssignValues_1_UCS2(AssignValues):
    """Check the assignment of valued arrays (size 1, UCS2 values)"""
    ulen = 1
    ucs_value = ucs2_value


class TestAssignValues_1_UCS4(AssignValues):
    """Check the assignment of valued arrays (size 1, UCS4 values)"""
    ulen = 1
    ucs_value = ucs4_value


class TestAssignValues_2_UCS2(AssignValues):
    """Check the assignment of valued arrays (size 2, UCS2 values)"""
    ulen = 2
    ucs_value = ucs2_value


class TestAssignValues_2_UCS4(AssignValues):
    """Check the assignment of valued arrays (size 2, UCS4 values)"""
    ulen = 2
    ucs_value = ucs4_value


class TestAssignValues_1009_UCS2(AssignValues):
    """Check the assignment of valued arrays (size 1009, UCS2 values)"""
    ulen = 1009
    ucs_value = ucs2_value


class TestAssignValues_1009_UCS4(AssignValues):
    """Check the assignment of valued arrays (size 1009, UCS4 values)"""
    ulen = 1009
    ucs_value = ucs4_value


############################################################
#    Byteorder tests
############################################################

class ByteorderValues:
    """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).
        assert_(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()
        assert_((ua != ua2).all())
        assert_(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()
        assert_((ua != ua2).all())
        assert_(ua[-1, -1, -1] != ua2[-1, -1, -1])
        ua3 = ua2.newbyteorder()
        # Arrays must be equal after the round-trip
        assert_equal(ua, ua3)

    def test_values_cast(self):
        # Check byteorder of when casting the array for a strided and
        # contiguous array:
        test1 = np.array([self.ucs_value*self.ulen]*2, dtype='U%s' % self.ulen)
        test2 = np.repeat(test1, 2)[::2]
        for ua in (test1, test2):
            ua2 = ua.astype(dtype=ua.dtype.newbyteorder())
            assert_((ua == ua2).all())
            assert_(ua[-1] == ua2[-1])
            ua3 = ua2.astype(dtype=ua.dtype)
            # Arrays must be equal after the round-trip
            assert_equal(ua, ua3)

    def test_values_updowncast(self):
        # Check byteorder of when casting the array to a longer and shorter
        # string length for strided and contiguous arrays
        test1 = np.array([self.ucs_value*self.ulen]*2, dtype='U%s' % self.ulen)
        test2 = np.repeat(test1, 2)[::2]
        for ua in (test1, test2):
            # Cast to a longer type with zero padding
            longer_type = np.dtype('U%s' % (self.ulen+1)).newbyteorder()
            ua2 = ua.astype(dtype=longer_type)
            assert_((ua == ua2).all())
            assert_(ua[-1] == ua2[-1])
            # Cast back again with truncating:
            ua3 = ua2.astype(dtype=ua.dtype)
            # Arrays must be equal after the round-trip
            assert_equal(ua, ua3)


class TestByteorder_1_UCS2(ByteorderValues):
    """Check the byteorder in unicode (size 1, UCS2 values)"""
    ulen = 1
    ucs_value = ucs2_value


class TestByteorder_1_UCS4(ByteorderValues):
    """Check the byteorder in unicode (size 1, UCS4 values)"""
    ulen = 1
    ucs_value = ucs4_value


class TestByteorder_2_UCS2(ByteorderValues):
    """Check the byteorder in unicode (size 2, UCS2 values)"""
    ulen = 2
    ucs_value = ucs2_value


class TestByteorder_2_UCS4(ByteorderValues):
    """Check the byteorder in unicode (size 2, UCS4 values)"""
    ulen = 2
    ucs_value = ucs4_value


class TestByteorder_1009_UCS2(ByteorderValues):
    """Check the byteorder in unicode (size 1009, UCS2 values)"""
    ulen = 1009
    ucs_value = ucs2_value


class TestByteorder_1009_UCS4(ByteorderValues):
    """Check the byteorder in unicode (size 1009, UCS4 values)"""
    ulen = 1009
    ucs_value = ucs4_value

SILENT KILLER Tool