Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b2696360
提交
b2696360
authored
4月 06, 2025
作者:
ricardoV94
提交者:
Ricardo Vieira
4月 29, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Specialize Zero Alloc
上级
528b8d4b
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
14 行增加
和
3 行删除
+14
-3
basic.py
pytensor/tensor/basic.py
+14
-3
没有找到文件。
pytensor/tensor/basic.py
浏览文件 @
b2696360
...
@@ -1634,6 +1634,14 @@ class Alloc(COp):
...
@@ -1634,6 +1634,14 @@ class Alloc(COp):
if
v_static_dim
is
None
and
value_dim
==
1
and
out_dim
!=
1
:
if
v_static_dim
is
None
and
value_dim
==
1
and
out_dim
!=
1
:
raise
ValueError
(
Alloc
.
_runtime_broadcast_error_msg
)
raise
ValueError
(
Alloc
.
_runtime_broadcast_error_msg
)
@staticmethod
def
value_is_scalar_zero
(
x
:
TensorVariable
)
->
bool
:
return
(
all
(
x
.
type
.
broadcastable
)
and
isinstance
(
x
,
Constant
)
and
(
x
.
unique_value
==
0
)
)
def
perform
(
self
,
node
,
inputs
,
out_
):
def
perform
(
self
,
node
,
inputs
,
out_
):
(
out
,)
=
out_
(
out
,)
=
out_
v
=
inputs
[
0
]
v
=
inputs
[
0
]
...
@@ -1659,6 +1667,7 @@ class Alloc(COp):
...
@@ -1659,6 +1667,7 @@ class Alloc(COp):
o_static_shape
=
node
.
outputs
[
0
]
.
type
.
shape
o_static_shape
=
node
.
outputs
[
0
]
.
type
.
shape
v_ndim
=
len
(
v_static_shape
)
v_ndim
=
len
(
v_static_shape
)
o_ndim
=
len
(
o_static_shape
)
o_ndim
=
len
(
o_static_shape
)
is_zero
=
self
.
value_is_scalar_zero
(
node
.
inputs
[
0
])
assert
o_ndim
==
len
(
inp
[
1
:])
assert
o_ndim
==
len
(
inp
[
1
:])
# Declare variables
# Declare variables
...
@@ -1699,16 +1708,18 @@ class Alloc(COp):
...
@@ -1699,16 +1708,18 @@ class Alloc(COp):
{fail}
{fail}
}}
}}
}}
}}
if ({int(is_zero)} && (PyArray_IS_C_CONTIGUOUS({zz}) || PyArray_IS_F_CONTIGUOUS({zz}))){{
PyArray_FILLWBYTE({zz}, 0);
}}
// This function takes care of broadcasting
// This function takes care of broadcasting
if (PyArray_CopyInto({zz}, {vv}) == -1)
else
if (PyArray_CopyInto({zz}, {vv}) == -1)
{fail}
{fail}
"""
"""
return
code
return
code
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
(
4
,)
return
(
5
,)
def
infer_shape
(
self
,
fgraph
,
node
,
input_shapes
):
def
infer_shape
(
self
,
fgraph
,
node
,
input_shapes
):
return
[
node
.
inputs
[
1
:]]
return
[
node
.
inputs
[
1
:]]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论