Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
494a4c6f
提交
494a4c6f
authored
12月 09, 2013
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
get_scalar_constant_value() support more Elewmise op.
Needed to detect the right broadcast pattern.
上级
95938fe8
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
34 行增加
和
14 行删除
+34
-14
basic.py
theano/tensor/basic.py
+18
-13
test_basic.py
theano/tensor/tests/test_basic.py
+15
-0
test_opt.py
theano/tensor/tests/test_opt.py
+1
-1
没有找到文件。
theano/tensor/basic.py
浏览文件 @
494a4c6f
...
@@ -559,26 +559,31 @@ def get_scalar_constant_value(v):
...
@@ -559,26 +559,31 @@ def get_scalar_constant_value(v):
compile
.
ops
.
OutputGuard
,
compile
.
ops
.
OutputGuard
,
compile
.
DeepCopyOp
)):
compile
.
DeepCopyOp
)):
return
get_scalar_constant_value
(
v
.
owner
.
inputs
[
0
])
return
get_scalar_constant_value
(
v
.
owner
.
inputs
[
0
])
if
isinstance
(
v
.
owner
.
op
,
Elemwise
)
and
\
isinstance
(
v
.
owner
.
op
.
scalar_op
,
scal
.
Second
):
shape
,
val
=
v
.
owner
.
inputs
return
get_scalar_constant_value
(
val
)
if
isinstance
(
v
.
owner
.
op
,
scal
.
Second
):
x
,
y
=
v
.
owner
.
inputs
return
get_scalar_constant_value
(
y
)
if
(
isinstance
(
v
.
owner
.
op
,
theano
.
compile
.
ops
.
Shape_i
)
and
if
(
isinstance
(
v
.
owner
.
op
,
theano
.
compile
.
ops
.
Shape_i
)
and
isinstance
(
v
.
owner
.
inputs
[
0
],
Constant
)):
isinstance
(
v
.
owner
.
inputs
[
0
],
Constant
)):
return
v
.
owner
.
inputs
[
0
]
.
data
.
shape
[
v
.
owner
.
op
.
i
]
return
v
.
owner
.
inputs
[
0
]
.
data
.
shape
[
v
.
owner
.
op
.
i
]
# Don't act as the constant_folding optimization here as this
# Don't act as the constant_folding optimization here as this
# fct is used too early in the optimization phase. This would
# fct is used too early in the optimization phase. This would
# mess with the stabilization optimization.
# mess with the stabilization optimization and be too slow.
if
(
isinstance
(
v
.
owner
.
op
,
Elemwise
)
and
isinstance
(
# We put all the scalar Ops used by get_canonical_form_slice()
v
.
owner
.
op
.
scalar_op
,
scal
.
Cast
))
or
\
# to allow it to determine the broadcast pattern correctly.
isinstance
(
v
.
owner
.
op
,
scal
.
Cast
):
elemwises
=
(
scal
.
Cast
,
scal
.
Switch
,
const
=
get_scalar_constant_value
(
v
.
owner
.
inputs
[
0
])
scal
.
NEQ
,
scal
.
EQ
,
scal
.
LT
,
scal
.
GT
,
scal
.
LE
,
scal
.
GE
,
scal
.
Sub
,
scal
.
Add
,
scal
.
Mod
,
scal
.
Mul
,
scal
.
IntDiv
,
scal
.
TrueDiv
,
scal
.
Second
)
if
(
isinstance
(
v
.
owner
.
op
,
Elemwise
)
and
len
(
v
.
owner
.
outputs
)
==
1
and
(
isinstance
(
v
.
owner
.
op
.
scalar_op
,
elemwises
)
or
isinstance
(
v
.
owner
.
op
,
elemwises
))):
try
:
const
=
[
get_scalar_constant_value
(
i
)
for
i
in
v
.
owner
.
inputs
]
ret
=
[[
None
]]
ret
=
[[
None
]]
v
.
owner
.
op
.
perform
(
v
.
owner
,
[
const
]
,
ret
)
v
.
owner
.
op
.
perform
(
v
.
owner
,
const
,
ret
)
return
ret
[
0
][
0
]
return
ret
[
0
][
0
]
except
NotScalarConstantError
:
pass
if
isinstance
(
v
.
owner
.
op
,
theano
.
tensor
.
subtensor
.
Subtensor
)
and
v
.
ndim
==
0
:
if
isinstance
(
v
.
owner
.
op
,
theano
.
tensor
.
subtensor
.
Subtensor
)
and
v
.
ndim
==
0
:
# This condition depends on Subtensor always embedding constant
# This condition depends on Subtensor always embedding constant
# indices in the Op rather than making them inputs to the Apply
# indices in the Op rather than making them inputs to the Apply
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
494a4c6f
...
@@ -5928,6 +5928,21 @@ class T_get_scalar_constant_value(unittest.TestCase):
...
@@ -5928,6 +5928,21 @@ class T_get_scalar_constant_value(unittest.TestCase):
s
=
opt
.
Shape_i
(
1
)(
c
)
s
=
opt
.
Shape_i
(
1
)(
c
)
assert
get_scalar_constant_value
(
s
)
==
4
assert
get_scalar_constant_value
(
s
)
==
4
def
test_elemwise
(
self
):
# We test only for a few elemwise, the list of all supported
# elemwise are in the fct.
c
=
theano
.
tensor
.
constant
(
numpy
.
random
.
rand
())
s
=
c
+
1
assert
get_scalar_constant_value
(
s
)
==
c
.
data
+
1
s
=
c
-
1
assert
get_scalar_constant_value
(
s
)
==
c
.
data
-
1
s
=
c
*
1.2
assert
get_scalar_constant_value
(
s
)
==
c
.
data
*
1.2
s
=
c
<
0.5
assert
get_scalar_constant_value
(
s
)
==
int
(
c
.
data
<
0.5
)
s
=
tensor
.
second
(
c
,
.
4
)
assert
get_scalar_constant_value
(
s
)
==
.
4
class
T_as_tensor_variable
(
unittest
.
TestCase
):
class
T_as_tensor_variable
(
unittest
.
TestCase
):
"""
"""
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
494a4c6f
...
@@ -2408,7 +2408,7 @@ def test_local_subtensor_of_alloc():
...
@@ -2408,7 +2408,7 @@ def test_local_subtensor_of_alloc():
for
slices
in
slicess
:
for
slices
in
slicess
:
z
=
yx
.
__getitem__
(
slices
)
z
=
yx
.
__getitem__
(
slices
)
f
=
theano
.
function
([
x
],
z
)
f
=
theano
.
function
([
x
],
z
)
theano
.
printing
.
debugprint
(
f
)
#
theano.printing.debugprint(f)
# if theano.config.mode != 'FAST_COMPILE':
# if theano.config.mode != 'FAST_COMPILE':
# assert not any([isinstance(node.op, Subtensor)
# assert not any([isinstance(node.op, Subtensor)
# for node in f.maker.fgraph.toposort()])
# for node in f.maker.fgraph.toposort()])
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论