Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
eaf79124
提交
eaf79124
authored
3月 23, 2008
作者:
olivier@olivier-desktop
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
made tests use DualLinker
上级
e22a5f23
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
28 行增加
和
7 行删除
+28
-7
_test_tensor.py
_test_tensor.py
+28
-7
没有找到文件。
_test_tensor.py
浏览文件 @
eaf79124
...
@@ -9,6 +9,16 @@ import gof, gof.graph
...
@@ -9,6 +9,16 @@ import gof, gof.graph
from
gof.python25
import
any
from
gof.python25
import
any
def
_numpy_checker
(
x
,
y
):
"""
Checks if x.data and y.data have the same contents.
Used in DualLinker to compare C version with Python version.
"""
if
(
x
.
data
!=
y
.
data
)
.
any
():
raise
Exception
(
"Output mismatch."
,
{
'performlinker'
:
x
.
data
,
'clinker'
:
y
.
data
})
#TODO: consider moving this function / functionality to gradient.py
#TODO: consider moving this function / functionality to gradient.py
# rationale: it's tricky, and necessary everytime you want to verify
# rationale: it's tricky, and necessary everytime you want to verify
# gradient numerically
# gradient numerically
...
@@ -82,6 +92,11 @@ def check_eq2_c(self, inputs, output, args_in, arg_out):
...
@@ -82,6 +92,11 @@ def check_eq2_c(self, inputs, output, args_in, arg_out):
val
=
fn
(
*
args_in
)
val
=
fn
(
*
args_in
)
self
.
failUnless
(
numpy
.
all
(
val
==
arg_out
),
(
val
,
arg_out
))
self
.
failUnless
(
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
.
failUnless
(
numpy
.
all
(
val
==
arg_out
),
(
val
,
arg_out
))
class
T_argmax
(
unittest
.
TestCase
):
class
T_argmax
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
numpy
.
random
.
seed
(
123784
)
numpy
.
random
.
seed
(
123784
)
...
@@ -408,24 +423,24 @@ class T_mul(unittest.TestCase):
...
@@ -408,24 +423,24 @@ class T_mul(unittest.TestCase):
def
test_elemwise
(
self
):
def
test_elemwise
(
self
):
a
=
astensor
(
0.0
)
a
=
astensor
(
0.0
)
b
=
astensor
(
0.0
)
b
=
astensor
(
0.0
)
check_eq2
(
self
,
[
a
,
b
],
mul_elemwise
(
a
,
b
),
[
3.0
,
4.0
],
12.0
)
check_eq2
_both
(
self
,
[
a
,
b
],
mul_elemwise
(
a
,
b
),
[
3.0
,
4.0
],
12.0
)
check_eq2
(
self
,
[
a
,
b
],
mul_elemwise
(
b
,
a
),
[
-
1.0
,
2.0
],
-
2.0
)
check_eq2
_both
(
self
,
[
a
,
b
],
mul_elemwise
(
b
,
a
),
[
-
1.0
,
2.0
],
-
2.0
)
self
.
failUnless
(
isinstance
(
mul
(
a
,
b
)
.
owner
,
Scale
))
self
.
failUnless
(
isinstance
(
mul
(
a
,
b
)
.
owner
,
Scale
))
a
=
astensor
(
numpy
.
ones
(
2
))
a
=
astensor
(
numpy
.
ones
(
2
))
b
=
astensor
(
numpy
.
ones
(
2
))
b
=
astensor
(
numpy
.
ones
(
2
))
aa
=
numpy
.
asarray
([
-
0.5
,
4.0
])
aa
=
numpy
.
asarray
([
-
0.5
,
4.0
])
bb
=
numpy
.
asarray
([
-
0.5
,
2.0
])
bb
=
numpy
.
asarray
([
-
0.5
,
2.0
])
check_eq2
(
self
,
[
a
,
b
],
mul_elemwise
(
a
,
b
),
[
aa
,
bb
],
numpy
.
asarray
([
0.25
,
8.0
]))
check_eq2
_both
(
self
,
[
a
,
b
],
mul_elemwise
(
a
,
b
),
[
aa
,
bb
],
numpy
.
asarray
([
0.25
,
8.0
]))
check_eq2
(
self
,
[
a
,
b
],
mul_elemwise
(
a
,
b
),
[
bb
,
aa
],
numpy
.
asarray
([
0.25
,
8.0
]))
check_eq2
_both
(
self
,
[
a
,
b
],
mul_elemwise
(
a
,
b
),
[
bb
,
aa
],
numpy
.
asarray
([
0.25
,
8.0
]))
self
.
failUnless
(
isinstance
(
mul
(
a
,
b
)
.
owner
,
MulElemwise
))
self
.
failUnless
(
isinstance
(
mul
(
a
,
b
)
.
owner
,
MulElemwise
))
def
test_scalar
(
self
):
def
test_scalar
(
self
):
r
=
numpy
.
random
.
rand
(
2
,
3
)
r
=
numpy
.
random
.
rand
(
2
,
3
)
a
=
astensor
(
r
)
a
=
astensor
(
r
)
b
=
astensor
(
2.0
)
b
=
astensor
(
2.0
)
check_eq2
(
self
,
[
a
,
b
],
scale
(
a
,
b
),
[
r
,
2.0
],
r
*
2.0
)
check_eq2
_both
(
self
,
[
a
,
b
],
scale
(
a
,
b
),
[
r
,
2.0
],
r
*
2.0
)
check_eq2
(
self
,
[
a
,
b
],
scale
(
a
,
b
),
[
r
,
4.0
],
r
*
4.0
)
check_eq2
_both
(
self
,
[
a
,
b
],
scale
(
a
,
b
),
[
r
,
4.0
],
r
*
4.0
)
self
.
failUnless
(
b
.
data
==
2.0
)
self
.
failUnless
(
b
.
data
==
2.0
)
def
test_operator
(
self
):
def
test_operator
(
self
):
...
@@ -443,10 +458,16 @@ class T_mul(unittest.TestCase):
...
@@ -443,10 +458,16 @@ class T_mul(unittest.TestCase):
try
:
try
:
check_eq2
(
self
,
[
a
,
b
],
MulElemwise
(
a
,
b
)
.
out
,
check_eq2
(
self
,
[
a
,
b
],
MulElemwise
(
a
,
b
)
.
out
,
[
numpy
.
ones
(
3
),
numpy
.
ones
(
4
)],
1.0
)
[
numpy
.
ones
(
3
),
numpy
.
ones
(
4
)],
1.0
)
self
.
fail
()
except
ValueError
,
e
:
except
ValueError
,
e
:
self
.
failUnless
(
e
[
0
]
is
tensor
.
_assert_same_shapes
.
E_shape
)
self
.
failUnless
(
e
[
0
]
is
tensor
.
_assert_same_shapes
.
E_shape
)
return
try
:
check_eq2_c
(
self
,
[
a
,
b
],
MulElemwise
(
a
,
b
)
.
out
,
[
numpy
.
ones
(
3
),
numpy
.
ones
(
4
)],
1.0
)
self
.
fail
()
self
.
fail
()
except
ValueError
,
e
:
pass
class
T_div
(
unittest
.
TestCase
):
class
T_div
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论