• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python gpuarray.arange函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pycuda.gpuarray.arange函数的典型用法代码示例。如果您正苦于以下问题:Python arange函数的具体用法?Python arange怎么用?Python arange使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_take

    def test_take(self):
        idx = gpuarray.arange(0, 10000, 2, dtype=np.uint32)
        for dtype in [np.float32, np.complex64]:
            a = gpuarray.arange(0, 600000, dtype=np.uint32).astype(dtype)
            a_host = a.get()
            result = gpuarray.take(a, idx)

            assert (a_host[idx.get()] == result.get()).all()
开发者ID:rutsky,项目名称:pycuda,代码行数:8,代码来源:test_gpuarray.py


示例2: test_fmod

    def test_fmod(self):
        """tests if the fmod function works"""
        for s in sizes:
            a = gpuarray.arange(s, dtype=np.float32)/10
            a2 = gpuarray.arange(s, dtype=np.float32)/45.2 + 0.1
            b = cumath.fmod(a, a2)

            a = a.get()
            a2 = a2.get()
            b = b.get()

            for i in range(s):
                assert math.fmod(a[i], a2[i]) == b[i]
开发者ID:DirkHaehnel,项目名称:pycuda,代码行数:13,代码来源:test_cumath.py


示例3: test_ldexp

    def test_ldexp(self):
        """tests if the ldexp function works"""
        for s in sizes:
            a = gpuarray.arange(s, dtype=np.float32)
            a2 = gpuarray.arange(s, dtype=np.float32)*1e-3
            b = cumath.ldexp(a, a2)

            a = a.get()
            a2 = a2.get()
            b = b.get()

            for i in range(s):
                assert math.ldexp(a[i], int(a2[i])) == b[i]
开发者ID:DirkHaehnel,项目名称:pycuda,代码行数:13,代码来源:test_cumath.py


示例4: bptrs

def bptrs(a):
    """
    Pointer array when input represents a batch of matrices.
    """

    return gpuarray.arange(a.ptr,a.ptr+a.shape[0]*a.strides[0],a.strides[0],
                dtype=cublas.ctypes.c_void_p)
开发者ID:Brainiarc7,项目名称:scikit-cuda,代码行数:7,代码来源:test_cublas.py


示例5: test_arange

    def test_arange(self):
        """test the arrangement of the array"""
        a = gpuarray.arange(12)

        res = a.get()

        for i in range(12):
            self.assert_(res[i] ==i)
开发者ID:berlinguyinca,项目名称:pycuda,代码行数:8,代码来源:test_abstract_array.py


示例6: test_abs

    def test_abs(self):
        """test if the abs function works"""
        a = gpuarray.arange(111)
        a = a * -1

        res = a.get()

        for i in range (111):
            self.assert_(res[i] <= 0)

        a = abs(a)

        res = a.get()

        for i in range (111):
            self.assert_(res[i] >= 0)
            self.assert_(res[i] == i)


        for i in range(100,200):
            a = gpuarray.arange(500 * i)
            self.assert_(a[len(a)-1] == len(a)-1)
开发者ID:berlinguyinca,项目名称:pycuda,代码行数:22,代码来源:test_abstract_array.py


示例7: test

    def test():
        gpu_func = getattr(cumath, name)
        cpu_func = getattr(np, numpy_func_names.get(name, name))

        for s in sizes:
            for dtype in dtypes:
                args = gpuarray.arange(a, b, (b-a)/s, dtype=np.float32)
                gpu_results = gpu_func(args).get()
                cpu_results = cpu_func(args.get())

                max_err = np.max(np.abs(cpu_results - gpu_results))
                assert (max_err <= threshold).all(), \
                        (max_err, name, dtype)
开发者ID:abergeron,项目名称:pycuda,代码行数:13,代码来源:test_cumath.py


示例8: test_abs

    def test_abs(self):
        a = -gpuarray.arange(111, dtype=np.float32)
        res = a.get()

        for i in range(111):
            assert res[i] <= 0

        a = abs(a)

        res = a.get()

        for i in range(111):
            assert abs(res[i]) >= 0
            assert res[i] == i
开发者ID:rutsky,项目名称:pycuda,代码行数:14,代码来源:test_gpuarray.py


