Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6812b4bc
提交
6812b4bc
authored
8月 27, 2013
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Declare classes outside of test class so the Op can be pickled
上级
b0de5da7
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
78 行增加
和
70 行删除
+78
-70
test_compute_test_value.py
theano/gof/tests/test_compute_test_value.py
+26
-22
test_tutorial.py
theano/tests/test_tutorial.py
+52
-48
没有找到文件。
theano/gof/tests/test_compute_test_value.py
浏览文件 @
6812b4bc
...
@@ -14,6 +14,30 @@ from theano.scan_module import scan
...
@@ -14,6 +14,30 @@ from theano.scan_module import scan
from
theano.tensor.basic
import
_allclose
from
theano.tensor.basic
import
_allclose
# Used in TestComputeTestValue.test_no_perform
class
IncOneC
(
Op
):
"""An Op with only a C (c_code) implementation"""
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
def
__hash__
(
self
):
return
hash
(
type
(
self
))
def
make_node
(
self
,
input
):
input
=
scalar
.
as_scalar
(
input
)
output
=
input
.
type
()
return
Apply
(
self
,
[
input
],
[
output
])
def
c_code_cache_version
(
self
):
return
(
1
,)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
x
,
=
inputs
z
,
=
outputs
return
"
%(z)
s =
%(x)
s + 1;"
%
locals
()
class
TestComputeTestValue
(
unittest
.
TestCase
):
class
TestComputeTestValue
(
unittest
.
TestCase
):
def
test_variable_only
(
self
):
def
test_variable_only
(
self
):
...
@@ -338,28 +362,6 @@ class TestComputeTestValue(unittest.TestCase):
...
@@ -338,28 +362,6 @@ class TestComputeTestValue(unittest.TestCase):
def
test_no_perform
(
self
):
def
test_no_perform
(
self
):
if
not
theano
.
config
.
cxx
:
if
not
theano
.
config
.
cxx
:
raise
SkipTest
(
"G++ not available, so we need to skip this test."
)
raise
SkipTest
(
"G++ not available, so we need to skip this test."
)
class
IncOneC
(
Op
):
"""An Op with only a C (c_code) implementation"""
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
def
__hash__
(
self
):
return
hash
(
type
(
self
))
def
make_node
(
self
,
input
):
input
=
scalar
.
as_scalar
(
input
)
output
=
input
.
type
()
return
Apply
(
self
,
[
input
],
[
output
])
def
c_code_cache_version
(
self
):
return
(
1
,)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
x
,
=
inputs
z
,
=
outputs
return
"
%(z)
s =
%(x)
s + 1;"
%
locals
()
orig_compute_test_value
=
theano
.
config
.
compute_test_value
orig_compute_test_value
=
theano
.
config
.
compute_test_value
try
:
try
:
...
@@ -368,6 +370,8 @@ class TestComputeTestValue(unittest.TestCase):
...
@@ -368,6 +370,8 @@ class TestComputeTestValue(unittest.TestCase):
i
=
scalar
.
int32
(
'i'
)
i
=
scalar
.
int32
(
'i'
)
i
.
tag
.
test_value
=
3
i
.
tag
.
test_value
=
3
# Class IncOneC is defined outside of the TestComputeTestValue
# so it can be pickled and unpickled
o
=
IncOneC
()(
i
)
o
=
IncOneC
()(
i
)
# Check that the perform function is not implemented
# Check that the perform function is not implemented
...
...
theano/tests/test_tutorial.py
浏览文件 @
6812b4bc
...
@@ -879,6 +879,56 @@ class T_using_gpu(unittest.TestCase):
...
@@ -879,6 +879,56 @@ class T_using_gpu(unittest.TestCase):
for
x
in
f
.
maker
.
fgraph
.
toposort
()])
for
x
in
f
.
maker
.
fgraph
.
toposort
()])
# Used in T_fibby
class
Fibby
(
theano
.
Op
):
"""
An arbitrarily generalized Fibbonacci sequence
"""
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
def
__hash__
(
self
):
return
hash
(
type
(
self
))
def
make_node
(
self
,
x
):
x_
=
theano
.
tensor
.
as_tensor_variable
(
x
)
assert
x_
.
ndim
==
1
return
theano
.
Apply
(
self
,
inputs
=
[
x_
],
outputs
=
[
x_
.
type
()])
# using x_.type() is dangerous, it copies x's broadcasting
# behaviour
def
perform
(
self
,
node
,
inputs
,
output_storage
):
x
,
=
inputs
y
=
output_storage
[
0
][
0
]
=
x
.
copy
()
for
i
in
range
(
2
,
len
(
x
)):
y
[
i
]
=
y
[
i
-
1
]
*
y
[
i
-
2
]
+
x
[
i
]
def
c_code
(
self
,
node
,
name
,
inames
,
onames
,
sub
):
x
,
=
inames
y
,
=
onames
fail
=
sub
[
'fail'
]
return
"""
Py_XDECREF(
%(y)
s);
%(y)
s = (PyArrayObject*)PyArray_FromArray(
%(x)
s, 0, NPY_ARRAY_ENSURECOPY);
if (!
%(y)
s)
%(fail)
s;
{//New scope needed to make compilation work
dtype_
%(y)
s * y = (dtype_
%(y)
s*)
%(y)
s->data;
dtype_
%(x)
s * x = (dtype_
%(x)
s*)
%(x)
s->data;
for (int i = 2; i <
%(x)
s->dimensions[0]; ++i)
y[i] = y[i-1]*y[i-2] + x[i];
}
"""
%
locals
()
def
c_code_cache_version
(
self
):
return
(
1
,)
class
T_fibby
(
unittest
.
TestCase
):
class
T_fibby
(
unittest
.
TestCase
):
## All tests here belong to
## All tests here belong to
## http://deeplearning.net/software/theano/extending/fibby.html
## http://deeplearning.net/software/theano/extending/fibby.html
...
@@ -887,54 +937,8 @@ class T_fibby(unittest.TestCase):
...
@@ -887,54 +937,8 @@ class T_fibby(unittest.TestCase):
def
test_fibby_1
(
self
):
def
test_fibby_1
(
self
):
class
Fibby
(
theano
.
Op
):
# The definition of class Fibby is done outside of the test,
# so the object can be pickled.
"""
An arbitrarily generalized Fibbonacci sequence
"""
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
def
__hash__
(
self
):
return
hash
(
type
(
self
))
def
make_node
(
self
,
x
):
x_
=
theano
.
tensor
.
as_tensor_variable
(
x
)
assert
x_
.
ndim
==
1
return
theano
.
Apply
(
self
,
inputs
=
[
x_
],
outputs
=
[
x_
.
type
()])
# using x_.type() is dangerous, it copies x's broadcasting
# behaviour
def
perform
(
self
,
node
,
inputs
,
output_storage
):
x
,
=
inputs
y
=
output_storage
[
0
][
0
]
=
x
.
copy
()
for
i
in
range
(
2
,
len
(
x
)):
y
[
i
]
=
y
[
i
-
1
]
*
y
[
i
-
2
]
+
x
[
i
]
def
c_code
(
self
,
node
,
name
,
inames
,
onames
,
sub
):
x
,
=
inames
y
,
=
onames
fail
=
sub
[
'fail'
]
return
"""
Py_XDECREF(
%(y)
s);
%(y)
s = (PyArrayObject*)PyArray_FromArray(
%(x)
s, 0, NPY_ARRAY_ENSURECOPY);
if (!
%(y)
s)
%(fail)
s;
{//New scope needed to make compilation work
dtype_
%(y)
s * y = (dtype_
%(y)
s*)
%(y)
s->data;
dtype_
%(x)
s * x = (dtype_
%(x)
s*)
%(x)
s->data;
for (int i = 2; i <
%(x)
s->dimensions[0]; ++i)
y[i] = y[i-1]*y[i-2] + x[i];
}
"""
%
locals
()
def
c_code_cache_version
(
self
):
return
(
1
,)
fibby
=
Fibby
()
fibby
=
Fibby
()
from
theano.tensor.opt
import
(
get_scalar_constant_value
,
from
theano.tensor.opt
import
(
get_scalar_constant_value
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论