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

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

上级 6a09a928
......@@ -4,8 +4,9 @@ import pytest
import theano
import theano.typed_list
import theano.tensor as tt
from theano import tensor as T, sparse
from theano import sparse
from theano.tensor.type_other import SliceType
from theano.typed_list.type import TypedListType
from theano.typed_list.basic import (
......@@ -39,7 +40,7 @@ def random_lil(shape, dtype, nnz):
idx = np.random.randint(1, huge + 1, size=2) % shape
value = np.random.rand()
# if dtype *int*, value will always be zeros!
if dtype in theano.tensor.integer_dtypes:
if dtype in tt.integer_dtypes:
value = int(value * 100)
# The call to tuple is needed as scipy 0.13.1 do not support
# ndarray with length 2 as idx tuple.
......@@ -54,14 +55,14 @@ class TestGetItem:
def test_sanity_check_slice(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
mySymbolicSlice = SliceType()()
z = GetItem()(mySymbolicMatricesList, mySymbolicSlice)
assert not isinstance(z, T.TensorVariable)
assert not isinstance(z, tt.TensorVariable)
f = theano.function([mySymbolicMatricesList, mySymbolicSlice], z)
......@@ -72,10 +73,10 @@ class TestGetItem:
def test_sanity_check_single(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
mySymbolicScalar = T.scalar(dtype="int64")
mySymbolicScalar = tt.scalar(dtype="int64")
z = GetItem()(mySymbolicMatricesList, mySymbolicScalar)
......@@ -87,9 +88,9 @@ class TestGetItem:
def test_interface(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
mySymbolicScalar = T.scalar(dtype="int64")
mySymbolicScalar = tt.scalar(dtype="int64")
z = mySymbolicMatricesList[mySymbolicScalar]
......@@ -107,16 +108,16 @@ class TestGetItem:
def test_wrong_input(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
mySymbolicMatrix = T.matrix()
mySymbolicMatrix = tt.matrix()
with pytest.raises(TypeError):
GetItem()(mySymbolicMatricesList, mySymbolicMatrix)
def test_constant_input(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
z = GetItem()(mySymbolicMatricesList, 0)
......@@ -137,9 +138,9 @@ class TestGetItem:
class TestAppend:
def test_inplace(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
myMatrix = T.matrix()
myMatrix = tt.matrix()
z = Append(True)(mySymbolicMatricesList, myMatrix)
......@@ -153,9 +154,9 @@ class TestAppend:
def test_sanity_check(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
myMatrix = T.matrix()
myMatrix = tt.matrix()
z = Append()(mySymbolicMatricesList, myMatrix)
......@@ -169,9 +170,9 @@ class TestAppend:
def test_interfaces(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
myMatrix = T.matrix()
myMatrix = tt.matrix()
z = mySymbolicMatricesList.append(myMatrix)
......@@ -187,10 +188,10 @@ class TestAppend:
class TestExtend:
def test_inplace(self):
mySymbolicMatricesList1 = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
mySymbolicMatricesList2 = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
z = Extend(True)(mySymbolicMatricesList1, mySymbolicMatricesList2)
......@@ -207,10 +208,10 @@ class TestExtend:
def test_sanity_check(self):
mySymbolicMatricesList1 = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
mySymbolicMatricesList2 = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
z = Extend()(mySymbolicMatricesList1, mySymbolicMatricesList2)
......@@ -225,10 +226,10 @@ class TestExtend:
def test_interface(self):
mySymbolicMatricesList1 = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
mySymbolicMatricesList2 = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
z = mySymbolicMatricesList1.extend(mySymbolicMatricesList2)
......@@ -245,10 +246,10 @@ class TestExtend:
class TestInsert:
def test_inplace(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
myMatrix = T.matrix()
myScalar = T.scalar(dtype="int64")
myMatrix = tt.matrix()
myScalar = tt.scalar(dtype="int64")
z = Insert(True)(mySymbolicMatricesList, myScalar, myMatrix)
......@@ -264,10 +265,10 @@ class TestInsert:
def test_sanity_check(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
myMatrix = T.matrix()
myScalar = T.scalar(dtype="int64")
myMatrix = tt.matrix()
myScalar = tt.scalar(dtype="int64")
z = Insert()(mySymbolicMatricesList, myScalar, myMatrix)
......@@ -281,10 +282,10 @@ class TestInsert:
def test_interface(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
myMatrix = T.matrix()
myScalar = T.scalar(dtype="int64")
myMatrix = tt.matrix()
myScalar = tt.scalar(dtype="int64")
z = mySymbolicMatricesList.insert(myScalar, myMatrix)
......@@ -300,9 +301,9 @@ class TestInsert:
class TestRemove:
def test_inplace(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
myMatrix = T.matrix()
myMatrix = tt.matrix()
z = Remove(True)(mySymbolicMatricesList, myMatrix)
......@@ -316,9 +317,9 @@ class TestRemove:
def test_sanity_check(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
myMatrix = T.matrix()
myMatrix = tt.matrix()
z = Remove()(mySymbolicMatricesList, myMatrix)
......@@ -332,9 +333,9 @@ class TestRemove:
def test_interface(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
myMatrix = T.matrix()
myMatrix = tt.matrix()
z = mySymbolicMatricesList.remove(myMatrix)
......@@ -350,7 +351,7 @@ class TestRemove:
class TestReverse:
def test_inplace(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
z = Reverse(True)(mySymbolicMatricesList)
......@@ -365,7 +366,7 @@ class TestReverse:
def test_sanity_check(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
z = Reverse()(mySymbolicMatricesList)
......@@ -380,7 +381,7 @@ class TestReverse:
def test_interface(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
z = mySymbolicMatricesList.reverse()
......@@ -397,9 +398,9 @@ class TestReverse:
class TestIndex:
def test_sanity_check(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
myMatrix = T.matrix()
myMatrix = tt.matrix()
z = Index()(mySymbolicMatricesList, myMatrix)
......@@ -413,9 +414,9 @@ class TestIndex:
def test_interface(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
myMatrix = T.matrix()
myMatrix = tt.matrix()
z = mySymbolicMatricesList.ind(myMatrix)
......@@ -429,10 +430,10 @@ class TestIndex:
def test_non_tensor_type(self):
mySymbolicNestedMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False)), 1
tt.TensorType(theano.config.floatX, (False, False)), 1
)()
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
z = Index()(mySymbolicNestedMatricesList, mySymbolicMatricesList)
......@@ -465,9 +466,9 @@ class TestIndex:
class TestCount:
def test_sanity_check(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
myMatrix = T.matrix()
myMatrix = tt.matrix()
z = Count()(mySymbolicMatricesList, myMatrix)
......@@ -481,9 +482,9 @@ class TestCount:
def test_interface(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
myMatrix = T.matrix()
myMatrix = tt.matrix()
z = mySymbolicMatricesList.count(myMatrix)
......@@ -497,10 +498,10 @@ class TestCount:
def test_non_tensor_type(self):
mySymbolicNestedMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False)), 1
tt.TensorType(theano.config.floatX, (False, False)), 1
)()
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
z = Count()(mySymbolicNestedMatricesList, mySymbolicMatricesList)
......@@ -533,7 +534,7 @@ class TestCount:
class TestLength:
def test_sanity_check(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
z = Length()(mySymbolicMatricesList)
......@@ -546,7 +547,7 @@ class TestLength:
def test_interface(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
z = mySymbolicMatricesList.__len__()
......@@ -559,18 +560,18 @@ class TestLength:
class TestMakeList:
def test_wrong_shape(self):
a = T.vector()
b = T.matrix()
a = tt.vector()
b = tt.matrix()
with pytest.raises(TypeError):
make_list((a, b))
def test_correct_answer(self):
a = T.matrix()
b = T.matrix()
a = tt.matrix()
b = tt.matrix()
x = T.tensor3()
y = T.tensor3()
x = tt.tensor3()
y = tt.tensor3()
A = np.cast[theano.config.floatX](np.random.rand(5, 3))
B = np.cast[theano.config.floatX](np.random.rand(7, 2))
......
import numpy as np
import theano
import theano.tensor as tt
import theano.typed_list
from theano import In
from theano import tensor as T
from theano.typed_list.type import TypedListType
from theano.typed_list.basic import Insert, Append, Extend, Remove, Reverse
......@@ -20,7 +20,7 @@ def rand_ranged_matrix(minimum, maximum, shape):
class TestInplace:
def test_reverse_inplace(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
z = Reverse()(mySymbolicMatricesList)
......@@ -41,9 +41,9 @@ class TestInplace:
def test_append_inplace(self):
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)
m = theano.compile.mode.get_default_mode().including("typed_list_inplace_opt")
f = theano.function(
......@@ -65,11 +65,11 @@ class TestInplace:
def test_extend_inplace(self):
mySymbolicMatricesList1 = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
mySymbolicMatricesList2 = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
z = Extend()(mySymbolicMatricesList1, mySymbolicMatricesList2)
......@@ -92,10 +92,10 @@ class TestInplace:
def test_insert_inplace(self):
mySymbolicMatricesList = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
mySymbolicIndex = T.scalar(dtype="int64")
mySymbolicMatrix = T.matrix()
mySymbolicIndex = tt.scalar(dtype="int64")
mySymbolicMatrix = tt.matrix()
z = Insert()(mySymbolicMatricesList, mySymbolicIndex, mySymbolicMatrix)
m = theano.compile.mode.get_default_mode().including("typed_list_inplace_opt")
......@@ -120,9 +120,9 @@ class TestInplace:
def test_remove_inplace(self):
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)
m = theano.compile.mode.get_default_mode().including("typed_list_inplace_opt")
f = theano.function(
......@@ -144,7 +144,7 @@ class TestInplace:
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])
f = theano.function([], l)
topo = f.maker.fgraph.toposort()
......
......@@ -2,8 +2,8 @@ import pytest
import numpy as np
import theano
import theano.typed_list
import theano.tensor as tt
from theano import tensor as T
from theano.typed_list.type import TypedListType
from tests import unittest_tools as utt
......@@ -35,7 +35,7 @@ class TestTypedListType:
# specified on creation
# 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):
myType.filter([4])
......@@ -45,7 +45,7 @@ class TestTypedListType:
# if no iterable variable is given on input
# 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):
myType.filter(4)
......@@ -56,11 +56,11 @@ class TestTypedListType:
# variables
# list of matrices
myType1 = TypedListType(T.TensorType(theano.config.floatX, (False, False)))
myType1 = TypedListType(tt.TensorType(theano.config.floatX, (False, False)))
# list of matrices
myType2 = TypedListType(T.TensorType(theano.config.floatX, (False, False)))
myType2 = TypedListType(tt.TensorType(theano.config.floatX, (False, False)))
# list of scalars
myType3 = TypedListType(T.TensorType(theano.config.floatX, ()))
myType3 = TypedListType(tt.TensorType(theano.config.floatX, ()))
assert myType2 == myType1
assert myType3 != myType1
......@@ -68,7 +68,7 @@ class TestTypedListType:
def test_filter_sanity_check(self):
# 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])
......@@ -79,17 +79,16 @@ class TestTypedListType:
# filtered. If they weren't this code would raise
# 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")
assert np.array_equal(myType.filter([x]), [x])
@pytest.mark.skip(reason="This fails for unknown reasons?")
def test_load(self):
myType = TypedListType(T.TensorType(theano.config.floatX, (False, False)))
def test_load_alot(self):
myType = TypedListType(tt.TensorType(theano.config.floatX, (False, False)))
x = rand_ranged_matrix(-1000, 1000, [100, 100])
x = rand_ranged_matrix(-1000, 1000, [10, 10])
testList = []
for i in range(10000):
testList.append(x)
......@@ -99,7 +98,9 @@ class TestTypedListType:
def test_basic_nested_list(self):
# 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)
......@@ -110,7 +111,9 @@ class TestTypedListType:
def test_comparison_different_depth(self):
# 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)
......@@ -122,10 +125,10 @@ class TestTypedListType:
# test for the 'depth' optionnal argument
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)))
......@@ -134,7 +137,7 @@ class TestTypedListType:
def test_get_depth(self):
# 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)))
......@@ -143,7 +146,7 @@ class TestTypedListType:
def test_comparison_uneven_nested(self):
# 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)))
......@@ -154,7 +157,7 @@ class TestTypedListType:
def test_variable_is_Typed_List_variable(self):
mySymbolicVariable = TypedListType(
T.TensorType(theano.config.floatX, (False, False))
tt.TensorType(theano.config.floatX, (False, False))
)()
assert isinstance(mySymbolicVariable, theano.typed_list.TypedListVariable)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论