Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c789ce95
提交
c789ce95
authored
5月 23, 2015
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Flake8 for gof/type.py
上级
867bba87
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
57 行增加
和
44 行删除
+57
-44
type.py
theano/gof/type.py
+57
-43
test_flake8.py
theano/tests/test_flake8.py
+0
-1
没有找到文件。
theano/gof/type.py
浏览文件 @
c789ce95
...
...
@@ -45,7 +45,8 @@ class CLinkerType(CLinkerObject):
- `MethodNotDefined`: Subclass does not implement this method
"""
raise
MethodNotDefined
(
"c_literal"
,
type
(
self
),
self
.
__class__
.
__name__
)
raise
MethodNotDefined
(
"c_literal"
,
type
(
self
),
self
.
__class__
.
__name__
)
def
c_declare
(
self
,
name
,
sub
,
check_input
=
True
):
"""Required: Return c code to declare variables that will be
...
...
@@ -56,7 +57,8 @@ class CLinkerType(CLinkerObject):
return "PyObject ** addr_of_
%(name)
s;"
:param name: the name of the ``PyObject *`` pointer that will the value for this Type
:param name: the name of the ``PyObject *`` pointer that will
the value for this Type
:type name: string
...
...
@@ -138,7 +140,8 @@ class CLinkerType(CLinkerObject):
- `MethodNotDefined`: Subclass does not implement this method
"""
raise
MethodNotDefined
(
"c_extract"
,
type
(
self
),
self
.
__class__
.
__name__
)
raise
MethodNotDefined
(
"c_extract"
,
type
(
self
),
self
.
__class__
.
__name__
)
def
c_extract_out
(
self
,
name
,
sub
,
check_input
=
True
):
"""Optional: C code to extract a PyObject * instance.
...
...
@@ -156,9 +159,9 @@ class CLinkerType(CLinkerObject):
%(c_extract_code)
s
}
"""
%
dict
(
name
=
name
,
c_init_code
=
self
.
c_init
(
name
,
sub
),
c_extract_code
=
self
.
c_extract
(
name
,
sub
,
check_input
))
name
=
name
,
c_init_code
=
self
.
c_init
(
name
,
sub
),
c_extract_code
=
self
.
c_extract
(
name
,
sub
,
check_input
))
def
c_cleanup
(
self
,
name
,
sub
):
"""Return c code to clean up after `c_extract`.
...
...
@@ -184,11 +187,12 @@ class CLinkerType(CLinkerObject):
def
c_sync
(
self
,
name
,
sub
):
"""Required: Return c code to pack C types back into a PyObject.
The code returned from this function must be templated using "
%(name)
s",
representing the name that the caller wants to call this Variable. The
returned code may set "py_
%(name)
s" to a PyObject* and that PyObject*
will be accessible from Python via variable.data. Do not forget to adjust
reference counts if "py_
%(name)
s" is changed from its original value.
The code returned from this function must be templated using
"
%(name)
s", representing the name that the caller wants to
call this Variable. The returned code may set "py_
%(name)
s"
to a PyObject* and that PyObject* will be accessible from
Python via variable.data. Do not forget to adjust reference
counts if "py_
%(name)
s" is changed from its original value.
:Parameters:
- `name`: WRITEME
...
...
@@ -205,10 +209,11 @@ class CLinkerType(CLinkerObject):
def
c_code_cache_version
(
self
):
"""Return a tuple of integers indicating the version of this Type.
An empty tuple indicates an 'unversioned' Type that will not be cached between processes.
An empty tuple indicates an 'unversioned' Type that will not
be cached between processes.
The cache mechanism may erase cached modules that have been
superceded by newer
versions. See `ModuleCache` for details.
The cache mechanism may erase cached modules that have been
superceded by newer
versions. See `ModuleCache` for details.
"""
return
()
...
...
@@ -221,19 +226,21 @@ class PureType(object):
- creating `Variable` instances (conventionally, `__call__` does this), and
- filtering a value assigned to a `Variable` so that the value
conforms to restrictions
imposed by the type (also known as casting, this is done by `filter`),
- filtering a value assigned to a `Variable` so that the value
conforms to restrictions imposed by the type (also known as
casting, this is done by `filter`),
"""
# the type that will be created by call to make_variable.
Variable
=
graph
.
Variable
Variable
=
graph
.
Variable
# the type that will be created by call to make_variable.
Constant
=
graph
.
Constant
# the type that will be created by call to make_constant
# the type that will be created by call to make_constant
Constant
=
graph
.
Constant
def
filter
(
self
,
data
,
strict
=
False
,
allow_downcast
=
None
):
"""Required: Return data or an appropriately wrapped/converted data.
Subclass implementation should raise a TypeError exception if
the data is not of an
acceptable type.
Subclass implementation should raise a TypeError exception if
the data is not of an
acceptable type.
If strict is True, the data returned must be the same as the
data passed as an argument. If it is False, and allow_downcast
...
...
@@ -272,18 +279,19 @@ class PureType(object):
if
other
.
type
!=
self
:
raise
TypeError
(
'Cannot convert Type
%(othertype)
s '
'(of Variable
%(other)
s) into Type
%(self)
s. '
'You can try to manually convert
%(other)
s into a
%(self)
s.'
%
dict
(
othertype
=
other
.
type
,
other
=
other
,
self
=
self
)
)
'Cannot convert Type
%(othertype)
s '
'(of Variable
%(other)
s) into Type
%(self)
s. '
'You can try to manually convert
%(other)
s into a
%(self)
s.'
%
dict
(
othertype
=
other
.
type
,
other
=
other
,
self
=
self
)
)
return
other
def
is_valid_value
(
self
,
a
):
"""Required: Return True for any python object `a` that would be a legal value for a Variable of this Type"""
"""Required: Return True for any python object `a` that would be a
legal value for a Variable of this Type"""
try
:
self
.
filter
(
a
,
strict
=
True
)
return
True
...
...
@@ -291,7 +299,8 @@ class PureType(object):
return
False
def
value_validity_msg
(
self
,
a
):
"""Optional: return a message explaining the output of is_valid_value"""
"""Optional: return a message explaining the output of
is_valid_value"""
return
"none"
def
make_variable
(
self
,
name
=
None
):
...
...
@@ -371,7 +380,8 @@ class Type(object2, PureType, CLinkerType):
But you are encouraged to write your own, as described in WRITEME.
The following following code illustrates the use of a Type instance, here tensor.fvector:
The following following code illustrates the use of a Type
instance, here tensor.fvector:
.. code-block:: python
...
...
@@ -381,17 +391,21 @@ class Type(object2, PureType, CLinkerType):
# Create a second Variable with the same Type instance
c = tensor.fvector()
Whenever you create a symbolic variable in theano (technically, `Variable`) it will contain a
reference to a Type instance. That reference is typically constant during the lifetime of
the Variable. Many variables can refer to a single Type instance, as do b and c above. The
Type instance defines the kind of value which might end up in that variable when executing
a `Function`. In this sense, theano is like a strongly-typed language because the types
are included in the graph before the values. In our example above, b is a Variable which is
guaranteed to correspond to a numpy.ndarray of rank 1 when we try to do some computations
Whenever you create a symbolic variable in theano (technically,
`Variable`) it will contain a reference to a Type instance. That
reference is typically constant during the lifetime of the
Variable. Many variables can refer to a single Type instance, as
do b and c above. The Type instance defines the kind of value
which might end up in that variable when executing a `Function`.
In this sense, theano is like a strongly-typed language because
the types are included in the graph before the values. In our
example above, b is a Variable which is guaranteed to correspond
to a numpy.ndarray of rank 1 when we try to do some computations
with it.
Many `Op` instances will raise an exception if they are applied to inputs with incorrect
types. Type references are also useful to do type-checking in pattern-based optimizations.
Many `Op` instances will raise an exception if they are applied to
inputs with incorrect types. Type references are also useful to
do type-checking in pattern-based optimizations.
"""
def
convert_variable
(
self
,
var
):
...
...
@@ -451,8 +465,8 @@ class Generic(SingletonType):
"""
Represents a generic Python object.
This class implements the `PureType` and `CLinkerType` interfaces
for generic PyObject
instances.
This class implements the `PureType` and `CLinkerType` interfaces
for generic PyObject
instances.
EXAMPLE of what this means, or when you would use this type.
...
...
theano/tests/test_flake8.py
浏览文件 @
c789ce95
...
...
@@ -270,7 +270,6 @@ whitelist_flake8 = [
"gof/destroyhandler.py"
,
"gof/unify.py"
,
"gof/graph.py"
,
"gof/type.py"
,
"gof/__init__.py"
,
"gof/cc.py"
,
"gof/opt.py"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论