Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c513419c
提交
c513419c
authored
12月 01, 2025
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
12月 07, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Numba Blockwise: Fix OpFromGraph as core_op
上级
01ac0c7c
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
27 行增加
和
5 行删除
+27
-5
builders.py
pytensor/compile/builders.py
+7
-2
blockwise.py
pytensor/link/numba/dispatch/blockwise.py
+0
-1
elemwise.py
pytensor/link/numba/dispatch/elemwise.py
+0
-1
test_compile_ops.py
tests/link/numba/test_compile_ops.py
+20
-1
没有找到文件。
pytensor/compile/builders.py
浏览文件 @
c513419c
...
@@ -4,6 +4,7 @@ import warnings
...
@@ -4,6 +4,7 @@ import warnings
from
collections.abc
import
Callable
,
Sequence
from
collections.abc
import
Callable
,
Sequence
from
copy
import
copy
from
copy
import
copy
from
functools
import
partial
from
functools
import
partial
from
itertools
import
chain
from
typing
import
Union
,
cast
from
typing
import
Union
,
cast
from
pytensor.compile.function
import
function
from
pytensor.compile.function
import
function
...
@@ -47,11 +48,15 @@ def infer_shape(outs, inputs, input_shapes):
...
@@ -47,11 +48,15 @@ def infer_shape(outs, inputs, input_shapes):
assert
len
(
inp_shp
)
==
inp
.
type
.
ndim
assert
len
(
inp_shp
)
==
inp
.
type
.
ndim
shape_feature
=
ShapeFeature
()
shape_feature
=
ShapeFeature
()
shape_feature
.
on_attach
(
FunctionGraph
([],
[]))
fgraph
=
FunctionGraph
([],
[],
features
=
[
shape_feature
])
for
v
in
chain
.
from_iterable
(
s
for
s
in
input_shapes
if
s
is
not
None
):
# Import input_shape nodes, as for some graphs ShapeFeature assumes these were seen before
if
(
node
:
=
v
.
owner
)
is
not
None
:
fgraph
.
import_node
(
node
,
import_missing
=
True
)
# Initialize shape_of with the input shapes
# Initialize shape_of with the input shapes
for
inp
,
inp_shp
in
zip
(
inputs
,
input_shapes
,
strict
=
True
):
for
inp
,
inp_shp
in
zip
(
inputs
,
input_shapes
,
strict
=
True
):
shape_feature
.
set_shape
(
inp
,
inp_shp
)
shape_feature
.
set_shape
(
inp
,
inp_shp
,
override
=
True
)
def
local_traverse
(
out
):
def
local_traverse
(
out
):
"""
"""
...
...
pytensor/link/numba/dispatch/blockwise.py
浏览文件 @
c513419c
...
@@ -36,7 +36,6 @@ def numba_funcify_Blockwise(op: BlockwiseWithCoreShape, node, **kwargs):
...
@@ -36,7 +36,6 @@ def numba_funcify_Blockwise(op: BlockwiseWithCoreShape, node, **kwargs):
core_op_fn
,
core_op_key
=
numba_funcify_and_cache_key
(
core_op_fn
,
core_op_key
=
numba_funcify_and_cache_key
(
core_op
,
core_op
,
node
=
core_node
,
node
=
core_node
,
parent_node
=
node
,
**
kwargs
,
**
kwargs
,
)
)
core_op_fn
=
store_core_outputs
(
core_op_fn
,
nin
=
nin
,
nout
=
nout
)
core_op_fn
=
store_core_outputs
(
core_op_fn
,
nin
=
nin
,
nout
=
nout
)
...
...
pytensor/link/numba/dispatch/elemwise.py
浏览文件 @
c513419c
...
@@ -274,7 +274,6 @@ def numba_funcify_Elemwise(op, node, **kwargs):
...
@@ -274,7 +274,6 @@ def numba_funcify_Elemwise(op, node, **kwargs):
scalar_op_fn
,
scalar_cache_key
=
numba_funcify_and_cache_key
(
scalar_op_fn
,
scalar_cache_key
=
numba_funcify_and_cache_key
(
op
.
scalar_op
,
op
.
scalar_op
,
node
=
scalar_node
,
node
=
scalar_node
,
parent_node
=
node
,
**
kwargs
,
**
kwargs
,
)
)
...
...
tests/link/numba/test_compile_ops.py
浏览文件 @
c513419c
...
@@ -4,9 +4,10 @@ import pytest
...
@@ -4,9 +4,10 @@ import pytest
from
pytensor
import
OpFromGraph
,
config
,
function
,
ifelse
from
pytensor
import
OpFromGraph
,
config
,
function
,
ifelse
from
pytensor
import
tensor
as
pt
from
pytensor
import
tensor
as
pt
from
pytensor.compile
import
ViewOp
from
pytensor.compile
import
ViewOp
from
pytensor.graph
import
vectorize_graph
from
pytensor.raise_op
import
assert_op
from
pytensor.raise_op
import
assert_op
from
pytensor.scalar
import
Add
from
pytensor.scalar
import
Add
from
pytensor.tensor
import
matrix
from
pytensor.tensor
import
dmatrix
,
dtensor3
,
matrix
from
pytensor.tensor.elemwise
import
Elemwise
from
pytensor.tensor.elemwise
import
Elemwise
from
tests.link.numba.test_basic
import
compare_numba_and_py
from
tests.link.numba.test_basic
import
compare_numba_and_py
...
@@ -171,6 +172,24 @@ def test_ofg_aliased_outputs():
...
@@ -171,6 +172,24 @@ def test_ofg_aliased_outputs():
np
.
testing
.
assert_allclose
(
res
,
np
.
ones
((
2
,
2
)))
np
.
testing
.
assert_allclose
(
res
,
np
.
ones
((
2
,
2
)))
def
test_ofg_elemwise_regression
():
# Regression bug for https://github.com/pymc-devs/pytensor/issues/1507
x
=
dmatrix
(
"x"
,
shape
=
(
None
,
None
))
z
=
OpFromGraph
(
inputs
=
[
x
],
outputs
=
[
x
+
1
],
)(
x
)
x_batched
=
dtensor3
(
"X_batched"
,
shape
=
(
None
,
None
,
None
))
z_batched
=
vectorize_graph
(
z
,
{
x
:
x_batched
})
compare_numba_and_py
(
[
x_batched
],
[
z_batched
],
[
np
.
random
.
normal
(
size
=
(
3
,
2
,
4
))],
eval_obj_mode
=
False
,
)
def
test_check_and_raise
():
def
test_check_and_raise
():
x
=
pt
.
vector
()
x
=
pt
.
vector
()
x_test_value
=
np
.
array
([
1.0
,
2.0
],
dtype
=
config
.
floatX
)
x_test_value
=
np
.
array
([
1.0
,
2.0
],
dtype
=
config
.
floatX
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论