当前位置: 首页>>代码示例>>Python>>正文


Python OCLArray.empty_like方法代码示例

本文整理汇总了Python中gputools.OCLArray.empty_like方法的典型用法代码示例。如果您正苦于以下问题:Python OCLArray.empty_like方法的具体用法?Python OCLArray.empty_like怎么用?Python OCLArray.empty_like使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gputools.OCLArray的用法示例。


在下文中一共展示了OCLArray.empty_like方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: bilateral3

# 需要导入模块: from gputools import OCLArray [as 别名]
# 或者: from gputools.OCLArray import empty_like [as 别名]
def bilateral3(data, size_filter, sigma_p, sigma_x = 10.):
    """bilateral filter """
    
    dtype = data.dtype.type
    dtypes_kernels = {np.float32:"bilat3_float",}

    if not dtype in dtypes_kernels.keys():
        logger.info("data type %s not supported yet (%s), casting to float:"%(dtype,dtypes_kernels.keys()))
        data = data.astype(np.float32)
        dtype = data.dtype.type


    img = OCLImage.from_array(data)
    res = OCLArray.empty_like(data)

    
    prog = OCLProgram(abspath("kernels/bilateral3.cl"))

    print img.shape

    prog.run_kernel(dtypes_kernels[dtype],
                    img.shape,None,
                    img,res.data,
                    np.int32(img.shape[0]),np.int32(img.shape[1]),
                    np.int32(size_filter),np.float32(sigma_x),np.float32(sigma_p))


    return res.get()
开发者ID:robintw,项目名称:gputools,代码行数:30,代码来源:bilateral3.py

示例2: _fft_convolve_numpy

# 需要导入模块: from gputools import OCLArray [as 别名]
# 或者: from gputools.OCLArray import empty_like [as 别名]
def _fft_convolve_numpy(data, h, plan = None,
                        kernel_is_fft = False,
                        kernel_is_fftshifted = False):
    """ convolving via opencl fft for numpy arrays

    data and h must have the same size
    """

    dev = get_device()

    if data.shape != h.shape:
        raise ValueError("data and kernel must have same size! %s vs %s "%(str(data.shape),str(h.shape)))

    
    data_g = OCLArray.from_array(data.astype(np.complex64))

    if not kernel_is_fftshifted:
        h = np.fft.fftshift(h)

    
    h_g = OCLArray.from_array(h.astype(np.complex64))
    res_g = OCLArray.empty_like(data_g)
    
    _fft_convolve_gpu(data_g,h_g,res_g = res_g,
                      plan = plan,
                      kernel_is_fft = kernel_is_fft)

    res =  abs(res_g.get())

    del data_g
    del h_g
    del res_g
    
    return res
开发者ID:robintw,项目名称:gputools,代码行数:36,代码来源:oclfft_convolve.py

示例3: _convolve_sep2_gpu

# 需要导入模块: from gputools import OCLArray [as 别名]
# 或者: from gputools.OCLArray import empty_like [as 别名]
def _convolve_sep2_gpu(data_g, hx_g, hy_g, res_g = None):

    assert_bufs_type(np.float32,data_g,hx_g,hy_g)

    prog = OCLProgram(abspath("kernels/convolve_sep.cl"))

    Ny,Nx = hy_g.shape[0],hx_g.shape[0]

    tmp_g = OCLArray.empty_like(data_g)

    if res_g is None:
        res_g = OCLArray.empty_like(data_g)
    
    prog.run_kernel("conv_sep2_x",data_g.shape[::-1],None,data_g.data,hx_g.data,tmp_g.data,np.int32(Nx))
    prog.run_kernel("conv_sep2_y",data_g.shape[::-1],None,tmp_g.data,hy_g.data,res_g.data,np.int32(Ny))

    return res_g
开发者ID:maweigert,项目名称:gputools,代码行数:19,代码来源:convolve_sep.py

示例4: test_bessel

# 需要导入模块: from gputools import OCLArray [as 别名]
# 或者: from gputools.OCLArray import empty_like [as 别名]
def test_bessel(n,x):
    x_g = OCLArray.from_array(x.astype(float32))
    res_g = OCLArray.empty_like(x.astype(float32))
    
    p = OCLProgram(absPath("kernels/bessel.cl"))
    p.run_kernel("bessel_fill",x_g.shape,None,
                 x_g.data,res_g.data,int32(n))

    return res_g.get()
开发者ID:maweigert,项目名称:bpm,代码行数:11,代码来源:_focus_fields_debye.py

示例5: fftshift

