Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
abe8581a
提交
abe8581a
authored
12月 01, 2015
作者:
Mathieu Germain
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use np.cumprod instead of np.diag in OpDecoratorTests
because as_op does not support operation that returns a view.
上级
f4268206
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
20 行增加
和
19 行删除
+20
-19
extending_theano.txt
doc/tutorial/extending_theano.txt
+4
-2
test_ops.py
theano/compile/tests/test_ops.py
+16
-17
没有找到文件。
doc/tutorial/extending_theano.txt
浏览文件 @
abe8581a
...
...
@@ -302,10 +302,10 @@ You can try it as follows:
.. testoutput:: example
:hide:
:options: +ELLIPSIS
...
...
.. code-block:: none
[[ 0.02443785 0.67833979 0.91954769 0.95444365]
...
...
@@ -657,6 +657,8 @@ signature:
It converts the Python function to a callable object that takes as
inputs Theano variables that were declared.
.. note::
The python function wrapped by the `as_op` decorator needs to return a new data allocation, no views or in place modification of the input.
as_op Example
-------------
...
...
theano/compile/tests/test_ops.py
浏览文件 @
abe8581a
...
...
@@ -6,7 +6,6 @@ import numpy as np
from
theano.tests
import
unittest_tools
as
utt
from
theano
import
function
import
theano
from
theano
import
tensor
from
theano.tensor
import
dmatrix
,
dvector
from
numpy
import
allclose
from
theano.compile
import
as_op
...
...
@@ -21,16 +20,17 @@ def mul(a, b):
class
OpDecoratorTests
(
utt
.
InferShapeTester
):
def
test_1arg
(
self
):
x
=
dmatrix
(
'x'
)
@as_op
(
dmatrix
,
dvector
)
def
diag
(
x
):
return
np
.
diag
(
x
)
def
cumprod
(
x
):
return
np
.
cumprod
(
x
)
fn
=
function
([
x
],
diag
(
x
))
fn
=
function
([
x
],
cumprod
(
x
))
r
=
fn
([[
1.5
,
5
],
[
2
,
2
]])
r0
=
np
.
array
([
1.5
,
2
])
r0
=
np
.
array
([
1.5
,
7.5
,
15.
,
30.
])
assert
allclose
(
r
,
r0
),
(
r
,
r0
)
...
...
@@ -41,12 +41,12 @@ class OpDecoratorTests(utt.InferShapeTester):
y
.
tag
.
test_value
=
[
0
,
0
]
@as_op
([
dmatrix
,
dvector
],
dvector
)
def
diag_mult
(
x
,
y
):
return
np
.
diag
(
x
)
*
y
def
cumprod_plus
(
x
,
y
):
return
np
.
cumprod
(
x
)
+
y
fn
=
function
([
x
,
y
],
diag_mult
(
x
,
y
))
r
=
fn
([[
1.5
,
5
],
[
2
,
2
]],
[
1
,
100
])
r0
=
np
.
array
([
1.5
,
200
])
fn
=
function
([
x
,
y
],
cumprod_plus
(
x
,
y
))
r
=
fn
([[
1.5
,
5
],
[
2
,
2
]],
[
1
,
100
,
2
,
200
])
r0
=
np
.
array
([
2.5
,
107.5
,
17.
,
230.
])
assert
allclose
(
r
,
r0
),
(
r
,
r0
)
...
...
@@ -61,12 +61,12 @@ class OpDecoratorTests(utt.InferShapeTester):
return
[
y
]
@as_op
([
dmatrix
,
dvector
],
dvector
,
infer_shape
)
def
diag_mult
(
x
,
y
):
return
np
.
diag
(
x
)
*
y
def
cumprod_plus
(
x
,
y
):
return
np
.
cumprod
(
x
)
+
y
self
.
_compile_and_check
([
x
,
y
],
[
diag_mult
(
x
,
y
)],
[[[
1.5
,
5
],
[
2
,
2
]],
[
1
,
100
]],
diag_mult
.
__class__
,
warn
=
False
)
self
.
_compile_and_check
([
x
,
y
],
[
cumprod_plus
(
x
,
y
)],
[[[
1.5
,
5
],
[
2
,
2
]],
[
1
,
100
,
2
,
200
]],
cumprod_plus
.
__class__
,
warn
=
False
)
def
test_pickle
(
self
):
x
=
dmatrix
(
'x'
)
...
...
@@ -81,5 +81,4 @@ class OpDecoratorTests(utt.InferShapeTester):
def
test_shape_i_hash
():
assert
isinstance
(
theano
.
tensor
.
opt
.
Shape_i
(
np
.
int64
(
1
))
.
__hash__
(),
int
)
assert
isinstance
(
theano
.
tensor
.
opt
.
Shape_i
(
np
.
int64
(
1
))
.
__hash__
(),
int
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论