本文整理汇总了Python中pycuda.gpuarray.arange函数的典型用法代码示例。如果您正苦于以下问题:Python arange函数的具体用法?Python arange怎么用?Python arange使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了arange函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
示例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]
示例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]
示例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)
示例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)
示例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)
示例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)
示例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
示例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]
示例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
示例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
示例12: test_arange
def test_arange(self):
a = gpuarray.arange(12, dtype=np.float32)
assert (np.arange(12, dtype=np.float32) == a.get()).all()
示例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
示例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()
示例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