Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
dfbc1334
提交
dfbc1334
authored
2月 27, 2014
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add new subtensor helper make_constant and use it to fix a bug in local_subtensor_merge.
上级
85209fbb
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
22 行增加
和
15 行删除
+22
-15
opt.py
theano/tensor/opt.py
+3
-1
subtensor.py
theano/tensor/subtensor.py
+17
-0
var.py
theano/tensor/var.py
+2
-14
没有找到文件。
theano/tensor/opt.py
浏览文件 @
dfbc1334
...
...
@@ -25,7 +25,8 @@ from theano.gof.utils import MethodNotDefined
from
theano.configparser
import
config
from
theano.tensor.elemwise
import
Elemwise
,
DimShuffle
from
theano.tensor.subtensor
import
(
get_idx_list
,
get_canonical_form_slice
,
Subtensor
,
IncSubtensor
,
AdvancedIncSubtensor1
)
Subtensor
,
IncSubtensor
,
make_constant
,
AdvancedIncSubtensor1
)
from
theano
import
scalar
from
theano.tensor
import
basic
as
T
from
theano
import
compile
# to register the optimizer built by this file
...
...
@@ -1955,6 +1956,7 @@ def local_subtensor_merge(node):
else
:
merged_slices
+=
slices1
[
pos_1
:]
merged_slices
=
make_constant
(
merged_slices
)
subtens
=
Subtensor
(
merged_slices
)
sl_ins
=
Subtensor
.
collapse
(
merged_slices
,
...
...
theano/tensor/subtensor.py
浏览文件 @
dfbc1334
...
...
@@ -47,6 +47,23 @@ class AdvancedIndexingError(TypeError):
# Helpful functions to deal with Subtensor and IncSubtensor
##########
def
make_constant
(
args
):
"""
Convert python litterals 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
,
(
int
,
long
,
numpy
.
integer
)):
return
scal
.
ScalarConstant
(
scal
.
int64
,
a
)
else
:
return
a
return
tuple
(
map
(
conv
,
args
))
def
get_idx_list
(
inputs
,
idx_list
):
'''
Given a list of inputs to the subtensor and its idx_list reorders
...
...
theano/tensor/var.py
浏览文件 @
dfbc1334
...
...
@@ -4,8 +4,7 @@ import numpy
import
theano
from
theano.compat
import
all
,
PY3
from
theano.scalar
import
(
ComplexError
,
IntegerDivisionError
,
ScalarConstant
,
int64
)
from
theano.scalar
import
ComplexError
,
IntegerDivisionError
from
theano.gof
import
Constant
,
Variable
from
theano.gof.utils
import
hashtype
from
theano.tensor.utils
import
hash_from_ndarray
...
...
@@ -350,18 +349,7 @@ class _tensor_py_operators:
if
not
isinstance
(
args
,
tuple
):
args
=
args
,
# Convert python literals to theano constants
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
,
(
int
,
long
,
numpy
.
integer
)):
return
ScalarConstant
(
int64
,
a
)
else
:
return
a
args
=
tuple
(
map
(
conv
,
args
))
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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论