Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
fbc5a3a0
提交
fbc5a3a0
authored
4月 14, 2013
作者:
Matthew Rocklin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
matrix_of_scalars -> tensor_of_scalars
上级
5e02f08e
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
21 行增加
和
9 行删除
+21
-9
basic.py
theano/tensor/basic.py
+8
-6
test_basic.py
theano/tensor/tests/test_basic.py
+13
-3
没有找到文件。
theano/tensor/basic.py
浏览文件 @
fbc5a3a0
...
@@ -8225,18 +8225,20 @@ def diag(v, k=0):
...
@@ -8225,18 +8225,20 @@ def diag(v, k=0):
else
:
else
:
raise
ValueError
(
"Input must be 1- or 2-d."
)
raise
ValueError
(
"Input must be 1- or 2-d."
)
def
matrix_of_scalars
(
list_of_lists
):
def
tensor_of_scalars
(
arg
):
""" Returns a
matrix
of scalars
""" Returns a
tensor
of scalars
>>> from theano.tensor import
matrix
_of_scalars, scalar
>>> from theano.tensor import
tensor
_of_scalars, scalar
>>> from theano import function
>>> from theano import function
>>> a,b,c,d = map(scalar, 'abcd')
>>> a,b,c,d = map(scalar, 'abcd')
>>> X =
matrix
_of_scalars([[a, b],
>>> X =
tensor
_of_scalars([[a, b],
... [c, d]])
... [c, d]])
>>> f = function([a, b, c, d], X)
>>> f = function([a, b, c, d], X)
>>> f(1, 2, 3, 4)
>>> f(1, 2, 3, 4)
array([[ 1., 2.],
array([[ 1., 2.],
[ 3., 4.]], dtype=float32)
[ 3., 4.]], dtype=float32)
"""
"""
from
functools
import
partial
if
isinstance
(
arg
,
(
tuple
,
list
)):
return
stack
(
*
map
(
partial
(
apply
,
stack
),
list_of_lists
))
return
stack
(
*
map
(
tensor_of_scalars
,
arg
))
else
:
return
arg
theano/tensor/tests/test_basic.py
浏览文件 @
fbc5a3a0
...
@@ -44,7 +44,7 @@ from theano.tensor import (_shared, wvector, bvector, autocast_float_as,
...
@@ -44,7 +44,7 @@ from theano.tensor import (_shared, wvector, bvector, autocast_float_as,
dtensor3
,
SpecifyShape
,
Mean
,
IncSubtensor
,
AdvancedIncSubtensor1
,
dtensor3
,
SpecifyShape
,
Mean
,
IncSubtensor
,
AdvancedIncSubtensor1
,
itensor3
,
Tile
,
AdvancedIncSubtensor
,
switch
,
Diagonal
,
Diag
,
itensor3
,
Tile
,
AdvancedIncSubtensor
,
switch
,
Diagonal
,
Diag
,
nonzero
,
flatnonzero
,
nonzero_values
,
inplace_increment
,
nonzero
,
flatnonzero
,
nonzero_values
,
inplace_increment
,
matrix
_of_scalars
)
tensor
_of_scalars
)
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
...
@@ -6779,15 +6779,25 @@ def test_transpose():
...
@@ -6779,15 +6779,25 @@ def test_transpose():
assert
tensor
.
transpose
(
x3
)
.
name
==
'x3.T'
assert
tensor
.
transpose
(
x3
)
.
name
==
'x3.T'
assert
tensor
.
transpose
(
tensor
.
dmatrix
())
.
name
is
None
assert
tensor
.
transpose
(
tensor
.
dmatrix
())
.
name
is
None
def
test_
matrix
_of_scalars
():
def
test_
tensor
_of_scalars
():
a
,
b
,
c
,
d
=
map
(
scalar
,
'abcd'
)
a
,
b
,
c
,
d
=
map
(
scalar
,
'abcd'
)
X
=
matrix
_of_scalars
([[
a
,
b
],
X
=
tensor
_of_scalars
([[
a
,
b
],
[
c
,
d
]])
[
c
,
d
]])
f
=
function
([
a
,
b
,
c
,
d
],
X
)
f
=
function
([
a
,
b
,
c
,
d
],
X
)
result
=
f
(
1
,
2
,
3
,
4
)
result
=
f
(
1
,
2
,
3
,
4
)
assert
result
.
shape
==
(
2
,
2
)
assert
result
.
shape
==
(
2
,
2
)
assert
numpy
.
allclose
(
f
(
1
,
2
,
3
,
4
),
numpy
.
asarray
([[
1
,
2
],[
3
,
4
]]))
assert
numpy
.
allclose
(
f
(
1
,
2
,
3
,
4
),
numpy
.
asarray
([[
1
,
2
],[
3
,
4
]]))
X
=
tensor_of_scalars
([
a
,
b
,
c
,
d
])
f
=
function
([
a
,
b
,
c
,
d
],
X
)
result
=
f
(
1
,
2
,
3
,
4
)
assert
result
.
shape
==
(
4
,)
assert
numpy
.
allclose
(
f
(
1
,
2
,
3
,
4
),
numpy
.
asarray
([[
1
,
2
,
3
,
4
]]))
X
=
tensor_of_scalars
([[[
a
],[
b
]],[[
c
],[
d
]]])
f
=
function
([
a
,
b
,
c
,
d
],
X
)
result
=
f
(
1
,
2
,
3
,
4
)
assert
result
.
shape
==
(
2
,
2
,
1
)
class
TestSpecifyShape
(
unittest
.
TestCase
):
class
TestSpecifyShape
(
unittest
.
TestCase
):
def
shortDescription
(
self
):
def
shortDescription
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论