Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5a0e695e
提交
5a0e695e
authored
12月 01, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make tensor.stack() work when the first element is a python/numpy int, float, complex
上级
84898822
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
13 行增加
和
7 行删除
+13
-7
basic.py
theano/tensor/basic.py
+11
-5
test_basic.py
theano/tensor/tests/test_basic.py
+2
-2
没有找到文件。
theano/tensor/basic.py
浏览文件 @
5a0e695e
...
...
@@ -33,6 +33,9 @@ def _info(*msg):
def
_warn
(
*
msg
):
_logger
.
warn
(
' '
.
join
(
msg
))
#This is needed as we will hide it later
python_complex
=
complex
def
check_equal_numpy
(
x
,
y
):
"""
Returns True iff x and y are equal (checks the dtype and
...
...
@@ -3269,11 +3272,14 @@ def stack(*tensors):
raise
Exception
(
'theano.tensor.stack(*tensors) must have at least one parameter'
)
# If all tensors are scalars of the same type, call make_vector.
# It makes the graph simpler, by not adding DimShuffles and Rebroadcasts
if
numpy
.
all
([(
isinstance
(
t
,
Variable
)
and
isinstance
(
t
.
type
,
TensorType
)
and
t
.
ndim
==
0
and
t
.
type
.
__class__
==
tensors
[
0
]
.
type
.
__class__
)
or
isinstance
(
t
,
(
numpy
.
number
,
float
,
int
,
complex
))
#in case their is direct int
if
isinstance
(
tensors
[
0
],
(
numpy
.
number
,
float
,
int
,
python_complex
)):
tensors
=
list
(
tensors
)
tensors
[
0
]
=
as_tensor_variable
(
tensors
[
0
])
if
numpy
.
all
([
isinstance
(
t
,
(
numpy
.
number
,
float
,
int
,
python_complex
))
#in case their is direct int
or
(
isinstance
(
t
,
Variable
)
and
isinstance
(
t
.
type
,
TensorType
)
and
t
.
ndim
==
0
and
t
.
type
.
__class__
==
tensors
[
0
]
.
type
.
__class__
)
for
t
in
tensors
]):
tensors
=
map
(
as_tensor_variable
,
tensors
)
#in case their is direct int
dtype
=
scal
.
upcast
(
*
[
i
.
dtype
for
i
in
tensors
])
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
5a0e695e
...
...
@@ -1571,10 +1571,10 @@ class T_Join_and_Split(unittest.TestCase):
event when the scalar are simple int type.'''
a
=
tensor
.
iscalar
(
'a'
)
b
=
tensor
.
lscalar
(
'b'
)
s
=
stack
(
a
,
b
,
10
,
numpy
.
int8
(
3
))
s
=
stack
(
10
,
a
,
b
,
numpy
.
int8
(
3
))
f
=
function
([
a
,
b
],
s
)
val
=
f
(
1
,
2
)
self
.
failUnless
(
numpy
.
all
(
val
==
[
1
,
2
,
10
,
3
]))
self
.
failUnless
(
numpy
.
all
(
val
==
[
1
0
,
1
,
2
,
3
]))
e
=
f
.
maker
.
env
.
toposort
()
assert
len
([
n
for
n
in
e
if
isinstance
(
n
.
op
,
opt
.
MakeVector
)])
>
0
assert
len
([
n
for
n
in
e
if
isinstance
(
n
,
Join
)])
==
0
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论