Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b7c58547
提交
b7c58547
authored
5月 21, 2014
作者:
abergeron
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1864 from nouiz/fix_numpy_deepcopy
Fix deepcopy of shared variable due to a Numpy problem.
上级
b178561e
de485e77
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
54 行增加
和
9 行删除
+54
-9
debugmode.py
theano/compile/debugmode.py
+1
-0
link.py
theano/gof/link.py
+25
-1
test_link.py
theano/gof/tests/test_link.py
+28
-8
没有找到文件。
theano/compile/debugmode.py
浏览文件 @
b7c58547
...
@@ -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
浏览文件 @
b7c58547
"""WRITEME"""
"""WRITEME"""
from
copy
import
copy
from
copy
import
copy
,
deepcopy
import
StringIO
import
StringIO
import
sys
import
sys
import
traceback
import
traceback
...
@@ -318,6 +318,30 @@ class Container(object):
...
@@ -318,6 +318,30 @@ class Container(object):
def
__repr__
(
self
):
def
__repr__
(
self
):
return
"<"
+
repr
(
self
.
storage
[
0
])
+
">"
return
"<"
+
repr
(
self
.
storage
[
0
])
+
">"
def
__deepcopy__
(
self
,
memo
):
data_was_in_memo
=
id
(
self
.
storage
[
0
])
in
memo
r
=
type
(
self
)(
deepcopy
(
self
.
type
,
memo
=
memo
),
deepcopy
(
self
.
storage
,
memo
=
memo
),
deepcopy
(
self
.
readonly
,
memo
=
memo
),
deepcopy
(
self
.
strict
,
memo
=
memo
),
deepcopy
(
self
.
allow_downcast
,
memo
=
memo
),
deepcopy
(
self
.
name
,
memo
=
memo
),
)
# Work around NumPy deepcopy of ndarray with 0 dimention that
# don't return an ndarray.
if
(
r
.
storage
[
0
]
is
not
None
and
not
self
.
type
.
is_valid_value
(
r
.
storage
[
0
])):
assert
not
data_was_in_memo
assert
self
.
type
.
is_valid_value
(
self
.
storage
[
0
])
# This should also work for read only container.
r
.
storage
[
0
]
=
self
.
type
.
filter
(
r
.
storage
[
0
],
strict
=
False
,
allow_downcast
=
False
)
memo
[
id
(
self
.
storage
[
0
])]
=
r
.
storage
[
0
]
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
浏览文件 @
b7c58547
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
...
@@ -110,7 +114,8 @@ class TestPerformLinker(unittest.TestCase):
...
@@ -110,7 +114,8 @@ class TestPerformLinker(unittest.TestCase):
x
,
y
,
z
=
inputs
()
x
,
y
,
z
=
inputs
()
a
,
d
=
add
(
x
,
y
),
div
(
x
,
y
)
a
,
d
=
add
(
x
,
y
),
div
(
x
,
y
)
e
=
mul
(
a
,
d
)
e
=
mul
(
a
,
d
)
fn
=
perform_linker
(
FunctionGraph
(
*
graph
.
clone
([
x
,
y
,
a
],
[
e
])))
.
make_function
()
fn
=
perform_linker
(
FunctionGraph
(
*
graph
.
clone
([
x
,
y
,
a
],
[
e
])))
.
make_function
()
assert
fn
(
1.0
,
2.0
,
9.0
)
==
4.5
assert
fn
(
1.0
,
2.0
,
9.0
)
==
4.5
def
test_skiphole
(
self
):
def
test_skiphole
(
self
):
...
@@ -118,7 +123,8 @@ class TestPerformLinker(unittest.TestCase):
...
@@ -118,7 +123,8 @@ class TestPerformLinker(unittest.TestCase):
a
=
add
(
x
,
y
)
a
=
add
(
x
,
y
)
r
=
raise_err
(
a
)
r
=
raise_err
(
a
)
e
=
add
(
r
,
a
)
e
=
add
(
r
,
a
)
fn
=
perform_linker
(
FunctionGraph
(
*
graph
.
clone
([
x
,
y
,
r
],
[
e
])))
.
make_function
()
fn
=
perform_linker
(
FunctionGraph
(
*
graph
.
clone
([
x
,
y
,
r
],
[
e
])))
.
make_function
()
assert
fn
(
1.0
,
2.0
,
4.5
)
==
7.5
assert
fn
(
1.0
,
2.0
,
4.5
)
==
7.5
...
@@ -137,8 +143,8 @@ class TestWrapLinker(unittest.TestCase):
...
@@ -137,8 +143,8 @@ class TestWrapLinker(unittest.TestCase):
x
,
y
,
z
=
inputs
()
x
,
y
,
z
=
inputs
()
e
=
mul
(
add
(
x
,
y
),
div
(
x
,
y
))
e
=
mul
(
add
(
x
,
y
),
div
(
x
,
y
))
fn
,
i
,
o
=
wrap_linker
(
fn
,
i
,
o
=
wrap_linker
(
FunctionGraph
([
x
,
y
,
z
],
[
e
]),
FunctionGraph
([
x
,
y
,
z
],
[
e
]),
[
PerformLinker
(
allow_gc
=
False
)],
wrap
)
.
make_thunk
()
[
PerformLinker
(
allow_gc
=
False
)],
wrap
)
.
make_thunk
()
i
[
0
]
.
data
=
1
i
[
0
]
.
data
=
1
i
[
1
]
.
data
=
2
i
[
1
]
.
data
=
2
fn
()
fn
()
...
@@ -155,20 +161,21 @@ class TestWrapLinker(unittest.TestCase):
...
@@ -155,20 +161,21 @@ class TestWrapLinker(unittest.TestCase):
x
,
y
,
z
=
inputs
()
x
,
y
,
z
=
inputs
()
e
=
mul
(
add
(
x
,
y
),
div
(
x
,
y
))
e
=
mul
(
add
(
x
,
y
),
div
(
x
,
y
))
fn
,
i
,
o
=
wrap_linker
(
fn
,
i
,
o
=
wrap_linker
(
FunctionGraph
([
x
,
y
,
z
],
[
e
]),
FunctionGraph
([
x
,
y
,
z
],
[
e
]),
[
PerformLinker
(
allow_gc
=
False
)],
wrap
)
.
make_thunk
()
[
PerformLinker
(
allow_gc
=
False
)],
wrap
)
.
make_thunk
()
i
[
0
]
.
data
=
1
i
[
0
]
.
data
=
1
i
[
1
]
.
data
=
2
i
[
1
]
.
data
=
2
fn
()
fn
()
assert
nodes
==
[
div
,
add
,
mul
]
assert
nodes
==
[
div
,
add
,
mul
]
assert
o
[
0
]
.
data
==
1.5
assert
o
[
0
]
.
data
==
1.5
def
test_sort_schedule_fn
():
def
test_sort_schedule_fn
():
import
theano
import
theano
from
theano.gof.sched
import
sort_schedule_fn
,
make_depends
from
theano.gof.sched
import
sort_schedule_fn
,
make_depends
x
=
theano
.
tensor
.
matrix
(
'x'
)
x
=
theano
.
tensor
.
matrix
(
'x'
)
y
=
theano
.
tensor
.
dot
(
x
[:
5
]
*
2
,
x
.
T
+
1
)
.
T
y
=
theano
.
tensor
.
dot
(
x
[:
5
]
*
2
,
x
.
T
+
1
)
.
T
str_cmp
=
lambda
a
,
b
:
cmp
(
str
(
a
),
str
(
b
))
# lexicographical sort
str_cmp
=
lambda
a
,
b
:
cmp
(
str
(
a
),
str
(
b
))
# lexicographical sort
linker
=
theano
.
OpWiseCLinker
(
schedule
=
sort_schedule_fn
(
str_cmp
))
linker
=
theano
.
OpWiseCLinker
(
schedule
=
sort_schedule_fn
(
str_cmp
))
mode
=
theano
.
Mode
(
linker
=
linker
)
mode
=
theano
.
Mode
(
linker
=
linker
)
f
=
theano
.
function
((
x
,),
(
y
,),
mode
=
mode
)
f
=
theano
.
function
((
x
,),
(
y
,),
mode
=
mode
)
...
@@ -176,5 +183,18 @@ def test_sort_schedule_fn():
...
@@ -176,5 +183,18 @@ def test_sort_schedule_fn():
nodes
=
f
.
maker
.
linker
.
make_all
()[
-
1
]
nodes
=
f
.
maker
.
linker
.
make_all
()[
-
1
]
depends
=
make_depends
()
depends
=
make_depends
()
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 bug.
"""
t
=
theano
.
tensor
.
scalar
()
v
=
numpy
.
asarray
(
0.
)
for
readonly
in
[
True
,
False
]:
c
=
Container
(
t
,
[
v
],
readonly
=
readonly
)
assert
isinstance
(
c
.
storage
[
0
],
numpy
.
ndarray
)
d
=
deepcopy
(
c
)
assert
isinstance
(
d
.
storage
[
0
],
numpy
.
ndarray
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论