Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
fa40b9bc
提交
fa40b9bc
authored
10月 15, 2021
作者:
kc611
提交者:
Brandon T. Willard
10月 19, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Numba support for IfElse Op
上级
c2e3dbb1
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
92 行增加
和
1 行删除
+92
-1
basic.py
aesara/link/numba/dispatch/basic.py
+30
-0
test_numba.py
tests/link/test_numba.py
+62
-1
没有找到文件。
aesara/link/numba/dispatch/basic.py
浏览文件 @
fa40b9bc
...
...
@@ -16,6 +16,7 @@ from aesara.compile.ops import DeepCopyOp
from
aesara.graph.basic
import
Apply
from
aesara.graph.fg
import
FunctionGraph
from
aesara.graph.type
import
Type
from
aesara.ifelse
import
IfElse
from
aesara.link.utils
import
(
compile_function_src
,
fgraph_to_python
,
...
...
@@ -682,3 +683,32 @@ def numba_funcify_BatchedDot(op, node, **kwargs):
# NOTE: The remaining `aesara.tensor.blas` `Op`s appear unnecessary, because
# they're only used to optimize basic `Dot` nodes, and those GEMV and GEMM
# optimizations are apparently already performed by Numba
@numba_funcify.register
(
IfElse
)
def
numba_funcify_IfElse
(
op
,
**
kwargs
):
n_outs
=
op
.
n_outs
if
n_outs
>
1
:
@numba.njit
def
ifelse
(
cond
,
*
args
):
if
cond
:
res
=
args
[:
n_outs
]
else
:
res
=
args
[
n_outs
:]
return
res
else
:
@numba.njit
def
ifelse
(
cond
,
*
args
):
if
cond
:
res
=
args
[:
n_outs
]
else
:
res
=
args
[
n_outs
:]
return
res
[
0
]
return
ifelse
tests/link/test_numba.py
浏览文件 @
fa40b9bc
...
...
@@ -22,9 +22,10 @@ from aesara.compile.ops import ViewOp, deep_copy_op
from
aesara.compile.sharedvalue
import
SharedVariable
from
aesara.graph.basic
import
Apply
,
Constant
from
aesara.graph.fg
import
FunctionGraph
from
aesara.graph.op
import
Op
from
aesara.graph.op
import
Op
,
get_test_value
from
aesara.graph.optdb
import
OptimizationQuery
from
aesara.graph.type
import
Type
from
aesara.ifelse
import
ifelse
from
aesara.link.numba.dispatch
import
basic
as
numba_basic
from
aesara.link.numba.linker
import
NumbaLinker
from
aesara.scalar.basic
import
Composite
...
...
@@ -3076,3 +3077,63 @@ def test_scan_while():
np
.
array
(
45
)
.
astype
(
config
.
floatX
),
]
compare_numba_and_py
(
out_fg
,
test_input_vals
)
@pytest.mark.parametrize
(
"inputs, cond_fn, true_vals, false_vals"
,
[
([],
lambda
:
np
.
array
(
True
),
np
.
r_
[
1
,
2
,
3
],
np
.
r_
[
-
1
,
-
2
,
-
3
]),
(
[
set_test_value
(
aet
.
dscalar
(),
np
.
array
(
0.2
,
dtype
=
np
.
float64
))],
lambda
x
:
x
<
0.5
,
np
.
r_
[
1
,
2
,
3
],
np
.
r_
[
-
1
,
-
2
,
-
3
],
),
(
[
set_test_value
(
aet
.
dscalar
(),
np
.
array
(
0.3
,
dtype
=
np
.
float64
)),
set_test_value
(
aet
.
dscalar
(),
np
.
array
(
0.5
,
dtype
=
np
.
float64
)),
],
lambda
x
,
y
:
x
>
y
,
x
,
y
,
),
(
[
set_test_value
(
aet
.
dvector
(),
np
.
array
([
0.3
,
0.1
],
dtype
=
np
.
float64
)),
set_test_value
(
aet
.
dvector
(),
np
.
array
([
0.5
,
0.9
],
dtype
=
np
.
float64
)),
],
lambda
x
,
y
:
aet
.
all
(
x
>
y
),
x
,
y
,
),
(
[
set_test_value
(
aet
.
dvector
(),
np
.
array
([
0.3
,
0.1
],
dtype
=
np
.
float64
)),
set_test_value
(
aet
.
dvector
(),
np
.
array
([
0.5
,
0.9
],
dtype
=
np
.
float64
)),
],
lambda
x
,
y
:
aet
.
all
(
x
>
y
),
[
x
,
2
*
x
],
[
y
,
3
*
y
],
),
(
[
set_test_value
(
aet
.
dvector
(),
np
.
array
([
0.5
,
0.9
],
dtype
=
np
.
float64
)),
set_test_value
(
aet
.
dvector
(),
np
.
array
([
0.3
,
0.1
],
dtype
=
np
.
float64
)),
],
lambda
x
,
y
:
aet
.
all
(
x
>
y
),
[
x
,
2
*
x
],
[
y
,
3
*
y
],
),
],
)
def
test_numba_ifelse
(
inputs
,
cond_fn
,
true_vals
,
false_vals
):
out
=
ifelse
(
cond_fn
(
*
inputs
),
true_vals
,
false_vals
)
if
not
isinstance
(
out
,
list
):
out
=
[
out
]
out_fg
=
FunctionGraph
(
inputs
,
out
)
compare_numba_and_py
(
out_fg
,
[
get_test_value
(
i
)
for
i
in
out_fg
.
inputs
])
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论