Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
723c58f0
提交
723c58f0
authored
9月 01, 2008
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more tests in _test_compile.py
上级
85dbd796
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
181 行增加
和
1 行删除
+181
-1
_test_compile.py
_test_compile.py
+181
-1
没有找到文件。
_test_compile.py
浏览文件 @
723c58f0
...
@@ -9,6 +9,19 @@ import tensor
...
@@ -9,6 +9,19 @@ import tensor
PatternOptimizer
=
lambda
p1
,
p2
,
ign
=
True
:
gof
.
OpKeyOptimizer
(
gof
.
PatternSub
(
p1
,
p2
),
ignore_newtrees
=
ign
)
PatternOptimizer
=
lambda
p1
,
p2
,
ign
=
True
:
gof
.
OpKeyOptimizer
(
gof
.
PatternSub
(
p1
,
p2
),
ignore_newtrees
=
ign
)
def
checkfor
(
testcase
,
fn
,
E
):
try
:
fn
()
except
Exception
,
e
:
if
isinstance
(
e
,
E
):
# we got the exception we wanted
return
else
:
# we did not get the exception we wanted
raise
# fn worked, but it shouldn't have
testcase
.
fail
()
def
graph1
():
# (x+y) * (x/z)
def
graph1
():
# (x+y) * (x/z)
x
,
y
,
z
=
floats
(
'xyz'
)
x
,
y
,
z
=
floats
(
'xyz'
)
...
@@ -169,7 +182,174 @@ class T_OpFromGraph(unittest.TestCase):
...
@@ -169,7 +182,174 @@ class T_OpFromGraph(unittest.TestCase):
assert
numpy
.
all
(
11.0
==
fn
(
xv
,
yv
,
zv
))
assert
numpy
.
all
(
11.0
==
fn
(
xv
,
yv
,
zv
))
class
T_state
(
unittest
.
TestCase
):
class
T_function
(
unittest
.
TestCase
):
def
test_empty
(
self
):
fn
=
function
([],
[])
#ok
self
.
failunless
(
fn
()
==
[])
def
test_missing_inputs
(
self
):
raise
NotImplementedError
()
MissingInputException
=
None
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
fn
=
function
([],
[
x
])
checkfor
(
self
,
fn
,
MissingInputException
)
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
fn
=
function
([
s
],
[
x
])
checkfor
(
self
,
fn
,
MissingInputException
)
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
fn
=
function
([
s
],
x
)
checkfor
(
self
,
fn
,
MissingInputException
)
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
fn
=
function
([
s
],
Out
(
x
))
checkfor
(
self
,
fn
,
MissingInputException
)
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
fn
=
function
([
In
(
x
,
update
=
s
+
x
)],
x
)
checkfor
(
self
,
fn
,
MissingInputException
)
def
fn
():
x
,
s
=
T
.
scalars
(
'xs'
)
fn
=
function
([
In
(
x
,
update
=
mul
(
s
,
s
)
+
x
)],
x
)
checkfor
(
self
,
fn
,
MissingInputException
)
def
test_input_anon_singleton
(
self
):
x
,
s
=
T
.
scalars
(
'xs'
)
fn
=
function
([
s
,
x
],
[
x
+
s
])
self
.
failUnless
(
fn
(
2
,
3
)
==
[
5
])
# no state
self
.
failUnless
(
fn
(
2
,
3
)
==
[
5
])
def
test_input_anon_unpack
(
self
):
x
,
s
=
T
.
scalars
(
'xs'
)
fn
=
function
([
s
,
x
],
x
+
s
)
self
.
failUnless
(
fn
(
2
,
3
)
==
5
)
def
test_eq
(
self
):
x
,
s
=
T
.
scalars
(
'xs'
)
xx
,
ss
=
T
.
scalars
(
'xs'
)
f
=
function
([
x
,
s
],
x
+
s
)
ff
=
function
([
xx
,
ss
],
xx
+
ss
)
self
.
failUnless
(
f
==
ff
)
self
.
failUnless
(
f
!=
function
([
x
,
s
],
x
-
s
))
self
.
failUnless
(
ff
!=
function
([
x
,
s
],
x
-
s
))
def
test_naming_rule0
(
self
):
x
,
s
=
T
.
scalars
(
'xs'
)
f
=
function
([
x
,
s
],
x
/
s
)
self
.
failUnless
(
f
(
1
,
2
)
==
0.5
)
self
.
failUnless
(
f
(
2
,
1
)
==
2.0
)
self
.
failUnless
(
f
(
s
=
2
,
x
=
1
)
==
0.5
)
self
.
failUnless
(
f
(
x
=
2
,
s
=
1
)
==
2.0
)
self
.
failUnless
(
f
(
2
,
s
=
1
)
==
2.0
)
checkfor
(
self
,
lambda
:
f
(
2
,
x
=
2.0
),
TypeError
)
#got multiple values for keyword argument 'x'
checkfor
(
self
,
lambda
:
f
(
x
=
1
),
TypeError
)
#takes exactly 2 non-keyword arguments (1 given)
checkfor
(
self
,
lambda
:
f
(
s
=
1
),
TypeError
)
#takes exactly 2 non-keyword arguments (0 given)
def
test_naming_rule1
(
self
):
a
=
T
.
scalar
()
# the a is for 'anonymous' (un-named).
x
,
s
=
T
.
scalars
(
'xs'
)
f
=
function
([
a
,
s
],
a
/
s
)
self
.
failUnless
(
f
(
1
,
2
)
==
0.5
)
self
.
failUnless
(
f
(
2
,
1
)
==
2.0
)
self
.
failUnless
(
f
(
2
,
s
=
1
)
==
2.0
)
checkfor
(
self
,
lambda
:
f
(
q
=
2
,
s
=
1
),
TypeError
)
#got unexpected keyword argument 'q'
checkfor
(
self
,
lambda
:
f
(
a
=
2
,
s
=
1
),
TypeError
)
#got unexpected keyword argument 'a'
def
test_naming_rule2
(
self
):
a
=
T
.
scalar
()
# the a is for 'anonymous' (un-named).
x
,
s
=
T
.
scalars
(
'xs'
)
#x's name is ignored because it is followed by anonymous parameter a.
f
=
function
([
x
,
a
,
s
],
a
/
s
)
self
.
failUnless
(
f
(
9
,
1
,
2
)
==
0.5
)
self
.
failUnless
(
f
(
9
,
2
,
1
)
==
2.0
)
self
.
failUnless
(
f
(
9
,
2
,
s
=
1
)
==
2.0
)
checkfor
(
self
,
lambda
:
f
(
x
=
9
,
a
=
2
,
s
=
1
),
TypeError
)
#got unexpected keyword argument 'x'
checkfor
(
self
,
lambda
:
f
(
5.0
,
x
=
9
),
TypeError
)
#got unexpected keyword argument 'x'
def
test_naming_rule3
(
self
):
a
=
T
.
scalar
()
# the a is for 'anonymous' (un-named).
x
,
s
=
T
.
scalars
(
'xs'
)
#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
)
self
.
failUnless
(
f
(
9
,
2
,
4
)
==
9.5
)
#can specify all args in order
self
.
failUnless
(
f
(
9
,
2
,
s
=
4
)
==
9.5
)
# can give s as kwarg
self
.
failUnless
(
f
(
9
,
s
=
4
)
==
9.25
)
# can give s as kwarg, get default a
self
.
failUnless
(
f
(
x
=
9
,
s
=
4
)
==
9.25
)
# can give s as kwarg, omit a, x as kw
checkfor
(
self
,
lambda
:
f
(
x
=
9
,
a
=
2
,
s
=
4
),
TypeError
)
#got unexpected keyword argument 'a'
checkfor
(
self
,
lambda
:
f
(),
TypeError
)
#takes exactly 3 non-keyword arguments (0 given)
checkfor
(
self
,
lambda
:
f
(
x
=
9
),
TypeError
)
#takes exactly 3 non-keyword arguments (1 given)
def
test_naming_rule4
(
self
):
a
=
T
.
scalar
()
# the a is for 'anonymous' (un-named).
x
,
s
=
T
.
scalars
(
'xs'
)
f
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
s
],
a
/
s
+
x
)
self
.
failUnless
(
f
(
9
,
2
,
4
)
==
9.5
)
#can specify all args in order
self
.
failUnless
(
f
(
9
,
2
,
s
=
4
)
==
9.5
)
# can give s as kwarg
self
.
failUnless
(
f
(
9
,
s
=
4
)
==
9.25
)
# can give s as kwarg, get default a
self
.
failUnless
(
f
(
9
,
a
=
2
,
s
=
4
)
==
9.5
)
# can give s as kwarg, a as kwarg
self
.
failUnless
(
f
(
x
=
9
,
a
=
2
,
s
=
4
)
==
9.5
)
# can give all kwargs
self
.
failUnless
(
f
(
x
=
9
,
s
=
4
)
==
9.25
)
# can give all kwargs
checkfor
(
self
,
lambda
:
f
(),
TypeError
)
#takes exactly 3 non-keyword arguments (0 given)
checkfor
(
self
,
lambda
:
f
(
5.0
,
x
=
9
),
TypeError
)
#got multiple values for keyword argument 'x'
def
test_state_acces
(
self
):
a
=
T
.
scalar
()
# the a is for 'anonymous' (un-named).
x
,
s
=
T
.
scalars
(
'xs'
)
f
=
function
([
x
,
In
(
a
,
value
=
1.0
,
name
=
'a'
),
In
(
s
,
value
=
0.0
,
update
=
s
+
a
*
x
)],
s
+
a
*
x
)
self
.
failUnless
(
f
.
a
==
1.0
)
self
.
failUnless
(
f
.
state
[
a
]
is
f
.
a
)
self
.
failUnless
(
f
.
s
==
0.0
)
self
.
failUnless
(
f
.
state
[
s
]
is
f
.
s
)
self
.
failUnless
(
f
(
3.0
)
==
3.0
)
self
.
failUnless
(
f
(
3.0
,
a
=
2.0
)
==
9.0
)
#3.0 + 2*3.0
self
.
failUnless
(
f
.
a
==
1.0
)
#state hasn't changed permanently, we just overrode it last line
self
.
failUnless
(
f
.
s
==
9.0
)
f
.
a
=
5.0
self
.
failUnless
(
f
.
a
==
5.0
)
self
.
failUnless
(
f
.
state
[
a
]
is
f
.
a
)
self
.
failUnless
(
f
(
3.0
)
==
24.0
)
#9 + 3*5
self
.
failUnless
(
f
.
s
==
24.0
)
self
.
failUnless
(
f
.
state
[
s
]
is
f
.
s
)
def
test_same_names
(
self
):
a
,
x
,
s
=
T
.
scalars
(
'xxx'
)
#implicit names would cause error. What do we do?
f
=
function
([
a
,
x
,
s
],
a
+
x
+
s
)
raise
NotImplementedError
()
def
test_weird_names
(
self
):
a
,
x
,
s
=
T
.
scalars
(
'xxx'
)
checkfor
(
self
,
lambda
:
function
([
In
(
a
,
name
=
[])],[]),
UnhashableName
)
f
=
function
([
In
(
a
,
name
=
set
([
'adsf'
,())],
value
=
1.0
),
In
(
x
,
name
=
(),
value
=
2.0
),
In
(
s
,
name
=
T
.
scalar
(),
value
=
3.0
)],
a
+
x
+
s
)
def
test_accumulator
(
self
):
def
test_accumulator
(
self
):
"""Test low-level interface with state."""
"""Test low-level interface with state."""
x
=
T
.
scalar
(
'x'
)
x
=
T
.
scalar
(
'x'
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论