Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
65ae5df3
提交
65ae5df3
authored
6月 25, 2021
作者:
Shi Fan
提交者:
Brandon T. Willard
6月 25, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove intermediate function call in numba_funcify_Elemwise
上级
da28a260
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
13 行增加
和
24 行删除
+13
-24
dispatch.py
aesara/link/numba/dispatch.py
+10
-23
utils.py
aesara/link/utils.py
+3
-1
没有找到文件。
aesara/link/numba/dispatch.py
浏览文件 @
65ae5df3
import
inspect
import
operator
import
operator
import
warnings
import
warnings
from
functools
import
reduce
,
singledispatch
from
functools
import
reduce
,
singledispatch
...
@@ -438,34 +439,22 @@ def create_vectorize_func(op, node, use_signature=False, identity=None, **kwargs
...
@@ -438,34 +439,22 @@ def create_vectorize_func(op, node, use_signature=False, identity=None, **kwargs
signature
=
[]
signature
=
[]
numba_vectorize
=
numba
.
vectorize
(
signature
,
identity
=
identity
)
numba_vectorize
=
numba
.
vectorize
(
signature
,
identity
=
identity
)
global_env
=
{
"scalar_op"
:
scalar_op_fn
,
"numba_vectorize"
:
numba_vectorize
}
elemwise_fn
=
numba_vectorize
(
scalar_op_fn
)
elemwise_fn
.
py_scalar_func
=
scalar_op_fn
elemwise_fn_name
=
f
"elemwise_{get_name_for_object(scalar_op_fn)}"
return
elemwise_fn
unique_names
=
unique_name_generator
(
[
elemwise_fn_name
,
"scalar_op"
,
"scalar_op"
,
"numba_vectorize"
],
suffix_sep
=
"_"
)
input_names
=
[
unique_names
(
v
,
force_unique
=
True
)
for
v
in
node
.
inputs
]
input_signature_str
=
", "
.
join
(
input_names
)
elemwise_src
=
f
"""
@numba_vectorize
def {elemwise_fn_name}({input_signature_str}):
return scalar_op({input_signature_str})
"""
elemwise_fn
=
compile_function_src
(
elemwise_src
,
elemwise_fn_name
,
global_env
)
return
elemwise_fn
,
input_names
@numba_funcify.register
(
Elemwise
)
@numba_funcify.register
(
Elemwise
)
def
numba_funcify_Elemwise
(
op
,
node
,
**
kwargs
):
def
numba_funcify_Elemwise
(
op
,
node
,
**
kwargs
):
elemwise_fn
,
input_names
=
create_vectorize_func
(
op
,
node
,
use_signature
=
False
)
elemwise_fn
=
create_vectorize_func
(
op
,
node
,
use_signature
=
False
)
elemwise_fn_name
=
elemwise_fn
.
__name__
elemwise_fn_name
=
elemwise_fn
.
__name__
if
op
.
inplace_pattern
:
if
op
.
inplace_pattern
:
sign_obj
=
inspect
.
signature
(
elemwise_fn
.
py_scalar_func
)
input_names
=
list
(
sign_obj
.
parameters
.
keys
())
input_idx
=
op
.
inplace_pattern
[
0
]
input_idx
=
op
.
inplace_pattern
[
0
]
updated_input_name
=
input_names
[
input_idx
]
updated_input_name
=
input_names
[
input_idx
]
...
@@ -481,7 +470,7 @@ def {inplace_elemwise_fn_name}({input_signature_str}):
...
@@ -481,7 +470,7 @@ def {inplace_elemwise_fn_name}({input_signature_str}):
inplace_elemwise_fn
=
compile_function_src
(
inplace_elemwise_fn
=
compile_function_src
(
inplace_elemwise_src
,
inplace_elemwise_fn_name
,
inplace_global_env
inplace_elemwise_src
,
inplace_elemwise_fn_name
,
inplace_global_env
)
)
return
numba
.
njit
(
in
line
=
"always"
)(
in
place_elemwise_fn
)
return
numba
.
njit
(
inplace_elemwise_fn
)
return
elemwise_fn
return
elemwise_fn
...
@@ -626,9 +615,7 @@ def numba_funcify_CAReduce(op, node, **kwargs):
...
@@ -626,9 +615,7 @@ def numba_funcify_CAReduce(op, node, **kwargs):
)
)
# TODO: Use `scalar_op_identity`?
# TODO: Use `scalar_op_identity`?
elemwise_fn
,
*
_
=
create_vectorize_func
(
elemwise_fn
=
create_vectorize_func
(
op
,
dummy_node
,
use_signature
=
True
,
**
kwargs
)
op
,
dummy_node
,
use_signature
=
True
,
**
kwargs
)
input_name
=
get_name_for_object
(
node
.
inputs
[
0
])
input_name
=
get_name_for_object
(
node
.
inputs
[
0
])
ndim
=
node
.
inputs
[
0
]
.
ndim
ndim
=
node
.
inputs
[
0
]
.
ndim
...
...
aesara/link/utils.py
浏览文件 @
65ae5df3
...
@@ -588,7 +588,9 @@ def compile_function_src(src, function_name, global_env=None, local_env=None):
...
@@ -588,7 +588,9 @@ def compile_function_src(src, function_name, global_env=None, local_env=None):
mod_code
=
compile
(
src
,
filename
,
mode
=
"exec"
)
mod_code
=
compile
(
src
,
filename
,
mode
=
"exec"
)
exec
(
mod_code
,
global_env
,
local_env
)
exec
(
mod_code
,
global_env
,
local_env
)
return
local_env
[
function_name
]
res
=
local_env
[
function_name
]
res
.
__source__
=
src
return
res
def
get_name_for_object
(
x
:
Any
):
def
get_name_for_object
(
x
:
Any
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论