Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ac51f01c
提交
ac51f01c
authored
11月 25, 2025
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
11月 27, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement extensible deepcopy in numba
上级
69567532
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
58 行增加
和
23 行删除
+58
-23
compile_ops.py
pytensor/link/numba/dispatch/compile_ops.py
+34
-13
random.py
pytensor/link/numba/dispatch/random.py
+11
-10
subtensor.py
pytensor/link/numba/dispatch/subtensor.py
+13
-0
没有找到文件。
pytensor/link/numba/dispatch/compile_ops.py
浏览文件 @
ac51f01c
from
copy
import
deepcopy
from
hashlib
import
sha256
import
numba
import
numpy
as
np
from
pytensor.compile.builders
import
OpFromGraph
...
...
@@ -15,7 +17,34 @@ from pytensor.link.numba.dispatch.basic import (
register_funcify_default_op_cache_key
,
)
from
pytensor.raise_op
import
CheckAndRaise
from
pytensor.tensor.type
import
TensorType
def
numba_deepcopy
(
x
):
return
deepcopy
(
x
)
@numba.extending.overload
(
numba_deepcopy
)
def
numba_deepcopy_tensor
(
x
):
if
isinstance
(
x
,
numba
.
types
.
Number
):
def
number_deepcopy
(
x
):
return
x
return
number_deepcopy
if
isinstance
(
x
,
numba
.
types
.
Array
):
def
array_deepcopy
(
x
):
return
np
.
copy
(
x
)
return
array_deepcopy
if
isinstance
(
x
,
numba
.
types
.
UnicodeType
):
def
string_deepcopy
(
x
):
return
x
return
string_deepcopy
@register_funcify_and_cache_key
(
OpFromGraph
)
...
...
@@ -64,19 +93,11 @@ def numba_funcify_type_casting(op, **kwargs):
@register_funcify_default_op_cache_key
(
DeepCopyOp
)
def
numba_funcify_DeepCopyOp
(
op
,
node
,
**
kwargs
):
if
isinstance
(
node
.
inputs
[
0
]
.
type
,
TensorType
):
@numba_basic.numba_njit
def
deepcopy
(
x
):
return
np
.
copy
(
x
)
else
:
@numba_basic.numba_njit
def
deepcopy
(
x
):
return
x
@numba_basic.numba_njit
def
deepcopy
(
x
):
return
numba_deepcopy
(
x
)
return
deepcopy
return
deepcopy
,
1
@register_funcify_default_op_cache_key
(
IfElse
)
...
...
pytensor/link/numba/dispatch/random.py
浏览文件 @
ac51f01c
from
collections.abc
import
Callable
from
copy
import
copy
,
deepcopy
from
copy
import
deepcopy
from
functools
import
singledispatch
from
hashlib
import
sha256
from
textwrap
import
dedent
...
...
@@ -20,6 +20,7 @@ from pytensor.link.numba.dispatch.basic import (
numba_funcify
,
register_funcify_and_cache_key
,
)
from
pytensor.link.numba.dispatch.compile_ops
import
numba_deepcopy
from
pytensor.link.numba.dispatch.vectorize_codegen
import
(
_jit_options
,
_vectorized
,
...
...
@@ -35,16 +36,16 @@ from pytensor.tensor.type_other import NoneTypeT
from
pytensor.tensor.utils
import
_parse_gufunc_signature
@overload
(
copy
)
def
copy_NumPyRandomGenerator
(
rng
):
def
impl
(
rng
):
# TODO: Open issue on Numba?
with
numba
.
objmode
(
new_rng
=
types
.
npy_rng
):
new_rng
=
deepcopy
(
rng
)
@numba.extending.overload
(
numba_deepcopy
)
def
numba_deepcopy_random_generator
(
x
):
if
isinstance
(
x
,
numba
.
types
.
NumPyRandomGeneratorType
):
return
new_rng
def
random_generator_deepcopy
(
x
):
with
numba
.
objmode
(
new_rng
=
types
.
npy_rng
):
new_rng
=
deepcopy
(
x
)
return
new_rng
return
impl
return
random_generator_deepcopy
@singledispatch
...
...
@@ -449,7 +450,7 @@ def numba_funcify_RandomVariable(op: RandomVariableWithCoreShape, node, **kwargs
def
ov_random
(
core_shape
,
rng
,
size
,
*
dist_params
):
def
impl
(
core_shape
,
rng
,
size
,
*
dist_params
):
if
not
inplace
:
rng
=
copy
(
rng
)
rng
=
numba_deep
copy
(
rng
)
draws
=
_vectorized
(
core_op_fn
,
...
...
pytensor/link/numba/dispatch/subtensor.py
浏览文件 @
ac51f01c
...
...
@@ -18,6 +18,7 @@ from pytensor.link.numba.dispatch.basic import (
register_funcify_and_cache_key
,
register_funcify_default_op_cache_key
,
)
from
pytensor.link.numba.dispatch.compile_ops
import
numba_deepcopy
from
pytensor.tensor
import
TensorType
from
pytensor.tensor.rewriting.subtensor
import
is_full_slice
from
pytensor.tensor.subtensor
import
(
...
...
@@ -104,6 +105,18 @@ def enable_slice_boxing():
enable_slice_boxing
()
@numba.extending.overload
(
numba_deepcopy
)
def
numba_deepcopy_slice
(
x
):
if
isinstance
(
x
,
types
.
SliceType
):
def
deepcopy_slice
(
x
):
return
slice
(
numba_deepcopy
(
x
.
start
),
numba_deepcopy
(
x
.
stop
),
numba_deepcopy
(
x
.
step
)
)
return
deepcopy_slice
@register_funcify_default_op_cache_key
(
MakeSlice
)
def
numba_funcify_MakeSlice
(
op
,
**
kwargs
):
@numba_basic.numba_njit
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论