Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8685e8cb
提交
8685e8cb
authored
2月 13, 2014
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix get_scalar_constant_value().
上级
9ca3be9c
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
26 行增加
和
14 行删除
+26
-14
basic.py
theano/tensor/basic.py
+26
-14
没有找到文件。
theano/tensor/basic.py
浏览文件 @
8685e8cb
...
...
@@ -590,14 +590,23 @@ def get_scalar_constant_value(v):
v
.
owner
.
op
.
perform
(
v
.
owner
,
const
,
ret
)
return
ret
[
0
][
0
]
if
isinstance
(
v
.
owner
.
op
,
theano
.
tensor
.
subtensor
.
Subtensor
)
and
v
.
ndim
==
0
:
# This condition depends on Subtensor always embedding constant
# indices in the Op rather than making them inputs to the Apply
# node.
if
isinstance
(
v
.
owner
.
inputs
[
0
],
TensorConstant
)
and
\
len
(
v
.
owner
.
inputs
)
==
1
:
if
isinstance
(
v
.
owner
.
inputs
[
0
],
TensorConstant
):
indices
=
list
(
reversed
(
list
(
v
.
owner
.
inputs
[
1
:])))
def
conv
(
e
):
if
isintance
(
e
,
gof
.
Type
):
return
get_constant_scalar_value
(
indices
.
pop
())
elif
isinstance
(
e
,
slice
):
return
slice
(
conv
(
e
.
start
),
conv
(
e
.
stop
),
conv
(
e
.
step
))
elif
isintance
(
e
,
(
int
,
long
,
numpy
.
integer
)):
return
int
(
e
)
else
:
raise
NotScalarConstantError
(
v
)
cdata
=
tuple
(
map
(
conv
,
v
.
owner
.
op
.
idx_list
))
try
:
return
v
.
owner
.
inputs
[
0
]
.
data
.
__getitem__
(
tuple
(
v
.
owner
.
op
.
idx_list
))
return
v
.
owner
.
inputs
[
0
]
.
data
.
__getitem__
(
cdata
)
except
IndexError
:
raise
IndexError
(
str
(
tuple
(
v
.
owner
.
op
.
idx_list
))
+
...
...
@@ -620,10 +629,12 @@ def get_scalar_constant_value(v):
v
.
owner
.
inputs
[
0
]
.
owner
.
inputs
)
and
len
(
v
.
owner
.
op
.
idx_list
)
==
1
):
idx
=
v
.
owner
.
op
.
idx_list
[
0
]
if
isinstance
(
idx
,
gof
.
Type
):
idx
=
get_scalar_constant_value
(
v
.
owner
.
inputs
[
1
])
# Note the '+ 1' is because the first argument to Join is the
# axis.
ret
=
v
.
owner
.
inputs
[
0
]
.
owner
.
inputs
[
v
.
owner
.
op
.
idx_list
[
0
]
+
1
]
ret
=
v
.
owner
.
inputs
[
0
]
.
owner
.
inputs
[
idx
+
1
]
ret
=
get_scalar_constant_value
(
ret
)
# join can cast implicitly its input in some case.
return
theano
.
_asarray
(
ret
,
dtype
=
v
.
type
.
dtype
)
...
...
@@ -636,13 +647,12 @@ def get_scalar_constant_value(v):
python_all
(
var
.
ndim
==
0
for
var
in
v
.
owner
.
inputs
[
0
]
.
owner
.
inputs
)
and
len
(
v
.
owner
.
op
.
idx_list
)
==
1
and
#idx_list can contain Scalar Type object.
isinstance
(
v
.
owner
.
op
.
idx_list
[
0
],
(
int
,
long
,
numpy
.
integer
))):
idx
=
v
.
owner
.
op
.
idx_list
[
0
]
if
isinstance
(
idx
,
gof
.
Type
):
idx
=
get_scalar_constant_value
(
v
.
owner
.
inputs
[
1
])
# Python 2.4 does not support indexing with numpy.integer
# So we cast it.
idx
=
int
(
v
.
owner
.
op
.
idx_list
[
0
]
)
idx
=
int
(
idx
)
ret
=
v
.
owner
.
inputs
[
0
]
.
owner
.
inputs
[
idx
]
ret
=
get_scalar_constant_value
(
ret
)
# MakeVector can cast implicitly its input in some case.
...
...
@@ -658,6 +668,8 @@ def get_scalar_constant_value(v):
op
=
owner
.
op
idx_list
=
op
.
idx_list
idx
=
idx_list
[
0
]
if
isinstance
(
idx
,
gof
.
Type
):
idx
=
get_scalar_constant_value
(
owner
.
inputs
[
1
])
grandparent
=
leftmost_parent
.
owner
.
inputs
[
0
]
gp_broadcastable
=
grandparent
.
type
.
broadcastable
ndim
=
grandparent
.
type
.
ndim
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论