Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d8fbe1e9
提交
d8fbe1e9
authored
10月 17, 2014
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Some infer_shape changes.
上级
a0eb7306
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
25 行增加
和
6 行删除
+25
-6
basic.py
theano/tensor/basic.py
+13
-3
test_basic.py
theano/tensor/tests/test_basic.py
+12
-3
没有找到文件。
theano/tensor/basic.py
浏览文件 @
d8fbe1e9
...
@@ -5103,14 +5103,23 @@ def choose(a, choices, out=None, mode='raise'):
...
@@ -5103,14 +5103,23 @@ def choose(a, choices, out=None, mode='raise'):
class
Choose
(
Op
):
class
Choose
(
Op
):
__props__
=
(
'mode'
,)
__props__
=
(
'mode'
,)
def
__init__
(
self
,
mode
):
assert
mode
in
(
"raise"
,
"wrap"
,
"clip"
)
self
.
mode
=
mode
def
infer_shape
(
self
,
node
,
shapes
):
def
infer_shape
(
self
,
node
,
shapes
):
if
isinstance
(
node
.
inputs
[
1
],
tuple
):
if
isinstance
(
node
.
inputs
[
1
],
TensorVariable
):
return
[(
shapes
[
0
])]
else
:
import
theano.typed_list
assert
isinstance
(
node
.
inputs
[
1
],
theano
.
typed_list
.
TypedListVariable
)
#import pdb;pdb.set_trace()
raise
ShapeError
(
""
)
shape
=
shapes
[
0
]
shape
=
shapes
[
0
]
for
i
in
range
(
len
(
shapes
[
0
])
-
1
):
for
i
in
range
(
len
(
shapes
[
0
])
-
1
):
shape
[
i
]
=
shapes
[
1
][
i
]
shape
[
i
]
=
shapes
[
1
][
i
]
return
[(
shape
)]
return
[(
shape
)]
else
:
return
[(
shapes
[
0
])]
def
make_node
(
self
,
a
,
choices
):
def
make_node
(
self
,
a
,
choices
):
from
theano
import
typed_list
from
theano
import
typed_list
...
@@ -5124,4 +5133,5 @@ class Choose(Op):
...
@@ -5124,4 +5133,5 @@ class Choose(Op):
def
perform
(
self
,
node
,
inputs
,
(
z
,
)):
def
perform
(
self
,
node
,
inputs
,
(
z
,
)):
a
=
inputs
[
0
]
a
=
inputs
[
0
]
choice
=
inputs
[
1
]
choice
=
inputs
[
1
]
# TODO reuse out?
z
[
0
]
=
numpy
.
choose
(
a
,
choice
,
mode
=
self
.
mode
)
z
[
0
]
=
numpy
.
choose
(
a
,
choice
,
mode
=
self
.
mode
)
theano/tensor/tests/test_basic.py
浏览文件 @
d8fbe1e9
...
@@ -7073,20 +7073,29 @@ class T_Choose(utt.InferShapeTester):
...
@@ -7073,20 +7073,29 @@ class T_Choose(utt.InferShapeTester):
# Op that should be removed from the graph.
# Op that should be removed from the graph.
self
.
op_class
)
self
.
op_class
)
def
test_infer_shape_tuple
(
self
):
# Disabled as it isn't implemented.
def
___test_infer_shape_tuple
(
self
):
a
=
tensor
.
tensor3
(
dtype
=
'int64'
)
a
=
tensor
.
tensor3
(
dtype
=
'int64'
)
b
=
tensor
.
tensor3
(
dtype
=
'int64'
)
b
=
tensor
.
tensor3
(
dtype
=
'int64'
)
c
=
tensor
.
tensor3
(
dtype
=
'int64'
)
c
=
tensor
.
tensor3
(
dtype
=
'int64'
)
A
=
numpy
.
asarray
([
1
,
0
],
dtype
=
'int64'
)
.
reshape
((
2
,
1
,
1
))
A
=
numpy
.
asarray
([
1
,
0
],
dtype
=
'int64'
)
.
reshape
((
2
,
1
,
1
))
B
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
1
,
4
,
1
),
dtype
=
'int64'
)
B
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
1
,
4
,
1
),
dtype
=
'int64'
)
C
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
1
,
1
,
7
),
dtype
=
'int64'
)
C
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
1
,
1
,
7
),
dtype
=
'int64'
)
f
=
function
([
a
,
b
,
c
],
choose
(
a
,
(
b
,
c
)))
f
=
function
([
a
,
b
,
c
],
choose
(
a
,
(
b
,
c
)))
shape
=
(
2
,
4
,
7
)
shape
=
(
2
,
4
,
7
)
assert
numpy
.
allclose
(
f
(
A
,
B
,
C
)
.
shape
,
shape
)
assert
numpy
.
allclose
(
f
(
A
,
B
,
C
)
.
shape
,
shape
)
self
.
_compile_and_check
([
a
,
b
,
c
],
# theano.function inputs
[
self
.
op
(
a
,
(
b
,
c
))],
# theano.function outputs
# Always use not square matrix!
# inputs data
[
A
,
B
,
C
],
# Op that should be removed from the graph.
self
.
op_class
)
"""
"""
if __name__ == '__main__':
if __name__ == '__main__':
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论