Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3b722cec
提交
3b722cec
authored
11月 21, 2025
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
12月 06, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Numba Dot: Handle complex inputs
上级
3ff76039
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
50 行增加
和
13 行删除
+50
-13
elemwise.py
pytensor/link/numba/dispatch/elemwise.py
+31
-13
test_elemwise.py
tests/link/numba/test_elemwise.py
+19
-0
没有找到文件。
pytensor/link/numba/dispatch/elemwise.py
浏览文件 @
3b722cec
...
...
@@ -8,6 +8,7 @@ from numba.core.extending import overload
from
numpy.lib.array_utils
import
normalize_axis_index
,
normalize_axis_tuple
from
numpy.lib.stride_tricks
import
as_strided
from
pytensor
import
config
from
pytensor.graph.op
import
Op
from
pytensor.link.numba.cache
import
(
compile_numba_function_src
,
...
...
@@ -608,37 +609,54 @@ def numba_funcify_Dot(op, node, **kwargs):
x
,
y
=
node
.
inputs
[
out
]
=
node
.
outputs
x_dtype
=
x
.
type
.
dtype
y_dtype
=
y
.
type
.
dtype
dot_dtype
=
f
"float{max((32, out.type.numpy_dtype.itemsize * 8))}"
out_dtype
=
out
.
type
.
dtype
x_dtype
=
x
.
type
.
numpy_dtype
y_dtype
=
y
.
type
.
numpy_dtype
if
x_dtype
==
dot_dtype
and
y_dtype
==
dot_dtype
:
numba_dot_dtype
=
out_dtype
=
out
.
type
.
numpy_dtype
if
out_dtype
.
kind
not
in
"fc"
:
# Numba alawys returns non-integral outputs, we need to cast to float
numba_dot_dtype
=
np
.
dtype
(
f
"float{max((32, out.type.numpy_dtype.itemsize * 8))}"
)
if
config
.
compiler_verbose
and
not
(
x_dtype
==
y_dtype
==
out_dtype
==
numba_dot_dtype
):
print
(
# noqa: T201
"Numba Dot requires a type casting of inputs and/or output: "
f
"{x_dtype=}, {y_dtype=}, {out_dtype=}, {numba_dot_dtype=}"
)
if
x_dtype
==
numba_dot_dtype
and
y_dtype
==
numba_dot_dtype
:
@numba_basic.numba_njit
def
dot
(
x
,
y
):
return
np
.
asarray
(
np
.
dot
(
x
,
y
))
elif
x_dtype
==
dot_dtype
and
y_dtype
!=
dot_dtype
:
elif
x_dtype
==
numba_dot_dtype
and
y_dtype
!=
numba_
dot_dtype
:
@numba_basic.numba_njit
def
dot
(
x
,
y
):
return
np
.
asarray
(
np
.
dot
(
x
,
y
.
astype
(
dot_dtype
)))
return
np
.
asarray
(
np
.
dot
(
x
,
y
.
astype
(
numba_
dot_dtype
)))
elif
x_dtype
!=
dot_dtype
and
y_dtype
==
dot_dtype
:
elif
x_dtype
!=
numba_dot_dtype
and
y_dtype
==
numba_
dot_dtype
:
@numba_basic.numba_njit
def
dot
(
x
,
y
):
return
np
.
asarray
(
np
.
dot
(
x
.
astype
(
dot_dtype
),
y
))
return
np
.
asarray
(
np
.
dot
(
x
.
astype
(
numba_
dot_dtype
),
y
))
else
:
@numba_basic.numba_njit
def
dot
(
x
,
y
):
return
np
.
asarray
(
np
.
dot
(
x
.
astype
(
dot_dtype
),
y
.
astype
(
dot_dtype
)))
return
np
.
asarray
(
np
.
dot
(
x
.
astype
(
numba_dot_dtype
),
y
.
astype
(
numba_dot_dtype
))
)
cache_version
=
1
if
out_dtype
==
dot_dtype
:
return
dot
if
out_dtype
==
numba_
dot_dtype
:
return
dot
,
cache_version
else
:
...
...
@@ -646,7 +664,7 @@ def numba_funcify_Dot(op, node, **kwargs):
def
dot_with_cast
(
x
,
y
):
return
dot
(
x
,
y
)
.
astype
(
out_dtype
)
return
dot_with_cast
return
dot_with_cast
,
cache_version
@register_funcify_default_op_cache_key
(
BatchedDot
)
...
...
tests/link/numba/test_elemwise.py
浏览文件 @
3b722cec
...
...
@@ -718,6 +718,25 @@ class TestsBenchmark:
(
pt
.
vector
(
dtype
=
"int16"
),
rng
.
random
(
size
=
(
2
,))
.
astype
(
np
.
int16
)),
(
pt
.
vector
(
dtype
=
"uint8"
),
rng
.
random
(
size
=
(
2
,))
.
astype
(
np
.
uint8
)),
),
# Viewing the array with 2 last dimensions as complex128 means
# the first entry will be real part and the second entry the imaginary part
(
(
pt
.
matrix
(
dtype
=
"complex128"
),
rng
.
random
(
size
=
(
5
,
4
,
2
))
.
view
(
"complex128"
)
.
squeeze
(
-
1
),
),
(
pt
.
matrix
(
dtype
=
"complex128"
),
rng
.
random
(
size
=
(
4
,
3
,
2
))
.
view
(
"complex128"
)
.
squeeze
(
-
1
),
),
),
(
(
pt
.
matrix
(
dtype
=
"int64"
),
rng
.
random
(
size
=
(
5
,
4
))
.
astype
(
"int64"
)),
(
pt
.
matrix
(
dtype
=
"complex128"
),
rng
.
random
(
size
=
(
4
,
3
,
2
))
.
view
(
"complex128"
)
.
squeeze
(
-
1
),
),
),
],
)
def
test_Dot
(
x
,
y
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论