提交 f42f2163 authored 作者: Brandon T. Willard's avatar Brandon T. Willard

Replace theano.tensor alias T with tt in theano.gpuarray

上级 43ab4ff0
import os
import sys
import theano
import theano.tensor as tt
import theano.tensor.nnet.ctc
from theano import config, gof
import theano.tensor as T
from .basic_ops import (
from theano.gpuarray.basic_ops import (
gpu_contiguous,
as_gpuarray_variable,
infer_context_name,
gpuarray_helper_inc_dir,
)
import theano.tensor.nnet.ctc
from .type import GpuArrayType, gpu_context_type
from .elemwise import GpuDimShuffle
from theano.gpuarray.type import GpuArrayType, gpu_context_type
from theano.gpuarray.elemwise import GpuDimShuffle
from theano.gradient import grad_undefined
from theano.gof import local_optimizer
from theano.tensor.opt import register_canonicalize
from theano.tensor.nnet.ctc import ctc_available
import os
import sys
from . import pygpu
from theano.gpuarray import pygpu
class GpuConnectionistTemporalClassification(gof.COp):
......@@ -104,8 +106,8 @@ class GpuConnectionistTemporalClassification(gof.COp):
t_activations = gpu_contiguous(t_activations)
# Labels and input lengths are always on the CPU
t_labels = T.as_tensor_variable(labels)
t_input_lengths = T.as_tensor_variable(input_lengths)
t_labels = tt.as_tensor_variable(labels)
t_input_lengths = tt.as_tensor_variable(input_lengths)
if t_activations.type.dtype != "float32":
raise TypeError("activations must use the float32 type.")
......@@ -162,7 +164,7 @@ class GpuConnectionistTemporalClassification(gof.COp):
),
new_order=(1, 0, 2),
)(gradients)
grad_bdot = T.basic.batched_dot(grad_op, grad_shuffle)
grad_bdot = tt.batched_dot(grad_op, grad_shuffle)
grad_shuffle_reverse = GpuDimShuffle(
input_broadcastable=(
False,
......
import numpy as np
import theano
import theano.tensor as tt
from theano import Op
import theano.tensor as T
from theano.gradient import DisconnectedType
from theano.gpuarray.basic_ops import (
gpu_contiguous,
as_gpuarray_variable,
infer_context_name,
)
from theano.gpuarray.type import GpuArrayType
from .basic_ops import gpu_contiguous, as_gpuarray_variable, infer_context_name
from .type import GpuArrayType
import theano.tensor.fft
from .opt import register_opt, op_lifter, register_opt2
from theano.tensor.fft import IRFFTOp
from theano.gpuarray.opt import register_opt, op_lifter, register_opt2
try:
import pygpu
......@@ -67,11 +72,11 @@ class CuRFFTOp(Op):
# If no shape is provided as input, default to input data shape.
if s is None:
s = inp.shape[1:]
s = T.as_tensor_variable(s)
s = tt.as_tensor_variable(s)
assert inp.dtype == "float32"
assert s.ndim == 1
assert s.dtype in theano.tensor.integer_dtypes
assert s.dtype in tt.integer_dtypes
return theano.Apply(self, [inp, s], [self.output_type(inp)()])
......@@ -153,7 +158,7 @@ class CuRFFTOp(Op):
+ [slice(1, (s[-1] // 2) + (s[-1] % 2))]
+ [slice(None)]
)
gout = T.set_subtensor(gout[idx], gout[idx] * 0.5)
gout = tt.set_subtensor(gout[idx], gout[idx] * 0.5)
return [cuirfft_op(gout, s), DisconnectedType()()]
def connection_pattern(self, node):
......@@ -198,8 +203,8 @@ class CuIRFFTOp(Op):
# If no shape is provided as input, calculate shape assuming even real transform.
if s is None:
s = inp.shape[1:-1]
s = T.set_subtensor(s[-1], (s[-1] - 1) * 2)
s = T.as_tensor_variable(s)
s = tt.set_subtensor(s[-1], (s[-1] - 1) * 2)
s = tt.as_tensor_variable(s)
assert inp.dtype == "float32"
assert s.ndim == 1
......@@ -285,7 +290,7 @@ class CuIRFFTOp(Op):
+ [slice(1, (s[-1] // 2) + (s[-1] % 2))]
+ [slice(None)]
)
gf = T.set_subtensor(gf[idx], gf[idx] * 2)
gf = tt.set_subtensor(gf[idx], gf[idx] * 2)
return [gf, DisconnectedType()()]
def connection_pattern(self, node):
......@@ -325,7 +330,7 @@ def curfft(inp, norm=None):
cond_norm = _unitary(norm)
scaling = 1
if cond_norm == "ortho":
scaling = T.sqrt(s.prod().astype("float32"))
scaling = tt.sqrt(s.prod().astype("float32"))
return curfft_op(inp, s) / scaling
......@@ -364,16 +369,16 @@ def cuirfft(inp, norm=None, is_odd=False):
s = inp.shape[1:-1]
if is_odd:
s = T.set_subtensor(s[-1], (s[-1] - 1) * 2 + 1)
s = tt.set_subtensor(s[-1], (s[-1] - 1) * 2 + 1)
else:
s = T.set_subtensor(s[-1], (s[-1] - 1) * 2)
s = tt.set_subtensor(s[-1], (s[-1] - 1) * 2)
cond_norm = _unitary(norm)
scaling = 1
if cond_norm is None:
scaling = s.prod().astype("float32")
elif cond_norm == "ortho":
scaling = T.sqrt(s.prod().astype("float32"))
scaling = tt.sqrt(s.prod().astype("float32"))
return cuirfft_op(inp, s) / scaling
......@@ -389,13 +394,13 @@ def _unitary(norm):
if skcuda_available:
@register_opt("fast_compile")
@op_lifter([theano.tensor.fft.RFFTOp])
@register_opt2([theano.tensor.fft.RFFTOp], "fast_compile")
@op_lifter([IRFFTOp])
@register_opt2([IRFFTOp], "fast_compile")
def local_gpua_curfft_op(op, ctx_name, inputs, outputs):
return curfft_op
@register_opt("fast_compile")
@op_lifter([theano.tensor.fft.IRFFTOp])
@register_opt2([theano.tensor.fft.IRFFTOp], "fast_compile")
@op_lifter([IRFFTOp])
@register_opt2([IRFFTOp], "fast_compile")
def local_gpua_cuirfft_op(op, ctx_name, inputs, outputs):
return cuirfft_op
import theano.tensor as tt
from theano import Op, Apply
from theano.gof import ParamsType
from theano.tensor.nnet.neighbours import Images2Neibs
import theano.tensor as T
try:
from pygpu import gpuarray
except ImportError:
pass
from .basic_ops import as_gpuarray_variable, GpuKernelBase, Kernel, infer_context_name
from .type import GpuArrayType, gpu_context_type
from theano.gpuarray.basic_ops import (
as_gpuarray_variable,
GpuKernelBase,
Kernel,
infer_context_name,
)
from theano.gpuarray.type import GpuArrayType, gpu_context_type
class GpuImages2Neibs(GpuKernelBase, Images2Neibs, Op):
......@@ -25,17 +31,17 @@ class GpuImages2Neibs(GpuKernelBase, Images2Neibs, Op):
def make_node(self, ten4, neib_shape, neib_step=None):
ten4 = as_gpuarray_variable(ten4, infer_context_name(ten4))
neib_shape = T.as_tensor_variable(neib_shape)
neib_shape = tt.as_tensor_variable(neib_shape)
if neib_step is None:
neib_step = neib_shape
else:
neib_step = T.as_tensor_variable(neib_step)
neib_step = tt.as_tensor_variable(neib_step)
assert ten4.ndim == 4
assert neib_shape.ndim == 1
assert neib_step.ndim == 1
assert neib_shape.dtype in T.integer_dtypes
assert neib_step.dtype in T.integer_dtypes
assert neib_shape.dtype in tt.integer_dtypes
assert neib_step.dtype in tt.integer_dtypes
return Apply(
self,
......
import numpy as np
import theano.tensor as T
import theano.tensor as tt
from six import integer_types
from six.moves import StringIO
from theano import tensor, gof, Op
from theano import gof, Op
from theano.gof import ParamsType
from theano.gradient import grad_not_implemented
from theano.tensor.subtensor import IncSubtensor, Subtensor, get_idx_list
from theano.tensor import AllocDiag
from theano.tensor.subtensor import (
IncSubtensor,
AdvancedSubtensor,
Subtensor,
AdvancedIncSubtensor,
AdvancedSubtensor1,
get_idx_list,
)
from theano.scalar import bool as bool_t, int32 as int_t, uint32 as size_t
try:
......@@ -17,8 +25,8 @@ try:
except ImportError:
pass
from .type import GpuArrayType, gpu_context_type
from .basic_ops import (
from theano.gpuarray.type import GpuArrayType, gpu_context_type
from theano.gpuarray.basic_ops import (
as_gpuarray_variable,
HideC,
GpuKernelBase,
......@@ -52,7 +60,7 @@ class GpuSubtensor(HideC, Subtensor):
def make_node(self, x, *inputs):
ctx_name = infer_context_name(x)
rval = tensor.Subtensor.make_node(self, x, *inputs)
rval = Subtensor.make_node(self, x, *inputs)
otype = GpuArrayType(
dtype=rval.outputs[0].type.dtype,
broadcastable=rval.outputs[0].type.broadcastable,
......@@ -226,7 +234,7 @@ class GpuIncSubtensor(IncSubtensor):
-----
The optimization to make this inplace is in tensor/opt.
The same optimization handles IncSubtensor and GpuIncSubtensor.
This Op has c_code too; it inherits tensor.IncSubtensor's c_code.
This Op has c_code too; it inherits IncSubtensor's c_code.
The helper methods like :meth:`do_type_checking`,
:meth:`copy_of_x`, etc. specialize the c_code for this Op.
......@@ -239,7 +247,7 @@ class GpuIncSubtensor(IncSubtensor):
ctx_name = infer_context_name(x, y)
x = as_gpuarray_variable(x, ctx_name)
y = as_gpuarray_variable(y, ctx_name)
rval = tensor.IncSubtensor.make_node(self, x, y, *inputs)
rval = IncSubtensor.make_node(self, x, y, *inputs)
ret = gof.Apply(self, [x, y] + rval.inputs[2:], [x.type()])
return ret
......@@ -450,7 +458,7 @@ int sub_setarray(GpuArray *dst, GpuArray *src) {
return parent_version + (10,)
class GpuAdvancedSubtensor1(HideC, tensor.AdvancedSubtensor1):
class GpuAdvancedSubtensor1(HideC, AdvancedSubtensor1):
"""
AdvancedSubrensor1 on the GPU.
"""
......@@ -461,11 +469,11 @@ class GpuAdvancedSubtensor1(HideC, tensor.AdvancedSubtensor1):
ctx_name = infer_context_name(x, ilist)
x_ = as_gpuarray_variable(x, ctx_name)
ilist__ = tensor.as_tensor_variable(ilist)
if ilist__.type.dtype not in tensor.integer_dtypes:
ilist__ = tt.as_tensor_variable(ilist)
if ilist__.type.dtype not in tt.integer_dtypes:
raise TypeError("index must be integers")
if ilist__.type.dtype != "int64":
ilist__ = tensor.cast(ilist__, "int64")
ilist__ = tt.cast(ilist__, "int64")
ilist_ = gpu_contiguous(as_gpuarray_variable(ilist__, ctx_name))
......@@ -676,14 +684,14 @@ class BaseGpuAdvancedSubtensor(object):
out[0] = o
class GpuAdvancedSubtensor(HideC, BaseGpuAdvancedSubtensor, tensor.AdvancedSubtensor):
class GpuAdvancedSubtensor(HideC, BaseGpuAdvancedSubtensor, AdvancedSubtensor):
"""
AdvancedSubtensor on the GPU.
"""
def make_node(self, x, *inputs):
ctx_name = infer_context_name(x)
rval = tensor.AdvancedSubtensor.make_node(self, x, *inputs)
rval = AdvancedSubtensor.make_node(self, x, *inputs)
otype = GpuArrayType(
dtype=rval.outputs[0].type.dtype,
broadcastable=rval.outputs[0].type.broadcastable,
......@@ -809,9 +817,7 @@ class BaseGpuAdvancedIncSubtensor(object):
out[0] = x_
class GpuAdvancedIncSubtensor(
HideC, BaseGpuAdvancedIncSubtensor, tensor.AdvancedIncSubtensor
):
class GpuAdvancedIncSubtensor(HideC, BaseGpuAdvancedIncSubtensor, AdvancedIncSubtensor):
"""
Implement AdvancedIncSubtensor on the gpu.
......@@ -819,7 +825,7 @@ class GpuAdvancedIncSubtensor(
def make_node(self, x, y, *inputs):
ctx_name = infer_context_name(x, y)
rval = tensor.AdvancedIncSubtensor.make_node(self, x, y, *inputs)
rval = AdvancedIncSubtensor.make_node(self, x, y, *inputs)
otype = GpuArrayType(
dtype=rval.outputs[0].type.dtype,
broadcastable=rval.outputs[0].type.broadcastable,
......@@ -863,11 +869,11 @@ class GpuAdvancedIncSubtensor1(Op):
ctx_name = infer_context_name(x, y)
x_ = as_gpuarray_variable(x, ctx_name)
y_ = as_gpuarray_variable(y, ctx_name)
ilist_ = tensor.as_tensor_variable(ilist)
ilist_ = tt.as_tensor_variable(ilist)
assert x_.type.ndim >= y_.type.ndim
if ilist_.type.dtype not in tensor.integer_dtypes:
if ilist_.type.dtype not in tt.integer_dtypes:
raise TypeError("index must be integers")
if ilist_.type.ndim != 1:
raise TypeError("index must be vector")
......@@ -1106,7 +1112,7 @@ class GpuAdvancedIncSubtensor1_dev20(GpuKernelBase, HideC, GpuAdvancedIncSubtens
assert x_.type.ndim >= y_.type.ndim
if ilist_.type.dtype not in tensor.integer_dtypes:
if ilist_.type.dtype not in tt.integer_dtypes:
raise TypeError("index must be integers")
if ilist_.type.ndim != 1:
raise TypeError("index must be vector")
......@@ -1437,11 +1443,11 @@ class GpuExtractDiag(Op):
# The following logic is inspired by C code of PyArray_Diagonal().
offset = self.offset
if offset > 0:
diag_size = T.clip(dim2 - offset, 0, dim1)
diag_size = tt.clip(dim2 - offset, 0, dim1)
elif offset < 0:
diag_size = T.clip(dim1 + offset, 0, dim2)
diag_size = tt.clip(dim1 + offset, 0, dim2)
else:
diag_size = T.minimum(dim1, dim2)
diag_size = tt.minimum(dim1, dim2)
out_shape.append(diag_size)
return [tuple(out_shape)]
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论