Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1451d214
提交
1451d214
authored
11月 03, 2011
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
removing vast commented test cases in tensor test_basic
上级
410405cf
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
0 行增加
和
319 行删除
+0
-319
test_basic.py
theano/tensor/tests/test_basic.py
+0
-319
没有找到文件。
theano/tensor/tests/test_basic.py
浏览文件 @
1451d214
...
...
@@ -1255,24 +1255,6 @@ def _approx_eq(a,b,eps=1.0e-4):
return
True
_approx_eq
.
debug
=
0
# def check_eq(self, node_in, node_out, arg_in, arg_out):
# fn = Function([node_in], node_out)
# self.assertTrue( numpy.all(fn(arg_in) == arg_out), (arg_in, arg_out))
# def check_eq2(self, inputs, output, args_in, arg_out):
# fn = Function(inputs, output)
# val = fn(*args_in)
# self.assertTrue( numpy.all(val == arg_out), (val, arg_out))
# def check_eq2_c(self, inputs, output, args_in, arg_out):
# fn = Function(inputs, [output], linker_cls = gof.CLinker)
# val = fn(*args_in)
# self.assertTrue( numpy.all(val == arg_out), (val, arg_out))
# def check_eq2_both(self, inputs, output, args_in, arg_out):
# fn = Function(inputs, [output], linker_cls = lambda env: gof.DualLinker(env, _numpy_checker))
# val = fn(*args_in)
# self.assertTrue( numpy.all(val == arg_out), (val, arg_out))
def
test_tensor_values_eq_approx
():
#test, inf, -inf and nan equal themself
...
...
@@ -3214,173 +3196,6 @@ class T_mean(unittest.TestCase):
data
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
50
),
dtype
=
config
.
floatX
)
assert
numpy
.
allclose
(
f
(
data
),
numpy
.
mean
(
data
))
# class T_abs(unittest.TestCase):
# def test_impl(self):
# t = as_tensor_variable(1.0)
# check_eq(self, t, abs(t), 1.0, 1.0)
# check_eq(self, t, abs(t), -1.0, 1.0)
# for shape in (2,), (3,4):
# t = as_tensor_variable(numpy.ones(shape))
# d = numpy.random.rand(*shape)*2-1.0
# check_eq(self, t, abs(t), d, abs(d))
# check_eq(self, t, abs(t), -d, abs(-d))
# def test_grad(self):
# utt.verify_grad(Abs, [numpy.ones(())])
# utt.verify_grad(Abs, [numpy.ones(3)])
# class AbsBadGrad(Abs):
# def grad(self, (x, ), (gz, )):
# return mul(gz * sgn(x),0.9),
# def test_badgrad(self):
# try:
# utt.verify_grad(T_abs.AbsBadGrad, [numpy.ones(())])
# except Exception, e:
# self.assertTrue(str(e) == utt.verify_grad.E_grad, str(e))
# return
# self.fail()
# class T_fill(unittest.TestCase):
# def test0(self):
# t = fill(numpy.asarray([1,2,3]), 9)
# self.assertTrue(t.owner.__class__ == Fill)
# o = t.owner
# self.assertTrue(o.inputs[0].broadcastable == (0,))
# # self.assertTrue(o.inputs[0].dtype[0:3] == 'int')
# self.assertTrue(o.inputs[1].broadcastable == (1,))
# # self.assertTrue(o.inputs[1].dtype[0:3] == 'flo')
# self.assertTrue(o.outputs[0].broadcastable == (0,))
# # self.assertTrue(o.outputs[0].dtype[0:3] == 'flo')
# self.assertTrue(numpy.all(eval_outputs([t]) == [9,9,9]))
# def test1(self):
# x = as_tensor_variable(numpy.ones((4,5)))
# l = ones_like(x[:,0:1])
# r = ones_like(x[0:1,:])
# xx = x + dot(l,r)
# self.assertTrue(numpy.mean(eval_outputs([xx]) == 2.0))
# class T_sum(unittest.TestCase):
# def test_impl(self):
# t = as_tensor_variable(0.0)
# check_eq(self, t, Sum(t).out, 1.0, 1.0)
# check_eq(self, t, Sum(t).out, -1.0, -1.0)
# t = as_tensor_variable([0.0, 0.0])
# d = numpy.asarray([-0.4, 1.2])
# check_eq(self, t, Sum(t).out, d, numpy.sum(d))
# check_eq(self, t, Sum(t).out, -d, -numpy.sum(d))
# class T_mul(unittest.TestCase):
# def setUp(self):
# utt.seed_rng()
# def test_elemwise(self):
# a = as_tensor_variable(0.0)
# b = as_tensor_variable(0.0)
# check_eq2_both(self, [a,b], mul(a,b), [3.0, 4.0], 12.0)
# check_eq2_both(self, [a,b], mul(b,a), [-1.0,2.0], -2.0)
# a = as_tensor_variable(numpy.ones(2))
# b = as_tensor_variable(numpy.ones(2))
# aa = numpy.asarray([-0.5, 4.0])
# bb = numpy.asarray([-0.5, 2.0])
# check_eq2_both(self, [a,b], mul(a,b), [aa,bb], numpy.asarray([0.25, 8.0]))
# check_eq2_both(self, [a,b], mul(a,b), [bb,aa], numpy.asarray([0.25, 8.0]))
# def test_scalar(self):
# r = numpy.random.rand(2,3)
# a = as_tensor_variable(r)
# b = as_tensor_variable(2.0)
# check_eq2_both(self, [a,b], mul(a,b), [r, 2.0], r*2.0)
# check_eq2_both(self, [a,b], mul(a,b), [r, 4.0], r*4.0)
# self.assertTrue(b.data == 2.0)
# def test_rowcol(self):
# r1 = numpy.random.rand(3,5)
# r2 = numpy.random.rand(1,5)
# r3 = numpy.random.rand(3,1)
# a1, a2, a3 = as_tensor_variable(r1), as_tensor_variable(r2), as_tensor_variable(r3)
# check_eq2_both(self, [a1,a2], mul(a1,a2), [r1, r2], r1*r2)
# check_eq2_both(self, [a1,a3], mul(a1,a3), [r1, r3], r1*r3)
# def test_grad_elemwise(self):
# utt.verify_grad(Mul, [numpy.random.rand(3,4), numpy.random.rand(3,4)])
# def test_grad_scalar_l(self):
# utt.verify_grad(Mul, [numpy.asarray([3.0]), numpy.random.rand(3)])
# def test_grad_scalar_r(self):
# utt.verify_grad(Mul, [numpy.random.rand(3), numpy.asarray([3.0])])
# def test_grad_row(self):
# utt.verify_grad(Mul, [numpy.random.rand(3, 5), numpy.random.rand(1, 5)])
# def test_grad_row2(self):
# op = lambda x, y: Mul(x, DimShuffle(y, ['x', 0]).out)
# utt.verify_grad(op, [numpy.random.rand(3, 5), numpy.random.rand(5)])
# def test_grad_col(self):
# utt.verify_grad(Mul, [numpy.random.rand(3, 5), numpy.random.rand(3, 1)])
# def test_wrong_shapes(self):
# a = as_tensor_variable(numpy.ones(3))
# b = as_tensor_variable(numpy.ones(4))
# try:
# check_eq2(self, [a,b], Mul(a,b).out,
# [numpy.ones(3), numpy.ones(4)], 1.0)
# self.fail()
# except ValueError, e:
# self.assertTrue('shape mismatch' in str(e))
# try:
# check_eq2_c(self, [a,b], Mul(a,b).out,
# [numpy.ones(3), numpy.ones(4)], 1.0)
# self.fail()
# except ValueError, e:
# pass
# class T_div(unittest.TestCase):
# def setUp(self):
# utt.seed_rng()
# def test_grad_e(self):
# utt.verify_grad(Div, [numpy.random.rand(3), numpy.ones(3)])
# utt.verify_grad(Div, [numpy.random.rand(3,5), numpy.random.rand(3,5)+0.1])
# utt.verify_grad(Div, [numpy.ones(()), numpy.ones(())])
# def test_grad_sl(self):
# utt.verify_grad(Div, [numpy.ones((3, 5)), numpy.ones((1, 1))])
# utt.verify_grad(Div, [numpy.random.rand(3), numpy.ones((1, ))])
# utt.verify_grad(Div, [numpy.random.rand(3,5), numpy.random.rand(1,1)])
# class T_log2(unittest.TestCase):
# def setUp(self):
# utt.seed_rng()
# def test0(self):
# utt.verify_grad(Log2, [numpy.random.rand(3,1)+0.0001])
# class T_log(unittest.TestCase):
# def setUp(self):
# utt.seed_rng()
# def test0(self):
# utt.verify_grad(Log, [numpy.random.rand(3,1)+0.0001])
# def test1(self):
# a = as_tensor_variable(numpy.ones(2))
# b = as_tensor_variable(numpy.ones(2))
# aa = numpy.asarray([0.5, 4.0])
# bb = numpy.asarray([0.5, 2.0])
# check_eq2(self, [a], log(a), [aa], numpy.log(numpy.asarray(aa)))
# class T_pow(unittest.TestCase):
# def setUp(self):
# utt.seed_rng()
# def test_elemwise(self):
# utt.verify_grad(Div, [numpy.random.rand(3,4), numpy.random.rand(3,4)+0.1])
# utt.verify_grad(Pow, [numpy.random.rand(3,4), numpy.random.rand(3,4)])
# def test_scalar_l(self):
# utt.verify_grad(Pow, [numpy.asarray([3.0]), numpy.random.rand(3)])
# def test_scalar_r(self):
# utt.verify_grad(Pow, [numpy.random.rand(3), numpy.asarray([3.0])])
# def test_row(self):
# utt.verify_grad(Pow, [numpy.random.rand(3, 5), numpy.random.rand(1, 5)])
# def test_col(self):
# utt.verify_grad(Pow, [numpy.random.rand(3, 5), numpy.random.rand(3, 1)])
class
test_matinv
(
unittest
.
TestCase
):
...
...
@@ -3646,140 +3461,6 @@ class T_scalarfromtensor(unittest.TestCase):
self
.
assertTrue
(
isinstance
(
v
,
numpy
.
int64
))
self
.
assertTrue
(
v
.
shape
==
(),
v
.
shape
)
# def _tensor(data, broadcastable=None, name=None):
# """Return a TensorType containing given data"""
# data = numpy.asarray(data)
# if broadcastable is None:
# broadcastable = [s==1 for s in data.shape]
# elif broadcastable in [0, 1]:
# broadcastable = [broadcastable] * len(data.shape)
# rval = TensorType(data.dtype, broadcastable, name)
# rval.data = data # will raise if broadcastable was mis-specified
# return rval
# class T_tensor(unittest.TestCase):
# def setUp(self):
# utt.seed_rng()
# def test0(self): # allocate from a scalar float
# t = _tensor(1.0)
# self.assertTrue(isinstance(t, TensorType))
# self.assertTrue(t.dtype == 'float64')
# self.assertTrue(t.broadcastable == ())
# self.assertTrue(t.role == None)
# self.assertTrue(isinstance(t.data, numpy.ndarray))
# self.assertTrue(str(t.data.dtype) == 'float64')
# self.assertTrue(t.data == 1.0)
# def test0_int(self): # allocate from a scalar float
# t = _tensor(1)
# self.assertTrue(isinstance(t, TensorType))
# self.assertTrue(t.dtype == 'int64' or t.dtype == 'int32')
# def test1(self): # allocate from a vector of ints, not broadcastable
# t = _tensor(numpy.ones(5,dtype='int32'))
# self.assertTrue(isinstance(t, TensorType))
# self.assertTrue(t.dtype == 'int32')
# self.assertTrue(t.broadcastable == (0,))
# self.assertTrue(isinstance(t.data, numpy.ndarray))
# self.assertTrue(str(t.data.dtype) == 'int32')
# def test2(self): # allocate from a column matrix of complex with name
# t = _tensor(numpy.ones((5,1),dtype='complex64'),name='bart')
# self.assertTrue(isinstance(t, TensorType))
# self.assertTrue(t.dtype == 'complex64')
# self.assertTrue(t.broadcastable == (0,1))
# self.assertTrue(isinstance(t.data, numpy.ndarray))
# self.assertTrue(t.name == 'bart')
# def test2b(self): # allocate from a column matrix, not broadcastable
# t = _tensor(numpy.ones((5,1),dtype='complex64'),broadcastable=0)
# self.assertTrue(isinstance(t, TensorType))
# self.assertTrue(t.dtype == 'complex64')
# self.assertTrue(t.broadcastable == (0,0))
# self.assertTrue(isinstance(t.data, numpy.ndarray))
# f = Function([t], [t], linker_cls=gof.CLinker)
# self.assertTrue(numpy.all(t.data == f(t.data)))
# def test_data_normal(self): #test that assigning to .data works when it should
# t = _tensor(numpy.ones((5,1),dtype='complex64'), broadcastable=0)
# o27 = numpy.ones((2,7), dtype='complex64')
# t.data = o27
# lst = t._data
# self.assertTrue(t.data.shape == (2,7))
# self.assertTrue(t.data is o27)
# self.assertTrue(t._data is lst)
# def test_data_badrank0(self):
# t = _tensor(numpy.ones((5,1),dtype='complex64'), broadcastable=0)
# try:
# t.data = numpy.ones((2,7,1))
# self.fail()
# except ValueError, e:
# self.assertTrue(e[0] is TensorType.filter.E_rank)
# try:
# t.data = numpy.ones(1)
# self.fail()
# except ValueError, e:
# self.assertTrue(e[0] is TensorType.filter.E_rank)
# def test_data_badrank1(self):
# t = _tensor(numpy.ones((1,1),dtype='complex64'), broadcastable=1)
# try:
# t.data = numpy.ones((1,1,1))
# self.fail()
# except ValueError, e:
# self.assertTrue(e[0] is TensorType.filter.E_rank)
# try:
# t.data = numpy.ones(1)
# self.fail()
# except ValueError, e:
# self.assertTrue(e[0] is TensorType.filter.E_rank)
# def test_data_badshape0(self):
# t = _tensor(numpy.ones((1,1),dtype='complex64'), broadcastable=1)
# try:
# t.data = numpy.ones((1,2))
# self.fail()
# except ValueError, e:
# self.assertTrue(e[0] is TensorType.filter.E_shape)
# try:
# t.data = numpy.ones((0,1))
# self.fail()
# except ValueError, e:
# self.assertTrue(e[0] is TensorType.filter.E_shape)
# def test_cast0(self):
# t = TensorType('float32', [0])
# t.data = numpy.random.rand(4) > 0.5
# self.assertTrue(str(t.data.dtype) == t.dtype)
# class T_stdlib(unittest.TestCase):
# def test0(self):
# t = _tensor(1.0)
# tt = t.clone(False)
# self.assertTrue(t.dtype == tt.dtype)
# self.assertTrue(t.broadcastable is tt.broadcastable)
# self.assertTrue(tt.data is None)
# self.assertTrue(t.data == 1.0)
# def test0b(self):
# t = _tensor(1.0)
# tt = t.clone()
# self.assertTrue(t.dtype == tt.dtype)
# self.assertTrue(t.broadcastable is tt.broadcastable)
# self.assertTrue(tt.data is None)
# self.assertTrue(t.data == 1.0)
# def test1(self):
# t = _tensor(1.0)
# tt = t.clone(True)
# self.assertTrue(t.dtype == tt.dtype)
# self.assertTrue(t.broadcastable is tt.broadcastable)
# self.assertTrue(tt.data == 1.0)
# self.assertTrue(t.data == 1.0)
# self.assertTrue(t.data is not tt.data)
# def test1b(self):
# t = _tensor(1.0)
# tt = copy(t)
# self.assertTrue(t.dtype == tt.dtype)
# self.assertTrue(t.broadcastable is tt.broadcastable)
# self.assertTrue(tt.data == 1.0)
# self.assertTrue(t.data == 1.0)
# self.assertTrue(t.data is not tt.data)
class
test_grad
(
unittest
.
TestCase
):
class
O
(
gof
.
op
.
Op
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论