Exemple #1
0
 def test_integer_downcast_signed_to_unsigned(self):
     arr, nt = ic.downcast_integers(unsigned_byte_arr().astype(np.int64))
     self.assertEqual(10, len(arr))
     self.assertEqual(arr[0], 1)
     self.assertEqual(arr[9], 10)
     self.assertEqual(nt.kind, t.NumpyKinds.UNSIGNED)
     self.assertEqual(nt.size, t.NumpySizes.BYTE)
     return
Exemple #2
0
 def test_integer_downcast_downcast_to_byte_signed(self):
     arr, nt = ic.downcast_integers(integer_byte_arr().astype(np.int16))
     self.assertEqual(11, len(arr))
     self.assertEqual(arr[0], -5)
     self.assertEqual(arr[10], 5)
     self.assertEqual(nt.kind, t.NumpyKinds.INTEGER)
     self.assertEqual(nt.size, t.NumpySizes.BYTE)
     return
def integer_hash_decompression(arr: np.array, transform: IntegerHashTransformation) -> np.array:
    """
    Decompresses a hashed integer array
    :param arr: compressed key array
    :param transform: hash transform info
    :return: decompressed array
    """
    logging.debug('decompressing hash array with info: {}'.format(transform))
    ret_array = np.zeros(arr.shape, dtype=transform.key_values_type.to_dtype())
    for i in range(len(arr)):
        ret_array[i] = transform.key_values[arr[i]]
    return downcast_integers(ret_array)[0]
def integer_minimize_decompression(arr: np.array, transform: IntegerMinimizeTransformation) -> np.array:
    """
    Decompresses a minimize transform
    :param arr: minimized array
    :param transform: transformation info
    :return: un-minimized array
    """
    logging.debug('decompressing minimized array with info: {}'.format(transform))
    ret_array_type = t.NumpyType(
        kind=t.NumpyKinds.from_dtype(arr.dtype),
        size=t.NumpySizes.DOUBLE  # make it as big as possible then shrink after addition
    )
    return downcast_integers(arr.astype(ret_array_type.to_dtype()) + transform.reference_value)[0]
def integer_derivative_decompression(arr: np.array, transform: IntegerElementWiseTransformation) -> np.array:
    """
    Decompresses an element-wise derivative transform
    :param arr: derivative array
    :param transform: transformation info
    :return: decompressed array
    """
    logging.debug('decompressing derivative array with info: {}'.format(transform))
    ret_array_type = t.NumpyType(
        kind=t.NumpyKinds.from_dtype(arr.dtype),
        size=t.NumpySizes.DOUBLE
    )
    ret_array = np.cumsum(arr.astype(ret_array_type.to_dtype())) + transform.reference_value
    ret_array = np.insert(ret_array, 0, transform.reference_value)
    return downcast_integers(ret_array)[0]
Exemple #6
0
 def test_integer_downcast_kind_error(self):
     with self.assertRaises(x.NumpyDtypeKindInvalidException):
         ic.downcast_integers(np.array([], dtype=np.float32))
     return