Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8f9f5da1
提交
8f9f5da1
authored
4月 16, 2013
作者:
Olivier Delalleau
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1335 from mrocklin/matrix_of_scalars
Add matrix_of_scalars function
上级
8632816e
8eefe5a0
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
58 行增加
和
1 行删除
+58
-1
basic.py
theano/tensor/basic.py
+30
-0
test_basic.py
theano/tensor/tests/test_basic.py
+28
-1
没有找到文件。
theano/tensor/basic.py
浏览文件 @
8f9f5da1
...
@@ -8224,3 +8224,33 @@ def diag(v, k=0):
...
@@ -8224,3 +8224,33 @@ def diag(v, k=0):
return
diagonal
(
v
,
k
)
return
diagonal
(
v
,
k
)
else
:
else
:
raise
ValueError
(
"Input must be 1- or 2-d."
)
raise
ValueError
(
"Input must be 1- or 2-d."
)
def
stacklists
(
arg
):
""" Recursivly stack lists of tensors to maintain similar structure
This function can create a tensor from a shaped list of scalars
>>> from theano.tensor import stacklists, scalar, matrix
>>> from theano import function
>>> a,b,c,d = map(scalar, 'abcd')
>>> X = stacklists([[a, b],
... [c, d]])
>>> f = function([a, b, c, d], X)
>>> f(1, 2, 3, 4)
array([[ 1., 2.],
[ 3., 4.]], dtype=float32)
We can also stack arbitrarily shaped tensors. Here we stack matrices into
a 2 by 2 grid.
>>> from numpy import ones
>>> a,b,c,d, = [tensor.matrix(a) for a in 'abcd']
>>> X = stacklists([[a, b],
... [c, d]])
>>> f = function([a, b, c, d], X)
>>> x = ones((4, 4), 'float32')
>>> f(x, x, x, x).shape
(2, 2, 4, 4)
"""
if
isinstance
(
arg
,
(
tuple
,
list
)):
return
stack
(
*
map
(
stacklists
,
arg
))
else
:
return
arg
theano/tensor/tests/test_basic.py
浏览文件 @
8f9f5da1
...
@@ -43,7 +43,8 @@ from theano.tensor import (_shared, wvector, bvector, autocast_float_as,
...
@@ -43,7 +43,8 @@ from theano.tensor import (_shared, wvector, bvector, autocast_float_as,
ScalarFromTensor
,
TensorFromScalar
,
dtensor4
,
Rebroadcast
,
Alloc
,
ScalarFromTensor
,
TensorFromScalar
,
dtensor4
,
Rebroadcast
,
Alloc
,
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
,
stacklists
)
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
...
@@ -6778,6 +6779,32 @@ def test_transpose():
...
@@ -6778,6 +6779,32 @@ 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_stacklists
():
a
,
b
,
c
,
d
=
map
(
scalar
,
'abcd'
)
X
=
stacklists
([[
a
,
b
],
[
c
,
d
]])
f
=
function
([
a
,
b
,
c
,
d
],
X
)
result
=
f
(
1
,
2
,
3
,
4
)
assert
result
.
shape
==
(
2
,
2
)
assert
numpy
.
allclose
(
f
(
1
,
2
,
3
,
4
),
numpy
.
asarray
([[
1
,
2
],[
3
,
4
]]))
X
=
stacklists
([
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
=
stacklists
([[[
a
],[
b
]],[[
c
],[
d
]]])
f
=
function
([
a
,
b
,
c
,
d
],
X
)
result
=
f
(
1
,
2
,
3
,
4
)
assert
result
.
shape
==
(
2
,
2
,
1
)
a
,
b
,
c
,
d
=
[
matrix
(
a
)
for
a
in
'abcd'
]
X
=
stacklists
([[
a
,
b
],
[
c
,
d
]])
f
=
function
([
a
,
b
,
c
,
d
],
X
)
x
=
numpy
.
ones
((
4
,
4
),
'float32'
)
assert
f
(
x
,
x
,
x
,
x
)
.
shape
==
(
2
,
2
,
4
,
4
)
class
TestSpecifyShape
(
unittest
.
TestCase
):
class
TestSpecifyShape
(
unittest
.
TestCase
):
def
shortDescription
(
self
):
def
shortDescription
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论