Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b71bfbc4
提交
b71bfbc4
authored
7月 31, 2012
作者:
Eric Larsen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Split op and test classes, improve description of out_var in make_node.
上级
64cda1d9
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
58 行增加
和
45 行删除
+58
-45
kron.py
theano/sandbox/linalg/kron.py
+6
-45
test_kron.py
theano/sandbox/linalg/tests/test_kron.py
+52
-0
没有找到文件。
theano/sandbox/linalg/kron.py
浏览文件 @
b71bfbc4
import
numpy
import
numpy
import
theano
from
theano.gof
import
Op
,
Apply
from
theano.gof
import
Op
,
Apply
from
theano
import
tensor
,
function
from
theano
import
tensor
from
theano.tests
import
unittest_tools
as
utt
try
:
try
:
import
scipy.linalg
import
scipy.linalg
...
@@ -24,6 +24,7 @@ class Kron(Op):
...
@@ -24,6 +24,7 @@ class Kron(Op):
A: array, shape (M*P, N*Q)
A: array, shape (M*P, N*Q)
The result is the block matrix:
The result is the block matrix:
(notice that a[i,j]*b is itself a matrix of the same shape as b)
a[0,0]*b a[0,1]*b ... a[0,-1]*b
a[0,0]*b a[0,1]*b ... a[0,-1]*b
a[1,0]*b a[1,1]*b ... a[1,-1]*b
a[1,0]*b a[1,1]*b ... a[1,-1]*b
...
@@ -42,7 +43,7 @@ class Kron(Op):
...
@@ -42,7 +43,7 @@ class Kron(Op):
def
make_node
(
self
,
a
,
b
):
def
make_node
(
self
,
a
,
b
):
assert
imported_scipy
,
(
assert
imported_scipy
,
(
"Scipy not available. Scipy is needed for the
Solve
op"
)
"Scipy not available. Scipy is needed for the
Kron
op"
)
a
=
tensor
.
as_tensor_variable
(
a
)
a
=
tensor
.
as_tensor_variable
(
a
)
b
=
tensor
.
as_tensor_variable
(
b
)
b
=
tensor
.
as_tensor_variable
(
b
)
...
@@ -50,9 +51,9 @@ class Kron(Op):
...
@@ -50,9 +51,9 @@ class Kron(Op):
raise
TypeError
(
'
%
s: inputs must have two dimensions'
%
raise
TypeError
(
'
%
s: inputs must have two dimensions'
%
self
.
__class__
.
__name__
)
self
.
__class__
.
__name__
)
out_
type
=
tensor
.
TensorType
(
dtype
=
(
a
[
0
,
0
]
*
b
[
0
,
0
])
.
dtype
,
out_
var
=
tensor
.
TensorType
(
dtype
=
theano
.
scalar
.
upcast
(
a
,
b
)
,
broadcastable
=
(
False
,
False
))()
broadcastable
=
(
False
,
False
))()
return
Apply
(
self
,
[
a
,
b
],
[
out_
type
])
return
Apply
(
self
,
[
a
,
b
],
[
out_
var
])
def
infer_shape
(
self
,
node
,
in_shapes
):
def
infer_shape
(
self
,
node
,
in_shapes
):
shape_a
,
shape_b
=
in_shapes
shape_a
,
shape_b
=
in_shapes
...
@@ -67,43 +68,3 @@ class Kron(Op):
...
@@ -67,43 +68,3 @@ class Kron(Op):
' implemented'
%
self
.
__class__
.
__name__
)
' implemented'
%
self
.
__class__
.
__name__
)
kron
=
Kron
()
kron
=
Kron
()
class
TestKron
(
utt
.
InferShapeTester
):
rng
=
numpy
.
random
.
RandomState
(
43
)
def
setUp
(
self
):
super
(
TestKron
,
self
)
.
setUp
()
self
.
op_class
=
Kron
self
.
op
=
kron
def
test_perform
(
self
):
x
=
tensor
.
dmatrix
()
y
=
tensor
.
dmatrix
()
f
=
function
([
x
,
y
],
kron
(
x
,
y
))
for
shp0
in
[(
8
,
6
),
(
5
,
8
)]:
for
shp1
in
[(
5
,
7
),
(
3
,
3
)]:
a
=
numpy
.
random
.
rand
(
*
shp0
)
b
=
numpy
.
random
.
rand
(
*
shp1
)
out
=
f
(
a
,
b
)
assert
numpy
.
allclose
(
out
,
scipy
.
linalg
.
kron
(
a
,
b
))
def
test_infer_shape
(
self
):
x
=
tensor
.
dmatrix
()
y
=
tensor
.
dmatrix
()
self
.
_compile_and_check
([
x
,
y
],
[
self
.
op
(
x
,
y
)],
[
numpy
.
random
.
rand
(
8
,
5
),
numpy
.
random
.
rand
(
3
,
7
)],
self
.
op_class
)
self
.
_compile_and_check
([
x
,
y
],
[
self
.
op
(
x
,
y
)],
[
numpy
.
random
.
rand
(
2
,
5
),
numpy
.
random
.
rand
(
6
,
3
)],
self
.
op_class
)
if
__name__
==
"__main__"
:
t
=
TestKron
(
'setUp'
)
t
.
setUp
()
t
.
test_perform
()
t
.
test_infer_shape
()
theano/sandbox/linalg/tests/test_kron.py
0 → 100644
浏览文件 @
b71bfbc4
import
numpy
from
theano
import
tensor
,
function
from
theano.tests
import
unittest_tools
as
utt
from
theano.sandbox.linalg.kron
import
Kron
,
kron
try
:
import
scipy.linalg
imported_scipy
=
True
except
ImportError
:
imported_scipy
=
False
class
TestKron
(
utt
.
InferShapeTester
):
rng
=
numpy
.
random
.
RandomState
(
43
)
def
setUp
(
self
):
super
(
TestKron
,
self
)
.
setUp
()
self
.
op_class
=
Kron
self
.
op
=
kron
def
test_perform
(
self
):
assert
imported_scipy
,
(
"Scipy not available. Scipy is needed for TestKron"
)
x
=
tensor
.
dmatrix
()
y
=
tensor
.
dmatrix
()
f
=
function
([
x
,
y
],
kron
(
x
,
y
))
for
shp0
in
[(
8
,
6
),
(
5
,
8
)]:
for
shp1
in
[(
5
,
7
),
(
3
,
3
)]:
a
=
numpy
.
random
.
rand
(
*
shp0
)
b
=
numpy
.
random
.
rand
(
*
shp1
)
out
=
f
(
a
,
b
)
assert
numpy
.
allclose
(
out
,
scipy
.
linalg
.
kron
(
a
,
b
))
def
test_infer_shape
(
self
):
x
=
tensor
.
dmatrix
()
y
=
tensor
.
dmatrix
()
self
.
_compile_and_check
([
x
,
y
],
[
self
.
op
(
x
,
y
)],
[
numpy
.
random
.
rand
(
8
,
5
),
numpy
.
random
.
rand
(
3
,
7
)],
self
.
op_class
)
self
.
_compile_and_check
([
x
,
y
],
[
self
.
op
(
x
,
y
)],
[
numpy
.
random
.
rand
(
2
,
5
),
numpy
.
random
.
rand
(
6
,
3
)],
self
.
op_class
)
if
__name__
==
"__main__"
:
t
=
TestKron
(
'setUp'
)
t
.
setUp
()
t
.
test_perform
()
t
.
test_infer_shape
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论