Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c1a4cefc
提交
c1a4cefc
authored
12月 01, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make get_constant_value go throught Subtensor of MakeVector as Subtensor of Join.
上级
5a0e695e
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
38 行增加
和
0 行删除
+38
-0
basic.py
theano/tensor/basic.py
+14
-0
test_basic.py
theano/tensor/tests/test_basic.py
+24
-0
没有找到文件。
theano/tensor/basic.py
浏览文件 @
c1a4cefc
...
@@ -391,6 +391,20 @@ def get_constant_value(v):
...
@@ -391,6 +391,20 @@ def get_constant_value(v):
ret
=
get_constant_value
(
ret
)
ret
=
get_constant_value
(
ret
)
#join can cast implicitly its input in some case.
#join can cast implicitly its input in some case.
return
theano
.
_asarray
(
ret
,
dtype
=
v
.
type
.
dtype
)
return
theano
.
_asarray
(
ret
,
dtype
=
v
.
type
.
dtype
)
if
(
v
.
owner
.
inputs
[
0
]
.
owner
and
isinstance
(
v
.
owner
.
inputs
[
0
]
.
owner
.
op
,
theano
.
tensor
.
opt
.
MakeVector
)
and
# MakeVector normally accept only scalar as input.
# We put this check in case there is change in the future
all
(
var
.
ndim
==
0
for
var
in
v
.
owner
.
inputs
[
0
]
.
owner
.
inputs
)):
# The index list 'idx_list' should have length one
# since joining scalar variables results in a 1D vector.
assert
len
(
v
.
owner
.
op
.
idx_list
)
==
1
ret
=
v
.
owner
.
inputs
[
0
]
.
owner
.
inputs
[
v
.
owner
.
op
.
idx_list
[
0
]]
ret
=
get_constant_value
(
ret
)
#MakeVector can cast implicitly its input in some case.
return
theano
.
_asarray
(
ret
,
dtype
=
v
.
type
.
dtype
)
raise
TypeError
(
v
)
raise
TypeError
(
v
)
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
c1a4cefc
...
@@ -1571,6 +1571,8 @@ class T_Join_and_Split(unittest.TestCase):
...
@@ -1571,6 +1571,8 @@ class T_Join_and_Split(unittest.TestCase):
event when the scalar are simple int type.'''
event when the scalar are simple int type.'''
a
=
tensor
.
iscalar
(
'a'
)
a
=
tensor
.
iscalar
(
'a'
)
b
=
tensor
.
lscalar
(
'b'
)
b
=
tensor
.
lscalar
(
'b'
)
#test when the constant is the first element.
#The first element is used in a special way
s
=
stack
(
10
,
a
,
b
,
numpy
.
int8
(
3
))
s
=
stack
(
10
,
a
,
b
,
numpy
.
int8
(
3
))
f
=
function
([
a
,
b
],
s
)
f
=
function
([
a
,
b
],
s
)
val
=
f
(
1
,
2
)
val
=
f
(
1
,
2
)
...
@@ -3468,6 +3470,28 @@ def test_dimshuffle_duplicate():
...
@@ -3468,6 +3470,28 @@ def test_dimshuffle_duplicate():
assert
success
assert
success
class
T_get_constant_value
(
unittest
.
TestCase
):
def
test_get_constant_value
(
self
):
a
=
tensor
.
stack
(
1
,
2
,
3
)
assert
get_constant_value
(
a
[
0
])
==
1
assert
get_constant_value
(
a
[
1
])
==
2
assert
get_constant_value
(
a
[
2
])
==
3
b
=
tensor
.
iscalar
()
a
=
tensor
.
stack
(
b
,
2
,
3
)
self
.
assertRaises
(
TypeError
,
get_constant_value
,
a
[
0
])
assert
get_constant_value
(
a
[
1
])
==
2
assert
get_constant_value
(
a
[
2
])
==
3
#For now get_constant_value got throught only MakeVector and Join of scalar.
v
=
tensor
.
ivector
()
a
=
tensor
.
stack
(
v
,
2
,
3
)
self
.
assertRaises
(
TypeError
,
get_constant_value
,
a
[
0
])
self
.
assertRaises
(
TypeError
,
get_constant_value
,
a
[
1
])
self
.
assertRaises
(
TypeError
,
get_constant_value
,
a
[
2
])
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
if
1
:
if
1
:
unittest
.
main
()
unittest
.
main
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论