Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
68162534
提交
68162534
authored
8月 04, 2017
作者:
Gijs van Tulder
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Little fixes to improve boolean mask indexing.
上级
1fbb77b6
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
10 行增加
和
9 行删除
+10
-9
subtensor.py
theano/tensor/subtensor.py
+7
-2
test_subtensor.py
theano/tensor/tests/test_subtensor.py
+1
-1
var.py
theano/tensor/var.py
+2
-6
没有找到文件。
theano/tensor/subtensor.py
浏览文件 @
68162534
...
@@ -336,6 +336,11 @@ class Subtensor(Op):
...
@@ -336,6 +336,11 @@ class Subtensor(Op):
theano
.
tensor
.
wscalar
,
theano
.
tensor
.
bscalar
]
theano
.
tensor
.
wscalar
,
theano
.
tensor
.
bscalar
]
invalid_tensor_types
=
[
theano
.
tensor
.
fscalar
,
theano
.
tensor
.
dscalar
,
invalid_tensor_types
=
[
theano
.
tensor
.
fscalar
,
theano
.
tensor
.
dscalar
,
theano
.
tensor
.
cscalar
,
theano
.
tensor
.
zscalar
]
theano
.
tensor
.
cscalar
,
theano
.
tensor
.
zscalar
]
if
(
isinstance
(
entry
,
(
np
.
ndarray
,
theano
.
tensor
.
Variable
))
and
hasattr
(
entry
,
'dtype'
)
and
entry
.
dtype
==
'bool'
):
raise
AdvancedIndexingError
(
Subtensor
.
e_indextype
,
entry
)
if
(
isinstance
(
entry
,
gof
.
Variable
)
and
if
(
isinstance
(
entry
,
gof
.
Variable
)
and
(
entry
.
type
in
invalid_scal_types
or
(
entry
.
type
in
invalid_scal_types
or
entry
.
type
in
invalid_tensor_types
)):
entry
.
type
in
invalid_tensor_types
)):
...
@@ -2049,8 +2054,8 @@ def as_index_variable(idx):
...
@@ -2049,8 +2054,8 @@ def as_index_variable(idx):
if
isinstance
(
idx
,
gof
.
Variable
)
and
isinstance
(
idx
.
type
,
NoneTypeT
):
if
isinstance
(
idx
,
gof
.
Variable
)
and
isinstance
(
idx
.
type
,
NoneTypeT
):
return
idx
return
idx
idx
=
theano
.
tensor
.
as_tensor_variable
(
idx
)
idx
=
theano
.
tensor
.
as_tensor_variable
(
idx
)
if
idx
.
type
.
dtype
not
in
theano
.
tensor
.
integer_dtypes
and
idx
.
type
.
dtype
!=
'bool'
:
if
idx
.
type
.
dtype
not
in
theano
.
tensor
.
discrete_dtypes
:
raise
TypeError
(
'index must be integers'
)
raise
TypeError
(
'index must be integers
or a boolean mask
'
)
return
idx
return
idx
...
...
theano/tensor/tests/test_subtensor.py
浏览文件 @
68162534
...
@@ -385,7 +385,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
...
@@ -385,7 +385,7 @@ class T_subtensor(unittest.TestCase, utt.TestOptimizationMixin):
assert_array_equal
(
numpy_n
[
np
.
newaxis
,
1
:,
mask
],
n
[
np
.
newaxis
,
1
:,
mask
]
.
eval
())
assert_array_equal
(
numpy_n
[
np
.
newaxis
,
1
:,
mask
],
n
[
np
.
newaxis
,
1
:,
mask
]
.
eval
())
assert_array_equal
(
numpy_inc_subtensor
(
numpy_n
,
[
0
,
mask
],
1
),
assert_array_equal
(
numpy_inc_subtensor
(
numpy_n
,
[
0
,
mask
],
1
),
inc_subtensor
(
n
[
0
,
mask
],
1
)
.
eval
())
inc_subtensor
(
n
[
0
,
mask
],
1
)
.
eval
())
assert_array_equal
(
numpy_inc_subtensor
(
numpy_n
,
[
Ellipsis
,
mask
],
1
),
assert_array_equal
(
numpy_inc_subtensor
(
numpy_n
,
[
slice
(
None
)
,
mask
],
1
),
inc_subtensor
(
n
[:,
mask
],
1
)
.
eval
())
inc_subtensor
(
n
[:,
mask
],
1
)
.
eval
())
# indexing with a boolean ndarray
# indexing with a boolean ndarray
...
...
theano/tensor/var.py
浏览文件 @
68162534
...
@@ -534,12 +534,7 @@ class _tensor_py_operators(object):
...
@@ -534,12 +534,7 @@ class _tensor_py_operators(object):
axis
=
None
axis
=
None
for
i
,
arg
in
enumerate
(
args
):
for
i
,
arg
in
enumerate
(
args
):
try
:
try
:
if
(
isinstance
(
arg
,
(
np
.
ndarray
,
theano
.
tensor
.
Variable
))
and
if
arg
is
not
np
.
newaxis
:
hasattr
(
arg
,
'dtype'
)
and
arg
.
dtype
==
'bool'
):
advanced
=
True
axis
=
None
break
elif
arg
is
not
np
.
newaxis
:
theano
.
tensor
.
subtensor
.
Subtensor
.
convert
(
arg
)
theano
.
tensor
.
subtensor
.
Subtensor
.
convert
(
arg
)
except
theano
.
tensor
.
subtensor
.
AdvancedIndexingError
:
except
theano
.
tensor
.
subtensor
.
AdvancedIndexingError
:
if
advanced
:
if
advanced
:
...
@@ -555,6 +550,7 @@ class _tensor_py_operators(object):
...
@@ -555,6 +550,7 @@ class _tensor_py_operators(object):
equal_slices
(
a
,
slice
(
None
))
for
a
in
args
[:
axis
])
and
equal_slices
(
a
,
slice
(
None
))
for
a
in
args
[:
axis
])
and
all
(
isinstance
(
a
,
slice
)
and
all
(
isinstance
(
a
,
slice
)
and
equal_slices
(
a
,
slice
(
None
))
for
a
in
args
[
axis
+
1
:])
and
equal_slices
(
a
,
slice
(
None
))
for
a
in
args
[
axis
+
1
:])
and
(
not
hasattr
(
args
[
axis
],
'dtype'
)
or
args
[
axis
]
.
dtype
!=
'bool'
)
and
isinstance
(
args
[
axis
],
isinstance
(
args
[
axis
],
(
np
.
ndarray
,
list
,
(
np
.
ndarray
,
list
,
TensorVariable
,
TensorConstant
,
TensorVariable
,
TensorConstant
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论