Esempio n. 1
0
def eye_cl(queue, n):
    """Create GPUArray identity matrix (ones on diagonal) of size (n x n).

    Parameters
    ----------
    queue
        PyOpenCL queue.
    n : int
        Size of identity matrix (n x n).

    Returns
    -------
    gpuarray
        Identity matrix (n x n) as GPUArray.
    """
    return give_cl(queue, eye(n, dtype=float32))
Esempio n. 2
0
def diag_cl(queue, a):
    """Construct GPUArray diagonal.

    Parameters
    ----------
    queue
        PyOpenCL queue.
    a : array, list
        Elements along diagonal.

    Returns
    -------
    gpuarray
        GPUArray with inserted diagonal.
    """
    return give_cl(queue, diag(a))
Esempio n. 3
0
    from numpy import pi

    ctx   = cl.create_some_context()
    queue = cl.CommandQueue(ctx)

    # a = abs_cl(give_cl(queue, [-0.1, -1.7]))
    # a = acos_cl(give_cl(queue, [0.5, 1]))
    # a = asin_cl(give_cl(queue, [0.5, 1]))
    # a = atan_cl(give_cl(queue, [0.5, 1]))
    # a = cos_cl(give_cl(queue, [0, pi/4]))
    # a = cosh_cl(give_cl(queue, [0, pi/4]))
    # a = maximum_cl(give_cl(queue, [1, 2, 3]), give_cl(queue, [3, 2, 1]))
    # a = maximum_cl(give_cl(queue, [1, 2, 3]))
    # a = minimum_cl(give_cl(queue, [1, 2, 3]), give_cl(queue, [3, 2, 1]))
    # a = minimum_cl(give_cl(queue, [1, 2, 3]))
    # a = sin_cl(give_cl(queue, [0, pi/4]))
    # a = sinh_cl(give_cl(queue, [0, pi/4]))
    # a = sqrt_cl(give_cl(queue, [4, 9]))
    # a = tan_cl(give_cl(queue, [0, pi/4]))
    # a = tanh_cl(give_cl(queue, [0, pi/4]))
    # a = exp_cl(give_cl(queue, [0, 1]))
    # a = floor_cl(give_cl(queue, [0.5, 0.1, 1.9]))
    # a = ceil_cl(give_cl(queue, [0.5, 0.1, 1.9]))
    # a = log_cl(give_cl(queue, [1, 10]))
    # a = log10_cl(give_cl(queue, [1, 10]))
    # a = round_cl(give_cl(queue, [1.4, 1.5, 1.6]))
    a = sum_cl(queue, give_cl(queue, [[1, 2, 3], [4, 5, 6], [7, 8, 9]]), axis=1)

    print(a)
    print(type(a))
Esempio n. 4
0
    Parameters
    ----------
    queue
        PyOpenCL queue.
    n : int
        Size of identity matrix (n x n).

    Returns
    -------
    gpuarray
        Identity matrix (n x n) as GPUArray.
    """
    return give_cl(queue, eye(n, dtype=float32))


# ==============================================================================
# Main
# ==============================================================================

if __name__ == "__main__":
    from compas_hpc import get_cl

    ctx = cl.create_some_context(interactive=False)
    queue = cl.CommandQueue(ctx)

    a_ = give_cl(queue, [[0, 1, 2]])

    print(get_cl(diag_cl(queue, [0, 1, 2])))
    print(get_cl(eye_cl(queue, 3)))
    print(get_cl(transpose_cl(a_)))
Esempio n. 5
0
    ctx = cl.create_some_context()
    queue = cl.CommandQueue(ctx)

    # a = abs_cl(give_cl(queue, [-0.1, -1.7]))
    # a = acos_cl(give_cl(queue, [0.5, 1]))
    # a = asin_cl(give_cl(queue, [0.5, 1]))
    # a = atan_cl(give_cl(queue, [0.5, 1]))
    # a = cos_cl(give_cl(queue, [0, pi/4]))
    # a = cosh_cl(give_cl(queue, [0, pi/4]))
    # a = maximum_cl(give_cl(queue, [1, 2, 3]), give_cl(queue, [3, 2, 1]))
    # a = maximum_cl(give_cl(queue, [1, 2, 3]))
    # a = minimum_cl(give_cl(queue, [1, 2, 3]), give_cl(queue, [3, 2, 1]))
    # a = minimum_cl(give_cl(queue, [1, 2, 3]))
    # a = sin_cl(give_cl(queue, [0, pi/4]))
    # a = sinh_cl(give_cl(queue, [0, pi/4]))
    # a = sqrt_cl(give_cl(queue, [4, 9]))
    # a = tan_cl(give_cl(queue, [0, pi/4]))
    # a = tanh_cl(give_cl(queue, [0, pi/4]))
    # a = exp_cl(give_cl(queue, [0, 1]))
    # a = floor_cl(give_cl(queue, [0.5, 0.1, 1.9]))
    # a = ceil_cl(give_cl(queue, [0.5, 0.1, 1.9]))
    # a = log_cl(give_cl(queue, [1, 10]))
    # a = log10_cl(give_cl(queue, [1, 10]))
    # a = round_cl(give_cl(queue, [1.4, 1.5, 1.6]))
    a = sum_cl(queue,
               give_cl(queue, [[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
               axis=1)

    print(a)
    print(type(a))