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 个修改的文件
包含
46 行增加
和
33 行删除
+46
-33
type.py
theano/gof/type.py
+46
-32
test_flake8.py
theano/tests/test_flake8.py
+0
-1
没有找到文件。
theano/gof/type.py
浏览文件 @
c789ce95
...
@@ -45,7 +45,8 @@ class CLinkerType(CLinkerObject):
...
@@ -45,7 +45,8 @@ class CLinkerType(CLinkerObject):
- `MethodNotDefined`: Subclass does not implement this method
- `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
):
def
c_declare
(
self
,
name
,
sub
,
check_input
=
True
):
"""Required: Return c code to declare variables that will be
"""Required: Return c code to declare variables that will be
...
@@ -56,7 +57,8 @@ class CLinkerType(CLinkerObject):
...
@@ -56,7 +57,8 @@ class CLinkerType(CLinkerObject):
return "PyObject ** addr_of_
%(name)
s;"
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
:type name: string
...
@@ -138,7 +140,8 @@ class CLinkerType(CLinkerObject):
...
@@ -138,7 +140,8 @@ class CLinkerType(CLinkerObject):
- `MethodNotDefined`: Subclass does not implement this method
- `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
):
def
c_extract_out
(
self
,
name
,
sub
,
check_input
=
True
):
"""Optional: C code to extract a PyObject * instance.
"""Optional: C code to extract a PyObject * instance.
...
@@ -184,11 +187,12 @@ class CLinkerType(CLinkerObject):
...
@@ -184,11 +187,12 @@ class CLinkerType(CLinkerObject):
def
c_sync
(
self
,
name
,
sub
):
def
c_sync
(
self
,
name
,
sub
):
"""Required: Return c code to pack C types back into a PyObject.
"""Required: Return c code to pack C types back into a PyObject.
The code returned from this function must be templated using "
%(name)
s",
The code returned from this function must be templated using
representing the name that the caller wants to call this Variable. The
"
%(name)
s", representing the name that the caller wants to
returned code may set "py_
%(name)
s" to a PyObject* and that PyObject*
call this Variable. The returned code may set "py_
%(name)
s"
will be accessible from Python via variable.data. Do not forget to adjust
to a PyObject* and that PyObject* will be accessible from
reference counts if "py_
%(name)
s" is changed from its original value.
Python via variable.data. Do not forget to adjust reference
counts if "py_
%(name)
s" is changed from its original value.
:Parameters:
:Parameters:
- `name`: WRITEME
- `name`: WRITEME
...
@@ -205,10 +209,11 @@ class CLinkerType(CLinkerObject):
...
@@ -205,10 +209,11 @@ class CLinkerType(CLinkerObject):
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
"""Return a tuple of integers indicating the version of this Type.
"""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
The cache mechanism may erase cached modules that have been
versions. See `ModuleCache` for details.
superceded by newer
versions. See `ModuleCache` for details.
"""
"""
return
()
return
()
...
@@ -221,19 +226,21 @@ class PureType(object):
...
@@ -221,19 +226,21 @@ class PureType(object):
- creating `Variable` instances (conventionally, `__call__` does this), and
- creating `Variable` instances (conventionally, `__call__` does this), and
- filtering a value assigned to a `Variable` so that the value
conforms to restrictions
- filtering a value assigned to a `Variable` so that the value
imposed by the type (also known as casting, this is done by `filter`),
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.
# the type that will be created by call to make_constant
Constant
=
graph
.
Constant
# the type that will be created by call to make_constant
Constant
=
graph
.
Constant
def
filter
(
self
,
data
,
strict
=
False
,
allow_downcast
=
None
):
def
filter
(
self
,
data
,
strict
=
False
,
allow_downcast
=
None
):
"""Required: Return data or an appropriately wrapped/converted data.
"""Required: Return data or an appropriately wrapped/converted data.
Subclass implementation should raise a TypeError exception if
the data is not of an
Subclass implementation should raise a TypeError exception if
acceptable type.
the data is not of an
acceptable type.
If strict is True, the data returned must be the same as the
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
data passed as an argument. If it is False, and allow_downcast
...
@@ -283,7 +290,8 @@ class PureType(object):
...
@@ -283,7 +290,8 @@ class PureType(object):
return
other
return
other
def
is_valid_value
(
self
,
a
):
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
:
try
:
self
.
filter
(
a
,
strict
=
True
)
self
.
filter
(
a
,
strict
=
True
)
return
True
return
True
...
@@ -291,7 +299,8 @@ class PureType(object):
...
@@ -291,7 +299,8 @@ class PureType(object):
return
False
return
False
def
value_validity_msg
(
self
,
a
):
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"
return
"none"
def
make_variable
(
self
,
name
=
None
):
def
make_variable
(
self
,
name
=
None
):
...
@@ -371,7 +380,8 @@ class Type(object2, PureType, CLinkerType):
...
@@ -371,7 +380,8 @@ class Type(object2, PureType, CLinkerType):
But you are encouraged to write your own, as described in WRITEME.
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
.. code-block:: python
...
@@ -381,17 +391,21 @@ class Type(object2, PureType, CLinkerType):
...
@@ -381,17 +391,21 @@ class Type(object2, PureType, CLinkerType):
# Create a second Variable with the same Type instance
# Create a second Variable with the same Type instance
c = tensor.fvector()
c = tensor.fvector()
Whenever you create a symbolic variable in theano (technically, `Variable`) it will contain a
Whenever you create a symbolic variable in theano (technically,
reference to a Type instance. That reference is typically constant during the lifetime of
`Variable`) it will contain a reference to a Type instance. That
the Variable. Many variables can refer to a single Type instance, as do b and c above. The
reference is typically constant during the lifetime of the
Type instance defines the kind of value which might end up in that variable when executing
Variable. Many variables can refer to a single Type instance, as
a `Function`. In this sense, theano is like a strongly-typed language because the types
do b and c above. The Type instance defines the kind of value
are included in the graph before the values. In our example above, b is a Variable which is
which might end up in that variable when executing a `Function`.
guaranteed to correspond to a numpy.ndarray of rank 1 when we try to do some computations
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.
with it.
Many `Op` instances will raise an exception if they are applied to inputs with incorrect
Many `Op` instances will raise an exception if they are applied to
types. Type references are also useful to do type-checking in pattern-based optimizations.
inputs with incorrect types. Type references are also useful to
do type-checking in pattern-based optimizations.
"""
"""
def
convert_variable
(
self
,
var
):
def
convert_variable
(
self
,
var
):
...
@@ -451,8 +465,8 @@ class Generic(SingletonType):
...
@@ -451,8 +465,8 @@ class Generic(SingletonType):
"""
"""
Represents a generic Python object.
Represents a generic Python object.
This class implements the `PureType` and `CLinkerType` interfaces
for generic PyObject
This class implements the `PureType` and `CLinkerType` interfaces
instances.
for generic PyObject
instances.
EXAMPLE of what this means, or when you would use this type.
EXAMPLE of what this means, or when you would use this type.
...
...
theano/tests/test_flake8.py
浏览文件 @
c789ce95
...
@@ -270,7 +270,6 @@ whitelist_flake8 = [
...
@@ -270,7 +270,6 @@ whitelist_flake8 = [
"gof/destroyhandler.py"
,
"gof/destroyhandler.py"
,
"gof/unify.py"
,
"gof/unify.py"
,
"gof/graph.py"
,
"gof/graph.py"
,
"gof/type.py"
,
"gof/__init__.py"
,
"gof/__init__.py"
,
"gof/cc.py"
,
"gof/cc.py"
,
"gof/opt.py"
,
"gof/opt.py"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论