Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
05ea255f
提交
05ea255f
authored
4月 17, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
4月 17, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement Numba slice boxing to enable `AdvancedSubtensor` with slices
上级
adc9ce96
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
37 行增加
和
10 行删除
+37
-10
dispatch.py
aesara/link/numba/dispatch.py
+33
-3
test_numba.py
tests/link/test_numba.py
+4
-7
没有找到文件。
aesara/link/numba/dispatch.py
浏览文件 @
05ea255f
...
@@ -4,6 +4,9 @@ import numba
...
@@ -4,6 +4,9 @@ import numba
import
numpy
as
np
import
numpy
as
np
import
scipy
import
scipy
import
scipy.special
import
scipy.special
from
llvmlite.llvmpy.core
import
Type
as
llvm_Type
from
numba
import
types
from
numba.extending
import
box
from
aesara.compile.ops
import
DeepCopyOp
from
aesara.compile.ops
import
DeepCopyOp
from
aesara.graph.fg
import
FunctionGraph
from
aesara.graph.fg
import
FunctionGraph
...
@@ -15,6 +18,32 @@ from aesara.tensor.subtensor import AdvancedSubtensor, AdvancedSubtensor1, Subte
...
@@ -15,6 +18,32 @@ from aesara.tensor.subtensor import AdvancedSubtensor, AdvancedSubtensor1, Subte
from
aesara.tensor.type_other
import
MakeSlice
from
aesara.tensor.type_other
import
MakeSlice
def
slice_new
(
self
,
start
,
stop
,
step
):
fnty
=
llvm_Type
.
function
(
self
.
pyobj
,
[
self
.
pyobj
,
self
.
pyobj
,
self
.
pyobj
])
fn
=
self
.
_get_function
(
fnty
,
name
=
"PySlice_New"
)
return
self
.
builder
.
call
(
fn
,
[
start
,
stop
,
step
])
@box
(
types
.
SliceType
)
def
box_slice
(
typ
,
val
,
c
):
"""Implement boxing for ``slice`` objects in Numba.
This makes it possible to return an Numba's internal representation of a
``slice`` object as a proper ``slice`` to Python.
"""
start
=
c
.
box
(
types
.
int64
,
c
.
builder
.
extract_value
(
val
,
0
))
stop
=
c
.
box
(
types
.
int64
,
c
.
builder
.
extract_value
(
val
,
1
))
if
typ
.
has_step
:
step
=
c
.
box
(
types
.
int64
,
c
.
builder
.
extract_value
(
val
,
2
))
else
:
step
=
c
.
pyapi
.
get_null_object
()
slice_val
=
slice_new
(
c
.
pyapi
,
start
,
stop
,
step
)
return
slice_val
@singledispatch
@singledispatch
def
numba_typify
(
data
,
dtype
=
None
,
**
kwargs
):
def
numba_typify
(
data
,
dtype
=
None
,
**
kwargs
):
return
data
return
data
...
@@ -199,9 +228,10 @@ def numba_funcify_DeepCopyOp(op, node, **kwargs):
...
@@ -199,9 +228,10 @@ def numba_funcify_DeepCopyOp(op, node, **kwargs):
@numba_funcify.register
(
MakeSlice
)
@numba_funcify.register
(
MakeSlice
)
def
numba_funcify_MakeSlice
(
op
,
**
kwargs
):
def
numba_funcify_MakeSlice
(
op
,
**
kwargs
):
# XXX: This won't work when calling into object mode (e.g. for advanced
"""
# indexing), because there's no Numba unboxing for its native `slice`
XXX: This requires a ``slice`` boxing implementation to work with Numba's
# objects.
object mode.
"""
@numba.njit
@numba.njit
def
makeslice
(
*
x
):
def
makeslice
(
*
x
):
...
...
tests/link/test_numba.py
浏览文件 @
05ea255f
...
@@ -145,13 +145,10 @@ def test_AdvancedSubtensor1(x, indices):
...
@@ -145,13 +145,10 @@ def test_AdvancedSubtensor1(x, indices):
"x, indices"
,
"x, indices"
,
[
[
(
aet
.
as_tensor
(
np
.
arange
(
3
*
4
*
5
)
.
reshape
((
3
,
4
,
5
))),
([
1
,
2
],
[
2
,
3
])),
(
aet
.
as_tensor
(
np
.
arange
(
3
*
4
*
5
)
.
reshape
((
3
,
4
,
5
))),
([
1
,
2
],
[
2
,
3
])),
# XXX TODO: This will fail because advanced indexing calls into object
(
# mode (i.e. Python) and there's no unboxing for Numba's internal/native
aet
.
as_tensor
(
np
.
arange
(
3
*
4
*
5
)
.
reshape
((
3
,
4
,
5
))),
# `slice` objects.
([
1
,
2
],
slice
(
None
),
[
3
,
4
]),
# (
),
# aet.as_tensor(np.arange(3 * 4 * 5).reshape((3, 4, 5))),
# ([1, 2], slice(None), [3, 4]),
# ),
],
],
)
)
def
test_AdvancedSubtensor
(
x
,
indices
):
def
test_AdvancedSubtensor
(
x
,
indices
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论