Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e3430b61
提交
e3430b61
authored
12月 07, 2015
作者:
Ramana.S
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Moved the mae_node method
上级
57a2f9c8
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
48 行增加
和
21 行删除
+48
-21
test_ops.py
theano/compile/tests/test_ops.py
+0
-20
op.py
theano/gof/op.py
+21
-0
test_op.py
theano/gof/tests/test_op.py
+27
-1
没有找到文件。
theano/compile/tests/test_ops.py
浏览文件 @
e3430b61
...
...
@@ -34,26 +34,6 @@ class OpDecoratorTests(utt.InferShapeTester):
assert
allclose
(
r
,
r0
),
(
r
,
r0
)
def
test_make_node
(
self
):
x
=
dmatrix
(
'x'
)
x
.
tag
.
test_value
=
np
.
zeros
((
2
,
2
))
y
=
dvector
(
'y'
)
y
.
tag
.
test_value
=
[
0
,
0
]
with
self
.
assertRaisesRegexp
(
NotImplementedError
,
"itypes not defined"
)
:
@as_op
(
itypes
=
[],
otypes
=
dvector
)
def
none_itypes
(
x
,
y
):
return
np
.
dot
(
x
,
y
)
none_itypes
(
x
,
y
)
with
self
.
assertRaisesRegexp
(
NotImplementedError
,
"otypes not defined"
)
:
@as_op
(
itypes
=
[
dmatrix
,
dvector
],
otypes
=
[])
def
none_otypes
(
x
,
y
):
return
np
.
dot
(
x
,
y
)
none_otypes
(
x
,
y
)
def
test_2arg
(
self
):
x
=
dmatrix
(
'x'
)
x
.
tag
.
test_value
=
np
.
zeros
((
2
,
2
))
...
...
theano/gof/op.py
浏览文件 @
e3430b61
...
...
@@ -765,6 +765,10 @@ class Op(utils.object2, PureOp, CLinkerOp):
Convenience class to bundle `PureOp` and `CLinkerOp`.
"""
def
__new__
(
cls
,
*
args
,
**
kwargs
):
# this function exists to silently and transparently ensure that all
# existing Ops get a _op_use_c_code attribute
...
...
@@ -932,6 +936,23 @@ class Op(utils.object2, PureOp, CLinkerOp):
# condition: either there was no c_code, or it failed
return
self
.
make_py_thunk
(
node
,
storage_map
,
compute_map
,
no_recycling
)
def
make_node
(
self
,
*
inputs
):
if
not
hasattr
(
self
,
'itypes'
):
raise
NotImplementedError
(
"itypes not defined"
)
if
not
hasattr
(
self
,
'otypes'
)
:
raise
NotImplementedError
(
"otypes not defined"
)
if
len
(
inputs
)
!=
len
(
self
.
itypes
):
raise
ValueError
(
"We expected
%
d inputs but got
%
d."
%
(
len
(
self
.
itypes
),
len
(
inputs
)))
if
not
all
(
inp
.
type
==
it
for
inp
,
it
in
zip
(
inputs
,
self
.
itypes
)):
raise
TypeError
(
"We expected inputs of types '
%
s' but got types '
%
s' "
%
(
str
([
inp
.
type
for
inp
in
inputs
]),
str
(
self
.
itypes
)))
return
theano
.
Apply
(
self
,
inputs
,
[
o
()
for
o
in
self
.
otypes
])
def
get_test_value
(
v
):
...
...
theano/gof/tests/test_op.py
浏览文件 @
e3430b61
...
...
@@ -9,6 +9,7 @@ from six import string_types
from
theano.gof.type
import
Type
,
Generic
from
theano.gof.graph
import
Apply
,
Variable
import
theano.tensor
as
T
from
theano.compile
import
as_op
from
theano
import
scalar
from
theano
import
shared
...
...
@@ -57,7 +58,8 @@ class MyType(Type):
class
MyOp
(
Op
):
__props__
=
()
'''
def make_node(self, *inputs):
inputs = list(map(as_variable, inputs))
for input in inputs:
...
...
@@ -65,6 +67,7 @@ class MyOp(Op):
raise Exception("Error 1")
outputs = [MyType(sum([input.type.thingy for input in inputs]))()]
return Apply(self, inputs, outputs)
'''
MyOp
=
MyOp
()
...
...
@@ -381,5 +384,28 @@ def test_debug_error_message():
finally
:
config
.
compute_test_value
=
prev_value
'''
def test_make_node():
x = T.dmatrix('x')
x.tag.test_value = numpy.zeros((2, 2))
y = T.dvector('y')
y.tag.test_value = [0, 0]
with unittest.assertRaisesRegexp(NotImplementedError, "itypes not defined") :
@as_op(itypes=[], otypes=T.dvector)
def none_itypes(x,y):
return numpy.dot(x,y)
none_itypes(x,y)
with assertRaisesRegexp(NotImplementedError, "otypes not defined") :
@as_op(itypes=[T.dmatrix, T.dvector], otypes=[])
def none_otypes(x,y):
return numpy.dot(x,y)
none_otypes(x, y)
'''
if
__name__
==
'__main__'
:
unittest
.
main
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论