# 需要导入模块: from gputools import OCLArray [as 别名]
# 或者: from gputools.OCLArray import empty_like [as 别名]
def fftshift(arr_obj, axes = None, res_g = None, return_buffer = False):
    """
    gpu version of fftshift for numpy arrays or OCLArrays

    Parameters
    ----------
    arr_obj: numpy array or OCLArray (float32/complex64)
        the array to be fftshifted
    axes: list or None
        the axes over which to shift (like np.fft.fftshift)
        if None, all axes are taken
    res_g:
        if given, fills it with the result (has to be same shape and dtype as arr_obj)
        else internally creates a new one
    Returns
    -------
        if return_buffer, returns the result as (well :) OCLArray
        else returns the result as numpy array

    """

    if axes is None:
        axes = range(arr_obj.ndim)


    if isinstance(arr_obj, OCLArray):
        if not arr_obj.dtype.type in DTYPE_KERNEL_NAMES.keys():
            raise NotImplementedError("only works for float32 or complex64")
    elif isinstance(arr_obj, np.ndarray):
        if np.iscomplexobj(arr_obj):
            arr_obj = OCLArray.from_array(arr_obj.astype(np.complex64,copy = False))
        else:
            arr_obj = OCLArray.from_array(arr_obj.astype(np.float32,copy = False))
    else:
        raise ValueError("unknown type (%s)"%(type(arr_obj)))

    if not np.all([arr_obj.shape[a]%2==0 for a in axes]):
        raise NotImplementedError("only works on axes of even dimensions")

    if res_g is None:
        res_g = OCLArray.empty_like(arr_obj)


    # iterate over all axes
    # FIXME: this is still rather inefficient
    in_g = arr_obj
    for ax in axes:
        _fftshift_single(in_g, res_g, ax)
        in_g = res_g

    if return_buffer:
        return res_g
    else:
        return res_g.get()
开发者ID:maweigert,项目名称:gputools,代码行数:56,代码来源:fftshift.py

示例6: transfer

# 需要导入模块: from gputools import OCLArray [as 别名]
# 或者: from gputools.OCLArray import empty_like [as 别名]
def transfer(data):
    """transfers data"""

    d1_g = OCLArray.from_array(data)
    d2_g = OCLArray.empty_like(data)

    if data.dtype.type == np.float32:
        im = OCLImage.empty(data.shape[::1],dtype = np.float32)
    elif data.dtype.type == np.complex64:
        im = OCLImage.empty(data.shape[::1],dtype = np.float32, num_channels=2)

    im.copy_buffer(d1_g)
    d2_g.copy_image(im)

    return d2_g.get()
开发者ID:maweigert,项目名称:gputools,代码行数:17,代码来源:test_resample.py

示例7: get_gpu

# 需要导入模块: from gputools import OCLArray [as 别名]
# 或者: from gputools.OCLArray import empty_like [as 别名]
def get_gpu(N = 256, niter=100, sig = 1.):
    np.random.seed(0)
    a = np.random.normal(0,sig,(N,N)).astype(np.complex64)
    b = (1.*a.copy()).astype(np.complex64)

    c_g = OCLArray.empty_like(b)
    b_g = OCLArray.from_array(b)
    p = fft_plan((N,N), fast_math = False)
    
    rels = []
    for _ in range(niter):
        fft(b_g,res_g = c_g, plan = p)
        fft(c_g, res_g = b_g, inverse = True, plan = p)

        # b = fft(fft(b), inverse = True)
        # rels.append(np.amax(np.abs(a-b))/np.amax(np.abs(a)))
        rels.append(np.amax(np.abs(a-b_g.get()))/np.amax(np.abs(a)))

    return np.array(rels)
开发者ID:maweigert,项目名称:biobeam,代码行数:21,代码来源:test_fft_accur.py

示例8: isinstance

# 需要导入模块: from gputools import OCLArray [as 别名]
# 或者: from gputools.OCLArray import empty_like [as 别名]
#     dtype = d_g.dtype.type
#
#     if not isinstance(d_g, OCLArray):
#         raise ValueError("only works on  OCLArrays")
#
#     if not dtype in dtype_kernel_name.keys():
#         raise NotImplementedError("only works for float32 or complex64")
#
#     if not np.all([n%2==0 for n in d_g.shape]):
#         raise NotImplementedError("only works on even length arryas")
#
#     prog = OCLProgram(abspath("kernels/fftshift.cl"))
#     prog.run_kernel(dtype_kernel_name[dtype],(Nx,Ny,),None,
#                     d_g.data, d_g.data,
#                     np.int32(Nx), np.int32(Ny))

    # return d_g

if __name__ == '__main__':

    Nx, Ny, Nz = (256,)*3
    d = np.linspace(0,1,Nx*Ny*Nz).reshape(Nz, Ny,Nx).astype(np.float32)

    d[Nz/2-30:Nz/2+30,Ny/2-20:Ny/2+20,Nx/2-20:Nx/2+20] = 2.

    d_g = OCLArray.from_array(d)
    out_g = OCLArray.empty_like(d)


    out = fftshift(d, axes= (0,1,2))
开发者ID:maweigert,项目名称:gputools,代码行数:32,代码来源:fftshift.py


注:本文中的gputools.OCLArray.empty_like方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。