示例9: test_frexp

    def test_frexp(self):
        """tests if the frexp function works"""
        for s in sizes:
            a = gpuarray.arange(s, dtype=np.float32)/10
            significands, exponents = cumath.frexp(a)

            a = a.get()
            significands = significands.get()
            exponents = exponents.get()

            for i in range(s):
                sig_true, ex_true = math.frexp(a[i])

                assert sig_true == significands[i]
                assert ex_true == exponents[i]
开发者ID:DirkHaehnel,项目名称:pycuda,代码行数:15,代码来源:test_cumath.py


示例10: test_modf

    def test_modf(self):
        """tests if the modf function works"""
        for s in sizes:
            a = gpuarray.arange(s, dtype=np.float32)/10
            fracpart, intpart = cumath.modf(a)

            a = a.get()
            intpart = intpart.get()
            fracpart = fracpart.get()

            for i in range(s):
                fracpart_true, intpart_true = math.modf(a[i])

                assert intpart_true == intpart[i]
                assert abs(fracpart_true - fracpart[i]) < 1e-4
开发者ID:DirkHaehnel,项目名称:pycuda,代码行数:15,代码来源:test_cumath.py


示例11: test_sum_allocator

    def test_sum_allocator(self):
        import pycuda.tools
        pool = pycuda.tools.DeviceMemoryPool()

        rng = np.random.randint(low=512,high=1024)

        a = gpuarray.arange(rng,dtype=np.int32)
        b = gpuarray.sum(a)
        c = gpuarray.sum(a, allocator=pool.allocate)

        # Test that we get the correct results
        assert b.get() == rng*(rng-1)//2
        assert c.get() == rng*(rng-1)//2

        # Test that result arrays were allocated with the appropriate allocator
        assert b.allocator == a.allocator
        assert c.allocator == pool.allocate
开发者ID:rutsky,项目名称:pycuda,代码行数:17,代码来源:test_gpuarray.py


示例12: test_arange

 def test_arange(self):
     a = gpuarray.arange(12, dtype=np.float32)
     assert (np.arange(12, dtype=np.float32) == a.get()).all()
开发者ID:rutsky,项目名称:pycuda,代码行数:3,代码来源:test_gpuarray.py


示例13: compute_pi

def compute_pi(n):
    h = 1.0 / n
    x = h * (ga.arange(1, n, dtype=np.float32) + 0.5)
    s = ga.sum(4.0 / (1.0 + x**2), dtype=np.float32)
    return s.get() * h
开发者ID:Irud666,项目名称:heterogeno,代码行数:5,代码来源:pycuda+izracunavanje+pi.py


示例14: range

ndev = 2
devlist = range(ndev)

# Setup the pycuda side
drv.init()
ctxs = [drv.Device(i).retain_primary_context() for i in devlist]

# Setup the communicator object
nc = NCCLComm(devlist)

# Now create gpuarrays for sending/recv buffers
srcs, dsts, size = [], [], 10

# Create some test arrays
for ctx in ctxs:
    ctx.push()
    srcs.append(gpuarray.arange(100, 200, size, dtype='<f4'))
    dsts.append(gpuarray.zeros((size,), dtype='<f4'))
    ctx.pop()

# Perform the reduction
nc.all_reduce(size, srcs, dsts)
nc.sync()

# Look at the results
for c, i, o in zip(ctxs, srcs, dsts):
    c.push()
    print i.get()
    print o.get()
    c.pop()
开发者ID:apark263,项目名称:nccl_wrapper,代码行数:30,代码来源:nccllib_test.py


示例15: int

time = int(round(22.0 * xres / yres))
#print time
xlen = time / float(size[0])
#print xlen

#initialize out
out = np.zeros(0)

#rgb aliases
r=0
g=1
b=2

for x in range(xres):
    #float32 degrades quality, but float64 not support by gpus
    t_gpu = gpuarray.arange(x*xlen, x*xlen + xlen, 1./44100, dtype=np.float32)
    tone_gpu = gpuarray.zeros(t_gpu.size, dtype=np.float32)
    print "{0}%".format(round(100.0 * x / xres, 2))
    for y in range(yres):
        p = d[x+xres*y]
        #keep playing with these values
        amplitude = 10**(1-5.25+4.25*(p[r]+p[g]+p[b])/(255*3))
#        print amplitude, math.log(amplitude+1)
#        amplitude = math.log(amplitude+1)# / math.log(255)
#        print x, y, amplitude
        if p[r] > 10 or p[g] > 10 and p[b] > 10:
            tone_gpu += oscillator(t_gpu,
                                   amp = amplitude,
                                   #amp=(p[r]+p[g]+p[b]),
                                   freq=yscale * (yres - y))
    tone_gpu = tone_gpu + 1
