Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f7cf2734
提交
f7cf2734
authored
6月 20, 2025
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
6月 21, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Extract ViewOp functionality into a base TypeCastOp
上级
ddcd9882
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
30 行增加
和
23 行删除
+30
-23
ops.py
pytensor/compile/ops.py
+11
-12
basic.py
pytensor/link/jax/dispatch/basic.py
+5
-5
scalar.py
pytensor/link/numba/dispatch/scalar.py
+5
-5
basic.py
pytensor/link/pytorch/dispatch/basic.py
+9
-1
没有找到文件。
pytensor/compile/ops.py
浏览文件 @
f7cf2734
...
@@ -33,11 +33,8 @@ def register_view_op_c_code(type, code, version=()):
...
@@ -33,11 +33,8 @@ def register_view_op_c_code(type, code, version=()):
ViewOp
.
c_code_and_version
[
type
]
=
(
code
,
version
)
ViewOp
.
c_code_and_version
[
type
]
=
(
code
,
version
)
class
ViewOp
(
COp
):
class
TypeCastingOp
(
COp
):
"""
"""Op that performs a graph-level type cast operation, but has no effect computation-wise (identity function)."""
Returns an inplace view of the input. Used internally by PyTensor.
"""
view_map
=
{
0
:
[
0
]}
view_map
=
{
0
:
[
0
]}
# Mapping from Type to C code (and version) to use.
# Mapping from Type to C code (and version) to use.
...
@@ -47,13 +44,8 @@ class ViewOp(COp):
...
@@ -47,13 +44,8 @@ class ViewOp(COp):
__props__
:
tuple
=
()
__props__
:
tuple
=
()
_f16_ok
:
bool
=
True
_f16_ok
:
bool
=
True
def
make_node
(
self
,
x
):
def
perform
(
self
,
node
,
inputs
,
outputs_storage
):
return
Apply
(
self
,
[
x
],
[
x
.
type
()])
outputs_storage
[
0
][
0
]
=
inputs
[
0
]
def
perform
(
self
,
node
,
inp
,
out
):
(
x
,)
=
inp
(
z
,)
=
out
z
[
0
]
=
x
def
__str__
(
self
):
def
__str__
(
self
):
return
f
"{self.__class__.__name__}"
return
f
"{self.__class__.__name__}"
...
@@ -90,6 +82,13 @@ class ViewOp(COp):
...
@@ -90,6 +82,13 @@ class ViewOp(COp):
return
tuple
(
version
)
return
tuple
(
version
)
class
ViewOp
(
TypeCastingOp
):
"""Returns an inplace view of the input. Used internally by PyTensor."""
def
make_node
(
self
,
x
):
return
Apply
(
self
,
[
x
],
[
x
.
type
()])
def
infer_shape
(
self
,
fgraph
,
node
,
input_shapes
):
def
infer_shape
(
self
,
fgraph
,
node
,
input_shapes
):
return
input_shapes
return
input_shapes
...
...
pytensor/link/jax/dispatch/basic.py
浏览文件 @
f7cf2734
...
@@ -8,7 +8,7 @@ import numpy as np
...
@@ -8,7 +8,7 @@ import numpy as np
from
pytensor.compile
import
JAX
from
pytensor.compile
import
JAX
from
pytensor.compile.builders
import
OpFromGraph
from
pytensor.compile.builders
import
OpFromGraph
from
pytensor.compile.ops
import
DeepCopyOp
,
View
Op
from
pytensor.compile.ops
import
DeepCopyOp
,
TypeCasting
Op
from
pytensor.configdefaults
import
config
from
pytensor.configdefaults
import
config
from
pytensor.graph.fg
import
FunctionGraph
from
pytensor.graph.fg
import
FunctionGraph
from
pytensor.ifelse
import
IfElse
from
pytensor.ifelse
import
IfElse
...
@@ -111,12 +111,12 @@ def jax_funcify_DeepCopyOp(op, **kwargs):
...
@@ -111,12 +111,12 @@ def jax_funcify_DeepCopyOp(op, **kwargs):
return
deepcopyop
return
deepcopyop
@jax_funcify.register
(
View
Op
)
@jax_funcify.register
(
TypeCasting
Op
)
def
jax_funcify_
View
Op
(
op
,
**
kwargs
):
def
jax_funcify_
TypeCasting
Op
(
op
,
**
kwargs
):
def
viewop
(
x
):
def
type_cast
(
x
):
return
x
return
x
return
viewop
return
type_cast
@jax_funcify.register
(
OpFromGraph
)
@jax_funcify.register
(
OpFromGraph
)
...
...
pytensor/link/numba/dispatch/scalar.py
浏览文件 @
f7cf2734
...
@@ -2,7 +2,7 @@ import math
...
@@ -2,7 +2,7 @@ import math
import
numpy
as
np
import
numpy
as
np
from
pytensor.compile.ops
import
View
Op
from
pytensor.compile.ops
import
TypeCasting
Op
from
pytensor.graph.basic
import
Variable
from
pytensor.graph.basic
import
Variable
from
pytensor.link.numba.dispatch
import
basic
as
numba_basic
from
pytensor.link.numba.dispatch
import
basic
as
numba_basic
from
pytensor.link.numba.dispatch.basic
import
(
from
pytensor.link.numba.dispatch.basic
import
(
...
@@ -198,14 +198,14 @@ def numba_funcify_Cast(op, node, **kwargs):
...
@@ -198,14 +198,14 @@ def numba_funcify_Cast(op, node, **kwargs):
@numba_basic.numba_njit
@numba_basic.numba_njit
def
viewop
(
x
):
def
identity
(
x
):
return
x
return
x
@numba_funcify.register
(
Identity
)
@numba_funcify.register
(
Identity
)
@numba_funcify.register
(
View
Op
)
@numba_funcify.register
(
TypeCasting
Op
)
def
numba_funcify_
ViewOp
(
op
,
**
kwargs
):
def
numba_funcify_
type_casting
(
op
,
**
kwargs
):
return
numba_basic
.
global_numba_func
(
viewop
)
return
numba_basic
.
global_numba_func
(
identity
)
@numba_basic.numba_njit
@numba_basic.numba_njit
...
...
pytensor/link/pytorch/dispatch/basic.py
浏览文件 @
f7cf2734
...
@@ -9,7 +9,7 @@ from pytensor import In
...
@@ -9,7 +9,7 @@ from pytensor import In
from
pytensor.compile
import
PYTORCH
from
pytensor.compile
import
PYTORCH
from
pytensor.compile.builders
import
OpFromGraph
from
pytensor.compile.builders
import
OpFromGraph
from
pytensor.compile.function.types
import
add_supervisor_to_fgraph
from
pytensor.compile.function.types
import
add_supervisor_to_fgraph
from
pytensor.compile.ops
import
DeepCopyOp
from
pytensor.compile.ops
import
DeepCopyOp
,
TypeCastingOp
from
pytensor.graph.basic
import
Constant
from
pytensor.graph.basic
import
Constant
from
pytensor.graph.fg
import
FunctionGraph
from
pytensor.graph.fg
import
FunctionGraph
from
pytensor.ifelse
import
IfElse
from
pytensor.ifelse
import
IfElse
...
@@ -71,6 +71,14 @@ def pytorch_funcify_FunctionGraph(
...
@@ -71,6 +71,14 @@ def pytorch_funcify_FunctionGraph(
)
)
@pytorch_funcify.register
(
TypeCastingOp
)
def
pytorch_funcify_CastingOp
(
op
,
node
,
**
kwargs
):
def
type_cast
(
x
):
return
x
return
type_cast
@pytorch_funcify.register
(
CheckAndRaise
)
@pytorch_funcify.register
(
CheckAndRaise
)
def
pytorch_funcify_CheckAndRaise
(
op
,
**
kwargs
):
def
pytorch_funcify_CheckAndRaise
(
op
,
**
kwargs
):
error
=
op
.
exc_type
error
=
op
.
exc_type
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论