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

Replace theano.tensor alias T with tt in tests

上级 ef279e19
import numpy as np
import theano
import theano.tensor as T
import theano.tensor as tt
from theano.breakpoint import PdbBreakpoint
......@@ -14,15 +14,15 @@ class TestPdbBreakpoint(utt.InferShapeTester):
# Sample computation that involves tensors with different numbers
# of dimensions
self.input1 = T.fmatrix()
self.input2 = T.fscalar()
self.output = T.dot(
self.input1 = tt.fmatrix()
self.input2 = tt.fscalar()
self.output = tt.dot(
(self.input1 - self.input2), (self.input1 - self.input2).transpose()
)
# Declare the conditional breakpoint
self.breakpointOp = PdbBreakpoint("Sum of output too high")
self.condition = T.gt(self.output.sum(), 1000)
self.condition = tt.gt(self.output.sum(), 1000)
(
self.monitored_input1,
self.monitored_input2,
......@@ -47,8 +47,8 @@ class TestPdbBreakpoint(utt.InferShapeTester):
input2_value = 10.0
grads = [
T.grad(self.monitored_input1.sum(), self.input1),
T.grad(self.monitored_input2.sum(), self.input2),
tt.grad(self.monitored_input1.sum(), self.input1),
tt.grad(self.monitored_input2.sum(), self.input2),
]
# Add self.monitored_input1 as an output to the Theano function to
......
import theano
import theano.tensor as T
import theano.tensor as tt
class dictionary_output_checker:
class TestDictionaryOutput:
def test_output_dictionary(self):
# Tests that theano.function works when outputs is a dictionary
x = T.scalar()
x = tt.scalar()
f = theano.function([x], outputs={"a": x, "c": x * 2, "b": x * 3, "1": x * 4})
outputs = f(10.0)
......@@ -19,8 +19,8 @@ class dictionary_output_checker:
def test_input_named_variables(self):
# Tests that named variables work when outputs is a dictionary
x = T.scalar("x")
y = T.scalar("y")
x = tt.scalar("x")
y = tt.scalar("y")
f = theano.function([x, y], outputs={"a": x + y, "b": x * y})
......@@ -31,11 +31,11 @@ class dictionary_output_checker:
def test_output_order_sorted(self):
# Tests that the output keys are sorted correctly.
x = T.scalar("x")
y = T.scalar("y")
z = T.scalar("z")
e1 = T.scalar("1")
e2 = T.scalar("2")
x = tt.scalar("x")
y = tt.scalar("y")
z = tt.scalar("z")
e1 = tt.scalar("1")
e2 = tt.scalar("2")
f = theano.function(
[x, y, z, e1, e2], outputs={"x": x, "y": y, "z": z, "1": e1, "2": e2}
......@@ -51,16 +51,16 @@ class dictionary_output_checker:
# Tests that one can compose two theano functions when the outputs are
# provided in a dictionary.
x = T.scalar("x")
y = T.scalar("y")
x = tt.scalar("x")
y = tt.scalar("y")
a = x + y
b = x * y
f = theano.function([x, y], outputs={"a": a, "b": b})
a = T.scalar("a")
b = T.scalar("b")
a = tt.scalar("a")
b = tt.scalar("b")
l = a + b
r = a * b
......@@ -75,7 +75,7 @@ class dictionary_output_checker:
def test_output_list_still_works(self):
# Test that theano.function works if outputs is a list.
x = T.scalar("x")
x = tt.scalar("x")
f = theano.function([x], outputs=[x * 3, x * 2, x * 4, x])
......@@ -89,7 +89,7 @@ class dictionary_output_checker:
def test_debug_mode_dict(self):
# Tests that debug mode works where outputs is a dictionary.
x = T.scalar("x")
x = tt.scalar("x")
f = theano.function(
[x], outputs={"1": x, "2": 2 * x, "3": 3 * x}, mode="DEBUG_MODE"
......@@ -104,7 +104,7 @@ class dictionary_output_checker:
def test_debug_mode_list(self):
# Tests that debug mode works where the outputs argument is a list.
x = T.scalar("x")
x = tt.scalar("x")
f = theano.function([x], outputs=[x, 2 * x, 3 * x], mode="DEBUG_MODE")
......@@ -118,7 +118,7 @@ class dictionary_output_checker:
# Tests that an exception is thrown if a non-string key is used in
# the outputs dictionary.
x = T.scalar("x")
x = tt.scalar("x")
try:
theano.function([x], outputs={1.0: x})
raise Exception("Did not throw exception with 1.0 as only key")
......
......@@ -12,11 +12,12 @@ The config option is in configdefaults.py
This note is written by Li Yao.
"""
from collections import OrderedDict
import numpy as np
import six.moves.cPickle as pickle
import theano
import theano.tensor as T
import theano.tensor as tt
from collections import OrderedDict
floatX = "float32"
......@@ -25,11 +26,11 @@ def test_pickle_unpickle_with_reoptimization():
mode = theano.config.mode
if mode in ["DEBUG_MODE", "DebugMode"]:
mode = "FAST_RUN"
x1 = T.fmatrix("x1")
x2 = T.fmatrix("x2")
x1 = tt.fmatrix("x1")
x2 = tt.fmatrix("x2")
x3 = theano.shared(np.ones((10, 10), dtype=floatX))
x4 = theano.shared(np.ones((10, 10), dtype=floatX))
y = T.sum(T.sum(T.sum(x1 ** 2 + x2) + x3) + x4)
y = tt.sum(tt.sum(tt.sum(x1 ** 2 + x2) + x3) + x4)
updates = OrderedDict()
updates[x3] = x3 + 1
......@@ -57,11 +58,11 @@ def test_pickle_unpickle_without_reoptimization():
mode = theano.config.mode
if mode in ["DEBUG_MODE", "DebugMode"]:
mode = "FAST_RUN"
x1 = T.fmatrix("x1")
x2 = T.fmatrix("x2")
x1 = tt.fmatrix("x1")
x2 = tt.fmatrix("x2")
x3 = theano.shared(np.ones((10, 10), dtype=floatX))
x4 = theano.shared(np.ones((10, 10), dtype=floatX))
y = T.sum(T.sum(T.sum(x1 ** 2 + x2) + x3) + x4)
y = tt.sum(tt.sum(tt.sum(x1 ** 2 + x2) + x3) + x4)
updates = OrderedDict()
updates[x3] = x3 + 1
......
import pytest
import theano
import theano.tensor as T
import theano.tensor as tt
from theano.updates import OrderedUpdates
......@@ -21,7 +21,7 @@ class TestIfelse:
with pytest.raises(TypeError):
up.__setitem__(5, 7)
with pytest.raises(TypeError):
up.__setitem__(T.vector(), 7)
up.__setitem__(tt.vector(), 7)
up[theano.shared(88)] = 7
......
......@@ -6,7 +6,7 @@ import pytest
import numpy as np
import theano
import theano.tensor as T
import theano.tensor as tt
from functools import wraps
from copy import copy, deepcopy
......@@ -79,7 +79,7 @@ def verify_grad(op, pt, n_tests=2, rng=None, *args, **kwargs):
if rng is None:
seed_rng()
rng = np.random
T.verify_grad(op, pt, n_tests, rng, *args, **kwargs)
tt.verify_grad(op, pt, n_tests, rng, *args, **kwargs)
#
......@@ -92,7 +92,7 @@ def verify_grad(op, pt, n_tests=2, rng=None, *args, **kwargs):
# print e.analytic_grad
# raise
#
verify_grad.E_grad = T.verify_grad.E_grad
verify_grad.E_grad = tt.verify_grad.E_grad
# A helpful class to check random values close to the boundaries
......@@ -155,7 +155,7 @@ class OptimizationTestMixin(object):
class OpContractTestMixin(object):
# self.ops should be a list of instantiations of an Op class to test.
# self.other_op should be an op which is different from every op
other_op = T.add
other_op = tt.add
def copy(self, x):
return copy(x)
......@@ -296,7 +296,7 @@ class WrongValue(Exception):
def assert_allclose(expected, value, rtol=None, atol=None):
if not T.basic._allclose(expected, value, rtol, atol):
if not tt.basic._allclose(expected, value, rtol, atol):
raise WrongValue(expected, value, rtol, atol)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论