Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b889ec1e
提交
b889ec1e
authored
5月 22, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
5月 22, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix use of typing.NoReturn
上级
62651c4a
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
26 行增加
和
38 行删除
+26
-38
fg.py
aesara/graph/fg.py
+16
-16
op.py
aesara/graph/op.py
+6
-7
type.py
aesara/graph/type.py
+2
-2
basic.py
aesara/link/basic.py
+2
-13
没有找到文件。
aesara/graph/fg.py
浏览文件 @
b889ec1e
"""A container for specifying and manipulating a graph with distinct inputs and outputs."""
"""A container for specifying and manipulating a graph with distinct inputs and outputs."""
import
time
import
time
from
collections
import
OrderedDict
from
collections
import
OrderedDict
from
typing
import
Any
,
Dict
,
List
,
NoReturn
,
Optional
,
Tuple
,
Union
from
typing
import
Any
,
Dict
,
List
,
Optional
,
Tuple
,
Union
import
aesara
import
aesara
from
aesara.configdefaults
import
config
from
aesara.configdefaults
import
config
...
@@ -171,7 +171,7 @@ class FunctionGraph(MetaObject):
...
@@ -171,7 +171,7 @@ class FunctionGraph(MetaObject):
self
.
profile
=
None
self
.
profile
=
None
self
.
update_mapping
=
update_mapping
self
.
update_mapping
=
update_mapping
def
add_input
(
self
,
var
:
Variable
,
check
:
bool
=
True
)
->
No
Return
:
def
add_input
(
self
,
var
:
Variable
,
check
:
bool
=
True
)
->
No
ne
:
"""Add a new variable as an input to this `FunctionGraph`.
"""Add a new variable as an input to this `FunctionGraph`.
Parameters
Parameters
...
@@ -186,7 +186,7 @@ class FunctionGraph(MetaObject):
...
@@ -186,7 +186,7 @@ class FunctionGraph(MetaObject):
self
.
setup_var
(
var
)
self
.
setup_var
(
var
)
self
.
variables
.
add
(
var
)
self
.
variables
.
add
(
var
)
def
setup_var
(
self
,
var
:
Variable
)
->
No
Return
:
def
setup_var
(
self
,
var
:
Variable
)
->
No
ne
:
"""Set up a variable so it belongs to this `FunctionGraph`.
"""Set up a variable so it belongs to this `FunctionGraph`.
Parameters
Parameters
...
@@ -196,7 +196,7 @@ class FunctionGraph(MetaObject):
...
@@ -196,7 +196,7 @@ class FunctionGraph(MetaObject):
"""
"""
self
.
clients
.
setdefault
(
var
,
[])
self
.
clients
.
setdefault
(
var
,
[])
def
setup_node
(
self
,
node
:
Apply
)
->
No
Return
:
def
setup_node
(
self
,
node
:
Apply
)
->
No
ne
:
"""Set up node so it belongs to this `FunctionGraph`.
"""Set up node so it belongs to this `FunctionGraph`.
Parameters
Parameters
...
@@ -220,7 +220,7 @@ class FunctionGraph(MetaObject):
...
@@ -220,7 +220,7 @@ class FunctionGraph(MetaObject):
" the values must be tuples or lists."
" the values must be tuples or lists."
)
)
def
disown
(
self
)
->
No
Return
:
def
disown
(
self
)
->
No
ne
:
"""Clear internal variables."""
"""Clear internal variables."""
for
f
in
self
.
_features
:
for
f
in
self
.
_features
:
self
.
remove_feature
(
f
)
self
.
remove_feature
(
f
)
...
@@ -236,7 +236,7 @@ class FunctionGraph(MetaObject):
...
@@ -236,7 +236,7 @@ class FunctionGraph(MetaObject):
"""Return a list of all the `(node, i)` pairs such that `node.inputs[i]` is `var`."""
"""Return a list of all the `(node, i)` pairs such that `node.inputs[i]` is `var`."""
return
self
.
clients
[
var
]
return
self
.
clients
[
var
]
def
add_client
(
self
,
var
:
Variable
,
new_client
:
Tuple
[
Apply
,
int
])
->
No
Return
:
def
add_client
(
self
,
var
:
Variable
,
new_client
:
Tuple
[
Apply
,
int
])
->
No
ne
:
"""Update the clients of `var` with `new_clients`.
"""Update the clients of `var` with `new_clients`.
Parameters
Parameters
...
@@ -250,7 +250,7 @@ class FunctionGraph(MetaObject):
...
@@ -250,7 +250,7 @@ class FunctionGraph(MetaObject):
def
remove_client
(
def
remove_client
(
self
,
var
:
Variable
,
client_to_remove
:
Tuple
[
Apply
,
int
],
reason
:
str
=
None
self
,
var
:
Variable
,
client_to_remove
:
Tuple
[
Apply
,
int
],
reason
:
str
=
None
)
->
No
Return
:
)
->
No
ne
:
"""Recursively removes clients of a variable.
"""Recursively removes clients of a variable.
This is the main method to remove variables or `Apply` nodes from
This is the main method to remove variables or `Apply` nodes from
...
@@ -316,7 +316,7 @@ class FunctionGraph(MetaObject):
...
@@ -316,7 +316,7 @@ class FunctionGraph(MetaObject):
def
import_var
(
def
import_var
(
self
,
var
:
Variable
,
reason
:
str
=
None
,
import_missing
:
bool
=
False
self
,
var
:
Variable
,
reason
:
str
=
None
,
import_missing
:
bool
=
False
)
->
No
Return
:
)
->
No
ne
:
"""Import variables into this `FunctionGraph`.
"""Import variables into this `FunctionGraph`.
This will also import the `variable`'s `Apply` node.
This will also import the `variable`'s `Apply` node.
...
@@ -358,7 +358,7 @@ class FunctionGraph(MetaObject):
...
@@ -358,7 +358,7 @@ class FunctionGraph(MetaObject):
check
:
bool
=
True
,
check
:
bool
=
True
,
reason
:
str
=
None
,
reason
:
str
=
None
,
import_missing
:
bool
=
False
,
import_missing
:
bool
=
False
,
)
->
No
Return
:
)
->
No
ne
:
"""Recursively import everything between an `Apply` node and the `FunctionGraph`'s outputs.
"""Recursively import everything between an `Apply` node and the `FunctionGraph`'s outputs.
Parameters:
Parameters:
...
@@ -424,7 +424,7 @@ class FunctionGraph(MetaObject):
...
@@ -424,7 +424,7 @@ class FunctionGraph(MetaObject):
new_var
:
Variable
,
new_var
:
Variable
,
reason
:
str
=
None
,
reason
:
str
=
None
,
import_missing
:
bool
=
False
,
import_missing
:
bool
=
False
,
)
->
No
Return
:
)
->
No
ne
:
"""Change ``node.inputs[i]`` to `new_var`.
"""Change ``node.inputs[i]`` to `new_var`.
``new_var.type == old_var.type`` must be ``True``, where ``old_var`` is the
``new_var.type == old_var.type`` must be ``True``, where ``old_var`` is the
...
@@ -486,7 +486,7 @@ class FunctionGraph(MetaObject):
...
@@ -486,7 +486,7 @@ class FunctionGraph(MetaObject):
reason
:
str
=
None
,
reason
:
str
=
None
,
verbose
:
bool
=
None
,
verbose
:
bool
=
None
,
import_missing
:
bool
=
False
,
import_missing
:
bool
=
False
,
)
->
No
Return
:
)
->
No
ne
:
"""Replace a variable in the `FunctionGraph`.
"""Replace a variable in the `FunctionGraph`.
This is the main interface to manipulate the subgraph in `FunctionGraph`.
This is the main interface to manipulate the subgraph in `FunctionGraph`.
...
@@ -547,12 +547,12 @@ class FunctionGraph(MetaObject):
...
@@ -547,12 +547,12 @@ class FunctionGraph(MetaObject):
node
,
i
,
new_var
,
reason
=
reason
,
import_missing
=
import_missing
node
,
i
,
new_var
,
reason
=
reason
,
import_missing
=
import_missing
)
)
def
replace_all
(
self
,
pairs
:
List
[
Tuple
[
Variable
,
Variable
]],
**
kwargs
)
->
No
Return
:
def
replace_all
(
self
,
pairs
:
List
[
Tuple
[
Variable
,
Variable
]],
**
kwargs
)
->
No
ne
:
"""Replace variables in the ``FunctionGraph`` according to ``(var, new_var)`` pairs in a list."""
"""Replace variables in the ``FunctionGraph`` according to ``(var, new_var)`` pairs in a list."""
for
var
,
new_var
in
pairs
:
for
var
,
new_var
in
pairs
:
self
.
replace
(
var
,
new_var
,
**
kwargs
)
self
.
replace
(
var
,
new_var
,
**
kwargs
)
def
attach_feature
(
self
,
feature
:
Feature
)
->
No
Return
:
def
attach_feature
(
self
,
feature
:
Feature
)
->
No
ne
:
"""Add a ``graph.features.Feature`` to this function graph and trigger its on_attach callback."""
"""Add a ``graph.features.Feature`` to this function graph and trigger its on_attach callback."""
# Filter out literally identical `Feature`s
# Filter out literally identical `Feature`s
if
feature
in
self
.
_features
:
if
feature
in
self
.
_features
:
...
@@ -578,7 +578,7 @@ class FunctionGraph(MetaObject):
...
@@ -578,7 +578,7 @@ class FunctionGraph(MetaObject):
# Add the feature
# Add the feature
self
.
_features
.
append
(
feature
)
self
.
_features
.
append
(
feature
)
def
remove_feature
(
self
,
feature
:
Feature
)
->
No
Return
:
def
remove_feature
(
self
,
feature
:
Feature
)
->
No
ne
:
"""
"""
Removes the feature from the graph.
Removes the feature from the graph.
...
@@ -595,7 +595,7 @@ class FunctionGraph(MetaObject):
...
@@ -595,7 +595,7 @@ class FunctionGraph(MetaObject):
if
detach
is
not
None
:
if
detach
is
not
None
:
detach
(
self
)
detach
(
self
)
def
execute_callbacks
(
self
,
name
:
str
,
*
args
,
**
kwargs
)
->
No
Return
:
def
execute_callbacks
(
self
,
name
:
str
,
*
args
,
**
kwargs
)
->
No
ne
:
"""Execute callbacks
"""Execute callbacks
Calls `getattr(feature, name)(*args)` for each feature which has
Calls `getattr(feature, name)(*args)` for each feature which has
...
@@ -706,7 +706,7 @@ class FunctionGraph(MetaObject):
...
@@ -706,7 +706,7 @@ class FunctionGraph(MetaObject):
ords
.
setdefault
(
node
,
[])
.
extend
(
prereqs
)
ords
.
setdefault
(
node
,
[])
.
extend
(
prereqs
)
return
ords
return
ords
def
check_integrity
(
self
)
->
No
Return
:
def
check_integrity
(
self
)
->
No
ne
:
"""
"""
Call this for a diagnosis if things go awry.
Call this for a diagnosis if things go awry.
...
...
aesara/graph/op.py
浏览文件 @
b889ec1e
...
@@ -18,7 +18,6 @@ from typing import (
...
@@ -18,7 +18,6 @@ from typing import (
ClassVar
,
ClassVar
,
Dict
,
Dict
,
List
,
List
,
NoReturn
,
Optional
,
Optional
,
Pattern
,
Pattern
,
Set
,
Set
,
...
@@ -51,7 +50,7 @@ ComputeMapType = List[bool]
...
@@ -51,7 +50,7 @@ ComputeMapType = List[bool]
OutputStorageType
=
List
[
Optional
[
List
[
Any
]]]
OutputStorageType
=
List
[
Optional
[
List
[
Any
]]]
ParamsInputType
=
Optional
[
Tuple
[
Any
]]
ParamsInputType
=
Optional
[
Tuple
[
Any
]]
PerformMethodType
=
Callable
[
PerformMethodType
=
Callable
[
[
Apply
,
List
[
Any
],
OutputStorageType
,
ParamsInputType
],
No
Return
[
Apply
,
List
[
Any
],
OutputStorageType
,
ParamsInputType
],
No
ne
]
]
ThunkType
=
Callable
[[
PerformMethodType
,
StorageMapType
,
ComputeMapType
,
Apply
],
Any
]
ThunkType
=
Callable
[[
PerformMethodType
,
StorageMapType
,
ComputeMapType
,
Apply
],
Any
]
...
@@ -380,7 +379,7 @@ class Op(MetaObject):
...
@@ -380,7 +379,7 @@ class Op(MetaObject):
inputs
:
List
[
Variable
],
inputs
:
List
[
Variable
],
output_storage
:
OutputStorageType
,
output_storage
:
OutputStorageType
,
params
:
ParamsInputType
=
None
,
params
:
ParamsInputType
=
None
,
)
->
No
Return
:
)
->
No
ne
:
"""Calculate the function on the inputs and put the variables in the output storage.
"""Calculate the function on the inputs and put the variables in the output storage.
Parameters
Parameters
...
@@ -456,7 +455,7 @@ class Op(MetaObject):
...
@@ -456,7 +455,7 @@ class Op(MetaObject):
storage_map
:
StorageMapType
,
storage_map
:
StorageMapType
,
compute_map
:
ComputeMapType
,
compute_map
:
ComputeMapType
,
impl
:
Optional
[
Text
],
impl
:
Optional
[
Text
],
)
->
No
Return
:
)
->
No
ne
:
"""Make any special modifications that the Op needs before doing `Op.make_thunk`.
"""Make any special modifications that the Op needs before doing `Op.make_thunk`.
This can modify the node inplace and should return nothing.
This can modify the node inplace and should return nothing.
...
@@ -682,7 +681,7 @@ def get_test_value(v: Variable) -> Any:
...
@@ -682,7 +681,7 @@ def get_test_value(v: Variable) -> Any:
return
v
.
get_test_value
()
return
v
.
get_test_value
()
def
missing_test_message
(
msg
:
Text
)
->
No
Return
:
def
missing_test_message
(
msg
:
Text
)
->
No
ne
:
"""
"""
Displays msg, a message saying that some test_value is missing,
Displays msg, a message saying that some test_value is missing,
in the appropriate form based on config.compute_test_value:
in the appropriate form based on config.compute_test_value:
...
@@ -840,7 +839,7 @@ int main( int argc, const char* argv[] )
...
@@ -840,7 +839,7 @@ int main( int argc, const char* argv[] )
)
)
return
default_openmp
return
default_openmp
def
update_self_openmp
(
self
)
->
No
Return
:
def
update_self_openmp
(
self
)
->
No
ne
:
"""
"""
Make sure self.openmp is not True if there is no support in gxx.
Make sure self.openmp is not True if there is no support in gxx.
...
@@ -981,7 +980,7 @@ class ExternalCOp(COp):
...
@@ -981,7 +980,7 @@ class ExternalCOp(COp):
"and specify the func_name"
"and specify the func_name"
)
)
def
load_c_code
(
self
,
func_files
:
List
[
Text
])
->
No
Return
:
def
load_c_code
(
self
,
func_files
:
List
[
Text
])
->
No
ne
:
"""Loads the C code to perform the `Op`."""
"""Loads the C code to perform the `Op`."""
func_files
=
[
self
.
get_path
(
f
)
for
f
in
func_files
]
func_files
=
[
self
.
get_path
(
f
)
for
f
in
func_files
]
self
.
func_codes
=
[]
self
.
func_codes
=
[]
...
...
aesara/graph/type.py
浏览文件 @
b889ec1e
...
@@ -4,7 +4,7 @@ import ctypes
...
@@ -4,7 +4,7 @@ import ctypes
import
platform
import
platform
import
re
import
re
from
abc
import
abstractmethod
from
abc
import
abstractmethod
from
typing
import
Any
,
NoReturn
,
Optional
,
Text
,
TypeVar
,
Union
from
typing
import
Any
,
Optional
,
Text
,
TypeVar
,
Union
from
aesara.graph
import
utils
from
aesara.graph
import
utils
from
aesara.graph.basic
import
Constant
,
Variable
from
aesara.graph.basic
import
Constant
,
Variable
...
@@ -71,7 +71,7 @@ class Type(MetaObject):
...
@@ -71,7 +71,7 @@ class Type(MetaObject):
storage
:
Any
,
storage
:
Any
,
strict
:
bool
=
False
,
strict
:
bool
=
False
,
allow_downcast
:
Optional
[
bool
]
=
None
,
allow_downcast
:
Optional
[
bool
]
=
None
,
)
->
No
Return
:
)
->
No
ne
:
"""Return data or an appropriately wrapped/converted data by converting it in-place.
"""Return data or an appropriately wrapped/converted data by converting it in-place.
This method allows one to reuse old allocated memory. If this method
This method allows one to reuse old allocated memory. If this method
...
...
aesara/link/basic.py
浏览文件 @
b889ec1e
from
abc
import
ABC
,
abstractmethod
from
abc
import
ABC
,
abstractmethod
from
copy
import
copy
,
deepcopy
from
copy
import
copy
,
deepcopy
from
typing
import
(
from
typing
import
TYPE_CHECKING
,
Any
,
Callable
,
Dict
,
List
,
Optional
,
Set
,
Tuple
,
Union
TYPE_CHECKING
,
Any
,
Callable
,
Dict
,
List
,
NoReturn
,
Optional
,
Set
,
Tuple
,
Union
,
)
from
numpy
import
ndarray
from
numpy
import
ndarray
...
@@ -32,7 +21,7 @@ if TYPE_CHECKING:
...
@@ -32,7 +21,7 @@ if TYPE_CHECKING:
StorageMapType
=
Dict
[
Variable
,
List
[
Optional
[
Union
[
ndarray
,
slice
]]]]
StorageMapType
=
Dict
[
Variable
,
List
[
Optional
[
Union
[
ndarray
,
slice
]]]]
OutputStorageType
=
List
[
Optional
[
List
[
Any
]]]
OutputStorageType
=
List
[
Optional
[
List
[
Any
]]]
ThunkType
=
Tuple
[
Callable
[[],
No
Return
],
List
[
"Container"
],
List
[
"Container"
]]
ThunkType
=
Tuple
[
Callable
[[],
No
ne
],
List
[
"Container"
],
List
[
"Container"
]]
class
Container
:
class
Container
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论