Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4f0249a5
提交
4f0249a5
authored
2月 25, 2017
作者:
notoraptor
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move code into theano/gof.
Fix Python3 compat. Add comment to explain the code. Update unit tests.
上级
5a14c0c4
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
17 行增加
和
13 行删除
+17
-13
__init__.py
theano/common/__init__.py
+0
-2
__init__.py
theano/common/tests/__init__.py
+0
-1
test_wrapper.py
theano/gof/tests/test_wrapper.py
+9
-8
wrapper.py
theano/gof/wrapper.py
+8
-1
test_flake8.py
theano/tests/test_flake8.py
+0
-1
没有找到文件。
theano/common/__init__.py
deleted
100644 → 0
浏览文件 @
5a14c0c4
from
__future__
import
absolute_import
,
print_function
,
division
from
.wrapper
import
Wrapper
,
Wrap
theano/common/tests/__init__.py
deleted
100644 → 0
浏览文件 @
5a14c0c4
from
__future__
import
absolute_import
,
print_function
,
division
theano/
common
/tests/test_wrapper.py
→
theano/
gof
/tests/test_wrapper.py
浏览文件 @
4f0249a5
...
@@ -11,14 +11,14 @@ from theano import tensor
...
@@ -11,14 +11,14 @@ from theano import tensor
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
dtype
=
config
.
floatX
dtype
=
config
.
floatX
ScalarT
ype
=
TensorType
(
dtype
,
tuple
())
scalar_t
ype
=
TensorType
(
dtype
,
tuple
())
# A test op to compute `y = a*x^2 + bx + c` for any tensor x,
# A test op to compute `y = a*x^2 + bx + c` for any tensor x,
# such that a, b, c are parameters of that op.
# such that a, b, c are parameters of that op.
class
QuadraticFunction
(
Op
):
class
QuadraticFunction
(
Op
):
__props__
=
(
'a'
,
'b'
,
'c'
)
__props__
=
(
'a'
,
'b'
,
'c'
)
params_type
=
Wrapper
(
a
=
ScalarType
,
b
=
ScalarType
,
c
=
ScalarT
ype
)
params_type
=
Wrapper
(
a
=
scalar_type
,
b
=
scalar_type
,
c
=
scalar_t
ype
)
def
__init__
(
self
,
a
,
b
,
c
):
def
__init__
(
self
,
a
,
b
,
c
):
self
.
a
=
a
self
.
a
=
a
...
@@ -43,13 +43,13 @@ class QuadraticFunction(Op):
...
@@ -43,13 +43,13 @@ class QuadraticFunction(Op):
def
c_support_code_apply
(
self
,
node
,
name
):
def
c_support_code_apply
(
self
,
node
,
name
):
float_type
=
node
.
inputs
[
0
]
.
type
.
dtype_specs
()[
1
]
float_type
=
node
.
inputs
[
0
]
.
type
.
dtype_specs
()[
1
]
return
"""
return
"""
/* Computes: x = a*x*x + b*x + c for x in
matrix
. */
/* Computes: x = a*x*x + b*x + c for x in
tensor
. */
int quadratic_
%(float_type)
s(PyArrayObject*
matrix
,
%(float_type)
s a,
%(float_type)
s b,
%(float_type)
s c) {
int quadratic_
%(float_type)
s(PyArrayObject*
tensor
,
%(float_type)
s a,
%(float_type)
s b,
%(float_type)
s c) {
NpyIter* iterator = NpyIter_New(
matrix
,
NpyIter* iterator = NpyIter_New(
tensor
,
NPY_ITER_READWRITE | NPY_ITER_EXTERNAL_LOOP | NPY_ITER_REFS_OK,
NPY_ITER_READWRITE | NPY_ITER_EXTERNAL_LOOP | NPY_ITER_REFS_OK,
NPY_KEEPORDER, NPY_NO_CASTING, NULL);
NPY_KEEPORDER, NPY_NO_CASTING, NULL);
if(iterator == NULL) {
if(iterator == NULL) {
PyErr_SetString(PyExc_RuntimeError, "Unable to iterate over a
matrix
for an elemwise operation.");
PyErr_SetString(PyExc_RuntimeError, "Unable to iterate over a
tensor
for an elemwise operation.");
return -1;
return -1;
}
}
NpyIter_IterNextFunc* get_next = NpyIter_GetIterNext(iterator, NULL);
NpyIter_IterNextFunc* get_next = NpyIter_GetIterNext(iterator, NULL);
...
@@ -130,6 +130,7 @@ class TestWrapper(TestCase):
...
@@ -130,6 +130,7 @@ class TestWrapper(TestCase):
a3
=
Generic
())
a3
=
Generic
())
assert
w1
==
w2
assert
w1
==
w2
assert
hash
(
w1
)
==
hash
(
w2
)
assert
hash
(
w1
)
==
hash
(
w2
)
assert
w1
.
name
==
w2
.
name
# Changing attributes names only.
# Changing attributes names only.
w2
=
Wrapper
(
a1
=
TensorType
(
'int64'
,
(
False
,
False
)),
w2
=
Wrapper
(
a1
=
TensorType
(
'int64'
,
(
False
,
False
)),
other_name
=
TensorType
(
'int64'
,
(
False
,
True
,
False
,
False
,
True
)),
other_name
=
TensorType
(
'int64'
,
(
False
,
True
,
False
,
False
,
True
)),
...
@@ -148,7 +149,7 @@ class TestWrapper(TestCase):
...
@@ -148,7 +149,7 @@ class TestWrapper(TestCase):
def
test_wrapper_filtering
(
self
):
def
test_wrapper_filtering
(
self
):
shape_tensor5
=
(
1
,
2
,
2
,
3
,
2
)
shape_tensor5
=
(
1
,
2
,
2
,
3
,
2
)
size_tensor5
=
reduce
(
lambda
x
,
y
:
x
*
y
,
shape_tensor5
,
1
)
size_tensor5
=
shape_tensor5
[
0
]
*
shape_tensor5
[
1
]
*
shape_tensor5
[
2
]
*
shape_tensor5
[
3
]
*
shape_tensor5
[
4
]
random_tensor
=
numpy
.
random
.
normal
(
size
=
size_tensor5
)
.
astype
(
'float64'
)
.
reshape
(
shape_tensor5
)
random_tensor
=
numpy
.
random
.
normal
(
size
=
size_tensor5
)
.
astype
(
'float64'
)
.
reshape
(
shape_tensor5
)
# With a wrapper that does not match the value.
# With a wrapper that does not match the value.
...
@@ -188,7 +189,7 @@ class TestWrapper(TestCase):
...
@@ -188,7 +189,7 @@ class TestWrapper(TestCase):
assert
w
.
values_eq_approx
(
o
,
o3
)
assert
w
.
values_eq_approx
(
o
,
o3
)
def
test_
wrapper
(
self
):
def
test_
op_params
(
self
):
a
,
b
,
c
=
2
,
3
,
-
7
a
,
b
,
c
=
2
,
3
,
-
7
x
=
tensor
.
matrix
()
x
=
tensor
.
matrix
()
y
=
QuadraticFunction
(
a
,
b
,
c
)(
x
)
y
=
QuadraticFunction
(
a
,
b
,
c
)(
x
)
...
...
theano/
common
/wrapper.py
→
theano/
gof
/wrapper.py
浏览文件 @
4f0249a5
...
@@ -56,6 +56,9 @@ class Wrap(object):
...
@@ -56,6 +56,9 @@ class Wrap(object):
def
__init__
(
self
,
**
kwargs
):
def
__init__
(
self
,
**
kwargs
):
if
len
(
kwargs
)
==
0
:
if
len
(
kwargs
)
==
0
:
raise
TypeError
(
'Wrap: cannot wrap empty data.'
)
raise
TypeError
(
'Wrap: cannot wrap empty data.'
)
# We want to use only the params provided in kwargs to hash the object,
# so I prefer to put them into a separate attribute (self.data) instead
# of directly in self.__dict__, to avoid confusion with builtin fields.
super
(
Wrap
,
self
)
.
__setattr__
(
'data'
,
kwargs
)
super
(
Wrap
,
self
)
.
__setattr__
(
'data'
,
kwargs
)
def
__repr__
(
self
):
def
__repr__
(
self
):
...
@@ -79,16 +82,20 @@ class Wrap(object):
...
@@ -79,16 +82,20 @@ class Wrap(object):
types
+=
(
type
(
self
.
data
[
k
]),)
types
+=
(
type
(
self
.
data
[
k
]),)
if
isinstance
(
self
.
data
[
k
],
numpy
.
ndarray
):
if
isinstance
(
self
.
data
[
k
],
numpy
.
ndarray
):
if
len
(
self
.
data
[
k
]
.
shape
)
==
0
:
if
len
(
self
.
data
[
k
]
.
shape
)
==
0
:
# NumPy scalar is not iterable, so we put it into a tuple.
attributes
+=
(
numpy
.
asscalar
(
self
.
data
[
k
]),)
attributes
+=
(
numpy
.
asscalar
(
self
.
data
[
k
]),)
else
:
else
:
# NumPy non-0-D arrays are iterable, so we append it as a tuple.
attributes
+=
tuple
(
self
.
data
[
k
])
attributes
+=
tuple
(
self
.
data
[
k
])
else
:
else
:
try
:
try
:
iter
(
self
.
data
[
k
])
iter
(
self
.
data
[
k
])
except
TypeError
:
except
TypeError
:
# Not iterable: we put it into a tuple.
attributes
+=
(
self
.
data
[
k
],)
attributes
+=
(
self
.
data
[
k
],)
else
:
else
:
attributes
+=
tuple
(
self
.
data
[
k
])
# Iterable: we append it directly.
attributes
+=
self
.
data
[
k
]
return
hash
((
type
(
self
),)
+
tuple
(
keys
)
+
tuple
(
types
)
+
tuple
(
attributes
))
return
hash
((
type
(
self
),)
+
tuple
(
keys
)
+
tuple
(
types
)
+
tuple
(
attributes
))
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
...
...
theano/tests/test_flake8.py
浏览文件 @
4f0249a5
...
@@ -36,7 +36,6 @@ whitelist_flake8 = [
...
@@ -36,7 +36,6 @@ whitelist_flake8 = [
"compat/six.py"
,
# This is bundled code that will be deleted, don't fix it
"compat/six.py"
,
# This is bundled code that will be deleted, don't fix it
"__init__.py"
,
"__init__.py"
,
"tests/__init__.py"
,
"tests/__init__.py"
,
"common/__init__.py"
,
"compile/__init__.py"
,
"compile/__init__.py"
,
"compile/sandbox/__init__.py"
,
"compile/sandbox/__init__.py"
,
"compile/tests/__init__.py"
,
"compile/tests/__init__.py"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论