开发者ID:nicolasavru,项目名称:DSP-Experiments,代码行数:31,代码来源:imageToWav-pycuda.py


示例16: ReductionKernel

import pycuda.gpuarray as gpuarray
import pycuda.autoinit
import numpy
from pycuda.reduction import ReductionKernel

vector_length = 400

input_vector_a = gpuarray.arange(vector_length, dtype=numpy.int)
input_vector_b = gpuarray.arange(vector_length, dtype=numpy.int)
dot_product = ReductionKernel(numpy.int,
                       arguments="int *x, int *y",
                       map_expr="x[i]*y[i]",
                       reduce_expr="a+b", neutral="0")

dot_product = dot_product(input_vector_a, input_vector_b).get()

print("INPUT MATRIX A")
print input_vector_a

print("INPUT MATRIX B")
print input_vector_b

print("RESULT DOT PRODUCT OF A * B")
print dot_product

开发者ID:lancelote,项目名称:parallel_python,代码行数:24,代码来源:PyCudaReductionKernel.py


示例17: stats_callback

        if stats_callback is not None:
            stats_callback(size,  self,
                    kernel_rec.kernel.prepared_timed_call(vectors[0]._grid, results[0]._block, *args))
        else:
            kernel_rec.kernel.prepared_async_call(vectors[0]._grid, results[0]._block, self.stream, *args)

        return results




if __name__ == "__main__":
    test_dtype = numpy.float32

    import pycuda.autoinit
    from pymbolic import parse
    expr = parse("2*x+3*y+4*z")
    print expr
    cexpr = CompiledVectorExpression(expr,
            lambda expr: (True, test_dtype),
            test_dtype)

    from pymbolic import var
    ctx = {
        var("x"): gpuarray.arange(5, dtype=test_dtype),
        var("y"): gpuarray.arange(5, dtype=test_dtype),
        var("z"): gpuarray.arange(5, dtype=test_dtype),
        }

    print cexpr(lambda expr: ctx[expr])
开发者ID:gimac,项目名称:hedge,代码行数:30,代码来源:vector_expr.py


示例18: time

c = 5*a+6*b
e = time()
print 'cpu elapsed time: %f \n' % (e-s)

###################
# 4) map/reduce kernel

print '\n map/reduce kernel\n'
print '--------------------\n'

from pycuda.reduction import ReductionKernel

sz = 7000

# on device
a = gpuarray.arange(sz, dtype=numpy.float32)
b = gpuarray.arange(sz, dtype=numpy.float32)

krnl = ReductionKernel(numpy.float32, neutral="0",
        reduce_expr="a+2*b+b*b", map_expr="x[i] + y[i]",
        arguments="float *x, float *y")

# device perf
s = time()
my_dot_prod = krnl(a, b).get()
e = time()
print 'kernel time: %f' % (e-s)

# on host
a2 = arange(sz, dtype=numpy.float32)
b2 = arange(sz, dtype=numpy.float32)
开发者ID:darien,项目名称:finweb,代码行数:31,代码来源:gpu_experiments.py


示例19: test_take

 def test_take(self):
     idx = gpuarray.arange(0, 200000, 2, dtype=np.uint32)
     a = gpuarray.arange(0, 600000, 3, dtype=np.float32)
     result = gpuarray.take(a, idx)
     assert ((3*idx).get() == result.get()).all()
开发者ID:leifdenby,项目名称:pycuda,代码行数:5,代码来源:test_gpuarray.py


示例20: ReductionKernel

from pycuda.reduction import ReductionKernel
import pycuda.gpuarray as gpuarray
import pycuda.autoinit
import numpy

a = gpuarray.arange(400, dtype=numpy.float32)
b = gpuarray.arange(400, dtype=numpy.float32)

dot = ReductionKernel(dtype_out=numpy.float32, neutral="0",reduce_expr="a+b", map_expr="x[i]*y[i]",arguments="const float *x, const float *y")

a_dot_b = dot(a, b).get()
a_dot_b_cpu = numpy.dot(a.get(), b.get())
开发者ID:benlansdell,项目名称:hydra,代码行数:12,代码来源:pycudareduction.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python gpuarray.dot函数代码示例发布时间:2022-05-25
下一篇:
Python elementwise.get_binary_op_kernel函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap