Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c4702cd9
提交
c4702cd9
authored
11月 30, 2025
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
12月 07, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Numba Alloc: Patch so it works inside a Blockwise
上级
c513419c
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
17 行增加
和
5 行删除
+17
-5
tensor_basic.py
pytensor/link/numba/dispatch/tensor_basic.py
+5
-3
test_blockwise.py
tests/link/numba/test_blockwise.py
+12
-2
没有找到文件。
pytensor/link/numba/dispatch/tensor_basic.py
浏览文件 @
c4702cd9
...
...
@@ -74,13 +74,13 @@ def numba_funcify_Alloc(op, node, **kwargs):
f
'if val.shape[{-i - 1}] == 1 and scalar_shape[{-i - 1}] != 1: raise ValueError("{Alloc._runtime_broadcast_error_msg}")'
)
check_runtime_broadcast_src
=
indent
(
"
\n
"
.
join
(
check_runtime_broadcast
),
" "
*
4
)
dtype
=
node
.
inputs
[
0
]
.
type
.
dtype
alloc_def_src
=
f
"""
def alloc(val, {", ".join(shape_var_names)}):
{shapes_to_items_src}
scalar_shape = {create_tuple_string(shape_var_item_names)}
{check_runtime_broadcast_src}
res = np.empty(scalar_shape, dtype=
val.dtype
)
res = np.empty(scalar_shape, dtype=
np.{dtype}
)
res[...] = val
return res
"""
...
...
@@ -88,10 +88,12 @@ def alloc(val, {", ".join(shape_var_names)}):
alloc_def_src
,
"alloc"
,
globals
()
|
{
"np"
:
np
},
write_to_disk
=
True
,
)
cache_version
=
-
1
cache_key
=
sha256
(
str
((
type
(
op
),
node
.
inputs
[
0
]
.
type
.
broadcastable
))
.
encode
()
str
((
type
(
op
),
node
.
inputs
[
0
]
.
type
.
broadcastable
,
cache_version
))
.
encode
()
)
.
hexdigest
()
return
numba_basic
.
numba_njit
(
alloc_fn
),
cache_key
...
...
tests/link/numba/test_blockwise.py
浏览文件 @
c4702cd9
...
...
@@ -2,8 +2,8 @@ import numpy as np
import
pytest
from
pytensor
import
function
from
pytensor.tensor
import
tensor
,
tensor3
from
pytensor.tensor.basic
import
A
Range
from
pytensor.tensor
import
lvector
,
tensor
,
tensor3
from
pytensor.tensor.basic
import
A
lloc
,
ARange
,
constant
from
pytensor.tensor.blockwise
import
Blockwise
,
BlockwiseWithCoreShape
from
pytensor.tensor.nlinalg
import
SVD
,
Det
from
pytensor.tensor.slinalg
import
Cholesky
,
cholesky
...
...
@@ -70,3 +70,13 @@ def test_repeated_args():
final_node
=
fn
.
maker
.
fgraph
.
outputs
[
0
]
.
owner
assert
isinstance
(
final_node
.
op
,
BlockwiseWithCoreShape
)
assert
final_node
.
inputs
[
0
]
is
final_node
.
inputs
[
1
]
def
test_blockwise_alloc
():
val
=
lvector
(
"val"
)
out
=
Blockwise
(
Alloc
(),
signature
=
"(),(),()->(2,3)"
)(
val
,
constant
(
2
,
dtype
=
"int64"
),
constant
(
3
,
dtype
=
"int64"
)
)
assert
out
.
type
.
ndim
==
3
compare_numba_and_py
([
val
],
[
out
],
[
np
.
arange
(
5
)],
eval_obj_mode
=
False
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论