Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d1315406
提交
d1315406
authored
7月 19, 2023
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
8月 25, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix segfault bug in Alloc C implementation
上级
81e7dff6
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
17 行增加
和
3 行删除
+17
-3
basic.py
pytensor/tensor/basic.py
+2
-2
test_basic.py
tests/tensor/test_basic.py
+15
-1
没有找到文件。
pytensor/tensor/basic.py
浏览文件 @
d1315406
...
...
@@ -1506,7 +1506,7 @@ class Alloc(COp):
if (need_new_out)
{{
Py_XDECREF({zz});
{zz} = (PyArrayObject*) PyArray_SimpleNew({ndim}, shape, PyArray_TYPE(
(PyArrayObject*) py_
{vv}));
{zz} = (PyArrayObject*) PyArray_SimpleNew({ndim}, shape, PyArray_TYPE({vv}));
if (!{zz})
{{
PyErr_SetString(PyExc_MemoryError, "alloc failed");
...
...
@@ -1522,7 +1522,7 @@ class Alloc(COp):
return
code
def
c_code_cache_version
(
self
):
return
(
2
,)
return
(
3
,)
def
infer_shape
(
self
,
fgraph
,
node
,
input_shapes
):
return
[
node
.
inputs
[
1
:]]
...
...
tests/tensor/test_basic.py
浏览文件 @
d1315406
...
...
@@ -14,7 +14,7 @@ from pytensor.compile.io import In, Out
from
pytensor.compile.mode
import
Mode
,
get_default_mode
from
pytensor.compile.ops
import
DeepCopyOp
from
pytensor.gradient
import
grad
,
hessian
from
pytensor.graph.basic
import
Apply
from
pytensor.graph.basic
import
Apply
,
equal_computations
from
pytensor.graph.op
import
Op
from
pytensor.graph.replace
import
clone_replace
from
pytensor.misc.safe_asarray
import
_asarray
...
...
@@ -719,6 +719,7 @@ class TestAlloc:
shared
=
staticmethod
(
pytensor
.
shared
)
allocs
=
[
Alloc
()]
*
3
def
setup_method
(
self
):
self
.
rng
=
np
.
random
.
default_rng
(
seed
=
utt
.
fetch_seed
())
...
...
@@ -850,6 +851,19 @@ class TestAlloc:
with
pytest
.
raises
(
ValueError
,
match
=
msg
):
at
.
alloc
(
x
,
3
,
1
,
6
)
def
test_alloc_of_view_linker
(
self
):
"""Check we can allocate a new array properly in the C linker when input is a view."""
x_v
=
vector
(
"x"
,
shape
=
(
None
,))
dim_len
=
scalar
(
"dim_len"
,
dtype
=
int
)
out
=
alloc
(
specify_shape
(
x_v
,
(
1
,)),
5
,
dim_len
)
f
=
pytensor
.
function
([
x_v
,
dim_len
],
out
,
mode
=
Mode
(
"c"
))
assert
equal_computations
(
f
.
maker
.
fgraph
.
outputs
,
[
alloc
(
specify_shape
(
x_v
,
(
1
,)),
5
,
dim_len
)]
)
np
.
testing
.
assert_array_equal
(
f
(
x
=
np
.
zeros
((
1
,)),
dim_len
=
3
),
np
.
zeros
((
5
,
3
)))
def
test_infer_shape
():
with
pytest
.
raises
(
TypeError
,
match
=
"^Shapes must be scalar integers.*"
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论