Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f15258d9
提交
f15258d9
authored
10月 09, 2025
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
10月 16, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reorder functions in numba/dispatch/basic.py
Helpers before dispatchers
上级
351ce53e
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
65 行增加
和
65 行删除
+65
-65
basic.py
pytensor/link/numba/dispatch/basic.py
+65
-65
没有找到文件。
pytensor/link/numba/dispatch/basic.py
浏览文件 @
f15258d9
...
...
@@ -166,6 +166,55 @@ def create_arg_string(x):
return
args
@numba.extending.intrinsic
def
direct_cast
(
typingctx
,
val
,
typ
):
if
isinstance
(
typ
,
numba
.
types
.
TypeRef
):
casted
=
typ
.
instance_type
elif
isinstance
(
typ
,
numba
.
types
.
DTypeSpec
):
casted
=
typ
.
dtype
else
:
casted
=
typ
sig
=
casted
(
casted
,
typ
)
def
codegen
(
context
,
builder
,
signature
,
args
):
val
,
_
=
args
context
.
nrt
.
incref
(
builder
,
signature
.
return_type
,
val
)
return
val
return
sig
,
codegen
def
int_to_float_fn
(
inputs
,
out_dtype
):
"""Create a Numba function that converts integer and boolean ``ndarray``s to floats."""
if
(
all
(
inp
.
type
.
dtype
==
out_dtype
for
inp
in
inputs
)
and
np
.
dtype
(
out_dtype
)
.
kind
==
"f"
):
@numba_njit
(
inline
=
"always"
)
def
inputs_cast
(
x
):
return
x
elif
any
(
i
.
type
.
numpy_dtype
.
kind
in
"uib"
for
i
in
inputs
):
args_dtype
=
np
.
dtype
(
f
"f{out_dtype.itemsize}"
)
@numba_njit
(
inline
=
"always"
)
def
inputs_cast
(
x
):
return
x
.
astype
(
args_dtype
)
else
:
args_dtype_sz
=
max
(
_arg
.
type
.
numpy_dtype
.
itemsize
for
_arg
in
inputs
)
args_dtype
=
np
.
dtype
(
f
"f{args_dtype_sz}"
)
@numba_njit
(
inline
=
"always"
)
def
inputs_cast
(
x
):
return
x
.
astype
(
args_dtype
)
return
inputs_cast
@singledispatch
def
numba_typify
(
data
,
dtype
=
None
,
**
kwargs
):
return
data
...
...
@@ -231,6 +280,22 @@ def numba_funcify(op, node=None, storage_map=None, **kwargs):
return
generate_fallback_impl
(
op
,
node
,
storage_map
,
**
kwargs
)
@numba_funcify.register
(
FunctionGraph
)
def
numba_funcify_FunctionGraph
(
fgraph
,
node
=
None
,
fgraph_name
=
"numba_funcified_fgraph"
,
**
kwargs
,
):
return
fgraph_to_python
(
fgraph
,
numba_funcify
,
type_conversion_fn
=
numba_typify
,
fgraph_name
=
fgraph_name
,
**
kwargs
,
)
@numba_funcify.register
(
OpFromGraph
)
def
numba_funcify_OpFromGraph
(
op
,
node
=
None
,
**
kwargs
):
_
=
kwargs
.
pop
(
"storage_map"
,
None
)
...
...
@@ -263,22 +328,6 @@ def numba_funcify_OpFromGraph(op, node=None, **kwargs):
return
opfromgraph
@numba_funcify.register
(
FunctionGraph
)
def
numba_funcify_FunctionGraph
(
fgraph
,
node
=
None
,
fgraph_name
=
"numba_funcified_fgraph"
,
**
kwargs
,
):
return
fgraph_to_python
(
fgraph
,
numba_funcify
,
type_conversion_fn
=
numba_typify
,
fgraph_name
=
fgraph_name
,
**
kwargs
,
)
@numba_funcify.register
(
DeepCopyOp
)
def
numba_funcify_DeepCopyOp
(
op
,
node
,
**
kwargs
):
if
isinstance
(
node
.
inputs
[
0
]
.
type
,
TensorType
):
...
...
@@ -296,55 +345,6 @@ def numba_funcify_DeepCopyOp(op, node, **kwargs):
return
deepcopy
@numba.extending.intrinsic
def
direct_cast
(
typingctx
,
val
,
typ
):
if
isinstance
(
typ
,
numba
.
types
.
TypeRef
):
casted
=
typ
.
instance_type
elif
isinstance
(
typ
,
numba
.
types
.
DTypeSpec
):
casted
=
typ
.
dtype
else
:
casted
=
typ
sig
=
casted
(
casted
,
typ
)
def
codegen
(
context
,
builder
,
signature
,
args
):
val
,
_
=
args
context
.
nrt
.
incref
(
builder
,
signature
.
return_type
,
val
)
return
val
return
sig
,
codegen
def
int_to_float_fn
(
inputs
,
out_dtype
):
"""Create a Numba function that converts integer and boolean ``ndarray``s to floats."""
if
(
all
(
inp
.
type
.
dtype
==
out_dtype
for
inp
in
inputs
)
and
np
.
dtype
(
out_dtype
)
.
kind
==
"f"
):
@numba_njit
(
inline
=
"always"
)
def
inputs_cast
(
x
):
return
x
elif
any
(
i
.
type
.
numpy_dtype
.
kind
in
"uib"
for
i
in
inputs
):
args_dtype
=
np
.
dtype
(
f
"f{out_dtype.itemsize}"
)
@numba_njit
(
inline
=
"always"
)
def
inputs_cast
(
x
):
return
x
.
astype
(
args_dtype
)
else
:
args_dtype_sz
=
max
(
_arg
.
type
.
numpy_dtype
.
itemsize
for
_arg
in
inputs
)
args_dtype
=
np
.
dtype
(
f
"f{args_dtype_sz}"
)
@numba_njit
(
inline
=
"always"
)
def
inputs_cast
(
x
):
return
x
.
astype
(
args_dtype
)
return
inputs_cast
@numba_funcify.register
(
IfElse
)
def
numba_funcify_IfElse
(
op
,
**
kwargs
):
n_outs
=
op
.
n_outs
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论