Beispiel #1
0
 def decompress(self, tensor_compressed, shape):
     tensor_compressed, = tensor_compressed
     cupy_tensor = cupy.fromDlpack(to_dlpack(tensor_compressed))
     sign = cupy_tensor > 127
     exps = cupy.bitwise_and(cupy_tensor, 0b01111111)
     floats = cupy.left_shift((exps + 18).astype(cupy.int32), 23).view(cupy.float32)
     tensor_decompressed = cupy.where(sign, -floats, floats)
     tensor_decompressed = cupy.multiply((exps >= 1).astype(cupy.float32), tensor_decompressed)
     return from_dlpack(tensor_decompressed.toDlpack()).view(shape)
def bitwise_left_shift(x1: Array, x2: Array, /) -> Array:
    """
    Array API compatible wrapper for :py:func:`np.left_shift <numpy.left_shift>`.

    See its docstring for more information.
    """
    if x1.dtype not in _integer_dtypes or x2.dtype not in _integer_dtypes:
        raise TypeError(
            "Only integer dtypes are allowed in bitwise_left_shift")
    # Call result type here just to raise on disallowed type combinations
    _result_type(x1.dtype, x2.dtype)
    x1, x2 = Array._normalize_two_args(x1, x2)
    # Note: bitwise_left_shift is only defined for x2 nonnegative.
    if np.any(x2._array < 0):
        raise ValueError(
            "bitwise_left_shift(x1, x2) is only defined for x2 >= 0")
    return Array._new(np.left_shift(x1._array, x2._array))
Beispiel #3
0
def gradient_noise_3d(fx, fy, fz, ix, iy, iz, seed):
    vi = (__BN_X_NOISE_GEN * ix) + (__BN_Y_NOISE_GEN * iy) + (
        __BN_Z_NOISE_GEN * iz) + __BN_SEED_NOISE_GEN * seed
    vi = cp.bitwise_and(vi, 0xffffffff)
    vi = cp.bitwise_xor(vi, cp.right_shift(vi, __BN_SHIFT_NOISE_GEN))
    vi = cp.bitwise_and(vi, 0xff)

    vi_l2 = cp.left_shift(vi, 2)

    xvGrad = g_randomVectors[vi_l2]
    yvGrad = g_randomVectors[vi_l2 + 1]
    zvGrad = g_randomVectors[vi_l2 + 2]

    xvPoint = fx - ix
    yvPoint = fy - iy
    zvPoint = fz - iz

    return ((xvGrad * xvPoint) + (yvGrad * yvPoint) +
            (zvGrad * zvPoint)) * 2.12
Beispiel #4
0
 def __rlshift__(self, other):
     return cupy.left_shift(other, self)
Beispiel #5
0
 def __lshift__(self, other):
     return cupy.left_shift(self, other)