Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
11fefcee
提交
11fefcee
authored
4月 10, 2017
作者:
amrithasuresh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Updated numpy as np
上级
e1efaabb
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
23 行增加
和
23 行删除
+23
-23
extending_theano_solution_1.py
doc/extending/extending_theano_solution_1.py
+23
-23
没有找到文件。
doc/extending/extending_theano_solution_1.py
浏览文件 @
11fefcee
...
@@ -85,7 +85,7 @@ class SumDiffOp(theano.Op):
...
@@ -85,7 +85,7 @@ class SumDiffOp(theano.Op):
# 3. Testing apparatus
# 3. Testing apparatus
import
numpy
import
numpy
as
np
from
theano.gof
import
Op
,
Apply
from
theano.gof
import
Op
,
Apply
from
theano
import
tensor
,
function
,
printing
from
theano
import
tensor
,
function
,
printing
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
...
@@ -93,7 +93,7 @@ from theano.tests import unittest_tools as utt
...
@@ -93,7 +93,7 @@ from theano.tests import unittest_tools as utt
class
TestProdOp
(
utt
.
InferShapeTester
):
class
TestProdOp
(
utt
.
InferShapeTester
):
rng
=
n
umpy
.
random
.
RandomState
(
43
)
rng
=
n
p
.
random
.
RandomState
(
43
)
def
setUp
(
self
):
def
setUp
(
self
):
super
(
TestProdOp
,
self
)
.
setUp
()
super
(
TestProdOp
,
self
)
.
setUp
()
...
@@ -103,14 +103,14 @@ class TestProdOp(utt.InferShapeTester):
...
@@ -103,14 +103,14 @@ class TestProdOp(utt.InferShapeTester):
x
=
theano
.
tensor
.
matrix
()
x
=
theano
.
tensor
.
matrix
()
y
=
theano
.
tensor
.
matrix
()
y
=
theano
.
tensor
.
matrix
()
f
=
theano
.
function
([
x
,
y
],
self
.
op_class
()(
x
,
y
))
f
=
theano
.
function
([
x
,
y
],
self
.
op_class
()(
x
,
y
))
x_val
=
n
umpy
.
random
.
rand
(
5
,
4
)
x_val
=
n
p
.
random
.
rand
(
5
,
4
)
y_val
=
n
umpy
.
random
.
rand
(
5
,
4
)
y_val
=
n
p
.
random
.
rand
(
5
,
4
)
out
=
f
(
x_val
,
y_val
)
out
=
f
(
x_val
,
y_val
)
assert
n
umpy
.
allclose
(
x_val
*
y_val
,
out
)
assert
n
p
.
allclose
(
x_val
*
y_val
,
out
)
def
test_gradient
(
self
):
def
test_gradient
(
self
):
utt
.
verify_grad
(
self
.
op_class
(),
[
n
umpy
.
random
.
rand
(
5
,
4
),
utt
.
verify_grad
(
self
.
op_class
(),
[
n
p
.
random
.
rand
(
5
,
4
),
n
umpy
.
random
.
rand
(
5
,
4
)],
n
p
.
random
.
rand
(
5
,
4
)],
n_tests
=
1
,
rng
=
TestProdOp
.
rng
)
n_tests
=
1
,
rng
=
TestProdOp
.
rng
)
def
test_infer_shape
(
self
):
def
test_infer_shape
(
self
):
...
@@ -118,14 +118,14 @@ class TestProdOp(utt.InferShapeTester):
...
@@ -118,14 +118,14 @@ class TestProdOp(utt.InferShapeTester):
y
=
tensor
.
dmatrix
()
y
=
tensor
.
dmatrix
()
self
.
_compile_and_check
([
x
,
y
],
[
self
.
op_class
()(
x
,
y
)],
self
.
_compile_and_check
([
x
,
y
],
[
self
.
op_class
()(
x
,
y
)],
[
n
umpy
.
random
.
rand
(
5
,
6
),
[
n
p
.
random
.
rand
(
5
,
6
),
n
umpy
.
random
.
rand
(
5
,
6
)],
n
p
.
random
.
rand
(
5
,
6
)],
self
.
op_class
)
self
.
op_class
)
class
TestSumDiffOp
(
utt
.
InferShapeTester
):
class
TestSumDiffOp
(
utt
.
InferShapeTester
):
rng
=
n
umpy
.
random
.
RandomState
(
43
)
rng
=
n
p
.
random
.
RandomState
(
43
)
def
setUp
(
self
):
def
setUp
(
self
):
super
(
TestSumDiffOp
,
self
)
.
setUp
()
super
(
TestSumDiffOp
,
self
)
.
setUp
()
...
@@ -135,10 +135,10 @@ class TestSumDiffOp(utt.InferShapeTester):
...
@@ -135,10 +135,10 @@ class TestSumDiffOp(utt.InferShapeTester):
x
=
theano
.
tensor
.
matrix
()
x
=
theano
.
tensor
.
matrix
()
y
=
theano
.
tensor
.
matrix
()
y
=
theano
.
tensor
.
matrix
()
f
=
theano
.
function
([
x
,
y
],
self
.
op_class
()(
x
,
y
))
f
=
theano
.
function
([
x
,
y
],
self
.
op_class
()(
x
,
y
))
x_val
=
n
umpy
.
random
.
rand
(
5
,
4
)
x_val
=
n
p
.
random
.
rand
(
5
,
4
)
y_val
=
n
umpy
.
random
.
rand
(
5
,
4
)
y_val
=
n
p
.
random
.
rand
(
5
,
4
)
out
=
f
(
x_val
,
y_val
)
out
=
f
(
x_val
,
y_val
)
assert
n
umpy
.
allclose
([
x_val
+
y_val
,
x_val
-
y_val
],
out
)
assert
n
p
.
allclose
([
x_val
+
y_val
,
x_val
-
y_val
],
out
)
def
test_gradient
(
self
):
def
test_gradient
(
self
):
def
output_0
(
x
,
y
):
def
output_0
(
x
,
y
):
...
@@ -147,11 +147,11 @@ class TestSumDiffOp(utt.InferShapeTester):
...
@@ -147,11 +147,11 @@ class TestSumDiffOp(utt.InferShapeTester):
def
output_1
(
x
,
y
):
def
output_1
(
x
,
y
):
return
self
.
op_class
()(
x
,
y
)[
1
]
return
self
.
op_class
()(
x
,
y
)[
1
]
utt
.
verify_grad
(
output_0
,
[
n
umpy
.
random
.
rand
(
5
,
4
),
utt
.
verify_grad
(
output_0
,
[
n
p
.
random
.
rand
(
5
,
4
),
n
umpy
.
random
.
rand
(
5
,
4
)],
n
p
.
random
.
rand
(
5
,
4
)],
n_tests
=
1
,
rng
=
TestSumDiffOp
.
rng
)
n_tests
=
1
,
rng
=
TestSumDiffOp
.
rng
)
utt
.
verify_grad
(
output_1
,
[
n
umpy
.
random
.
rand
(
5
,
4
),
utt
.
verify_grad
(
output_1
,
[
n
p
.
random
.
rand
(
5
,
4
),
n
umpy
.
random
.
rand
(
5
,
4
)],
n
p
.
random
.
rand
(
5
,
4
)],
n_tests
=
1
,
rng
=
TestSumDiffOp
.
rng
)
n_tests
=
1
,
rng
=
TestSumDiffOp
.
rng
)
def
test_infer_shape
(
self
):
def
test_infer_shape
(
self
):
...
@@ -161,14 +161,14 @@ class TestSumDiffOp(utt.InferShapeTester):
...
@@ -161,14 +161,14 @@ class TestSumDiffOp(utt.InferShapeTester):
# adapt the choice of the next instruction to the op under test
# adapt the choice of the next instruction to the op under test
self
.
_compile_and_check
([
x
,
y
],
self
.
op_class
()(
x
,
y
),
self
.
_compile_and_check
([
x
,
y
],
self
.
op_class
()(
x
,
y
),
[
n
umpy
.
random
.
rand
(
5
,
6
),
[
n
p
.
random
.
rand
(
5
,
6
),
n
umpy
.
random
.
rand
(
5
,
6
)],
n
p
.
random
.
rand
(
5
,
6
)],
self
.
op_class
)
self
.
op_class
)
# as_op exercice
# as_op exercice
import
theano
import
theano
import
numpy
import
numpy
as
np
from
theano.compile.ops
import
as_op
from
theano.compile.ops
import
as_op
...
@@ -180,7 +180,7 @@ def infer_shape_numpy_dot(node, input_shapes):
...
@@ -180,7 +180,7 @@ def infer_shape_numpy_dot(node, input_shapes):
@as_op
(
itypes
=
[
theano
.
tensor
.
fmatrix
,
theano
.
tensor
.
fmatrix
],
@as_op
(
itypes
=
[
theano
.
tensor
.
fmatrix
,
theano
.
tensor
.
fmatrix
],
otypes
=
[
theano
.
tensor
.
fmatrix
],
infer_shape
=
infer_shape_numpy_dot
)
otypes
=
[
theano
.
tensor
.
fmatrix
],
infer_shape
=
infer_shape_numpy_dot
)
def
numpy_add
(
a
,
b
):
def
numpy_add
(
a
,
b
):
return
n
umpy
.
add
(
a
,
b
)
return
n
p
.
add
(
a
,
b
)
def
infer_shape_numpy_add_sub
(
node
,
input_shapes
):
def
infer_shape_numpy_add_sub
(
node
,
input_shapes
):
...
@@ -192,13 +192,13 @@ def infer_shape_numpy_add_sub(node, input_shapes):
...
@@ -192,13 +192,13 @@ def infer_shape_numpy_add_sub(node, input_shapes):
@as_op
(
itypes
=
[
theano
.
tensor
.
fmatrix
,
theano
.
tensor
.
fmatrix
],
@as_op
(
itypes
=
[
theano
.
tensor
.
fmatrix
,
theano
.
tensor
.
fmatrix
],
otypes
=
[
theano
.
tensor
.
fmatrix
],
infer_shape
=
infer_shape_numpy_add_sub
)
otypes
=
[
theano
.
tensor
.
fmatrix
],
infer_shape
=
infer_shape_numpy_add_sub
)
def
numpy_add
(
a
,
b
):
def
numpy_add
(
a
,
b
):
return
n
umpy
.
add
(
a
,
b
)
return
n
p
.
add
(
a
,
b
)
@as_op
(
itypes
=
[
theano
.
tensor
.
fmatrix
,
theano
.
tensor
.
fmatrix
],
@as_op
(
itypes
=
[
theano
.
tensor
.
fmatrix
,
theano
.
tensor
.
fmatrix
],
otypes
=
[
theano
.
tensor
.
fmatrix
],
infer_shape
=
infer_shape_numpy_add_sub
)
otypes
=
[
theano
.
tensor
.
fmatrix
],
infer_shape
=
infer_shape_numpy_add_sub
)
def
numpy_sub
(
a
,
b
):
def
numpy_sub
(
a
,
b
):
return
n
umpy
.
sub
(
a
,
b
)
return
n
p
.
sub
(
a
,
b
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论