Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1c2bc8fe
提交
1c2bc8fe
authored
10月 06, 2024
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
10月 07, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove rarely used shape_i helpers
上级
d9b3924f
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
7 行增加
和
23 行删除
+7
-23
shape.py
pytensor/tensor/rewriting/shape.py
+1
-2
shape.py
pytensor/tensor/shape.py
+0
-10
subtensor.py
pytensor/tensor/subtensor.py
+3
-4
test_shape.py
tests/tensor/test_shape.py
+3
-7
没有找到文件。
pytensor/tensor/rewriting/shape.py
浏览文件 @
1c2bc8fe
...
...
@@ -42,7 +42,6 @@ from pytensor.tensor.shape import (
Shape_i
,
SpecifyShape
,
Unbroadcast
,
shape_i
,
specify_shape
,
unbroadcast
,
)
...
...
@@ -1060,7 +1059,7 @@ def local_Shape_of_SpecifyShape(fgraph, node):
# Replace `NoneConst` by `shape_i`
for
i
,
sh
in
enumerate
(
shape
):
if
NoneConst
.
equals
(
sh
):
shape
[
i
]
=
shape_i
(
x
,
i
,
fgraph
)
shape
[
i
]
=
x
.
shape
[
i
]
return
[
stack
(
shape
)
.
astype
(
np
.
int64
)]
...
...
pytensor/tensor/shape.py
浏览文件 @
1c2bc8fe
...
...
@@ -363,16 +363,6 @@ def shape_i(var, i, fgraph=None):
return
shape
(
var
)[
i
]
def
shape_i_op
(
i
):
key
=
i
if
key
not
in
shape_i_op
.
cache
:
shape_i_op
.
cache
[
key
]
=
Shape_i
(
i
)
return
shape_i_op
.
cache
[
key
]
shape_i_op
.
cache
=
{}
# type: ignore
def
register_shape_i_c_code
(
typ
,
code
,
check_input
,
version
=
()):
"""
Tell Shape_i how to generate C code for an PyTensor Type.
...
...
pytensor/tensor/subtensor.py
浏览文件 @
1c2bc8fe
...
...
@@ -38,7 +38,7 @@ from pytensor.tensor.blockwise import vectorize_node_fallback
from
pytensor.tensor.elemwise
import
DimShuffle
from
pytensor.tensor.exceptions
import
AdvancedIndexingError
,
NotScalarConstantError
from
pytensor.tensor.math
import
clip
from
pytensor.tensor.shape
import
Reshape
,
s
hape_i
,
specify_broadcastable
from
pytensor.tensor.shape
import
Reshape
,
S
hape_i
,
specify_broadcastable
from
pytensor.tensor.type
import
(
TensorType
,
bscalar
,
...
...
@@ -2705,10 +2705,9 @@ class AdvancedSubtensor(Op):
index_shapes
=
[]
for
idx
,
ishape
in
zip
(
indices
,
ishapes
[
1
:]):
# Mixed bool indexes are converted to nonzero entries
shape0_op
=
Shape_i
(
0
)
if
is_bool_index
(
idx
):
index_shapes
.
extend
(
(
shape_i
(
nz_dim
,
0
,
fgraph
=
fgraph
),)
for
nz_dim
in
nonzero
(
idx
)
)
index_shapes
.
extend
((
shape0_op
(
nz_dim
),)
for
nz_dim
in
nonzero
(
idx
))
# The `ishapes` entries for `SliceType`s will be None, and
# we need to give `indexed_result_shape` the actual slices.
elif
isinstance
(
getattr
(
idx
,
"type"
,
None
),
SliceType
):
...
...
tests/tensor/test_shape.py
浏览文件 @
1c2bc8fe
...
...
@@ -8,7 +8,6 @@ from pytensor import Mode, function, grad
from
pytensor.compile.ops
import
DeepCopyOp
from
pytensor.configdefaults
import
config
from
pytensor.graph.basic
import
Variable
,
equal_computations
from
pytensor.graph.fg
import
FunctionGraph
from
pytensor.graph.replace
import
clone_replace
,
vectorize_node
from
pytensor.graph.type
import
Type
from
pytensor.misc.safe_asarray
import
_asarray
...
...
@@ -16,7 +15,6 @@ from pytensor.scalar.basic import ScalarConstant
from
pytensor.tensor
import
as_tensor_variable
,
broadcast_to
,
get_vector_length
,
row
from
pytensor.tensor.basic
import
MakeVector
,
constant
,
stack
from
pytensor.tensor.elemwise
import
DimShuffle
,
Elemwise
from
pytensor.tensor.rewriting.shape
import
ShapeFeature
from
pytensor.tensor.shape
import
(
Reshape
,
Shape
,
...
...
@@ -26,7 +24,6 @@ from pytensor.tensor.shape import (
_specify_shape
,
reshape
,
shape
,
shape_i
,
shape_tuple
,
specify_broadcastable
,
specify_shape
,
...
...
@@ -633,13 +630,12 @@ def test_nonstandard_shapes():
tl_shape
=
shape
(
tl
)
assert
np
.
array_equal
(
tl_shape
.
get_test_value
(),
(
2
,
2
,
3
,
4
))
# T
here's no `FunctionGraph`, so it should return a `Subtensor`
tl_shape_i
=
shape
_i
(
tl
,
0
)
# T
est specific dim
tl_shape_i
=
shape
(
tl
)[
0
]
assert
isinstance
(
tl_shape_i
.
owner
.
op
,
Subtensor
)
assert
tl_shape_i
.
get_test_value
()
==
2
tl_fg
=
FunctionGraph
([
a
,
b
],
[
tl
],
features
=
[
ShapeFeature
()])
tl_shape_i
=
shape_i
(
tl
,
0
,
fgraph
=
tl_fg
)
tl_shape_i
=
Shape_i
(
0
)(
tl
)
assert
not
isinstance
(
tl_shape_i
.
owner
.
op
,
Subtensor
)
assert
tl_shape_i
.
get_test_value
()
==
2
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论