Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
89d5366c
提交
89d5366c
authored
3月 05, 2025
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
3月 05, 2025
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do not introduce 0 strides for broadcastable dimensions in DimShuffle
Some poorly implemented BLAS operations don't handle them correctly
上级
bf628c97
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
8 行增加
和
4 行删除
+8
-4
dimshuffle.c
pytensor/tensor/c_code/dimshuffle.c
+7
-2
test_elemwise.py
tests/tensor/test_elemwise.py
+1
-2
没有找到文件。
pytensor/tensor/c_code/dimshuffle.c
浏览文件 @
89d5366c
...
@@ -33,12 +33,17 @@ int APPLY_SPECIFIC(cpu_dimshuffle)(PyArrayObject *input, PyArrayObject **res, PA
...
@@ -33,12 +33,17 @@ int APPLY_SPECIFIC(cpu_dimshuffle)(PyArrayObject *input, PyArrayObject **res, PA
npy_intp
original_size
=
PyArray_SIZE
(
input
);
npy_intp
original_size
=
PyArray_SIZE
(
input
);
npy_intp
new_size
=
1
;
npy_intp
new_size
=
1
;
for
(
npy_intp
i
=
0
;
i
<
nd_out
;
++
i
)
{
for
(
npy_intp
i
=
0
;
i
<
nd_out
;
++
i
)
{
// We set the strides of length 1 dimensions to PyArray_ITEMSIZE(input).
// The value is arbitrary, because there is never a next element.
// np.expand_dims(x, 0) and x[None] do different things here.
// I would prefer zero, but there are some poorly implemented BLAS operations
// That don't handle zero strides correctly. At least they won't fail because of DimShuffle.
if
(
new_order
[
i
]
!=
-
1
)
{
if
(
new_order
[
i
]
!=
-
1
)
{
dimensions
[
i
]
=
PyArray_DIMS
(
input
)[
new_order
[
i
]];
dimensions
[
i
]
=
PyArray_DIMS
(
input
)[
new_order
[
i
]];
strides
[
i
]
=
PyArray_DIMS
(
input
)[
new_order
[
i
]]
==
1
?
0
:
PyArray_STRIDES
(
input
)[
new_order
[
i
]];
strides
[
i
]
=
PyArray_DIMS
(
input
)[
new_order
[
i
]]
==
1
?
PyArray_ITEMSIZE
(
input
)
:
PyArray_STRIDES
(
input
)[
new_order
[
i
]];
}
else
{
}
else
{
dimensions
[
i
]
=
1
;
dimensions
[
i
]
=
1
;
strides
[
i
]
=
0
;
strides
[
i
]
=
PyArray_ITEMSIZE
(
input
)
;
}
}
new_size
*=
dimensions
[
i
];
new_size
*=
dimensions
[
i
];
}
}
...
...
tests/tensor/test_elemwise.py
浏览文件 @
89d5366c
...
@@ -185,14 +185,13 @@ class TestDimShuffle(unittest_tools.InferShapeTester):
...
@@ -185,14 +185,13 @@ class TestDimShuffle(unittest_tools.InferShapeTester):
# as the broadcasted value; that way, we'll be able to tell that we're getting
# as the broadcasted value; that way, we'll be able to tell that we're getting
# junk data from a poorly constructed array view.
# junk data from a poorly constructed array view.
x_val
=
np
.
broadcast_to
(
2039
,
(
5000
,))
x_val
=
np
.
broadcast_to
(
2039
,
(
5000
,))
expected_x_val
=
x_val
[
None
]
for
i
in
range
(
1
):
for
i
in
range
(
1
):
inputs
[
0
]
.
storage
[
0
]
=
x_val
inputs
[
0
]
.
storage
[
0
]
=
x_val
thunk
()
thunk
()
# Make sure it's a view of the original data
# Make sure it's a view of the original data
assert
np
.
shares_memory
(
x_val
,
outputs
[
0
]
.
storage
[
0
])
assert
np
.
shares_memory
(
x_val
,
outputs
[
0
]
.
storage
[
0
])
# Confirm the right strides
# Confirm the right strides
assert
outputs
[
0
]
.
storage
[
0
]
.
strides
==
expected_x_val
.
strides
assert
outputs
[
0
]
.
storage
[
0
]
.
strides
[
-
1
]
==
0
# Confirm the broadcasted value in the output
# Confirm the broadcasted value in the output
assert
np
.
array_equiv
(
outputs
[
0
]
.
storage
[
0
],
2039
)
assert
np
.
array_equiv
(
outputs
[
0
]
.
storage
[
0
],
2039
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论