Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7857774b
提交
7857774b
authored
10月 05, 2020
作者:
Brandon T. Willard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename and refactor subtensor.make_constant
上级
25defabd
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
28 行增加
和
20 行删除
+28
-20
opt.py
theano/tensor/opt.py
+2
-2
subtensor.py
theano/tensor/subtensor.py
+21
-15
var.py
theano/tensor/var.py
+5
-3
没有找到文件。
theano/tensor/opt.py
浏览文件 @
7857774b
...
...
@@ -50,7 +50,7 @@ from theano.tensor.subtensor import (
get_canonical_form_slice
,
Subtensor
,
IncSubtensor
,
make
_constant
,
as_index
_constant
,
AdvancedIncSubtensor1
,
AdvancedIncSubtensor
,
AdvancedSubtensor1
,
...
...
@@ -3388,7 +3388,7 @@ def local_subtensor_merge(node):
else
:
merged_slices
+=
slices1
[
pos_1
:]
merged_slices
=
make_constant
(
merged_slices
)
merged_slices
=
tuple
(
as_index_constant
(
s
)
for
s
in
merged_slices
)
subtens
=
Subtensor
(
merged_slices
)
sl_ins
=
Subtensor
.
collapse
(
...
...
theano/tensor/subtensor.py
浏览文件 @
7857774b
...
...
@@ -51,21 +51,25 @@ class AdvancedBooleanIndexingError(TypeError):
pass
def
make_constant
(
args
):
"""Convert Python literals to Theano constants in Subtensor arguments."""
def
conv
(
a
):
if
a
is
None
:
return
a
elif
isinstance
(
a
,
slice
):
return
slice
(
conv
(
a
.
start
),
conv
(
a
.
stop
),
conv
(
a
.
step
))
elif
isinstance
(
a
,
(
integer_types
,
np
.
integer
)):
return
scal
.
ScalarConstant
(
scal
.
int64
,
a
)
else
:
# Use `tensor.scalar_from_tensor`?
return
a
def
as_index_constant
(
a
):
"""Convert Python literals to Theano constants--when possible--in Subtensor arguments.
return
tuple
(
map
(
conv
,
args
))
This will leave `Variable`s untouched.
"""
if
a
is
None
:
return
a
elif
isinstance
(
a
,
slice
):
return
slice
(
as_index_constant
(
a
.
start
),
as_index_constant
(
a
.
stop
),
as_index_constant
(
a
.
step
),
)
elif
isinstance
(
a
,
(
integer_types
,
np
.
integer
)):
return
scal
.
ScalarConstant
(
scal
.
int64
,
a
)
elif
not
isinstance
(
a
,
theano
.
tensor
.
Variable
):
return
theano
.
tensor
.
as_tensor
(
a
)
else
:
return
a
def
get_idx_list
(
inputs
,
idx_list
,
get_count
=
False
):
...
...
@@ -277,7 +281,9 @@ def range_len(slc):
"""
from
theano.tensor
import
switch
,
and_
,
lt
,
gt
start
,
stop
,
step
=
make_constant
([
slc
.
start
,
slc
.
stop
,
slc
.
step
])
start
,
stop
,
step
=
tuple
(
as_index_constant
(
a
)
for
a
in
[
slc
.
start
,
slc
.
stop
,
slc
.
step
]
)
return
switch
(
and_
(
gt
(
step
,
0
),
lt
(
start
,
stop
)),
1
+
(
stop
-
1
-
start
)
//
step
,
...
...
theano/tensor/var.py
浏览文件 @
7857774b
...
...
@@ -545,14 +545,16 @@ class _tensor_py_operators(object):
# Force input to be int64 datatype if input is an empty list or tuple
# Else leave it as is if it is a real number
# Convert python literals to theano constants
args
=
tuple
(
[
np
.
array
(
inp
,
dtype
=
np
.
int64
)
if
(
is_empty_array
(
inp
))
else
inp
theano
.
tensor
.
subtensor
.
as_index_constant
(
np
.
array
(
inp
,
dtype
=
np
.
int64
)
if
is_empty_array
(
inp
)
else
inp
)
for
inp
in
args
]
)
# Convert python literals to theano constants
args
=
theano
.
tensor
.
subtensor
.
make_constant
(
args
)
# Determine if advanced indexing is needed or not
# The logic is already in Subtensor.convert: if it succeeds,
# standard indexing is used; if it fails with
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论