Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7b7b6618
提交
7b7b6618
authored
9月 15, 2015
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Don't introduce useless prod op
上级
219d33bf
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
9 行增加
和
7 行删除
+9
-7
opt.py
theano/tensor/opt.py
+5
-4
test_opt.py
theano/tensor/tests/test_opt.py
+2
-2
var.py
theano/tensor/var.py
+2
-1
没有找到文件。
theano/tensor/opt.py
浏览文件 @
7b7b6618
...
@@ -4081,28 +4081,29 @@ def local_sum_prod_mul_by_scalar(node):
...
@@ -4081,28 +4081,29 @@ def local_sum_prod_mul_by_scalar(node):
"""
"""
# TODO: if the the thing inside the Sum is a division,
# TODO: if the the thing inside the Sum is a division,
# we should get at the numerator....
# we should get at the numerator....
if
isinstance
(
node
.
op
,
T
.
Sum
)
or
isinstance
(
node
.
op
,
T
.
elemwise
.
Prod
):
if
isinstance
(
node
.
op
,
(
T
.
Sum
,
T
.
elemwise
.
Prod
)
):
node_inps
,
=
node
.
inputs
node_inps
,
=
node
.
inputs
if
node_inps
.
owner
and
node_inps
.
owner
.
op
==
T
.
mul
:
if
node_inps
.
owner
and
node_inps
.
owner
.
op
==
T
.
mul
:
terms
=
node_inps
.
owner
.
inputs
terms
=
node_inps
.
owner
.
inputs
scalars
=
[
t
.
dimshuffle
()
for
t
in
terms
if
scalars
=
[
t
.
dimshuffle
()
for
t
in
terms
if
numpy
.
all
(
t
.
type
.
broadcastable
)]
numpy
.
all
(
t
.
type
.
broadcastable
)]
non_scalars
=
[
t
for
t
in
terms
if
not
numpy
.
all
(
t
.
broadcastable
)]
if
len
(
scalars
)
==
0
:
if
len
(
scalars
)
==
0
:
# Nothing to optimize here
# Nothing to optimize here
return
return
non_scalars
=
[
t
for
t
in
terms
if
not
numpy
.
all
(
t
.
broadcastable
)]
# Perform the op only on the non-scalar inputs, if applicable
# Perform the op only on the non-scalar inputs, if applicable
if
len
(
non_scalars
)
==
0
:
if
len
(
non_scalars
)
==
0
:
new_op_input_nb_elements
=
1
new_op_input_nb_elements
=
1
new_op_output
=
1
new_op_output
=
1
elif
len
(
non_scalars
)
==
1
:
elif
len
(
non_scalars
)
==
1
:
new_op_input_nb_elements
=
T
.
prod
(
non_scalars
[
0
]
.
shape
)
new_op_input_nb_elements
=
non_scalars
[
0
]
.
size
new_op_output
=
node
.
op
(
non_scalars
[
0
])
new_op_output
=
node
.
op
(
non_scalars
[
0
])
else
:
else
:
new_op_input
=
T
.
mul
(
*
non_scalars
)
new_op_input
=
T
.
mul
(
*
non_scalars
)
new_op_input_nb_elements
=
T
.
prod
(
new_op_input
.
shape
)
new_op_input_nb_elements
=
new_op_input
.
size
new_op_output
=
node
.
op
(
new_op_input
)
new_op_output
=
node
.
op
(
new_op_input
)
# If node.op is a T.elemwise.Prod, then the scalars need to be
# If node.op is a T.elemwise.Prod, then the scalars need to be
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
7b7b6618
...
@@ -4568,7 +4568,7 @@ class T_local_sum_prod(unittest.TestCase):
...
@@ -4568,7 +4568,7 @@ class T_local_sum_prod(unittest.TestCase):
# Case 2
# Case 2
test_reduction_opt
([
vect
,
scalar1
],
[
v_val
,
s1_val
],
T
.
elemwise
.
Prod
,
test_reduction_opt
([
vect
,
scalar1
],
[
v_val
,
s1_val
],
T
.
elemwise
.
Prod
,
(
s1_val
*
v_val
)
.
prod
(),
2
)
(
s1_val
*
v_val
)
.
prod
(),
1
)
# Case 3
# Case 3
test_reduction_opt
([
vect
,
mat
,
scalar1
],
[
v_val
,
m_val
,
s1_val
],
test_reduction_opt
([
vect
,
mat
,
scalar1
],
[
v_val
,
m_val
,
s1_val
],
...
@@ -4581,7 +4581,7 @@ class T_local_sum_prod(unittest.TestCase):
...
@@ -4581,7 +4581,7 @@ class T_local_sum_prod(unittest.TestCase):
# Case 5
# Case 5
test_reduction_opt
([
vect
,
scalar1
,
scalar2
],
[
v_val
,
s1_val
,
s2_val
],
test_reduction_opt
([
vect
,
scalar1
,
scalar2
],
[
v_val
,
s1_val
,
s2_val
],
T
.
elemwise
.
Prod
,
(
s1_val
*
s2_val
*
v_val
)
.
prod
(),
T
.
elemwise
.
Prod
,
(
s1_val
*
s2_val
*
v_val
)
.
prod
(),
2
)
1
)
# Case 6
# Case 6
test_reduction_opt
([
vect
,
mat
,
scalar1
,
scalar2
],
test_reduction_opt
([
vect
,
mat
,
scalar1
,
scalar2
],
...
...
theano/tensor/var.py
浏览文件 @
7b7b6618
...
@@ -280,7 +280,8 @@ class _tensor_py_operators:
...
@@ -280,7 +280,8 @@ class _tensor_py_operators:
shape
=
property
(
lambda
self
:
theano
.
tensor
.
basic
.
shape
(
self
))
shape
=
property
(
lambda
self
:
theano
.
tensor
.
basic
.
shape
(
self
))
size
=
property
(
lambda
self
:
theano
.
tensor
.
basic
.
prod
(
self
.
shape
))
size
=
property
(
lambda
self
:
self
.
shape
[
0
]
if
self
.
ndim
==
1
else
theano
.
tensor
.
basic
.
prod
(
self
.
shape
))
# We can't implement __len__ to provide a better error message.
# We can't implement __len__ to provide a better error message.
def
any
(
self
,
axis
=
None
,
keepdims
=
False
):
def
any
(
self
,
axis
=
None
,
keepdims
=
False
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论