Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ff91f22e
提交
ff91f22e
authored
10月 04, 2016
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add some tests for silly numpy behaviour and make them pass.
上级
296fabec
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
58 行增加
和
14 行删除
+58
-14
subtensor.py
theano/gpuarray/subtensor.py
+22
-14
test_subtensor.py
theano/tensor/tests/test_subtensor.py
+36
-0
没有找到文件。
theano/gpuarray/subtensor.py
浏览文件 @
ff91f22e
...
...
@@ -519,16 +519,24 @@ class GpuAdvancedSubtensor(HideC, tensor.AdvancedSubtensor):
p
+=
1
narrays
+=
1
else
:
try
:
i
.
__index__
()
# We shift back the position of the array by the
# number of dimensions that are removed by
# indexing. If ap is bigger than 0 it means we
# have encountered at least one array.
if
ap
>=
0
:
ap
-=
1
except
Exception
:
pass
if
narrays
==
0
:
try
:
i
.
__index__
()
# We shift back the position of the array by the
# number of dimensions that are removed by
# indexing. If ap is bigger than 0 it means we
# have encountered at least one array.
if
ap
>=
0
:
ap
-=
1
# If this index is before the first array then
# we will not move the array back to its
# position. Mark this by faking that there
# are more than two arrays. This is crazy
# numpy behaviour so blame them.
if
narrays
==
0
:
narrays
=
2
except
Exception
:
pass
x
=
x
.
transpose
(
*
transp
)
...
...
@@ -556,11 +564,11 @@ class GpuAdvancedSubtensor(HideC, tensor.AdvancedSubtensor):
o
=
out_flat
.
reshape
(
out_flat_shp
)
# If there was only one array we need to move the indexed
# dimension back
# dimension(s) back to the position of the array, which is
# stored in ap. Note that ap is invalid is narrays != 1.
if
narrays
==
1
:
k
=
ap
ntransp
=
list
(
range
(
1
,
o
.
ndim
))
ntransp
.
insert
(
k
,
0
)
ntransp
=
list
(
range
(
take_idx
.
ndim
,
o
.
ndim
))
ntransp
[
ap
:
ap
]
=
list
(
range
(
take_idx
.
ndim
))
o
=
o
.
transpose
(
*
ntransp
)
out
[
0
]
=
o
...
...
theano/tensor/tests/test_subtensor.py
浏览文件 @
ff91f22e
...
...
@@ -1435,6 +1435,42 @@ class TestAdvancedSubtensor(unittest.TestCase):
rval
=
ft4v
[
0
,
:,
ix2v
,
:]
utt
.
assert_allclose
(
rval
,
aval
)
def
test_adv_subtensor_w_none_and_matrix
(
self
):
subt
=
self
.
ft4
[:,
None
,
:,
self
.
ix2
,
:]
f
=
theano
.
function
([
self
.
ft4
,
self
.
ix2
],
subt
,
mode
=
self
.
mode
)
ft4v
=
numpy
.
random
.
random
((
2
,
3
,
4
,
5
))
.
astype
(
'float32'
)
ix2v
=
numpy
.
asarray
([[
0
,
1
],
[
1
,
0
]])
aval
=
f
(
ft4v
,
ix2v
)
rval
=
ft4v
[:,
None
,
:,
ix2v
,
:]
utt
.
assert_allclose
(
rval
,
aval
)
def
test_adv_subtensor_w_slice_and_matrix
(
self
):
subt
=
self
.
ft4
[:,
0
:
1
,
self
.
ix2
,
:]
f
=
theano
.
function
([
self
.
ft4
,
self
.
ix2
],
subt
,
mode
=
self
.
mode
)
ft4v
=
numpy
.
random
.
random
((
2
,
3
,
4
,
5
))
.
astype
(
'float32'
)
ix2v
=
numpy
.
asarray
([[
0
,
1
],
[
1
,
0
]])
aval
=
f
(
ft4v
,
ix2v
)
rval
=
ft4v
[:,
0
:
1
,
ix2v
,
:]
utt
.
assert_allclose
(
rval
,
aval
)
def
test_adv_subtensor_w_matrix_and_int
(
self
):
subt
=
self
.
ft4
[:,
:,
self
.
ix2
,
0
]
f
=
theano
.
function
([
self
.
ft4
,
self
.
ix2
],
subt
,
mode
=
self
.
mode
)
ft4v
=
numpy
.
random
.
random
((
2
,
3
,
4
,
5
))
.
astype
(
'float32'
)
ix2v
=
numpy
.
asarray
([[
0
,
1
],
[
1
,
0
]])
aval
=
f
(
ft4v
,
ix2v
)
rval
=
ft4v
[:,
:,
ix2v
,
0
]
utt
.
assert_allclose
(
rval
,
aval
)
def
test_adv_subtensor_w_matrix_and_none
(
self
):
subt
=
self
.
ft4
[:,
:,
self
.
ix2
,
None
,
:]
f
=
theano
.
function
([
self
.
ft4
,
self
.
ix2
],
subt
,
mode
=
self
.
mode
)
ft4v
=
numpy
.
random
.
random
((
2
,
3
,
4
,
5
))
.
astype
(
'float32'
)
ix2v
=
numpy
.
asarray
([[
0
,
1
],
[
1
,
0
]])
aval
=
f
(
ft4v
,
ix2v
)
rval
=
ft4v
[:,
:,
ix2v
,
None
,
:]
utt
.
assert_allclose
(
rval
,
aval
)
def
test_inc_adv_subtensor_w_2vec
(
self
):
if
inplace_increment
is
None
:
raise
inplace_increment_missing
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论