本文整理汇总了Python中pygpu.gpuarray.zeros函数的典型用法代码示例。如果您正苦于以下问题:Python zeros函数的具体用法?Python zeros怎么用?Python zeros使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zeros函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_elemwise_bool
def test_elemwise_bool():
a = gpuarray.empty((2,), context=context)
exc = None
try:
bool(a)
except ValueError as e:
exc = e
assert exc is not None
a = gpuarray.zeros((1,), context=context)
assert not bool(a)
a = gpuarray.zeros((), context=context)
assert not bool(a)
开发者ID:nouiz,项目名称:libgpuarray,代码行数:12,代码来源:test_elemwise.py
示例2: perform
def perform(self, node, inputs, outs):
out, = outs
v = inputs[0]
sh = tuple(map(int, inputs[1:]))
if out[0] is None or out[0].shape != sh:
if self.memset_0:
out[0] = gpuarray.zeros(sh, dtype=v.dtype)
else:
out[0] = gpuarray.empty(sh, dtype=v.dtype)
out[0][...] = v
else:
out[0][...] = v
if config.gpuarray.sync:
out[0].sync()
开发者ID:naisanza,项目名称:Theano,代码行数:14,代码来源:basic_ops.py
示例3: perform
def perform(self, node, inputs, outs):
out, = outs
v = inputs[0]
sh = tuple(map(int, inputs[1:]))
if out[0] is None or out[0].shape != sh:
if v.size == 1 and numpy.asarray(v)[0].item() == 0:
out[0] = gpuarray.zeros(sh, dtype=v.dtype)
else:
out[0] = gpuarray.empty(sh, dtype=v.dtype)
out[0][...] = v
else:
out[0][...] = v
if config.gpuarray.sync:
out[0].sync()
开发者ID:clorenz7,项目名称:Theano,代码行数:14,代码来源:basic_ops.py
示例4: perform
def perform(self, node, inputs, outputs):
(x,) = inputs
(z,) = outputs
dim = x.shape[0] + abs(self.offset)
z[0] = gpuarray.zeros((dim, dim), dtype=x.dtype, context=x.context)
if self.offset <= 0: # diag in the lower triangle
diag_z = z[0][-self.offset, :(dim + self.offset)]
else: # diag in the upper triangle
diag_z = z[0][:(dim - self.offset), self.offset]
diag_z.strides = (sum(z[0].strides),)
diag_z[:] = x[:]
开发者ID:juancamilog,项目名称:Theano,代码行数:14,代码来源:subtensor.py
示例5: test_shape
def test_shape():
x = GpuArrayType(dtype='float32', broadcastable=[False, False, False])()
v = gpuarray.zeros((3, 4, 5), dtype='float32', context=get_context(test_ctx_name))
f = theano.function([x], x.shape)
topo = f.maker.fgraph.toposort()
assert np.all(f(v) == (3, 4, 5))
if theano.config.mode != 'FAST_COMPILE':
assert len(topo) == 4
assert isinstance(topo[0].op, T.opt.Shape_i)
assert isinstance(topo[1].op, T.opt.Shape_i)
assert isinstance(topo[2].op, T.opt.Shape_i)
assert isinstance(topo[3].op, T.opt.MakeVector)
mode = mode_with_gpu.excluding("local_shape_to_shape_i")
f = theano.function([x], x.shape, mode=mode)
topo = f.maker.fgraph.toposort()
assert np.all(f(v) == (3, 4, 5))
assert len(topo) == 1
assert isinstance(topo[0].op, T.Shape)
开发者ID:DEVESHTARASIA,项目名称:Theano,代码行数:18,代码来源:test_basic_ops.py
示例6: test_elemwise_bool
assert out_c[1].shape == out_g[1].shape
assert out_c[0].dtype == out_g[0].dtype
assert out_c[1].dtype == out_g[1].dtype
assert numpy.allclose(out_c[0], numpy.asarray(out_g[0]))
assert numpy.allclose(out_c[1], numpy.asarray(out_g[1]))
def test_elemwise_bool():
a = gpuarray.empty((2,), context=context)
exc = None
try:
bool(a)
except ValueError, e:
exc = e
assert e is not None
a = gpuarray.zeros((1,), context=context)
assert bool(a) == False
a = gpuarray.zeros((), context=context)
assert bool(a) == False
def test_broadcast():
for shapea, shapeb in [((3, 5), (3, 5)),
((1, 5), (3, 5)),
((3, 5), (3, 1)),
((1, 5), (3, 1)),
((3, 1), (3, 5)),
((3, 5), (3, 1)),
((1, 1), (1, 1)),
((3, 4, 5), (4, 5)),
((4, 5), (3, 4, 5)),
开发者ID:chagge,项目名称:libgpuarray,代码行数:31,代码来源:test_elemwise.py
示例7: test_zero_noparam
def test_zero_noparam():
try:
gpu_ndarray.zeros()
assert False
except TypeError:
pass
开发者ID:MaxBareiss,项目名称:libgpuarray,代码行数:6,代码来源:test_gpu_ndarray.py
示例8: test_zeros_no_dtype
def test_zeros_no_dtype():
# no dtype and order param
x = gpu_ndarray.zeros((), context=ctx)
y = numpy.zeros(())
check_meta(x, y)
开发者ID:MaxBareiss,项目名称:libgpuarray,代码行数:5,代码来源:test_gpu_ndarray.py
示例9: zeros
def zeros(shp, order, dtype):
x = gpu_ndarray.zeros(shp, dtype, order, context=ctx)
y = numpy.zeros(shp, dtype, order)
check_all(x, y)
开发者ID:MaxBareiss,项目名称:libgpuarray,代码行数:4,代码来源:test_gpu_ndarray.py
示例10: thunk
def thunk():
context = inputs[0][0].context
# Size of the matrices to invert.
z = outputs[0]
# Matrix.
A = inputs[0][0]
# Solution vectors.
b = inputs[1][0]
assert(len(A.shape) == 2)
assert(len(b.shape) == 2)
if self.trans in ['T', 'C']:
trans = 1
l, n = A.shape
k, m = b.shape
elif self.trans == 'N':
trans = 0
n, l = A.shape
k, m = b.shape
else:
raise ValueError('Invalid value for trans')
if l != n:
raise ValueError('A must be a square matrix')
if n != k:
raise ValueError('A and b must be aligned.')
lda = max(1, n)
ldb = max(1, k, m)
# We copy A and b as cusolver operates inplace
b = gpuarray.array(b, copy=True, order='F')
if not self.inplace:
A = gpuarray.array(A, copy=True)
A_ptr = A.gpudata
b_ptr = b.gpudata
# cusolver expects a F ordered matrix, but A is not explicitly
# converted between C and F order, instead we switch the
# "transpose" flag.
if A.flags['C_CONTIGUOUS']:
trans = 1 - trans
workspace_size = cusolver.cusolverDnSgetrf_bufferSize(
cusolver_handle, n, n, A_ptr, lda)
if (thunk.workspace is None or
thunk.workspace.size != workspace_size):
thunk.workspace = gpuarray.zeros((workspace_size,),
dtype='float32',
context=context)
if thunk.pivots is None or thunk.pivots.size != min(n, n):
thunk.pivots = gpuarray.zeros((min(n, n),),
dtype='float32',
context=context)
if thunk.dev_info is None:
thunk.dev_info = gpuarray.zeros((1,),
dtype='float32',
context=context)
workspace_ptr = thunk.workspace.gpudata
pivots_ptr = thunk.pivots.gpudata
dev_info_ptr = thunk.dev_info.gpudata
cusolver.cusolverDnSgetrf(
cusolver_handle, n, n, A_ptr, lda, workspace_ptr,
pivots_ptr, dev_info_ptr)
cusolver.cusolverDnSgetrs(
cusolver_handle, trans, n, m, A_ptr, lda,
pivots_ptr, b_ptr, ldb, dev_info_ptr)
z[0] = b
开发者ID:bouthilx,项目名称:Theano,代码行数:78,代码来源:linalg.py
注:本文中的pygpu.gpuarray.zeros函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论