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

Replace theano.tensor alias T with tt in tests.compile

上级 33667eb7
...@@ -3,13 +3,14 @@ import numpy as np ...@@ -3,13 +3,14 @@ import numpy as np
import pytest import pytest
import theano import theano
import theano.tensor as tt
from theano import config, shared from theano import config, shared
from theano.gradient import DisconnectedType from theano.gradient import DisconnectedType
from theano.gof.null_type import NullType from theano.gof.null_type import NullType
from theano.compile import function from theano.compile import function
from theano import tensor as T
from theano.tensor.shared_randomstreams import RandomStreams from theano.tensor.shared_randomstreams import RandomStreams
from theano.compile.builders import OpFromGraph from theano.compile.builders import OpFromGraph
...@@ -22,7 +23,7 @@ class TestOpFromGraph(unittest_tools.InferShapeTester): ...@@ -22,7 +23,7 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
"cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)] "cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)]
) )
def test_straightforward(self, cls_ofg): def test_straightforward(self, cls_ofg):
x, y, z = T.matrices("xyz") x, y, z = tt.matrices("xyz")
e = x + y * z e = x + y * z
op = cls_ofg([x, y, z], [e]) op = cls_ofg([x, y, z], [e])
# (1+3*5=array of 16) - (3+1*5=array of 8) # (1+3*5=array of 16) - (3+1*5=array of 8)
...@@ -42,8 +43,8 @@ class TestOpFromGraph(unittest_tools.InferShapeTester): ...@@ -42,8 +43,8 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
"cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)] "cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)]
) )
def test_size_changes(self, cls_ofg): def test_size_changes(self, cls_ofg):
x, y, z = T.matrices("xyz") x, y, z = tt.matrices("xyz")
e = T.dot(x, y) e = tt.dot(x, y)
op = cls_ofg([x, y], [e]) op = cls_ofg([x, y], [e])
f = op(x, op(y, z)) f = op(x, op(y, z))
fn = function([x, y, z], f) fn = function([x, y, z], f)
...@@ -61,11 +62,11 @@ class TestOpFromGraph(unittest_tools.InferShapeTester): ...@@ -61,11 +62,11 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
"cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)] "cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)]
) )
def test_grad(self, cls_ofg): def test_grad(self, cls_ofg):
x, y, z = T.matrices("xyz") x, y, z = tt.matrices("xyz")
e = x + y * z e = x + y * z
op = cls_ofg([x, y, z], [e]) op = cls_ofg([x, y, z], [e])
f = op(x, y, z) f = op(x, y, z)
f = f - T.grad(T.sum(f), y) f = f - tt.grad(tt.sum(f), y)
fn = function([x, y, z], f) fn = function([x, y, z], f)
xv = np.ones((2, 2), dtype=config.floatX) xv = np.ones((2, 2), dtype=config.floatX)
yv = np.ones((2, 2), dtype=config.floatX) * 3 yv = np.ones((2, 2), dtype=config.floatX) * 3
...@@ -76,12 +77,12 @@ class TestOpFromGraph(unittest_tools.InferShapeTester): ...@@ -76,12 +77,12 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
"cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)] "cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)]
) )
def test_grad_grad(self, cls_ofg): def test_grad_grad(self, cls_ofg):
x, y, z = T.matrices("xyz") x, y, z = tt.matrices("xyz")
e = x + y * z e = x + y * z
op = cls_ofg([x, y, z], [e]) op = cls_ofg([x, y, z], [e])
f = op(x, y, z) f = op(x, y, z)
f = f - T.grad(T.sum(f), y) f = f - tt.grad(tt.sum(f), y)
f = f - T.grad(T.sum(f), y) f = f - tt.grad(tt.sum(f), y)
fn = function([x, y, z], f) fn = function([x, y, z], f)
xv = np.ones((2, 2), dtype=config.floatX) xv = np.ones((2, 2), dtype=config.floatX)
yv = np.ones((2, 2), dtype=config.floatX) * 3 yv = np.ones((2, 2), dtype=config.floatX) * 3
...@@ -92,7 +93,7 @@ class TestOpFromGraph(unittest_tools.InferShapeTester): ...@@ -92,7 +93,7 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
"cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)] "cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)]
) )
def test_shared(self, cls_ofg): def test_shared(self, cls_ofg):
x, y, z = T.matrices("xyz") x, y, z = tt.matrices("xyz")
s = shared(np.random.rand(2, 2).astype(config.floatX)) s = shared(np.random.rand(2, 2).astype(config.floatX))
e = x + y * z + s e = x + y * z + s
op = cls_ofg([x, y, z], [e]) op = cls_ofg([x, y, z], [e])
...@@ -112,12 +113,12 @@ class TestOpFromGraph(unittest_tools.InferShapeTester): ...@@ -112,12 +113,12 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
"cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)] "cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)]
) )
def test_shared_grad(self, cls_ofg): def test_shared_grad(self, cls_ofg):
x, y, z = T.matrices("xyz") x, y, z = tt.matrices("xyz")
s = shared(np.random.rand(2, 2).astype(config.floatX)) s = shared(np.random.rand(2, 2).astype(config.floatX))
e = x + y * z + s e = x + y * z + s
op = cls_ofg([x, y, z], [e]) op = cls_ofg([x, y, z], [e])
f = op(x, y, z) f = op(x, y, z)
f = f - T.grad(T.sum(f), y) f = f - tt.grad(tt.sum(f), y)
fn = function([x, y, z], f) fn = function([x, y, z], f)
xv = np.ones((2, 2), dtype=config.floatX) xv = np.ones((2, 2), dtype=config.floatX)
yv = np.ones((2, 2), dtype=config.floatX) * 3 yv = np.ones((2, 2), dtype=config.floatX) * 3
...@@ -126,7 +127,7 @@ class TestOpFromGraph(unittest_tools.InferShapeTester): ...@@ -126,7 +127,7 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
# grad again the shared variable # grad again the shared variable
f = op(x, y, z) f = op(x, y, z)
f = f - T.grad(T.sum(f), s) f = f - tt.grad(tt.sum(f), s)
fn = function([x, y, z], f) fn = function([x, y, z], f)
assert np.allclose(15.0 + s.get_value(), fn(xv, yv, zv)) assert np.allclose(15.0 + s.get_value(), fn(xv, yv, zv))
...@@ -134,24 +135,24 @@ class TestOpFromGraph(unittest_tools.InferShapeTester): ...@@ -134,24 +135,24 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
"cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)] "cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)]
) )
def test_grad_override(self, cls_ofg): def test_grad_override(self, cls_ofg):
x, y = T.vectors("xy") x, y = tt.vectors("xy")
def go(inps, gs): def go(inps, gs):
x, y = inps x, y = inps
(g,) = gs (g,) = gs
return [g * y * 2, g * x * 1.5] return [g * y * 2, g * x * 1.5]
dedz = T.vector("dedz") dedz = tt.vector("dedz")
op_mul_grad = cls_ofg([x, y, dedz], go([x, y], [dedz])) op_mul_grad = cls_ofg([x, y, dedz], go([x, y], [dedz]))
op_mul = cls_ofg([x, y], [x * y], grad_overrides=go) op_mul = cls_ofg([x, y], [x * y], grad_overrides=go)
op_mul2 = cls_ofg([x, y], [x * y], grad_overrides=op_mul_grad) op_mul2 = cls_ofg([x, y], [x * y], grad_overrides=op_mul_grad)
# single override case (function or OfG instance) # single override case (function or OfG instance)
xx, yy = T.vector("xx"), T.vector("yy") xx, yy = tt.vector("xx"), tt.vector("yy")
for op in [op_mul, op_mul2]: for op in [op_mul, op_mul2]:
zz = T.sum(op(xx, yy)) zz = tt.sum(op(xx, yy))
dx, dy = T.grad(zz, [xx, yy]) dx, dy = tt.grad(zz, [xx, yy])
fn = function([xx, yy], [dx, dy]) fn = function([xx, yy], [dx, dy])
xv = np.random.rand(16).astype(config.floatX) xv = np.random.rand(16).astype(config.floatX)
yv = np.random.rand(16).astype(config.floatX) yv = np.random.rand(16).astype(config.floatX)
...@@ -170,14 +171,14 @@ class TestOpFromGraph(unittest_tools.InferShapeTester): ...@@ -170,14 +171,14 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
g = gs[0] g = gs[0]
return g * x * 1.5 return g * x * 1.5
w, b = T.vectors("wb") w, b = tt.vectors("wb")
# we make the 3rd gradient default (no override) # we make the 3rd gradient default (no override)
op_linear = cls_ofg( op_linear = cls_ofg(
[x, w, b], [x * w + b], grad_overrides=[go1, go2, "default"] [x, w, b], [x * w + b], grad_overrides=[go1, go2, "default"]
) )
xx, ww, bb = T.vector("xx"), T.vector("yy"), T.vector("bb") xx, ww, bb = tt.vector("xx"), tt.vector("yy"), tt.vector("bb")
zz = T.sum(op_linear(xx, ww, bb)) zz = tt.sum(op_linear(xx, ww, bb))
dx, dw, db = T.grad(zz, [xx, ww, bb]) dx, dw, db = tt.grad(zz, [xx, ww, bb])
fn = function([xx, ww, bb], [dx, dw, db]) fn = function([xx, ww, bb], [dx, dw, db])
xv = np.random.rand(16).astype(config.floatX) xv = np.random.rand(16).astype(config.floatX)
wv = np.random.rand(16).astype(config.floatX) wv = np.random.rand(16).astype(config.floatX)
...@@ -193,15 +194,15 @@ class TestOpFromGraph(unittest_tools.InferShapeTester): ...@@ -193,15 +194,15 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
[x * w + b], [x * w + b],
grad_overrides=[go1, NullType()(), DisconnectedType()()], grad_overrides=[go1, NullType()(), DisconnectedType()()],
) )
zz2 = T.sum(op_linear2(xx, ww, bb)) zz2 = tt.sum(op_linear2(xx, ww, bb))
dx2, dw2, db2 = T.grad( dx2, dw2, db2 = tt.grad(
zz2, zz2,
[xx, ww, bb], [xx, ww, bb],
return_disconnected="Disconnected", return_disconnected="Disconnected",
disconnected_inputs="ignore", disconnected_inputs="ignore",
null_gradients="return", null_gradients="return",
) )
assert isinstance(dx2.type, T.TensorType) assert isinstance(dx2.type, tt.TensorType)
assert dx2.ndim == 1 assert dx2.ndim == 1
assert isinstance(dw2.type, NullType) assert isinstance(dw2.type, NullType)
assert isinstance(db2.type, DisconnectedType) assert isinstance(db2.type, DisconnectedType)
...@@ -210,25 +211,25 @@ class TestOpFromGraph(unittest_tools.InferShapeTester): ...@@ -210,25 +211,25 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
"cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)] "cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)]
) )
def test_lop_override(self, cls_ofg): def test_lop_override(self, cls_ofg):
x = T.vector() x = tt.vector()
y = 1.0 / (1.0 + T.exp(-x)) y = 1.0 / (1.0 + tt.exp(-x))
def lop_ov(inps, outs, grads): def lop_ov(inps, outs, grads):
(y_,) = outs (y_,) = outs
(dedy_,) = grads (dedy_,) = grads
return [2.0 * y_ * (1.0 - y_) * dedy_] return [2.0 * y_ * (1.0 - y_) * dedy_]
y_, dedy = T.vector(), T.vector() y_, dedy = tt.vector(), tt.vector()
op_lop_ov = cls_ofg([x, y_, dedy], [2.0 * y_ * (1.0 - y_) * dedy]) op_lop_ov = cls_ofg([x, y_, dedy], [2.0 * y_ * (1.0 - y_) * dedy])
xx = T.vector() xx = tt.vector()
yy1 = T.sum(T.nnet.sigmoid(xx)) yy1 = tt.sum(tt.nnet.sigmoid(xx))
gyy1 = 2.0 * T.grad(yy1, xx) gyy1 = 2.0 * tt.grad(yy1, xx)
for ov in [lop_ov, op_lop_ov]: for ov in [lop_ov, op_lop_ov]:
op = cls_ofg([x], [y], lop_overrides=ov) op = cls_ofg([x], [y], lop_overrides=ov)
yy2 = T.sum(op(xx)) yy2 = tt.sum(op(xx))
gyy2 = T.grad(yy2, xx) gyy2 = tt.grad(yy2, xx)
fn = function([xx], [gyy1, gyy2]) fn = function([xx], [gyy1, gyy2])
xval = np.random.rand(32).astype(config.floatX) xval = np.random.rand(32).astype(config.floatX)
...@@ -239,15 +240,15 @@ class TestOpFromGraph(unittest_tools.InferShapeTester): ...@@ -239,15 +240,15 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
"cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)] "cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)]
) )
def test_rop(self, cls_ofg): def test_rop(self, cls_ofg):
a = T.vector() a = tt.vector()
M = T.matrix() M = tt.matrix()
b = T.dot(a, M) b = tt.dot(a, M)
op_matmul = cls_ofg([a, M], [b]) op_matmul = cls_ofg([a, M], [b])
x = T.vector() x = tt.vector()
W = T.matrix() W = tt.matrix()
y = op_matmul(x, W) y = op_matmul(x, W)
du = T.vector() du = tt.vector()
dv = T.Rop(y, x, du) dv = tt.Rop(y, x, du)
fn = function([x, W, du], dv) fn = function([x, W, du], dv)
xval = np.random.rand(16).astype(config.floatX) xval = np.random.rand(16).astype(config.floatX)
Wval = np.random.rand(16, 16).astype(config.floatX) Wval = np.random.rand(16, 16).astype(config.floatX)
...@@ -260,24 +261,24 @@ class TestOpFromGraph(unittest_tools.InferShapeTester): ...@@ -260,24 +261,24 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
"cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)] "cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)]
) )
def test_rop_override(self, cls_ofg): def test_rop_override(self, cls_ofg):
x, y = T.vectors("xy") x, y = tt.vectors("xy")
def ro(inps, epts): def ro(inps, epts):
x, y = inps x, y = inps
u, v = epts u, v = epts
return [u * y * 2.0 + x * v * 1.5] return [u * y * 2.0 + x * v * 1.5]
u, v = T.vectors("uv") u, v = tt.vectors("uv")
op_mul_rop = cls_ofg([x, y, u, v], ro([x, y], [u, v])) op_mul_rop = cls_ofg([x, y, u, v], ro([x, y], [u, v]))
op_mul = cls_ofg([x, y], [x * y], rop_overrides=ro) op_mul = cls_ofg([x, y], [x * y], rop_overrides=ro)
op_mul2 = cls_ofg([x, y], [x * y], rop_overrides=op_mul_rop) op_mul2 = cls_ofg([x, y], [x * y], rop_overrides=op_mul_rop)
# single override case # single override case
xx, yy = T.vector("xx"), T.vector("yy") xx, yy = tt.vector("xx"), tt.vector("yy")
du, dv = T.vector("du"), T.vector("dv") du, dv = tt.vector("du"), tt.vector("dv")
for op in [op_mul, op_mul2]: for op in [op_mul, op_mul2]:
zz = op_mul(xx, yy) zz = op_mul(xx, yy)
dw = T.Rop(zz, [xx, yy], [du, dv]) dw = tt.Rop(zz, [xx, yy], [du, dv])
fn = function([xx, yy, du, dv], dw) fn = function([xx, yy, du, dv], dw)
vals = np.random.rand(4, 32).astype(config.floatX) vals = np.random.rand(4, 32).astype(config.floatX)
dwval = fn(*vals) dwval = fn(*vals)
...@@ -289,13 +290,13 @@ class TestOpFromGraph(unittest_tools.InferShapeTester): ...@@ -289,13 +290,13 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
"cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)] "cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)]
) )
def test_connection_pattern_override(self, cls_ofg): def test_connection_pattern_override(self, cls_ofg):
x, y = T.vectors("xy") x, y = tt.vectors("xy")
def f1(x, y): def f1(x, y):
del x del x
# but we know how to backpropagate for x for some reasons # but we know how to backpropagate for x for some reasons
# and we don't care about the gradient wrt y. # and we don't care about the gradient wrt y.
return y + T.round(y) return y + tt.round(y)
def f1_back(inputs, output_gradients): def f1_back(inputs, output_gradients):
return [output_gradients[0], theano.gradient.disconnected_type()] return [output_gradients[0], theano.gradient.disconnected_type()]
...@@ -321,12 +322,12 @@ class TestOpFromGraph(unittest_tools.InferShapeTester): ...@@ -321,12 +322,12 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
"cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)] "cls_ofg", [OpFromGraph, partial(OpFromGraph, inline=True)]
) )
def test_nested(self, cls_ofg): def test_nested(self, cls_ofg):
x, y = T.vectors("xy") x, y = tt.vectors("xy")
u, v = x + y, x - y u, v = x + y, x - y
op_ft = cls_ofg([x, y], [u, v]) op_ft = cls_ofg([x, y], [u, v])
op_ift = cls_ofg([x, y], [u / 2, v / 2]) op_ift = cls_ofg([x, y], [u / 2, v / 2])
xx, yy = T.vector("xx"), T.vector("yy") xx, yy = tt.vector("xx"), tt.vector("yy")
xx2, yy2 = op_ift(*op_ft(xx, yy)) xx2, yy2 = op_ift(*op_ft(xx, yy))
fn = function([xx, yy], [xx2, yy2]) fn = function([xx, yy], [xx2, yy2])
...@@ -341,7 +342,7 @@ class TestOpFromGraph(unittest_tools.InferShapeTester): ...@@ -341,7 +342,7 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
) )
def test_connection_pattern(self, cls_ofg): def test_connection_pattern(self, cls_ofg):
# Basic case # Basic case
x, y, z = T.matrices("xyz") x, y, z = tt.matrices("xyz")
out1 = x * y out1 = x * y
out2 = y * z out2 = y * z
...@@ -352,7 +353,7 @@ class TestOpFromGraph(unittest_tools.InferShapeTester): ...@@ -352,7 +353,7 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
# Graph with ops that don't have a 'full' connection pattern # Graph with ops that don't have a 'full' connection pattern
# and with ops that have multiple outputs # and with ops that have multiple outputs
m, n, p, q = T.matrices("mnpq") m, n, p, q = tt.matrices("mnpq")
o1, o2 = op1(m, n, p) o1, o2 = op1(m, n, p)
out1, out2 = op1(o1, q, o2) out1, out2 = op1(o1, q, o2)
op2 = cls_ofg([m, n, p, q], [out1, out2]) op2 = cls_ofg([m, n, p, q], [out1, out2])
...@@ -364,7 +365,7 @@ class TestOpFromGraph(unittest_tools.InferShapeTester): ...@@ -364,7 +365,7 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
# Inner graph where some computation doesn't rely on explicit inputs # Inner graph where some computation doesn't rely on explicit inputs
srng = RandomStreams(seed=234) srng = RandomStreams(seed=234)
rv_u = srng.uniform((2, 2)) rv_u = srng.uniform((2, 2))
x, y = T.matrices("xy") x, y = tt.matrices("xy")
out1 = x + rv_u out1 = x + rv_u
out2 = y + 3 out2 = y + 3
out3 = 3 + rv_u out3 = 3 + rv_u
...@@ -381,14 +382,14 @@ class TestOpFromGraph(unittest_tools.InferShapeTester): ...@@ -381,14 +382,14 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
def test_infer_shape(self): def test_infer_shape(self):
# test infer shape does not need to against inline case # test infer shape does not need to against inline case
# since the Op is remove during optimization phase # since the Op is remove during optimization phase
x = T.matrix("x") x = tt.matrix("x")
y = T.matrix("y") y = tt.matrix("y")
o1 = x + y o1 = x + y
o2 = x * y o2 = x * y
op_graph = OpFromGraph([x, y], [o1, o2]) op_graph = OpFromGraph([x, y], [o1, o2])
q = T.matrix("q") q = tt.matrix("q")
p = T.matrix("p") p = tt.matrix("p")
self._compile_and_check( self._compile_and_check(
[q, p], [q, p],
op_graph(q, p), op_graph(q, p),
...@@ -401,11 +402,11 @@ class TestOpFromGraph(unittest_tools.InferShapeTester): ...@@ -401,11 +402,11 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
@theano.change_flags(compute_test_value="raise") @theano.change_flags(compute_test_value="raise")
def test_compute_test_value(self): def test_compute_test_value(self):
x = T.scalar("x") x = tt.scalar("x")
x.tag.test_value = np.array(1.0, dtype=config.floatX) x.tag.test_value = np.array(1.0, dtype=config.floatX)
op = OpFromGraph([x], [x ** 3]) op = OpFromGraph([x], [x ** 3])
y = T.scalar("y") y = tt.scalar("y")
y.tag.test_value = np.array(1.0, dtype=config.floatX) y.tag.test_value = np.array(1.0, dtype=config.floatX)
f = op(y) f = op(y)
grad_f = T.grad(f, y) grad_f = tt.grad(f, y)
assert grad_f.tag.test_value is not None assert grad_f.tag.test_value is not None
...@@ -5,9 +5,9 @@ import pytest ...@@ -5,9 +5,9 @@ import pytest
import time import time
import theano import theano
import theano.tensor as tt
import theano.gpuarray import theano.gpuarray
from theano import tensor as T
from theano import config, gof from theano import config, gof
from theano.compile.io import In, Out from theano.compile.io import In, Out
from theano.compile import function from theano.compile import function
...@@ -39,9 +39,9 @@ class TestFunction: ...@@ -39,9 +39,9 @@ class TestFunction:
def test_none(self): def test_none(self):
fn = function([], None) # ok fn = function([], None) # ok
rval = fn() rval = fn()
assert rval != [], ( assert (
"See #254: Using None as function output leads " "to [] return value" rval != []
) ), "See #254: Using None as function output leads to [] return value"
assert rval is None assert rval is None
def test_empty(self): def test_empty(self):
...@@ -49,83 +49,83 @@ class TestFunction: ...@@ -49,83 +49,83 @@ class TestFunction:
assert fn() == [] assert fn() == []
def test_extra_inputs(self): def test_extra_inputs(self):
x, s = T.scalars("xs") x, s = tt.scalars("xs")
fn = function([x], [x]) fn = function([x], [x])
with pytest.raises(TypeError): with pytest.raises(TypeError):
fn(1, 2) fn(1, 2)
def test_missing_inputs(self): def test_missing_inputs(self):
def fn(): def fn():
x, s = T.scalars("xs") x, s = tt.scalars("xs")
function([], [x]) function([], [x])
checkfor(self, fn, MissingInputError) checkfor(self, fn, MissingInputError)
def fn(): def fn():
x, s = T.scalars("xs") x, s = tt.scalars("xs")
# Ignore unused input s, as it hides the other error # Ignore unused input s, as it hides the other error
function([s], [x], on_unused_input="ignore") function([s], [x], on_unused_input="ignore")
checkfor(self, fn, MissingInputError) checkfor(self, fn, MissingInputError)
def fn(): def fn():
x, s = T.scalars("xs") x, s = tt.scalars("xs")
function([s], [x]) function([s], [x])
checkfor(self, fn, UnusedInputError) checkfor(self, fn, UnusedInputError)
def fn(): def fn():
x, s = T.scalars("xs") x, s = tt.scalars("xs")
# Ignore unused input s, as it hides the other error # Ignore unused input s, as it hides the other error
function([s], x, on_unused_input="ignore") function([s], x, on_unused_input="ignore")
checkfor(self, fn, MissingInputError) checkfor(self, fn, MissingInputError)
def fn(): def fn():
x, s = T.scalars("xs") x, s = tt.scalars("xs")
function([s], x) function([s], x)
checkfor(self, fn, UnusedInputError) checkfor(self, fn, UnusedInputError)
def fn(): def fn():
x, s = T.scalars("xs") x, s = tt.scalars("xs")
# Ignore unused input s, as it hides the other error # Ignore unused input s, as it hides the other error
function([s], Out(x), on_unused_input="ignore") function([s], Out(x), on_unused_input="ignore")
checkfor(self, fn, MissingInputError) checkfor(self, fn, MissingInputError)
def fn(): def fn():
x, s = T.scalars("xs") x, s = tt.scalars("xs")
function([s], Out(x)) function([s], Out(x))
checkfor(self, fn, UnusedInputError) checkfor(self, fn, UnusedInputError)
def fn(): def fn():
x, s = T.scalars("xs") x, s = tt.scalars("xs")
function([In(x, update=s + x)], x) function([In(x, update=s + x)], x)
checkfor(self, fn, MissingInputError) checkfor(self, fn, MissingInputError)
def fn(): def fn():
x, s = T.scalars("xs") x, s = tt.scalars("xs")
function([In(x, update=((s * s) + x))], x) function([In(x, update=((s * s) + x))], x)
checkfor(self, fn, MissingInputError) checkfor(self, fn, MissingInputError)
def test_input_anon_singleton(self): def test_input_anon_singleton(self):
x, s = T.scalars("xs") x, s = tt.scalars("xs")
fn = function([s, x], [x + s]) fn = function([s, x], [x + s])
assert fn(2, 3) == [5] assert fn(2, 3) == [5]
# no state # no state
assert fn(2, 3) == [5] assert fn(2, 3) == [5]
def test_input_anon_unpack(self): def test_input_anon_unpack(self):
x, s = T.scalars("xs") x, s = tt.scalars("xs")
fn = function([s, x], x + s) fn = function([s, x], x + s)
assert fn(2, 3) == 5 assert fn(2, 3) == 5
def test_naming_rule0(self): def test_naming_rule0(self):
x, s = T.scalars("xs") x, s = tt.scalars("xs")
f = function([x, s], x / s) f = function([x, s], x / s)
assert f(1, 2) == 0.5 assert f(1, 2) == 0.5
assert f(2, 1) == 2.0 assert f(2, 1) == 2.0
...@@ -143,8 +143,8 @@ class TestFunction: ...@@ -143,8 +143,8 @@ class TestFunction:
) # takes exactly 2 non-keyword arguments (0 given) ) # takes exactly 2 non-keyword arguments (0 given)
def test_naming_rule1(self): def test_naming_rule1(self):
a = T.scalar() # the a is for 'anonymous' (un-named). a = tt.scalar() # the a is for 'anonymous' (un-named).
x, s = T.scalars("xs") x, s = tt.scalars("xs")
f = function([a, s], a / s) f = function([a, s], a / s)
assert f(1, 2) == 0.5 assert f(1, 2) == 0.5
assert f(2, 1) == 2.0 assert f(2, 1) == 2.0
...@@ -157,8 +157,8 @@ class TestFunction: ...@@ -157,8 +157,8 @@ class TestFunction:
) # got unexpected keyword argument 'a' ) # got unexpected keyword argument 'a'
def test_naming_rule2(self): def test_naming_rule2(self):
a = T.scalar() # the a is for 'anonymous' (un-named). a = tt.scalar() # the a is for 'anonymous' (un-named).
x, s = T.scalars("xs") x, s = tt.scalars("xs")
# x's name is ignored because it is followed by anonymous parameter a. # x's name is ignored because it is followed by anonymous parameter a.
# Ignore unused input x, as it hides the other error # Ignore unused input x, as it hides the other error
...@@ -174,8 +174,8 @@ class TestFunction: ...@@ -174,8 +174,8 @@ class TestFunction:
) # got unexpected keyword argument 'x' ) # got unexpected keyword argument 'x'
def test_naming_rule3(self): def test_naming_rule3(self):
a = T.scalar() # the a is for 'anonymous' (un-named). a = tt.scalar() # the a is for 'anonymous' (un-named).
x, s = T.scalars("xs") x, s = tt.scalars("xs")
# x's name is not ignored (as in test_naming_rule2) because a has a default value. # x's name is not ignored (as in test_naming_rule2) because a has a default value.
f = function([x, In(a, value=1.0), s], a / s + x) f = function([x, In(a, value=1.0), s], a / s + x)
...@@ -194,8 +194,8 @@ class TestFunction: ...@@ -194,8 +194,8 @@ class TestFunction:
) # takes exactly 3 non-keyword arguments (1 given) ) # takes exactly 3 non-keyword arguments (1 given)
def test_naming_rule4(self): def test_naming_rule4(self):
a = T.scalar() # the a is for 'anonymous' (un-named). a = tt.scalar() # the a is for 'anonymous' (un-named).
x, s = T.scalars("xs") x, s = tt.scalars("xs")
f = function([x, In(a, value=1.0, name="a"), s], a / s + x) f = function([x, In(a, value=1.0, name="a"), s], a / s + x)
...@@ -213,8 +213,8 @@ class TestFunction: ...@@ -213,8 +213,8 @@ class TestFunction:
) # got multiple values for keyword argument 'x' ) # got multiple values for keyword argument 'x'
def test_state_access(self): def test_state_access(self):
a = T.scalar() # the a is for 'anonymous' (un-named). a = tt.scalar() # the a is for 'anonymous' (un-named).
x, s = T.scalars("xs") x, s = tt.scalars("xs")
f = function( f = function(
[x, In(a, value=1.0, name="a"), In(s, value=0.0, update=s + a * x)], [x, In(a, value=1.0, name="a"), In(s, value=0.0, update=s + a * x)],
...@@ -238,14 +238,14 @@ class TestFunction: ...@@ -238,14 +238,14 @@ class TestFunction:
assert f[s] == 24.0 assert f[s] == 24.0
def test_same_names(self): def test_same_names(self):
a, x, s = T.scalars("xxx") a, x, s = tt.scalars("xxx")
# implicit names would cause error. What do we do? # implicit names would cause error. What do we do?
f = function([a, x, s], a + x + s) f = function([a, x, s], a + x + s)
assert f(1, 2, 3) == 6 assert f(1, 2, 3) == 6
checkfor(self, lambda: f(1, 2, x=3), TypeError) checkfor(self, lambda: f(1, 2, x=3), TypeError)
def test_weird_names(self): def test_weird_names(self):
a, x, s = T.scalars("xxx") a, x, s = tt.scalars("xxx")
checkfor(self, lambda: function([In(a, name=[])], []), TypeError) checkfor(self, lambda: function([In(a, name=[])], []), TypeError)
...@@ -254,7 +254,7 @@ class TestFunction: ...@@ -254,7 +254,7 @@ class TestFunction:
[ [
In(a, name=set(["adsf", ()]), value=1.0), In(a, name=set(["adsf", ()]), value=1.0),
In(x, name=(), value=2.0), In(x, name=(), value=2.0),
In(s, name=T.scalar(), value=3.0), In(s, name=tt.scalar(), value=3.0),
], ],
a + x + s, a + x + s,
) )
...@@ -263,8 +263,8 @@ class TestFunction: ...@@ -263,8 +263,8 @@ class TestFunction:
checkfor(self, t, TypeError) checkfor(self, t, TypeError)
def test_copy(self): def test_copy(self):
a = T.scalar() # the a is for 'anonymous' (un-named). a = tt.scalar() # the a is for 'anonymous' (un-named).
x, s = T.scalars("xs") x, s = tt.scalars("xs")
f = function( f = function(
[ [
...@@ -298,11 +298,11 @@ class TestFunction: ...@@ -298,11 +298,11 @@ class TestFunction:
assert f(1, 2) != g(1, 2) # they should not be equal anymore. assert f(1, 2) != g(1, 2) # they should not be equal anymore.
def test_copy_share_memory(self): def test_copy_share_memory(self):
x = T.fscalar("x") x = tt.fscalar("x")
# SharedVariable for tests, one of them has update # SharedVariable for tests, one of them has update
y = theano.shared(value=1) y = theano.shared(value=1)
z = theano.shared(value=2) z = theano.shared(value=2)
out = T.tanh((x + y + 2) / (x + z - 0.2) ** 2) out = tt.tanh((x + y + 2) / (x + z - 0.2) ** 2)
# Test for different linkers # Test for different linkers
for mode in ["FAST_RUN", "FAST_COMPILE"]: for mode in ["FAST_RUN", "FAST_COMPILE"]:
...@@ -321,7 +321,7 @@ class TestFunction: ...@@ -321,7 +321,7 @@ class TestFunction:
l = [ l = [
val val
for key, val in storage_map_cpy.items() for key, val in storage_map_cpy.items()
if key not in i_o_variables or isinstance(key, T.Constant) if key not in i_o_variables or isinstance(key, tt.Constant)
] ]
for storage in l: for storage in l:
assert any([storage is s for s in ori_storages]) assert any([storage is s for s in ori_storages])
...@@ -333,10 +333,10 @@ class TestFunction: ...@@ -333,10 +333,10 @@ class TestFunction:
assert here.data is there.data assert here.data is there.data
def test_swap_SharedVariable(self): def test_swap_SharedVariable(self):
i = T.iscalar() i = tt.iscalar()
x_list = theano.shared(value=np.random.rand(10).astype(config.floatX)) x_list = theano.shared(value=np.random.rand(10).astype(config.floatX))
x = T.scalar("x") x = tt.scalar("x")
# SharedVariable for tests, one of them has update # SharedVariable for tests, one of them has update
y = theano.shared(value=1, name="y") y = theano.shared(value=1, name="y")
z = theano.shared(value=2, name="z") z = theano.shared(value=2, name="z")
...@@ -407,11 +407,11 @@ class TestFunction: ...@@ -407,11 +407,11 @@ class TestFunction:
train_y = theano.shared(value=np.random.rand(10, 1).astype(config.floatX)) train_y = theano.shared(value=np.random.rand(10, 1).astype(config.floatX))
test_y = theano.shared(value=np.random.rand(10, 1).astype(config.floatX)) test_y = theano.shared(value=np.random.rand(10, 1).astype(config.floatX))
i = T.iscalar("index") i = tt.iscalar("index")
x = T.vector("x") x = tt.vector("x")
y = T.vector("y") y = tt.vector("y")
# this formular has no sense but for a test # this formular has no sense but for a test
out = (T.sum(x) - y) ** 2 out = (tt.sum(x) - y) ** 2
train = theano.function( train = theano.function(
[i], [i],
out, out,
...@@ -428,8 +428,8 @@ class TestFunction: ...@@ -428,8 +428,8 @@ class TestFunction:
assert in1.value is in2.value assert in1.value is in2.value
def test_copy_delete_updates(self): def test_copy_delete_updates(self):
w = T.iscalar("w") w = tt.iscalar("w")
x = T.fscalar("x") x = tt.fscalar("x")
# SharedVariable for tests, one of them has update # SharedVariable for tests, one of them has update
y = theano.shared(value=1, name="y") y = theano.shared(value=1, name="y")
z = theano.shared(value=2, name="z") z = theano.shared(value=2, name="z")
...@@ -456,8 +456,8 @@ class TestFunction: ...@@ -456,8 +456,8 @@ class TestFunction:
cpy = ori.copy(delete_updates=True) cpy = ori.copy(delete_updates=True)
def test_shared_state0(self): def test_shared_state0(self):
a = T.scalar() # the a is for 'anonymous' (un-named). a = tt.scalar() # the a is for 'anonymous' (un-named).
x, s = T.scalars("xs") x, s = tt.scalars("xs")
f = function( f = function(
[ [
...@@ -484,8 +484,8 @@ class TestFunction: ...@@ -484,8 +484,8 @@ class TestFunction:
assert g[s] == 0 assert g[s] == 0
def test_shared_state1(self): def test_shared_state1(self):
a = T.scalar() # the a is for 'anonymous' (un-named). a = tt.scalar() # the a is for 'anonymous' (un-named).
x, s = T.scalars("xs") x, s = tt.scalars("xs")
f = function( f = function(
[ [
...@@ -508,8 +508,8 @@ class TestFunction: ...@@ -508,8 +508,8 @@ class TestFunction:
assert g[s] == 4 assert g[s] == 4
def test_shared_state2(self): def test_shared_state2(self):
a = T.scalar() # the a is for 'anonymous' (un-named). a = tt.scalar() # the a is for 'anonymous' (un-named).
x, s = T.scalars("xs") x, s = tt.scalars("xs")
f = function( f = function(
[ [
...@@ -538,7 +538,7 @@ class TestFunction: ...@@ -538,7 +538,7 @@ class TestFunction:
# doc/topics/function.txt. If it does not pass anymore and yet the # doc/topics/function.txt. If it does not pass anymore and yet the
# behavior is still intended the doc and the test should both be # behavior is still intended the doc and the test should both be
# updated accordingly. # updated accordingly.
x, s = T.scalars("xs") x, s = tt.scalars("xs")
inc = function([x, In(s, update=(s + x), value=10.0)], []) inc = function([x, In(s, update=(s + x), value=10.0)], [])
dec = function( dec = function(
[x, In(s, update=(s - x), value=inc.container[s], implicit=False)], [] [x, In(s, update=(s - x), value=inc.container[s], implicit=False)], []
...@@ -554,7 +554,7 @@ class TestFunction: ...@@ -554,7 +554,7 @@ class TestFunction:
def test_constant_output(self): def test_constant_output(self):
# Test that if the output is a constant, we respect the theano memory interface # Test that if the output is a constant, we respect the theano memory interface
f = theano.function([], T.constant([4])) f = theano.function([], tt.constant([4]))
# print f.maker.fgraph.toposort() # print f.maker.fgraph.toposort()
out = f() out = f()
assert (out == 4).all() assert (out == 4).all()
...@@ -565,7 +565,7 @@ class TestFunction: ...@@ -565,7 +565,7 @@ class TestFunction:
assert (out2 == 4).all() assert (out2 == 4).all()
# Test that if the output is a constant and borrow, we respect the theano memory interface # Test that if the output is a constant and borrow, we respect the theano memory interface
f = theano.function([], Out(T.constant([4]), borrow=True)) f = theano.function([], Out(tt.constant([4]), borrow=True))
# print f.maker.fgraph.toposort() # print f.maker.fgraph.toposort()
out = f() out = f()
assert (out == 4).all() assert (out == 4).all()
...@@ -585,7 +585,7 @@ class TestFunction: ...@@ -585,7 +585,7 @@ class TestFunction:
# either through a view-map or a destroy map. New tests should be added in the future # either through a view-map or a destroy map. New tests should be added in the future
# when borrow=True is implemented. # when borrow=True is implemented.
a = T.dmatrix() a = tt.dmatrix()
aval = np.random.rand(3, 3) aval = np.random.rand(3, 3)
# when borrow=False, test that a destroy map cannot alias output to input # when borrow=False, test that a destroy map cannot alias output to input
...@@ -599,7 +599,7 @@ class TestFunction: ...@@ -599,7 +599,7 @@ class TestFunction:
assert not np.may_share_memory(aval, f(aval)) assert not np.may_share_memory(aval, f(aval))
def test_borrow_output(self): def test_borrow_output(self):
a = T.dmatrix() a = tt.dmatrix()
f = function([a], Out(a, borrow=False)) f = function([a], Out(a, borrow=False))
o = np.ones((3, 3)) o = np.ones((3, 3))
assert o is not f(o) # function no longer permits aliasing outputs to inputs assert o is not f(o) # function no longer permits aliasing outputs to inputs
...@@ -626,15 +626,15 @@ class TestFunction: ...@@ -626,15 +626,15 @@ class TestFunction:
assert np.all(four == 4) assert np.all(four == 4)
def test_disconnected_input(self): def test_disconnected_input(self):
a = T.scalar("a") a = tt.scalar("a")
v = T.vector("v") v = tt.vector("v")
with pytest.raises(UnusedInputError): with pytest.raises(UnusedInputError):
function([a, v], v * 2) function([a, v], v * 2)
function([a, v], v * 2, on_unused_input="ignore") function([a, v], v * 2, on_unused_input="ignore")
def test_masked_input(self): def test_masked_input(self):
m = T.matrix("m") m = tt.matrix("m")
mt = m.T mt = m.T
mt.name = "m.T" mt.name = "m.T"
with pytest.raises(UnusedInputError): with pytest.raises(UnusedInputError):
...@@ -644,7 +644,7 @@ class TestFunction: ...@@ -644,7 +644,7 @@ class TestFunction:
def test_givens_input_var(self): def test_givens_input_var(self):
# Ensure error is raised when trying to replace an input variable. # Ensure error is raised when trying to replace an input variable.
x = T.scalar("x") x = tt.scalar("x")
y = x * 2 y = x * 2
with pytest.raises(RuntimeError): with pytest.raises(RuntimeError):
function([x], y, givens={x: x + 1}) function([x], y, givens={x: x + 1})
...@@ -652,7 +652,7 @@ class TestFunction: ...@@ -652,7 +652,7 @@ class TestFunction:
def test_free(self): def test_free(self):
# Make test on free() function # Make test on free() function
x = T.vector("x") x = tt.vector("x")
func = function([x], x + 1) func = function([x], x + 1)
func.fn.allow_gc = False func.fn.allow_gc = False
func([1]) func([1])
...@@ -673,7 +673,7 @@ class TestFunction: ...@@ -673,7 +673,7 @@ class TestFunction:
# Check that default values are restored # Check that default values are restored
# when an exception occurs in interactive mode. # when an exception occurs in interactive mode.
a, b = T.dscalars("a", "b") a, b = tt.dscalars("a", "b")
c = a + b c = a + b
func = theano.function( func = theano.function(
[theano.In(a, name="first"), theano.In(b, value=1, name="second")], c [theano.In(a, name="first"), theano.In(b, value=1, name="second")], c
...@@ -688,7 +688,7 @@ class TestFunction: ...@@ -688,7 +688,7 @@ class TestFunction:
b = np.random.rand(5, 4) b = np.random.rand(5, 4)
s1 = theano.shared(b) s1 = theano.shared(b)
s2 = theano.shared(b) s2 = theano.shared(b)
x1 = T.vector() x1 = tt.vector()
# Assert cases we should not check for aliased inputs # Assert cases we should not check for aliased inputs
for d in [ for d in [
...@@ -729,8 +729,8 @@ class TestFunction: ...@@ -729,8 +729,8 @@ class TestFunction:
class TestPicklefunction: class TestPicklefunction:
def test_deepcopy(self): def test_deepcopy(self):
a = T.scalar() # the a is for 'anonymous' (un-named). a = tt.scalar() # the a is for 'anonymous' (un-named).
x, s = T.scalars("xs") x, s = tt.scalars("xs")
f = function( f = function(
[ [
...@@ -785,8 +785,8 @@ class TestPicklefunction: ...@@ -785,8 +785,8 @@ class TestPicklefunction:
assert f(3) == g(3) # They should be in sync again. assert f(3) == g(3) # They should be in sync again.
def test_deepcopy_trust_input(self): def test_deepcopy_trust_input(self):
a = T.dscalar() # the a is for 'anonymous' (un-named). a = tt.dscalar() # the a is for 'anonymous' (un-named).
x, s = T.dscalars("xs") x, s = tt.dscalars("xs")
f = function( f = function(
[ [
...@@ -817,7 +817,7 @@ class TestPicklefunction: ...@@ -817,7 +817,7 @@ class TestPicklefunction:
g(2.0) g(2.0)
def test_output_keys(self): def test_output_keys(self):
x = T.vector() x = tt.vector()
f = theano.function([x], {"vec": x ** 2}) f = theano.function([x], {"vec": x ** 2})
o = f([2, 3, 4]) o = f([2, 3, 4])
assert isinstance(o, dict) assert isinstance(o, dict)
...@@ -829,7 +829,7 @@ class TestPicklefunction: ...@@ -829,7 +829,7 @@ class TestPicklefunction:
def test_deepcopy_shared_container(self): def test_deepcopy_shared_container(self):
# Ensure that shared containers remain shared after a deep copy. # Ensure that shared containers remain shared after a deep copy.
a, x = T.scalars("ax") a, x = tt.scalars("ax")
h = function([In(a, value=0.0)], a) h = function([In(a, value=0.0)], a)
f = function([x, In(a, value=h.container[a], implicit=True)], x + a) f = function([x, In(a, value=h.container[a], implicit=True)], x + a)
...@@ -852,8 +852,8 @@ class TestPicklefunction: ...@@ -852,8 +852,8 @@ class TestPicklefunction:
assert fc[ac] == 2 assert fc[ac] == 2
def test_pickle(self): def test_pickle(self):
a = T.scalar() # the a is for 'anonymous' (un-named). a = tt.scalar() # the a is for 'anonymous' (un-named).
x, s = T.scalars("xs") x, s = tt.scalars("xs")
f = function( f = function(
[ [
...@@ -900,15 +900,15 @@ class TestPicklefunction: ...@@ -900,15 +900,15 @@ class TestPicklefunction:
assert f(1, 2) != g(1, 2) # they should not be equal anymore. assert f(1, 2) != g(1, 2) # they should not be equal anymore.
def test_optimizations_preserved(self): def test_optimizations_preserved(self):
a = T.dvector() # the a is for 'anonymous' (un-named). a = tt.dvector() # the a is for 'anonymous' (un-named).
x = T.dvector("x") x = tt.dvector("x")
s = T.dvector("s") s = tt.dvector("s")
xm = T.dmatrix("x") xm = tt.dmatrix("x")
sm = T.dmatrix("s") sm = tt.dmatrix("s")
f = function( f = function(
[a, x, s, xm, sm], [a, x, s, xm, sm],
((a.T.T) * (T.dot(xm, (sm.T.T.T)) + x).T * (x / x) + s), ((a.T.T) * (tt.dot(xm, (sm.T.T.T)) + x).T * (x / x) + s),
) )
old_default_mode = config.mode old_default_mode = config.mode
old_default_opt = config.optimizer old_default_opt = config.optimizer
...@@ -946,9 +946,9 @@ class TestPicklefunction: ...@@ -946,9 +946,9 @@ class TestPicklefunction:
assert [i.type for i in nf.outputs] == [i.type for i in ng.outputs] assert [i.type for i in nf.outputs] == [i.type for i in ng.outputs]
def test_multiple_functions(self): def test_multiple_functions(self):
a = T.scalar() # the a is for 'anonymous' (un-named). a = tt.scalar() # the a is for 'anonymous' (un-named).
x, s = T.scalars("xs") x, s = tt.scalars("xs")
v = T.vector("v") v = tt.vector("v")
# put in some inputs # put in some inputs
list_of_things = [s, x, v] list_of_things = [s, x, v]
...@@ -1045,10 +1045,10 @@ class TestPicklefunction: ...@@ -1045,10 +1045,10 @@ class TestPicklefunction:
b = np.random.rand(5, 4) b = np.random.rand(5, 4)
x = T.matrix() x = tt.matrix()
y = theano.shared(b) y = theano.shared(b)
f = theano.function([x], T.dot(x, y)) f = theano.function([x], tt.dot(x, y))
from theano.compat import BytesIO from theano.compat import BytesIO
...@@ -1094,9 +1094,9 @@ class TestPicklefunction: ...@@ -1094,9 +1094,9 @@ class TestPicklefunction:
class SomethingToPickle(object): class SomethingToPickle(object):
def __init__(self): def __init__(self):
a = T.scalar() # the a is for 'anonymous' (un-named). a = tt.scalar() # the a is for 'anonymous' (un-named).
x, s = T.scalars("xs") x, s = tt.scalars("xs")
v = T.vector("v") v = tt.vector("v")
self.s = s self.s = s
self.x = x self.x = x
...@@ -1128,7 +1128,7 @@ def test_empty_givens_updates(): ...@@ -1128,7 +1128,7 @@ def test_empty_givens_updates():
# Empty givens / updates dictionaries were not properly detected before, # Empty givens / updates dictionaries were not properly detected before,
# triggering useless crashes at compile time. # triggering useless crashes at compile time.
x = T.scalar() x = tt.scalar()
y = x * 2 y = x * 2
function([theano.In(x)], y, givens={}) function([theano.In(x)], y, givens={})
function([theano.In(x)], y, updates={}) function([theano.In(x)], y, updates={})
...@@ -1162,7 +1162,7 @@ def test_sync_update(): ...@@ -1162,7 +1162,7 @@ def test_sync_update():
target=tests.gpuarray.config.test_ctx_name, target=tests.gpuarray.config.test_ctx_name,
) )
updates = [(w, w + np.asarray(0.001, "float32") * T.dot(x, x))] updates = [(w, w + np.asarray(0.001, "float32") * tt.dot(x, x))]
f = theano.function([], updates=updates, mode=tests.gpuarray.config.mode_with_gpu) f = theano.function([], updates=updates, mode=tests.gpuarray.config.mode_with_gpu)
assert len(f.maker.fgraph.apply_nodes) == 1 assert len(f.maker.fgraph.apply_nodes) == 1
......
import pytest import pytest
import theano import theano
import theano.tensor as T import theano.tensor as tt
from theano.compile.mode import Mode, AddFeatureOptimizer from theano.compile.mode import Mode, AddFeatureOptimizer
from theano.gof.toolbox import NoOutputFromInplace from theano.gof.toolbox import NoOutputFromInplace
...@@ -11,10 +11,10 @@ from theano.gof.toolbox import NoOutputFromInplace ...@@ -11,10 +11,10 @@ from theano.gof.toolbox import NoOutputFromInplace
not theano.config.cxx, reason="G++ not available, so we need to skip this test." not theano.config.cxx, reason="G++ not available, so we need to skip this test."
) )
def test_no_output_from_implace(): def test_no_output_from_implace():
x = T.matrix() x = tt.matrix()
y = T.matrix() y = tt.matrix()
a = T.dot(x, y) a = tt.dot(x, y)
b = T.tanh(a) b = tt.tanh(a)
# Ensure that the elemwise op that produces the output is inplace when # Ensure that the elemwise op that produces the output is inplace when
# using a mode that does not include the optimization # using a mode that does not include the optimization
......
...@@ -5,7 +5,7 @@ Test compilation modes ...@@ -5,7 +5,7 @@ Test compilation modes
import copy import copy
import theano import theano
import theano.tensor as T import theano.tensor as tt
from theano.compile import Mode from theano.compile import Mode
...@@ -25,8 +25,8 @@ class TestBunchOfModes: ...@@ -25,8 +25,8 @@ class TestBunchOfModes:
modes = predef_modes + [Mode(linker, "fast_run") for linker in linkers] modes = predef_modes + [Mode(linker, "fast_run") for linker in linkers]
for mode in modes: for mode in modes:
x = T.matrix() x = tt.matrix()
y = T.vector() y = tt.vector()
f = theano.function([x, y], x + y, mode=mode) f = theano.function([x, y], x + y, mode=mode)
# test that it runs something # test that it runs something
f([[1, 2], [3, 4]], [5, 6]) f([[1, 2], [3, 4]], [5, 6])
......
...@@ -2,23 +2,23 @@ ...@@ -2,23 +2,23 @@
This test is for testing the NanGuardMode. This test is for testing the NanGuardMode.
""" """
import logging import logging
import pytest import pytest
import numpy as np import numpy as np
from theano.compile.nanguardmode import NanGuardMode
import theano import theano
import theano.tensor as T import theano.tensor as tt
from theano.compile.nanguardmode import NanGuardMode
def test_NanGuardMode(): def test_NanGuardMode():
# Tests if NanGuardMode is working by feeding in numpy.inf and numpy.nans # Tests if NanGuardMode is working by feeding in numpy.inf and numpy.nans
# intentionally. A working implementation should be able to capture all # intentionally. A working implementation should be able to capture all
# the abnormalties. # the abnormalties.
x = T.matrix() x = tt.matrix()
w = theano.shared(np.random.randn(5, 7).astype(theano.config.floatX)) w = theano.shared(np.random.randn(5, 7).astype(theano.config.floatX))
y = T.dot(x, w) y = tt.dot(x, w)
fun = theano.function( fun = theano.function(
[x], y, mode=NanGuardMode(nan_is_error=True, inf_is_error=True) [x], y, mode=NanGuardMode(nan_is_error=True, inf_is_error=True)
...@@ -51,8 +51,8 @@ def test_NanGuardMode(): ...@@ -51,8 +51,8 @@ def test_NanGuardMode():
nana = np.tile(np.asarray(np.nan).astype(theano.config.floatX), (3, 4, 5)) nana = np.tile(np.asarray(np.nan).astype(theano.config.floatX), (3, 4, 5))
biga = np.tile(np.asarray(1e20).astype(theano.config.floatX), (3, 4, 5)) biga = np.tile(np.asarray(1e20).astype(theano.config.floatX), (3, 4, 5))
x = T.tensor3() x = tt.tensor3()
y = x[:, T.arange(2), T.arange(2), None] y = x[:, tt.arange(2), tt.arange(2), None]
fun = theano.function( fun = theano.function(
[x], y, mode=NanGuardMode(nan_is_error=True, inf_is_error=True) [x], y, mode=NanGuardMode(nan_is_error=True, inf_is_error=True)
) )
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import numpy as np import numpy as np
import theano import theano
import theano.tensor as T import theano.tensor as tt
from six.moves import StringIO from six.moves import StringIO
from theano.ifelse import ifelse from theano.ifelse import ifelse
...@@ -23,10 +23,10 @@ class TestProfiling: ...@@ -23,10 +23,10 @@ class TestProfiling:
theano.config.profile_memory = True theano.config.profile_memory = True
theano.config.profiling.min_peak_memory = True theano.config.profiling.min_peak_memory = True
x = [T.fvector("val%i" % i) for i in range(3)] x = [tt.fvector("val%i" % i) for i in range(3)]
z = [] z = []
z += [T.outer(x[i], x[i + 1]).sum(axis=1) for i in range(len(x) - 1)] z += [tt.outer(x[i], x[i + 1]).sum(axis=1) for i in range(len(x) - 1)]
z += [x[i] + x[i + 1] for i in range(len(x) - 1)] z += [x[i] + x[i + 1] for i in range(len(x) - 1)]
p = theano.ProfileStats(False, gpu_checks=False) p = theano.ProfileStats(False, gpu_checks=False)
...@@ -79,10 +79,10 @@ class TestProfiling: ...@@ -79,10 +79,10 @@ class TestProfiling:
theano.config.profile = True theano.config.profile = True
theano.config.profile_memory = True theano.config.profile_memory = True
a, b = T.scalars("a", "b") a, b = tt.scalars("a", "b")
x, y = T.scalars("x", "y") x, y = tt.scalars("x", "y")
z = ifelse(T.lt(a, b), x * 2, y * 2) z = ifelse(tt.lt(a, b), x * 2, y * 2)
p = theano.ProfileStats(False, gpu_checks=False) p = theano.ProfileStats(False, gpu_checks=False)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论