Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
466cdaa8
提交
466cdaa8
authored
2月 03, 2017
作者:
Frédéric Bastien
提交者:
GitHub
2月 03, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5454 from bscellier/import_numpy_gof
Import numpy gof
上级
4e29b2f7
7bb08f51
显示空白字符变更
内嵌
并排
正在显示
18 个修改的文件
包含
103 行增加
和
105 行删除
+103
-105
cc.py
theano/gof/cc.py
+2
-2
cmodule.py
theano/gof/cmodule.py
+2
-2
compiledir.py
theano/gof/compiledir.py
+2
-2
graph.py
theano/gof/graph.py
+2
-2
link.py
theano/gof/link.py
+3
-3
op.py
theano/gof/op.py
+2
-2
opt.py
theano/gof/opt.py
+2
-3
test_cc.py
theano/gof/tests/test_cc.py
+14
-14
test_cmodule.py
theano/gof/tests/test_cmodule.py
+4
-4
test_compute_test_value.py
theano/gof/tests/test_compute_test_value.py
+27
-27
test_graph.py
theano/gof/tests/test_graph.py
+2
-2
test_graph_opt_caching.py
theano/gof/tests/test_graph_opt_caching.py
+7
-7
test_lazy.py
theano/gof/tests/test_lazy.py
+4
-4
test_link.py
theano/gof/tests/test_link.py
+5
-5
test_op.py
theano/gof/tests/test_op.py
+14
-14
test_types.py
theano/gof/tests/test_types.py
+2
-2
test_vm.py
theano/gof/tests/test_vm.py
+6
-7
utils.py
theano/gof/utils.py
+3
-3
没有找到文件。
theano/gof/cc.py
浏览文件 @
466cdaa8
...
@@ -11,7 +11,7 @@ import os
...
@@ -11,7 +11,7 @@ import os
import
sys
import
sys
import
logging
import
logging
import
numpy
import
numpy
as
np
import
theano
import
theano
from
theano
import
config
from
theano
import
config
...
@@ -1347,7 +1347,7 @@ class CLinker(link.Linker):
...
@@ -1347,7 +1347,7 @@ class CLinker(link.Linker):
# We must always add the numpy ABI version here as
# We must always add the numpy ABI version here as
# DynamicModule always add the include <numpy/arrayobject.h>
# DynamicModule always add the include <numpy/arrayobject.h>
sig
.
append
(
'NPY_ABI_VERSION=0x
%
X'
%
sig
.
append
(
'NPY_ABI_VERSION=0x
%
X'
%
n
umpy
.
core
.
multiarray
.
_get_ndarray_c_version
())
n
p
.
core
.
multiarray
.
_get_ndarray_c_version
())
if
c_compiler
:
if
c_compiler
:
sig
.
append
(
'c_compiler_str='
+
c_compiler
.
version_str
())
sig
.
append
(
'c_compiler_str='
+
c_compiler
.
version_str
())
...
...
theano/gof/cmodule.py
浏览文件 @
466cdaa8
...
@@ -20,7 +20,7 @@ import platform
...
@@ -20,7 +20,7 @@ import platform
import
distutils.sysconfig
import
distutils.sysconfig
import
warnings
import
warnings
import
numpy
.distutils
# TODO: TensorType should handle thi
s
import
numpy
as
np
# TODO: TensorType should handle nunpy.distutil
s
import
theano
import
theano
from
theano.compat
import
PY3
,
decode
,
decode_iter
from
theano.compat
import
PY3
,
decode
,
decode_iter
...
@@ -1578,7 +1578,7 @@ def get_gcc_shared_library_arg():
...
@@ -1578,7 +1578,7 @@ def get_gcc_shared_library_arg():
def
std_include_dirs
():
def
std_include_dirs
():
numpy_inc_dirs
=
n
umpy
.
distutils
.
misc_util
.
get_numpy_include_dirs
()
numpy_inc_dirs
=
n
p
.
distutils
.
misc_util
.
get_numpy_include_dirs
()
py_inc
=
distutils
.
sysconfig
.
get_python_inc
()
py_inc
=
distutils
.
sysconfig
.
get_python_inc
()
py_plat_spec_inc
=
distutils
.
sysconfig
.
get_python_inc
(
plat_specific
=
True
)
py_plat_spec_inc
=
distutils
.
sysconfig
.
get_python_inc
(
plat_specific
=
True
)
python_inc_dirs
=
([
py_inc
]
if
py_inc
==
py_plat_spec_inc
python_inc_dirs
=
([
py_inc
]
if
py_inc
==
py_plat_spec_inc
...
...
theano/gof/compiledir.py
浏览文件 @
466cdaa8
...
@@ -4,7 +4,7 @@ import logging
...
@@ -4,7 +4,7 @@ import logging
import
os
import
os
import
shutil
import
shutil
import
numpy
import
numpy
as
np
import
theano
import
theano
from
six
import
string_types
,
iteritems
from
six
import
string_types
,
iteritems
...
@@ -42,7 +42,7 @@ def cleanup():
...
@@ -42,7 +42,7 @@ def cleanup():
have_npy_abi_version
=
False
have_npy_abi_version
=
False
have_c_compiler
=
False
have_c_compiler
=
False
for
obj
in
flatten
(
key
):
for
obj
in
flatten
(
key
):
if
isinstance
(
obj
,
n
umpy
.
ndarray
):
if
isinstance
(
obj
,
n
p
.
ndarray
):
# Reuse have_npy_abi_version to
# Reuse have_npy_abi_version to
# force the removing of key
# force the removing of key
have_npy_abi_version
=
False
have_npy_abi_version
=
False
...
...
theano/gof/graph.py
浏览文件 @
466cdaa8
...
@@ -481,12 +481,12 @@ class Variable(Node):
...
@@ -481,12 +481,12 @@ class Variable(Node):
Examples
Examples
--------
--------
>>> import numpy
>>> import numpy
as np
>>> import theano.tensor as T
>>> import theano.tensor as T
>>> x = T.dscalar('x')
>>> x = T.dscalar('x')
>>> y = T.dscalar('y')
>>> y = T.dscalar('y')
>>> z = x + y
>>> z = x + y
>>> n
umpy
.allclose(z.eval({x : 16.3, y : 12.1}), 28.4)
>>> n
p
.allclose(z.eval({x : 16.3, y : 12.1}), 28.4)
True
True
We passed :func:`eval` a dictionary mapping symbolic theano
We passed :func:`eval` a dictionary mapping symbolic theano
...
...
theano/gof/link.py
浏览文件 @
466cdaa8
...
@@ -7,7 +7,7 @@ from copy import copy, deepcopy
...
@@ -7,7 +7,7 @@ from copy import copy, deepcopy
from
sys
import
getsizeof
from
sys
import
getsizeof
import
sys
import
sys
import
traceback
import
traceback
import
numpy
import
numpy
as
np
import
theano
import
theano
from
theano.compat
import
izip
from
theano.compat
import
izip
...
@@ -236,11 +236,11 @@ def raise_with_op(node, thunk=None, exc_info=None, storage_map=None):
...
@@ -236,11 +236,11 @@ def raise_with_op(node, thunk=None, exc_info=None, storage_map=None):
# storage_map_item[3]: bytes
# storage_map_item[3]: bytes
if
hasattr
(
storage_map
[
k
][
0
],
'dtype'
):
if
hasattr
(
storage_map
[
k
][
0
],
'dtype'
):
dtype
=
storage_map
[
k
][
0
]
.
dtype
dtype
=
storage_map
[
k
][
0
]
.
dtype
storage_map_item
.
append
(
n
umpy
.
dtype
(
dtype
)
.
itemsize
)
storage_map_item
.
append
(
n
p
.
dtype
(
dtype
)
.
itemsize
)
if
shapeinfo
is
None
:
if
shapeinfo
is
None
:
storage_map_item
.
append
(
-
1
)
storage_map_item
.
append
(
-
1
)
else
:
else
:
sz
=
n
umpy
.
dtype
(
dtype
)
.
itemsize
*
numpy
.
prod
(
shapeinfo
)
sz
=
n
p
.
dtype
(
dtype
)
.
itemsize
*
np
.
prod
(
shapeinfo
)
storage_map_item
.
append
(
sz
)
storage_map_item
.
append
(
sz
)
total_size
+=
sz
total_size
+=
sz
if
not
k
.
owner
:
if
not
k
.
owner
:
...
...
theano/gof/op.py
浏览文件 @
466cdaa8
...
@@ -9,7 +9,7 @@ from __future__ import absolute_import, print_function, division
...
@@ -9,7 +9,7 @@ from __future__ import absolute_import, print_function, division
import
inspect
import
inspect
import
logging
import
logging
import
numpy
import
numpy
as
np
import
os
import
os
import
re
import
re
import
sys
import
sys
...
@@ -1430,7 +1430,7 @@ class COp(Op):
...
@@ -1430,7 +1430,7 @@ class COp(Op):
(
macro_name
,
macro_value
))
(
macro_name
,
macro_value
))
undef_macros
.
append
(
undef_template
%
macro_name
)
undef_macros
.
append
(
undef_template
%
macro_name
)
d
=
n
umpy
.
dtype
(
v
.
dtype
)
d
=
n
p
.
dtype
(
v
.
dtype
)
macro_name
=
"TYPENUM_"
+
vname
macro_name
=
"TYPENUM_"
+
vname
macro_value
=
d
.
num
macro_value
=
d
.
num
...
...
theano/gof/opt.py
浏览文件 @
466cdaa8
...
@@ -15,7 +15,7 @@ import time
...
@@ -15,7 +15,7 @@ import time
import
warnings
import
warnings
import
traceback
import
traceback
import
numpy
import
numpy
as
np
import
theano
import
theano
from
theano
import
config
from
theano
import
config
...
@@ -1695,8 +1695,7 @@ class PatternSub(LocalOptimizer):
...
@@ -1695,8 +1695,7 @@ class PatternSub(LocalOptimizer):
u
=
u
.
merge
(
expr
,
v
)
u
=
u
.
merge
(
expr
,
v
)
elif
(
isinstance
(
pattern
,
(
integer_types
,
float
))
and
elif
(
isinstance
(
pattern
,
(
integer_types
,
float
))
and
isinstance
(
expr
,
graph
.
Constant
)):
isinstance
(
expr
,
graph
.
Constant
)):
if
numpy
.
all
(
if
np
.
all
(
theano
.
tensor
.
constant
(
pattern
)
.
value
==
expr
.
value
):
theano
.
tensor
.
constant
(
pattern
)
.
value
==
expr
.
value
):
return
u
return
u
else
:
else
:
return
retry_with_equiv
()
return
retry_with_equiv
()
...
...
theano/gof/tests/test_cc.py
浏览文件 @
466cdaa8
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
import
numpy
import
numpy
as
np
import
theano
import
theano
from
theano.gof.link
import
PerformLinker
from
theano.gof.link
import
PerformLinker
...
@@ -211,16 +211,16 @@ def test_clinker_literal_cache():
...
@@ -211,16 +211,16 @@ def test_clinker_literal_cache():
A
=
theano
.
tensor
.
matrix
()
A
=
theano
.
tensor
.
matrix
()
input1
=
theano
.
tensor
.
vector
()
input1
=
theano
.
tensor
.
vector
()
normal_svd
=
n
umpy
.
array
([[
5.936276e+01
,
-
4.664007e-07
,
-
2.56265e-06
],
normal_svd
=
n
p
.
array
([[
5.936276e+01
,
-
4.664007e-07
,
-
2.56265e-06
],
[
-
4.664007e-07
,
9.468691e-01
,
-
3.18862e-02
],
[
-
4.664007e-07
,
9.468691e-01
,
-
3.18862e-02
],
[
-
2.562651e-06
,
-
3.188625e-02
,
1.05226e+00
]],
[
-
2.562651e-06
,
-
3.188625e-02
,
1.05226e+00
]],
dtype
=
theano
.
config
.
floatX
)
dtype
=
theano
.
config
.
floatX
)
orientationi
=
n
umpy
.
array
([
59.36276866
,
1.06116353
,
0.93797339
],
orientationi
=
n
p
.
array
([
59.36276866
,
1.06116353
,
0.93797339
],
dtype
=
theano
.
config
.
floatX
)
dtype
=
theano
.
config
.
floatX
)
for
out1
in
[
A
-
input1
[
0
]
*
n
umpy
.
identity
(
3
),
for
out1
in
[
A
-
input1
[
0
]
*
n
p
.
identity
(
3
),
input1
[
0
]
*
n
umpy
.
identity
(
3
)]:
input1
[
0
]
*
n
p
.
identity
(
3
)]:
benchmark
=
theano
.
function
(
benchmark
=
theano
.
function
(
inputs
=
[
A
,
input1
],
inputs
=
[
A
,
input1
],
outputs
=
[
out1
],
outputs
=
[
out1
],
...
@@ -421,7 +421,7 @@ def test_shared_input_output():
...
@@ -421,7 +421,7 @@ def test_shared_input_output():
g0
=
g
(
0
)
g0
=
g
(
0
)
assert
f0
==
g0
==
5
,
(
f0
,
g0
)
assert
f0
==
g0
==
5
,
(
f0
,
g0
)
vstate
=
theano
.
shared
(
n
umpy
.
zeros
(
3
,
dtype
=
'int32'
))
vstate
=
theano
.
shared
(
n
p
.
zeros
(
3
,
dtype
=
'int32'
))
vstate
.
name
=
'vstate'
vstate
.
name
=
'vstate'
fv
=
theano
.
function
([
inc
],
vstate
,
updates
=
[(
vstate
,
vstate
+
inc
)],
fv
=
theano
.
function
([
inc
],
vstate
,
updates
=
[(
vstate
,
vstate
+
inc
)],
mode
=
mode
)
mode
=
mode
)
...
@@ -430,21 +430,21 @@ def test_shared_input_output():
...
@@ -430,21 +430,21 @@ def test_shared_input_output():
# Initial value
# Initial value
fv0
=
fv
(
0
)
fv0
=
fv
(
0
)
gv0
=
gv
(
0
)
gv0
=
gv
(
0
)
assert
n
umpy
.
all
(
fv0
==
0
),
fv0
assert
n
p
.
all
(
fv0
==
0
),
fv0
assert
n
umpy
.
all
(
gv0
==
0
),
gv0
assert
n
p
.
all
(
gv0
==
0
),
gv0
# Increment state via f, returns the previous value.
# Increment state via f, returns the previous value.
fv2
=
fv
(
2
)
fv2
=
fv
(
2
)
assert
n
umpy
.
all
(
fv2
==
fv0
),
(
fv2
,
fv0
)
assert
n
p
.
all
(
fv2
==
fv0
),
(
fv2
,
fv0
)
fv0
=
fv
(
0
)
fv0
=
fv
(
0
)
gv0
=
gv
(
0
)
gv0
=
gv
(
0
)
assert
n
umpy
.
all
(
fv0
==
2
),
fv0
assert
n
p
.
all
(
fv0
==
2
),
fv0
assert
n
umpy
.
all
(
gv0
==
2
),
gv0
assert
n
p
.
all
(
gv0
==
2
),
gv0
# Increment state via g, returns the previous value
# Increment state via g, returns the previous value
gv3
=
gv
(
3
)
gv3
=
gv
(
3
)
assert
n
umpy
.
all
(
gv3
==
gv0
),
(
gv3
,
gv0
)
assert
n
p
.
all
(
gv3
==
gv0
),
(
gv3
,
gv0
)
fv0
=
fv
(
0
)
fv0
=
fv
(
0
)
gv0
=
gv
(
0
)
gv0
=
gv
(
0
)
assert
n
umpy
.
all
(
fv0
==
5
),
fv0
assert
n
p
.
all
(
fv0
==
5
),
fv0
assert
n
umpy
.
all
(
gv0
==
5
),
gv0
assert
n
p
.
all
(
gv0
==
5
),
gv0
theano/gof/tests/test_cmodule.py
浏览文件 @
466cdaa8
...
@@ -6,7 +6,7 @@ deterministic based on the input type and the op.
...
@@ -6,7 +6,7 @@ deterministic based on the input type and the op.
"""
"""
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
numpy
import
numpy
as
np
import
theano
import
theano
from
theano.gof.cmodule
import
GCC_compiler
from
theano.gof.cmodule
import
GCC_compiler
...
@@ -26,7 +26,7 @@ class MyOp(theano.compile.ops.DeepCopyOp):
...
@@ -26,7 +26,7 @@ class MyOp(theano.compile.ops.DeepCopyOp):
itype
=
node
.
inputs
[
0
]
.
type
.
__class__
itype
=
node
.
inputs
[
0
]
.
type
.
__class__
if
itype
in
self
.
c_code_and_version
:
if
itype
in
self
.
c_code_and_version
:
code
,
version
=
self
.
c_code_and_version
[
itype
]
code
,
version
=
self
.
c_code_and_version
[
itype
]
rand
=
n
umpy
.
random
.
rand
()
rand
=
n
p
.
random
.
rand
()
return
(
"""printf("
%(rand)
s
\\
n");"""
+
code
)
%
locals
()
return
(
"""printf("
%(rand)
s
\\
n");"""
+
code
)
%
locals
()
# Else, no C code
# Else, no C code
return
super
(
theano
.
compile
.
ops
.
DeepCopyOp
,
self
)
.
c_code
(
return
super
(
theano
.
compile
.
ops
.
DeepCopyOp
,
self
)
.
c_code
(
...
@@ -47,7 +47,7 @@ def test_inter_process_cache():
...
@@ -47,7 +47,7 @@ def test_inter_process_cache():
x
,
y
=
theano
.
tensor
.
dvectors
(
'xy'
)
x
,
y
=
theano
.
tensor
.
dvectors
(
'xy'
)
f
=
theano
.
function
([
x
,
y
],
[
MyOp
()(
x
),
MyOp
()(
y
)])
f
=
theano
.
function
([
x
,
y
],
[
MyOp
()(
x
),
MyOp
()(
y
)])
f
(
n
umpy
.
arange
(
60
),
numpy
.
arange
(
60
))
f
(
n
p
.
arange
(
60
),
np
.
arange
(
60
))
if
theano
.
config
.
mode
==
'FAST_COMPILE'
or
theano
.
config
.
cxx
==
""
:
if
theano
.
config
.
mode
==
'FAST_COMPILE'
or
theano
.
config
.
cxx
==
""
:
assert
MyOp
.
nb_called
==
0
assert
MyOp
.
nb_called
==
0
else
:
else
:
...
@@ -56,7 +56,7 @@ def test_inter_process_cache():
...
@@ -56,7 +56,7 @@ def test_inter_process_cache():
# What if we compile a new function with new variables?
# What if we compile a new function with new variables?
x
,
y
=
theano
.
tensor
.
dvectors
(
'xy'
)
x
,
y
=
theano
.
tensor
.
dvectors
(
'xy'
)
f
=
theano
.
function
([
x
,
y
],
[
MyOp
()(
x
),
MyOp
()(
y
)])
f
=
theano
.
function
([
x
,
y
],
[
MyOp
()(
x
),
MyOp
()(
y
)])
f
(
n
umpy
.
arange
(
60
),
numpy
.
arange
(
60
))
f
(
n
p
.
arange
(
60
),
np
.
arange
(
60
))
if
theano
.
config
.
mode
==
'FAST_COMPILE'
or
theano
.
config
.
cxx
==
""
:
if
theano
.
config
.
mode
==
'FAST_COMPILE'
or
theano
.
config
.
cxx
==
""
:
assert
MyOp
.
nb_called
==
0
assert
MyOp
.
nb_called
==
0
else
:
else
:
...
...
theano/gof/tests/test_compute_test_value.py
浏览文件 @
466cdaa8
...
@@ -4,7 +4,7 @@ import sys
...
@@ -4,7 +4,7 @@ import sys
import
traceback
import
traceback
import
warnings
import
warnings
import
numpy
import
numpy
as
np
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
import
unittest
import
unittest
...
@@ -44,9 +44,9 @@ class TestComputeTestValue(unittest.TestCase):
...
@@ -44,9 +44,9 @@ class TestComputeTestValue(unittest.TestCase):
theano
.
config
.
compute_test_value
=
'raise'
theano
.
config
.
compute_test_value
=
'raise'
x
=
T
.
matrix
(
'x'
)
x
=
T
.
matrix
(
'x'
)
x
.
tag
.
test_value
=
n
umpy
.
random
.
rand
(
3
,
4
)
.
astype
(
config
.
floatX
)
x
.
tag
.
test_value
=
n
p
.
random
.
rand
(
3
,
4
)
.
astype
(
config
.
floatX
)
y
=
T
.
matrix
(
'y'
)
y
=
T
.
matrix
(
'y'
)
y
.
tag
.
test_value
=
n
umpy
.
random
.
rand
(
4
,
5
)
.
astype
(
config
.
floatX
)
y
.
tag
.
test_value
=
n
p
.
random
.
rand
(
4
,
5
)
.
astype
(
config
.
floatX
)
# should work
# should work
z
=
T
.
dot
(
x
,
y
)
z
=
T
.
dot
(
x
,
y
)
...
@@ -56,7 +56,7 @@ class TestComputeTestValue(unittest.TestCase):
...
@@ -56,7 +56,7 @@ class TestComputeTestValue(unittest.TestCase):
z
.
tag
.
test_value
)
z
.
tag
.
test_value
)
# this test should fail
# this test should fail
y
.
tag
.
test_value
=
n
umpy
.
random
.
rand
(
6
,
5
)
.
astype
(
config
.
floatX
)
y
.
tag
.
test_value
=
n
p
.
random
.
rand
(
6
,
5
)
.
astype
(
config
.
floatX
)
self
.
assertRaises
(
ValueError
,
T
.
dot
,
x
,
y
)
self
.
assertRaises
(
ValueError
,
T
.
dot
,
x
,
y
)
finally
:
finally
:
theano
.
config
.
compute_test_value
=
orig_compute_test_value
theano
.
config
.
compute_test_value
=
orig_compute_test_value
...
@@ -66,7 +66,7 @@ class TestComputeTestValue(unittest.TestCase):
...
@@ -66,7 +66,7 @@ class TestComputeTestValue(unittest.TestCase):
try
:
try
:
x
=
T
.
matrix
(
'x'
)
x
=
T
.
matrix
(
'x'
)
y
=
T
.
matrix
(
'y'
)
y
=
T
.
matrix
(
'y'
)
y
.
tag
.
test_value
=
n
umpy
.
random
.
rand
(
4
,
5
)
.
astype
(
config
.
floatX
)
y
.
tag
.
test_value
=
n
p
.
random
.
rand
(
4
,
5
)
.
astype
(
config
.
floatX
)
# should skip computation of test value
# should skip computation of test value
theano
.
config
.
compute_test_value
=
'off'
theano
.
config
.
compute_test_value
=
'off'
...
@@ -96,11 +96,11 @@ class TestComputeTestValue(unittest.TestCase):
...
@@ -96,11 +96,11 @@ class TestComputeTestValue(unittest.TestCase):
theano
.
config
.
compute_test_value
=
'raise'
theano
.
config
.
compute_test_value
=
'raise'
x
=
T
.
matrix
(
'x'
)
x
=
T
.
matrix
(
'x'
)
x
.
tag
.
test_value
=
n
umpy
.
random
.
rand
(
3
,
4
)
.
astype
(
config
.
floatX
)
x
.
tag
.
test_value
=
n
p
.
random
.
rand
(
3
,
4
)
.
astype
(
config
.
floatX
)
y
=
T
.
matrix
(
'y'
)
y
=
T
.
matrix
(
'y'
)
y
.
tag
.
test_value
=
n
umpy
.
random
.
rand
(
4
,
5
)
.
astype
(
config
.
floatX
)
y
.
tag
.
test_value
=
n
p
.
random
.
rand
(
4
,
5
)
.
astype
(
config
.
floatX
)
z
=
theano
.
shared
(
n
umpy
.
random
.
rand
(
5
,
6
)
.
astype
(
config
.
floatX
))
z
=
theano
.
shared
(
n
p
.
random
.
rand
(
5
,
6
)
.
astype
(
config
.
floatX
))
# should work
# should work
out
=
T
.
dot
(
T
.
dot
(
x
,
y
),
z
)
out
=
T
.
dot
(
T
.
dot
(
x
,
y
),
z
)
...
@@ -114,7 +114,7 @@ class TestComputeTestValue(unittest.TestCase):
...
@@ -114,7 +114,7 @@ class TestComputeTestValue(unittest.TestCase):
return
T
.
dot
(
T
.
dot
(
x
,
y
),
z
)
return
T
.
dot
(
T
.
dot
(
x
,
y
),
z
)
# this test should fail
# this test should fail
z
.
set_value
(
n
umpy
.
random
.
rand
(
7
,
6
)
.
astype
(
config
.
floatX
))
z
.
set_value
(
n
p
.
random
.
rand
(
7
,
6
)
.
astype
(
config
.
floatX
))
self
.
assertRaises
(
ValueError
,
f
,
x
,
y
,
z
)
self
.
assertRaises
(
ValueError
,
f
,
x
,
y
,
z
)
finally
:
finally
:
theano
.
config
.
compute_test_value
=
orig_compute_test_value
theano
.
config
.
compute_test_value
=
orig_compute_test_value
...
@@ -125,8 +125,8 @@ class TestComputeTestValue(unittest.TestCase):
...
@@ -125,8 +125,8 @@ class TestComputeTestValue(unittest.TestCase):
theano
.
config
.
compute_test_value
=
'raise'
theano
.
config
.
compute_test_value
=
'raise'
x
=
T
.
matrix
(
'x'
)
x
=
T
.
matrix
(
'x'
)
x
.
tag
.
test_value
=
n
umpy
.
random
.
rand
(
3
,
4
)
.
astype
(
config
.
floatX
)
x
.
tag
.
test_value
=
n
p
.
random
.
rand
(
3
,
4
)
.
astype
(
config
.
floatX
)
y
=
theano
.
shared
(
n
umpy
.
random
.
rand
(
4
,
6
)
.
astype
(
config
.
floatX
),
y
=
theano
.
shared
(
n
p
.
random
.
rand
(
4
,
6
)
.
astype
(
config
.
floatX
),
'y'
)
'y'
)
# should work
# should work
...
@@ -136,7 +136,7 @@ class TestComputeTestValue(unittest.TestCase):
...
@@ -136,7 +136,7 @@ class TestComputeTestValue(unittest.TestCase):
assert
_allclose
(
f
(
x
.
tag
.
test_value
),
z
.
tag
.
test_value
)
assert
_allclose
(
f
(
x
.
tag
.
test_value
),
z
.
tag
.
test_value
)
# this test should fail
# this test should fail
y
.
set_value
(
n
umpy
.
random
.
rand
(
5
,
6
)
.
astype
(
config
.
floatX
))
y
.
set_value
(
n
p
.
random
.
rand
(
5
,
6
)
.
astype
(
config
.
floatX
))
self
.
assertRaises
(
ValueError
,
T
.
dot
,
x
,
y
)
self
.
assertRaises
(
ValueError
,
T
.
dot
,
x
,
y
)
finally
:
finally
:
theano
.
config
.
compute_test_value
=
orig_compute_test_value
theano
.
config
.
compute_test_value
=
orig_compute_test_value
...
@@ -146,8 +146,8 @@ class TestComputeTestValue(unittest.TestCase):
...
@@ -146,8 +146,8 @@ class TestComputeTestValue(unittest.TestCase):
try
:
try
:
theano
.
config
.
compute_test_value
=
'raise'
theano
.
config
.
compute_test_value
=
'raise'
x
=
n
umpy
.
random
.
rand
(
2
,
3
)
.
astype
(
config
.
floatX
)
x
=
n
p
.
random
.
rand
(
2
,
3
)
.
astype
(
config
.
floatX
)
y
=
theano
.
shared
(
n
umpy
.
random
.
rand
(
3
,
6
)
.
astype
(
config
.
floatX
),
y
=
theano
.
shared
(
n
p
.
random
.
rand
(
3
,
6
)
.
astype
(
config
.
floatX
),
'y'
)
'y'
)
# should work
# should work
...
@@ -157,7 +157,7 @@ class TestComputeTestValue(unittest.TestCase):
...
@@ -157,7 +157,7 @@ class TestComputeTestValue(unittest.TestCase):
assert
_allclose
(
f
(),
z
.
tag
.
test_value
)
assert
_allclose
(
f
(),
z
.
tag
.
test_value
)
# this test should fail
# this test should fail
x
=
n
umpy
.
random
.
rand
(
2
,
4
)
.
astype
(
config
.
floatX
)
x
=
n
p
.
random
.
rand
(
2
,
4
)
.
astype
(
config
.
floatX
)
self
.
assertRaises
(
ValueError
,
T
.
dot
,
x
,
y
)
self
.
assertRaises
(
ValueError
,
T
.
dot
,
x
,
y
)
finally
:
finally
:
theano
.
config
.
compute_test_value
=
orig_compute_test_value
theano
.
config
.
compute_test_value
=
orig_compute_test_value
...
@@ -167,7 +167,7 @@ class TestComputeTestValue(unittest.TestCase):
...
@@ -167,7 +167,7 @@ class TestComputeTestValue(unittest.TestCase):
try
:
try
:
theano
.
config
.
compute_test_value
=
'raise'
theano
.
config
.
compute_test_value
=
'raise'
x
=
theano
.
shared
(
n
umpy
.
random
.
rand
(
0
,
6
)
.
astype
(
config
.
floatX
),
x
=
theano
.
shared
(
n
p
.
random
.
rand
(
0
,
6
)
.
astype
(
config
.
floatX
),
'x'
)
'x'
)
# should work
# should work
...
@@ -184,8 +184,8 @@ class TestComputeTestValue(unittest.TestCase):
...
@@ -184,8 +184,8 @@ class TestComputeTestValue(unittest.TestCase):
try
:
try
:
theano
.
config
.
compute_test_value
=
'raise'
theano
.
config
.
compute_test_value
=
'raise'
x
=
T
.
constant
(
n
umpy
.
random
.
rand
(
2
,
3
),
dtype
=
config
.
floatX
)
x
=
T
.
constant
(
n
p
.
random
.
rand
(
2
,
3
),
dtype
=
config
.
floatX
)
y
=
theano
.
shared
(
n
umpy
.
random
.
rand
(
3
,
6
)
.
astype
(
config
.
floatX
),
y
=
theano
.
shared
(
n
p
.
random
.
rand
(
3
,
6
)
.
astype
(
config
.
floatX
),
'y'
)
'y'
)
# should work
# should work
...
@@ -195,7 +195,7 @@ class TestComputeTestValue(unittest.TestCase):
...
@@ -195,7 +195,7 @@ class TestComputeTestValue(unittest.TestCase):
assert
_allclose
(
f
(),
z
.
tag
.
test_value
)
assert
_allclose
(
f
(),
z
.
tag
.
test_value
)
# this test should fail
# this test should fail
x
=
T
.
constant
(
n
umpy
.
random
.
rand
(
2
,
4
),
dtype
=
config
.
floatX
)
x
=
T
.
constant
(
n
p
.
random
.
rand
(
2
,
4
),
dtype
=
config
.
floatX
)
self
.
assertRaises
(
ValueError
,
T
.
dot
,
x
,
y
)
self
.
assertRaises
(
ValueError
,
T
.
dot
,
x
,
y
)
finally
:
finally
:
theano
.
config
.
compute_test_value
=
orig_compute_test_value
theano
.
config
.
compute_test_value
=
orig_compute_test_value
...
@@ -207,9 +207,9 @@ class TestComputeTestValue(unittest.TestCase):
...
@@ -207,9 +207,9 @@ class TestComputeTestValue(unittest.TestCase):
x
=
T
.
fmatrix
(
'x'
)
x
=
T
.
fmatrix
(
'x'
)
# Incorrect dtype (float64) for test_value
# Incorrect dtype (float64) for test_value
x
.
tag
.
test_value
=
n
umpy
.
random
.
rand
(
3
,
4
)
x
.
tag
.
test_value
=
n
p
.
random
.
rand
(
3
,
4
)
y
=
T
.
dmatrix
(
'y'
)
y
=
T
.
dmatrix
(
'y'
)
y
.
tag
.
test_value
=
n
umpy
.
random
.
rand
(
4
,
5
)
y
.
tag
.
test_value
=
n
p
.
random
.
rand
(
4
,
5
)
self
.
assertRaises
(
TypeError
,
T
.
dot
,
x
,
y
)
self
.
assertRaises
(
TypeError
,
T
.
dot
,
x
,
y
)
finally
:
finally
:
...
@@ -222,9 +222,9 @@ class TestComputeTestValue(unittest.TestCase):
...
@@ -222,9 +222,9 @@ class TestComputeTestValue(unittest.TestCase):
try
:
try
:
config
.
compute_test_value
=
"raise"
config
.
compute_test_value
=
"raise"
x
=
T
.
matrix
()
x
=
T
.
matrix
()
x
.
tag
.
test_value
=
n
umpy
.
zeros
((
2
,
3
),
dtype
=
config
.
floatX
)
x
.
tag
.
test_value
=
n
p
.
zeros
((
2
,
3
),
dtype
=
config
.
floatX
)
y
=
T
.
matrix
()
y
=
T
.
matrix
()
y
.
tag
.
test_value
=
n
umpy
.
zeros
((
2
,
2
),
dtype
=
config
.
floatX
)
y
.
tag
.
test_value
=
n
p
.
zeros
((
2
,
2
),
dtype
=
config
.
floatX
)
self
.
assertRaises
(
ValueError
,
x
.
__mul__
,
y
)
self
.
assertRaises
(
ValueError
,
x
.
__mul__
,
y
)
finally
:
finally
:
theano
.
config
.
compute_test_value
=
orig_compute_test_value
theano
.
config
.
compute_test_value
=
orig_compute_test_value
...
@@ -240,7 +240,7 @@ class TestComputeTestValue(unittest.TestCase):
...
@@ -240,7 +240,7 @@ class TestComputeTestValue(unittest.TestCase):
k
=
T
.
iscalar
(
"k"
)
k
=
T
.
iscalar
(
"k"
)
A
=
T
.
vector
(
"A"
)
A
=
T
.
vector
(
"A"
)
k
.
tag
.
test_value
=
3
k
.
tag
.
test_value
=
3
A
.
tag
.
test_value
=
n
umpy
.
random
.
rand
(
5
)
.
astype
(
config
.
floatX
)
A
.
tag
.
test_value
=
n
p
.
random
.
rand
(
5
)
.
astype
(
config
.
floatX
)
def
fx
(
prior_result
,
A
):
def
fx
(
prior_result
,
A
):
return
prior_result
*
A
return
prior_result
*
A
...
@@ -267,7 +267,7 @@ class TestComputeTestValue(unittest.TestCase):
...
@@ -267,7 +267,7 @@ class TestComputeTestValue(unittest.TestCase):
k
=
T
.
iscalar
(
"k"
)
k
=
T
.
iscalar
(
"k"
)
A
=
T
.
matrix
(
"A"
)
A
=
T
.
matrix
(
"A"
)
k
.
tag
.
test_value
=
3
k
.
tag
.
test_value
=
3
A
.
tag
.
test_value
=
n
umpy
.
random
.
rand
(
5
,
3
)
.
astype
(
config
.
floatX
)
A
.
tag
.
test_value
=
n
p
.
random
.
rand
(
5
,
3
)
.
astype
(
config
.
floatX
)
def
fx
(
prior_result
,
A
):
def
fx
(
prior_result
,
A
):
return
T
.
dot
(
prior_result
,
A
)
return
T
.
dot
(
prior_result
,
A
)
...
@@ -304,7 +304,7 @@ class TestComputeTestValue(unittest.TestCase):
...
@@ -304,7 +304,7 @@ class TestComputeTestValue(unittest.TestCase):
k
=
T
.
iscalar
(
"k"
)
k
=
T
.
iscalar
(
"k"
)
A
=
T
.
matrix
(
"A"
)
A
=
T
.
matrix
(
"A"
)
k
.
tag
.
test_value
=
3
k
.
tag
.
test_value
=
3
A
.
tag
.
test_value
=
n
umpy
.
random
.
rand
(
5
,
3
)
.
astype
(
config
.
floatX
)
A
.
tag
.
test_value
=
n
p
.
random
.
rand
(
5
,
3
)
.
astype
(
config
.
floatX
)
def
fx
(
prior_result
,
A
):
def
fx
(
prior_result
,
A
):
return
T
.
dot
(
prior_result
,
A
)
return
T
.
dot
(
prior_result
,
A
)
...
@@ -400,7 +400,7 @@ class TestComputeTestValue(unittest.TestCase):
...
@@ -400,7 +400,7 @@ class TestComputeTestValue(unittest.TestCase):
try
:
try
:
theano
.
config
.
compute_test_value
=
'raise'
theano
.
config
.
compute_test_value
=
'raise'
init_Mu1
=
theano
.
shared
(
init_Mu1
=
theano
.
shared
(
n
umpy
.
zeros
((
5
,),
dtype
=
config
.
floatX
))
.
dimshuffle
(
'x'
,
0
)
n
p
.
zeros
((
5
,),
dtype
=
config
.
floatX
))
.
dimshuffle
(
'x'
,
0
)
theano
.
function
([],
outputs
=
[
init_Mu1
])
theano
.
function
([],
outputs
=
[
init_Mu1
])
finally
:
finally
:
...
...
theano/gof/tests/test_graph.py
浏览文件 @
466cdaa8
...
@@ -4,7 +4,7 @@ import pickle
...
@@ -4,7 +4,7 @@ import pickle
import
unittest
import
unittest
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
import
numpy
import
numpy
as
np
from
theano
import
(
from
theano
import
(
sparse
,
sparse
,
...
@@ -362,7 +362,7 @@ class TestAutoName:
...
@@ -362,7 +362,7 @@ class TestAutoName:
r1
=
tensor
.
TensorType
(
dtype
=
'int32'
,
broadcastable
=
())(
'myvar'
)
r1
=
tensor
.
TensorType
(
dtype
=
'int32'
,
broadcastable
=
())(
'myvar'
)
r2
=
tensor
.
TensorVariable
(
tensor
.
TensorType
(
dtype
=
'int32'
,
r2
=
tensor
.
TensorVariable
(
tensor
.
TensorType
(
dtype
=
'int32'
,
broadcastable
=
()))
broadcastable
=
()))
r3
=
shared
(
n
umpy
.
random
.
randn
(
3
,
4
))
r3
=
shared
(
n
p
.
random
.
randn
(
3
,
4
))
assert
r1
.
auto_name
==
"auto_"
+
str
(
autoname_id
)
assert
r1
.
auto_name
==
"auto_"
+
str
(
autoname_id
)
assert
r2
.
auto_name
==
"auto_"
+
str
(
autoname_id
+
1
)
assert
r2
.
auto_name
==
"auto_"
+
str
(
autoname_id
+
1
)
assert
r3
.
auto_name
==
"auto_"
+
str
(
autoname_id
+
2
)
assert
r3
.
auto_name
==
"auto_"
+
str
(
autoname_id
+
2
)
...
...
theano/gof/tests/test_graph_opt_caching.py
浏览文件 @
466cdaa8
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
os
import
os
import
numpy
import
numpy
as
np
import
theano
import
theano
import
theano.tensor
as
T
import
theano.tensor
as
T
...
@@ -19,20 +19,20 @@ def test_graph_opt_caching():
...
@@ -19,20 +19,20 @@ def test_graph_opt_caching():
theano
.
config
.
cache_optimizations
=
True
theano
.
config
.
cache_optimizations
=
True
a
=
T
.
fmatrix
(
'a'
)
a
=
T
.
fmatrix
(
'a'
)
b
=
T
.
fmatrix
(
'b'
)
b
=
T
.
fmatrix
(
'b'
)
c
=
theano
.
shared
(
n
umpy
.
ones
((
10
,
10
),
dtype
=
floatX
))
c
=
theano
.
shared
(
n
p
.
ones
((
10
,
10
),
dtype
=
floatX
))
d
=
theano
.
shared
(
n
umpy
.
ones
((
10
,
10
),
dtype
=
floatX
))
d
=
theano
.
shared
(
n
p
.
ones
((
10
,
10
),
dtype
=
floatX
))
e
=
T
.
sum
(
T
.
sum
(
T
.
sum
(
a
**
2
+
b
)
+
c
)
+
d
)
e
=
T
.
sum
(
T
.
sum
(
T
.
sum
(
a
**
2
+
b
)
+
c
)
+
d
)
f1
=
theano
.
function
([
a
,
b
],
e
,
mode
=
mode
)
f1
=
theano
.
function
([
a
,
b
],
e
,
mode
=
mode
)
m
=
T
.
fmatrix
(
'x1'
)
m
=
T
.
fmatrix
(
'x1'
)
n
=
T
.
fmatrix
(
'x2'
)
n
=
T
.
fmatrix
(
'x2'
)
p
=
theano
.
shared
(
n
umpy
.
ones
((
10
,
10
),
dtype
=
floatX
))
p
=
theano
.
shared
(
n
p
.
ones
((
10
,
10
),
dtype
=
floatX
))
q
=
theano
.
shared
(
n
umpy
.
ones
((
10
,
10
),
dtype
=
floatX
))
q
=
theano
.
shared
(
n
p
.
ones
((
10
,
10
),
dtype
=
floatX
))
j
=
T
.
sum
(
T
.
sum
(
T
.
sum
(
m
**
2
+
n
)
+
p
)
+
q
)
j
=
T
.
sum
(
T
.
sum
(
T
.
sum
(
m
**
2
+
n
)
+
p
)
+
q
)
f2
=
theano
.
function
([
m
,
n
],
j
,
mode
=
mode
)
f2
=
theano
.
function
([
m
,
n
],
j
,
mode
=
mode
)
in1
=
n
umpy
.
ones
((
10
,
10
),
dtype
=
floatX
)
in1
=
n
p
.
ones
((
10
,
10
),
dtype
=
floatX
)
in2
=
n
umpy
.
ones
((
10
,
10
),
dtype
=
floatX
)
in2
=
n
p
.
ones
((
10
,
10
),
dtype
=
floatX
)
assert
f1
(
in1
,
in2
)
==
f2
(
in1
,
in2
)
assert
f1
(
in1
,
in2
)
==
f2
(
in1
,
in2
)
finally
:
finally
:
theano
.
config
.
cache_optimizations
=
default
theano
.
config
.
cache_optimizations
=
default
...
...
theano/gof/tests/test_lazy.py
浏览文件 @
466cdaa8
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
from
copy
import
deepcopy
from
copy
import
deepcopy
import
numpy
import
numpy
as
np
import
theano
import
theano
from
theano.gof.op
import
PureOp
from
theano.gof.op
import
PureOp
...
@@ -154,13 +154,13 @@ def more_complex_test():
...
@@ -154,13 +154,13 @@ def more_complex_test():
optimizer
=
'fast_run'
))
optimizer
=
'fast_run'
))
if
theano
.
config
.
vm
.
lazy
is
False
:
if
theano
.
config
.
vm
.
lazy
is
False
:
try
:
try
:
f
(
1
,
0
,
n
umpy
.
array
(
10
,
dtype
=
x1
.
dtype
),
0
)
f
(
1
,
0
,
n
p
.
array
(
10
,
dtype
=
x1
.
dtype
),
0
)
assert
False
assert
False
except
NotImplementedOp
.
E
:
except
NotImplementedOp
.
E
:
pass
pass
else
:
else
:
print
(
f
(
1
,
0
,
n
umpy
.
array
(
10
,
dtype
=
x1
.
dtype
),
0
))
print
(
f
(
1
,
0
,
n
p
.
array
(
10
,
dtype
=
x1
.
dtype
),
0
))
assert
f
(
1
,
0
,
n
umpy
.
array
(
10
,
dtype
=
x1
.
dtype
),
0
)
==
20.5
assert
f
(
1
,
0
,
n
p
.
array
(
10
,
dtype
=
x1
.
dtype
),
0
)
==
20.5
print
(
'... passed'
)
print
(
'... passed'
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
theano/gof/tests/test_link.py
浏览文件 @
466cdaa8
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
from
copy
import
deepcopy
from
copy
import
deepcopy
import
unittest
import
unittest
import
numpy
import
numpy
as
np
import
theano
import
theano
from
theano.gof
import
graph
from
theano.gof
import
graph
...
@@ -203,17 +203,17 @@ def test_container_deepcopy():
...
@@ -203,17 +203,17 @@ def test_container_deepcopy():
# It seam that numpy.asarray(0.).astype(floatX) can return a numpy
# It seam that numpy.asarray(0.).astype(floatX) can return a numpy
# scalar with some NumPy Version. So we call numpy.asarray with
# scalar with some NumPy Version. So we call numpy.asarray with
# the dtype parameter.
# the dtype parameter.
v
=
n
umpy
.
asarray
(
0.
,
dtype
=
theano
.
config
.
floatX
)
v
=
n
p
.
asarray
(
0.
,
dtype
=
theano
.
config
.
floatX
)
assert
isinstance
(
v
,
n
umpy
.
ndarray
),
type
(
v
)
assert
isinstance
(
v
,
n
p
.
ndarray
),
type
(
v
)
for
readonly
in
[
True
,
False
]:
for
readonly
in
[
True
,
False
]:
c
=
Container
(
t
,
[
v
],
readonly
=
readonly
)
c
=
Container
(
t
,
[
v
],
readonly
=
readonly
)
assert
isinstance
(
c
.
storage
[
0
],
n
umpy
.
ndarray
),
(
c
.
storage
[
0
],
assert
isinstance
(
c
.
storage
[
0
],
n
p
.
ndarray
),
(
c
.
storage
[
0
],
type
(
c
.
storage
[
0
]))
type
(
c
.
storage
[
0
]))
assert
c
.
storage
[
0
]
.
dtype
==
v
.
dtype
,
(
c
.
storage
[
0
]
.
dtype
,
v
.
dtype
)
assert
c
.
storage
[
0
]
.
dtype
==
v
.
dtype
,
(
c
.
storage
[
0
]
.
dtype
,
v
.
dtype
)
assert
c
.
storage
[
0
]
.
dtype
==
c
.
type
.
dtype
,
(
c
.
storage
[
0
]
.
dtype
,
assert
c
.
storage
[
0
]
.
dtype
==
c
.
type
.
dtype
,
(
c
.
storage
[
0
]
.
dtype
,
c
.
type
.
dtype
)
c
.
type
.
dtype
)
d
=
deepcopy
(
c
)
d
=
deepcopy
(
c
)
assert
isinstance
(
d
.
storage
[
0
],
n
umpy
.
ndarray
),
(
d
.
storage
[
0
],
assert
isinstance
(
d
.
storage
[
0
],
n
p
.
ndarray
),
(
d
.
storage
[
0
],
type
(
d
.
storage
[
0
]))
type
(
d
.
storage
[
0
]))
assert
d
.
storage
[
0
]
.
dtype
==
v
.
dtype
,
(
d
.
storage
[
0
]
.
dtype
,
v
.
dtype
)
assert
d
.
storage
[
0
]
.
dtype
==
v
.
dtype
,
(
d
.
storage
[
0
]
.
dtype
,
v
.
dtype
)
assert
d
.
storage
[
0
]
.
dtype
==
c
.
type
.
dtype
,
(
d
.
storage
[
0
]
.
dtype
,
assert
d
.
storage
[
0
]
.
dtype
==
c
.
type
.
dtype
,
(
d
.
storage
[
0
]
.
dtype
,
...
...
theano/gof/tests/test_op.py
浏览文件 @
466cdaa8
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
import
unittest
import
unittest
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
import
numpy
import
numpy
as
np
import
theano
import
theano
import
theano.gof.op
as
op
import
theano.gof.op
as
op
...
@@ -181,7 +181,7 @@ class TestMakeThunk(unittest.TestCase):
...
@@ -181,7 +181,7 @@ class TestMakeThunk(unittest.TestCase):
o
.
owner
.
op
.
c_code
,
o
.
owner
.
op
.
c_code
,
o
.
owner
,
'o'
,
[
'x'
],
'z'
,
{
'fail'
:
''
})
o
.
owner
,
'o'
,
[
'x'
],
'z'
,
{
'fail'
:
''
})
storage_map
=
{
i
:
[
n
umpy
.
int32
(
3
)],
storage_map
=
{
i
:
[
n
p
.
int32
(
3
)],
o
:
[
None
]}
o
:
[
None
]}
compute_map
=
{
i
:
[
True
],
compute_map
=
{
i
:
[
True
],
o
:
[
False
]}
o
:
[
False
]}
...
@@ -218,7 +218,7 @@ class TestMakeThunk(unittest.TestCase):
...
@@ -218,7 +218,7 @@ class TestMakeThunk(unittest.TestCase):
o
.
owner
.
op
.
perform
,
o
.
owner
.
op
.
perform
,
o
.
owner
,
0
,
[
None
])
o
.
owner
,
0
,
[
None
])
storage_map
=
{
i
:
[
n
umpy
.
int32
(
3
)],
storage_map
=
{
i
:
[
n
p
.
int32
(
3
)],
o
:
[
None
]}
o
:
[
None
]}
compute_map
=
{
i
:
[
True
],
compute_map
=
{
i
:
[
True
],
o
:
[
False
]}
o
:
[
False
]}
...
@@ -251,9 +251,9 @@ class TestMakeThunk(unittest.TestCase):
...
@@ -251,9 +251,9 @@ class TestMakeThunk(unittest.TestCase):
x_input
=
T
.
dmatrix
(
'x_input'
)
x_input
=
T
.
dmatrix
(
'x_input'
)
f
=
theano
.
function
([
x_input
],
DoubleOp
()(
x_input
))
f
=
theano
.
function
([
x_input
],
DoubleOp
()(
x_input
))
inp
=
n
umpy
.
random
.
rand
(
5
,
4
)
inp
=
n
p
.
random
.
rand
(
5
,
4
)
out
=
f
(
inp
)
out
=
f
(
inp
)
assert
n
umpy
.
allclose
(
inp
*
2
,
out
)
assert
n
p
.
allclose
(
inp
*
2
,
out
)
def
test_test_value_python_objects
():
def
test_test_value_python_objects
():
...
@@ -262,33 +262,33 @@ def test_test_value_python_objects():
...
@@ -262,33 +262,33 @@ def test_test_value_python_objects():
def
test_test_value_ndarray
():
def
test_test_value_ndarray
():
x
=
n
umpy
.
zeros
((
5
,
5
))
x
=
n
p
.
zeros
((
5
,
5
))
v
=
op
.
get_test_value
(
x
)
v
=
op
.
get_test_value
(
x
)
assert
(
v
==
x
)
.
all
()
assert
(
v
==
x
)
.
all
()
def
test_test_value_constant
():
def
test_test_value_constant
():
x
=
T
.
as_tensor_variable
(
n
umpy
.
zeros
((
5
,
5
)))
x
=
T
.
as_tensor_variable
(
n
p
.
zeros
((
5
,
5
)))
v
=
op
.
get_test_value
(
x
)
v
=
op
.
get_test_value
(
x
)
assert
n
umpy
.
all
(
v
==
numpy
.
zeros
((
5
,
5
)))
assert
n
p
.
all
(
v
==
np
.
zeros
((
5
,
5
)))
def
test_test_value_shared
():
def
test_test_value_shared
():
x
=
shared
(
n
umpy
.
zeros
((
5
,
5
)))
x
=
shared
(
n
p
.
zeros
((
5
,
5
)))
v
=
op
.
get_test_value
(
x
)
v
=
op
.
get_test_value
(
x
)
assert
n
umpy
.
all
(
v
==
numpy
.
zeros
((
5
,
5
)))
assert
n
p
.
all
(
v
==
np
.
zeros
((
5
,
5
)))
def
test_test_value_op
():
def
test_test_value_op
():
try
:
try
:
prev_value
=
config
.
compute_test_value
prev_value
=
config
.
compute_test_value
config
.
compute_test_value
=
'raise'
config
.
compute_test_value
=
'raise'
x
=
T
.
log
(
n
umpy
.
ones
((
5
,
5
)))
x
=
T
.
log
(
n
p
.
ones
((
5
,
5
)))
v
=
op
.
get_test_value
(
x
)
v
=
op
.
get_test_value
(
x
)
assert
n
umpy
.
allclose
(
v
,
numpy
.
zeros
((
5
,
5
)))
assert
n
p
.
allclose
(
v
,
np
.
zeros
((
5
,
5
)))
finally
:
finally
:
config
.
compute_test_value
=
prev_value
config
.
compute_test_value
=
prev_value
...
@@ -337,8 +337,8 @@ def test_get_debug_values_success():
...
@@ -337,8 +337,8 @@ def test_get_debug_values_success():
config
.
compute_test_value
=
mode
config
.
compute_test_value
=
mode
x
=
T
.
vector
()
x
=
T
.
vector
()
x
.
tag
.
test_value
=
n
umpy
.
zeros
((
4
,),
dtype
=
config
.
floatX
)
x
.
tag
.
test_value
=
n
p
.
zeros
((
4
,),
dtype
=
config
.
floatX
)
y
=
n
umpy
.
zeros
((
5
,
5
))
y
=
n
p
.
zeros
((
5
,
5
))
iters
=
0
iters
=
0
...
...
theano/gof/tests/test_types.py
浏览文件 @
466cdaa8
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
numpy
import
numpy
as
np
import
theano
import
theano
from
theano
import
Op
,
Apply
from
theano
import
Op
,
Apply
...
@@ -72,7 +72,7 @@ def test_cdata():
...
@@ -72,7 +72,7 @@ def test_cdata():
# This should be a passthrough function for vectors
# This should be a passthrough function for vectors
f
=
theano
.
function
([
i
],
i2
,
mode
=
mode
)
f
=
theano
.
function
([
i
],
i2
,
mode
=
mode
)
v
=
n
umpy
.
random
.
randn
(
9
)
.
astype
(
'float32'
)
v
=
n
p
.
random
.
randn
(
9
)
.
astype
(
'float32'
)
v2
=
f
(
v
)
v2
=
f
(
v
)
assert
(
v2
==
v
)
.
all
()
assert
(
v2
==
v
)
.
all
()
theano/gof/tests/test_vm.py
浏览文件 @
466cdaa8
...
@@ -5,7 +5,7 @@ import time
...
@@ -5,7 +5,7 @@ import time
import
unittest
import
unittest
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
import
numpy
import
numpy
as
np
from
six
import
itervalues
from
six
import
itervalues
from
theano
import
function
from
theano
import
function
...
@@ -92,7 +92,7 @@ def test_speed():
...
@@ -92,7 +92,7 @@ def test_speed():
def
time_numpy
():
def
time_numpy
():
steps_a
=
5
steps_a
=
5
steps_b
=
100
steps_b
=
100
x
=
n
umpy
.
asarray
([
2.0
,
3.0
],
dtype
=
theano
.
config
.
floatX
)
x
=
n
p
.
asarray
([
2.0
,
3.0
],
dtype
=
theano
.
config
.
floatX
)
numpy_version
(
x
,
steps_a
)
numpy_version
(
x
,
steps_a
)
t0
=
time
.
time
()
t0
=
time
.
time
()
...
@@ -195,7 +195,6 @@ def test_speed_lazy():
...
@@ -195,7 +195,6 @@ def test_speed_lazy():
def
test_partial_function
():
def
test_partial_function
():
import
numpy
as
np
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
def
check_partial_function
(
linker_name
):
def
check_partial_function
(
linker_name
):
...
@@ -234,7 +233,7 @@ def test_partial_function_with_updates():
...
@@ -234,7 +233,7 @@ def test_partial_function_with_updates():
def
check_updates
(
linker_name
):
def
check_updates
(
linker_name
):
x
=
tensor
.
lscalar
(
'input'
)
x
=
tensor
.
lscalar
(
'input'
)
y
=
theano
.
shared
(
n
umpy
.
asarray
(
1
,
'int64'
),
name
=
'global'
)
y
=
theano
.
shared
(
n
p
.
asarray
(
1
,
'int64'
),
name
=
'global'
)
f
=
theano
.
function
([
x
],
[
x
,
x
+
34
],
updates
=
[(
y
,
x
+
1
)],
mode
=
Mode
(
f
=
theano
.
function
([
x
],
[
x
,
x
+
34
],
updates
=
[(
y
,
x
+
1
)],
mode
=
Mode
(
optimizer
=
None
,
linker
=
linker_name
))
optimizer
=
None
,
linker
=
linker_name
))
g
=
theano
.
function
([
x
],
[
x
-
6
],
updates
=
[(
y
,
y
+
3
)],
mode
=
Mode
(
g
=
theano
.
function
([
x
],
[
x
-
6
],
updates
=
[(
y
,
y
+
3
)],
mode
=
Mode
(
...
@@ -283,7 +282,7 @@ if run_memory_usage_tests:
...
@@ -283,7 +282,7 @@ if run_memory_usage_tests:
def
test_leak2
():
def
test_leak2
():
import
theano.sandbox.cuda
as
cuda
import
theano.sandbox.cuda
as
cuda
for
i
in
xrange
(
1000000
):
for
i
in
xrange
(
1000000
):
n
=
n
umpy
.
asarray
([
2.3
,
4.5
],
dtype
=
'f'
)
n
=
n
p
.
asarray
([
2.3
,
4.5
],
dtype
=
'f'
)
c
=
sys
.
getrefcount
(
n
)
c
=
sys
.
getrefcount
(
n
)
a
=
cuda
.
CudaNdarray
(
n
)
a
=
cuda
.
CudaNdarray
(
n
)
a
.
sum
()
a
.
sum
()
...
@@ -338,7 +337,7 @@ if run_memory_usage_tests:
...
@@ -338,7 +337,7 @@ if run_memory_usage_tests:
f_a
=
function
([
x
],
a
,
f_a
=
function
([
x
],
a
,
mode
=
Mode
(
optimizer
=
None
,
mode
=
Mode
(
optimizer
=
None
,
linker
=
linker
()))
linker
=
linker
()))
inp
=
n
umpy
.
random
.
rand
(
1000000
)
inp
=
n
p
.
random
.
rand
(
1000000
)
for
i
in
xrange
(
100
):
for
i
in
xrange
(
100
):
f_a
(
inp
)
f_a
(
inp
)
if
0
:
# this doesn't seem to work, prints 0 for everything
if
0
:
# this doesn't seem to work, prints 0 for everything
...
@@ -375,7 +374,7 @@ if run_memory_usage_tests:
...
@@ -375,7 +374,7 @@ if run_memory_usage_tests:
f_a
=
function
([
x
],
a
,
f_a
=
function
([
x
],
a
,
mode
=
Mode
(
optimizer
=
None
,
mode
=
Mode
(
optimizer
=
None
,
linker
=
linker
()))
linker
=
linker
()))
inp
=
n
umpy
.
random
.
rand
(
1000000
)
inp
=
n
p
.
random
.
rand
(
1000000
)
for
i
in
xrange
(
500
):
for
i
in
xrange
(
500
):
f_a
(
inp
)
f_a
(
inp
)
print
(
1
)
print
(
1
)
...
...
theano/gof/utils.py
浏览文件 @
466cdaa8
...
@@ -3,7 +3,7 @@ import linecache
...
@@ -3,7 +3,7 @@ import linecache
import
sys
import
sys
import
traceback
import
traceback
import
numpy
import
numpy
as
np
from
six
import
iteritems
,
integer_types
,
string_types
,
with_metaclass
from
six
import
iteritems
,
integer_types
,
string_types
,
with_metaclass
from
six.moves
import
StringIO
from
six.moves
import
StringIO
...
@@ -561,8 +561,8 @@ else:
...
@@ -561,8 +561,8 @@ else:
try
:
try
:
return
hashlib
.
md5
(
msg
)
.
hexdigest
()
return
hashlib
.
md5
(
msg
)
.
hexdigest
()
except
TypeError
:
except
TypeError
:
assert
isinstance
(
msg
,
n
umpy
.
ndarray
)
assert
isinstance
(
msg
,
n
p
.
ndarray
)
return
hashlib
.
md5
(
n
umpy
.
getbuffer
(
msg
))
.
hexdigest
()
return
hashlib
.
md5
(
n
p
.
getbuffer
(
msg
))
.
hexdigest
()
def
hash_from_file
(
file_path
):
def
hash_from_file
(
file_path
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论