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 个修改的文件
包含
109 行增加
和
111 行删除
+109
-111
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
+18
-18
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
+7
-7
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
import
sys
import
logging
import
numpy
import
numpy
as
np
import
theano
from
theano
import
config
...
...
@@ -1347,7 +1347,7 @@ class CLinker(link.Linker):
# We must always add the numpy ABI version here as
# DynamicModule always add the include <numpy/arrayobject.h>
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
:
sig
.
append
(
'c_compiler_str='
+
c_compiler
.
version_str
())
...
...
theano/gof/cmodule.py
浏览文件 @
466cdaa8
...
...
@@ -20,7 +20,7 @@ import platform
import
distutils.sysconfig
import
warnings
import
numpy
.distutils
# TODO: TensorType should handle thi
s
import
numpy
as
np
# TODO: TensorType should handle nunpy.distutil
s
import
theano
from
theano.compat
import
PY3
,
decode
,
decode_iter
...
...
@@ -1578,7 +1578,7 @@ def get_gcc_shared_library_arg():
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_plat_spec_inc
=
distutils
.
sysconfig
.
get_python_inc
(
plat_specific
=
True
)
python_inc_dirs
=
([
py_inc
]
if
py_inc
==
py_plat_spec_inc
...
...
theano/gof/compiledir.py
浏览文件 @
466cdaa8
...
...
@@ -4,7 +4,7 @@ import logging
import
os
import
shutil
import
numpy
import
numpy
as
np
import
theano
from
six
import
string_types
,
iteritems
...
...
@@ -42,7 +42,7 @@ def cleanup():
have_npy_abi_version
=
False
have_c_compiler
=
False
for
obj
in
flatten
(
key
):
if
isinstance
(
obj
,
n
umpy
.
ndarray
):
if
isinstance
(
obj
,
n
p
.
ndarray
):
# Reuse have_npy_abi_version to
# force the removing of key
have_npy_abi_version
=
False
...
...
theano/gof/graph.py
浏览文件 @
466cdaa8
...
...
@@ -481,12 +481,12 @@ class Variable(Node):
Examples
--------
>>> import numpy
>>> import numpy
as np
>>> import theano.tensor as T
>>> x = T.dscalar('x')
>>> y = T.dscalar('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
We passed :func:`eval` a dictionary mapping symbolic theano
...
...
theano/gof/link.py
浏览文件 @
466cdaa8
...
...
@@ -7,7 +7,7 @@ from copy import copy, deepcopy
from
sys
import
getsizeof
import
sys
import
traceback
import
numpy
import
numpy
as
np
import
theano
from
theano.compat
import
izip
...
...
@@ -236,11 +236,11 @@ def raise_with_op(node, thunk=None, exc_info=None, storage_map=None):
# storage_map_item[3]: bytes
if
hasattr
(
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
:
storage_map_item
.
append
(
-
1
)
else
:
sz
=
n
umpy
.
dtype
(
dtype
)
.
itemsize
*
numpy
.
prod
(
shapeinfo
)
sz
=
n
p
.
dtype
(
dtype
)
.
itemsize
*
np
.
prod
(
shapeinfo
)
storage_map_item
.
append
(
sz
)
total_size
+=
sz
if
not
k
.
owner
:
...
...
theano/gof/op.py
浏览文件 @
466cdaa8
...
...
@@ -9,7 +9,7 @@ from __future__ import absolute_import, print_function, division
import
inspect
import
logging
import
numpy
import
numpy
as
np
import
os
import
re
import
sys
...
...
@@ -1430,7 +1430,7 @@ class COp(Op):
(
macro_name
,
macro_value
))
undef_macros
.
append
(
undef_template
%
macro_name
)
d
=
n
umpy
.
dtype
(
v
.
dtype
)
d
=
n
p
.
dtype
(
v
.
dtype
)
macro_name
=
"TYPENUM_"
+
vname
macro_value
=
d
.
num
...
...
theano/gof/opt.py
浏览文件 @
466cdaa8
...
...
@@ -15,7 +15,7 @@ import time
import
warnings
import
traceback
import
numpy
import
numpy
as
np
import
theano
from
theano
import
config
...
...
@@ -1695,8 +1695,7 @@ class PatternSub(LocalOptimizer):
u
=
u
.
merge
(
expr
,
v
)
elif
(
isinstance
(
pattern
,
(
integer_types
,
float
))
and
isinstance
(
expr
,
graph
.
Constant
)):
if
numpy
.
all
(
theano
.
tensor
.
constant
(
pattern
)
.
value
==
expr
.
value
):
if
np
.
all
(
theano
.
tensor
.
constant
(
pattern
)
.
value
==
expr
.
value
):
return
u
else
:
return
retry_with_equiv
()
...
...
theano/gof/tests/test_cc.py
浏览文件 @
466cdaa8
...
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
from
nose.plugins.skip
import
SkipTest
import
numpy
import
numpy
as
np
import
theano
from
theano.gof.link
import
PerformLinker
...
...
@@ -211,16 +211,16 @@ def test_clinker_literal_cache():
A
=
theano
.
tensor
.
matrix
()
input1
=
theano
.
tensor
.
vector
()
normal_svd
=
n
umpy
.
array
([[
5.936276e+01
,
-
4.664007e-07
,
-
2.56265e-06
],
[
-
4.664007e-07
,
9.468691e-01
,
-
3.18862e-02
],
[
-
2.562651e-06
,
-
3.188625e-02
,
1.05226e+00
]],
dtype
=
theano
.
config
.
floatX
)
normal_svd
=
n
p
.
array
([[
5.936276e+01
,
-
4.664007e-07
,
-
2.56265e-06
],
[
-
4.664007e-07
,
9.468691e-01
,
-
3.18862e-02
],
[
-
2.562651e-06
,
-
3.188625e-02
,
1.05226e+00
]],
dtype
=
theano
.
config
.
floatX
)
orientationi
=
n
umpy
.
array
([
59.36276866
,
1.06116353
,
0.93797339
],
dtype
=
theano
.
config
.
floatX
)
orientationi
=
n
p
.
array
([
59.36276866
,
1.06116353
,
0.93797339
],
dtype
=
theano
.
config
.
floatX
)
for
out1
in
[
A
-
input1
[
0
]
*
n
umpy
.
identity
(
3
),
input1
[
0
]
*
n
umpy
.
identity
(
3
)]:
for
out1
in
[
A
-
input1
[
0
]
*
n
p
.
identity
(
3
),
input1
[
0
]
*
n
p
.
identity
(
3
)]:
benchmark
=
theano
.
function
(
inputs
=
[
A
,
input1
],
outputs
=
[
out1
],
...
...
@@ -421,7 +421,7 @@ def test_shared_input_output():
g0
=
g
(
0
)
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'
fv
=
theano
.
function
([
inc
],
vstate
,
updates
=
[(
vstate
,
vstate
+
inc
)],
mode
=
mode
)
...
...
@@ -430,21 +430,21 @@ def test_shared_input_output():
# Initial value
fv0
=
fv
(
0
)
gv0
=
gv
(
0
)
assert
n
umpy
.
all
(
fv0
==
0
),
fv0
assert
n
umpy
.
all
(
gv0
==
0
),
gv0
assert
n
p
.
all
(
fv0
==
0
),
fv0
assert
n
p
.
all
(
gv0
==
0
),
gv0
# Increment state via f, returns the previous value.
fv2
=
fv
(
2
)
assert
n
umpy
.
all
(
fv2
==
fv0
),
(
fv2
,
fv0
)
assert
n
p
.
all
(
fv2
==
fv0
),
(
fv2
,
fv0
)
fv0
=
fv
(
0
)
gv0
=
gv
(
0
)
assert
n
umpy
.
all
(
fv0
==
2
),
fv0
assert
n
umpy
.
all
(
gv0
==
2
),
gv0
assert
n
p
.
all
(
fv0
==
2
),
fv0
assert
n
p
.
all
(
gv0
==
2
),
gv0
# Increment state via g, returns the previous value
gv3
=
gv
(
3
)
assert
n
umpy
.
all
(
gv3
==
gv0
),
(
gv3
,
gv0
)
assert
n
p
.
all
(
gv3
==
gv0
),
(
gv3
,
gv0
)
fv0
=
fv
(
0
)
gv0
=
gv
(
0
)
assert
n
umpy
.
all
(
fv0
==
5
),
fv0
assert
n
umpy
.
all
(
gv0
==
5
),
gv0
assert
n
p
.
all
(
fv0
==
5
),
fv0
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.
"""
from
__future__
import
absolute_import
,
print_function
,
division
import
numpy
import
numpy
as
np
import
theano
from
theano.gof.cmodule
import
GCC_compiler
...
...
@@ -26,7 +26,7 @@ class MyOp(theano.compile.ops.DeepCopyOp):
itype
=
node
.
inputs
[
0
]
.
type
.
__class__
if
itype
in
self
.
c_code_and_version
:
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
()
# Else, no C code
return
super
(
theano
.
compile
.
ops
.
DeepCopyOp
,
self
)
.
c_code
(
...
...
@@ -47,7 +47,7 @@ def test_inter_process_cache():
x
,
y
=
theano
.
tensor
.
dvectors
(
'xy'
)
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
==
""
:
assert
MyOp
.
nb_called
==
0
else
:
...
...
@@ -56,7 +56,7 @@ def test_inter_process_cache():
# What if we compile a new function with new variables?
x
,
y
=
theano
.
tensor
.
dvectors
(
'xy'
)
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
==
""
:
assert
MyOp
.
nb_called
==
0
else
:
...
...
theano/gof/tests/test_compute_test_value.py
浏览文件 @
466cdaa8
...
...
@@ -4,7 +4,7 @@ import sys
import
traceback
import
warnings
import
numpy
import
numpy
as
np
from
nose.plugins.skip
import
SkipTest
import
unittest
...
...
@@ -44,9 +44,9 @@ class TestComputeTestValue(unittest.TestCase):
theano
.
config
.
compute_test_value
=
'raise'
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
.
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
z
=
T
.
dot
(
x
,
y
)
...
...
@@ -56,7 +56,7 @@ class TestComputeTestValue(unittest.TestCase):
z
.
tag
.
test_value
)
# 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
)
finally
:
theano
.
config
.
compute_test_value
=
orig_compute_test_value
...
...
@@ -66,7 +66,7 @@ class TestComputeTestValue(unittest.TestCase):
try
:
x
=
T
.
matrix
(
'x'
)
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
theano
.
config
.
compute_test_value
=
'off'
...
...
@@ -96,11 +96,11 @@ class TestComputeTestValue(unittest.TestCase):
theano
.
config
.
compute_test_value
=
'raise'
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
.
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
out
=
T
.
dot
(
T
.
dot
(
x
,
y
),
z
)
...
...
@@ -114,7 +114,7 @@ class TestComputeTestValue(unittest.TestCase):
return
T
.
dot
(
T
.
dot
(
x
,
y
),
z
)
# 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
)
finally
:
theano
.
config
.
compute_test_value
=
orig_compute_test_value
...
...
@@ -125,8 +125,8 @@ class TestComputeTestValue(unittest.TestCase):
theano
.
config
.
compute_test_value
=
'raise'
x
=
T
.
matrix
(
'x'
)
x
.
tag
.
test_value
=
n
umpy
.
random
.
rand
(
3
,
4
)
.
astype
(
config
.
floatX
)
y
=
theano
.
shared
(
n
umpy
.
random
.
rand
(
4
,
6
)
.
astype
(
config
.
floatX
),
x
.
tag
.
test_value
=
n
p
.
random
.
rand
(
3
,
4
)
.
astype
(
config
.
floatX
)
y
=
theano
.
shared
(
n
p
.
random
.
rand
(
4
,
6
)
.
astype
(
config
.
floatX
),
'y'
)
# should work
...
...
@@ -136,7 +136,7 @@ class TestComputeTestValue(unittest.TestCase):
assert
_allclose
(
f
(
x
.
tag
.
test_value
),
z
.
tag
.
test_value
)
# 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
)
finally
:
theano
.
config
.
compute_test_value
=
orig_compute_test_value
...
...
@@ -146,8 +146,8 @@ class TestComputeTestValue(unittest.TestCase):
try
:
theano
.
config
.
compute_test_value
=
'raise'
x
=
n
umpy
.
random
.
rand
(
2
,
3
)
.
astype
(
config
.
floatX
)
y
=
theano
.
shared
(
n
umpy
.
random
.
rand
(
3
,
6
)
.
astype
(
config
.
floatX
),
x
=
n
p
.
random
.
rand
(
2
,
3
)
.
astype
(
config
.
floatX
)
y
=
theano
.
shared
(
n
p
.
random
.
rand
(
3
,
6
)
.
astype
(
config
.
floatX
),
'y'
)
# should work
...
...
@@ -157,7 +157,7 @@ class TestComputeTestValue(unittest.TestCase):
assert
_allclose
(
f
(),
z
.
tag
.
test_value
)
# 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
)
finally
:
theano
.
config
.
compute_test_value
=
orig_compute_test_value
...
...
@@ -167,7 +167,7 @@ class TestComputeTestValue(unittest.TestCase):
try
:
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'
)
# should work
...
...
@@ -184,8 +184,8 @@ class TestComputeTestValue(unittest.TestCase):
try
:
theano
.
config
.
compute_test_value
=
'raise'
x
=
T
.
constant
(
n
umpy
.
random
.
rand
(
2
,
3
),
dtype
=
config
.
floatX
)
y
=
theano
.
shared
(
n
umpy
.
random
.
rand
(
3
,
6
)
.
astype
(
config
.
floatX
),
x
=
T
.
constant
(
n
p
.
random
.
rand
(
2
,
3
),
dtype
=
config
.
floatX
)
y
=
theano
.
shared
(
n
p
.
random
.
rand
(
3
,
6
)
.
astype
(
config
.
floatX
),
'y'
)
# should work
...
...
@@ -195,7 +195,7 @@ class TestComputeTestValue(unittest.TestCase):
assert
_allclose
(
f
(),
z
.
tag
.
test_value
)
# 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
)
finally
:
theano
.
config
.
compute_test_value
=
orig_compute_test_value
...
...
@@ -207,9 +207,9 @@ class TestComputeTestValue(unittest.TestCase):
x
=
T
.
fmatrix
(
'x'
)
# 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
.
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
)
finally
:
...
...
@@ -222,9 +222,9 @@ class TestComputeTestValue(unittest.TestCase):
try
:
config
.
compute_test_value
=
"raise"
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
.
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
)
finally
:
theano
.
config
.
compute_test_value
=
orig_compute_test_value
...
...
@@ -240,7 +240,7 @@ class TestComputeTestValue(unittest.TestCase):
k
=
T
.
iscalar
(
"k"
)
A
=
T
.
vector
(
"A"
)
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
):
return
prior_result
*
A
...
...
@@ -267,7 +267,7 @@ class TestComputeTestValue(unittest.TestCase):
k
=
T
.
iscalar
(
"k"
)
A
=
T
.
matrix
(
"A"
)
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
):
return
T
.
dot
(
prior_result
,
A
)
...
...
@@ -304,7 +304,7 @@ class TestComputeTestValue(unittest.TestCase):
k
=
T
.
iscalar
(
"k"
)
A
=
T
.
matrix
(
"A"
)
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
):
return
T
.
dot
(
prior_result
,
A
)
...
...
@@ -400,7 +400,7 @@ class TestComputeTestValue(unittest.TestCase):
try
:
theano
.
config
.
compute_test_value
=
'raise'
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
])
finally
:
...
...
theano/gof/tests/test_graph.py
浏览文件 @
466cdaa8
...
...
@@ -4,7 +4,7 @@ import pickle
import
unittest
from
nose.plugins.skip
import
SkipTest
import
numpy
import
numpy
as
np
from
theano
import
(
sparse
,
...
...
@@ -362,7 +362,7 @@ class TestAutoName:
r1
=
tensor
.
TensorType
(
dtype
=
'int32'
,
broadcastable
=
())(
'myvar'
)
r2
=
tensor
.
TensorVariable
(
tensor
.
TensorType
(
dtype
=
'int32'
,
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
r2
.
auto_name
==
"auto_"
+
str
(
autoname_id
+
1
)
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
import
os
import
numpy
import
numpy
as
np
import
theano
import
theano.tensor
as
T
...
...
@@ -19,20 +19,20 @@ def test_graph_opt_caching():
theano
.
config
.
cache_optimizations
=
True
a
=
T
.
fmatrix
(
'a'
)
b
=
T
.
fmatrix
(
'b'
)
c
=
theano
.
shared
(
n
umpy
.
ones
((
10
,
10
),
dtype
=
floatX
))
d
=
theano
.
shared
(
n
umpy
.
ones
((
10
,
10
),
dtype
=
floatX
))
c
=
theano
.
shared
(
n
p
.
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
)
f1
=
theano
.
function
([
a
,
b
],
e
,
mode
=
mode
)
m
=
T
.
fmatrix
(
'x1'
)
n
=
T
.
fmatrix
(
'x2'
)
p
=
theano
.
shared
(
n
umpy
.
ones
((
10
,
10
),
dtype
=
floatX
))
q
=
theano
.
shared
(
n
umpy
.
ones
((
10
,
10
),
dtype
=
floatX
))
p
=
theano
.
shared
(
n
p
.
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
)
f2
=
theano
.
function
([
m
,
n
],
j
,
mode
=
mode
)
in1
=
n
umpy
.
ones
((
10
,
10
),
dtype
=
floatX
)
in2
=
n
umpy
.
ones
((
10
,
10
),
dtype
=
floatX
)
in1
=
n
p
.
ones
((
10
,
10
),
dtype
=
floatX
)
in2
=
n
p
.
ones
((
10
,
10
),
dtype
=
floatX
)
assert
f1
(
in1
,
in2
)
==
f2
(
in1
,
in2
)
finally
:
theano
.
config
.
cache_optimizations
=
default
...
...
theano/gof/tests/test_lazy.py
浏览文件 @
466cdaa8
from
__future__
import
absolute_import
,
print_function
,
division
from
copy
import
deepcopy
import
numpy
import
numpy
as
np
import
theano
from
theano.gof.op
import
PureOp
...
...
@@ -154,13 +154,13 @@ def more_complex_test():
optimizer
=
'fast_run'
))
if
theano
.
config
.
vm
.
lazy
is
False
:
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
except
NotImplementedOp
.
E
:
pass
else
:
print
(
f
(
1
,
0
,
n
umpy
.
array
(
10
,
dtype
=
x1
.
dtype
),
0
))
assert
f
(
1
,
0
,
n
umpy
.
array
(
10
,
dtype
=
x1
.
dtype
),
0
)
==
20.5
print
(
f
(
1
,
0
,
n
p
.
array
(
10
,
dtype
=
x1
.
dtype
),
0
))
assert
f
(
1
,
0
,
n
p
.
array
(
10
,
dtype
=
x1
.
dtype
),
0
)
==
20.5
print
(
'... passed'
)
if
__name__
==
'__main__'
:
...
...
theano/gof/tests/test_link.py
浏览文件 @
466cdaa8
...
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
from
copy
import
deepcopy
import
unittest
import
numpy
import
numpy
as
np
import
theano
from
theano.gof
import
graph
...
...
@@ -203,18 +203,18 @@ def test_container_deepcopy():
# It seam that numpy.asarray(0.).astype(floatX) can return a numpy
# scalar with some NumPy Version. So we call numpy.asarray with
# the dtype parameter.
v
=
n
umpy
.
asarray
(
0.
,
dtype
=
theano
.
config
.
floatX
)
assert
isinstance
(
v
,
n
umpy
.
ndarray
),
type
(
v
)
v
=
n
p
.
asarray
(
0.
,
dtype
=
theano
.
config
.
floatX
)
assert
isinstance
(
v
,
n
p
.
ndarray
),
type
(
v
)
for
readonly
in
[
True
,
False
]:
c
=
Container
(
t
,
[
v
],
readonly
=
readonly
)
assert
isinstance
(
c
.
storage
[
0
],
n
umpy
.
ndarray
),
(
c
.
storage
[
0
],
type
(
c
.
storage
[
0
]))
assert
isinstance
(
c
.
storage
[
0
],
n
p
.
ndarray
),
(
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
==
c
.
type
.
dtype
,
(
c
.
storage
[
0
]
.
dtype
,
c
.
type
.
dtype
)
d
=
deepcopy
(
c
)
assert
isinstance
(
d
.
storage
[
0
],
n
umpy
.
ndarray
),
(
d
.
storage
[
0
],
type
(
d
.
storage
[
0
]))
assert
isinstance
(
d
.
storage
[
0
],
n
p
.
ndarray
),
(
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
==
c
.
type
.
dtype
,
(
d
.
storage
[
0
]
.
dtype
,
c
.
type
.
dtype
)
theano/gof/tests/test_op.py
浏览文件 @
466cdaa8
...
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
import
unittest
from
nose.plugins.skip
import
SkipTest
import
numpy
import
numpy
as
np
import
theano
import
theano.gof.op
as
op
...
...
@@ -181,7 +181,7 @@ class TestMakeThunk(unittest.TestCase):
o
.
owner
.
op
.
c_code
,
o
.
owner
,
'o'
,
[
'x'
],
'z'
,
{
'fail'
:
''
})
storage_map
=
{
i
:
[
n
umpy
.
int32
(
3
)],
storage_map
=
{
i
:
[
n
p
.
int32
(
3
)],
o
:
[
None
]}
compute_map
=
{
i
:
[
True
],
o
:
[
False
]}
...
...
@@ -218,7 +218,7 @@ class TestMakeThunk(unittest.TestCase):
o
.
owner
.
op
.
perform
,
o
.
owner
,
0
,
[
None
])
storage_map
=
{
i
:
[
n
umpy
.
int32
(
3
)],
storage_map
=
{
i
:
[
n
p
.
int32
(
3
)],
o
:
[
None
]}
compute_map
=
{
i
:
[
True
],
o
:
[
False
]}
...
...
@@ -251,9 +251,9 @@ class TestMakeThunk(unittest.TestCase):
x_input
=
T
.
dmatrix
(
'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
)
assert
n
umpy
.
allclose
(
inp
*
2
,
out
)
assert
n
p
.
allclose
(
inp
*
2
,
out
)
def
test_test_value_python_objects
():
...
...
@@ -262,33 +262,33 @@ def test_test_value_python_objects():
def
test_test_value_ndarray
():
x
=
n
umpy
.
zeros
((
5
,
5
))
x
=
n
p
.
zeros
((
5
,
5
))
v
=
op
.
get_test_value
(
x
)
assert
(
v
==
x
)
.
all
()
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
)
assert
n
umpy
.
all
(
v
==
numpy
.
zeros
((
5
,
5
)))
assert
n
p
.
all
(
v
==
np
.
zeros
((
5
,
5
)))
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
)
assert
n
umpy
.
all
(
v
==
numpy
.
zeros
((
5
,
5
)))
assert
n
p
.
all
(
v
==
np
.
zeros
((
5
,
5
)))
def
test_test_value_op
():
try
:
prev_value
=
config
.
compute_test_value
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
)
assert
n
umpy
.
allclose
(
v
,
numpy
.
zeros
((
5
,
5
)))
assert
n
p
.
allclose
(
v
,
np
.
zeros
((
5
,
5
)))
finally
:
config
.
compute_test_value
=
prev_value
...
...
@@ -337,8 +337,8 @@ def test_get_debug_values_success():
config
.
compute_test_value
=
mode
x
=
T
.
vector
()
x
.
tag
.
test_value
=
n
umpy
.
zeros
((
4
,),
dtype
=
config
.
floatX
)
y
=
n
umpy
.
zeros
((
5
,
5
))
x
.
tag
.
test_value
=
n
p
.
zeros
((
4
,),
dtype
=
config
.
floatX
)
y
=
n
p
.
zeros
((
5
,
5
))
iters
=
0
...
...
theano/gof/tests/test_types.py
浏览文件 @
466cdaa8
from
__future__
import
absolute_import
,
print_function
,
division
import
numpy
import
numpy
as
np
import
theano
from
theano
import
Op
,
Apply
...
...
@@ -72,7 +72,7 @@ def test_cdata():
# This should be a passthrough function for vectors
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
)
assert
(
v2
==
v
)
.
all
()
theano/gof/tests/test_vm.py
浏览文件 @
466cdaa8
...
...
@@ -5,7 +5,7 @@ import time
import
unittest
from
nose.plugins.skip
import
SkipTest
import
numpy
import
numpy
as
np
from
six
import
itervalues
from
theano
import
function
...
...
@@ -92,7 +92,7 @@ def test_speed():
def
time_numpy
():
steps_a
=
5
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
)
t0
=
time
.
time
()
...
...
@@ -195,7 +195,6 @@ def test_speed_lazy():
def
test_partial_function
():
import
numpy
as
np
from
theano.tests
import
unittest_tools
as
utt
def
check_partial_function
(
linker_name
):
...
...
@@ -234,7 +233,7 @@ def test_partial_function_with_updates():
def
check_updates
(
linker_name
):
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
(
optimizer
=
None
,
linker
=
linker_name
))
g
=
theano
.
function
([
x
],
[
x
-
6
],
updates
=
[(
y
,
y
+
3
)],
mode
=
Mode
(
...
...
@@ -283,7 +282,7 @@ if run_memory_usage_tests:
def
test_leak2
():
import
theano.sandbox.cuda
as
cuda
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
)
a
=
cuda
.
CudaNdarray
(
n
)
a
.
sum
()
...
...
@@ -338,7 +337,7 @@ if run_memory_usage_tests:
f_a
=
function
([
x
],
a
,
mode
=
Mode
(
optimizer
=
None
,
linker
=
linker
()))
inp
=
n
umpy
.
random
.
rand
(
1000000
)
inp
=
n
p
.
random
.
rand
(
1000000
)
for
i
in
xrange
(
100
):
f_a
(
inp
)
if
0
:
# this doesn't seem to work, prints 0 for everything
...
...
@@ -375,7 +374,7 @@ if run_memory_usage_tests:
f_a
=
function
([
x
],
a
,
mode
=
Mode
(
optimizer
=
None
,
linker
=
linker
()))
inp
=
n
umpy
.
random
.
rand
(
1000000
)
inp
=
n
p
.
random
.
rand
(
1000000
)
for
i
in
xrange
(
500
):
f_a
(
inp
)
print
(
1
)
...
...
theano/gof/utils.py
浏览文件 @
466cdaa8
...
...
@@ -3,7 +3,7 @@ import linecache
import
sys
import
traceback
import
numpy
import
numpy
as
np
from
six
import
iteritems
,
integer_types
,
string_types
,
with_metaclass
from
six.moves
import
StringIO
...
...
@@ -561,8 +561,8 @@ else:
try
:
return
hashlib
.
md5
(
msg
)
.
hexdigest
()
except
TypeError
:
assert
isinstance
(
msg
,
n
umpy
.
ndarray
)
return
hashlib
.
md5
(
n
umpy
.
getbuffer
(
msg
))
.
hexdigest
()
assert
isinstance
(
msg
,
n
p
.
ndarray
)
return
hashlib
.
md5
(
n
p
.
getbuffer
(
msg
))
.
hexdigest
()
def
hash_from_file
(
file_path
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论