Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9a55cfe6
提交
9a55cfe6
authored
12月 20, 2022
作者:
Adrian Seyboldt
提交者:
Adrian Seyboldt
1月 04, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add shape checking in numba elemwise
上级
69eb09ad
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
35 行增加
和
31 行删除
+35
-31
elemwise.py
pytensor/link/numba/dispatch/elemwise.py
+0
-19
elemwise_codegen.py
pytensor/link/numba/dispatch/elemwise_codegen.py
+35
-12
没有找到文件。
pytensor/link/numba/dispatch/elemwise.py
浏览文件 @
9a55cfe6
...
...
@@ -454,10 +454,6 @@ def _vectorized(
inplace_pattern
,
inputs
,
):
#if not isinstance(scalar_func, types.Literal):
# raise TypingError("scalar func must be literal.")
#scalar_func = scalar_func.literal_value
arg_types
=
[
scalar_func
,
input_bc_patterns
,
...
...
@@ -516,8 +512,6 @@ def _vectorized(
inplace_pattern_val
=
inplace_pattern
input_types
=
inputs
#assert not inplace_pattern_val
def
codegen
(
ctx
,
builder
,
...
...
@@ -551,18 +545,6 @@ def _vectorized(
input_types
,
)
def
_check_input_shapes
(
*
_
):
# TODO impl
return
_check_input_shapes
(
ctx
,
builder
,
iter_shape
,
inputs
,
input_bc_patterns_val
,
)
elemwise_codegen
.
make_loop_call
(
typingctx
,
ctx
,
...
...
@@ -594,7 +576,6 @@ def _vectorized(
builder
,
sig
.
return_type
,
[
out
.
_getvalue
()
for
out
in
outputs
]
)
# TODO check inplace_pattern
ret_type
=
types
.
Tuple
(
[
types
.
Array
(
numba
.
from_dtype
(
np
.
dtype
(
dtype
)),
ndim
,
"C"
)
...
...
pytensor/link/numba/dispatch/elemwise_codegen.py
浏览文件 @
9a55cfe6
...
...
@@ -3,32 +3,55 @@ import numpy as np
from
llvmlite
import
ir
from
numba
import
types
from
numba.core
import
cgutils
from
numba.core.base
import
BaseContext
from
numba.np
import
arrayobj
def
compute_itershape
(
ctx
,
ctx
:
BaseContext
,
builder
:
ir
.
IRBuilder
,
in_shapes
,
broadcast_pattern
,
):
one
=
ir
.
IntType
(
64
)(
1
)
ndim
=
len
(
in_shapes
[
0
])
#shape = [ir.IntType(64)(1) for _ in range(ndim)]
shape
=
[
None
]
*
ndim
for
i
in
range
(
ndim
):
# TODO Error checking...
# What if all shapes are 0?
for
bc
,
in_shape
in
zip
(
broadcast_pattern
,
in_shapes
):
for
j
,
(
bc
,
in_shape
)
in
enumerate
(
zip
(
broadcast_pattern
,
in_shapes
,
strict
=
True
)
):
length
=
in_shape
[
i
]
if
bc
[
i
]:
# TODO
# raise error if length != 1
pass
with
builder
.
if_then
(
builder
.
icmp_unsigned
(
"!="
,
length
,
one
),
likely
=
False
):
msg
=
(
f
"Input {j} to elemwise is expected to have shape 1 in axis {i}"
)
ctx
.
call_conv
.
return_user_exc
(
builder
,
ValueError
,
(
msg
,))
elif
shape
[
i
]
is
not
None
:
with
builder
.
if_then
(
builder
.
icmp_unsigned
(
"!="
,
length
,
shape
[
i
]),
likely
=
False
):
with
builder
.
if_else
(
builder
.
icmp_unsigned
(
"=="
,
length
,
one
))
as
(
then
,
otherwise
,
):
with
then
:
msg
=
(
f
"Incompative shapes for input {j} and axis {i} of "
f
"elemwise. Input {j} has shape 1, but is not statically "
"known to have shape 1, and thus not broadcastable."
)
ctx
.
call_conv
.
return_user_exc
(
builder
,
ValueError
,
(
msg
,))
with
otherwise
:
msg
=
(
f
"Input {j} to elemwise has an incompatible "
f
"shape in axis {i}."
)
ctx
.
call_conv
.
return_user_exc
(
builder
,
ValueError
,
(
msg
,))
else
:
# TODO
# if shape[i] is not None:
# raise Error if !=
shape
[
i
]
=
in_shape
[
i
]
shape
[
i
]
=
length
for
i
in
range
(
ndim
):
if
shape
[
i
]
is
None
:
shape
[
i
]
=
one
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论