提交 8d809317 authored 作者: Benjamin Scellier's avatar Benjamin Scellier

file theano/gpuarray/subtensor.py

上级 671275d9
...@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division ...@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
import os import os
import numpy import numpy as np
from six import integer_types from six import integer_types
from six.moves import StringIO from six.moves import StringIO
...@@ -128,7 +128,7 @@ class GpuSubtensor(HideC, Subtensor): ...@@ -128,7 +128,7 @@ class GpuSubtensor(HideC, Subtensor):
def fix_idx(idx): def fix_idx(idx):
if idx is None: if idx is None:
return "0", 1 return "0", 1
elif isinstance(idx, (numpy.integer, integer_types)): elif isinstance(idx, (np.integer, integer_types)):
return str(idx), 0 return str(idx), 0
elif isinstance(idx, gof.Type): elif isinstance(idx, gof.Type):
return indices.pop(0), 0 return indices.pop(0), 0
...@@ -155,7 +155,7 @@ class GpuSubtensor(HideC, Subtensor): ...@@ -155,7 +155,7 @@ class GpuSubtensor(HideC, Subtensor):
else: else:
if isinstance(idx, gof.Type): if isinstance(idx, gof.Type):
start = indices.pop(0) start = indices.pop(0)
elif isinstance(idx, (numpy.integer, integer_types)): elif isinstance(idx, (np.integer, integer_types)):
start = idx start = idx
else: else:
assert 0, idx assert 0, idx
...@@ -511,7 +511,7 @@ class GpuAdvancedSubtensor(HideC, tensor.AdvancedSubtensor): ...@@ -511,7 +511,7 @@ class GpuAdvancedSubtensor(HideC, tensor.AdvancedSubtensor):
# if there are more than one (narray > 1) it should be ignored. # if there are more than one (narray > 1) it should be ignored.
ap = 0 ap = 0
for k, i in enumerate(list(nidx)): for k, i in enumerate(list(nidx)):
if (isinstance(i, numpy.ndarray) and if (isinstance(i, np.ndarray) and
i.ndim != 0): i.ndim != 0):
transp.remove(k) transp.remove(k)
transp.insert(p, k) transp.insert(p, k)
...@@ -545,7 +545,7 @@ class GpuAdvancedSubtensor(HideC, tensor.AdvancedSubtensor): ...@@ -545,7 +545,7 @@ class GpuAdvancedSubtensor(HideC, tensor.AdvancedSubtensor):
x = x.__getitem__(idx_) x = x.__getitem__(idx_)
# flatten the array-indexed dimensions # flatten the array-indexed dimensions
shape = ((numpy.prod(x.shape[0: p]),) + shape = ((np.prod(x.shape[0: p]),) +
x.shape[p:]) x.shape[p:])
input_flat = x.reshape(shape) input_flat = x.reshape(shape)
...@@ -644,7 +644,7 @@ class GpuAdvancedIncSubtensor1(Op): ...@@ -644,7 +644,7 @@ class GpuAdvancedIncSubtensor1(Op):
# content to index x and y (This is because we serve as # content to index x and y (This is because we serve as
# fallback for _dev20). # fallback for _dev20).
if isinstance(idx, gpuarray.GpuArray): if isinstance(idx, gpuarray.GpuArray):
idx = numpy.asarray(idx) idx = np.asarray(idx)
# If `y` has as many dimensions as `x`, then we want to iterate # If `y` has as many dimensions as `x`, then we want to iterate
# jointly on `x` and `y`. Otherwise, it means `y` should be # jointly on `x` and `y`. Otherwise, it means `y` should be
...@@ -877,10 +877,10 @@ if (GpuArray_vector_add_fast(%(out)s, %(y)s, %(ind)s, %(set_instead_of_inc)s)) { ...@@ -877,10 +877,10 @@ if (GpuArray_vector_add_fast(%(out)s, %(y)s, %(ind)s, %(set_instead_of_inc)s)) {
dtype_y = node.inputs[1].dtype dtype_y = node.inputs[1].dtype
dtype_ind = node.inputs[2].dtype dtype_ind = node.inputs[2].dtype
dtype_out = node.outputs[0].dtype dtype_out = node.outputs[0].dtype
itemsize_x = numpy.dtype(dtype_x).itemsize itemsize_x = np.dtype(dtype_x).itemsize
itemsize_y = numpy.dtype(dtype_y).itemsize itemsize_y = np.dtype(dtype_y).itemsize
itemsize_ind = numpy.dtype(dtype_ind).itemsize itemsize_ind = np.dtype(dtype_ind).itemsize
itemsize_out = numpy.dtype(dtype_out).itemsize itemsize_out = np.dtype(dtype_out).itemsize
flags = Kernel.get_flags(dtype_x, dtype_y, dtype_ind) flags = Kernel.get_flags(dtype_x, dtype_y, dtype_ind)
type_x = gpuarray.dtype_to_ctype(dtype_x) type_x = gpuarray.dtype_to_ctype(dtype_x)
type_y = gpuarray.dtype_to_ctype(dtype_y) type_y = gpuarray.dtype_to_ctype(dtype_y)
...@@ -1007,10 +1007,10 @@ __device__ ga_half atomicExch(ga_half *addr, ga_half val) { ...@@ -1007,10 +1007,10 @@ __device__ ga_half atomicExch(ga_half *addr, ga_half val) {
dtype_y = node.inputs[1].dtype dtype_y = node.inputs[1].dtype
dtype_ind = node.inputs[2].dtype dtype_ind = node.inputs[2].dtype
dtype_out = node.outputs[0].dtype dtype_out = node.outputs[0].dtype
itemsize_x = numpy.dtype(dtype_x).itemsize itemsize_x = np.dtype(dtype_x).itemsize
itemsize_y = numpy.dtype(dtype_y).itemsize itemsize_y = np.dtype(dtype_y).itemsize
itemsize_ind = numpy.dtype(dtype_ind).itemsize itemsize_ind = np.dtype(dtype_ind).itemsize
itemsize_out = numpy.dtype(dtype_out).itemsize itemsize_out = np.dtype(dtype_out).itemsize
k_var = "k_vector_add_fast_" + nodename k_var = "k_vector_add_fast_" + nodename
return super(GpuAdvancedIncSubtensor1_dev20, self).c_support_code_struct(node, nodename) + """ return super(GpuAdvancedIncSubtensor1_dev20, self).c_support_code_struct(node, nodename) + """
...@@ -1112,7 +1112,7 @@ class GpuDiagonal(Subtensor): ...@@ -1112,7 +1112,7 @@ class GpuDiagonal(Subtensor):
if x.size == 0: if x.size == 0:
out_shape = [d for i, d in enumerate(x.shape) out_shape = [d for i, d in enumerate(x.shape)
if i not in (self.axis1, self.axis2)] if i not in (self.axis1, self.axis2)]
diag_size = numpy.min((x.shape[self.axis1], x.shape[self.axis2])) diag_size = np.min((x.shape[self.axis1], x.shape[self.axis2]))
out_shape.append(diag_size) out_shape.append(diag_size)
z[0] = node.outputs[0].type.value_zeros(tuple(out_shape)) z[0] = node.outputs[0].type.value_zeros(tuple(out_shape))
return return
...@@ -1128,15 +1128,15 @@ class GpuDiagonal(Subtensor): ...@@ -1128,15 +1128,15 @@ class GpuDiagonal(Subtensor):
if x.shape[stride_axis] < x.shape[slice_axis]: if x.shape[stride_axis] < x.shape[slice_axis]:
# in the bigger triangle # in the bigger triangle
numstride = small_axis - numpy.max(( numstride = small_axis - np.max((
0, small_axis + numpy.abs(self.offset) - large_axis)) 0, small_axis + np.abs(self.offset) - large_axis))
else: else:
# in the smaller triangle # in the smaller triangle
numstride = small_axis - numpy.abs(self.offset) numstride = small_axis - np.abs(self.offset)
slicer = [numpy.s_[:], ] * x.ndim slicer = [np.s_[:], ] * x.ndim
slicer[stride_axis] = numpy.s_[:numstride] slicer[stride_axis] = np.s_[:numstride]
slicer[slice_axis] = numpy.abs(self.offset) slicer[slice_axis] = np.abs(self.offset)
slicer = tuple(slicer) slicer = tuple(slicer)
# step 2) Swap stride_axis to the last dim because we want the dim on # step 2) Swap stride_axis to the last dim because we want the dim on
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论