Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
fbef8859
提交
fbef8859
authored
7月 16, 2015
作者:
--global
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add test for local_sum_prod_mul_by_scalar
上级
de826376
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
91 行增加
和
0 行删除
+91
-0
test_opt.py
theano/tensor/tests/test_opt.py
+91
-0
没有找到文件。
theano/tensor/tests/test_opt.py
浏览文件 @
fbef8859
...
@@ -4499,6 +4499,97 @@ class T_local_sum_prod(unittest.TestCase):
...
@@ -4499,6 +4499,97 @@ class T_local_sum_prod(unittest.TestCase):
self
.
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'canonicalize'
,
self
.
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'canonicalize'
,
'specialize'
)
'specialize'
)
def
test_local_sum_prod_mul_by_scalar
(
self
):
# Test the optimization local_sum_prod_mul_by_scalar for both Sum and
# Prod ops in six cases each :
# 1-the inputs to the mul contain a scalar and no non-scalar
# 2-the inputs to the mul contain a scalar and one non-scalar
# 3-the inputs to the mul contain a scalar and two non-scalars
# 4-the inputs to the mul contain two scalars and no non-scalar
# 5-the inputs to the mul contain two scalars and one non-scalar
# 6-the inputs to the mul contain two scalars and two non-scalars
vect
=
T
.
dvector
()
mat
=
T
.
dmatrix
()
scalar1
=
T
.
dscalar
()
scalar2
=
T
.
dscalar
()
v_val
=
numpy
.
random
.
rand
(
2
)
m_val
=
numpy
.
random
.
rand
(
2
,
2
)
s1_val
=
numpy
.
random
.
rand
()
s2_val
=
numpy
.
random
.
rand
()
# Test sum
def
test_sum_opt
(
inputs
,
inputs_val
,
expected_output
):
mul_out
=
T
.
mul
(
*
inputs
)
f
=
theano
.
function
(
inputs
,
T
.
sum
(
mul_out
),
mode
=
self
.
mode
)
out
=
f
(
*
inputs_val
)
utt
.
assert_allclose
(
out
,
expected_output
)
# Case 1
test_sum_opt
([
scalar1
],
[
s1_val
],
s1_val
)
# Case 2
test_sum_opt
([
vect
,
scalar1
],
[
v_val
,
s1_val
],
s1_val
*
v_val
.
sum
())
# Case 3# Case 1
test_sum_opt
([
scalar1
],
[
s1_val
],
s1_val
)
# Case 2
test_sum_opt
([
vect
,
scalar1
],
[
v_val
,
s1_val
],
s1_val
*
v_val
.
sum
())
# Case 3
test_sum_opt
([
vect
,
mat
,
scalar1
],
[
v_val
,
m_val
,
s1_val
],
s1_val
*
(
v_val
*
m_val
)
.
sum
())
# Case 4
test_sum_opt
([
scalar1
,
scalar2
],
[
s1_val
,
s2_val
],
s1_val
*
s2_val
)
# Case 5
test_sum_opt
([
vect
,
scalar1
,
scalar2
],
[
v_val
,
s1_val
,
s2_val
],
s1_val
*
s2_val
*
v_val
.
sum
())
# Case 6
test_sum_opt
([
vect
,
mat
,
scalar1
,
scalar2
],
[
v_val
,
m_val
,
s1_val
,
s2_val
],
s1_val
*
s2_val
*
(
v_val
*
m_val
)
.
sum
())
# Test prod
def
test_prod_opt
(
inputs
,
inputs_val
,
expected_output
):
mul_out
=
T
.
mul
(
*
inputs
)
f
=
theano
.
function
(
inputs
,
T
.
prod
(
mul_out
),
mode
=
self
.
mode
)
out
=
f
(
*
inputs_val
)
utt
.
assert_allclose
(
out
,
expected_output
)
# Case 1
test_prod_opt
([
scalar1
],
[
s1_val
],
s1_val
)
# Case 2
test_prod_opt
([
vect
,
scalar1
],
[
v_val
,
s1_val
],
(
s1_val
*
v_val
)
.
prod
())
# Case 3
test_prod_opt
([
vect
,
mat
,
scalar1
],
[
v_val
,
m_val
,
s1_val
],
(
s1_val
*
v_val
*
m_val
)
.
prod
())
# Case 4
test_prod_opt
([
scalar1
,
scalar2
],
[
s1_val
,
s2_val
],
s1_val
*
s2_val
)
# Case 5
test_prod_opt
([
vect
,
scalar1
,
scalar2
],
[
v_val
,
s1_val
,
s2_val
],
(
s1_val
*
s2_val
*
v_val
)
.
prod
())
# Case 6
test_prod_opt
([
vect
,
mat
,
scalar1
,
scalar2
],
[
v_val
,
m_val
,
s1_val
,
s2_val
],
(
s1_val
*
s2_val
*
v_val
*
m_val
)
.
prod
())
def
test_local_sum_prod_all_to_none
(
self
):
def
test_local_sum_prod_all_to_none
(
self
):
a
=
T
.
tensor3
()
a
=
T
.
tensor3
()
input
=
numpy
.
arange
(
3
*
4
*
5
,
dtype
=
config
.
floatX
)
.
reshape
(
3
,
4
,
5
)
input
=
numpy
.
arange
(
3
*
4
*
5
,
dtype
=
config
.
floatX
)
.
reshape
(
3
,
4
,
5
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论