Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4298b761
提交
4298b761
authored
11月 19, 2025
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
12月 05, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Numba Split: Validate sizes
上级
de6aca85
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
25 行增加
和
3 行删除
+25
-3
tensor_basic.py
pytensor/link/numba/dispatch/tensor_basic.py
+12
-3
test_tensor_basic.py
tests/link/numba/test_tensor_basic.py
+13
-0
没有找到文件。
pytensor/link/numba/dispatch/tensor_basic.py
浏览文件 @
4298b761
...
@@ -124,10 +124,19 @@ def numba_funcify_Join(op, **kwargs):
...
@@ -124,10 +124,19 @@ def numba_funcify_Join(op, **kwargs):
@register_funcify_default_op_cache_key
(
Split
)
@register_funcify_default_op_cache_key
(
Split
)
def
numba_funcify_Split
(
op
,
**
kwargs
):
def
numba_funcify_Split
(
op
,
**
kwargs
):
@numba_basic.numba_njit
@numba_basic.numba_njit
def
split
(
tensor
,
axis
,
indices
):
def
split
(
x
,
axis
,
sizes
):
return
np
.
split
(
tensor
,
np
.
cumsum
(
indices
)[:
-
1
],
axis
=
axis
.
item
())
if
(
sizes
<
0
)
.
any
():
raise
ValueError
(
"Split sizes cannot be negative"
)
axis
=
axis
.
item
()
split_indices
=
np
.
cumsum
(
sizes
)
if
split_indices
[
-
1
]
!=
x
.
shape
[
axis
]:
raise
ValueError
(
f
"Split sizes sum to {split_indices[-1]}; expected {x.shape[axis]}"
)
return
np
.
split
(
x
,
split_indices
[:
-
1
],
axis
=
axis
)
return
split
cache_version
=
1
return
split
,
cache_version
@register_funcify_default_op_cache_key
(
ExtractDiag
)
@register_funcify_default_op_cache_key
(
ExtractDiag
)
...
...
tests/link/numba/test_tensor_basic.py
浏览文件 @
4298b761
...
@@ -10,6 +10,7 @@ from pytensor.scalar import Add
...
@@ -10,6 +10,7 @@ from pytensor.scalar import Add
from
tests.link.numba.test_basic
import
(
from
tests.link.numba.test_basic
import
(
compare_numba_and_py
,
compare_numba_and_py
,
compare_shape_dtype
,
compare_shape_dtype
,
numba_mode
,
)
)
from
tests.tensor.test_basic
import
check_alloc_runtime_broadcast
from
tests.tensor.test_basic
import
check_alloc_runtime_broadcast
...
@@ -245,6 +246,18 @@ def test_Split_view():
...
@@ -245,6 +246,18 @@ def test_Split_view():
)
)
def
test_split_errors
():
x
=
pt
.
dvector
(
"x"
,
shape
=
(
5
,))
splits
=
pt
.
tensor
(
shape
=
(
3
,),
dtype
=
"int64"
)
outs
=
pt
.
split
(
x
,
splits
)
fn
=
function
([
x
,
splits
],
outs
,
mode
=
numba_mode
)
test_x
=
np
.
zeros
((
5
,))
with
pytest
.
raises
(
ValueError
,
match
=
"Split sizes sum to 4; expected 5"
):
fn
(
test_x
,
np
.
array
([
1
,
2
,
1
],
dtype
=
"int64"
))
with
pytest
.
raises
(
ValueError
,
match
=
"Split sizes cannot be negative"
):
fn
(
test_x
,
np
.
array
([
2
,
4
,
-
1
],
dtype
=
"int64"
))
@pytest.mark.parametrize
(
@pytest.mark.parametrize
(
"val, offset"
,
"val, offset"
,
[
[
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论