Пример #1
0
def diag_cuda(a):
    """Construct GPUArray diagonal.

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

    Returns
    -------
    gpuarray
        GPUArray with inserted diagonal.

    Examples
    --------
    >>> a = diag_cuda([1, 2, 3])
    array([[ 1.,  0.,  0.],
           [ 0.,  2.,  0.],
           [ 0.,  0.,  3.]])

    >>> type(a)
    <class 'pycuda.gpuarray.GPUArray'>
    """
    return give_cuda(diag(a))
Пример #2
0
def eye_cuda(n):
    """Create GPUArray identity matrix (ones on diagonal) of size (n x n).

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

    Returns
    -------
    gpuarray
        Identity matrix (n x n) as GPUArray.

    Examples
    --------
    >>> a = eye_cuda(3)
    array([[ 1.,  0.,  0.],
           [ 0.,  1.,  0.],
           [ 0.,  0.,  1.]])

    >>> type(a)
    <class 'pycuda.gpuarray.GPUArray'>
    """
    return give_cuda(eye(n, dtype=float32))
Пример #3
0
    # a = maximum_cuda(give_cuda([1, 2, 3]))
    # a = minimum_cuda(give_cuda([1, 2, 3]), give_cuda([3, 2, 1]))
#     # a = minimum_cuda(give_cuda([1, 2, 3]))
#     # b = argmax_cuda(give_cuda([[1, 2, 3], [6, 5, 4]]), axis=1)
#     # c = argmin_cuda(give_cuda([[1, 2, 3], [6, 5, 4]]), axis=1)
    # a = acos_cuda(give_cuda([0.5, 1]))
    # a = asin_cuda(give_cuda([0.5, 1]))
    # a = atan_cuda(give_cuda([0.5, 1]))
    # a = ceil_cuda(give_cuda([0.5, 0.1, 1.9]))
    # a = cos_cuda(give_cuda([0, pi/4]))
    # a = cosh_cuda(give_cuda([0, pi/4]))
    # a = exp_cuda(give_cuda([0, 1]))
    # a = floor_cuda(give_cuda([0.5, 0.1, 1.9]))
    # a = log_cuda(give_cuda([1, 10]))
    # a = log10_cuda(give_cuda([1, 10]))
#     # k = max_cuda(give_cuda([[1, 2, 3], [6, 5, 4]]), axis=1)
#     # l = min_cuda(give_cuda([[1, 2, 3], [6, 5, 4]]), axis=1)
#     # m = mean_cuda(give_cuda([[1, 2], [3, 4]]), axis=0)
    # a = sin_cuda(give_cuda([0, pi/4]))
    # a = sinh_cuda(give_cuda([0, pi/4]))
    # a = sqrt_cuda(give_cuda([4, 9]))
#     # a = sum_cuda(give_cuda([[1, 2], [3, 4]]), axis=None)
    # a = tan_cuda(give_cuda([0, pi/4]))
    # a = tanh_cuda(give_cuda([0, pi/4]))
    # a = round_cuda(give_cuda([1.4, 1.5, 1.6]))
    # a = round_cuda(give_cuda([[1.4, 1.5, 1.6], [2.4, 2.5, 2.6]]))
    a = sum_cuda(give_cuda([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), axis=1)

    print(a)
    print(type(a))
Пример #4
0
# ==============================================================================
# Main
# ==============================================================================

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

    from numpy import allclose
    from numpy import dot
    from numpy.random import rand

    from time import time

    a = diag_cuda([1., 2., 3.])
    a = eye_cuda(3)
    b = give_cuda([[5, -2, 1], [0, 3, -1], [2, 0, 7]])
    c = transpose_cuda(b)

    a = rand(200, 3)
    b = rand(3, 500)
    c = dot(a, b)

    a_ = give_cuda(a)
    b_ = give_cuda(b)
    c_ = dot_cuda(a_, b_)

    tic = time()
    print(1000 * (time() - tic))
    print(allclose(c, get_cuda(c_)))