Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
09c8c2d3
提交
09c8c2d3
authored
2月 12, 2010
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added disabled-by-default experimental advanced indexing code
上级
9563676f
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
39 行增加
和
2 行删除
+39
-2
basic.py
theano/tensor/basic.py
+39
-2
没有找到文件。
theano/tensor/basic.py
浏览文件 @
09c8c2d3
...
@@ -4,7 +4,7 @@ __docformat__ = "restructuredtext en"
...
@@ -4,7 +4,7 @@ __docformat__ = "restructuredtext en"
import
__builtin__
import
__builtin__
import
sys
# for sys.maxint
import
sys
# for sys.maxint
from
theano.configparser
import
config
from
theano.configparser
import
config
,
AddConfigVar
,
BoolParam
import
traceback
#for overriding Op.__call__
import
traceback
#for overriding Op.__call__
if
sys
.
version_info
>=
(
2
,
5
):
if
sys
.
version_info
>=
(
2
,
5
):
import
functools
import
functools
...
@@ -943,7 +943,13 @@ class _tensor_py_operators:
...
@@ -943,7 +943,13 @@ class _tensor_py_operators:
break
break
if
advanced
:
if
advanced
:
return
AdvancedSubtensor
(
args
)(
self
,
*
args
)
if
config
.
experimental
.
advanced_indexing
:
if
len
(
args
)
==
1
:
return
AdvancedSubtensor1
()(
self
,
*
args
)
else
:
return
AdvancedSubtensor
(
args
)(
self
,
*
args
)
else
:
return
AdvancedSubtensor
(
args
)(
self
,
*
args
)
else
:
else
:
return
Subtensor
(
args
)(
self
,
*
Subtensor
.
collapse
(
args
,
lambda
entry
:
isinstance
(
entry
,
Variable
)))
return
Subtensor
(
args
)(
self
,
*
Subtensor
.
collapse
(
args
,
lambda
entry
:
isinstance
(
entry
,
Variable
)))
...
@@ -3136,6 +3142,37 @@ def inverse_permutation(perm):
...
@@ -3136,6 +3142,37 @@ def inverse_permutation(perm):
# Should reproduce numpy's behaviour:
# Should reproduce numpy's behaviour:
# http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#advanced-indexing
# http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#advanced-indexing
AddConfigVar
(
'experimental.advanced_indexing'
,
"enable not-well-tested advanced indexing functionality"
,
BoolParam
(
False
))
class
AdvancedSubtensor1
(
Op
):
"""Implement x[ilist] where ilist is a vector of integers."""
def
__hash__
(
self
):
return
hash
(
type
(
self
))
def
__eq__
(
self
,
other
):
type
(
self
)
==
type
(
other
)
def
make_node
(
self
,
x
,
ilist
):
x_
=
as_tensor_variable
(
x
)
ilist_
=
as_tensor_variable
(
ilist
)
if
ilist_
.
type
.
dtype
[:
3
]
not
in
(
'int'
,
'uin'
):
raise
TypeError
(
'index must be integers'
)
if
ilist_
.
type
.
broadcastable
!=
(
False
,):
raise
TypeError
(
'index must be vector'
)
if
x_
.
type
.
ndim
==
0
:
raise
TypeError
(
'cannot index into a scalar'
)
if
x_
.
type
.
broadcastable
[
0
]:
# the caller should have made a copy of x len(ilist) times
raise
TypeError
(
'cannot index into a broadcastable dimension'
)
return
gof
.
Apply
(
self
,
[
x_
,
ilist_
],
[
x_
.
type
()])
def
perform
(
self
,
node
,
(
x
,
i
),
(
out
,)):
out
[
0
]
=
x
[
i
]
class
AdvancedSubtensor
(
Op
):
class
AdvancedSubtensor
(
Op
):
"""Return a subtensor copy, using advanced indexing.
"""Return a subtensor copy, using advanced indexing.
"""
"""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论