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

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

上级 6a09a928
import numpy as np import numpy as np
import theano import theano
import theano.tensor as tt
import theano.typed_list import theano.typed_list
from theano import In from theano import In
from theano import tensor as T
from theano.typed_list.type import TypedListType from theano.typed_list.type import TypedListType
from theano.typed_list.basic import Insert, Append, Extend, Remove, Reverse from theano.typed_list.basic import Insert, Append, Extend, Remove, Reverse
...@@ -20,7 +20,7 @@ def rand_ranged_matrix(minimum, maximum, shape): ...@@ -20,7 +20,7 @@ def rand_ranged_matrix(minimum, maximum, shape):
class TestInplace: class TestInplace:
def test_reverse_inplace(self): def test_reverse_inplace(self):
mySymbolicMatricesList = TypedListType( mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False)) tt.TensorType(theano.config.floatX, (False, False))
)() )()
z = Reverse()(mySymbolicMatricesList) z = Reverse()(mySymbolicMatricesList)
...@@ -41,9 +41,9 @@ class TestInplace: ...@@ -41,9 +41,9 @@ class TestInplace:
def test_append_inplace(self): def test_append_inplace(self):
mySymbolicMatricesList = TypedListType( mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False)) tt.TensorType(theano.config.floatX, (False, False))
)() )()
mySymbolicMatrix = T.matrix() mySymbolicMatrix = tt.matrix()
z = Append()(mySymbolicMatricesList, mySymbolicMatrix) z = Append()(mySymbolicMatricesList, mySymbolicMatrix)
m = theano.compile.mode.get_default_mode().including("typed_list_inplace_opt") m = theano.compile.mode.get_default_mode().including("typed_list_inplace_opt")
f = theano.function( f = theano.function(
...@@ -65,11 +65,11 @@ class TestInplace: ...@@ -65,11 +65,11 @@ class TestInplace:
def test_extend_inplace(self): def test_extend_inplace(self):
mySymbolicMatricesList1 = TypedListType( mySymbolicMatricesList1 = TypedListType(
T.TensorType(theano.config.floatX, (False, False)) tt.TensorType(theano.config.floatX, (False, False))
)() )()
mySymbolicMatricesList2 = TypedListType( mySymbolicMatricesList2 = TypedListType(
T.TensorType(theano.config.floatX, (False, False)) tt.TensorType(theano.config.floatX, (False, False))
)() )()
z = Extend()(mySymbolicMatricesList1, mySymbolicMatricesList2) z = Extend()(mySymbolicMatricesList1, mySymbolicMatricesList2)
...@@ -92,10 +92,10 @@ class TestInplace: ...@@ -92,10 +92,10 @@ class TestInplace:
def test_insert_inplace(self): def test_insert_inplace(self):
mySymbolicMatricesList = TypedListType( mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False)) tt.TensorType(theano.config.floatX, (False, False))
)() )()
mySymbolicIndex = T.scalar(dtype="int64") mySymbolicIndex = tt.scalar(dtype="int64")
mySymbolicMatrix = T.matrix() mySymbolicMatrix = tt.matrix()
z = Insert()(mySymbolicMatricesList, mySymbolicIndex, mySymbolicMatrix) z = Insert()(mySymbolicMatricesList, mySymbolicIndex, mySymbolicMatrix)
m = theano.compile.mode.get_default_mode().including("typed_list_inplace_opt") m = theano.compile.mode.get_default_mode().including("typed_list_inplace_opt")
...@@ -120,9 +120,9 @@ class TestInplace: ...@@ -120,9 +120,9 @@ class TestInplace:
def test_remove_inplace(self): def test_remove_inplace(self):
mySymbolicMatricesList = TypedListType( mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False)) tt.TensorType(theano.config.floatX, (False, False))
)() )()
mySymbolicMatrix = T.matrix() mySymbolicMatrix = tt.matrix()
z = Remove()(mySymbolicMatricesList, mySymbolicMatrix) z = Remove()(mySymbolicMatricesList, mySymbolicMatrix)
m = theano.compile.mode.get_default_mode().including("typed_list_inplace_opt") m = theano.compile.mode.get_default_mode().including("typed_list_inplace_opt")
f = theano.function( f = theano.function(
...@@ -144,7 +144,7 @@ class TestInplace: ...@@ -144,7 +144,7 @@ class TestInplace:
def test_constant_folding(): def test_constant_folding():
m = theano.tensor.ones((1,), dtype="int8") m = tt.ones((1,), dtype="int8")
l = theano.typed_list.make_list([m, m]) l = theano.typed_list.make_list([m, m])
f = theano.function([], l) f = theano.function([], l)
topo = f.maker.fgraph.toposort() topo = f.maker.fgraph.toposort()
......
...@@ -2,8 +2,8 @@ import pytest ...@@ -2,8 +2,8 @@ import pytest
import numpy as np import numpy as np
import theano import theano
import theano.typed_list import theano.typed_list
import theano.tensor as tt
from theano import tensor as T
from theano.typed_list.type import TypedListType from theano.typed_list.type import TypedListType
from tests import unittest_tools as utt from tests import unittest_tools as utt
...@@ -35,7 +35,7 @@ class TestTypedListType: ...@@ -35,7 +35,7 @@ class TestTypedListType:
# specified on creation # specified on creation
# list of matrices # list of matrices
myType = TypedListType(T.TensorType(theano.config.floatX, (False, False))) myType = TypedListType(tt.TensorType(theano.config.floatX, (False, False)))
with pytest.raises(TypeError): with pytest.raises(TypeError):
myType.filter([4]) myType.filter([4])
...@@ -45,7 +45,7 @@ class TestTypedListType: ...@@ -45,7 +45,7 @@ class TestTypedListType:
# if no iterable variable is given on input # if no iterable variable is given on input
# list of matrices # list of matrices
myType = TypedListType(T.TensorType(theano.config.floatX, (False, False))) myType = TypedListType(tt.TensorType(theano.config.floatX, (False, False)))
with pytest.raises(TypeError): with pytest.raises(TypeError):
myType.filter(4) myType.filter(4)
...@@ -56,11 +56,11 @@ class TestTypedListType: ...@@ -56,11 +56,11 @@ class TestTypedListType:
# variables # variables
# list of matrices # list of matrices
myType1 = TypedListType(T.TensorType(theano.config.floatX, (False, False))) myType1 = TypedListType(tt.TensorType(theano.config.floatX, (False, False)))
# list of matrices # list of matrices
myType2 = TypedListType(T.TensorType(theano.config.floatX, (False, False))) myType2 = TypedListType(tt.TensorType(theano.config.floatX, (False, False)))
# list of scalars # list of scalars
myType3 = TypedListType(T.TensorType(theano.config.floatX, ())) myType3 = TypedListType(tt.TensorType(theano.config.floatX, ()))
assert myType2 == myType1 assert myType2 == myType1
assert myType3 != myType1 assert myType3 != myType1
...@@ -68,7 +68,7 @@ class TestTypedListType: ...@@ -68,7 +68,7 @@ class TestTypedListType:
def test_filter_sanity_check(self): def test_filter_sanity_check(self):
# Simple test on typed list type filter # Simple test on typed list type filter
myType = TypedListType(T.TensorType(theano.config.floatX, (False, False))) myType = TypedListType(tt.TensorType(theano.config.floatX, (False, False)))
x = rand_ranged_matrix(-1000, 1000, [100, 100]) x = rand_ranged_matrix(-1000, 1000, [100, 100])
...@@ -79,17 +79,16 @@ class TestTypedListType: ...@@ -79,17 +79,16 @@ class TestTypedListType:
# filtered. If they weren't this code would raise # filtered. If they weren't this code would raise
# an exception. # an exception.
myType = TypedListType(T.TensorType("float64", (False, False))) myType = TypedListType(tt.TensorType("float64", (False, False)))
x = np.asarray([[4, 5], [4, 5]], dtype="float32") x = np.asarray([[4, 5], [4, 5]], dtype="float32")
assert np.array_equal(myType.filter([x]), [x]) assert np.array_equal(myType.filter([x]), [x])
@pytest.mark.skip(reason="This fails for unknown reasons?") def test_load_alot(self):
def test_load(self): myType = TypedListType(tt.TensorType(theano.config.floatX, (False, False)))
myType = TypedListType(T.TensorType(theano.config.floatX, (False, False)))
x = rand_ranged_matrix(-1000, 1000, [100, 100]) x = rand_ranged_matrix(-1000, 1000, [10, 10])
testList = [] testList = []
for i in range(10000): for i in range(10000):
testList.append(x) testList.append(x)
...@@ -99,7 +98,9 @@ class TestTypedListType: ...@@ -99,7 +98,9 @@ class TestTypedListType:
def test_basic_nested_list(self): def test_basic_nested_list(self):
# Testing nested list with one level of depth # Testing nested list with one level of depth
myNestedType = TypedListType(T.TensorType(theano.config.floatX, (False, False))) myNestedType = TypedListType(
tt.TensorType(theano.config.floatX, (False, False))
)
myType = TypedListType(myNestedType) myType = TypedListType(myNestedType)
...@@ -110,7 +111,9 @@ class TestTypedListType: ...@@ -110,7 +111,9 @@ class TestTypedListType:
def test_comparison_different_depth(self): def test_comparison_different_depth(self):
# Nested list with different depth aren't the same # Nested list with different depth aren't the same
myNestedType = TypedListType(T.TensorType(theano.config.floatX, (False, False))) myNestedType = TypedListType(
tt.TensorType(theano.config.floatX, (False, False))
)
myNestedType2 = TypedListType(myNestedType) myNestedType2 = TypedListType(myNestedType)
...@@ -122,10 +125,10 @@ class TestTypedListType: ...@@ -122,10 +125,10 @@ class TestTypedListType:
# test for the 'depth' optionnal argument # test for the 'depth' optionnal argument
myNestedType = TypedListType( myNestedType = TypedListType(
T.TensorType(theano.config.floatX, (False, False)), 3 tt.TensorType(theano.config.floatX, (False, False)), 3
) )
myType = TypedListType(T.TensorType(theano.config.floatX, (False, False))) myType = TypedListType(tt.TensorType(theano.config.floatX, (False, False)))
myManualNestedType = TypedListType(TypedListType(TypedListType(myType))) myManualNestedType = TypedListType(TypedListType(TypedListType(myType)))
...@@ -134,7 +137,7 @@ class TestTypedListType: ...@@ -134,7 +137,7 @@ class TestTypedListType:
def test_get_depth(self): def test_get_depth(self):
# test case for get_depth utilitary function # test case for get_depth utilitary function
myType = TypedListType(T.TensorType(theano.config.floatX, (False, False))) myType = TypedListType(tt.TensorType(theano.config.floatX, (False, False)))
myManualNestedType = TypedListType(TypedListType(TypedListType(myType))) myManualNestedType = TypedListType(TypedListType(TypedListType(myType)))
...@@ -143,7 +146,7 @@ class TestTypedListType: ...@@ -143,7 +146,7 @@ class TestTypedListType:
def test_comparison_uneven_nested(self): def test_comparison_uneven_nested(self):
# test for comparison between uneven nested list # test for comparison between uneven nested list
myType = TypedListType(T.TensorType(theano.config.floatX, (False, False))) myType = TypedListType(tt.TensorType(theano.config.floatX, (False, False)))
myManualNestedType1 = TypedListType(TypedListType(TypedListType(myType))) myManualNestedType1 = TypedListType(TypedListType(TypedListType(myType)))
...@@ -154,7 +157,7 @@ class TestTypedListType: ...@@ -154,7 +157,7 @@ class TestTypedListType:
def test_variable_is_Typed_List_variable(self): def test_variable_is_Typed_List_variable(self):
mySymbolicVariable = TypedListType( mySymbolicVariable = TypedListType(
T.TensorType(theano.config.floatX, (False, False)) tt.TensorType(theano.config.floatX, (False, False))
)() )()
assert isinstance(mySymbolicVariable, theano.typed_list.TypedListVariable) assert isinstance(mySymbolicVariable, theano.typed_list.TypedListVariable)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论