Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5c25733d
提交
5c25733d
authored
5月 05, 2014
作者:
abergeron
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1832 from nouiz/fix_tests
[BUG] Fix bad view map in real(float32)
上级
26d91309
53e6d2c3
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
77 行增加
和
65 行删除
+77
-65
setup.py
setup.py
+9
-7
opt.py
theano/sandbox/cuda/opt.py
+3
-3
test_rng_mrg.py
theano/sandbox/test_rng_mrg.py
+30
-23
basic.py
theano/tensor/basic.py
+3
-2
test_complex.py
theano/tensor/tests/test_complex.py
+32
-30
没有找到文件。
setup.py
浏览文件 @
5c25733d
...
@@ -74,11 +74,11 @@ VERSION = '%d.%d.%d%s' % (MAJOR, MINOR, MICRO, SUFFIX)
...
@@ -74,11 +74,11 @@ VERSION = '%d.%d.%d%s' % (MAJOR, MINOR, MICRO, SUFFIX)
def
find_packages
(
where
=
'.'
,
exclude
=
()):
def
find_packages
(
where
=
'.'
,
exclude
=
()):
out
=
[]
out
=
[]
stack
=
[(
convert_path
(
where
),
''
)]
stack
=
[(
convert_path
(
where
),
''
)]
while
stack
:
while
stack
:
where
,
prefix
=
stack
.
pop
(
0
)
where
,
prefix
=
stack
.
pop
(
0
)
for
name
in
os
.
listdir
(
where
):
for
name
in
os
.
listdir
(
where
):
fn
=
os
.
path
.
join
(
where
,
name
)
fn
=
os
.
path
.
join
(
where
,
name
)
if
(
'.'
not
in
name
and
os
.
path
.
isdir
(
fn
)
and
if
(
'.'
not
in
name
and
os
.
path
.
isdir
(
fn
)
and
os
.
path
.
isfile
(
os
.
path
.
join
(
fn
,
'__init__.py'
))
os
.
path
.
isfile
(
os
.
path
.
join
(
fn
,
'__init__.py'
))
):
):
...
@@ -123,7 +123,7 @@ def git_version():
...
@@ -123,7 +123,7 @@ def git_version():
return
git_revision
return
git_revision
# Python 2.4 compatibility: Python versions 2.6 and later support new
# Python 2.4 compatibility: Python versions 2.6 and later support new
# exception syntax, but for now we have to resort to exec.
# exception syntax, but for now we have to resort to exec.
if
sys
.
hexversion
>=
0x2070000
:
if
sys
.
hexversion
>=
0x2070000
:
exec
(
"""
\
exec
(
"""
\
def write_text(filename, text):
def write_text(filename, text):
...
@@ -146,6 +146,7 @@ def write_text(filename, text):
...
@@ -146,6 +146,7 @@ def write_text(filename, text):
a.close()
a.close()
"""
)
"""
)
def
write_version_py
(
filename
=
os
.
path
.
join
(
'theano'
,
'generated_version.py'
)):
def
write_version_py
(
filename
=
os
.
path
.
join
(
'theano'
,
'generated_version.py'
)):
cnt
=
"""
cnt
=
"""
# THIS FILE IS GENERATED FROM THEANO SETUP.PY
# THIS FILE IS GENERATED FROM THEANO SETUP.PY
...
@@ -175,6 +176,7 @@ if not release:
...
@@ -175,6 +176,7 @@ if not release:
'isrelease'
:
str
(
ISRELEASED
)}
'isrelease'
:
str
(
ISRELEASED
)}
write_text
(
filename
,
text
)
write_text
(
filename
,
text
)
def
do_setup
():
def
do_setup
():
write_version_py
()
write_version_py
()
setup
(
name
=
NAME
,
setup
(
name
=
NAME
,
...
@@ -196,11 +198,11 @@ def do_setup():
...
@@ -196,11 +198,11 @@ def do_setup():
},
},
scripts
=
[
'bin/theano-cache'
,
'bin/theano-nose'
,
'bin/theano-test'
],
scripts
=
[
'bin/theano-cache'
,
'bin/theano-nose'
,
'bin/theano-test'
],
keywords
=
' '
.
join
([
keywords
=
' '
.
join
([
'theano'
,
'math'
,
'numerical'
,
'symbolic'
,
'blas'
,
'theano'
,
'math'
,
'numerical'
,
'symbolic'
,
'blas'
,
'numpy'
,
'gpu'
,
'autodiff'
,
'differentiation'
'numpy'
,
'gpu'
,
'autodiff'
,
'differentiation'
]),
]),
cmdclass
=
{
'build_py'
:
build_py
,
cmdclass
=
{
'build_py'
:
build_py
,
'build_scripts'
:
build_scripts
}
'build_scripts'
:
build_scripts
}
)
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
do_setup
()
do_setup
()
theano/sandbox/cuda/opt.py
浏览文件 @
5c25733d
...
@@ -1593,7 +1593,7 @@ def gpuScanOptimization(node):
...
@@ -1593,7 +1593,7 @@ def gpuScanOptimization(node):
# __init__ does not know about cuda ndarray and can not
# __init__ does not know about cuda ndarray and can not
# handle graphs with inputs being Cuda Ndarrays
# handle graphs with inputs being Cuda Ndarrays
tmp_in
,
tmp_out
=
gpu_reconstruct_graph
(
scan_ins
,
tmp_in
,
tmp_out
=
gpu_reconstruct_graph
(
scan_ins
,
scan_outs
)
scan_outs
)
local_fgraph
=
gof
.
FunctionGraph
(
tmp_in
,
tmp_out
)
local_fgraph
=
gof
.
FunctionGraph
(
tmp_in
,
tmp_out
)
_cmodule_key
=
gof
.
CLinker
()
.
cmodule_key_
(
local_fgraph
,
[])
_cmodule_key
=
gof
.
CLinker
()
.
cmodule_key_
(
local_fgraph
,
[])
info
[
'gpu_hash'
]
=
hash
(
_cmodule_key
)
info
[
'gpu_hash'
]
=
hash
(
_cmodule_key
)
...
@@ -1640,7 +1640,7 @@ def gpuScanOptimization(node):
...
@@ -1640,7 +1640,7 @@ def gpuScanOptimization(node):
# __init__ does not know about cuda ndarray and can not
# __init__ does not know about cuda ndarray and can not
# handle graphs with inputs being Cuda Ndarrays
# handle graphs with inputs being Cuda Ndarrays
tmp_in
,
tmp_out
=
gpu_reconstruct_graph
(
scan_ins
,
tmp_in
,
tmp_out
=
gpu_reconstruct_graph
(
scan_ins
,
scan_outs
)
scan_outs
)
local_fgraph
=
gof
.
FunctionGraph
(
tmp_in
,
tmp_out
)
local_fgraph
=
gof
.
FunctionGraph
(
tmp_in
,
tmp_out
)
_cmodule_key
=
gof
.
CLinker
()
.
cmodule_key_
(
local_fgraph
,
[])
_cmodule_key
=
gof
.
CLinker
()
.
cmodule_key_
(
local_fgraph
,
[])
info
[
'gpu_hash'
]
=
hash
(
_cmodule_key
)
info
[
'gpu_hash'
]
=
hash
(
_cmodule_key
)
...
@@ -1662,7 +1662,7 @@ def gpuScanOptimization(node):
...
@@ -1662,7 +1662,7 @@ def gpuScanOptimization(node):
optdb
.
register
(
'gpu_scanOp_make_inplace'
,
optdb
.
register
(
'gpu_scanOp_make_inplace'
,
scan_opt
.
ScanInplaceOptimizer
(
typeConstructor
=
typeConstructor
,
scan_opt
.
ScanInplaceOptimizer
(
typeConstructor
=
typeConstructor
,
gpu_flag
=
True
),
gpu_flag
=
True
),
75
,
75
,
'gpu'
,
'gpu'
,
'fast_run'
,
'fast_run'
,
...
...
theano/sandbox/test_rng_mrg.py
浏览文件 @
5c25733d
...
@@ -166,7 +166,8 @@ def test_consistency_cpu_parallel():
...
@@ -166,7 +166,8 @@ def test_consistency_cpu_parallel():
rstate
=
theano
.
shared
(
rstate
)
rstate
=
theano
.
shared
(
rstate
)
new_rstate
,
sample
=
rng_mrg
.
mrg_uniform
.
new
(
rstate
,
ndim
=
None
,
new_rstate
,
sample
=
rng_mrg
.
mrg_uniform
.
new
(
rstate
,
ndim
=
None
,
dtype
=
config
.
floatX
,
size
=
(
n_substreams
,))
dtype
=
config
.
floatX
,
size
=
(
n_substreams
,))
# Not really necessary, just mimicking
# Not really necessary, just mimicking
# rng_mrg.MRG_RandomStreams' behavior
# rng_mrg.MRG_RandomStreams' behavior
sample
.
rstate
=
rstate
sample
.
rstate
=
rstate
...
@@ -219,7 +220,8 @@ def test_consistency_GPU_serial():
...
@@ -219,7 +220,8 @@ def test_consistency_GPU_serial():
rstate
=
float32_shared_constructor
(
tmp_float_buf
)
rstate
=
float32_shared_constructor
(
tmp_float_buf
)
new_rstate
,
sample
=
rng_mrg
.
GPU_mrg_uniform
.
new
(
rstate
,
ndim
=
None
,
new_rstate
,
sample
=
rng_mrg
.
GPU_mrg_uniform
.
new
(
rstate
,
ndim
=
None
,
dtype
=
'float32'
,
size
=
(
1
,))
dtype
=
'float32'
,
size
=
(
1
,))
rstate
.
default_update
=
new_rstate
rstate
.
default_update
=
new_rstate
# Not really necessary, just mimicking
# Not really necessary, just mimicking
...
@@ -278,7 +280,8 @@ def test_consistency_GPU_parallel():
...
@@ -278,7 +280,8 @@ def test_consistency_GPU_parallel():
rstate
=
float32_shared_constructor
(
tmp_float_buf
)
rstate
=
float32_shared_constructor
(
tmp_float_buf
)
new_rstate
,
sample
=
rng_mrg
.
GPU_mrg_uniform
.
new
(
rstate
,
ndim
=
None
,
new_rstate
,
sample
=
rng_mrg
.
GPU_mrg_uniform
.
new
(
rstate
,
ndim
=
None
,
dtype
=
'float32'
,
size
=
(
n_substreams
,))
dtype
=
'float32'
,
size
=
(
n_substreams
,))
rstate
.
default_update
=
new_rstate
rstate
.
default_update
=
new_rstate
# Not really necessary, just mimicking
# Not really necessary, just mimicking
...
@@ -381,7 +384,8 @@ def test_consistency_GPUA_parallel():
...
@@ -381,7 +384,8 @@ def test_consistency_GPUA_parallel():
rstate
=
gpuarray_shared_constructor
(
rstate
)
rstate
=
gpuarray_shared_constructor
(
rstate
)
new_rstate
,
sample
=
rng_mrg
.
GPUA_mrg_uniform
.
new
(
rstate
,
ndim
=
None
,
new_rstate
,
sample
=
rng_mrg
.
GPUA_mrg_uniform
.
new
(
rstate
,
ndim
=
None
,
dtype
=
'float32'
,
size
=
(
n_substreams
,))
dtype
=
'float32'
,
size
=
(
n_substreams
,))
rstate
.
default_update
=
new_rstate
rstate
.
default_update
=
new_rstate
# Not really necessary, just mimicking
# Not really necessary, just mimicking
...
@@ -452,7 +456,7 @@ def basictest(f, steps, sample_size, prefix="", allow_01=False, inputs=None,
...
@@ -452,7 +456,7 @@ def basictest(f, steps, sample_size, prefix="", allow_01=False, inputs=None,
#print prefix, 'std', std
#print prefix, 'std', std
if
target_std
is
not
None
:
if
target_std
is
not
None
:
assert
abs
(
std
-
target_std
)
<
std_tol
*
(
1
+
abs
(
target_std
)),
(
assert
abs
(
std
-
target_std
)
<
std_tol
*
(
1
+
abs
(
target_std
)),
(
'bad std?
%
f
%
f
%
f'
%
(
std
,
target_std
,
std_tol
))
'bad std?
%
f
%
f
%
f'
%
(
std
,
target_std
,
std_tol
))
#print prefix, 'time', dt
#print prefix, 'time', dt
#print prefix, 'elements', steps * sample_size[0] * sample_size[1]
#print prefix, 'elements', steps * sample_size[0] * sample_size[1]
#print prefix, 'samples/sec', steps * sample_size[0] * sample_size[1] / dt
#print prefix, 'samples/sec', steps * sample_size[0] * sample_size[1] / dt
...
@@ -522,8 +526,8 @@ def test_uniform():
...
@@ -522,8 +526,8 @@ def test_uniform():
# well, it's really that this test w GPU doesn't make sense otw
# well, it's really that this test w GPU doesn't make sense otw
assert
u
.
dtype
==
'float32'
assert
u
.
dtype
==
'float32'
f
=
theano
.
function
(
var_input
,
theano
.
Out
(
f
=
theano
.
function
(
var_input
,
theano
.
Out
(
theano
.
sandbox
.
cuda
.
basic_ops
.
gpu_from_host
(
u
),
theano
.
sandbox
.
cuda
.
basic_ops
.
gpu_from_host
(
u
),
borrow
=
True
),
mode
=
mode_with_gpu
)
borrow
=
True
),
mode
=
mode_with_gpu
)
assert
any
([
isinstance
(
node
.
op
,
assert
any
([
isinstance
(
node
.
op
,
theano
.
sandbox
.
rng_mrg
.
GPU_mrg_uniform
)
theano
.
sandbox
.
rng_mrg
.
GPU_mrg_uniform
)
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
...
@@ -613,8 +617,8 @@ def test_binomial():
...
@@ -613,8 +617,8 @@ def test_binomial():
#well, it's really that this test w GPU doesn't make sense otw
#well, it's really that this test w GPU doesn't make sense otw
assert
u
.
dtype
==
'float32'
assert
u
.
dtype
==
'float32'
f
=
theano
.
function
(
var_input
,
theano
.
Out
(
f
=
theano
.
function
(
var_input
,
theano
.
Out
(
theano
.
sandbox
.
cuda
.
basic_ops
.
gpu_from_host
(
u
),
theano
.
sandbox
.
cuda
.
basic_ops
.
gpu_from_host
(
u
),
borrow
=
True
),
mode
=
mode_with_gpu
)
borrow
=
True
),
mode
=
mode_with_gpu
)
#theano.printing.debugprint(f)
#theano.printing.debugprint(f)
gpu_out
=
numpy
.
asarray
(
f
(
*
input
))
gpu_out
=
numpy
.
asarray
(
f
(
*
input
))
#print 'random?[:10]\n', gpu_out[0, 0:10]
#print 'random?[:10]\n', gpu_out[0, 0:10]
...
@@ -799,9 +803,9 @@ def test_multinomial():
...
@@ -799,9 +803,9 @@ def test_multinomial():
#well, it's really that this test w GPU doesn't make sense otw
#well, it's really that this test w GPU doesn't make sense otw
assert
n
.
dtype
==
'float32'
assert
n
.
dtype
==
'float32'
f
=
theano
.
function
(
f
=
theano
.
function
(
[],
[],
theano
.
sandbox
.
cuda
.
basic_ops
.
gpu_from_host
(
n
),
theano
.
sandbox
.
cuda
.
basic_ops
.
gpu_from_host
(
n
),
mode
=
mode_
.
including
(
'gpu'
))
mode
=
mode_
.
including
(
'gpu'
))
#theano.printing.debugprint(f)
#theano.printing.debugprint(f)
gpu_out
=
f
()
gpu_out
=
f
()
...
@@ -883,27 +887,30 @@ def test_multMatVect():
...
@@ -883,27 +887,30 @@ def test_multMatVect():
A2
=
tensor
.
lmatrix
(
'A2'
)
A2
=
tensor
.
lmatrix
(
'A2'
)
s2
=
tensor
.
ivector
(
's2'
)
s2
=
tensor
.
ivector
(
's2'
)
m2
=
tensor
.
iscalar
(
'm2'
)
m2
=
tensor
.
iscalar
(
'm2'
)
g0
=
rng_mrg
.
DotModulo
()(
A1
,
s1
,
m1
,
A2
,
s2
,
m2
)
g0
=
rng_mrg
.
DotModulo
()(
A1
,
s1
,
m1
,
A2
,
s2
,
m2
)
f0
=
theano
.
function
([
A1
,
s1
,
m1
,
A2
,
s2
,
m2
],
g0
)
f0
=
theano
.
function
([
A1
,
s1
,
m1
,
A2
,
s2
,
m2
],
g0
)
A1
=
numpy
.
random
.
randint
(
0
,
numpy
.
iinfo
(
numpy
.
int32
)
.
max
,
(
3
,
3
))
.
astype
(
'int64'
)
i32max
=
numpy
.
iinfo
(
numpy
.
int32
)
.
max
s1
=
numpy
.
random
.
randint
(
0
,
numpy
.
iinfo
(
numpy
.
int32
)
.
max
,
3
)
.
astype
(
'int32'
)
m1
=
numpy
.
asarray
(
numpy
.
random
.
randint
(
numpy
.
iinfo
(
numpy
.
int32
)
.
max
),
dtype
=
"int32"
)
A1
=
numpy
.
random
.
randint
(
0
,
i32max
,
(
3
,
3
))
.
astype
(
'int64'
)
A2
=
numpy
.
random
.
randint
(
0
,
numpy
.
iinfo
(
numpy
.
int32
)
.
max
,
(
3
,
3
))
.
astype
(
'int64'
)
s1
=
numpy
.
random
.
randint
(
0
,
i32max
,
3
)
.
astype
(
'int32'
)
s2
=
numpy
.
random
.
randint
(
0
,
numpy
.
iinfo
(
numpy
.
int32
)
.
max
,
3
)
.
astype
(
'int32'
)
m1
=
numpy
.
asarray
(
numpy
.
random
.
randint
(
i32max
),
dtype
=
"int32"
)
m2
=
numpy
.
asarray
(
numpy
.
random
.
randint
(
numpy
.
iinfo
(
numpy
.
int32
)
.
max
),
dtype
=
"int32"
)
A2
=
numpy
.
random
.
randint
(
0
,
i32max
,
(
3
,
3
))
.
astype
(
'int64'
)
s2
=
numpy
.
random
.
randint
(
0
,
i32max
,
3
)
.
astype
(
'int32'
)
m2
=
numpy
.
asarray
(
numpy
.
random
.
randint
(
i32max
),
dtype
=
"int32"
)
f0
.
input_storage
[
0
]
.
storage
[
0
]
=
A1
f0
.
input_storage
[
0
]
.
storage
[
0
]
=
A1
f0
.
input_storage
[
1
]
.
storage
[
0
]
=
s1
f0
.
input_storage
[
1
]
.
storage
[
0
]
=
s1
f0
.
input_storage
[
2
]
.
storage
[
0
]
=
m1
f0
.
input_storage
[
2
]
.
storage
[
0
]
=
m1
f0
.
input_storage
[
3
]
.
storage
[
0
]
=
A2
f0
.
input_storage
[
3
]
.
storage
[
0
]
=
A2
f0
.
input_storage
[
4
]
.
storage
[
0
]
=
s2
f0
.
input_storage
[
4
]
.
storage
[
0
]
=
s2
f0
.
input_storage
[
5
]
.
storage
[
0
]
=
m2
f0
.
input_storage
[
5
]
.
storage
[
0
]
=
m2
r_a1
=
rng_mrg
.
matVecModM
(
A1
,
s1
,
m1
)
r_a1
=
rng_mrg
.
matVecModM
(
A1
,
s1
,
m1
)
r_a2
=
rng_mrg
.
matVecModM
(
A2
,
s2
,
m2
)
r_a2
=
rng_mrg
.
matVecModM
(
A2
,
s2
,
m2
)
r_b
=
f0
.
fn
()[
0
]
f0
.
fn
()
r_b
=
f0
.
output_storage
[
0
]
.
value
assert
numpy
.
allclose
(
r_a1
,
r_b
[:
3
])
assert
numpy
.
allclose
(
r_a1
,
r_b
[:
3
])
assert
numpy
.
allclose
(
r_a2
,
r_b
[
3
:])
assert
numpy
.
allclose
(
r_a2
,
r_b
[
3
:])
...
...
theano/tensor/basic.py
浏览文件 @
5c25733d
...
@@ -2028,8 +2028,9 @@ def chi2sf(x, k):
...
@@ -2028,8 +2028,9 @@ def chi2sf(x, k):
"""chi squared survival function"""
"""chi squared survival function"""
#numpy.real(float32) return a view on the inputs.
@_scal_elemwise_with_nfunc
(
'real'
,
1
,
-
1
)
#@_scal_elemwise_with_nfunc('real', 1, -1)
@_scal_elemwise
def
real
(
z
):
def
real
(
z
):
"""Return real component of complex-valued tensor `z`"""
"""Return real component of complex-valued tensor `z`"""
_tensor_py_operators
.
real
=
property
(
real
)
_tensor_py_operators
.
real
=
property
(
real
)
...
...
theano/tensor/tests/test_complex.py
浏览文件 @
5c25733d
...
@@ -5,30 +5,31 @@ from theano.tests import unittest_tools as utt
...
@@ -5,30 +5,31 @@ from theano.tests import unittest_tools as utt
from
numpy.testing
import
dec
from
numpy.testing
import
dec
class
TestRealImag
(
unittest
.
TestCase
):
class
TestRealImag
(
unittest
.
TestCase
):
def
test0
(
self
):
def
test0
(
self
):
x
=
zvector
()
x
=
zvector
()
rng
=
numpy
.
random
.
RandomState
(
23
)
rng
=
numpy
.
random
.
RandomState
(
23
)
xval
=
numpy
.
asarray
(
list
(
numpy
.
complex
(
rng
.
randn
(),
rng
.
randn
())
for
i
in
xrange
(
10
)))
xval
=
numpy
.
asarray
(
list
(
numpy
.
complex
(
rng
.
randn
(),
rng
.
randn
())
assert
numpy
.
all
(
xval
.
real
==
theano
.
function
([
x
],
real
(
x
))(
xval
))
for
i
in
xrange
(
10
)))
assert
numpy
.
all
(
xval
.
imag
==
theano
.
function
([
x
],
imag
(
x
))(
xval
))
assert
numpy
.
all
(
xval
.
real
==
theano
.
function
([
x
],
real
(
x
))(
xval
))
assert
numpy
.
all
(
xval
.
imag
==
theano
.
function
([
x
],
imag
(
x
))(
xval
))
def
test_on_real_input
(
self
):
def
test_on_real_input
(
self
):
x
=
dvector
()
x
=
dvector
()
rng
=
numpy
.
random
.
RandomState
(
23
)
rng
=
numpy
.
random
.
RandomState
(
23
)
xval
=
rng
.
randn
(
10
)
xval
=
rng
.
randn
(
10
)
numpy
.
all
(
0
==
theano
.
function
([
x
],
imag
(
x
))(
xval
))
numpy
.
all
(
0
==
theano
.
function
([
x
],
imag
(
x
))(
xval
))
numpy
.
all
(
xval
==
theano
.
function
([
x
],
real
(
x
))(
xval
))
numpy
.
all
(
xval
==
theano
.
function
([
x
],
real
(
x
))(
xval
))
x
=
imatrix
()
x
=
imatrix
()
xval
=
numpy
.
asarray
(
rng
.
randn
(
3
,
3
)
*
100
,
dtype
=
'int32'
)
xval
=
numpy
.
asarray
(
rng
.
randn
(
3
,
3
)
*
100
,
dtype
=
'int32'
)
numpy
.
all
(
0
==
theano
.
function
([
x
],
imag
(
x
))(
xval
))
numpy
.
all
(
0
==
theano
.
function
([
x
],
imag
(
x
))(
xval
))
numpy
.
all
(
xval
==
theano
.
function
([
x
],
real
(
x
))(
xval
))
numpy
.
all
(
xval
==
theano
.
function
([
x
],
real
(
x
))(
xval
))
def
test_cast
(
self
):
def
test_cast
(
self
):
x
=
zvector
()
x
=
zvector
()
self
.
assertRaises
(
TypeError
,
cast
,
x
,
'int32'
)
self
.
assertRaises
(
TypeError
,
cast
,
x
,
'int32'
)
def
test_complex
(
self
):
def
test_complex
(
self
):
...
@@ -36,27 +37,27 @@ class TestRealImag(unittest.TestCase):
...
@@ -36,27 +37,27 @@ class TestRealImag(unittest.TestCase):
m
=
fmatrix
()
m
=
fmatrix
()
c
=
complex
(
m
[
0
],
m
[
1
])
c
=
complex
(
m
[
0
],
m
[
1
])
assert
c
.
type
==
cvector
assert
c
.
type
==
cvector
r
,
i
=
[
real
(
c
),
imag
(
c
)]
r
,
i
=
[
real
(
c
),
imag
(
c
)]
assert
r
.
type
==
fvector
assert
r
.
type
==
fvector
assert
i
.
type
==
fvector
assert
i
.
type
==
fvector
f
=
theano
.
function
([
m
],
[
r
,
i
]
)
f
=
theano
.
function
([
m
],
[
r
,
i
]
)
mval
=
numpy
.
asarray
(
rng
.
randn
(
2
,
5
),
dtype
=
'float32'
)
mval
=
numpy
.
asarray
(
rng
.
randn
(
2
,
5
),
dtype
=
'float32'
)
rval
,
ival
=
f
(
mval
)
rval
,
ival
=
f
(
mval
)
assert
numpy
.
all
(
rval
==
mval
[
0
]),
(
rval
,
mval
[
0
])
assert
numpy
.
all
(
rval
==
mval
[
0
]),
(
rval
,
mval
[
0
])
assert
numpy
.
all
(
ival
==
mval
[
1
]),
(
ival
,
mval
[
1
])
assert
numpy
.
all
(
ival
==
mval
[
1
]),
(
ival
,
mval
[
1
])
@dec.knownfailureif
(
True
,
"Complex grads not enabled, see #178"
)
@dec.knownfailureif
(
True
,
"Complex grads not enabled, see #178"
)
def
test_complex_grads
(
self
):
def
test_complex_grads
(
self
):
def
f
(
m
):
def
f
(
m
):
c
=
complex
(
m
[
0
],
m
[
1
])
c
=
complex
(
m
[
0
],
m
[
1
])
return
.
5
*
real
(
c
)
+
.
9
*
imag
(
c
)
return
.
5
*
real
(
c
)
+
.
9
*
imag
(
c
)
rng
=
numpy
.
random
.
RandomState
(
9333
)
rng
=
numpy
.
random
.
RandomState
(
9333
)
mval
=
numpy
.
asarray
(
rng
.
randn
(
2
,
5
))
mval
=
numpy
.
asarray
(
rng
.
randn
(
2
,
5
))
utt
.
verify_grad
(
f
,
[
mval
])
utt
.
verify_grad
(
f
,
[
mval
])
@dec.knownfailureif
(
True
,
"Complex grads not enabled, see #178"
)
@dec.knownfailureif
(
True
,
"Complex grads not enabled, see #178"
)
def
test_mul_mixed0
(
self
):
def
test_mul_mixed0
(
self
):
def
f
(
a
):
def
f
(
a
):
...
@@ -64,7 +65,7 @@ class TestRealImag(unittest.TestCase):
...
@@ -64,7 +65,7 @@ class TestRealImag(unittest.TestCase):
return
abs
((
ac
)
**
2
)
.
sum
()
return
abs
((
ac
)
**
2
)
.
sum
()
rng
=
numpy
.
random
.
RandomState
(
9333
)
rng
=
numpy
.
random
.
RandomState
(
9333
)
aval
=
numpy
.
asarray
(
rng
.
randn
(
2
,
5
))
aval
=
numpy
.
asarray
(
rng
.
randn
(
2
,
5
))
try
:
try
:
utt
.
verify_grad
(
f
,
[
aval
])
utt
.
verify_grad
(
f
,
[
aval
])
except
utt
.
verify_grad
.
E_grad
,
e
:
except
utt
.
verify_grad
.
E_grad
,
e
:
...
@@ -72,7 +73,7 @@ class TestRealImag(unittest.TestCase):
...
@@ -72,7 +73,7 @@ class TestRealImag(unittest.TestCase):
print
e
.
analytic_grad
print
e
.
analytic_grad
raise
raise
@dec.knownfailureif
(
True
,
"Complex grads not enabled, see #178"
)
@dec.knownfailureif
(
True
,
"Complex grads not enabled, see #178"
)
def
test_mul_mixed1
(
self
):
def
test_mul_mixed1
(
self
):
def
f
(
a
):
def
f
(
a
):
...
@@ -80,22 +81,23 @@ class TestRealImag(unittest.TestCase):
...
@@ -80,22 +81,23 @@ class TestRealImag(unittest.TestCase):
return
abs
(
ac
)
.
sum
()
return
abs
(
ac
)
.
sum
()
rng
=
numpy
.
random
.
RandomState
(
9333
)
rng
=
numpy
.
random
.
RandomState
(
9333
)
aval
=
numpy
.
asarray
(
rng
.
randn
(
2
,
5
))
aval
=
numpy
.
asarray
(
rng
.
randn
(
2
,
5
))
try
:
try
:
utt
.
verify_grad
(
f
,
[
aval
])
utt
.
verify_grad
(
f
,
[
aval
])
except
utt
.
verify_grad
.
E_grad
,
e
:
except
utt
.
verify_grad
.
E_grad
,
e
:
print
e
.
num_grad
.
gf
print
e
.
num_grad
.
gf
print
e
.
analytic_grad
print
e
.
analytic_grad
raise
raise
@dec.knownfailureif
(
True
,
"Complex grads not enabled, see #178"
)
@dec.knownfailureif
(
True
,
"Complex grads not enabled, see #178"
)
def
test_mul_mixed
(
self
):
def
test_mul_mixed
(
self
):
def
f
(
a
,
b
):
def
f
(
a
,
b
):
ac
=
complex
(
a
[
0
],
a
[
1
])
ac
=
complex
(
a
[
0
],
a
[
1
])
return
abs
((
ac
*
b
)
**
2
)
.
sum
()
return
abs
((
ac
*
b
)
**
2
)
.
sum
()
rng
=
numpy
.
random
.
RandomState
(
9333
)
rng
=
numpy
.
random
.
RandomState
(
9333
)
aval
=
numpy
.
asarray
(
rng
.
randn
(
2
,
5
))
aval
=
numpy
.
asarray
(
rng
.
randn
(
2
,
5
))
bval
=
rng
.
randn
(
5
)
bval
=
rng
.
randn
(
5
)
try
:
try
:
utt
.
verify_grad
(
f
,
[
aval
,
bval
])
utt
.
verify_grad
(
f
,
[
aval
,
bval
])
...
@@ -104,22 +106,22 @@ class TestRealImag(unittest.TestCase):
...
@@ -104,22 +106,22 @@ class TestRealImag(unittest.TestCase):
print
e
.
analytic_grad
print
e
.
analytic_grad
raise
raise
@dec.knownfailureif
(
True
,
"Complex grads not enabled, see #178"
)
@dec.knownfailureif
(
True
,
"Complex grads not enabled, see #178"
)
def
test_polar_grads
(
self
):
def
test_polar_grads
(
self
):
def
f
(
m
):
def
f
(
m
):
c
=
complex_from_polar
(
abs
(
m
[
0
]),
m
[
1
])
c
=
complex_from_polar
(
abs
(
m
[
0
]),
m
[
1
])
return
.
5
*
real
(
c
)
+
.
9
*
imag
(
c
)
return
.
5
*
real
(
c
)
+
.
9
*
imag
(
c
)
rng
=
numpy
.
random
.
RandomState
(
9333
)
rng
=
numpy
.
random
.
RandomState
(
9333
)
mval
=
numpy
.
asarray
(
rng
.
randn
(
2
,
5
))
mval
=
numpy
.
asarray
(
rng
.
randn
(
2
,
5
))
utt
.
verify_grad
(
f
,
[
mval
])
utt
.
verify_grad
(
f
,
[
mval
])
@dec.knownfailureif
(
True
,
"Complex grads not enabled, see #178"
)
@dec.knownfailureif
(
True
,
"Complex grads not enabled, see #178"
)
def
test_abs_grad
(
self
):
def
test_abs_grad
(
self
):
def
f
(
m
):
def
f
(
m
):
c
=
complex
(
m
[
0
],
m
[
1
])
c
=
complex
(
m
[
0
],
m
[
1
])
return
.
5
*
abs
(
c
)
return
.
5
*
abs
(
c
)
rng
=
numpy
.
random
.
RandomState
(
9333
)
rng
=
numpy
.
random
.
RandomState
(
9333
)
mval
=
numpy
.
asarray
(
rng
.
randn
(
2
,
5
))
mval
=
numpy
.
asarray
(
rng
.
randn
(
2
,
5
))
utt
.
verify_grad
(
f
,
[
mval
])
utt
.
verify_grad
(
f
,
[
mval
])
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论