Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d6c185de
提交
d6c185de
authored
12月 07, 2012
作者:
abalkin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed output rank for axis is not None case.
上级
0daa4491
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
15 行增加
和
8 行删除
+15
-8
basic.py
theano/tensor/basic.py
+9
-7
test_basic.py
theano/tensor/tests/test_basic.py
+6
-1
没有找到文件。
theano/tensor/basic.py
浏览文件 @
d6c185de
...
@@ -6833,7 +6833,14 @@ class Take(Op):
...
@@ -6833,7 +6833,14 @@ class Take(Op):
def
make_node
(
self
,
a
,
indices
):
def
make_node
(
self
,
a
,
indices
):
a
=
as_tensor_variable
(
a
)
a
=
as_tensor_variable
(
a
)
indices
=
as_tensor_variable
(
indices
)
indices
=
as_tensor_variable
(
indices
)
return
gof
.
Apply
(
self
,
(
a
,
indices
),
[
a
.
type
()])
if
self
.
axis
is
None
:
broadcastable
=
[
False
]
else
:
broadcastable
=
(
a
.
broadcastable
[:
self
.
axis
]
+
indices
.
broadcastable
+
a
.
broadcastable
[
self
.
axis
+
1
:])
return
gof
.
Apply
(
self
,
(
a
,
indices
),
[
TensorType
(
a
.
dtype
,
broadcastable
)()])
def
perform
(
self
,
node
,
inputs
,
outputs
):
def
perform
(
self
,
node
,
inputs
,
outputs
):
a
,
indices
=
inputs
a
,
indices
=
inputs
...
@@ -6854,14 +6861,9 @@ def take(a, indices, axis=None, mode='raise'):
...
@@ -6854,14 +6861,9 @@ def take(a, indices, axis=None, mode='raise'):
a
=
as_tensor_variable
(
a
)
a
=
as_tensor_variable
(
a
)
indices
=
as_tensor_variable
(
indices
)
indices
=
as_tensor_variable
(
indices
)
# Reuse advanced indexing in supported cases.
# Reuse advanced indexing in supported cases.
if
axis
is
None
:
if
axis
is
None
and
mode
==
'raise'
:
if
indices
.
ndim
==
1
:
if
indices
.
ndim
==
1
:
return
a
.
flatten
()[
indices
]
return
a
.
flatten
()[
indices
]
else
:
if
indices
.
ndim
==
0
:
item
=
[
slice
(
None
)]
*
a
.
ndim
item
[
axis
]
=
indices
return
a
[
tuple
(
item
)]
return
Take
(
axis
,
mode
)(
a
,
indices
)
return
Take
(
axis
,
mode
)(
a
,
indices
)
#########################
#########################
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
d6c185de
...
@@ -7170,7 +7170,12 @@ class TestTensorInstanceMethods(unittest.TestCase):
...
@@ -7170,7 +7170,12 @@ class TestTensorInstanceMethods(unittest.TestCase):
def
test_take
(
self
):
def
test_take
(
self
):
X
,
_
=
self
.
vars
X
,
_
=
self
.
vars
x
,
_
=
self
.
vals
x
,
_
=
self
.
vals
assert_array_equal
(
X
.
take
([
1
,
0
,
3
])
.
eval
({
X
:
x
}),
x
.
take
([
1
,
0
,
3
]))
indices
=
[
1
,
0
,
3
]
assert_array_equal
(
X
.
take
(
indices
)
.
eval
({
X
:
x
}),
x
.
take
(
indices
))
indices
=
[
1
,
0
,
1
]
assert_array_equal
(
X
.
take
(
indices
,
1
)
.
eval
({
X
:
x
}),
x
.
take
(
indices
,
1
))
indices
=
[[
1
,
0
,
1
],
[
0
,
1
,
1
]]
assert_array_equal
(
X
.
take
(
indices
,
1
)
.
eval
({
X
:
x
}),
x
.
take
(
indices
,
1
))
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论