Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7ae82b46
提交
7ae82b46
authored
11月 17, 2010
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Updates in tests due to allow_input_downcast=False, when floatX==float32
上级
fb9913c1
显示空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
172 行增加
和
107 行删除
+172
-107
test_builders.py
theano/compile/tests/test_builders.py
+10
-3
test_debugmode.py
theano/compile/tests/test_debugmode.py
+11
-6
test_function_module.py
theano/compile/tests/test_function_module.py
+2
-1
test_rng_mrg.py
theano/sandbox/test_rng_mrg.py
+13
-5
test_nnet.py
theano/tensor/nnet/tests/test_nnet.py
+7
-5
test_sigm.py
theano/tensor/nnet/tests/test_sigm.py
+4
-3
test_basic.py
theano/tensor/tests/test_basic.py
+8
-4
test_blas.py
theano/tensor/tests/test_blas.py
+12
-8
test_naacl09.py
theano/tensor/tests/test_naacl09.py
+11
-7
test_opt.py
theano/tensor/tests/test_opt.py
+31
-22
test_randomstreams.py
theano/tensor/tests/test_randomstreams.py
+29
-17
test_raw_random.py
theano/tensor/tests/test_raw_random.py
+8
-6
test_shared_randomstreams.py
theano/tensor/tests/test_shared_randomstreams.py
+3
-2
test_scan.py
theano/tests/test_scan.py
+23
-18
没有找到文件。
theano/compile/tests/test_builders.py
浏览文件 @
7ae82b46
import
unittest
import
unittest
from
theano
import
config
from
theano
import
gof
from
theano
import
gof
from
theano
import
compile
from
theano
import
compile
...
@@ -23,7 +24,9 @@ class T_OpFromGraph(unittest.TestCase):
...
@@ -23,7 +24,9 @@ class T_OpFromGraph(unittest.TestCase):
op
=
OpFromGraph
([
x
,
y
,
z
],
[
e
],
mode
=
'FAST_RUN'
)
op
=
OpFromGraph
([
x
,
y
,
z
],
[
e
],
mode
=
'FAST_RUN'
)
f
=
op
(
x
,
y
,
z
)
-
op
(
y
,
z
,
x
)
#(1+3*5=array of 16) - (3+1*5=array of 8)
f
=
op
(
x
,
y
,
z
)
-
op
(
y
,
z
,
x
)
#(1+3*5=array of 16) - (3+1*5=array of 8)
fn
=
function
([
x
,
y
,
z
],
f
)
fn
=
function
([
x
,
y
,
z
],
f
)
xv
,
yv
,
zv
=
N
.
ones
((
2
,
2
)),
N
.
ones
((
2
,
2
))
*
3
,
N
.
ones
((
2
,
2
))
*
5
xv
=
N
.
ones
((
2
,
2
),
dtype
=
config
.
floatX
)
yv
=
N
.
ones
((
2
,
2
),
dtype
=
config
.
floatX
)
*
3
zv
=
N
.
ones
((
2
,
2
),
dtype
=
config
.
floatX
)
*
5
print
function
,
function
.
__module__
print
function
,
function
.
__module__
print
fn
.
maker
.
env
.
toposort
()
print
fn
.
maker
.
env
.
toposort
()
print
fn
(
xv
,
yv
,
zv
)
print
fn
(
xv
,
yv
,
zv
)
...
@@ -36,7 +39,9 @@ class T_OpFromGraph(unittest.TestCase):
...
@@ -36,7 +39,9 @@ class T_OpFromGraph(unittest.TestCase):
op
=
OpFromGraph
([
x
,
y
],
[
e
],
mode
=
'FAST_RUN'
)
op
=
OpFromGraph
([
x
,
y
],
[
e
],
mode
=
'FAST_RUN'
)
f
=
op
(
x
,
op
(
y
,
z
))
f
=
op
(
x
,
op
(
y
,
z
))
fn
=
function
([
x
,
y
,
z
],
f
)
fn
=
function
([
x
,
y
,
z
],
f
)
xv
,
yv
,
zv
=
N
.
ones
((
2
,
3
)),
N
.
ones
((
3
,
4
))
*
3
,
N
.
ones
((
4
,
5
))
*
5
xv
=
N
.
ones
((
2
,
3
),
dtype
=
config
.
floatX
)
yv
=
N
.
ones
((
3
,
4
),
dtype
=
config
.
floatX
)
*
3
zv
=
N
.
ones
((
4
,
5
),
dtype
=
config
.
floatX
)
*
5
res
=
fn
(
xv
,
yv
,
zv
)
res
=
fn
(
xv
,
yv
,
zv
)
assert
res
.
shape
==
(
2
,
5
)
assert
res
.
shape
==
(
2
,
5
)
assert
numpy
.
all
(
180.0
==
res
)
assert
numpy
.
all
(
180.0
==
res
)
...
@@ -51,7 +56,9 @@ class T_OpFromGraph(unittest.TestCase):
...
@@ -51,7 +56,9 @@ class T_OpFromGraph(unittest.TestCase):
f
=
op
(
x
,
y
,
z
)
f
=
op
(
x
,
y
,
z
)
f
=
f
-
T
.
grad
(
T
.
sum
(
f
),
y
)
f
=
f
-
T
.
grad
(
T
.
sum
(
f
),
y
)
fn
=
function
([
x
,
y
,
z
],
f
)
fn
=
function
([
x
,
y
,
z
],
f
)
xv
,
yv
,
zv
=
N
.
ones
((
2
,
2
)),
N
.
ones
((
2
,
2
))
*
3
,
N
.
ones
((
2
,
2
))
*
5
xv
=
N
.
ones
((
2
,
2
),
dtype
=
config
.
floatX
)
yv
=
N
.
ones
((
2
,
2
),
dtype
=
config
.
floatX
)
*
3
zv
=
N
.
ones
((
2
,
2
),
dtype
=
config
.
floatX
)
*
5
assert
numpy
.
all
(
11.0
==
fn
(
xv
,
yv
,
zv
))
assert
numpy
.
all
(
11.0
==
fn
(
xv
,
yv
,
zv
))
...
...
theano/compile/tests/test_debugmode.py
浏览文件 @
7ae82b46
import
sys
import
sys
import
numpy
import
numpy
from
theano
import
config
from
theano
import
gof
from
theano
import
gof
import
theano
import
theano
import
theano.tensor
import
theano.tensor
...
@@ -447,23 +448,27 @@ class Test_check_isfinite(unittest.TestCase):
...
@@ -447,23 +448,27 @@ class Test_check_isfinite(unittest.TestCase):
g
=
theano
.
function
([
x
],
theano
.
tensor
.
log
(
x
),
mode
=
'DEBUG_MODE'
)
g
=
theano
.
function
([
x
],
theano
.
tensor
.
log
(
x
),
mode
=
'DEBUG_MODE'
)
# this should work
# this should work
f
(
numpy
.
log
([
3
,
4
,
5
]))
f
(
numpy
.
log
([
3
,
4
,
5
])
.
astype
(
config
.
floatX
)
)
# if TensorType.filter_checks_isfinite were true, these would raise ValueError
# if TensorType.filter_checks_isfinite were true, these would raise ValueError
# if not, DebugMode will check internally, and raise InvalidValueError
# if not, DebugMode will check internally, and raise InvalidValueError
# passing an invalid value as an input should trigger ValueError
# passing an invalid value as an input should trigger ValueError
self
.
failUnlessRaises
(
debugmode
.
InvalidValueError
,
f
,
numpy
.
log
([
3
,
-
4
,
5
]))
self
.
failUnlessRaises
(
debugmode
.
InvalidValueError
,
f
,
self
.
failUnlessRaises
(
debugmode
.
InvalidValueError
,
f
,
numpy
.
asarray
([
0
,
1.0
,
0
])
/
0
)
numpy
.
log
([
3
,
-
4
,
5
])
.
astype
(
config
.
floatX
))
self
.
failUnlessRaises
(
debugmode
.
InvalidValueError
,
f
,
numpy
.
asarray
([
1.0
,
1.0
,
1.0
])
/
0
)
self
.
failUnlessRaises
(
debugmode
.
InvalidValueError
,
f
,
(
numpy
.
asarray
([
0
,
1.0
,
0
])
/
0
)
.
astype
(
config
.
floatX
))
self
.
failUnlessRaises
(
debugmode
.
InvalidValueError
,
f
,
(
numpy
.
asarray
([
1.0
,
1.0
,
1.0
])
/
0
)
.
astype
(
config
.
floatX
))
# generating an invalid value internally should trigger InvalidValueError
# generating an invalid value internally should trigger InvalidValueError
self
.
failUnlessRaises
(
debugmode
.
InvalidValueError
,
g
,
[
3
,
-
4
,
5
])
self
.
failUnlessRaises
(
debugmode
.
InvalidValueError
,
g
,
numpy
.
asarray
([
3
,
-
4
,
5
],
dtype
=
config
.
floatX
))
# this should disable the exception
# this should disable the exception
theano
.
tensor
.
TensorType
.
filter_checks_isfinite
=
False
theano
.
tensor
.
TensorType
.
filter_checks_isfinite
=
False
theano
.
compile
.
mode
.
predefined_modes
[
'DEBUG_MODE'
]
.
check_isfinite
=
False
theano
.
compile
.
mode
.
predefined_modes
[
'DEBUG_MODE'
]
.
check_isfinite
=
False
# insert several Inf
# insert several Inf
f
(
numpy
.
asarray
(
[
1.0
,
1.0
,
1.0
])
/
0
)
f
(
numpy
.
asarray
(
numpy
.
asarray
([
1.0
,
1.0
,
1.0
])
/
0
,
dtype
=
config
.
floatX
)
)
def
test_check_isfinite_disabled
(
self
):
def
test_check_isfinite_disabled
(
self
):
...
...
theano/compile/tests/test_function_module.py
浏览文件 @
7ae82b46
...
@@ -467,7 +467,8 @@ class T_picklefunction(unittest.TestCase):
...
@@ -467,7 +467,8 @@ class T_picklefunction(unittest.TestCase):
assert
f2
.
container
[
s
]
.
storage
is
f1
.
container
[
s
]
.
storage
assert
f2
.
container
[
s
]
.
storage
is
f1
.
container
[
s
]
.
storage
# now put in a function with non-scalar
# now put in a function with non-scalar
f3
=
function
([
x
,
In
(
v
,
value
=
numpy
.
asarray
([
2
,
3
,
4.
]))],
x
+
v
)
v_value
=
numpy
.
asarray
([
2
,
3
,
4.
],
dtype
=
config
.
floatX
)
f3
=
function
([
x
,
In
(
v
,
value
=
v_value
)],
x
+
v
)
list_of_things
.
append
(
f3
)
list_of_things
.
append
(
f3
)
# try to pickle the entire things
# try to pickle the entire things
...
...
theano/sandbox/test_rng_mrg.py
浏览文件 @
7ae82b46
...
@@ -331,7 +331,10 @@ def test_uniform():
...
@@ -331,7 +331,10 @@ def test_uniform():
steps
=
int
(
1e3
)
steps
=
int
(
1e3
)
x
=
tensor
.
matrix
()
x
=
tensor
.
matrix
()
for
size
,
var_input
,
input
in
[(
sample_size
,[],[]),
(
x
.
shape
,[
x
],[
numpy
.
zeros
(
sample_size
)])]:
for
size
,
var_input
,
input
in
[
(
sample_size
,
[],
[]),
(
x
.
shape
,
[
x
],
[
numpy
.
zeros
(
sample_size
,
dtype
=
config
.
floatX
)])
]:
print
''
print
''
print
'ON CPU with size=(
%
s):'
%
str
(
size
)
print
'ON CPU with size=(
%
s):'
%
str
(
size
)
...
@@ -394,7 +397,10 @@ def test_binomial():
...
@@ -394,7 +397,10 @@ def test_binomial():
x
=
tensor
.
matrix
()
x
=
tensor
.
matrix
()
v
=
tensor
.
vector
()
v
=
tensor
.
vector
()
for
mean
in
[
0.1
,
0.5
]:
for
mean
in
[
0.1
,
0.5
]:
for
size
,
var_input
,
input
in
[(
sample_size
,[],[]),
(
x
.
shape
,[
x
],[
numpy
.
zeros
(
sample_size
)])]:
for
size
,
var_input
,
input
in
[
(
sample_size
,
[],
[]),
(
x
.
shape
,
[
x
],
[
numpy
.
zeros
(
sample_size
,
dtype
=
config
.
floatX
)])
]:
print
''
print
''
print
'ON CPU with size=(
%
s) and mean(
%
d):'
%
(
str
(
size
),
mean
)
print
'ON CPU with size=(
%
s) and mean(
%
d):'
%
(
str
(
size
),
mean
)
...
@@ -442,9 +448,11 @@ def test_normal0():
...
@@ -442,9 +448,11 @@ def test_normal0():
rtol
=.
01
rtol
=.
01
sample_size_odd
=
(
sample_size
[
0
],
sample_size
[
1
]
-
1
)
sample_size_odd
=
(
sample_size
[
0
],
sample_size
[
1
]
-
1
)
x
=
tensor
.
matrix
()
x
=
tensor
.
matrix
()
for
size
,
const_size
,
var_input
,
input
in
[(
sample_size
,
sample_size
,[],[]),
(
x
.
shape
,
sample_size
,[
x
],[
numpy
.
zeros
(
sample_size
)]),
for
size
,
const_size
,
var_input
,
input
in
[
(
sample_size_odd
,
sample_size_odd
,[],[]),
#test odd value
(
sample_size
,
sample_size
,
[],
[]),
(
x
.
shape
,
sample_size_odd
,[
x
],[
numpy
.
zeros
(
sample_size_odd
)]),
#test odd value
(
x
.
shape
,
sample_size
,
[
x
],
[
numpy
.
zeros
(
sample_size
,
dtype
=
config
.
floatX
)]),
(
sample_size_odd
,
sample_size_odd
,
[],
[]),
#test odd value
(
x
.
shape
,
sample_size_odd
,
[
x
],
[
numpy
.
zeros
(
sample_size_odd
,
dtype
=
config
.
floatX
)]),
#test odd value
]:
]:
print
''
print
''
print
'ON CPU:'
print
'ON CPU:'
...
...
theano/tensor/nnet/tests/test_nnet.py
浏览文件 @
7ae82b46
...
@@ -4,6 +4,7 @@ import numpy
...
@@ -4,6 +4,7 @@ import numpy
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
import
theano
import
theano
from
theano
import
config
from
theano
import
tensor
as
T
from
theano
import
tensor
as
T
from
theano
import
tensor
from
theano
import
tensor
from
theano
import
gof
from
theano
import
gof
...
@@ -62,7 +63,7 @@ class T_Softmax(unittest.TestCase):
...
@@ -62,7 +63,7 @@ class T_Softmax(unittest.TestCase):
x
=
T
.
vector
()
x
=
T
.
vector
()
f
=
theano
.
function
([
x
],
softmax
(
x
))
f
=
theano
.
function
([
x
],
softmax
(
x
))
xv
=
numpy
.
random
.
randn
(
6
)
xv
=
numpy
.
random
.
randn
(
6
)
.
astype
(
config
.
floatX
)
assert
numpy
.
allclose
(
f
(
xv
),
numpy
.
exp
(
xv
)
/
numpy
.
exp
(
xv
)
.
sum
())
assert
numpy
.
allclose
(
f
(
xv
),
numpy
.
exp
(
xv
)
/
numpy
.
exp
(
xv
)
.
sum
())
def
test_vector_grad
(
self
):
def
test_vector_grad
(
self
):
def
f
(
a
):
def
f
(
a
):
...
@@ -241,15 +242,16 @@ class T_CrossentropyCategorical1Hot(unittest.TestCase):
...
@@ -241,15 +242,16 @@ class T_CrossentropyCategorical1Hot(unittest.TestCase):
f
=
theano
.
function
([
x
,
one_of_n
],
xe
)
f
=
theano
.
function
([
x
,
one_of_n
],
xe
)
xe_val
=
f
(
numpy
.
asarray
([[
.
4
,
.
6
,
.
0
],
[
.
1
,
.
8
,
.
1
]]),
[
0
,
1
])
x_val
=
numpy
.
asarray
([[
.
4
,
.
6
,
.
0
],
[
.
1
,
.
8
,
.
1
]],
dtype
=
config
.
floatX
)
xe_val
=
f
(
x_val
,
[
0
,
1
])
assert
numpy
.
allclose
(
xe_val
,
-
numpy
.
log
([
.
4
,
.
8
]))
assert
numpy
.
allclose
(
xe_val
,
-
numpy
.
log
([
.
4
,
.
8
]))
def
oplike
(
x
):
def
oplike
(
x
):
return
op
(
x
,
[
0
,
1
])
return
op
(
x
,
[
0
,
1
])
tensor
.
verify_grad
(
oplike
,
[
numpy
.
asarray
([[
.
4
,
.
6
,
.
0
],
[
.
1
,
.
8
,
.
1
]])],
tensor
.
verify_grad
(
oplike
,
[
x_val
],
rng
=
numpy
.
random
)
rng
=
numpy
.
random
)
def
test_softmax_optimizations
(
self
):
def
test_softmax_optimizations
(
self
):
...
@@ -958,7 +960,7 @@ class Test_softmax_opt:
...
@@ -958,7 +960,7 @@ class Test_softmax_opt:
print
'==='
print
'==='
assert
len
(
f_ops
)
==
1
assert
len
(
f_ops
)
==
1
assert
softmax
in
f_ops
assert
softmax
in
f_ops
f
(
self
.
rng
.
rand
(
3
,
4
))
f
(
self
.
rng
.
rand
(
3
,
4
)
.
astype
(
config
.
floatX
)
)
def
test_grad
(
self
):
def
test_grad
(
self
):
c
=
T
.
matrix
()
c
=
T
.
matrix
()
...
...
theano/tensor/nnet/tests/test_sigm.py
浏览文件 @
7ae82b46
import
unittest
import
unittest
import
theano
import
theano
from
theano
import
tensor
as
T
from
theano
import
tensor
as
T
from
theano
import
config
from
theano
import
gof
from
theano
import
gof
import
numpy
import
numpy
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
...
@@ -97,7 +98,7 @@ class T_softplus_opts(unittest.TestCase):
...
@@ -97,7 +98,7 @@ class T_softplus_opts(unittest.TestCase):
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,
theano
.
scalar
.
Neg
)
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,
theano
.
scalar
.
Neg
)
assert
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
theano
.
tensor
.
nnet
.
sigm
.
ScalarSoftplus
)
assert
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
theano
.
tensor
.
nnet
.
sigm
.
ScalarSoftplus
)
assert
isinstance
(
topo
[
2
]
.
op
.
scalar_op
,
theano
.
scalar
.
Neg
)
assert
isinstance
(
topo
[
2
]
.
op
.
scalar_op
,
theano
.
scalar
.
Neg
)
f
(
numpy
.
random
.
rand
(
54
))
f
(
numpy
.
random
.
rand
(
54
)
.
astype
(
config
.
floatX
)
)
def
test_log1msigm_to_softplus
(
self
):
def
test_log1msigm_to_softplus
(
self
):
x
=
T
.
vector
()
x
=
T
.
vector
()
...
@@ -108,7 +109,7 @@ class T_softplus_opts(unittest.TestCase):
...
@@ -108,7 +109,7 @@ class T_softplus_opts(unittest.TestCase):
assert
len
(
topo
)
==
2
assert
len
(
topo
)
==
2
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,
theano
.
tensor
.
nnet
.
sigm
.
ScalarSoftplus
)
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,
theano
.
tensor
.
nnet
.
sigm
.
ScalarSoftplus
)
assert
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
theano
.
scalar
.
Neg
)
assert
isinstance
(
topo
[
1
]
.
op
.
scalar_op
,
theano
.
scalar
.
Neg
)
f
(
numpy
.
random
.
rand
(
54
))
f
(
numpy
.
random
.
rand
(
54
)
.
astype
(
config
.
floatX
)
)
def
test_log1pexp_to_softplus
(
self
):
def
test_log1pexp_to_softplus
(
self
):
m
=
theano
.
config
.
mode
m
=
theano
.
config
.
mode
...
@@ -122,4 +123,4 @@ class T_softplus_opts(unittest.TestCase):
...
@@ -122,4 +123,4 @@ class T_softplus_opts(unittest.TestCase):
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
assert
len
(
topo
)
==
1
assert
len
(
topo
)
==
1
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,
theano
.
tensor
.
nnet
.
sigm
.
ScalarSoftplus
)
assert
isinstance
(
topo
[
0
]
.
op
.
scalar_op
,
theano
.
tensor
.
nnet
.
sigm
.
ScalarSoftplus
)
f
(
numpy
.
random
.
rand
(
54
))
f
(
numpy
.
random
.
rand
(
54
)
.
astype
(
config
.
floatX
)
)
theano/tensor/tests/test_basic.py
浏览文件 @
7ae82b46
...
@@ -32,8 +32,12 @@ except ImportError:
...
@@ -32,8 +32,12 @@ except ImportError:
### seed random number generator so that unittests are deterministic ###
### seed random number generator so that unittests are deterministic ###
utt
.
seed_rng
()
utt
.
seed_rng
()
def
inplace_func
(
inputs
,
outputs
,
mode
=
get_default_mode
()):
def
inplace_func
(
inputs
,
outputs
,
mode
=
get_default_mode
(),
return
function
(
inputs
,
outputs
,
mode
=
mode
,
accept_inplace
=
True
)
allow_input_downcast
=
False
):
return
function
(
inputs
,
outputs
,
mode
=
mode
,
allow_input_downcast
=
allow_input_downcast
,
accept_inplace
=
True
)
def
eval_outputs
(
outputs
):
def
eval_outputs
(
outputs
):
variables
=
inplace_func
([],
outputs
)()
variables
=
inplace_func
([],
outputs
)()
...
@@ -2437,7 +2441,7 @@ class T_op_cache(unittest.TestCase):
...
@@ -2437,7 +2441,7 @@ class T_op_cache(unittest.TestCase):
fn_py
=
inplace_func
([
v
],
gv
)
fn_py
=
inplace_func
([
v
],
gv
)
fn_c_or_py
=
inplace_func
([
v
],
gv
)
fn_c_or_py
=
inplace_func
([
v
],
gv
)
a
=
numpy
.
random
.
rand
(
5
,
2
)
a
=
numpy
.
random
.
rand
(
5
,
2
)
.
astype
(
config
.
floatX
)
self
.
failUnless
(
numpy
.
all
(
fn_py
(
a
)
==
fn_c_or_py
(
a
)))
self
.
failUnless
(
numpy
.
all
(
fn_py
(
a
)
==
fn_c_or_py
(
a
)))
...
@@ -3168,7 +3172,7 @@ def test_default_state():
...
@@ -3168,7 +3172,7 @@ def test_default_state():
assert
f
(
3
)
==
15
assert
f
(
3
)
==
15
f
[
'x'
]
=
None
f
[
'x'
]
=
None
assert
numpy
.
allclose
(
f
(
1
),
4.8
)
assert
numpy
.
allclose
(
f
(
1
),
4.8
)
assert
numpy
.
allclose
(
f
(
2.2
),
7
)
assert
numpy
.
allclose
(
f
(
numpy
.
asarray
(
2.2
,
dtype
=
config
.
floatX
)
),
7
)
def
test_autocast
():
def
test_autocast
():
orig_autocast
=
autocast_float
.
dtypes
orig_autocast
=
autocast_float
.
dtypes
...
...
theano/tensor/tests/test_blas.py
浏览文件 @
7ae82b46
...
@@ -314,14 +314,18 @@ class Warning(Exception):
...
@@ -314,14 +314,18 @@ class Warning(Exception):
def
just_gemm
(
i
,
o
,
ishapes
=
[(
4
,
3
),
(
3
,
5
),
(
4
,
5
),
(),
()],
max_graphlen
=
0
):
def
just_gemm
(
i
,
o
,
ishapes
=
[(
4
,
3
),
(
3
,
5
),
(
4
,
5
),
(),
()],
max_graphlen
=
0
):
try
:
try
:
f
=
inplace_func
([
Param
(
ii
,
mutable
=
True
)
for
ii
in
i
],
o
,
mode
=
'FAST_RUN'
)
f
=
inplace_func
(
[
Param
(
ii
,
mutable
=
True
,
allow_downcast
=
True
)
for
ii
in
i
],
o
,
mode
=
'FAST_RUN'
)
at_least_one_gemm
=
False
at_least_one_gemm
=
False
for
node
in
f
.
maker
.
env
.
nodes
:
for
node
in
f
.
maker
.
env
.
nodes
:
if
node
.
op
==
T
.
dot
:
raise
Warning
(
'dot not changed to gemm_inplace in graph'
)
if
node
.
op
==
T
.
dot
:
raise
Warning
(
'dot not changed to gemm_inplace in graph'
)
if
node
.
op
==
_dot22
:
raise
Warning
(
'_dot22 not changed to gemm_inplace in graph'
)
if
node
.
op
==
_dot22
:
raise
Warning
(
'_dot22 not changed to gemm_inplace in graph'
)
if
node
.
op
==
gemm_inplace
:
at_least_one_gemm
=
True
if
node
.
op
==
gemm_inplace
:
at_least_one_gemm
=
True
assert
at_least_one_gemm
assert
at_least_one_gemm
g
=
inplace_func
(
i
,
o
,
mode
=
compile
.
Mode
(
linker
=
'py'
,
optimizer
=
None
))
g
=
inplace_func
(
i
,
o
,
mode
=
compile
.
Mode
(
linker
=
'py'
,
optimizer
=
None
),
allow_input_downcast
=
True
)
for
node
in
g
.
maker
.
env
.
nodes
:
for
node
in
g
.
maker
.
env
.
nodes
:
if
node
.
op
==
gemm_inplace
:
raise
Exception
(
'gemm_inplace in original graph'
)
if
node
.
op
==
gemm_inplace
:
raise
Exception
(
'gemm_inplace in original graph'
)
...
@@ -568,8 +572,8 @@ def test_dot22():
...
@@ -568,8 +572,8 @@ def test_dot22():
f
=
theano
.
function
([
a
,
b
],
T
.
dot
(
a
,
b
),
mode
=
mode_blas_opt
)
f
=
theano
.
function
([
a
,
b
],
T
.
dot
(
a
,
b
),
mode
=
mode_blas_opt
)
topo
=
f
.
maker
.
env
.
toposort
()
topo
=
f
.
maker
.
env
.
toposort
()
assert
_dot22
in
[
x
.
op
for
x
in
topo
]
assert
_dot22
in
[
x
.
op
for
x
in
topo
]
av
=
numpy
.
random
.
rand
(
5
,
5
)
av
=
numpy
.
random
.
rand
(
5
,
5
)
.
astype
(
config
.
floatX
)
bv
=
numpy
.
random
.
rand
(
5
,
5
)
bv
=
numpy
.
random
.
rand
(
5
,
5
)
.
astype
(
config
.
floatX
)
f
(
av
,
bv
)
f
(
av
,
bv
)
def
test_dot22scalar
():
def
test_dot22scalar
():
...
@@ -581,9 +585,9 @@ def test_dot22scalar():
...
@@ -581,9 +585,9 @@ def test_dot22scalar():
a
=
T
.
matrix
()
a
=
T
.
matrix
()
b
=
T
.
matrix
()
b
=
T
.
matrix
()
c
=
T
.
matrix
()
c
=
T
.
matrix
()
av
=
numpy
.
random
.
rand
(
5
,
5
)
av
=
numpy
.
random
.
rand
(
5
,
5
)
.
astype
(
config
.
floatX
)
bv
=
numpy
.
random
.
rand
(
5
,
5
)
bv
=
numpy
.
random
.
rand
(
5
,
5
)
.
astype
(
config
.
floatX
)
cv
=
numpy
.
random
.
rand
(
5
,
5
)
cv
=
numpy
.
random
.
rand
(
5
,
5
)
.
astype
(
config
.
floatX
)
if
True
:
if
True
:
f
=
theano
.
function
([
a
,
b
],
0.2
*
T
.
dot
(
a
,
b
),
mode
=
mode_blas_opt
)
f
=
theano
.
function
([
a
,
b
],
0.2
*
T
.
dot
(
a
,
b
),
mode
=
mode_blas_opt
)
...
@@ -651,4 +655,4 @@ def test_dot_w_self():
...
@@ -651,4 +655,4 @@ def test_dot_w_self():
f
=
theano
.
function
([
B
],
p
,
updates
=
{
A
:
A
-
grad
[
0
]}
)
f
=
theano
.
function
([
B
],
p
,
updates
=
{
A
:
A
-
grad
[
0
]}
)
# tests correctness in debugmode
# tests correctness in debugmode
f
(
numpy
.
asarray
([[
0
,
1
],
[
2
,
3
]]))
f
(
numpy
.
asarray
([[
0
,
1
],
[
2
,
3
]]
,
dtype
=
config
.
floatX
))
theano/tensor/tests/test_naacl09.py
浏览文件 @
7ae82b46
...
@@ -5,6 +5,7 @@ from theano import tensor as T
...
@@ -5,6 +5,7 @@ from theano import tensor as T
from
theano.tensor
import
nnet
as
NN
from
theano.tensor
import
nnet
as
NN
from
theano.compile
import
module
from
theano.compile
import
module
from
theano.compile.mode
import
get_default_mode
from
theano.compile.mode
import
get_default_mode
from
theano
import
config
from
theano
import
tensor
as
T
,
sparse
as
S
from
theano
import
tensor
as
T
,
sparse
as
S
import
numpy
as
N
import
numpy
as
N
import
sys
import
sys
...
@@ -199,17 +200,20 @@ class QuadraticDenoisingAA(module.Module):
...
@@ -199,17 +200,20 @@ class QuadraticDenoisingAA(module.Module):
sz
=
(
input_size
,
hidden_size
)
sz
=
(
input_size
,
hidden_size
)
inf
=
1
/
N
.
sqrt
(
input_size
)
inf
=
1
/
N
.
sqrt
(
input_size
)
hif
=
1
/
N
.
sqrt
(
hidden_size
)
hif
=
1
/
N
.
sqrt
(
hidden_size
)
obj
.
w1
=
R
.
uniform
(
size
=
sz
,
low
=
-
inf
,
high
=
inf
)
obj
.
w1
=
N
.
asarray
(
R
.
uniform
(
size
=
sz
,
low
=
-
inf
,
high
=
inf
),
dtype
=
config
.
floatX
)
if
not
self
.
tie_weights
:
if
not
self
.
tie_weights
:
obj
.
w2
=
R
.
uniform
(
size
=
list
(
reversed
(
sz
)),
low
=
-
hif
,
high
=
hif
)
obj
.
w2
=
N
.
asarray
(
obj
.
b1
=
N
.
zeros
(
hidden_size
)
R
.
uniform
(
size
=
list
(
reversed
(
sz
)),
low
=-
hif
,
high
=
hif
),
obj
.
b2
=
N
.
zeros
(
input_size
)
dtype
=
config
.
floatX
)
obj
.
b1
=
N
.
zeros
(
hidden_size
,
dtype
=
config
.
floatX
)
obj
.
b2
=
N
.
zeros
(
input_size
,
dtype
=
config
.
floatX
)
obj
.
qfilters
=
[
R
.
uniform
(
size
=
sz
,
low
=
-
inf
,
high
=
inf
)
*
qfilter_relscale
\
obj
.
qfilters
=
[
R
.
uniform
(
size
=
sz
,
low
=
-
inf
,
high
=
inf
)
*
qfilter_relscale
\
for
qf
in
self
.
qfilters
]
for
qf
in
self
.
qfilters
]
if
seed
is
not
None
:
if
seed
is
not
None
:
obj
.
random
.
seed
(
seed
)
obj
.
random
.
seed
(
seed
)
obj
.
lr
=
lr
obj
.
lr
=
N
.
asarray
(
lr
,
dtype
=
config
.
floatX
)
obj
.
__hide__
=
[
'params'
]
obj
.
__hide__
=
[
'params'
]
...
@@ -251,7 +255,7 @@ class SigmoidXEQuadraticDenoisingAA(QuadraticDenoisingAA):
...
@@ -251,7 +255,7 @@ class SigmoidXEQuadraticDenoisingAA(QuadraticDenoisingAA):
def
_instance_initialize
(
self
,
obj
,
input_size
,
hidden_size
,
noise_level
,
seed
,
lr
,
qfilter_relscale
):
def
_instance_initialize
(
self
,
obj
,
input_size
,
hidden_size
,
noise_level
,
seed
,
lr
,
qfilter_relscale
):
# obj.l2_coef = 0.0
# obj.l2_coef = 0.0
obj
.
noise_level
=
noise_level
obj
.
noise_level
=
N
.
asarray
(
noise_level
,
dtype
=
config
.
floatX
)
super
(
SigmoidXEQuadraticDenoisingAA
,
self
)
.
_instance_initialize
(
obj
,
input_size
,
hidden_size
,
seed
,
lr
,
qfilter_relscale
)
super
(
SigmoidXEQuadraticDenoisingAA
,
self
)
.
_instance_initialize
(
obj
,
input_size
,
hidden_size
,
seed
,
lr
,
qfilter_relscale
)
QDAA
=
SigmoidXEQuadraticDenoisingAA
QDAA
=
SigmoidXEQuadraticDenoisingAA
...
@@ -438,7 +442,7 @@ class ConvolutionalMLP(module.FancyModule):
...
@@ -438,7 +442,7 @@ class ConvolutionalMLP(module.FancyModule):
self
.
hidden_representation_size
=
hidden_representation_size
self
.
hidden_representation_size
=
hidden_representation_size
self
.
output_size
=
output_size
self
.
output_size
=
output_size
self
.
lr
=
lr
self
.
lr
=
N
.
asarray
(
lr
,
dtype
=
config
.
floatX
)
# for layer in obj.layers:
# for layer in obj.layers:
# if layer.lr is None:
# if layer.lr is None:
# layer.lr = lr
# layer.lr = lr
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
7ae82b46
...
@@ -9,6 +9,7 @@ from nose.plugins.skip import SkipTest
...
@@ -9,6 +9,7 @@ from nose.plugins.skip import SkipTest
from
numpy.testing.noseclasses
import
KnownFailureTest
from
numpy.testing.noseclasses
import
KnownFailureTest
import
theano
import
theano
from
theano
import
config
from
theano
import
gof
from
theano
import
gof
from
theano.tensor.opt
import
*
from
theano.tensor.opt
import
*
from
theano
import
tensor
#do not use, there is an import * below that hides it
from
theano
import
tensor
#do not use, there is an import * below that hides it
...
@@ -109,9 +110,14 @@ class test_greedy_distribute(unittest.TestCase):
...
@@ -109,9 +110,14 @@ class test_greedy_distribute(unittest.TestCase):
f
=
function
([
s
,
eps
,
x
,
y
],
r
**
2
)
f
=
function
([
s
,
eps
,
x
,
y
],
r
**
2
)
r0
=
f
(
4
,
1.e-6
,
[
1.5
,
2
],
[
2.3
,
3.1
])
s_val
=
numpy
.
asarray
(
4
,
dtype
=
config
.
floatX
)
r1
=
f
(
4
,
1.e-6
,
[
1.5
,
2
],
[
2.3
,
3.1
])
eps_val
=
numpy
.
asarray
(
1.e-6
,
dtype
=
config
.
floatX
)
r2
=
f
(
4
,
1.e-6
,
[
1.5
,
2
],
[
2.3
,
3.1
])
x_val
=
numpy
.
asarray
([
1.5
,
2
],
dtype
=
config
.
floatX
)
y_val
=
numpy
.
asarray
([
2.3
,
3.1
],
dtype
=
config
.
floatX
)
r0
=
f
(
s_val
,
eps_val
,
x_val
,
y_val
)
r1
=
f
(
s_val
,
eps_val
,
x_val
,
y_val
)
r2
=
f
(
s_val
,
eps_val
,
x_val
,
y_val
)
assert
numpy
.
all
(
r0
==
r1
)
assert
numpy
.
all
(
r0
==
r1
)
assert
numpy
.
all
(
r0
==
r2
)
assert
numpy
.
all
(
r0
==
r2
)
...
@@ -614,9 +620,9 @@ class test_canonize(unittest.TestCase):
...
@@ -614,9 +620,9 @@ class test_canonize(unittest.TestCase):
def
test_local_merge_abs
():
def
test_local_merge_abs
():
x
,
y
,
z
=
T
.
matrices
(
'xyz'
)
x
,
y
,
z
=
T
.
matrices
(
'xyz'
)
x_val
=
numpy
.
random
.
rand
(
5
,
5
)
x_val
=
numpy
.
random
.
rand
(
5
,
5
)
.
astype
(
config
.
floatX
)
y_val
=
numpy
.
random
.
rand
(
5
,
5
)
y_val
=
numpy
.
random
.
rand
(
5
,
5
)
.
astype
(
config
.
floatX
)
z_val
=
numpy
.
random
.
rand
(
5
,
5
)
z_val
=
numpy
.
random
.
rand
(
5
,
5
)
.
astype
(
config
.
floatX
)
mode
=
theano
.
config
.
mode
mode
=
theano
.
config
.
mode
if
mode
==
"FAST_COMPILE"
:
if
mode
==
"FAST_COMPILE"
:
mode
=
"FAST_RUN"
mode
=
"FAST_RUN"
...
@@ -1211,7 +1217,8 @@ class test_shapeoptimizer(unittest.TestCase):
...
@@ -1211,7 +1217,8 @@ class test_shapeoptimizer(unittest.TestCase):
# Without the optimization
# Without the optimization
f
=
theano
.
function
([
x
],
ins_x
.
shape
,
mode
=
mode
)
f
=
theano
.
function
([
x
],
ins_x
.
shape
,
mode
=
mode
)
assert
numpy
.
all
(
f
(
rng
.
randn
(
3
,
4
,
7
))
==
[
3
,
4
,
7
])
xval
=
rng
.
randn
(
3
,
4
,
7
)
.
astype
(
config
.
floatX
)
assert
numpy
.
all
(
f
(
xval
)
==
[
3
,
4
,
7
])
f_ops
=
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
f_ops
=
[
node
.
op
for
node
in
f
.
maker
.
env
.
toposort
()]
assert
len
(
f_ops
)
==
5
assert
len
(
f_ops
)
==
5
assert
identity_noshape
in
f_ops
assert
identity_noshape
in
f_ops
...
@@ -1224,7 +1231,8 @@ class test_shapeoptimizer(unittest.TestCase):
...
@@ -1224,7 +1231,8 @@ class test_shapeoptimizer(unittest.TestCase):
# The identity_shape op is should not be needed anymore to compute
# The identity_shape op is should not be needed anymore to compute
# the shape
# the shape
g
=
theano
.
function
([
x
],
ins_x
.
shape
,
mode
=
mode
)
g
=
theano
.
function
([
x
],
ins_x
.
shape
,
mode
=
mode
)
assert
numpy
.
all
(
g
(
rng
.
randn
(
6
,
1
,
2
))
==
[
6
,
1
,
2
])
xval
=
rng
.
randn
(
6
,
1
,
2
)
.
astype
(
config
.
floatX
)
assert
numpy
.
all
(
g
(
xval
)
==
[
6
,
1
,
2
])
g_ops
=
[
node
.
op
for
node
in
g
.
maker
.
env
.
toposort
()]
g_ops
=
[
node
.
op
for
node
in
g
.
maker
.
env
.
toposort
()]
assert
len
(
g_ops
)
==
4
assert
len
(
g_ops
)
==
4
assert
identity_noshape
not
in
g_ops
assert
identity_noshape
not
in
g_ops
...
@@ -1234,7 +1242,8 @@ class test_shapeoptimizer(unittest.TestCase):
...
@@ -1234,7 +1242,8 @@ class test_shapeoptimizer(unittest.TestCase):
###test multiple level of op without infer_shape
###test multiple level of op without infer_shape
ins_x3
=
identity_noshape
(
identity_noshape
(
identity_noshape
(
x
)))
ins_x3
=
identity_noshape
(
identity_noshape
(
identity_noshape
(
x
)))
h
=
theano
.
function
([
x
],
ins_x3
.
shape
,
mode
=
mode
)
h
=
theano
.
function
([
x
],
ins_x3
.
shape
,
mode
=
mode
)
assert
numpy
.
all
(
h
(
rng
.
randn
(
6
,
1
,
2
))
==
[
6
,
1
,
2
])
xval
=
rng
.
randn
(
6
,
1
,
2
)
.
astype
(
config
.
floatX
)
assert
numpy
.
all
(
h
(
xval
)
==
[
6
,
1
,
2
])
h_ops
=
[
node
.
op
for
node
in
h
.
maker
.
env
.
toposort
()]
h_ops
=
[
node
.
op
for
node
in
h
.
maker
.
env
.
toposort
()]
assert
len
(
h_ops
)
==
4
assert
len
(
h_ops
)
==
4
assert
identity_noshape
not
in
h_ops
assert
identity_noshape
not
in
h_ops
...
@@ -1660,7 +1669,7 @@ class T_local_erf(unittest.TestCase):
...
@@ -1660,7 +1669,7 @@ class T_local_erf(unittest.TestCase):
self
.
mode
.
_optimizer
.
position_cutoff
=
1.50001
self
.
mode
.
_optimizer
.
position_cutoff
=
1.50001
def
test_local_one_plus_erf
(
self
):
def
test_local_one_plus_erf
(
self
):
val
=
numpy
.
asarray
([
-
30
,
-
3
,
-
2
,
-
1
,
0
,
1
,
2
,
3
,
30
])
val
=
numpy
.
asarray
([
-
30
,
-
3
,
-
2
,
-
1
,
0
,
1
,
2
,
3
,
30
]
,
dtype
=
config
.
floatX
)
x
=
T
.
vector
()
x
=
T
.
vector
()
f
=
theano
.
function
([
x
],
1
+
T
.
erf
(
x
),
mode
=
self
.
mode
)
f
=
theano
.
function
([
x
],
1
+
T
.
erf
(
x
),
mode
=
self
.
mode
)
...
@@ -1683,7 +1692,7 @@ class T_local_erf(unittest.TestCase):
...
@@ -1683,7 +1692,7 @@ class T_local_erf(unittest.TestCase):
f
(
val
)
f
(
val
)
def
test_local_one_minus_erf
(
self
):
def
test_local_one_minus_erf
(
self
):
val
=
numpy
.
asarray
([
-
30
,
-
3
,
-
2
,
-
1
,
0
,
1
,
2
,
3
,
30
])
val
=
numpy
.
asarray
([
-
30
,
-
3
,
-
2
,
-
1
,
0
,
1
,
2
,
3
,
30
]
,
dtype
=
config
.
floatX
)
x
=
T
.
vector
()
x
=
T
.
vector
()
f
=
theano
.
function
([
x
],
1
-
T
.
erf
(
x
),
mode
=
self
.
mode
)
f
=
theano
.
function
([
x
],
1
-
T
.
erf
(
x
),
mode
=
self
.
mode
)
...
@@ -1711,7 +1720,7 @@ class T_local_erf(unittest.TestCase):
...
@@ -1711,7 +1720,7 @@ class T_local_erf(unittest.TestCase):
print
f
(
val
)
print
f
(
val
)
def
test_local_erf_minus_one
(
self
):
def
test_local_erf_minus_one
(
self
):
val
=
numpy
.
asarray
([
-
30
,
-
3
,
-
2
,
-
1
,
0
,
1
,
2
,
3
,
30
])
val
=
numpy
.
asarray
([
-
30
,
-
3
,
-
2
,
-
1
,
0
,
1
,
2
,
3
,
30
]
,
dtype
=
config
.
floatX
)
x
=
T
.
vector
()
x
=
T
.
vector
()
f
=
theano
.
function
([
x
],
T
.
erf
(
x
)
-
1
,
mode
=
self
.
mode
)
f
=
theano
.
function
([
x
],
T
.
erf
(
x
)
-
1
,
mode
=
self
.
mode
)
...
@@ -1747,7 +1756,7 @@ class T_local_erfc(unittest.TestCase):
...
@@ -1747,7 +1756,7 @@ class T_local_erfc(unittest.TestCase):
def
test_local_one_minus_erfc
(
self
):
def
test_local_one_minus_erfc
(
self
):
""" test opt: 1-erfc(x) => erf(x) and -erfc(x)+1 => erf(x)
""" test opt: 1-erfc(x) => erf(x) and -erfc(x)+1 => erf(x)
"""
"""
val
=
numpy
.
asarray
([
-
30
,
-
3
,
-
2
,
-
1
,
0
,
1
,
2
,
3
,
30
])
val
=
numpy
.
asarray
([
-
30
,
-
3
,
-
2
,
-
1
,
0
,
1
,
2
,
3
,
30
]
,
dtype
=
config
.
floatX
)
x
=
T
.
vector
(
'x'
)
x
=
T
.
vector
(
'x'
)
f
=
theano
.
function
([
x
],
1
-
T
.
erfc
(
x
),
mode
=
self
.
mode
)
f
=
theano
.
function
([
x
],
1
-
T
.
erfc
(
x
),
mode
=
self
.
mode
)
...
@@ -1771,7 +1780,7 @@ class T_local_erfc(unittest.TestCase):
...
@@ -1771,7 +1780,7 @@ class T_local_erfc(unittest.TestCase):
def
test_local_erf_neg_minus_one
(
self
):
def
test_local_erf_neg_minus_one
(
self
):
""" test opt: (-1)+erfc(-x)=>erf(x)"""
""" test opt: (-1)+erfc(-x)=>erf(x)"""
val
=
numpy
.
asarray
([
-
30
,
-
3
,
-
2
,
-
1
,
0
,
1
,
2
,
3
,
30
])
val
=
numpy
.
asarray
([
-
30
,
-
3
,
-
2
,
-
1
,
0
,
1
,
2
,
3
,
30
]
,
dtype
=
config
.
floatX
)
x
=
T
.
vector
(
'x'
)
x
=
T
.
vector
(
'x'
)
f
=
theano
.
function
([
x
],
-
1
+
T
.
erfc
(
-
x
),
mode
=
self
.
mode
)
f
=
theano
.
function
([
x
],
-
1
+
T
.
erfc
(
-
x
),
mode
=
self
.
mode
)
...
@@ -1794,7 +1803,7 @@ class T_local_erfc(unittest.TestCase):
...
@@ -1794,7 +1803,7 @@ class T_local_erfc(unittest.TestCase):
if
theano
.
config
.
mode
in
[
"DebugMode"
,
"DEBUG_MODE"
,
"FAST_COMPILE"
]:
if
theano
.
config
.
mode
in
[
"DebugMode"
,
"DEBUG_MODE"
,
"FAST_COMPILE"
]:
#python mode don't like the inv(0)
#python mode don't like the inv(0)
val
.
remove
(
0
)
val
.
remove
(
0
)
val
=
numpy
.
asarray
(
val
)
val
=
numpy
.
asarray
(
val
,
dtype
=
config
.
floatX
)
x
=
T
.
vector
(
'x'
)
x
=
T
.
vector
(
'x'
)
#their is some nan that will happear in the graph for the log of the negatives values
#their is some nan that will happear in the graph for the log of the negatives values
...
@@ -1833,7 +1842,7 @@ class T_local_erfc(unittest.TestCase):
...
@@ -1833,7 +1842,7 @@ class T_local_erfc(unittest.TestCase):
# In float32 their is a plage of values close to 10 that we stabilize as it give bigger error then the stabilized version.
# In float32 their is a plage of values close to 10 that we stabilize as it give bigger error then the stabilized version.
# The orig value in float32 -30.0, the stab value -20.1 the orig value in float64 -18.1.
# The orig value in float32 -30.0, the stab value -20.1 the orig value in float64 -18.1.
val
.
remove
(
10
)
val
.
remove
(
10
)
val
=
numpy
.
asarray
(
val
)
val
=
numpy
.
asarray
(
val
,
dtype
=
config
.
floatX
)
x
=
T
.
vector
(
'x'
)
x
=
T
.
vector
(
'x'
)
y
=
T
.
vector
(
'y'
)
y
=
T
.
vector
(
'y'
)
...
@@ -1919,7 +1928,7 @@ class T_local_sum(unittest.TestCase):
...
@@ -1919,7 +1928,7 @@ class T_local_sum(unittest.TestCase):
def
test_local_sum_all_to_none
(
self
):
def
test_local_sum_all_to_none
(
self
):
a
=
T
.
tensor3
()
a
=
T
.
tensor3
()
input
=
numpy
.
arange
(
3
*
3
*
3
)
.
reshape
(
3
,
3
,
3
)
input
=
numpy
.
arange
(
3
*
3
*
3
,
dtype
=
config
.
floatX
)
.
reshape
(
3
,
3
,
3
)
f
=
theano
.
function
([
a
],
a
.
sum
(),
mode
=
self
.
mode
)
f
=
theano
.
function
([
a
],
a
.
sum
(),
mode
=
self
.
mode
)
assert
len
(
f
.
maker
.
env
.
nodes
)
==
1
assert
len
(
f
.
maker
.
env
.
nodes
)
==
1
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
())
assert
numpy
.
allclose
(
f
(
input
),
input
.
sum
())
...
@@ -1935,7 +1944,7 @@ class T_local_sum(unittest.TestCase):
...
@@ -1935,7 +1944,7 @@ class T_local_sum(unittest.TestCase):
def
test_local_sum_sum
(
self
):
def
test_local_sum_sum
(
self
):
a
=
T
.
tensor3
()
a
=
T
.
tensor3
()
input
=
numpy
.
arange
(
3
*
3
*
3
)
.
reshape
(
3
,
3
,
3
)
input
=
numpy
.
arange
(
3
*
3
*
3
,
dtype
=
config
.
floatX
)
.
reshape
(
3
,
3
,
3
)
dims
=
[(
0
,
0
),(
1
,
0
),(
2
,
0
),(
0
,
1
),(
1
,
1
),(
2
,
1
)]
dims
=
[(
0
,
0
),(
1
,
0
),(
2
,
0
),(
0
,
1
),(
1
,
1
),(
2
,
1
)]
for
d
,
dd
in
dims
:
for
d
,
dd
in
dims
:
...
@@ -2036,10 +2045,10 @@ class T_local_sum_dimshuffle(unittest.TestCase):
...
@@ -2036,10 +2045,10 @@ class T_local_sum_dimshuffle(unittest.TestCase):
]
]
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
a_val
=
rng
.
randn
(
2
,
2
)
a_val
=
rng
.
randn
(
2
,
2
)
.
astype
(
config
.
floatX
)
b_val
=
rng
.
randn
(
2
)
b_val
=
rng
.
randn
(
2
)
.
astype
(
config
.
floatX
)
c_val
=
rng
.
randn
(
2
,
2
,
2
)
c_val
=
rng
.
randn
(
2
,
2
,
2
)
.
astype
(
config
.
floatX
)
d_val
=
rng
.
randn
(
)
d_val
=
numpy
.
asarray
(
rng
.
randn
(),
config
.
floatX
)
for
i
,
s
in
enumerate
(
sums
):
for
i
,
s
in
enumerate
(
sums
):
print
i
print
i
...
...
theano/tensor/tests/test_randomstreams.py
浏览文件 @
7ae82b46
...
@@ -9,7 +9,7 @@ from theano.compile import Module, Method, Member
...
@@ -9,7 +9,7 @@ from theano.compile import Module, Method, Member
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
from
theano
import
tensor
from
theano
import
tensor
from
theano
import
compile
,
gof
from
theano
import
compile
,
config
,
gof
class
T_RandomStreams
(
unittest
.
TestCase
):
class
T_RandomStreams
(
unittest
.
TestCase
):
...
@@ -402,10 +402,12 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -402,10 +402,12 @@ class T_RandomStreams(unittest.TestCase):
seed_gen
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
seed_gen
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
numpy_rng
=
numpy
.
random
.
RandomState
(
int
(
seed_gen
.
randint
(
2
**
30
)))
numpy_rng
=
numpy
.
random
.
RandomState
(
int
(
seed_gen
.
randint
(
2
**
30
)))
val0
=
made
.
f
([
-
5
,
.
5
,
0
,
1
])
low_val0
=
numpy
.
asarray
([
-
5
,
.
5
,
0
,
1
],
dtype
=
config
.
floatX
)
val1
=
made
.
f
([
.
9
])
low_val1
=
numpy
.
asarray
([
.
9
],
dtype
=
config
.
floatX
)
numpy_val0
=
numpy_rng
.
uniform
(
low
=
[
-
5
,
.
5
,
0
,
1
],
high
=
1
)
val0
=
made
.
f
(
low_val0
)
numpy_val1
=
numpy_rng
.
uniform
(
low
=
[
.
9
],
high
=
1
)
val1
=
made
.
f
(
low_val1
)
numpy_val0
=
numpy_rng
.
uniform
(
low
=
low_val0
,
high
=
1
)
numpy_val1
=
numpy_rng
.
uniform
(
low
=
low_val1
,
high
=
1
)
assert
numpy
.
allclose
(
val0
,
numpy_val0
)
assert
numpy
.
allclose
(
val0
,
numpy_val0
)
assert
numpy
.
allclose
(
val1
,
numpy_val1
)
assert
numpy
.
allclose
(
val1
,
numpy_val1
)
...
@@ -447,13 +449,22 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -447,13 +449,22 @@ class T_RandomStreams(unittest.TestCase):
rng_seed
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
.
randint
(
2
**
30
)
rng_seed
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
.
randint
(
2
**
30
)
numpy_rng
=
numpy
.
random
.
RandomState
(
int
(
rng_seed
))
numpy_rng
=
numpy
.
random
.
RandomState
(
int
(
rng_seed
))
val0
=
made
.
f
([
-
5
,
.
5
,
0
,
1
],
[[
1.
]])
low_vals
=
[
val1
=
made
.
f
([
.
9
],
[[
1.
],
[
1.1
],
[
1.5
]])
numpy
.
asarray
([
-
5
,
.
5
,
0
,
1
],
dtype
=
config
.
floatX
),
val2
=
made
.
f
([
-
5
,
.
5
,
0
,
1
],
[[
1.
],
[
1.1
],
[
1.5
]])
numpy
.
asarray
([
.
9
],
dtype
=
config
.
floatX
),
numpy
.
asarray
([
-
5
,
.
5
,
0
,
1
],
dtype
=
config
.
floatX
)
]
numpy_val0
=
numpy_rng
.
uniform
(
low
=
[
-
5
,
.
5
,
0
,
1
],
high
=
[
1.
])
high_vals
=
[
numpy_val1
=
numpy_rng
.
uniform
(
low
=
[
.
9
],
high
=
[[
1.
],
[
1.1
],
[
1.5
]])
numpy
.
asarray
([[
1.
]],
dtype
=
config
.
floatX
),
numpy_val2
=
numpy_rng
.
uniform
(
low
=
[
-
5
,
.
5
,
0
,
1
],
high
=
[[
1.
],
[
1.1
],
[
1.5
]])
numpy
.
asarray
([[
1.
],
[
1.1
],
[
1.5
]],
dtype
=
config
.
floatX
),
numpy
.
asarray
([[
1.
],
[
1.1
],
[
1.5
]],
dtype
=
config
.
floatX
)
]
val0
=
made
.
f
(
low_vals
[
0
],
high_vals
[
0
])
val1
=
made
.
f
(
low_vals
[
1
],
high_vals
[
1
])
val2
=
made
.
f
(
low_vals
[
2
],
high_vals
[
2
])
numpy_val0
=
numpy_rng
.
uniform
(
low
=
low_vals
[
0
],
high
=
high_vals
[
0
])
numpy_val1
=
numpy_rng
.
uniform
(
low
=
low_vals
[
1
],
high
=
high_vals
[
1
])
numpy_val2
=
numpy_rng
.
uniform
(
low
=
low_vals
[
2
],
high
=
high_vals
[
2
])
assert
numpy
.
allclose
(
val0
,
numpy_val0
)
assert
numpy
.
allclose
(
val0
,
numpy_val0
)
assert
numpy
.
allclose
(
val1
,
numpy_val1
)
assert
numpy
.
allclose
(
val1
,
numpy_val1
)
...
@@ -473,8 +484,8 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -473,8 +484,8 @@ class T_RandomStreams(unittest.TestCase):
made
=
m
.
make
()
made
=
m
.
make
()
made
.
random
.
initialize
()
made
.
random
.
initialize
()
low_val
=
[
.
1
,
.
2
,
.
3
]
low_val
=
numpy
.
asarray
([
.
1
,
.
2
,
.
3
],
dtype
=
config
.
floatX
)
high_val
=
[
1.1
,
2.2
,
3.3
]
high_val
=
numpy
.
asarray
([
1.1
,
2.2
,
3.3
],
dtype
=
config
.
floatX
)
seed_gen
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
seed_gen
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
numpy_rng
=
numpy
.
random
.
RandomState
(
int
(
seed_gen
.
randint
(
2
**
30
)))
numpy_rng
=
numpy
.
random
.
RandomState
(
int
(
seed_gen
.
randint
(
2
**
30
)))
...
@@ -510,7 +521,7 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -510,7 +521,7 @@ class T_RandomStreams(unittest.TestCase):
made
.
random
.
initialize
()
made
.
random
.
initialize
()
n_val
=
[
1
,
2
,
3
]
n_val
=
[
1
,
2
,
3
]
prob_val
=
[
.
1
,
.
2
,
.
3
]
prob_val
=
numpy
.
asarray
([
.
1
,
.
2
,
.
3
],
dtype
=
config
.
floatX
)
seed_gen
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
seed_gen
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
numpy_rng
=
numpy
.
random
.
RandomState
(
int
(
seed_gen
.
randint
(
2
**
30
)))
numpy_rng
=
numpy
.
random
.
RandomState
(
int
(
seed_gen
.
randint
(
2
**
30
)))
...
@@ -546,7 +557,7 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -546,7 +557,7 @@ class T_RandomStreams(unittest.TestCase):
made
.
random
.
initialize
()
made
.
random
.
initialize
()
avg_val
=
[
1
,
2
,
3
]
avg_val
=
[
1
,
2
,
3
]
std_val
=
[
.
1
,
.
2
,
.
3
]
std_val
=
numpy
.
asarray
([
.
1
,
.
2
,
.
3
],
dtype
=
config
.
floatX
)
seed_gen
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
seed_gen
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
numpy_rng
=
numpy
.
random
.
RandomState
(
int
(
seed_gen
.
randint
(
2
**
30
)))
numpy_rng
=
numpy
.
random
.
RandomState
(
int
(
seed_gen
.
randint
(
2
**
30
)))
...
@@ -624,7 +635,8 @@ class T_RandomStreams(unittest.TestCase):
...
@@ -624,7 +635,8 @@ class T_RandomStreams(unittest.TestCase):
made
.
random
.
initialize
()
made
.
random
.
initialize
()
n_val
=
[
1
,
2
,
3
]
n_val
=
[
1
,
2
,
3
]
pvals_val
=
[[
.
1
,
.
9
],
[
.
2
,
.
8
],
[
.
3
,
.
7
]]
pvals_val
=
numpy
.
asarray
([[
.
1
,
.
9
],
[
.
2
,
.
8
],
[
.
3
,
.
7
]],
dtype
=
config
.
floatX
)
seed_gen
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
seed_gen
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
numpy_rng
=
numpy
.
random
.
RandomState
(
int
(
seed_gen
.
randint
(
2
**
30
)))
numpy_rng
=
numpy
.
random
.
RandomState
(
int
(
seed_gen
.
randint
(
2
**
30
)))
...
...
theano/tensor/tests/test_raw_random.py
浏览文件 @
7ae82b46
...
@@ -9,7 +9,7 @@ from theano.tensor import raw_random
...
@@ -9,7 +9,7 @@ from theano.tensor import raw_random
from
theano
import
tensor
from
theano
import
tensor
from
theano
import
compile
,
gof
from
theano
import
compile
,
config
,
gof
class
T_random_function
(
unittest
.
TestCase
):
class
T_random_function
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
@@ -494,7 +494,7 @@ class T_random_function(unittest.TestCase):
...
@@ -494,7 +494,7 @@ class T_random_function(unittest.TestCase):
rng_state0
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng_state0
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
numpy_rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
numpy_rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
post0
,
val0
=
f
(
rng_state0
,
[
-
5
,
.
5
,
0
,
1
])
post0
,
val0
=
f
(
rng_state0
,
[
-
5
,
.
5
,
0
,
1
])
post1
,
val1
=
f
(
post0
,
[
.
9
]
)
post1
,
val1
=
f
(
post0
,
as_floatX
([
.
9
])
)
numpy_val0
=
as_floatX
(
numpy_rng
.
uniform
(
low
=
[
-
5
,
.
5
,
0
,
1
],
high
=
1
))
numpy_val0
=
as_floatX
(
numpy_rng
.
uniform
(
low
=
[
-
5
,
.
5
,
0
,
1
],
high
=
1
))
numpy_val1
=
as_floatX
(
numpy_rng
.
uniform
(
low
=
as_floatX
([
.
9
]),
high
=
1
))
numpy_val1
=
as_floatX
(
numpy_rng
.
uniform
(
low
=
as_floatX
([
.
9
]),
high
=
1
))
...
@@ -597,7 +597,7 @@ class T_random_function(unittest.TestCase):
...
@@ -597,7 +597,7 @@ class T_random_function(unittest.TestCase):
f
=
compile
.
function
([
rng_R
,
n
,
prob
],
[
post_r
,
out
],
accept_inplace
=
True
)
f
=
compile
.
function
([
rng_R
,
n
,
prob
],
[
post_r
,
out
],
accept_inplace
=
True
)
n_val
=
[
1
,
2
,
3
]
n_val
=
[
1
,
2
,
3
]
prob_val
=
[
.
1
,
.
2
,
.
3
]
prob_val
=
numpy
.
asarray
([
.
1
,
.
2
,
.
3
],
dtype
=
config
.
floatX
)
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
numpy_rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
numpy_rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
...
@@ -628,14 +628,15 @@ class T_random_function(unittest.TestCase):
...
@@ -628,14 +628,15 @@ class T_random_function(unittest.TestCase):
assert
out
.
ndim
==
1
assert
out
.
ndim
==
1
f
=
compile
.
function
([
rng_R
,
avg
,
std
],
[
post_r
,
out
],
accept_inplace
=
True
)
f
=
compile
.
function
([
rng_R
,
avg
,
std
],
[
post_r
,
out
],
accept_inplace
=
True
)
def
as_floatX
(
thing
):
return
numpy
.
asarray
(
thing
,
dtype
=
theano
.
config
.
floatX
)
avg_val
=
[
1
,
2
,
3
]
avg_val
=
[
1
,
2
,
3
]
std_val
=
[
.
1
,
.
2
,
.
3
]
std_val
=
as_floatX
([
.
1
,
.
2
,
.
3
])
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
numpy_rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
numpy_rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
# Arguments of size (3,)
# Arguments of size (3,)
def
as_floatX
(
thing
):
return
numpy
.
asarray
(
thing
,
dtype
=
theano
.
config
.
floatX
)
rng0
,
val0
=
f
(
rng
,
avg_val
,
std_val
)
rng0
,
val0
=
f
(
rng
,
avg_val
,
std_val
)
numpy_val0
=
as_floatX
(
numpy_rng
.
normal
(
loc
=
as_floatX
(
avg_val
),
numpy_val0
=
as_floatX
(
numpy_rng
.
normal
(
loc
=
as_floatX
(
avg_val
),
scale
=
as_floatX
(
std_val
)))
scale
=
as_floatX
(
std_val
)))
...
@@ -705,6 +706,7 @@ class T_random_function(unittest.TestCase):
...
@@ -705,6 +706,7 @@ class T_random_function(unittest.TestCase):
n_val
=
[
1
,
2
,
3
]
n_val
=
[
1
,
2
,
3
]
pvals_val
=
[[
.
1
,
.
9
],
[
.
2
,
.
8
],
[
.
3
,
.
7
]]
pvals_val
=
[[
.
1
,
.
9
],
[
.
2
,
.
8
],
[
.
3
,
.
7
]]
pvals_val
=
numpy
.
asarray
(
pvals_val
,
dtype
=
config
.
floatX
)
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
numpy_rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
numpy_rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
...
...
theano/tensor/tests/test_shared_randomstreams.py
浏览文件 @
7ae82b46
...
@@ -9,7 +9,7 @@ from theano.tensor.shared_randomstreams import RandomStreams
...
@@ -9,7 +9,7 @@ from theano.tensor.shared_randomstreams import RandomStreams
from
theano
import
function
from
theano
import
function
from
theano
import
tensor
from
theano
import
tensor
from
theano
import
compile
,
gof
from
theano
import
compile
,
config
,
gof
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
...
@@ -466,7 +466,7 @@ class T_SharedRandomStreams(unittest.TestCase):
...
@@ -466,7 +466,7 @@ class T_SharedRandomStreams(unittest.TestCase):
f
=
function
([
n
,
prob
],
out
)
f
=
function
([
n
,
prob
],
out
)
n_val
=
[
1
,
2
,
3
]
n_val
=
[
1
,
2
,
3
]
prob_val
=
[
.
1
,
.
2
,
.
3
]
prob_val
=
numpy
.
asarray
([
.
1
,
.
2
,
.
3
],
dtype
=
config
.
floatX
)
seed_gen
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
seed_gen
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
numpy_rng
=
numpy
.
random
.
RandomState
(
int
(
seed_gen
.
randint
(
2
**
30
)))
numpy_rng
=
numpy
.
random
.
RandomState
(
int
(
seed_gen
.
randint
(
2
**
30
)))
...
@@ -566,6 +566,7 @@ class T_SharedRandomStreams(unittest.TestCase):
...
@@ -566,6 +566,7 @@ class T_SharedRandomStreams(unittest.TestCase):
n_val
=
[
1
,
2
,
3
]
n_val
=
[
1
,
2
,
3
]
pvals_val
=
[[
.
1
,
.
9
],
[
.
2
,
.
8
],
[
.
3
,
.
7
]]
pvals_val
=
[[
.
1
,
.
9
],
[
.
2
,
.
8
],
[
.
3
,
.
7
]]
pvals_val
=
numpy
.
asarray
(
pvals_val
,
dtype
=
config
.
floatX
)
seed_gen
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
seed_gen
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
numpy_rng
=
numpy
.
random
.
RandomState
(
int
(
seed_gen
.
randint
(
2
**
30
)))
numpy_rng
=
numpy
.
random
.
RandomState
(
int
(
seed_gen
.
randint
(
2
**
30
)))
...
...
theano/tests/test_scan.py
浏览文件 @
7ae82b46
...
@@ -2,7 +2,10 @@
...
@@ -2,7 +2,10 @@
import
unittest
import
unittest
import
theano
import
theano
import
numpy
import
numpy
from
theano
import
config
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
'''
'''
Questions and notes about scan that should be answered :
Questions and notes about scan that should be answered :
...
@@ -161,7 +164,7 @@ class T_Scan(unittest.TestCase):
...
@@ -161,7 +164,7 @@ class T_Scan(unittest.TestCase):
my_f
=
theano
.
function
([
state
,
n_steps
],
output
,
updates
=
updates
)
my_f
=
theano
.
function
([
state
,
n_steps
],
output
,
updates
=
updates
)
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
state
=
rng
.
uniform
(
)
state
=
asarrayX
(
rng
.
uniform
()
)
steps
=
5
steps
=
5
numpy_values
=
numpy
.
array
([
state
*
(
2
**
(
k
+
1
))
for
k
in
xrange
(
steps
)
])
numpy_values
=
numpy
.
array
([
state
*
(
2
**
(
k
+
1
))
for
k
in
xrange
(
steps
)
])
...
@@ -186,10 +189,10 @@ class T_Scan(unittest.TestCase):
...
@@ -186,10 +189,10 @@ class T_Scan(unittest.TestCase):
f2
=
theano
.
function
([
u
,
x0
,
W_in
,
W
],
output
,
updates
=
updates
)
f2
=
theano
.
function
([
u
,
x0
,
W_in
,
W
],
output
,
updates
=
updates
)
# get random initial values
# get random initial values
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
v_u
=
rng
.
uniform
(
size
=
(
4
,),
low
=
-
5.
,
high
=
5.
)
v_u
=
asarrayX
(
rng
.
uniform
(
size
=
(
4
,),
low
=
-
5.
,
high
=
5.
)
)
v_x0
=
rng
.
uniform
(
)
v_x0
=
asarrayX
(
rng
.
uniform
()
)
W
=
rng
.
uniform
(
)
W
=
asarrayX
(
rng
.
uniform
()
)
W_in
=
rng
.
uniform
(
)
W_in
=
asarrayX
(
rng
.
uniform
()
)
# compute the output in numpy
# compute the output in numpy
v_out
=
numpy
.
zeros
((
4
,))
v_out
=
numpy
.
zeros
((
4
,))
...
@@ -218,8 +221,8 @@ class T_Scan(unittest.TestCase):
...
@@ -218,8 +221,8 @@ class T_Scan(unittest.TestCase):
f3
=
theano
.
function
([
u
,
x0
],
output
,
updates
=
updates
)
f3
=
theano
.
function
([
u
,
x0
],
output
,
updates
=
updates
)
# get random initial values
# get random initial values
v_u
=
rng
.
uniform
(
size
=
(
4
,),
low
=
-
5.
,
high
=
5.
)
v_u
=
asarrayX
(
rng
.
uniform
(
size
=
(
4
,),
low
=
-
5.
,
high
=
5.
)
)
v_x0
=
rng
.
uniform
(
)
v_x0
=
asarrayX
(
rng
.
uniform
()
)
# compute the output i numpy
# compute the output i numpy
v_out
=
numpy
.
zeros
((
4
,))
v_out
=
numpy
.
zeros
((
4
,))
v_out
[
0
]
=
v_u
[
0
]
*
W_in
.
value
+
v_x0
*
W
.
value
v_out
[
0
]
=
v_u
[
0
]
*
W_in
.
value
+
v_x0
*
W
.
value
...
@@ -491,7 +494,8 @@ class T_Scan(unittest.TestCase):
...
@@ -491,7 +494,8 @@ class T_Scan(unittest.TestCase):
#TypeError: ('__array__() takes no arguments (1 given)', <theano.scan.Scan object at 0x3dbbf90>(?_steps, u1, u2, y0, y1, 0.0, W1, W2), 'Sequence id of Apply node=0')
#TypeError: ('__array__() takes no arguments (1 given)', <theano.scan.Scan object at 0x3dbbf90>(?_steps, u1, u2, y0, y1, 0.0, W1, W2), 'Sequence id of Apply node=0')
#
#
# This don't seam to be a theano related bug...
# This don't seam to be a theano related bug...
vu1
=
rng
.
rand
(
3
,
20
)
#vu1 = rng.rand(3,20)
vu1
=
asarrayX
(
rng
.
rand
(
3
,
20
))
W1
=
theano
.
shared
(
vW1
,
'W1'
)
W1
=
theano
.
shared
(
vW1
,
'W1'
)
W2
=
theano
.
shared
(
vW2
,
'W2'
)
W2
=
theano
.
shared
(
vW2
,
'W2'
)
...
@@ -632,7 +636,7 @@ class T_Scan(unittest.TestCase):
...
@@ -632,7 +636,7 @@ class T_Scan(unittest.TestCase):
f2
=
theano
.
function
([
u
],
outputs
,
updates
=
updates
)
f2
=
theano
.
function
([
u
],
outputs
,
updates
=
updates
)
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
v_u
=
rng
.
uniform
(
size
=
(
5
,),
low
=
-
5.
,
high
=
5.
)
v_u
=
rng
.
uniform
(
size
=
(
5
,),
low
=
-
5.
,
high
=
5.
)
.
astype
(
config
.
floatX
)
numpy_result
=
v_u
+
3
numpy_result
=
v_u
+
3
theano_result
=
f2
(
v_u
)
theano_result
=
f2
(
v_u
)
assert
numpy
.
allclose
(
theano_result
,
numpy_result
)
assert
numpy
.
allclose
(
theano_result
,
numpy_result
)
...
@@ -645,7 +649,7 @@ class T_Scan(unittest.TestCase):
...
@@ -645,7 +649,7 @@ class T_Scan(unittest.TestCase):
f
=
theano
.
function
([
v
],
abs_expr
,
updates
=
abs_updates
)
f
=
theano
.
function
([
v
],
abs_expr
,
updates
=
abs_updates
)
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
vals
=
rng
.
uniform
(
size
=
(
10
,),
low
=
-
5.
,
high
=
5.
)
vals
=
rng
.
uniform
(
size
=
(
10
,),
low
=
-
5.
,
high
=
5.
)
.
astype
(
config
.
floatX
)
abs_vals
=
abs
(
vals
)
abs_vals
=
abs
(
vals
)
theano_vals
=
f
(
vals
)
theano_vals
=
f
(
vals
)
assert
numpy
.
allclose
(
abs_vals
,
theano_vals
)
assert
numpy
.
allclose
(
abs_vals
,
theano_vals
)
...
@@ -665,10 +669,10 @@ class T_Scan(unittest.TestCase):
...
@@ -665,10 +669,10 @@ class T_Scan(unittest.TestCase):
f2
=
theano
.
function
([
u
,
x0
,
W_in
,
W
],
output
,
updates
=
updates
)
f2
=
theano
.
function
([
u
,
x0
,
W_in
,
W
],
output
,
updates
=
updates
)
# get random initial values
# get random initial values
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
v_u
=
rng
.
uniform
(
size
=
(
4
,),
low
=
-
5.
,
high
=
5.
)
v_u
=
asarrayX
(
rng
.
uniform
(
size
=
(
4
,),
low
=-
5.
,
high
=
5.
)
)
v_x0
=
rng
.
uniform
(
)
v_x0
=
asarrayX
(
rng
.
uniform
()
)
W
=
rng
.
uniform
(
)
W
=
asarrayX
(
rng
.
uniform
()
)
W_in
=
rng
.
uniform
(
)
W_in
=
asarrayX
(
rng
.
uniform
()
)
# compute the output in numpy
# compute the output in numpy
v_out
=
numpy
.
zeros
((
4
,))
v_out
=
numpy
.
zeros
((
4
,))
...
@@ -686,7 +690,7 @@ class T_Scan(unittest.TestCase):
...
@@ -686,7 +690,7 @@ class T_Scan(unittest.TestCase):
f
=
theano
.
function
([
v
,
s
],
result
,
updates
=
updates
)
f
=
theano
.
function
([
v
,
s
],
result
,
updates
=
updates
)
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
v_v
=
rng
.
uniform
(
size
=
(
5
,),
low
=
-
5.
,
high
=
5.
)
v_v
=
rng
.
uniform
(
size
=
(
5
,),
low
=
-
5.
,
high
=
5.
)
.
astype
(
config
.
floatX
)
assert
abs
(
numpy
.
sum
(
v_v
)
-
f
(
v_v
,
0.
))
<
1e-3
assert
abs
(
numpy
.
sum
(
v_v
)
-
f
(
v_v
,
0.
))
<
1e-3
...
@@ -705,7 +709,7 @@ class T_Scan(unittest.TestCase):
...
@@ -705,7 +709,7 @@ class T_Scan(unittest.TestCase):
grad_fn
=
theano
.
function
([
u
,
x0
,
W_in
,
W
],
[
gu
,
gx0
,
gW_in
,
gW
],
grad_fn
=
theano
.
function
([
u
,
x0
,
W_in
,
W
],
[
gu
,
gx0
,
gW_in
,
gW
],
updates
=
updates
,
no_default_updates
=
True
)
updates
=
updates
,
no_default_updates
=
True
)
cost_fn
=
theano
.
function
([
u
,
x0
,
W_in
,
W
],
cost
,
updates
=
updates
,
cost_fn
=
theano
.
function
([
u
,
x0
,
W_in
,
W
],
cost
,
updates
=
updates
,
no_default_updates
=
True
)
no_default_updates
=
True
,
allow_input_downcast
=
True
)
# get random initial values
# get random initial values
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
...
@@ -754,7 +758,8 @@ class T_Scan(unittest.TestCase):
...
@@ -754,7 +758,8 @@ class T_Scan(unittest.TestCase):
grad_fn
=
theano
.
function
([
u1
,
u2
,
x0
,
y0
,
W_in1
],
gparams
,
grad_fn
=
theano
.
function
([
u1
,
u2
,
x0
,
y0
,
W_in1
],
gparams
,
updates
=
updates
,
no_default_updates
=
True
)
updates
=
updates
,
no_default_updates
=
True
)
cost_fn
=
theano
.
function
([
u1
,
u2
,
x0
,
y0
,
W_in1
],
cost
,
cost_fn
=
theano
.
function
([
u1
,
u2
,
x0
,
y0
,
W_in1
],
cost
,
updates
=
updates
,
no_default_updates
=
True
)
updates
=
updates
,
no_default_updates
=
True
,
allow_input_downcast
=
True
)
num_grad
=
multiple_outputs_numeric_grad
(
cost_fn
,[
v_u1
,
v_u2
,
v_x0
,
v_y0
,
vW_in1
])
num_grad
=
multiple_outputs_numeric_grad
(
cost_fn
,[
v_u1
,
v_u2
,
v_x0
,
v_y0
,
vW_in1
])
analytic_grad
=
grad_fn
(
v_u1
,
v_u2
,
v_x0
,
v_y0
,
vW_in1
)
analytic_grad
=
grad_fn
(
v_u1
,
v_u2
,
v_x0
,
v_y0
,
vW_in1
)
...
@@ -954,7 +959,7 @@ class T_Scan(unittest.TestCase):
...
@@ -954,7 +959,7 @@ class T_Scan(unittest.TestCase):
f
=
theano
.
function
([
x
],[
y
,
z
],
updates
=
updates
)
f
=
theano
.
function
([
x
],[
y
,
z
],
updates
=
updates
)
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
nx
=
rng
.
uniform
(
size
=
(
10
,
10
)
)
nx
=
rng
.
uniform
(
size
=
(
10
,
10
)
)
.
astype
(
config
.
floatX
)
ny1
,
nz1
=
f
(
nx
)
ny1
,
nz1
=
f
(
nx
)
ny2
,
nz2
=
f
(
nx
)
ny2
,
nz2
=
f
(
nx
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论