Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
76798960
提交
76798960
authored
6月 28, 2012
作者:
jsalvatier
提交者:
John Salvatier
3月 14, 2013
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
corrected some errors
上级
9d94cece
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
21 行增加
和
51 行删除
+21
-51
basic.py
theano/tensor/basic.py
+21
-51
没有找到文件。
theano/tensor/basic.py
浏览文件 @
76798960
...
...
@@ -1759,18 +1759,10 @@ class _tensor_py_operators:
axis
=
i
if
advanced
:
if
(
axis
is
not
None
and
numpy
.
all
(
a
==
slice
(
None
)
for
a
in
args
[:
axis
])
and
numpy
.
all
(
a
==
slice
(
None
)
for
a
in
args
[
axis
+
1
:])
and
isinstance
(
args
[
axis
],
(
numpy
.
ndarray
,
list
,
TensorVariable
,
TensorConstant
,
theano
.
tensor
.
sharedvar
.
TensorSharedVariable
))):
return
self
.
take
(
arg
,
axis
)
else
:
return
AdvancedSubtensor
()(
self
,
*
args
)
return
AdvancedSubtensor
()(
self
,
*
args
)
else
:
if
numpy
.
newaxis
in
args
:
# None (aka np.newaxis) in numpy indexing means to add a
...
...
@@ -7186,51 +7178,22 @@ class AdvancedIncSubtensor1(Op):
return
[
gx
,
gy
]
+
[
DisconnectedType
()()]
*
len
(
idx_list
)
advanced_inc_subtensor1
=
AdvancedIncSubtensor1
()
from
itertools
import
groupby
,
chain
def
simpleindex
(
a
):
try
:
return
as_tensor_variable
(
a
)
.
ndim
==
0
except
:
return
True
def
simple_broadcastable
(
a
,
idx
):
def
adv_broadcastable
(
a
,
idx
):
def
replace_slice
(
v
):
if
isinstance
(
v
,
slice
):
return
slice
(
None
,
None
)
if
simpleindex
(
v
):
return
0
return
v
try
:
return
numpy
.
zeros
(
(
1
,)
*
as_tensor_variable
(
v
)
.
ndim
,
int
)
except
ValueError
:
return
v
newidx
=
tuple
(
map
(
replace_slice
,
idx
))
fakeshape
=
[
bc
+
1
for
bc
in
a
.
broadcastable
]
retshape
=
numpy
.
empty
(
fakeshape
)[
newidx
]
.
shape
return
tuple
([
dim
==
1
for
dim
in
retshape
])
from
__builtin__
import
sum
as
concat
def
concat
(
ls
):
r
=
[]
map
(
r
.
extend
,
ls
)
return
r
def
advanced_broadcastable
(
a
,
idx
):
chunks
=
list
(
groupby
(
idx
,
simpleindex
))
chunks
=
[(
s
,
list
(
c
))
for
s
,
c
in
chunks
]
if
len
(
chunks
)
>
3
:
chunks
=
[
concat
(
c
for
s
,
c
in
chunks
if
s
),
concat
(
c
for
s
,
c
in
chunks
if
not
s
)]
def
getbroad
((
simple
,
c
)):
if
simple
:
return
simple_broadcastable
(
a
,
c
)
else
:
return
as_tensor_variable
(
c
[
0
])
.
broadcastable
return
concat
(
map
(
getbroad
,
chunks
))
class
AdvancedSubtensor
(
Op
):
"""Return a subtensor copy, using advanced indexing.
...
...
@@ -7250,13 +7213,20 @@ class AdvancedSubtensor(Op):
def
make_node
(
self
,
x
,
*
index
):
x
=
as_tensor_variable
(
x
)
# should be replaced with something that includes support for None and slices
# Note (9 Jul 2012): what does this 'FIXME' mean? Possibly that the
# current implementation must be generalized? Please specify.
def
as_index_variable
(
a
):
try
:
return
as_tensor_variable
(
a
)
except
:
return
a
idxvars
=
tuple
(
map
(
as_index_variable
,
index
))
return
gof
.
Apply
(
self
,
(
x
,)
+
tuple
(
map
(
as_tensor_variable
,
index
))
,
(
x
,)
+
idxvars
,
[
tensor
(
dtype
=
x
.
type
.
dtype
,
broadcastable
=
adv
anced
_broadcastable
(
x
,
index
)
)])
broadcastable
=
adv_broadcastable
(
x
,
index
)
)])
def
R_op
(
self
,
inputs
,
eval_points
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论