Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
fb9913c1
提交
fb9913c1
authored
11月 17, 2010
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update other tests, which used implicit downcasting.
上级
0d2c1831
显示空白字符变更
内嵌
并排
正在显示
12 个修改的文件
包含
81 行增加
和
71 行删除
+81
-71
test_shared.py
theano/compile/tests/test_shared.py
+20
-17
test_basic_ops.py
theano/sandbox/cuda/tests/test_basic_ops.py
+3
-3
test_nnet.py
theano/sandbox/cuda/tests/test_nnet.py
+3
-2
test_opt.py
theano/sandbox/cuda/tests/test_opt.py
+4
-4
test_basic.py
theano/tensor/tests/test_basic.py
+41
-35
test_complex.py
theano/tensor/tests/test_complex.py
+1
-1
test_gc.py
theano/tensor/tests/test_gc.py
+1
-1
test_misc.py
theano/tensor/tests/test_misc.py
+1
-1
test_opt.py
theano/tensor/tests/test_opt.py
+1
-1
test_randomstreams.py
theano/tensor/tests/test_randomstreams.py
+2
-2
test_raw_random.py
theano/tensor/tests/test_raw_random.py
+2
-2
test_shared_randomstreams.py
theano/tensor/tests/test_shared_randomstreams.py
+2
-2
没有找到文件。
theano/compile/tests/test_shared.py
浏览文件 @
fb9913c1
...
...
@@ -203,49 +203,52 @@ class Test_SharedVariable(unittest.TestCase):
# should keep the same bit width / precision as the original value used to create the
# shared variable.
#
# Since downcasting of a value now raises an Exception,
def
f
(
var
,
val
):
var
.
value
=
val
b
=
shared
(
numpy
.
int64
(
7
))
b
=
shared
(
numpy
.
int64
(
7
)
,
allow_downcast
=
True
)
assert
b
.
type
==
theano
.
tensor
.
lscalar
f
(
b
,
8.23
)
assert
b
.
value
==
8
b
=
shared
(
numpy
.
int32
(
7
))
b
=
shared
(
numpy
.
int32
(
7
)
,
allow_downcast
=
True
)
assert
b
.
type
==
theano
.
tensor
.
iscalar
f
(
b
,
8.23
)
assert
b
.
value
==
8
b
=
shared
(
numpy
.
int16
(
7
))
b
=
shared
(
numpy
.
int16
(
7
)
,
allow_downcast
=
True
)
assert
b
.
type
==
theano
.
tensor
.
wscalar
f
(
b
,
8.23
)
assert
b
.
value
==
8
b
=
shared
(
numpy
.
int8
(
7
))
b
=
shared
(
numpy
.
int8
(
7
)
,
allow_downcast
=
True
)
assert
b
.
type
==
theano
.
tensor
.
bscalar
f
(
b
,
8.23
)
assert
b
.
value
==
8
b
=
shared
(
numpy
.
float64
(
7.234
))
b
=
shared
(
numpy
.
float64
(
7.234
)
,
allow_downcast
=
True
)
assert
b
.
type
==
theano
.
tensor
.
dscalar
f
(
b
,
8
)
assert
b
.
value
==
8
b
=
shared
(
numpy
.
float32
(
7.234
))
b
=
shared
(
numpy
.
float32
(
7.234
)
,
allow_downcast
=
True
)
assert
b
.
type
==
theano
.
tensor
.
fscalar
f
(
b
,
8
)
assert
b
.
value
==
8
b
=
shared
(
numpy
.
float
(
7.234
))
b
=
shared
(
numpy
.
float
(
7.234
)
,
allow_downcast
=
True
)
assert
b
.
type
==
theano
.
tensor
.
dscalar
f
(
b
,
8
)
assert
b
.
value
==
8
b
=
shared
(
7.234
)
b
=
shared
(
7.234
,
allow_downcast
=
True
)
assert
b
.
type
==
theano
.
tensor
.
dscalar
f
(
b
,
8
)
assert
b
.
value
==
8
c
=
shared
(
numpy
.
zeros
((
5
,
5
),
dtype
=
'float32'
))
c
=
shared
(
numpy
.
zeros
((
5
,
5
),
dtype
=
'float32'
)
,
allow_downcast
=
True
)
self
.
failUnlessRaises
(
TypeError
,
f
,
b
,
numpy
.
random
.
rand
(
5
,
5
))
...
...
@@ -253,32 +256,32 @@ class Test_SharedVariable(unittest.TestCase):
def
test_tensor_floatX
(
self
):
def
f
(
var
,
val
):
var
.
value
=
val
b
=
shared
(
numpy
.
int64
([
7
]))
b
=
shared
(
numpy
.
int64
([
7
])
,
allow_downcast
=
True
)
assert
b
.
type
==
theano
.
tensor
.
lvector
f
(
b
,[
8.23
])
assert
b
.
value
==
8
b
=
shared
(
numpy
.
int32
([
7
]))
b
=
shared
(
numpy
.
int32
([
7
])
,
allow_downcast
=
True
)
assert
b
.
type
==
theano
.
tensor
.
ivector
f
(
b
,[
8.23
])
assert
b
.
value
==
8
b
=
shared
(
numpy
.
int16
([
7
]))
b
=
shared
(
numpy
.
int16
([
7
])
,
allow_downcast
=
True
)
assert
b
.
type
==
theano
.
tensor
.
wvector
f
(
b
,[
8.23
])
assert
b
.
value
==
8
b
=
shared
(
numpy
.
int8
([
7
]))
b
=
shared
(
numpy
.
int8
([
7
])
,
allow_downcast
=
True
)
assert
b
.
type
==
theano
.
tensor
.
bvector
f
(
b
,[
8.23
])
assert
b
.
value
==
8
b
=
shared
(
numpy
.
float64
([
7.234
]))
b
=
shared
(
numpy
.
float64
([
7.234
])
,
allow_downcast
=
True
)
assert
b
.
type
==
theano
.
tensor
.
dvector
f
(
b
,[
8
])
assert
b
.
value
==
8
b
=
shared
(
numpy
.
float32
([
7.234
]))
b
=
shared
(
numpy
.
float32
([
7.234
])
,
allow_downcast
=
True
)
assert
b
.
type
==
theano
.
tensor
.
fvector
f
(
b
,[
8
])
assert
b
.
value
==
8
...
...
@@ -293,12 +296,12 @@ class Test_SharedVariable(unittest.TestCase):
# assert b.type == theano.tensor.dvector
# f(b,[8])
b
=
shared
(
numpy
.
asarray
([
7.234
],
dtype
=
theano
.
config
.
floatX
))
b
=
shared
(
numpy
.
asarray
([
7.234
],
dtype
=
theano
.
config
.
floatX
)
,
allow_downcast
=
True
)
assert
b
.
dtype
==
theano
.
config
.
floatX
f
(
b
,[
8
])
assert
b
.
value
==
8
c
=
shared
(
numpy
.
zeros
((
5
,
5
),
dtype
=
'float32'
))
c
=
shared
(
numpy
.
zeros
((
5
,
5
),
dtype
=
'float32'
)
,
allow_downcast
=
True
)
self
.
failUnlessRaises
(
TypeError
,
f
,
b
,
numpy
.
random
.
rand
(
5
,
5
))
...
...
theano/sandbox/cuda/tests/test_basic_ops.py
浏览文件 @
fb9913c1
...
...
@@ -206,7 +206,7 @@ def test_elemwise_empty():
f2
=
pfunc
([
b
],
[],
updates
=
[(
a
,
a
+
b
)],
mode
=
mode_without_gpu
)
a0
=
a
.
value
*
1.0
f
(
numpy
.
ones
((
0
,
0
)))
f
(
numpy
.
ones
((
0
,
0
)
,
dtype
=
'float32'
))
assert
numpy
.
all
(
a0
+
1.0
==
a
.
value
)
...
...
@@ -225,7 +225,7 @@ def test_elemwise0():
print
'BEFORE ADD'
,
a
.
value
for
i
,
node
in
enumerate
(
f
.
maker
.
env
.
toposort
()):
print
i
,
node
f
(
numpy
.
ones
((
4
,
4
)))
f
(
numpy
.
ones
((
4
,
4
)
,
dtype
=
'float32'
))
print
'AFTER ADD'
,
a
.
value
assert
numpy
.
all
(
a0
+
1.0
==
a
.
value
)
...
...
@@ -796,7 +796,7 @@ def test_duplicate_arg_elemwise():
f
=
theano
.
function
([
A
],
B
,
mode
=
mode_with_gpu
)
Aval
=
numpy
.
random
.
RandomState
([
1
,
2
,
3
])
.
randn
(
5
,
5
)
Aval
=
numpy
.
random
.
RandomState
([
1
,
2
,
3
])
.
randn
(
5
,
5
)
.
astype
(
'float32'
)
Bval
=
Aval
+
Aval
assert
numpy
.
allclose
(
Bval
,
f
(
Aval
))
...
...
theano/sandbox/cuda/tests/test_nnet.py
浏览文件 @
fb9913c1
...
...
@@ -42,7 +42,8 @@ def test_GpuCrossentropySoftmaxArgmax1HotWithBias():
dot_result
=
T
.
fmatrix
(
'dot_result'
)
xx
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
batch_size
,
n_in
),
dtype
=
numpy
.
float32
)
yy
=
numpy
.
ones
((
batch_size
,),
dtype
=
'float32'
)
#?????yy = numpy.ones((batch_size,),dtype='float32')
yy
=
numpy
.
ones
((
batch_size
,),
dtype
=
'int32'
)
b_values
=
numpy
.
zeros
((
n_out
,),
dtype
=
'float32'
)
W_values
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
n_in
,
n_out
),
dtype
=
'float32'
)
...
...
@@ -82,7 +83,7 @@ def test_GpuCrossentropySoftmax1HotWithBiasDx():
batch_size
=
4097
n_out
=
1250
softmax_output_value
=
numpy
.
random
.
rand
(
batch_size
,
n_out
)
softmax_output_value
=
numpy
.
random
.
rand
(
batch_size
,
n_out
)
.
astype
(
'float32'
)
softmax_output
=
T
.
fmatrix
()
softmax_output
/=
softmax_output
.
sum
(
axis
=
1
)
.
reshape
(
softmax_output
.
shape
[
1
],
1
)
...
...
theano/sandbox/cuda/tests/test_opt.py
浏览文件 @
fb9913c1
...
...
@@ -73,7 +73,7 @@ def test_softmax():
f
=
theano
.
function
([
x
],
tensor
.
nnet
.
nnet
.
Softmax
()(
x
),
mode
=
mode_with_gpu
)
f2
=
theano
.
function
([
x
],
tensor
.
nnet
.
nnet
.
Softmax
()(
x
),
mode
=
mode_without_gpu
)
assert
isinstance
(
f
.
maker
.
env
.
toposort
()[
1
]
.
op
,
cuda
.
nnet
.
GpuSoftmax
)
xv
=
numpy
.
random
.
rand
(
7
,
8
)
xv
=
numpy
.
random
.
rand
(
7
,
8
)
.
astype
(
'float32'
)
assert
numpy
.
allclose
(
f
(
xv
),
f2
(
xv
))
...
...
@@ -84,8 +84,8 @@ def test_softmax_with_bias():
f
=
theano
.
function
([
x
,
b
],
tensor
.
nnet
.
nnet
.
SoftmaxWithBias
()(
x
,
b
),
mode
=
mode_with_gpu
)
f2
=
theano
.
function
([
x
,
b
],
tensor
.
nnet
.
nnet
.
SoftmaxWithBias
()(
x
,
b
),
mode
=
mode_without_gpu
)
assert
isinstance
(
f
.
maker
.
env
.
toposort
()[
2
]
.
op
,
cuda
.
nnet
.
GpuSoftmaxWithBias
)
xv
=
numpy
.
random
.
rand
(
7
,
8
)
bv
=
numpy
.
random
.
rand
(
8
)
xv
=
numpy
.
random
.
rand
(
7
,
8
)
.
astype
(
'float32'
)
bv
=
numpy
.
random
.
rand
(
8
)
.
astype
(
'float32'
)
assert
numpy
.
allclose
(
f
(
xv
,
bv
),
f2
(
xv
,
bv
))
def
test_opt_gpujoin_onlyajoin
():
...
...
@@ -153,7 +153,7 @@ def test_print_op():
assert
isinstance
(
topo
[
1
]
.
op
,
theano
.
printing
.
Print
)
assert
isinstance
(
topo
[
2
]
.
op
,
cuda
.
GpuElemwise
)
assert
topo
[
3
]
.
op
==
cuda
.
host_from_gpu
f
(
numpy
.
random
.
random
((
5
,
5
)))
f
(
numpy
.
random
.
random
((
5
,
5
))
.
astype
(
'float32'
)
)
def
test_elemwise_fusion
():
""" Test the the GpuElemwise fusion work correctly"""
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
fb9913c1
...
...
@@ -1654,48 +1654,48 @@ class test_comparison(unittest.TestCase):
def
test_gt
(
self
):
x
,
y
=
fvector
(),
fvector
()
fn
=
inplace_func
([
x
,
y
],
x
>
y
)
l
=
numpy
.
asarray
([
0.
,
-
1.
,
1.
])
r
=
numpy
.
asarray
([
0.
,
1.
,
-
1.
])
l
=
numpy
.
asarray
([
0.
,
-
1.
,
1.
]
,
dtype
=
'float32'
)
r
=
numpy
.
asarray
([
0.
,
1.
,
-
1.
]
,
dtype
=
'float32'
)
v
=
fn
(
l
,
r
)
self
.
failUnless
(
numpy
.
all
(
v
==
(
l
>
r
)),
(
v
,
(
l
>
r
)))
def
test_lt
(
self
):
x
,
y
=
fvector
(),
fvector
()
fn
=
inplace_func
([
x
,
y
],
x
<
y
)
l
=
numpy
.
asarray
([
0.
,
-
1.
,
1.
])
r
=
numpy
.
asarray
([
0.
,
1.
,
-
1.
])
l
=
numpy
.
asarray
([
0.
,
-
1.
,
1.
]
,
dtype
=
'float32'
)
r
=
numpy
.
asarray
([
0.
,
1.
,
-
1.
]
,
dtype
=
'float32'
)
v
=
fn
(
l
,
r
)
self
.
failUnless
(
numpy
.
all
(
v
==
(
l
<
r
)),
(
v
,
(
l
<
r
)))
def
test_le
(
self
):
x
,
y
=
fvector
(),
fvector
()
fn
=
inplace_func
([
x
,
y
],
x
<=
y
)
l
=
numpy
.
asarray
([
0.
,
-
1.
,
1.
])
r
=
numpy
.
asarray
([
0.
,
1.
,
-
1.
])
l
=
numpy
.
asarray
([
0.
,
-
1.
,
1.
]
,
dtype
=
'float32'
)
r
=
numpy
.
asarray
([
0.
,
1.
,
-
1.
]
,
dtype
=
'float32'
)
v
=
fn
(
l
,
r
)
self
.
failUnless
(
numpy
.
all
(
v
==
(
l
<=
r
)),
(
v
,
(
l
<=
r
)))
def
test_ge
(
self
):
x
,
y
=
fvector
(),
fvector
()
fn
=
inplace_func
([
x
,
y
],
x
>=
y
)
l
=
numpy
.
asarray
([
0.
,
-
1.
,
1.
])
r
=
numpy
.
asarray
([
0.
,
1.
,
-
1.
])
l
=
numpy
.
asarray
([
0.
,
-
1.
,
1.
]
,
dtype
=
'float32'
)
r
=
numpy
.
asarray
([
0.
,
1.
,
-
1.
]
,
dtype
=
'float32'
)
v
=
fn
(
l
,
r
)
self
.
failUnless
(
numpy
.
all
(
v
==
(
l
>=
r
)),
(
v
,
(
l
>=
r
)))
def
test_eq
(
self
):
x
,
y
=
fvector
(),
fvector
()
fn
=
inplace_func
([
x
,
y
],
eq
(
x
,
y
))
l
=
numpy
.
asarray
([
0.
,
-
1.
,
1.
])
r
=
numpy
.
asarray
([
0.
,
1.
,
-
1.
])
l
=
numpy
.
asarray
([
0.
,
-
1.
,
1.
]
,
dtype
=
'float32'
)
r
=
numpy
.
asarray
([
0.
,
1.
,
-
1.
]
,
dtype
=
'float32'
)
v
=
fn
(
l
,
r
)
self
.
failUnless
(
numpy
.
all
(
v
==
(
l
==
r
)),
(
v
,
(
l
==
r
)))
def
test_neq
(
self
):
x
,
y
=
fvector
(),
fvector
()
fn
=
inplace_func
([
x
,
y
],
neq
(
x
,
y
))
l
=
numpy
.
asarray
([
0.
,
-
1.
,
1.
])
r
=
numpy
.
asarray
([
0.
,
1.
,
-
1.
])
l
=
numpy
.
asarray
([
0.
,
-
1.
,
1.
]
,
dtype
=
'float32'
)
r
=
numpy
.
asarray
([
0.
,
1.
,
-
1.
]
,
dtype
=
'float32'
)
v
=
fn
(
l
,
r
)
self
.
failUnless
(
numpy
.
all
(
v
==
(
l
!=
r
)),
(
v
,
(
l
!=
r
)))
...
...
@@ -2607,30 +2607,32 @@ class TestARange(unittest.TestCase):
assert
numpy
.
all
(
f
(
0
,
0
,
1
)
==
numpy
.
arange
(
0
,
0
,
1
))
def
test_float32
(
self
):
"""Test arange constructor, on
integer
outputs"""
"""Test arange constructor, on
float32
outputs"""
start
,
stop
,
step
=
fscalars
(
'start'
,
'stop'
,
'step'
)
out
=
arange
(
start
,
stop
,
step
)
f
=
function
([
start
,
stop
,
step
],
out
)
assert
out
.
dtype
==
start
.
type
.
dtype
assert
numpy
.
all
(
f
(
0
,
5
,
1
)
==
numpy
.
arange
(
0
,
5
,
1
,
dtype
=
start
.
type
.
dtype
))
assert
numpy
.
all
(
f
(
2
,
11
,
4
)
==
numpy
.
arange
(
2
,
11
,
4
,
dtype
=
start
.
type
.
dtype
))
assert
numpy
.
all
(
f
(
-
5
,
1.1
,
1.2
)
==
numpy
.
arange
(
-
5
,
1.1
,
1.2
,
dtype
=
start
.
type
.
dtype
))
assert
numpy
.
all
(
f
(
1.3
,
2
,
-
2.1
)
==
numpy
.
arange
(
1.3
,
2
,
-
2.1
,
dtype
=
start
.
type
.
dtype
))
assert
numpy
.
all
(
f
(
10
,
2
,
2
)
==
numpy
.
arange
(
10
,
2
,
2
,
dtype
=
start
.
type
.
dtype
))
arg_vals
=
[
(
0
,
5
,
1
),
(
2
,
11
,
4
),
(
-
5
,
1.1
,
1.2
),
(
1.3
,
2
,
-
2.1
),
(
10
,
2
,
2
)
]
for
arg_v
in
arg_vals
:
start_v
,
stop_v
,
step_v
=
arg_v
start_v_
,
stop_v_
,
step_v_
=
numpy
.
asarray
(
arg_v
,
dtype
=
start
.
type
.
dtype
)
assert
numpy
.
all
(
f
(
start_v_
,
stop_v_
,
step_v_
)
==
\
numpy
.
arange
(
start_v
,
stop_v
,
step_v
,
dtype
=
start
.
type
.
dtype
))
def
test_float64
(
self
):
"""Test arange constructor, on
integer
outputs"""
"""Test arange constructor, on
float64
outputs"""
start
,
stop
,
step
=
dscalars
(
'start'
,
'stop'
,
'step'
)
out
=
arange
(
start
,
stop
,
step
)
f
=
function
([
start
,
stop
,
step
],
out
)
assert
out
.
dtype
==
start
.
type
.
dtype
assert
numpy
.
all
(
f
(
0
,
5
,
1
)
==
numpy
.
arange
(
0
,
5
,
1
,
dtype
=
start
.
type
.
dtype
))
assert
numpy
.
all
(
f
(
2
,
11
,
4
)
==
numpy
.
arange
(
2
,
11
,
4
,
dtype
=
start
.
type
.
dtype
))
assert
numpy
.
all
(
f
(
-
5
,
1.1
,
1.2
)
==
numpy
.
arange
(
-
5
,
1.1
,
1.2
,
dtype
=
start
.
type
.
dtype
))
assert
numpy
.
all
(
f
(
1.3
,
2
,
-
2.1
)
==
numpy
.
arange
(
1.3
,
2
,
-
2.1
,
dtype
=
start
.
type
.
dtype
))
assert
numpy
.
all
(
f
(
10
,
2
,
2
)
==
numpy
.
arange
(
10
,
2
,
2
,
dtype
=
start
.
type
.
dtype
))
arg_vals
=
[
(
0
,
5
,
1
),
(
2
,
11
,
4
),
(
-
5
,
1.1
,
1.2
),
(
1.3
,
2
,
-
2.1
),
(
10
,
2
,
2
)
]
for
arg_v
in
arg_vals
:
start_v
,
stop_v
,
step_v
=
arg_v
start_v_
,
stop_v_
,
step_v_
=
numpy
.
asarray
(
arg_v
,
dtype
=
start
.
type
.
dtype
)
assert
numpy
.
all
(
f
(
start_v_
,
stop_v_
,
step_v_
)
==
\
numpy
.
arange
(
start_v
,
stop_v
,
step_v
,
dtype
=
start
.
type
.
dtype
))
def
test_default_step
(
self
):
"""Test that arange constructor uses the correct default step"""
...
...
@@ -2669,9 +2671,10 @@ class TestARange(unittest.TestCase):
ff
=
function
([
fstop
],
fout
)
assert
fout
.
dtype
==
fstop
.
type
.
dtype
assert
numpy
.
all
(
ff
(
0.2
)
==
numpy
.
arange
(
0.2
))
assert
numpy
.
all
(
ff
(
-
0.7
)
==
numpy
.
arange
(
-
0.7
))
assert
numpy
.
all
(
ff
(
8.5
)
==
numpy
.
arange
(
8.5
))
fstop_values
=
[
0.2
,
-
0.7
,
8.5
]
for
fstop_v
in
fstop_values
:
fstop_v32
=
numpy
.
float32
(
fstop_v
)
assert
numpy
.
all
(
ff
(
fstop_v32
)
==
numpy
.
arange
(
fstop_v
))
def
test_upcast
(
self
):
"""Test that arange compute output type adequately"""
...
...
@@ -2756,7 +2759,7 @@ class TestInversePermutation(unittest.TestCase):
# Generate a random permutation
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
p_val
=
rng
.
permutation
(
10
)
p_val
=
rng
.
permutation
(
10
)
.
astype
(
'int32'
)
inv_val
=
f_inverse
(
p_val
)
# Check that the inverse of the inverse is the original permutation
...
...
@@ -2774,7 +2777,8 @@ class TestInversePermutation(unittest.TestCase):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
# Generate 10 random permutations
p_val
=
numpy
.
asarray
([
rng
.
permutation
(
10
)
for
i
in
range
(
7
)])
p_val
=
numpy
.
asarray
([
rng
.
permutation
(
10
)
for
i
in
range
(
7
)],
dtype
=
'int32'
)
inv_val
=
f_inverse
(
p_val
)
# Check that the inverse of the inverse is the original permutation list
...
...
@@ -2799,7 +2803,7 @@ class TestPermuteRowElements(unittest.TestCase):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
input_val
=
rng
.
uniform
(
size
=
(
5
,))
p_val
=
rng
.
permutation
(
5
)
p_val
=
rng
.
permutation
(
5
)
.
astype
(
'int32'
)
out_val
=
permute
(
input_val
,
p_val
)
# Should be equivalent to advanced indexing
...
...
@@ -2821,7 +2825,7 @@ class TestPermuteRowElements(unittest.TestCase):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
input_val
=
rng
.
uniform
(
size
=
(
3
,
5
))
p_val
=
rng
.
permutation
(
5
)
p_val
=
rng
.
permutation
(
5
)
.
astype
(
'int32'
)
out_val
=
permute
(
input_val
,
p_val
)
# The same permutation should be applied to every row of the input matrix.
...
...
@@ -2843,7 +2847,8 @@ class TestPermuteRowElements(unittest.TestCase):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
input_val
=
rng
.
uniform
(
size
=
(
3
,
5
))
p_val
=
numpy
.
asarray
([
rng
.
permutation
(
5
)
for
i
in
range
(
3
)])
p_val
=
numpy
.
asarray
([
rng
.
permutation
(
5
)
for
i
in
range
(
3
)],
dtype
=
'int32'
)
out_val
=
permute
(
input_val
,
p_val
)
# Each row of p contains a permutation to apply to the corresponding
...
...
@@ -2867,7 +2872,7 @@ class TestPermuteRowElements(unittest.TestCase):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
input_val
=
rng
.
uniform
(
size
=
(
5
,))
p_val
=
numpy
.
asarray
([
rng
.
permutation
(
5
)
for
i
in
range
(
3
)])
p_val
=
numpy
.
asarray
([
rng
.
permutation
(
5
)
for
i
in
range
(
3
)]
,
dtype
=
'int32'
)
out_val
=
permute
(
input_val
,
p_val
)
# Each row of p contains a permutation to apply to the input vector
...
...
@@ -2892,7 +2897,8 @@ class TestPermuteRowElements(unittest.TestCase):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
input_val
=
rng
.
uniform
(
size
=
(
4
,
1
,
5
))
p_val
=
numpy
.
asarray
([
rng
.
permutation
(
5
)
for
i
in
range
(
3
)])
p_val
=
numpy
.
asarray
([
rng
.
permutation
(
5
)
for
i
in
range
(
3
)],
dtype
=
'int32'
)
out_val
=
permute
(
input_val
,
p_val
)
# Each row of p contains a permutation to apply to each row
...
...
@@ -3039,7 +3045,7 @@ class test_tensordot(unittest.TestCase):
amat
=
fmatrix
()
bmat
=
dmatrix
()
#we let at float64 to test mix of float32 and float64.
axes
=
1
aval
=
self
.
rand
(
4
,
5
)
aval
=
self
.
rand
(
4
,
5
)
.
astype
(
'float32'
)
bval
=
numpy
.
random
.
rand
(
5
,
3
)
c
=
tensordot
(
amat
,
bmat
,
axes
)
f3
=
inplace_func
([
amat
,
bmat
],
c
)
...
...
theano/tensor/tests/test_complex.py
浏览文件 @
fb9913c1
...
...
@@ -23,7 +23,7 @@ class TestRealImag(unittest.TestCase):
x
=
imatrix
()
xval
=
numpy
.
asarray
(
rng
.
randn
(
3
,
3
)
*
100
,
dtype
=
'int'
)
xval
=
numpy
.
asarray
(
rng
.
randn
(
3
,
3
)
*
100
,
dtype
=
'int
32
'
)
numpy
.
all
(
0
==
theano
.
function
([
x
],
imag
(
x
))(
xval
))
numpy
.
all
(
xval
==
theano
.
function
([
x
],
real
(
x
))(
xval
))
...
...
theano/tensor/tests/test_gc.py
浏览文件 @
fb9913c1
...
...
@@ -12,7 +12,7 @@ def test_no_reuse():
f
=
theano
.
function
([
x
,
y
],
x
+
y
)
#provide both inputs in the first call
f
(
numpy
.
ones
(
10
),
numpy
.
ones
(
10
))
f
(
numpy
.
ones
(
10
,
dtype
=
'int64'
),
numpy
.
ones
(
10
,
dtype
=
'int64'
))
try
:
f
(
numpy
.
ones
(
10
))
...
...
theano/tensor/tests/test_misc.py
浏览文件 @
fb9913c1
...
...
@@ -10,7 +10,7 @@ def test_bug_2009_06_02_trac_387():
#f = theano.function([y], tensor.join(0,tensor.shape_padleft(y[0] / 2,1)))
f
=
theano
.
function
([
y
],
tensor
.
int_div
(
tensor
.
DimShuffle
(
y
[
0
]
.
broadcastable
,
[
'x'
])(
y
[
0
]),
2
))
sys
.
stdout
.
flush
()
print
f
(
numpy
.
ones
(
1
)
*
3
)
print
f
(
numpy
.
ones
(
1
,
dtype
=
'int64'
)
*
3
)
#z = tensor.lscalar('z')
#f = theano.function([z], tensor.DimShuffle([], ['x'])(z) / 2)
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
fb9913c1
...
...
@@ -2094,6 +2094,6 @@ def test_local_mul_to_neg():
a
=
T
.
imatrix
()
f1
=
theano
.
function
([
a
],
-
1
*
a
)
f2
=
theano
.
function
([
a
],
-
1.0
*
a
)
aval
=
numpy
.
random
.
randint
(
0
,
10
,(
2
,
2
))
aval
=
numpy
.
random
.
randint
(
0
,
10
,(
2
,
2
))
.
astype
(
'int32'
)
assert
f1
(
aval
)
.
dtype
==
a
.
dtype
assert
f2
(
aval
)
.
dtype
==
'float64'
theano/tensor/tests/test_randomstreams.py
浏览文件 @
fb9913c1
...
...
@@ -581,8 +581,8 @@ class T_RandomStreams(unittest.TestCase):
made
=
m
.
make
()
made
.
random
.
initialize
()
low_val
=
[
.
1
,
.
2
,
.
3
]
high_val
=
[
1
.1
,
2.2
,
3.3
]
low_val
=
[
100
,
200
,
300
]
high_val
=
[
1
10
,
220
,
330
]
seed_gen
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
numpy_rng
=
numpy
.
random
.
RandomState
(
int
(
seed_gen
.
randint
(
2
**
30
)))
...
...
theano/tensor/tests/test_raw_random.py
浏览文件 @
fb9913c1
...
...
@@ -665,8 +665,8 @@ class T_random_function(unittest.TestCase):
assert
out
.
ndim
==
1
f
=
compile
.
function
([
rng_R
,
low
,
high
],
[
post_r
,
out
],
accept_inplace
=
True
)
low_val
=
[
.
1
,
.
2
,
.
3
]
high_val
=
[
1
.1
,
2.2
,
3.3
]
low_val
=
[
100
,
200
,
300
]
high_val
=
[
1
10
,
220
,
330
]
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
numpy_rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
...
...
theano/tensor/tests/test_shared_randomstreams.py
浏览文件 @
fb9913c1
...
...
@@ -527,8 +527,8 @@ class T_SharedRandomStreams(unittest.TestCase):
assert
out
.
ndim
==
1
f
=
function
([
low
,
high
],
out
)
low_val
=
[
.
1
,
.
2
,
.
3
]
high_val
=
[
1
.1
,
2.2
,
3.3
]
low_val
=
[
100
,
200
,
300
]
high_val
=
[
1
10
,
220
,
330
]
seed_gen
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
numpy_rng
=
numpy
.
random
.
RandomState
(
int
(
seed_gen
.
randint
(
2
**
30
)))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论