Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
852114f3
提交
852114f3
authored
7月 23, 2014
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pep8
上级
ac850ee6
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
40 行增加
和
38 行删除
+40
-38
subtensor.py
theano/tensor/subtensor.py
+40
-38
没有找到文件。
theano/tensor/subtensor.py
浏览文件 @
852114f3
...
@@ -1296,7 +1296,7 @@ class IncSubtensor(Op):
...
@@ -1296,7 +1296,7 @@ class IncSubtensor(Op):
**
helper_args
**
helper_args
)
)
#Make a view on the output, as we will write into it.
#
Make a view on the output, as we will write into it.
alloc_zview
=
self
.
make_view_array
(
z
,
view_ndim
)
alloc_zview
=
self
.
make_view_array
(
z
,
view_ndim
)
build_view
=
"""
build_view
=
"""
...
@@ -1545,8 +1545,9 @@ class AdvancedSubtensor1(Op):
...
@@ -1545,8 +1545,9 @@ class AdvancedSubtensor1(Op):
if
not
numpy
.
can_cast
(
i
.
dtype
,
numpy
.
intp
):
if
not
numpy
.
can_cast
(
i
.
dtype
,
numpy
.
intp
):
# Check if there was actually an incorrect conversion
# Check if there was actually an incorrect conversion
if
numpy
.
any
(
i
!=
i_
):
if
numpy
.
any
(
i
!=
i_
):
raise
IndexError
(
'index contains values that are bigger '
raise
IndexError
(
'than the maximum array size on this system.'
,
i
)
'index contains values that are bigger '
'than the maximum array size on this system.'
,
i
)
i
=
i_
i
=
i_
out
[
0
]
=
x
.
take
(
i
,
axis
=
0
,
out
=
o
)
out
[
0
]
=
x
.
take
(
i
,
axis
=
0
,
out
=
o
)
...
@@ -1737,9 +1738,10 @@ class AdvancedIncSubtensor1(Op):
...
@@ -1737,9 +1738,10 @@ class AdvancedIncSubtensor1(Op):
opname
=
'set'
opname
=
'set'
else
:
else
:
opname
=
'increment'
opname
=
'increment'
raise
TypeError
(
'cannot
%
s x subtensor with ndim=
%
s'
raise
TypeError
(
' by y with ndim=
%
s to x subtensor with ndim=
%
s '
%
(
'cannot
%
s x subtensor with ndim=
%
s'
opname
,
x_
.
type
.
ndim
,
y_
.
type
.
ndim
))
' by y with ndim=
%
s to x subtensor with ndim=
%
s '
%
(
opname
,
x_
.
type
.
ndim
,
y_
.
type
.
ndim
))
return
Apply
(
self
,
[
x_
,
y_
,
ilist_
],
[
x_
.
type
()])
return
Apply
(
self
,
[
x_
,
y_
,
ilist_
],
[
x_
.
type
()])
...
@@ -1842,7 +1844,7 @@ def adv_index_broadcastable_pattern(a, idx):
...
@@ -1842,7 +1844,7 @@ def adv_index_broadcastable_pattern(a, idx):
newidx
=
tuple
(
map
(
replace_slice
,
idx
))
newidx
=
tuple
(
map
(
replace_slice
,
idx
))
#2 - True = 1; 2 - False = 2
#
2 - True = 1; 2 - False = 2
fakeshape
=
[
2
-
bc
for
bc
in
a
.
broadcastable
]
fakeshape
=
[
2
-
bc
for
bc
in
a
.
broadcastable
]
retshape
=
numpy
.
empty
(
fakeshape
)[
newidx
]
.
shape
retshape
=
numpy
.
empty
(
fakeshape
)[
newidx
]
.
shape
return
tuple
([
dim
==
1
for
dim
in
retshape
])
return
tuple
([
dim
==
1
for
dim
in
retshape
])
...
@@ -1872,7 +1874,7 @@ class AdvancedSubtensor(Op):
...
@@ -1872,7 +1874,7 @@ class AdvancedSubtensor(Op):
return
gof
.
Apply
(
self
,
return
gof
.
Apply
(
self
,
(
x
,)
+
index
,
(
x
,)
+
index
,
[
theano
.
tensor
.
tensor
(
dtype
=
x
.
type
.
dtype
,
[
theano
.
tensor
.
tensor
(
dtype
=
x
.
type
.
dtype
,
broadcastable
=
bcast
)])
broadcastable
=
bcast
)])
def
R_op
(
self
,
inputs
,
eval_points
):
def
R_op
(
self
,
inputs
,
eval_points
):
if
eval_points
[
0
]
is
None
:
if
eval_points
[
0
]
is
None
:
...
@@ -1902,13 +1904,11 @@ class AdvancedSubtensor(Op):
...
@@ -1902,13 +1904,11 @@ class AdvancedSubtensor(Op):
if
(
numpy
.
__version__
<=
'1.6.1'
and
if
(
numpy
.
__version__
<=
'1.6.1'
and
out
[
0
]
.
size
!=
numpy
.
uint32
(
out
[
0
]
.
size
)):
out
[
0
]
.
size
!=
numpy
.
uint32
(
out
[
0
]
.
size
)):
warnings
.
warn
(
warnings
.
warn
(
'Numpy versions 1.6.1 and below have a bug preventing '
'Numpy versions 1.6.1 and below have a bug preventing '
'advanced indexing from correctly filling arrays that '
'advanced indexing from correctly filling arrays that '
'are too big (>= 2^32 elements). It is possible that '
'are too big (>= 2^32 elements). It is possible that '
'out[0] (
%
s), with shape
%
s, is not correctly filled.'
'out[0] (
%
s), with shape
%
s, is not correctly filled.'
%
(
out
[
0
],
out
[
0
]
.
shape
))
%
(
out
[
0
],
out
[
0
]
.
shape
))
# return
#raise NotImplementedError()
def
connection_pattern
(
self
,
node
):
def
connection_pattern
(
self
,
node
):
...
@@ -1960,8 +1960,9 @@ class AdvancedIncSubtensor(Op):
...
@@ -1960,8 +1960,9 @@ class AdvancedIncSubtensor(Op):
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s{
%
s,
%
s}"
%
(
self
.
__class__
.
__name__
,
return
"
%
s{
%
s,
%
s}"
%
(
self
.
__class__
.
__name__
,
"inplace="
+
str
(
self
.
inplace
),
"inplace="
+
str
(
self
.
inplace
),
" set_instead_of_inc="
+
str
(
self
.
set_instead_of_inc
))
" set_instead_of_inc="
+
str
(
self
.
set_instead_of_inc
))
def
make_node
(
self
,
x
,
y
,
*
inputs
):
def
make_node
(
self
,
x
,
y
,
*
inputs
):
x
=
theano
.
tensor
.
as_tensor_variable
(
x
)
x
=
theano
.
tensor
.
as_tensor_variable
(
x
)
...
@@ -1995,17 +1996,18 @@ class AdvancedIncSubtensor(Op):
...
@@ -1995,17 +1996,18 @@ class AdvancedIncSubtensor(Op):
op
.
allow_legacy_perform
=
True
op
.
allow_legacy_perform
=
True
else
:
else
:
raise
NotImplementedError
(
raise
NotImplementedError
(
'Could not import inplace_increment, so some advanced '
'Could not import inplace_increment, so some advanced '
'indexing features are disabled. They will be '
'indexing features are disabled. They will be '
'available if you update NumPy to version 1.8 or '
'available if you update NumPy to version 1.8 or '
'later, or to the latest development version. '
'later, or to the latest development version. '
'You may need to clear the cache (theano-cache clear) '
'You may need to clear the cache (theano-cache clear) '
'afterwards.'
)
'afterwards.'
)
return
gof
.
Apply
(
op
,
return
gof
.
Apply
(
op
,
(
x
,
y
)
+
inputs
,
(
x
,
y
)
+
inputs
,
[
theano
.
tensor
.
tensor
(
dtype
=
x
.
type
.
dtype
,
[
theano
.
tensor
.
tensor
(
broadcastable
=
x
.
type
.
broadcastable
)])
dtype
=
x
.
type
.
dtype
,
broadcastable
=
x
.
type
.
broadcastable
)])
def
perform
(
self
,
node
,
inputs
,
out_
):
def
perform
(
self
,
node
,
inputs
,
out_
):
# TODO: 1. opt to make this in place 2. generalize as described in
# TODO: 1. opt to make this in place 2. generalize as described in
...
@@ -2025,21 +2027,21 @@ class AdvancedIncSubtensor(Op):
...
@@ -2025,21 +2027,21 @@ class AdvancedIncSubtensor(Op):
out
[
0
][
inputs
[
2
:]]
+=
inputs
[
1
]
out
[
0
][
inputs
[
2
:]]
+=
inputs
[
1
]
else
:
else
:
raise
NotImplementedError
(
raise
NotImplementedError
(
'Could not import inplace_increment, so some advanced '
'Could not import inplace_increment, so some advanced '
'indexing features are disabled. They will be '
'indexing features are disabled. They will be '
'available if you update NumPy to version 1.8 or '
'available if you update NumPy to version 1.8 or '
'later, or to the latest development version. '
'later, or to the latest development version. '
'You may need to clear the cache (theano-cache clear) '
'You may need to clear the cache (theano-cache clear) '
'afterwards.'
)
'afterwards.'
)
if
(
numpy
.
__version__
<=
'1.6.1'
and
if
(
numpy
.
__version__
<=
'1.6.1'
and
out
[
0
]
.
size
!=
numpy
.
uint32
(
out
[
0
]
.
size
)):
out
[
0
]
.
size
!=
numpy
.
uint32
(
out
[
0
]
.
size
)):
warnings
.
warn
(
warnings
.
warn
(
'Numpy versions 1.6.1 and below have a bug preventing '
'Numpy versions 1.6.1 and below have a bug preventing '
'advanced indexing from correctly filling arrays that '
'advanced indexing from correctly filling arrays that '
'are too big (>= 2^32 elements). It is possible that '
'are too big (>= 2^32 elements). It is possible that '
'out[0] (
%
s), with shape
%
s, is not correctly filled.'
'out[0] (
%
s), with shape
%
s, is not correctly filled.'
%
(
out
[
0
],
out
[
0
]
.
shape
))
%
(
out
[
0
],
out
[
0
]
.
shape
))
def
infer_shape
(
self
,
node
,
ishapes
):
def
infer_shape
(
self
,
node
,
ishapes
):
return
[
ishapes
[
0
]]
return
[
ishapes
[
0
]]
...
@@ -2097,6 +2099,6 @@ def take(a, indices, axis=None, mode='raise'):
...
@@ -2097,6 +2099,6 @@ def take(a, indices, axis=None, mode='raise'):
ndim
=
indices
.
ndim
ndim
=
indices
.
ndim
else
:
else
:
shape
=
theano
.
tensor
.
concatenate
(
shape
=
theano
.
tensor
.
concatenate
(
[
a
.
shape
[:
axis
],
indices
.
shape
,
a
.
shape
[
axis
+
1
:]])
[
a
.
shape
[:
axis
],
indices
.
shape
,
a
.
shape
[
axis
+
1
:]])
ndim
=
a
.
ndim
+
indices
.
ndim
-
1
ndim
=
a
.
ndim
+
indices
.
ndim
-
1
return
take
(
a
,
indices
.
flatten
(),
axis
,
mode
)
.
reshape
(
shape
,
ndim
)
return
take
(
a
,
indices
.
flatten
(),
axis
,
mode
)
.
reshape
(
shape
,
ndim
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论