Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9ed2de83
提交
9ed2de83
authored
6月 19, 2014
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pep8
上级
c4a93fe3
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
15 行增加
和
8 行删除
+15
-8
subtensor.py
theano/tensor/subtensor.py
+15
-8
没有找到文件。
theano/tensor/subtensor.py
浏览文件 @
9ed2de83
...
@@ -64,6 +64,7 @@ def make_constant(args):
...
@@ -64,6 +64,7 @@ def make_constant(args):
return
a
return
a
return
tuple
(
map
(
conv
,
args
))
return
tuple
(
map
(
conv
,
args
))
def
get_idx_list
(
inputs
,
idx_list
):
def
get_idx_list
(
inputs
,
idx_list
):
'''
'''
Given a list of inputs to the subtensor and its idx_list reorders
Given a list of inputs to the subtensor and its idx_list reorders
...
@@ -395,6 +396,7 @@ class Subtensor(Op):
...
@@ -395,6 +396,7 @@ class Subtensor(Op):
NotScalarConstantError: v
NotScalarConstantError: v
"""
"""
real_idx
=
get_idx_list
(
inputs
,
self
.
idx_list
)
real_idx
=
get_idx_list
(
inputs
,
self
.
idx_list
)
def
conv
(
val
):
def
conv
(
val
):
if
val
is
None
:
if
val
is
None
:
return
None
return
None
...
@@ -441,7 +443,8 @@ class Subtensor(Op):
...
@@ -441,7 +443,8 @@ class Subtensor(Op):
raise
exception
raise
exception
input_types
=
Subtensor
.
collapse
(
idx_list
,
input_types
=
Subtensor
.
collapse
(
idx_list
,
lambda
entry
:
isinstance
(
entry
,
gof
.
Type
))
lambda
entry
:
isinstance
(
entry
,
gof
.
Type
))
if
len
(
inputs
)
!=
len
(
input_types
):
if
len
(
inputs
)
!=
len
(
input_types
):
raise
IndexError
(
raise
IndexError
(
"Not enough inputs to fill in the Subtensor template."
,
"Not enough inputs to fill in the Subtensor template."
,
...
@@ -693,7 +696,7 @@ class Subtensor(Op):
...
@@ -693,7 +696,7 @@ class Subtensor(Op):
npy_intp xview_dims[
%(view_ndim)
s];
npy_intp xview_dims[
%(view_ndim)
s];
npy_intp xview_strides[
%(view_ndim)
s];
npy_intp xview_strides[
%(view_ndim)
s];
"""
%
locals
()
"""
%
locals
()
else
:
else
:
rval
=
"""
rval
=
"""
// Argument of the view
// Argument of the view
...
@@ -987,7 +990,8 @@ def inc_subtensor(x, y, inplace=False, set_instead_of_inc=False,
...
@@ -987,7 +990,8 @@ def inc_subtensor(x, y, inplace=False, set_instead_of_inc=False,
if
y
.
ndim
>
x
.
ndim
:
if
y
.
ndim
>
x
.
ndim
:
raise
TypeError
((
"Trying to increment a
%
d-dimensional "
raise
TypeError
((
"Trying to increment a
%
d-dimensional "
"subtensor with a
%
d-dimensional value."
)
%
(
x
.
ndim
,
y
.
ndim
))
"subtensor with a
%
d-dimensional value."
)
%
(
x
.
ndim
,
y
.
ndim
))
for
dim
in
range
(
y
.
ndim
):
for
dim
in
range
(
y
.
ndim
):
dim_offset
=
x
.
ndim
-
y
.
ndim
dim_offset
=
x
.
ndim
-
y
.
ndim
...
@@ -1042,7 +1046,8 @@ def inc_subtensor(x, y, inplace=False, set_instead_of_inc=False,
...
@@ -1042,7 +1046,8 @@ def inc_subtensor(x, y, inplace=False, set_instead_of_inc=False,
# return something that has the same shape as x, not as x.T (inner_x).
# return something that has the same shape as x, not as x.T (inner_x).
# So re-apply the outer dimshuffle on the new inc_subtensor,
# So re-apply the outer dimshuffle on the new inc_subtensor,
# and return advanced_inc_subtensor1(x.T, i, y).T.
# and return advanced_inc_subtensor1(x.T, i, y).T.
inner_incsubtensor
=
inc_subtensor
(
inner_x
,
y
,
inner_incsubtensor
=
inc_subtensor
(
inner_x
,
y
,
inplace
=
inplace
,
inplace
=
inplace
,
set_instead_of_inc
=
set_instead_of_inc
,
set_instead_of_inc
=
set_instead_of_inc
,
tolerate_inplace_aliasing
=
tolerate_inplace_aliasing
)
tolerate_inplace_aliasing
=
tolerate_inplace_aliasing
)
...
@@ -1052,7 +1057,8 @@ def inc_subtensor(x, y, inplace=False, set_instead_of_inc=False,
...
@@ -1052,7 +1057,8 @@ def inc_subtensor(x, y, inplace=False, set_instead_of_inc=False,
# Try to apply inc_subtensor on inner_x.
# Try to apply inc_subtensor on inner_x.
# If it works, there is no need to reshape, as the inc_subtensor
# If it works, there is no need to reshape, as the inc_subtensor
# will have the same shape as inner_x, which is what we want.
# will have the same shape as inner_x, which is what we want.
inner_incsubtensor
=
inc_subtensor
(
inner_x
,
y
.
flatten
(),
inner_incsubtensor
=
inc_subtensor
(
inner_x
,
y
.
flatten
(),
inplace
=
inplace
,
inplace
=
inplace
,
set_instead_of_inc
=
set_instead_of_inc
,
set_instead_of_inc
=
set_instead_of_inc
,
tolerate_inplace_aliasing
=
tolerate_inplace_aliasing
)
tolerate_inplace_aliasing
=
tolerate_inplace_aliasing
)
...
@@ -1138,8 +1144,8 @@ class IncSubtensor(Op):
...
@@ -1138,8 +1144,8 @@ class IncSubtensor(Op):
x
,
y
=
map
(
theano
.
tensor
.
as_tensor_variable
,
[
x
,
y
])
x
,
y
=
map
(
theano
.
tensor
.
as_tensor_variable
,
[
x
,
y
])
if
y
.
ndim
>
x
.
ndim
:
if
y
.
ndim
>
x
.
ndim
:
raise
ValueError
((
"Trying to increment a
%
d-dimensional "
raise
ValueError
((
"Trying to increment a
%
d-dimensional "
"subtensor with a
%
d-dimensional value."
)
%
(
x
.
ndim
,
"subtensor with a
%
d-dimensional value."
)
%
(
y
.
ndim
))
x
.
ndim
,
y
.
ndim
))
inputs
=
tuple
(
map
(
Subtensor
.
my_as_scalar
,
inputs
))
inputs
=
tuple
(
map
(
Subtensor
.
my_as_scalar
,
inputs
))
idx_list
=
list
(
self
.
idx_list
)
idx_list
=
list
(
self
.
idx_list
)
...
@@ -1151,7 +1157,8 @@ class IncSubtensor(Op):
...
@@ -1151,7 +1157,8 @@ class IncSubtensor(Op):
exception
.
subtensor_invalid
=
True
exception
.
subtensor_invalid
=
True
raise
exception
raise
exception
input_types
=
Subtensor
.
collapse
(
idx_list
,
input_types
=
Subtensor
.
collapse
(
idx_list
,
lambda
entry
:
isinstance
(
entry
,
gof
.
Type
))
lambda
entry
:
isinstance
(
entry
,
gof
.
Type
))
if
len
(
inputs
)
!=
len
(
input_types
):
if
len
(
inputs
)
!=
len
(
input_types
):
raise
IndexError
(
raise
IndexError
(
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论