Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8f7c7e9d
提交
8f7c7e9d
authored
5月 17, 2014
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix deepcopy of shared variable due to a Numpy problem.
The fix is taken from debugmode.
上级
01f54ac2
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
38 行增加
和
1 行删除
+38
-1
debugmode.py
theano/compile/debugmode.py
+1
-0
link.py
theano/gof/link.py
+21
-1
test_link.py
theano/gof/tests/test_link.py
+16
-0
没有找到文件。
theano/compile/debugmode.py
浏览文件 @
8f7c7e9d
...
@@ -847,6 +847,7 @@ def _lessbroken_deepcopy(a):
...
@@ -847,6 +847,7 @@ def _lessbroken_deepcopy(a):
called on a 0-d array will return a numpy scalar, not an array.
called on a 0-d array will return a numpy scalar, not an array.
"""
"""
# this exists because copy.deepcopy on numpy arrays is broken
# this exists because copy.deepcopy on numpy arrays is broken
# This logic is also in link.py
if
type
(
a
)
in
(
numpy
.
ndarray
,
numpy
.
memmap
):
if
type
(
a
)
in
(
numpy
.
ndarray
,
numpy
.
memmap
):
rval
=
a
.
copy
()
rval
=
a
.
copy
()
else
:
else
:
...
...
theano/gof/link.py
浏览文件 @
8f7c7e9d
"""WRITEME"""
"""WRITEME"""
from
copy
import
copy
from
copy
import
copy
,
deepcopy
import
StringIO
import
StringIO
import
sys
import
sys
import
traceback
import
traceback
import
numpy
import
theano
import
theano
from
theano.gof
import
utils
from
theano.gof
import
utils
from
theano.gof
import
graph
from
theano.gof
import
graph
...
@@ -318,6 +320,24 @@ class Container(object):
...
@@ -318,6 +320,24 @@ class Container(object):
def
__repr__
(
self
):
def
__repr__
(
self
):
return
"<"
+
repr
(
self
.
storage
[
0
])
+
">"
return
"<"
+
repr
(
self
.
storage
[
0
])
+
">"
def
__deepcopy__
(
self
,
memo
):
# this exists because copy.deepcopy on numpy arrays is broken
a
=
self
.
storage
[
0
]
if
type
(
a
)
in
(
numpy
.
ndarray
,
numpy
.
memmap
):
a
=
a
.
copy
()
else
:
a
=
copy
.
deepcopy
(
a
)
r
=
type
(
self
)(
deepcopy
(
self
.
type
,
memo
),
[
a
],
deepcopy
(
self
.
readonly
),
deepcopy
(
self
.
strict
),
deepcopy
(
self
.
allow_downcast
),
deepcopy
(
self
.
name
,
memo
),
)
return
r
def
map_storage
(
fgraph
,
order
,
input_storage
,
output_storage
):
def
map_storage
(
fgraph
,
order
,
input_storage
,
output_storage
):
"""Ensure there is storage (a length-1 list) for inputs, outputs, and interior nodes.
"""Ensure there is storage (a length-1 list) for inputs, outputs, and interior nodes.
...
...
theano/gof/tests/test_link.py
浏览文件 @
8f7c7e9d
from
copy
import
deepcopy
import
unittest
import
unittest
import
numpy
from
theano.gof
import
graph
from
theano.gof
import
graph
from
theano.gof.graph
import
Variable
,
Apply
,
Constant
from
theano.gof.graph
import
Variable
,
Apply
,
Constant
from
theano.gof.type
import
Type
from
theano.gof.type
import
Type
...
@@ -9,6 +12,7 @@ from theano.gof import fg
...
@@ -9,6 +12,7 @@ from theano.gof import fg
from
theano.gof.link
import
*
from
theano.gof.link
import
*
from
theano.compat
import
cmp
from
theano.compat
import
cmp
def
as_variable
(
x
):
def
as_variable
(
x
):
assert
isinstance
(
x
,
Variable
)
assert
isinstance
(
x
,
Variable
)
return
x
return
x
...
@@ -178,3 +182,15 @@ def test_sort_schedule_fn():
...
@@ -178,3 +182,15 @@ def test_sort_schedule_fn():
for
a
,
b
in
zip
(
nodes
[:
-
1
],
nodes
[
1
:]):
for
a
,
b
in
zip
(
nodes
[:
-
1
],
nodes
[
1
:]):
if
not
depends
((
b
,
a
)):
if
not
depends
((
b
,
a
)):
assert
str
(
a
)
<
str
(
b
)
assert
str
(
a
)
<
str
(
b
)
def
test_container_deepcopy
():
"""
This is a test to a work around a NumPy.
"""
t
=
theano
.
tensor
.
scalar
()
v
=
numpy
.
asarray
(
0.
)
c
=
Container
(
t
,
[
v
])
assert
isinstance
(
c
.
storage
[
0
],
numpy
.
ndarray
)
deepcopy
(
c
)
assert
isinstance
(
c
.
storage
[
0
],
numpy
.
ndarray
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论