Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
824cb369
提交
824cb369
authored
2月 03, 2017
作者:
ballasn
提交者:
GitHub
2月 03, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5458 from bscellier/import_numpy_gpuarray
Import numpy gpuarray
上级
2bb065fc
5159a6b3
全部展开
显示空白字符变更
内嵌
并排
正在显示
32 个修改的文件
包含
348 行增加
和
351 行删除
+348
-351
basic_ops.py
theano/gpuarray/basic_ops.py
+10
-10
blocksparse.py
theano/gpuarray/blocksparse.py
+2
-2
dnn.py
theano/gpuarray/dnn.py
+5
-5
elemwise.py
theano/gpuarray/elemwise.py
+2
-2
linalg.py
theano/gpuarray/linalg.py
+2
-2
neighbours.py
theano/gpuarray/neighbours.py
+3
-3
nnet.py
theano/gpuarray/nnet.py
+18
-18
opt.py
theano/gpuarray/opt.py
+4
-4
opt_util.py
theano/gpuarray/opt_util.py
+2
-2
subtensor.py
theano/gpuarray/subtensor.py
+21
-21
rnn_support.py
theano/gpuarray/tests/rnn_support.py
+6
-6
test_abstractconv.py
theano/gpuarray/tests/test_abstractconv.py
+2
-2
test_basic_ops.py
theano/gpuarray/tests/test_basic_ops.py
+34
-34
test_blas.py
theano/gpuarray/tests/test_blas.py
+5
-5
test_blocksparse.py
theano/gpuarray/tests/test_blocksparse.py
+2
-2
test_cgpukernelbase.py
theano/gpuarray/tests/test_cgpukernelbase.py
+2
-2
test_dnn.py
theano/gpuarray/tests/test_dnn.py
+0
-0
test_elemwise.py
theano/gpuarray/tests/test_elemwise.py
+9
-11
test_fft.py
theano/gpuarray/tests/test_fft.py
+9
-10
test_gemmcorr.py
theano/gpuarray/tests/test_gemmcorr.py
+9
-9
test_gemmcorr3d.py
theano/gpuarray/tests/test_gemmcorr3d.py
+9
-9
test_linalg.py
theano/gpuarray/tests/test_linalg.py
+29
-29
test_multinomial.py
theano/gpuarray/tests/test_multinomial.py
+39
-39
test_nerv.py
theano/gpuarray/tests/test_nerv.py
+4
-4
test_nnet.py
theano/gpuarray/tests/test_nnet.py
+14
-14
test_opt.py
theano/gpuarray/tests/test_opt.py
+30
-30
test_pickle.py
theano/gpuarray/tests/test_pickle.py
+2
-2
test_pool.py
theano/gpuarray/tests/test_pool.py
+11
-11
test_scan.py
theano/gpuarray/tests/test_scan.py
+15
-15
test_subtensor.py
theano/gpuarray/tests/test_subtensor.py
+22
-22
test_type.py
theano/gpuarray/tests/test_type.py
+5
-5
type.py
theano/gpuarray/type.py
+21
-21
没有找到文件。
theano/gpuarray/basic_ops.py
浏览文件 @
824cb369
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
import
os
import
os
import
copy
import
copy
import
re
import
re
import
numpy
import
numpy
as
np
from
theano
import
Op
,
Apply
,
Type
,
Variable
from
theano
import
Op
,
Apply
,
Type
,
Variable
from
theano
import
tensor
,
config
from
theano
import
tensor
,
config
...
@@ -206,7 +206,7 @@ class Kernel(object):
...
@@ -206,7 +206,7 @@ class Kernel(object):
def
get_flags
(
*
types
):
def
get_flags
(
*
types
):
def
get_dtype
(
t
):
def
get_dtype
(
t
):
if
isinstance
(
t
,
string_types
):
if
isinstance
(
t
,
string_types
):
return
n
umpy
.
dtype
(
t
)
return
n
p
.
dtype
(
t
)
elif
isinstance
(
t
,
Type
):
elif
isinstance
(
t
,
Type
):
return
t
.
dtype
return
t
.
dtype
elif
isinstance
(
t
,
Variable
):
elif
isinstance
(
t
,
Variable
):
...
@@ -215,13 +215,13 @@ class Kernel(object):
...
@@ -215,13 +215,13 @@ class Kernel(object):
raise
TypeError
(
"can't get a dtype from
%
s"
%
(
type
(
t
),))
raise
TypeError
(
"can't get a dtype from
%
s"
%
(
type
(
t
),))
dtypes
=
[
get_dtype
(
t
)
for
t
in
types
]
dtypes
=
[
get_dtype
(
t
)
for
t
in
types
]
flags
=
dict
(
cluda
=
True
)
flags
=
dict
(
cluda
=
True
)
if
any
(
d
==
n
umpy
.
float64
for
d
in
dtypes
):
if
any
(
d
==
n
p
.
float64
for
d
in
dtypes
):
flags
[
'have_double'
]
=
True
flags
[
'have_double'
]
=
True
if
any
(
d
.
itemsize
<
4
for
d
in
dtypes
):
if
any
(
d
.
itemsize
<
4
for
d
in
dtypes
):
flags
[
'have_small'
]
=
True
flags
[
'have_small'
]
=
True
if
any
(
d
.
kind
==
'c'
for
d
in
dtypes
):
if
any
(
d
.
kind
==
'c'
for
d
in
dtypes
):
flags
[
'have_complex'
]
=
True
flags
[
'have_complex'
]
=
True
if
any
(
d
==
n
umpy
.
float16
for
d
in
dtypes
):
if
any
(
d
==
n
p
.
float16
for
d
in
dtypes
):
flags
[
'have_half'
]
=
True
flags
[
'have_half'
]
=
True
return
flags
return
flags
...
@@ -275,8 +275,8 @@ def get_ctype(dtype):
...
@@ -275,8 +275,8 @@ def get_ctype(dtype):
elif
dtype
==
gpuarray
.
SSIZE
:
elif
dtype
==
gpuarray
.
SSIZE
:
return
"ssize_t"
return
"ssize_t"
else
:
else
:
if
not
isinstance
(
dtype
,
n
umpy
.
dtype
):
if
not
isinstance
(
dtype
,
n
p
.
dtype
):
dtype
=
n
umpy
.
dtype
(
dtype
)
dtype
=
n
p
.
dtype
(
dtype
)
return
'npy_'
+
dtype
.
name
return
'npy_'
+
dtype
.
name
...
@@ -311,7 +311,7 @@ class GpuKernelBase(object):
...
@@ -311,7 +311,7 @@ class GpuKernelBase(object):
except
MethodNotDefined
:
except
MethodNotDefined
:
o
=
[]
o
=
[]
# We rely on the input types for the directory to gpuarray includes
# We rely on the input types for the directory to gpuarray includes
return
o
+
[
n
umpy
.
get_include
()]
return
o
+
[
n
p
.
get_include
()]
def
_generate_kernel_bin
(
self
,
k
,
ctx
):
def
_generate_kernel_bin
(
self
,
k
,
ctx
):
gk
=
gpuarray
.
GpuKernel
(
k
.
code
,
k
.
name
,
k
.
params
,
context
=
ctx
,
gk
=
gpuarray
.
GpuKernel
(
k
.
code
,
k
.
name
,
k
.
params
,
context
=
ctx
,
...
@@ -466,7 +466,7 @@ def get_dtype(s):
...
@@ -466,7 +466,7 @@ def get_dtype(s):
if
s
==
'ssize'
:
if
s
==
'ssize'
:
return
gpuarray
.
SSIZE
return
gpuarray
.
SSIZE
else
:
else
:
return
n
umpy
.
dtype
(
s
)
return
n
p
.
dtype
(
s
)
class
CGpuKernelBase
(
COp
,
GpuKernelBase
):
class
CGpuKernelBase
(
COp
,
GpuKernelBase
):
...
@@ -565,7 +565,7 @@ class HostFromGpu(Op):
...
@@ -565,7 +565,7 @@ class HostFromGpu(Op):
def
perform
(
self
,
node
,
inp
,
out
):
def
perform
(
self
,
node
,
inp
,
out
):
x
,
=
inp
x
,
=
inp
z
,
=
out
z
,
=
out
z
[
0
]
=
n
umpy
.
asarray
(
x
)
z
[
0
]
=
n
p
.
asarray
(
x
)
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
outputs
,
sub
):
return
"""
return
"""
...
@@ -1285,7 +1285,7 @@ class GpuJoin(HideC, Join):
...
@@ -1285,7 +1285,7 @@ class GpuJoin(HideC, Join):
if
axis
<
0
:
if
axis
<
0
:
axis
+=
axis_and_tensors
[
1
]
.
ndim
axis
+=
axis_and_tensors
[
1
]
.
ndim
# we check these tensors for being empty.
# we check these tensors for being empty.
if
(
view
!=
-
1
)
and
n
umpy
.
all
(
if
(
view
!=
-
1
)
and
n
p
.
all
(
[
tensor
.
shape
[
axis
]
==
0
for
tensor
in
[
tensor
.
shape
[
axis
]
==
0
for
tensor
in
tensors
[
0
:
view
]
+
tensors
[
view
+
1
:]]):
tensors
[
0
:
view
]
+
tensors
[
view
+
1
:]]):
out
[
0
]
=
tensors
[
view
]
out
[
0
]
=
tensors
[
view
]
...
...
theano/gpuarray/blocksparse.py
浏览文件 @
824cb369
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
import
logging
import
logging
import
os
import
os
import
numpy
import
numpy
as
np
from
theano
import
Apply
,
tensor
from
theano
import
Apply
,
tensor
from
theano.gof
import
COp
from
theano.gof
import
COp
from
theano.tensor
import
discrete_dtypes
,
as_tensor_variable
from
theano.tensor
import
discrete_dtypes
,
as_tensor_variable
...
@@ -121,7 +121,7 @@ class GpuSparseBlockOuter(COp):
...
@@ -121,7 +121,7 @@ class GpuSparseBlockOuter(COp):
def
make_node
(
self
,
o
,
x
,
y
,
xIdx
,
yIdx
,
alpha
=
None
):
def
make_node
(
self
,
o
,
x
,
y
,
xIdx
,
yIdx
,
alpha
=
None
):
ctx
=
infer_context_name
(
o
,
x
,
y
)
ctx
=
infer_context_name
(
o
,
x
,
y
)
one
=
tensor
.
constant
(
n
umpy
.
asarray
(
1.0
,
dtype
=
'float32'
))
one
=
tensor
.
constant
(
n
p
.
asarray
(
1.0
,
dtype
=
'float32'
))
o
=
as_gpuarray_variable
(
o
,
ctx
)
o
=
as_gpuarray_variable
(
o
,
ctx
)
x
=
as_gpuarray_variable
(
x
,
ctx
)
x
=
as_gpuarray_variable
(
x
,
ctx
)
y
=
as_gpuarray_variable
(
y
,
ctx
)
y
=
as_gpuarray_variable
(
y
,
ctx
)
...
...
theano/gpuarray/dnn.py
浏览文件 @
824cb369
...
@@ -4,7 +4,7 @@ import os
...
@@ -4,7 +4,7 @@ import os
import
sys
import
sys
import
warnings
import
warnings
import
numpy
import
numpy
as
np
from
six
import
integer_types
from
six
import
integer_types
import
theano
import
theano
...
@@ -457,8 +457,8 @@ gpu_dnn_conv_desc.cache = {}
...
@@ -457,8 +457,8 @@ gpu_dnn_conv_desc.cache = {}
# scalar constants
# scalar constants
_zero
=
constant
(
n
umpy
.
asarray
(
0.0
,
dtype
=
'float64'
))
_zero
=
constant
(
n
p
.
asarray
(
0.0
,
dtype
=
'float64'
))
_one
=
constant
(
n
umpy
.
asarray
(
1.0
,
dtype
=
'float64'
))
_one
=
constant
(
n
p
.
asarray
(
1.0
,
dtype
=
'float64'
))
def
ensure_dt
(
val
,
default
,
name
,
dtype
):
def
ensure_dt
(
val
,
default
,
name
,
dtype
):
...
@@ -2482,8 +2482,8 @@ class RNNBlock(object):
...
@@ -2482,8 +2482,8 @@ class RNNBlock(object):
bytesize
=
_get_param_size
(
self
.
desc
,
input_size
,
self
.
dtype
,
bytesize
=
_get_param_size
(
self
.
desc
,
input_size
,
self
.
dtype
,
self
.
context_name
)
self
.
context_name
)
bytesize
=
int
(
bytesize
)
bytesize
=
int
(
bytesize
)
assert
bytesize
%
n
umpy
.
dtype
(
self
.
dtype
)
.
itemsize
==
0
assert
bytesize
%
n
p
.
dtype
(
self
.
dtype
)
.
itemsize
==
0
return
bytesize
//
n
umpy
.
dtype
(
self
.
dtype
)
.
itemsize
return
bytesize
//
n
p
.
dtype
(
self
.
dtype
)
.
itemsize
def
split_params
(
self
,
w
,
layer
,
input_size
):
def
split_params
(
self
,
w
,
layer
,
input_size
):
if
not
isinstance
(
w
,
GpuArraySharedVariable
):
if
not
isinstance
(
w
,
GpuArraySharedVariable
):
...
...
theano/gpuarray/elemwise.py
浏览文件 @
824cb369
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
copy
import
copy
import
numpy
import
numpy
as
np
import
theano
import
theano
from
theano
import
Apply
,
scalar
,
config
,
Op
from
theano
import
Apply
,
scalar
,
config
,
Op
...
@@ -27,7 +27,7 @@ from .fp16_help import load_w, write_w
...
@@ -27,7 +27,7 @@ from .fp16_help import load_w, write_w
def
make_argument
(
v
,
name
):
def
make_argument
(
v
,
name
):
return
ArrayArg
(
n
umpy
.
dtype
(
v
.
type
.
dtype
),
name
)
return
ArrayArg
(
n
p
.
dtype
(
v
.
type
.
dtype
),
name
)
def
as_C_string_const
(
s
):
def
as_C_string_const
(
s
):
...
...
theano/gpuarray/linalg.py
浏览文件 @
824cb369
...
@@ -7,7 +7,7 @@ import warnings
...
@@ -7,7 +7,7 @@ import warnings
from
theano
import
Op
from
theano
import
Op
from
theano.gpuarray
import
basic_ops
,
GpuArrayType
from
theano.gpuarray
import
basic_ops
,
GpuArrayType
import
numpy
import
numpy
as
np
from
numpy.linalg.linalg
import
LinAlgError
from
numpy.linalg.linalg
import
LinAlgError
try
:
try
:
...
@@ -107,7 +107,7 @@ class GpuCusolverSolve(Op):
...
@@ -107,7 +107,7 @@ class GpuCusolverSolve(Op):
ctx
.
cusolver_handle
=
cusolver
.
cusolverDnCreate
()
ctx
.
cusolver_handle
=
cusolver
.
cusolverDnCreate
()
def
check_dev_info
(
self
,
dev_info
):
def
check_dev_info
(
self
,
dev_info
):
val
=
n
umpy
.
asarray
(
dev_info
)[
0
]
val
=
n
p
.
asarray
(
dev_info
)[
0
]
if
val
>
0
:
if
val
>
0
:
raise
LinAlgError
(
'A is singular'
)
raise
LinAlgError
(
'A is singular'
)
...
...
theano/gpuarray/neighbours.py
浏览文件 @
824cb369
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
numpy
import
numpy
as
np
from
theano
import
Op
,
Apply
,
config
from
theano
import
Op
,
Apply
,
config
from
theano.tensor.nnet.neighbours
import
Images2Neibs
from
theano.tensor.nnet.neighbours
import
Images2Neibs
...
@@ -256,8 +256,8 @@ class GpuImages2Neibs(GpuKernelBase, Images2Neibs, Op):
...
@@ -256,8 +256,8 @@ class GpuImages2Neibs(GpuKernelBase, Images2Neibs, Op):
dtype_neib_shape
=
node
.
inputs
[
1
]
.
dtype
dtype_neib_shape
=
node
.
inputs
[
1
]
.
dtype
dtype_neib_step
=
node
.
inputs
[
2
]
.
dtype
dtype_neib_step
=
node
.
inputs
[
2
]
.
dtype
dtype_z
=
node
.
outputs
[
0
]
.
dtype
dtype_z
=
node
.
outputs
[
0
]
.
dtype
itemsize_ten4
=
n
umpy
.
dtype
(
dtype_ten4
)
.
itemsize
itemsize_ten4
=
n
p
.
dtype
(
dtype_ten4
)
.
itemsize
itemsize_z
=
n
umpy
.
dtype
(
dtype_z
)
.
itemsize
itemsize_z
=
n
p
.
dtype
(
dtype_z
)
.
itemsize
typecode_z
=
pygpu
.
gpuarray
.
dtype_to_typecode
(
node
.
outputs
[
0
]
.
dtype
)
typecode_z
=
pygpu
.
gpuarray
.
dtype_to_typecode
(
node
.
outputs
[
0
]
.
dtype
)
ten4
,
neib_shape
,
neib_step
=
inp
ten4
,
neib_shape
,
neib_step
=
inp
z
,
=
out
z
,
=
out
...
...
theano/gpuarray/nnet.py
浏览文件 @
824cb369
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
os
import
os
import
numpy
import
numpy
as
np
from
theano
import
Op
,
Apply
,
config
from
theano
import
Op
,
Apply
,
config
from
six
import
StringIO
from
six
import
StringIO
...
@@ -195,13 +195,13 @@ class GpuCrossentropySoftmaxArgmax1HotWithBias(GpuKernelBase, Op):
...
@@ -195,13 +195,13 @@ class GpuCrossentropySoftmaxArgmax1HotWithBias(GpuKernelBase, Op):
def
c_code
(
self
,
node
,
nodename
,
inp
,
out
,
sub
):
def
c_code
(
self
,
node
,
nodename
,
inp
,
out
,
sub
):
if
node
.
inputs
[
0
]
.
type
.
context
.
kind
!=
b
'cuda'
:
if
node
.
inputs
[
0
]
.
type
.
context
.
kind
!=
b
'cuda'
:
raise
NotImplementedError
(
'cuda only'
)
raise
NotImplementedError
(
'cuda only'
)
itemsize_x
=
n
umpy
.
dtype
(
node
.
inputs
[
0
]
.
dtype
)
.
itemsize
itemsize_x
=
n
p
.
dtype
(
node
.
inputs
[
0
]
.
dtype
)
.
itemsize
worksize_x
=
n
umpy
.
dtype
(
work_dtype
(
node
.
inputs
[
0
]
.
dtype
))
.
itemsize
worksize_x
=
n
p
.
dtype
(
work_dtype
(
node
.
inputs
[
0
]
.
dtype
))
.
itemsize
itemsize_b
=
n
umpy
.
dtype
(
node
.
inputs
[
1
]
.
dtype
)
.
itemsize
itemsize_b
=
n
p
.
dtype
(
node
.
inputs
[
1
]
.
dtype
)
.
itemsize
itemsize_y_idx
=
n
umpy
.
dtype
(
node
.
inputs
[
2
]
.
dtype
)
.
itemsize
itemsize_y_idx
=
n
p
.
dtype
(
node
.
inputs
[
2
]
.
dtype
)
.
itemsize
itemsize_nll
=
n
umpy
.
dtype
(
node
.
outputs
[
0
]
.
dtype
)
.
itemsize
itemsize_nll
=
n
p
.
dtype
(
node
.
outputs
[
0
]
.
dtype
)
.
itemsize
itemsize_sm
=
n
umpy
.
dtype
(
node
.
outputs
[
1
]
.
dtype
)
.
itemsize
itemsize_sm
=
n
p
.
dtype
(
node
.
outputs
[
1
]
.
dtype
)
.
itemsize
itemsize_am
=
n
umpy
.
dtype
(
node
.
outputs
[
2
]
.
dtype
)
.
itemsize
itemsize_am
=
n
p
.
dtype
(
node
.
outputs
[
2
]
.
dtype
)
.
itemsize
x
,
b
,
y_idx
=
inp
x
,
b
,
y_idx
=
inp
nll
,
sm
,
am
=
out
nll
,
sm
,
am
=
out
fail
=
sub
[
'fail'
]
fail
=
sub
[
'fail'
]
...
@@ -307,15 +307,15 @@ class GpuCrossentropySoftmax1HotWithBiasDx(GpuKernelBase, Op):
...
@@ -307,15 +307,15 @@ class GpuCrossentropySoftmax1HotWithBiasDx(GpuKernelBase, Op):
if
node
.
inputs
[
0
]
.
type
.
context
.
kind
!=
b
'cuda'
:
if
node
.
inputs
[
0
]
.
type
.
context
.
kind
!=
b
'cuda'
:
raise
NotImplementedError
(
"cuda only"
)
raise
NotImplementedError
(
"cuda only"
)
typecode_dx
=
pygpu
.
gpuarray
.
dtype_to_typecode
(
node
.
outputs
[
0
]
.
dtype
)
typecode_dx
=
pygpu
.
gpuarray
.
dtype_to_typecode
(
node
.
outputs
[
0
]
.
dtype
)
itemsize_dnll
=
n
umpy
.
dtype
(
node
.
inputs
[
0
]
.
dtype
)
.
itemsize
itemsize_dnll
=
n
p
.
dtype
(
node
.
inputs
[
0
]
.
dtype
)
.
itemsize
itemsize_sm
=
n
umpy
.
dtype
(
node
.
inputs
[
1
]
.
dtype
)
.
itemsize
itemsize_sm
=
n
p
.
dtype
(
node
.
inputs
[
1
]
.
dtype
)
.
itemsize
itemsize_y_idx
=
n
umpy
.
dtype
(
node
.
inputs
[
2
]
.
dtype
)
.
itemsize
itemsize_y_idx
=
n
p
.
dtype
(
node
.
inputs
[
2
]
.
dtype
)
.
itemsize
itemsize_dx
=
n
umpy
.
dtype
(
node
.
outputs
[
0
]
.
dtype
)
.
itemsize
itemsize_dx
=
n
p
.
dtype
(
node
.
outputs
[
0
]
.
dtype
)
.
itemsize
dtype_dnll
=
node
.
inputs
[
0
]
.
dtype
dtype_dnll
=
node
.
inputs
[
0
]
.
dtype
dtype_sm
=
node
.
inputs
[
1
]
.
dtype
dtype_sm
=
node
.
inputs
[
1
]
.
dtype
dtype_y_idx
=
node
.
inputs
[
2
]
.
dtype
dtype_y_idx
=
node
.
inputs
[
2
]
.
dtype
dtype_dx
=
node
.
outputs
[
0
]
.
dtype
dtype_dx
=
node
.
outputs
[
0
]
.
dtype
type_intp
=
gpuarray
.
dtype_to_ctype
(
n
umpy
.
intp
)
type_intp
=
gpuarray
.
dtype_to_ctype
(
n
p
.
intp
)
dnll
,
sm
,
y_idx
=
inp
dnll
,
sm
,
y_idx
=
inp
dx
,
=
out
dx
,
=
out
fail
=
sub
[
'fail'
]
fail
=
sub
[
'fail'
]
...
@@ -519,8 +519,8 @@ class GpuSoftmax(GpuKernelBase, Op):
...
@@ -519,8 +519,8 @@ class GpuSoftmax(GpuKernelBase, Op):
dtype_x
=
node
.
inputs
[
0
]
.
dtype
dtype_x
=
node
.
inputs
[
0
]
.
dtype
work_x
=
work_dtype
(
dtype_x
)
work_x
=
work_dtype
(
dtype_x
)
dtype_z
=
node
.
outputs
[
0
]
.
dtype
dtype_z
=
node
.
outputs
[
0
]
.
dtype
itemsize_x
=
n
umpy
.
dtype
(
dtype_x
)
.
itemsize
itemsize_x
=
n
p
.
dtype
(
dtype_x
)
.
itemsize
itemsize_z
=
n
umpy
.
dtype
(
dtype_z
)
.
itemsize
itemsize_z
=
n
p
.
dtype
(
dtype_z
)
.
itemsize
typecode
=
pygpu
.
gpuarray
.
dtype_to_typecode
(
node
.
outputs
[
0
]
.
dtype
)
typecode
=
pygpu
.
gpuarray
.
dtype_to_typecode
(
node
.
outputs
[
0
]
.
dtype
)
x
,
=
inp
x
,
=
inp
z
,
=
out
z
,
=
out
...
@@ -719,9 +719,9 @@ class GpuSoftmaxWithBias(GpuKernelBase, Op):
...
@@ -719,9 +719,9 @@ class GpuSoftmaxWithBias(GpuKernelBase, Op):
dtype_b
=
node
.
inputs
[
1
]
.
dtype
dtype_b
=
node
.
inputs
[
1
]
.
dtype
dtype_z
=
node
.
outputs
[
0
]
.
dtype
dtype_z
=
node
.
outputs
[
0
]
.
dtype
work_x
=
work_dtype
(
dtype_x
)
work_x
=
work_dtype
(
dtype_x
)
itemsize_x
=
n
umpy
.
dtype
(
dtype_x
)
.
itemsize
itemsize_x
=
n
p
.
dtype
(
dtype_x
)
.
itemsize
itemsize_b
=
n
umpy
.
dtype
(
dtype_b
)
.
itemsize
itemsize_b
=
n
p
.
dtype
(
dtype_b
)
.
itemsize
itemsize_z
=
n
umpy
.
dtype
(
dtype_z
)
.
itemsize
itemsize_z
=
n
p
.
dtype
(
dtype_z
)
.
itemsize
typecode
=
pygpu
.
gpuarray
.
dtype_to_typecode
(
node
.
outputs
[
0
]
.
dtype
)
typecode
=
pygpu
.
gpuarray
.
dtype_to_typecode
(
node
.
outputs
[
0
]
.
dtype
)
x
,
b
=
inp
x
,
b
=
inp
z
,
=
out
z
,
=
out
...
...
theano/gpuarray/opt.py
浏览文件 @
824cb369
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
copy
import
copy
import
numpy
import
numpy
as
np
import
logging
import
logging
import
pdb
import
pdb
import
time
import
time
...
@@ -622,7 +622,7 @@ def local_gpualloc_memset_0(node):
...
@@ -622,7 +622,7 @@ def local_gpualloc_memset_0(node):
inp
=
node
.
inputs
[
0
]
inp
=
node
.
inputs
[
0
]
if
(
isinstance
(
inp
,
GpuArrayConstant
)
and
if
(
isinstance
(
inp
,
GpuArrayConstant
)
and
inp
.
data
.
size
==
1
and
inp
.
data
.
size
==
1
and
(
n
umpy
.
asarray
(
inp
.
data
)
==
0
)
.
all
()):
(
n
p
.
asarray
(
inp
.
data
)
==
0
)
.
all
()):
new_op
=
gpu_alloc
(
node
.
op
.
context_name
,
memset_0
=
True
)
new_op
=
gpu_alloc
(
node
.
op
.
context_name
,
memset_0
=
True
)
return
[
new_op
(
*
node
.
inputs
)]
return
[
new_op
(
*
node
.
inputs
)]
...
@@ -632,7 +632,7 @@ def local_gpualloc_memset_0(node):
...
@@ -632,7 +632,7 @@ def local_gpualloc_memset_0(node):
def
local_gpua_alloc_empty_to_zeros
(
node
):
def
local_gpua_alloc_empty_to_zeros
(
node
):
if
isinstance
(
node
.
op
,
GpuAllocEmpty
):
if
isinstance
(
node
.
op
,
GpuAllocEmpty
):
context_name
=
infer_context_name
(
*
node
.
inputs
)
context_name
=
infer_context_name
(
*
node
.
inputs
)
z
=
n
umpy
.
asarray
(
0
,
dtype
=
node
.
outputs
[
0
]
.
dtype
)
z
=
n
p
.
asarray
(
0
,
dtype
=
node
.
outputs
[
0
]
.
dtype
)
return
[
gpu_alloc
(
context_name
)(
as_gpuarray_variable
(
z
,
context_name
),
return
[
gpu_alloc
(
context_name
)(
as_gpuarray_variable
(
z
,
context_name
),
*
node
.
inputs
)]
*
node
.
inputs
)]
optdb
.
register
(
'local_gpua_alloc_empty_to_zeros'
,
optdb
.
register
(
'local_gpua_alloc_empty_to_zeros'
,
...
@@ -830,7 +830,7 @@ def local_gpua_shape_graph(op, context_name, inputs, outputs):
...
@@ -830,7 +830,7 @@ def local_gpua_shape_graph(op, context_name, inputs, outputs):
def
gpu_print_wrapper
(
op
,
cnda
):
def
gpu_print_wrapper
(
op
,
cnda
):
op
.
old_op
.
global_fn
(
op
.
old_op
,
n
umpy
.
asarray
(
cnda
))
op
.
old_op
.
global_fn
(
op
.
old_op
,
n
p
.
asarray
(
cnda
))
@register_opt
(
'fast_compile'
)
@register_opt
(
'fast_compile'
)
...
...
theano/gpuarray/opt_util.py
浏览文件 @
824cb369
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
from
functools
import
wraps
from
functools
import
wraps
import
numpy
import
numpy
as
np
from
theano
import
tensor
,
scalar
as
scal
,
Constant
from
theano
import
tensor
,
scalar
as
scal
,
Constant
from
theano.gof
import
local_optimizer
from
theano.gof
import
local_optimizer
...
@@ -11,7 +11,7 @@ from theano.tensor import (DimShuffle, get_scalar_constant_value,
...
@@ -11,7 +11,7 @@ from theano.tensor import (DimShuffle, get_scalar_constant_value,
from
.basic_ops
import
GpuFromHost
,
HostFromGpu
,
GpuAllocEmpty
,
GpuReshape
,
gpu_alloc_empty
from
.basic_ops
import
GpuFromHost
,
HostFromGpu
,
GpuAllocEmpty
,
GpuReshape
,
gpu_alloc_empty
from
.elemwise
import
GpuDimShuffle
,
GpuElemwise
from
.elemwise
import
GpuDimShuffle
,
GpuElemwise
_one
=
scal
.
constant
(
n
umpy
.
asarray
(
1.0
,
dtype
=
'float32'
))
_one
=
scal
.
constant
(
n
p
.
asarray
(
1.0
,
dtype
=
'float32'
))
def
grab_cpu_scalar
(
v
,
nd
):
def
grab_cpu_scalar
(
v
,
nd
):
...
...
theano/gpuarray/subtensor.py
浏览文件 @
824cb369
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
import
os
import
os
import
numpy
import
numpy
as
np
from
six
import
integer_types
from
six
import
integer_types
from
six.moves
import
StringIO
from
six.moves
import
StringIO
...
@@ -128,7 +128,7 @@ class GpuSubtensor(HideC, Subtensor):
...
@@ -128,7 +128,7 @@ class GpuSubtensor(HideC, Subtensor):
def
fix_idx
(
idx
):
def
fix_idx
(
idx
):
if
idx
is
None
:
if
idx
is
None
:
return
"0"
,
1
return
"0"
,
1
elif
isinstance
(
idx
,
(
n
umpy
.
integer
,
integer_types
)):
elif
isinstance
(
idx
,
(
n
p
.
integer
,
integer_types
)):
return
str
(
idx
),
0
return
str
(
idx
),
0
elif
isinstance
(
idx
,
gof
.
Type
):
elif
isinstance
(
idx
,
gof
.
Type
):
return
indices
.
pop
(
0
),
0
return
indices
.
pop
(
0
),
0
...
@@ -155,7 +155,7 @@ class GpuSubtensor(HideC, Subtensor):
...
@@ -155,7 +155,7 @@ class GpuSubtensor(HideC, Subtensor):
else
:
else
:
if
isinstance
(
idx
,
gof
.
Type
):
if
isinstance
(
idx
,
gof
.
Type
):
start
=
indices
.
pop
(
0
)
start
=
indices
.
pop
(
0
)
elif
isinstance
(
idx
,
(
n
umpy
.
integer
,
integer_types
)):
elif
isinstance
(
idx
,
(
n
p
.
integer
,
integer_types
)):
start
=
idx
start
=
idx
else
:
else
:
assert
0
,
idx
assert
0
,
idx
...
@@ -511,7 +511,7 @@ class GpuAdvancedSubtensor(HideC, tensor.AdvancedSubtensor):
...
@@ -511,7 +511,7 @@ class GpuAdvancedSubtensor(HideC, tensor.AdvancedSubtensor):
# if there are more than one (narray > 1) it should be ignored.
# if there are more than one (narray > 1) it should be ignored.
ap
=
0
ap
=
0
for
k
,
i
in
enumerate
(
list
(
nidx
)):
for
k
,
i
in
enumerate
(
list
(
nidx
)):
if
(
isinstance
(
i
,
n
umpy
.
ndarray
)
and
if
(
isinstance
(
i
,
n
p
.
ndarray
)
and
i
.
ndim
!=
0
):
i
.
ndim
!=
0
):
transp
.
remove
(
k
)
transp
.
remove
(
k
)
transp
.
insert
(
p
,
k
)
transp
.
insert
(
p
,
k
)
...
@@ -545,7 +545,7 @@ class GpuAdvancedSubtensor(HideC, tensor.AdvancedSubtensor):
...
@@ -545,7 +545,7 @@ class GpuAdvancedSubtensor(HideC, tensor.AdvancedSubtensor):
x
=
x
.
__getitem__
(
idx_
)
x
=
x
.
__getitem__
(
idx_
)
# flatten the array-indexed dimensions
# flatten the array-indexed dimensions
shape
=
((
n
umpy
.
prod
(
x
.
shape
[
0
:
p
]),)
+
shape
=
((
n
p
.
prod
(
x
.
shape
[
0
:
p
]),)
+
x
.
shape
[
p
:])
x
.
shape
[
p
:])
input_flat
=
x
.
reshape
(
shape
)
input_flat
=
x
.
reshape
(
shape
)
...
@@ -644,7 +644,7 @@ class GpuAdvancedIncSubtensor1(Op):
...
@@ -644,7 +644,7 @@ class GpuAdvancedIncSubtensor1(Op):
# content to index x and y (This is because we serve as
# content to index x and y (This is because we serve as
# fallback for _dev20).
# fallback for _dev20).
if
isinstance
(
idx
,
gpuarray
.
GpuArray
):
if
isinstance
(
idx
,
gpuarray
.
GpuArray
):
idx
=
n
umpy
.
asarray
(
idx
)
idx
=
n
p
.
asarray
(
idx
)
# If `y` has as many dimensions as `x`, then we want to iterate
# If `y` has as many dimensions as `x`, then we want to iterate
# jointly on `x` and `y`. Otherwise, it means `y` should be
# jointly on `x` and `y`. Otherwise, it means `y` should be
...
@@ -877,10 +877,10 @@ if (GpuArray_vector_add_fast(%(out)s, %(y)s, %(ind)s, %(set_instead_of_inc)s)) {
...
@@ -877,10 +877,10 @@ if (GpuArray_vector_add_fast(%(out)s, %(y)s, %(ind)s, %(set_instead_of_inc)s)) {
dtype_y
=
node
.
inputs
[
1
]
.
dtype
dtype_y
=
node
.
inputs
[
1
]
.
dtype
dtype_ind
=
node
.
inputs
[
2
]
.
dtype
dtype_ind
=
node
.
inputs
[
2
]
.
dtype
dtype_out
=
node
.
outputs
[
0
]
.
dtype
dtype_out
=
node
.
outputs
[
0
]
.
dtype
itemsize_x
=
n
umpy
.
dtype
(
dtype_x
)
.
itemsize
itemsize_x
=
n
p
.
dtype
(
dtype_x
)
.
itemsize
itemsize_y
=
n
umpy
.
dtype
(
dtype_y
)
.
itemsize
itemsize_y
=
n
p
.
dtype
(
dtype_y
)
.
itemsize
itemsize_ind
=
n
umpy
.
dtype
(
dtype_ind
)
.
itemsize
itemsize_ind
=
n
p
.
dtype
(
dtype_ind
)
.
itemsize
itemsize_out
=
n
umpy
.
dtype
(
dtype_out
)
.
itemsize
itemsize_out
=
n
p
.
dtype
(
dtype_out
)
.
itemsize
flags
=
Kernel
.
get_flags
(
dtype_x
,
dtype_y
,
dtype_ind
)
flags
=
Kernel
.
get_flags
(
dtype_x
,
dtype_y
,
dtype_ind
)
type_x
=
gpuarray
.
dtype_to_ctype
(
dtype_x
)
type_x
=
gpuarray
.
dtype_to_ctype
(
dtype_x
)
type_y
=
gpuarray
.
dtype_to_ctype
(
dtype_y
)
type_y
=
gpuarray
.
dtype_to_ctype
(
dtype_y
)
...
@@ -1007,10 +1007,10 @@ __device__ ga_half atomicExch(ga_half *addr, ga_half val) {
...
@@ -1007,10 +1007,10 @@ __device__ ga_half atomicExch(ga_half *addr, ga_half val) {
dtype_y
=
node
.
inputs
[
1
]
.
dtype
dtype_y
=
node
.
inputs
[
1
]
.
dtype
dtype_ind
=
node
.
inputs
[
2
]
.
dtype
dtype_ind
=
node
.
inputs
[
2
]
.
dtype
dtype_out
=
node
.
outputs
[
0
]
.
dtype
dtype_out
=
node
.
outputs
[
0
]
.
dtype
itemsize_x
=
n
umpy
.
dtype
(
dtype_x
)
.
itemsize
itemsize_x
=
n
p
.
dtype
(
dtype_x
)
.
itemsize
itemsize_y
=
n
umpy
.
dtype
(
dtype_y
)
.
itemsize
itemsize_y
=
n
p
.
dtype
(
dtype_y
)
.
itemsize
itemsize_ind
=
n
umpy
.
dtype
(
dtype_ind
)
.
itemsize
itemsize_ind
=
n
p
.
dtype
(
dtype_ind
)
.
itemsize
itemsize_out
=
n
umpy
.
dtype
(
dtype_out
)
.
itemsize
itemsize_out
=
n
p
.
dtype
(
dtype_out
)
.
itemsize
k_var
=
"k_vector_add_fast_"
+
nodename
k_var
=
"k_vector_add_fast_"
+
nodename
return
super
(
GpuAdvancedIncSubtensor1_dev20
,
self
)
.
c_support_code_struct
(
node
,
nodename
)
+
"""
return
super
(
GpuAdvancedIncSubtensor1_dev20
,
self
)
.
c_support_code_struct
(
node
,
nodename
)
+
"""
...
@@ -1112,7 +1112,7 @@ class GpuDiagonal(Subtensor):
...
@@ -1112,7 +1112,7 @@ class GpuDiagonal(Subtensor):
if
x
.
size
==
0
:
if
x
.
size
==
0
:
out_shape
=
[
d
for
i
,
d
in
enumerate
(
x
.
shape
)
out_shape
=
[
d
for
i
,
d
in
enumerate
(
x
.
shape
)
if
i
not
in
(
self
.
axis1
,
self
.
axis2
)]
if
i
not
in
(
self
.
axis1
,
self
.
axis2
)]
diag_size
=
n
umpy
.
min
((
x
.
shape
[
self
.
axis1
],
x
.
shape
[
self
.
axis2
]))
diag_size
=
n
p
.
min
((
x
.
shape
[
self
.
axis1
],
x
.
shape
[
self
.
axis2
]))
out_shape
.
append
(
diag_size
)
out_shape
.
append
(
diag_size
)
z
[
0
]
=
node
.
outputs
[
0
]
.
type
.
value_zeros
(
tuple
(
out_shape
))
z
[
0
]
=
node
.
outputs
[
0
]
.
type
.
value_zeros
(
tuple
(
out_shape
))
return
return
...
@@ -1128,15 +1128,15 @@ class GpuDiagonal(Subtensor):
...
@@ -1128,15 +1128,15 @@ class GpuDiagonal(Subtensor):
if
x
.
shape
[
stride_axis
]
<
x
.
shape
[
slice_axis
]:
if
x
.
shape
[
stride_axis
]
<
x
.
shape
[
slice_axis
]:
# in the bigger triangle
# in the bigger triangle
numstride
=
small_axis
-
n
umpy
.
max
((
numstride
=
small_axis
-
n
p
.
max
((
0
,
small_axis
+
n
umpy
.
abs
(
self
.
offset
)
-
large_axis
))
0
,
small_axis
+
n
p
.
abs
(
self
.
offset
)
-
large_axis
))
else
:
else
:
# in the smaller triangle
# in the smaller triangle
numstride
=
small_axis
-
n
umpy
.
abs
(
self
.
offset
)
numstride
=
small_axis
-
n
p
.
abs
(
self
.
offset
)
slicer
=
[
n
umpy
.
s_
[:],
]
*
x
.
ndim
slicer
=
[
n
p
.
s_
[:],
]
*
x
.
ndim
slicer
[
stride_axis
]
=
n
umpy
.
s_
[:
numstride
]
slicer
[
stride_axis
]
=
n
p
.
s_
[:
numstride
]
slicer
[
slice_axis
]
=
n
umpy
.
abs
(
self
.
offset
)
slicer
[
slice_axis
]
=
n
p
.
abs
(
self
.
offset
)
slicer
=
tuple
(
slicer
)
slicer
=
tuple
(
slicer
)
# step 2) Swap stride_axis to the last dim because we want the dim on
# step 2) Swap stride_axis to the last dim because we want the dim on
...
...
theano/gpuarray/tests/rnn_support.py
浏览文件 @
824cb369
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
import
theano
import
theano
import
theano.tensor
as
T
import
theano.tensor
as
T
import
numpy
import
numpy
as
np
class
Model
(
object
):
class
Model
(
object
):
...
@@ -27,9 +27,9 @@ class Model(object):
...
@@ -27,9 +27,9 @@ class Model(object):
def
uniform
(
stdev
,
size
):
def
uniform
(
stdev
,
size
):
"""uniform distribution with the given stdev and size"""
"""uniform distribution with the given stdev and size"""
return
n
umpy
.
random
.
uniform
(
return
n
p
.
random
.
uniform
(
low
=-
stdev
*
n
umpy
.
sqrt
(
3
),
low
=-
stdev
*
n
p
.
sqrt
(
3
),
high
=
stdev
*
n
umpy
.
sqrt
(
3
),
high
=
stdev
*
n
p
.
sqrt
(
3
),
size
=
size
size
=
size
)
.
astype
(
theano
.
config
.
floatX
)
)
.
astype
(
theano
.
config
.
floatX
)
...
@@ -37,7 +37,7 @@ def uniform(stdev, size):
...
@@ -37,7 +37,7 @@ def uniform(stdev, size):
def
linear_transform_weights
(
input_dim
,
output_dim
,
def
linear_transform_weights
(
input_dim
,
output_dim
,
param_list
=
None
,
name
=
""
):
param_list
=
None
,
name
=
""
):
"theano shared variable given input and output dimension"
"theano shared variable given input and output dimension"
weight_inialization
=
uniform
(
n
umpy
.
sqrt
(
2.0
/
input_dim
),
weight_inialization
=
uniform
(
n
p
.
sqrt
(
2.0
/
input_dim
),
(
input_dim
,
output_dim
))
(
input_dim
,
output_dim
))
W
=
theano
.
shared
(
weight_inialization
,
name
=
name
)
W
=
theano
.
shared
(
weight_inialization
,
name
=
name
)
...
@@ -49,7 +49,7 @@ def linear_transform_weights(input_dim, output_dim,
...
@@ -49,7 +49,7 @@ def linear_transform_weights(input_dim, output_dim,
def
bias_weights
(
length
,
param_list
=
None
,
name
=
""
):
def
bias_weights
(
length
,
param_list
=
None
,
name
=
""
):
"theano shared variable for bias unit, given length"
"theano shared variable for bias unit, given length"
bias_initialization
=
n
umpy
.
zeros
(
length
)
.
astype
(
theano
.
config
.
floatX
)
bias_initialization
=
n
p
.
zeros
(
length
)
.
astype
(
theano
.
config
.
floatX
)
bias
=
theano
.
shared
(
bias
=
theano
.
shared
(
bias_initialization
,
bias_initialization
,
...
...
theano/gpuarray/tests/test_abstractconv.py
浏览文件 @
824cb369
...
@@ -3,7 +3,7 @@ from __future__ import absolute_import, print_function, division
...
@@ -3,7 +3,7 @@ from __future__ import absolute_import, print_function, division
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
from
nose.tools
import
assert_raises
from
nose.tools
import
assert_raises
import
numpy
import
numpy
as
np
from
theano.tensor.nnet.tests
import
test_abstract_conv
from
theano.tensor.nnet.tests
import
test_abstract_conv
from
..type
import
GpuArrayType
,
gpuarray_shared_constructor
,
get_context
from
..type
import
GpuArrayType
,
gpuarray_shared_constructor
,
get_context
...
@@ -250,7 +250,7 @@ class TestDnnConvTypes(test_abstract_conv.TestConvTypes):
...
@@ -250,7 +250,7 @@ class TestDnnConvTypes(test_abstract_conv.TestConvTypes):
self
.
filters
=
gpu_ftensor4
()
self
.
filters
=
gpu_ftensor4
()
self
.
topgrad
=
gpu_ftensor4
()
self
.
topgrad
=
gpu_ftensor4
()
self
.
constant_tensor
=
gpuarray
.
array
(
self
.
constant_tensor
=
gpuarray
.
array
(
n
umpy
.
zeros
((
3
,
5
,
7
,
11
),
dtype
=
'float32'
),
n
p
.
zeros
((
3
,
5
,
7
,
11
),
dtype
=
'float32'
),
context
=
get_context
(
test_ctx_name
))
context
=
get_context
(
test_ctx_name
))
...
...
theano/gpuarray/tests/test_basic_ops.py
浏览文件 @
824cb369
...
@@ -4,7 +4,7 @@ from theano.compat import izip
...
@@ -4,7 +4,7 @@ from theano.compat import izip
from
six
import
iteritems
from
six
import
iteritems
import
numpy
import
numpy
as
np
import
theano
import
theano
import
theano.tensor
as
T
import
theano.tensor
as
T
from
theano.tensor
import
TensorType
from
theano.tensor
import
TensorType
...
@@ -29,7 +29,7 @@ from .config import mode_with_gpu, mode_without_gpu, test_ctx_name
...
@@ -29,7 +29,7 @@ from .config import mode_with_gpu, mode_without_gpu, test_ctx_name
from
pygpu
import
gpuarray
from
pygpu
import
gpuarray
utt
.
seed_rng
()
utt
.
seed_rng
()
rng
=
n
umpy
.
random
.
RandomState
(
seed
=
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
seed
=
utt
.
fetch_seed
())
def
inplace_func
(
inputs
,
outputs
,
mode
=
None
,
allow_input_downcast
=
False
,
def
inplace_func
(
inputs
,
outputs
,
mode
=
None
,
allow_input_downcast
=
False
,
...
@@ -92,7 +92,7 @@ def makeTester(name, op, gpu_op, cases, checks=None, mode_gpu=mode_with_gpu,
...
@@ -92,7 +92,7 @@ def makeTester(name, op, gpu_op, cases, checks=None, mode_gpu=mode_with_gpu,
for
testname
,
inputs
in
iteritems
(
cases
):
for
testname
,
inputs
in
iteritems
(
cases
):
for
_
in
range
(
len
(
inputs
)):
for
_
in
range
(
len
(
inputs
)):
if
type
(
inputs
[
_
])
is
float
:
if
type
(
inputs
[
_
])
is
float
:
inputs
[
_
]
=
n
umpy
.
asarray
(
inputs
[
_
],
inputs
[
_
]
=
n
p
.
asarray
(
inputs
[
_
],
dtype
=
theano
.
config
.
floatX
)
dtype
=
theano
.
config
.
floatX
)
self
.
run_case
(
testname
,
inputs
)
self
.
run_case
(
testname
,
inputs
)
...
@@ -177,7 +177,7 @@ def test_transfer_cpu_gpu():
...
@@ -177,7 +177,7 @@ def test_transfer_cpu_gpu():
a
=
T
.
fmatrix
(
'a'
)
a
=
T
.
fmatrix
(
'a'
)
g
=
GpuArrayType
(
dtype
=
'float32'
,
broadcastable
=
(
False
,
False
))(
'g'
)
g
=
GpuArrayType
(
dtype
=
'float32'
,
broadcastable
=
(
False
,
False
))(
'g'
)
av
=
n
umpy
.
asarray
(
rng
.
rand
(
5
,
4
),
dtype
=
'float32'
)
av
=
n
p
.
asarray
(
rng
.
rand
(
5
,
4
),
dtype
=
'float32'
)
gv
=
gpuarray
.
array
(
av
,
context
=
get_context
(
test_ctx_name
))
gv
=
gpuarray
.
array
(
av
,
context
=
get_context
(
test_ctx_name
))
f
=
theano
.
function
([
a
],
GpuFromHost
(
test_ctx_name
)(
a
))
f
=
theano
.
function
([
a
],
GpuFromHost
(
test_ctx_name
)(
a
))
...
@@ -186,14 +186,14 @@ def test_transfer_cpu_gpu():
...
@@ -186,14 +186,14 @@ def test_transfer_cpu_gpu():
f
=
theano
.
function
([
g
],
host_from_gpu
(
g
))
f
=
theano
.
function
([
g
],
host_from_gpu
(
g
))
fv
=
f
(
gv
)
fv
=
f
(
gv
)
assert
n
umpy
.
all
(
fv
==
av
)
assert
n
p
.
all
(
fv
==
av
)
def
test_transfer_gpu_gpu
():
def
test_transfer_gpu_gpu
():
g
=
GpuArrayType
(
dtype
=
'float32'
,
broadcastable
=
(
False
,
False
),
g
=
GpuArrayType
(
dtype
=
'float32'
,
broadcastable
=
(
False
,
False
),
context_name
=
test_ctx_name
)()
context_name
=
test_ctx_name
)()
av
=
n
umpy
.
asarray
(
rng
.
rand
(
5
,
4
),
dtype
=
'float32'
)
av
=
n
p
.
asarray
(
rng
.
rand
(
5
,
4
),
dtype
=
'float32'
)
gv
=
gpuarray
.
array
(
av
,
context
=
get_context
(
test_ctx_name
))
gv
=
gpuarray
.
array
(
av
,
context
=
get_context
(
test_ctx_name
))
mode
=
mode_with_gpu
.
excluding
(
'cut_gpua_host_transfers'
,
'local_cut_gpua_host_gpua'
)
mode
=
mode_with_gpu
.
excluding
(
'cut_gpua_host_transfers'
,
'local_cut_gpua_host_gpua'
)
f
=
theano
.
function
([
g
],
GpuToGpu
(
test_ctx_name
)(
g
),
mode
=
mode
)
f
=
theano
.
function
([
g
],
GpuToGpu
(
test_ctx_name
)(
g
),
mode
=
mode
)
...
@@ -211,7 +211,7 @@ def test_transfer_strided():
...
@@ -211,7 +211,7 @@ def test_transfer_strided():
a
=
T
.
fmatrix
(
'a'
)
a
=
T
.
fmatrix
(
'a'
)
g
=
GpuArrayType
(
dtype
=
'float32'
,
broadcastable
=
(
False
,
False
))(
'g'
)
g
=
GpuArrayType
(
dtype
=
'float32'
,
broadcastable
=
(
False
,
False
))(
'g'
)
av
=
n
umpy
.
asarray
(
rng
.
rand
(
5
,
8
),
dtype
=
'float32'
)
av
=
n
p
.
asarray
(
rng
.
rand
(
5
,
8
),
dtype
=
'float32'
)
gv
=
gpuarray
.
array
(
av
,
context
=
get_context
(
test_ctx_name
))
gv
=
gpuarray
.
array
(
av
,
context
=
get_context
(
test_ctx_name
))
av
=
av
[:,
::
2
]
av
=
av
[:,
::
2
]
...
@@ -223,7 +223,7 @@ def test_transfer_strided():
...
@@ -223,7 +223,7 @@ def test_transfer_strided():
f
=
theano
.
function
([
g
],
host_from_gpu
(
g
))
f
=
theano
.
function
([
g
],
host_from_gpu
(
g
))
fv
=
f
(
gv
)
fv
=
f
(
gv
)
assert
n
umpy
.
all
(
fv
==
av
)
assert
n
p
.
all
(
fv
==
av
)
def
gpu_alloc_expected
(
x
,
*
shp
):
def
gpu_alloc_expected
(
x
,
*
shp
):
...
@@ -237,16 +237,16 @@ GpuAllocTester = makeTester(
...
@@ -237,16 +237,16 @@ GpuAllocTester = makeTester(
op
=
alloc
,
op
=
alloc
,
gpu_op
=
GpuAlloc
(
test_ctx_name
),
gpu_op
=
GpuAlloc
(
test_ctx_name
),
cases
=
dict
(
cases
=
dict
(
correct01
=
(
rand
(),
n
umpy
.
int32
(
7
)),
correct01
=
(
rand
(),
n
p
.
int32
(
7
)),
# just gives a DeepCopyOp with possibly wrong results on the CPU
# just gives a DeepCopyOp with possibly wrong results on the CPU
# correct01_bcast=(rand(1), n
umpy
.int32(7)),
# correct01_bcast=(rand(1), n
p
.int32(7)),
correct02
=
(
rand
(),
n
umpy
.
int32
(
4
),
numpy
.
int32
(
7
)),
correct02
=
(
rand
(),
n
p
.
int32
(
4
),
np
.
int32
(
7
)),
correct12
=
(
rand
(
7
),
n
umpy
.
int32
(
4
),
numpy
.
int32
(
7
)),
correct12
=
(
rand
(
7
),
n
p
.
int32
(
4
),
np
.
int32
(
7
)),
correct13
=
(
rand
(
7
),
n
umpy
.
int32
(
2
),
numpy
.
int32
(
4
),
correct13
=
(
rand
(
7
),
n
p
.
int32
(
2
),
np
.
int32
(
4
),
n
umpy
.
int32
(
7
)),
n
p
.
int32
(
7
)),
correct23
=
(
rand
(
4
,
7
),
n
umpy
.
int32
(
2
),
numpy
.
int32
(
4
),
correct23
=
(
rand
(
4
,
7
),
n
p
.
int32
(
2
),
np
.
int32
(
4
),
n
umpy
.
int32
(
7
)),
n
p
.
int32
(
7
)),
bad_shape12
=
(
rand
(
7
),
n
umpy
.
int32
(
7
),
numpy
.
int32
(
5
)),
bad_shape12
=
(
rand
(
7
),
n
p
.
int32
(
7
),
np
.
int32
(
5
)),
)
)
)
)
...
@@ -282,7 +282,7 @@ def test_shape():
...
@@ -282,7 +282,7 @@ def test_shape():
v
=
gpuarray
.
zeros
((
3
,
4
,
5
),
dtype
=
'float32'
,
context
=
get_context
(
test_ctx_name
))
v
=
gpuarray
.
zeros
((
3
,
4
,
5
),
dtype
=
'float32'
,
context
=
get_context
(
test_ctx_name
))
f
=
theano
.
function
([
x
],
x
.
shape
)
f
=
theano
.
function
([
x
],
x
.
shape
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
n
umpy
.
all
(
f
(
v
)
==
(
3
,
4
,
5
))
assert
n
p
.
all
(
f
(
v
)
==
(
3
,
4
,
5
))
if
theano
.
config
.
mode
!=
'FAST_COMPILE'
:
if
theano
.
config
.
mode
!=
'FAST_COMPILE'
:
assert
len
(
topo
)
==
4
assert
len
(
topo
)
==
4
assert
isinstance
(
topo
[
0
]
.
op
,
T
.
opt
.
Shape_i
)
assert
isinstance
(
topo
[
0
]
.
op
,
T
.
opt
.
Shape_i
)
...
@@ -292,7 +292,7 @@ def test_shape():
...
@@ -292,7 +292,7 @@ def test_shape():
mode
=
mode_with_gpu
.
excluding
(
"local_shape_to_shape_i"
)
mode
=
mode_with_gpu
.
excluding
(
"local_shape_to_shape_i"
)
f
=
theano
.
function
([
x
],
x
.
shape
,
mode
=
mode
)
f
=
theano
.
function
([
x
],
x
.
shape
,
mode
=
mode
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
n
umpy
.
all
(
f
(
v
)
==
(
3
,
4
,
5
))
assert
n
p
.
all
(
f
(
v
)
==
(
3
,
4
,
5
))
assert
len
(
topo
)
==
1
assert
len
(
topo
)
==
1
assert
isinstance
(
topo
[
0
]
.
op
,
T
.
Shape
)
assert
isinstance
(
topo
[
0
]
.
op
,
T
.
Shape
)
...
@@ -300,7 +300,7 @@ def test_shape():
...
@@ -300,7 +300,7 @@ def test_shape():
def
test_gpu_contiguous
():
def
test_gpu_contiguous
():
a
=
T
.
fmatrix
(
'a'
)
a
=
T
.
fmatrix
(
'a'
)
i
=
T
.
iscalar
(
'i'
)
i
=
T
.
iscalar
(
'i'
)
a_val
=
n
umpy
.
asarray
(
numpy
.
random
.
rand
(
4
,
5
),
dtype
=
'float32'
)
a_val
=
n
p
.
asarray
(
np
.
random
.
rand
(
4
,
5
),
dtype
=
'float32'
)
# The reshape is needed otherwise we make the subtensor on the CPU
# The reshape is needed otherwise we make the subtensor on the CPU
# to transfer less data.
# to transfer less data.
f
=
theano
.
function
([
a
,
i
],
gpu_contiguous
(
a
.
reshape
((
5
,
4
))[::
i
]),
f
=
theano
.
function
([
a
,
i
],
gpu_contiguous
(
a
.
reshape
((
5
,
4
))[::
i
]),
...
@@ -353,22 +353,22 @@ class G_Join_and_Split(test_basic.T_Join_and_Split):
...
@@ -353,22 +353,22 @@ class G_Join_and_Split(test_basic.T_Join_and_Split):
self
.
shared
=
gpuarray_shared_constructor
self
.
shared
=
gpuarray_shared_constructor
def
test_gpusplit_opt
(
self
):
def
test_gpusplit_opt
(
self
):
rng
=
n
umpy
.
random
.
RandomState
(
seed
=
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
seed
=
utt
.
fetch_seed
())
m
=
self
.
shared
(
rng
.
rand
(
4
,
6
)
.
astype
(
self
.
floatX
))
m
=
self
.
shared
(
rng
.
rand
(
4
,
6
)
.
astype
(
self
.
floatX
))
o
=
T
.
Split
(
2
)(
m
,
0
,
[
2
,
2
])
o
=
T
.
Split
(
2
)(
m
,
0
,
[
2
,
2
])
f
=
theano
.
function
([],
o
,
mode
=
self
.
mode
)
f
=
theano
.
function
([],
o
,
mode
=
self
.
mode
)
assert
any
([
isinstance
(
node
.
op
,
self
.
split_op_class
)
assert
any
([
isinstance
(
node
.
op
,
self
.
split_op_class
)
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
o1
,
o2
=
f
()
o1
,
o2
=
f
()
assert
n
umpy
.
allclose
(
o1
,
m
.
get_value
(
borrow
=
True
)[:
2
])
assert
n
p
.
allclose
(
o1
,
m
.
get_value
(
borrow
=
True
)[:
2
])
assert
n
umpy
.
allclose
(
o2
,
m
.
get_value
(
borrow
=
True
)[
2
:])
assert
n
p
.
allclose
(
o2
,
m
.
get_value
(
borrow
=
True
)[
2
:])
def
test_gpujoin_gpualloc
():
def
test_gpujoin_gpualloc
():
a
=
T
.
fmatrix
(
'a'
)
a
=
T
.
fmatrix
(
'a'
)
a_val
=
n
umpy
.
asarray
(
numpy
.
random
.
rand
(
4
,
5
),
dtype
=
'float32'
)
a_val
=
n
p
.
asarray
(
np
.
random
.
rand
(
4
,
5
),
dtype
=
'float32'
)
b
=
T
.
fmatrix
(
'b'
)
b
=
T
.
fmatrix
(
'b'
)
b_val
=
n
umpy
.
asarray
(
numpy
.
random
.
rand
(
3
,
5
),
dtype
=
'float32'
)
b_val
=
n
p
.
asarray
(
np
.
random
.
rand
(
3
,
5
),
dtype
=
'float32'
)
f
=
theano
.
function
([
a
,
b
],
T
.
join
(
0
,
T
.
zeros_like
(
a
),
T
.
ones_like
(
b
))
+
4
,
f
=
theano
.
function
([
a
,
b
],
T
.
join
(
0
,
T
.
zeros_like
(
a
),
T
.
ones_like
(
b
))
+
4
,
mode
=
mode_without_gpu
)
mode
=
mode_without_gpu
)
...
@@ -387,7 +387,7 @@ def test_gpujoin_gpualloc():
...
@@ -387,7 +387,7 @@ def test_gpujoin_gpualloc():
for
node
in
f_gpu2
.
maker
.
fgraph
.
toposort
()])
==
2
for
node
in
f_gpu2
.
maker
.
fgraph
.
toposort
()])
==
2
assert
sum
([
node
.
op
==
gpu_join
assert
sum
([
node
.
op
==
gpu_join
for
node
in
f_gpu2
.
maker
.
fgraph
.
toposort
()])
==
1
for
node
in
f_gpu2
.
maker
.
fgraph
.
toposort
()])
==
1
assert
n
umpy
.
allclose
(
f
(
a_val
,
b_val
),
f_gpu2
(
a_val
,
b_val
))
assert
n
p
.
allclose
(
f
(
a_val
,
b_val
),
f_gpu2
(
a_val
,
b_val
))
def
test_gpueye
():
def
test_gpueye
():
...
@@ -401,14 +401,14 @@ def test_gpueye():
...
@@ -401,14 +401,14 @@ def test_gpueye():
M
=
N
M
=
N
N_symb
=
T
.
iscalar
()
N_symb
=
T
.
iscalar
()
M_symb
=
T
.
iscalar
()
M_symb
=
T
.
iscalar
()
k_symb
=
n
umpy
.
asarray
(
0
)
k_symb
=
n
p
.
asarray
(
0
)
out
=
T
.
eye
(
N_symb
,
M_symb
,
k_symb
,
dtype
=
dtype
)
out
=
T
.
eye
(
N_symb
,
M_symb
,
k_symb
,
dtype
=
dtype
)
f
=
theano
.
function
([
N_symb
,
M_symb
],
f
=
theano
.
function
([
N_symb
,
M_symb
],
T
.
stack
(
out
),
T
.
stack
(
out
),
mode
=
mode_with_gpu
)
mode
=
mode_with_gpu
)
result
=
n
umpy
.
asarray
(
f
(
N
,
M
))
result
=
n
p
.
asarray
(
f
(
N
,
M
))
assert
n
umpy
.
allclose
(
result
,
numpy
.
eye
(
N
,
M_
,
dtype
=
dtype
))
assert
n
p
.
allclose
(
result
,
np
.
eye
(
N
,
M_
,
dtype
=
dtype
))
assert
result
.
dtype
==
n
umpy
.
dtype
(
dtype
)
assert
result
.
dtype
==
n
p
.
dtype
(
dtype
)
assert
any
([
isinstance
(
node
.
op
,
GpuEye
)
assert
any
([
isinstance
(
node
.
op
,
GpuEye
)
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
...
@@ -429,8 +429,8 @@ def test_hostfromgpu_shape_i():
...
@@ -429,8 +429,8 @@ def test_hostfromgpu_shape_i():
'specialize'
)
'specialize'
)
a
=
T
.
fmatrix
(
'a'
)
a
=
T
.
fmatrix
(
'a'
)
ca
=
theano
.
gpuarray
.
type
.
GpuArrayType
(
'float32'
,
(
False
,
False
))()
ca
=
theano
.
gpuarray
.
type
.
GpuArrayType
(
'float32'
,
(
False
,
False
))()
av
=
n
umpy
.
asarray
(
numpy
.
random
.
rand
(
5
,
4
),
dtype
=
'float32'
)
av
=
n
p
.
asarray
(
np
.
random
.
rand
(
5
,
4
),
dtype
=
'float32'
)
cv
=
gpuarray
.
asarray
(
n
umpy
.
random
.
rand
(
5
,
4
),
cv
=
gpuarray
.
asarray
(
n
p
.
random
.
rand
(
5
,
4
),
dtype
=
'float32'
,
dtype
=
'float32'
,
context
=
get_context
(
test_ctx_name
))
context
=
get_context
(
test_ctx_name
))
...
@@ -464,7 +464,7 @@ def test_Gpujoin_inplace():
...
@@ -464,7 +464,7 @@ def test_Gpujoin_inplace():
non-empty element.
non-empty element.
"""
"""
s
=
T
.
lscalar
()
s
=
T
.
lscalar
()
data
=
n
umpy
.
array
([
3
,
4
,
5
],
dtype
=
theano
.
config
.
floatX
)
data
=
n
p
.
array
([
3
,
4
,
5
],
dtype
=
theano
.
config
.
floatX
)
x
=
gpuarray_shared_constructor
(
data
,
borrow
=
True
)
x
=
gpuarray_shared_constructor
(
data
,
borrow
=
True
)
z
=
T
.
zeros
((
s
,))
z
=
T
.
zeros
((
s
,))
...
@@ -473,4 +473,4 @@ def test_Gpujoin_inplace():
...
@@ -473,4 +473,4 @@ def test_Gpujoin_inplace():
f
=
theano
.
function
([
s
],
theano
.
Out
(
c
,
borrow
=
True
))
f
=
theano
.
function
([
s
],
theano
.
Out
(
c
,
borrow
=
True
))
assert
x
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)
is
f
(
0
)
assert
x
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)
is
f
(
0
)
assert
n
umpy
.
allclose
(
f
(
0
),
[
3
,
4
,
5
])
assert
n
p
.
allclose
(
f
(
0
),
[
3
,
4
,
5
])
theano/gpuarray/tests/test_blas.py
浏览文件 @
824cb369
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
from
unittest
import
TestCase
from
unittest
import
TestCase
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
import
itertools
import
itertools
import
numpy
import
numpy
as
np
import
theano
import
theano
from
theano
import
tensor
from
theano
import
tensor
...
@@ -138,8 +138,8 @@ def test_gemv_zeros():
...
@@ -138,8 +138,8 @@ def test_gemv_zeros():
# Apply to an empty matrix shape (5,0) and an empty vector shape (0,)
# Apply to an empty matrix shape (5,0) and an empty vector shape (0,)
dim
=
1000
dim
=
1000
A
=
n
umpy
.
zeros
((
dim
,
0
),
dtype
=
theano
.
config
.
floatX
)
A
=
n
p
.
zeros
((
dim
,
0
),
dtype
=
theano
.
config
.
floatX
)
b
=
n
umpy
.
zeros
((
0
,),
dtype
=
theano
.
config
.
floatX
)
b
=
n
p
.
zeros
((
0
,),
dtype
=
theano
.
config
.
floatX
)
tmp
=
f
(
A
,
b
)
tmp
=
f
(
A
,
b
)
assert
n
umpy
.
allclose
(
tmp
,
assert
n
p
.
allclose
(
tmp
,
numpy
.
zeros
((
dim
,)))
np
.
zeros
((
dim
,)))
theano/gpuarray/tests/test_blocksparse.py
浏览文件 @
824cb369
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
numpy
import
numpy
as
np
import
theano
import
theano
from
theano
import
tensor
from
theano
import
tensor
...
@@ -39,7 +39,7 @@ class BlockSparse_Gemv_and_Outer(test_blocksparse.BlockSparse_Gemv_and_Outer):
...
@@ -39,7 +39,7 @@ class BlockSparse_Gemv_and_Outer(test_blocksparse.BlockSparse_Gemv_and_Outer):
o
=
gpu_sparse_block_gemv
(
b
.
take
(
oIdx
,
axis
=
0
),
W
,
h
,
iIdx
,
oIdx
)
o
=
gpu_sparse_block_gemv
(
b
.
take
(
oIdx
,
axis
=
0
),
W
,
h
,
iIdx
,
oIdx
)
gW
=
theano
.
grad
(
o
.
sum
(),
W
)
gW
=
theano
.
grad
(
o
.
sum
(),
W
)
lr
=
n
umpy
.
asarray
(
0.05
,
dtype
=
'float32'
)
lr
=
n
p
.
asarray
(
0.05
,
dtype
=
'float32'
)
upd
=
W
-
lr
*
gW
upd
=
W
-
lr
*
gW
...
...
theano/gpuarray/tests/test_cgpukernelbase.py
浏览文件 @
824cb369
from
__future__
import
division
,
absolute_import
,
print_function
from
__future__
import
division
,
absolute_import
,
print_function
import
numpy
import
numpy
as
np
from
six.moves
import
xrange
from
six.moves
import
xrange
import
theano
import
theano
...
@@ -69,4 +69,4 @@ def test_cgpukernelbase():
...
@@ -69,4 +69,4 @@ def test_cgpukernelbase():
r
=
f
()
r
=
f
()
assert
(
n
umpy
.
asarray
(
r
)
==
numpy
.
eye
(
4
,
5
,
dtype
=
'int32'
))
.
all
()
assert
(
n
p
.
asarray
(
r
)
==
np
.
eye
(
4
,
5
,
dtype
=
'int32'
))
.
all
()
theano/gpuarray/tests/test_dnn.py
浏览文件 @
824cb369
差异被折叠。
点击展开。
theano/gpuarray/tests/test_elemwise.py
浏览文件 @
824cb369
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
numpy
import
numpy
as
np
import
scipy.special
import
scipy.special
import
theano
import
theano
...
@@ -45,8 +45,8 @@ def test_elemwise_pow():
...
@@ -45,8 +45,8 @@ def test_elemwise_pow():
output
=
base
**
exp
output
=
base
**
exp
f
=
theano
.
function
([
base
,
exp
],
output
)
f
=
theano
.
function
([
base
,
exp
],
output
)
base_val
=
n
umpy
.
random
.
randint
(
0
,
5
,
size
=
10
)
.
astype
(
dtype_base
)
base_val
=
n
p
.
random
.
randint
(
0
,
5
,
size
=
10
)
.
astype
(
dtype_base
)
exp_val
=
n
umpy
.
random
.
randint
(
0
,
3
,
size
=
10
)
.
astype
(
dtype_exp
)
exp_val
=
n
p
.
random
.
randint
(
0
,
3
,
size
=
10
)
.
astype
(
dtype_exp
)
# Call the function to make sure the output is valid
# Call the function to make sure the output is valid
out
=
f
(
base_val
,
exp_val
)
out
=
f
(
base_val
,
exp_val
)
...
@@ -68,7 +68,7 @@ class TestMathErrorFunctions(TestCase):
...
@@ -68,7 +68,7 @@ class TestMathErrorFunctions(TestCase):
# to have the GPU ops run on large data.
# to have the GPU ops run on large data.
default_array
=
[
x
/
10.0
for
x
in
range
(
-
50
,
50
)]
*
1000
default_array
=
[
x
/
10.0
for
x
in
range
(
-
50
,
50
)]
*
1000
for
dtype
in
self
.
dtypes
:
for
dtype
in
self
.
dtypes
:
numpy_array
=
n
umpy
.
asarray
(
default_array
,
dtype
=
dtype
)
numpy_array
=
n
p
.
asarray
(
default_array
,
dtype
=
dtype
)
self
.
default_arrays
[
dtype
]
=
numpy_array
self
.
default_arrays
[
dtype
]
=
numpy_array
self
.
expected_erfinv_outputs
[
dtype
]
=
scipy
.
special
.
erfinv
(
numpy_array
)
self
.
expected_erfinv_outputs
[
dtype
]
=
scipy
.
special
.
erfinv
(
numpy_array
)
self
.
expected_erfcinv_outputs
[
dtype
]
=
scipy
.
special
.
erfcinv
(
numpy_array
)
self
.
expected_erfcinv_outputs
[
dtype
]
=
scipy
.
special
.
erfcinv
(
numpy_array
)
...
@@ -127,7 +127,7 @@ class test_float16():
...
@@ -127,7 +127,7 @@ class test_float16():
o
=
(
cz
-
cz
**
2
+
o
=
(
cz
-
cz
**
2
+
tensor
.
cast
(
x
,
'int16'
)
+
tensor
.
cast
(
x
,
'float32'
)
+
tensor
.
cast
(
x
,
'int16'
)
+
tensor
.
cast
(
x
,
'float32'
)
+
tensor
.
cast
(
w
,
'float16'
)
-
tensor
.
cast
(
w
,
'float16'
)
-
tensor
.
constant
(
n
umpy
.
float16
(
1.0
)))
tensor
.
constant
(
n
p
.
float16
(
1.0
)))
theano
.
function
([
w
,
x
,
y
],
o
,
mode
=
mode_with_gpu
)
theano
.
function
([
w
,
x
,
y
],
o
,
mode
=
mode_with_gpu
)
...
@@ -154,9 +154,9 @@ class test_float16():
...
@@ -154,9 +154,9 @@ class test_float16():
i8
.
astype
(
'float32'
)],
i8
.
astype
(
'float32'
)],
mode
=
mode_with_gpu
)
mode
=
mode_with_gpu
)
d1
=
(
n
umpy
.
random
.
rand
(
4
)
*
10
)
.
astype
(
'float16'
)
d1
=
(
n
p
.
random
.
rand
(
4
)
*
10
)
.
astype
(
'float16'
)
d2
=
(
n
umpy
.
random
.
rand
(
5
)
*
10
)
.
astype
(
'float32'
)
d2
=
(
n
p
.
random
.
rand
(
5
)
*
10
)
.
astype
(
'float32'
)
d3
=
(
n
umpy
.
random
.
rand
(
6
)
*
10
)
.
astype
(
'int8'
)
d3
=
(
n
p
.
random
.
rand
(
6
)
*
10
)
.
astype
(
'int8'
)
res
=
f
(
d1
,
d2
,
d3
)
res
=
f
(
d1
,
d2
,
d3
)
for
i
,
out
in
enumerate
(
f
.
outputs
):
for
i
,
out
in
enumerate
(
f
.
outputs
):
...
@@ -337,9 +337,7 @@ class T_gpureduce_dtype(test_elemwise.T_reduce_dtype):
...
@@ -337,9 +337,7 @@ class T_gpureduce_dtype(test_elemwise.T_reduce_dtype):
def
speed_reduce10
():
def
speed_reduce10
():
import
numpy
data
=
np
.
random
.
rand
(
1000
,
1000
)
.
astype
(
"float32"
)
import
theano
data
=
numpy
.
random
.
rand
(
1000
,
1000
)
.
astype
(
"float32"
)
m
=
theano
.
tensor
.
fmatrix
()
m
=
theano
.
tensor
.
fmatrix
()
f
=
theano
.
function
([
m
],
[
m
.
sum
(
axis
=
0
),
m
.
T
.
sum
(
axis
=
0
)],
f
=
theano
.
function
([
m
],
[
m
.
sum
(
axis
=
0
),
m
.
T
.
sum
(
axis
=
0
)],
mode
=
mode_with_gpu
)
mode
=
mode_with_gpu
)
...
...
theano/gpuarray/tests/test_fft.py
浏览文件 @
824cb369
...
@@ -7,7 +7,6 @@ import theano.tensor as T
...
@@ -7,7 +7,6 @@ import theano.tensor as T
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
import
theano.gpuarray.fft
import
theano.gpuarray.fft
import
numpy.fft
from
.config
import
mode_with_gpu
from
.config
import
mode_with_gpu
...
@@ -37,7 +36,7 @@ class TestFFT(unittest.TestCase):
...
@@ -37,7 +36,7 @@ class TestFFT(unittest.TestCase):
res_rfft_comp
=
(
np
.
asarray
(
res_rfft
[:,
:,
0
])
+
res_rfft_comp
=
(
np
.
asarray
(
res_rfft
[:,
:,
0
])
+
1
j
*
np
.
asarray
(
res_rfft
[:,
:,
1
]))
1
j
*
np
.
asarray
(
res_rfft
[:,
:,
1
]))
rfft_ref
=
n
umpy
.
fft
.
rfft
(
inputs_val
,
axis
=
1
)
rfft_ref
=
n
p
.
fft
.
rfft
(
inputs_val
,
axis
=
1
)
utt
.
assert_allclose
(
rfft_ref
,
res_rfft_comp
)
utt
.
assert_allclose
(
rfft_ref
,
res_rfft_comp
)
...
@@ -72,7 +71,7 @@ class TestFFT(unittest.TestCase):
...
@@ -72,7 +71,7 @@ class TestFFT(unittest.TestCase):
res_rfft_comp
=
(
np
.
asarray
(
res_rfft
[:,
:,
:,
0
])
+
res_rfft_comp
=
(
np
.
asarray
(
res_rfft
[:,
:,
:,
0
])
+
1
j
*
np
.
asarray
(
res_rfft
[:,
:,
:,
1
]))
1
j
*
np
.
asarray
(
res_rfft
[:,
:,
:,
1
]))
rfft_ref
=
n
umpy
.
fft
.
rfftn
(
inputs_val
,
axes
=
(
1
,
2
))
rfft_ref
=
n
p
.
fft
.
rfftn
(
inputs_val
,
axes
=
(
1
,
2
))
utt
.
assert_allclose
(
rfft_ref
,
res_rfft_comp
,
atol
=
1e-4
,
rtol
=
1e-4
)
utt
.
assert_allclose
(
rfft_ref
,
res_rfft_comp
,
atol
=
1e-4
,
rtol
=
1e-4
)
...
@@ -91,7 +90,7 @@ class TestFFT(unittest.TestCase):
...
@@ -91,7 +90,7 @@ class TestFFT(unittest.TestCase):
utt
.
assert_allclose
(
inputs_val
,
np
.
asarray
(
res_ifft
))
utt
.
assert_allclose
(
inputs_val
,
np
.
asarray
(
res_ifft
))
inputs_val
=
n
umpy
.
random
.
random
((
1
,
N
,
N
,
2
))
.
astype
(
'float32'
)
inputs_val
=
n
p
.
random
.
random
((
1
,
N
,
N
,
2
))
.
astype
(
'float32'
)
inputs
=
theano
.
shared
(
inputs_val
)
inputs
=
theano
.
shared
(
inputs_val
)
irfft
=
theano
.
gpuarray
.
fft
.
cuirfft
(
inputs
)
irfft
=
theano
.
gpuarray
.
fft
.
cuirfft
(
inputs
)
...
@@ -123,7 +122,7 @@ class TestFFT(unittest.TestCase):
...
@@ -123,7 +122,7 @@ class TestFFT(unittest.TestCase):
res_rfft_comp
=
(
np
.
asarray
(
res_rfft
[:,
:,
:,
0
])
+
res_rfft_comp
=
(
np
.
asarray
(
res_rfft
[:,
:,
:,
0
])
+
1
j
*
np
.
asarray
(
res_rfft
[:,
:,
:,
1
]))
1
j
*
np
.
asarray
(
res_rfft
[:,
:,
:,
1
]))
rfft_ref
=
n
umpy
.
fft
.
rfftn
(
inputs_val
,
axes
=
(
1
,
2
))
rfft_ref
=
n
p
.
fft
.
rfftn
(
inputs_val
,
axes
=
(
1
,
2
))
utt
.
assert_allclose
(
rfft_ref
/
N
,
res_rfft_comp
,
atol
=
1e-4
,
rtol
=
1e-4
)
utt
.
assert_allclose
(
rfft_ref
/
N
,
res_rfft_comp
,
atol
=
1e-4
,
rtol
=
1e-4
)
...
@@ -146,7 +145,7 @@ class TestFFT(unittest.TestCase):
...
@@ -146,7 +145,7 @@ class TestFFT(unittest.TestCase):
f_irfft
=
theano
.
function
([],
irfft
,
mode
=
mode_with_gpu
)
f_irfft
=
theano
.
function
([],
irfft
,
mode
=
mode_with_gpu
)
res_irfft
=
f_irfft
()
res_irfft
=
f_irfft
()
irfft_ref
=
n
umpy
.
fft
.
irfftn
(
inputs_ref
,
axes
=
(
1
,
2
))
irfft_ref
=
n
p
.
fft
.
irfftn
(
inputs_ref
,
axes
=
(
1
,
2
))
utt
.
assert_allclose
(
irfft_ref
*
N
,
res_irfft
,
atol
=
1e-4
,
rtol
=
1e-4
)
utt
.
assert_allclose
(
irfft_ref
*
N
,
res_irfft
,
atol
=
1e-4
,
rtol
=
1e-4
)
...
@@ -195,7 +194,7 @@ class TestFFT(unittest.TestCase):
...
@@ -195,7 +194,7 @@ class TestFFT(unittest.TestCase):
res_rfft_comp
=
(
np
.
asarray
(
res_rfft
[:,
:,
:,
0
])
+
res_rfft_comp
=
(
np
.
asarray
(
res_rfft
[:,
:,
:,
0
])
+
1
j
*
np
.
asarray
(
res_rfft
[:,
:,
:,
1
]))
1
j
*
np
.
asarray
(
res_rfft
[:,
:,
:,
1
]))
rfft_ref
=
n
umpy
.
fft
.
rfftn
(
inputs_val
,
s
=
(
M
,
M
),
axes
=
(
1
,
2
))
rfft_ref
=
n
p
.
fft
.
rfftn
(
inputs_val
,
s
=
(
M
,
M
),
axes
=
(
1
,
2
))
utt
.
assert_allclose
(
rfft_ref
,
res_rfft_comp
,
atol
=
1e-4
,
rtol
=
1e-4
)
utt
.
assert_allclose
(
rfft_ref
,
res_rfft_comp
,
atol
=
1e-4
,
rtol
=
1e-4
)
...
@@ -214,7 +213,7 @@ class TestFFT(unittest.TestCase):
...
@@ -214,7 +213,7 @@ class TestFFT(unittest.TestCase):
res_irfft
=
f_irfft
()
res_irfft
=
f_irfft
()
inputs_ref
=
inputs_val
[:,
:,
:,
0
]
+
1
j
*
inputs_val
[:,
:,
:,
1
]
inputs_ref
=
inputs_val
[:,
:,
:,
0
]
+
1
j
*
inputs_val
[:,
:,
:,
1
]
irfft_ref
=
n
umpy
.
fft
.
irfftn
(
inputs_ref
,
s
=
(
M
,
M
),
axes
=
(
1
,
2
))
*
M
irfft_ref
=
n
p
.
fft
.
irfftn
(
inputs_ref
,
s
=
(
M
,
M
),
axes
=
(
1
,
2
))
*
M
utt
.
assert_allclose
(
irfft_ref
,
res_irfft
,
atol
=
1e-4
,
rtol
=
1e-4
)
utt
.
assert_allclose
(
irfft_ref
,
res_irfft
,
atol
=
1e-4
,
rtol
=
1e-4
)
...
@@ -243,12 +242,12 @@ class TestFFT(unittest.TestCase):
...
@@ -243,12 +242,12 @@ class TestFFT(unittest.TestCase):
utt
.
verify_grad
(
f_irfft
,
[
inputs_val
],
eps
=
eps
)
utt
.
verify_grad
(
f_irfft
,
[
inputs_val
],
eps
=
eps
)
def
test_params
(
self
):
def
test_params
(
self
):
inputs_val
=
n
umpy
.
random
.
random
((
1
,
N
))
.
astype
(
'float32'
)
inputs_val
=
n
p
.
random
.
random
((
1
,
N
))
.
astype
(
'float32'
)
inputs
=
theano
.
shared
(
inputs_val
)
inputs
=
theano
.
shared
(
inputs_val
)
self
.
assertRaises
(
ValueError
,
theano
.
gpuarray
.
fft
.
curfft
,
inputs
,
norm
=
123
)
self
.
assertRaises
(
ValueError
,
theano
.
gpuarray
.
fft
.
curfft
,
inputs
,
norm
=
123
)
inputs_val
=
n
umpy
.
random
.
random
((
1
,
N
//
2
+
1
,
2
))
.
astype
(
'float32'
)
inputs_val
=
n
p
.
random
.
random
((
1
,
N
//
2
+
1
,
2
))
.
astype
(
'float32'
)
inputs
=
theano
.
shared
(
inputs_val
)
inputs
=
theano
.
shared
(
inputs_val
)
self
.
assertRaises
(
ValueError
,
theano
.
gpuarray
.
fft
.
cuirfft
,
inputs
,
norm
=
123
)
self
.
assertRaises
(
ValueError
,
theano
.
gpuarray
.
fft
.
cuirfft
,
inputs
,
norm
=
123
)
...
...
theano/gpuarray/tests/test_gemmcorr.py
浏览文件 @
824cb369
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
unittest
import
unittest
import
numpy
import
numpy
as
np
import
theano
import
theano
from
theano
import
config
from
theano
import
config
...
@@ -23,8 +23,8 @@ class TestCorrMM(unittest.TestCase):
...
@@ -23,8 +23,8 @@ class TestCorrMM(unittest.TestCase):
inputs_shape
=
[
inputs_shape
[
i
]
for
i
in
(
0
,
3
,
1
,
2
)]
inputs_shape
=
[
inputs_shape
[
i
]
for
i
in
(
0
,
3
,
1
,
2
)]
filters_shape
=
[
filters_shape
[
i
]
for
i
in
(
0
,
3
,
1
,
2
)]
filters_shape
=
[
filters_shape
[
i
]
for
i
in
(
0
,
3
,
1
,
2
)]
inputs_val
=
n
umpy
.
random
.
random
(
inputs_shape
)
.
astype
(
config
.
floatX
)
inputs_val
=
n
p
.
random
.
random
(
inputs_shape
)
.
astype
(
config
.
floatX
)
filters_val
=
n
umpy
.
random
.
random
(
filters_shape
)
.
astype
(
config
.
floatX
)
filters_val
=
n
p
.
random
.
random
(
filters_shape
)
.
astype
(
config
.
floatX
)
inputs
=
gpuarray_shared_constructor
(
inputs_val
)
inputs
=
gpuarray_shared_constructor
(
inputs_val
)
filters
=
gpuarray_shared_constructor
(
filters_val
)
filters
=
gpuarray_shared_constructor
(
filters_val
)
...
@@ -122,11 +122,11 @@ class TestCorrMM(unittest.TestCase):
...
@@ -122,11 +122,11 @@ class TestCorrMM(unittest.TestCase):
filters_shape
=
[
filters_shape
[
i
]
for
i
in
(
0
,
3
,
1
,
2
)]
filters_shape
=
[
filters_shape
[
i
]
for
i
in
(
0
,
3
,
1
,
2
)]
dCdH_shape
=
[
dCdH_shape
[
i
]
for
i
in
(
0
,
3
,
1
,
2
)]
dCdH_shape
=
[
dCdH_shape
[
i
]
for
i
in
(
0
,
3
,
1
,
2
)]
inputs_val
=
n
umpy
.
random
.
random
(
inputs_shape
)
.
astype
(
config
.
floatX
)
inputs_val
=
n
p
.
random
.
random
(
inputs_shape
)
.
astype
(
config
.
floatX
)
dCdH_val
=
n
umpy
.
random
.
random
(
dCdH_shape
)
.
astype
(
config
.
floatX
)
dCdH_val
=
n
p
.
random
.
random
(
dCdH_shape
)
.
astype
(
config
.
floatX
)
inputs
=
gpuarray_shared_constructor
(
inputs_val
)
inputs
=
gpuarray_shared_constructor
(
inputs_val
)
dCdH
=
gpuarray_shared_constructor
(
dCdH_val
)
dCdH
=
gpuarray_shared_constructor
(
dCdH_val
)
shape
=
gpuarray_shared_constructor
(
n
umpy
.
array
(
filters_shape
[
2
:]))
shape
=
gpuarray_shared_constructor
(
n
p
.
array
(
filters_shape
[
2
:]))
if
(
subsample
==
(
1
,
1
)):
if
(
subsample
==
(
1
,
1
)):
conv_ref
=
CorrMM_gradWeights
(
subsample
=
subsample
)(
conv_ref
=
CorrMM_gradWeights
(
subsample
=
subsample
)(
...
@@ -169,14 +169,14 @@ class TestCorrMM(unittest.TestCase):
...
@@ -169,14 +169,14 @@ class TestCorrMM(unittest.TestCase):
inputs_shape
=
[
inputs_shape
[
i
]
for
i
in
(
0
,
3
,
1
,
2
)]
inputs_shape
=
[
inputs_shape
[
i
]
for
i
in
(
0
,
3
,
1
,
2
)]
filters_shape
=
[
filters_shape
[
i
]
for
i
in
(
0
,
3
,
1
,
2
)]
filters_shape
=
[
filters_shape
[
i
]
for
i
in
(
0
,
3
,
1
,
2
)]
inputs_val
=
n
umpy
.
random
.
random
(
inputs_shape
)
.
astype
(
config
.
floatX
)
inputs_val
=
n
p
.
random
.
random
(
inputs_shape
)
.
astype
(
config
.
floatX
)
filters_val
=
n
umpy
.
random
.
random
(
filters_shape
)
.
astype
(
config
.
floatX
)
filters_val
=
n
p
.
random
.
random
(
filters_shape
)
.
astype
(
config
.
floatX
)
inputs
=
gpuarray_shared_constructor
(
inputs_val
)
inputs
=
gpuarray_shared_constructor
(
inputs_val
)
filters
=
gpuarray_shared_constructor
(
filters_val
)
filters
=
gpuarray_shared_constructor
(
filters_val
)
bottom_height
=
(
inputs_shape
[
2
]
-
1
)
*
subsample
[
0
]
+
filters_shape
[
2
]
bottom_height
=
(
inputs_shape
[
2
]
-
1
)
*
subsample
[
0
]
+
filters_shape
[
2
]
bottom_width
=
(
inputs_shape
[
3
]
-
1
)
*
subsample
[
1
]
+
filters_shape
[
3
]
bottom_width
=
(
inputs_shape
[
3
]
-
1
)
*
subsample
[
1
]
+
filters_shape
[
3
]
bottom_shape
=
gpuarray_shared_constructor
(
n
umpy
.
array
([
bottom_height
,
bottom_width
]))
bottom_shape
=
gpuarray_shared_constructor
(
n
p
.
array
([
bottom_height
,
bottom_width
]))
if
(
subsample
==
(
1
,
1
)):
if
(
subsample
==
(
1
,
1
)):
conv_ref
=
CorrMM_gradInputs
(
subsample
=
subsample
)(
conv_ref
=
CorrMM_gradInputs
(
subsample
=
subsample
)(
...
...
theano/gpuarray/tests/test_gemmcorr3d.py
浏览文件 @
824cb369
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
unittest
import
unittest
import
numpy
import
numpy
as
np
import
theano
import
theano
from
theano
import
config
from
theano
import
config
...
@@ -23,8 +23,8 @@ class TestCorr3dMM(unittest.TestCase):
...
@@ -23,8 +23,8 @@ class TestCorr3dMM(unittest.TestCase):
inputs_shape
=
[
inputs_shape
[
i
]
for
i
in
(
0
,
4
,
1
,
2
,
3
)]
inputs_shape
=
[
inputs_shape
[
i
]
for
i
in
(
0
,
4
,
1
,
2
,
3
)]
filters_shape
=
[
filters_shape
[
i
]
for
i
in
(
0
,
4
,
1
,
2
,
3
)]
filters_shape
=
[
filters_shape
[
i
]
for
i
in
(
0
,
4
,
1
,
2
,
3
)]
inputs_val
=
n
umpy
.
random
.
random
(
inputs_shape
)
.
astype
(
config
.
floatX
)
inputs_val
=
n
p
.
random
.
random
(
inputs_shape
)
.
astype
(
config
.
floatX
)
filters_val
=
n
umpy
.
random
.
random
(
filters_shape
)
.
astype
(
config
.
floatX
)
filters_val
=
n
p
.
random
.
random
(
filters_shape
)
.
astype
(
config
.
floatX
)
inputs
=
gpuarray_shared_constructor
(
inputs_val
)
inputs
=
gpuarray_shared_constructor
(
inputs_val
)
filters
=
gpuarray_shared_constructor
(
filters_val
)
filters
=
gpuarray_shared_constructor
(
filters_val
)
...
@@ -121,11 +121,11 @@ class TestCorr3dMM(unittest.TestCase):
...
@@ -121,11 +121,11 @@ class TestCorr3dMM(unittest.TestCase):
filters_shape
=
[
filters_shape
[
i
]
for
i
in
(
0
,
4
,
1
,
2
,
3
)]
filters_shape
=
[
filters_shape
[
i
]
for
i
in
(
0
,
4
,
1
,
2
,
3
)]
dCdH_shape
=
[
dCdH_shape
[
i
]
for
i
in
(
0
,
4
,
1
,
2
,
3
)]
dCdH_shape
=
[
dCdH_shape
[
i
]
for
i
in
(
0
,
4
,
1
,
2
,
3
)]
inputs_val
=
n
umpy
.
random
.
random
(
inputs_shape
)
.
astype
(
config
.
floatX
)
inputs_val
=
n
p
.
random
.
random
(
inputs_shape
)
.
astype
(
config
.
floatX
)
dCdH_val
=
n
umpy
.
random
.
random
(
dCdH_shape
)
.
astype
(
config
.
floatX
)
dCdH_val
=
n
p
.
random
.
random
(
dCdH_shape
)
.
astype
(
config
.
floatX
)
inputs
=
gpuarray_shared_constructor
(
inputs_val
)
inputs
=
gpuarray_shared_constructor
(
inputs_val
)
dCdH
=
gpuarray_shared_constructor
(
dCdH_val
)
dCdH
=
gpuarray_shared_constructor
(
dCdH_val
)
shape
=
gpuarray_shared_constructor
(
n
umpy
.
array
(
filters_shape
[
2
:]))
shape
=
gpuarray_shared_constructor
(
n
p
.
array
(
filters_shape
[
2
:]))
if
(
subsample
==
(
1
,
1
,
1
)):
if
(
subsample
==
(
1
,
1
,
1
)):
conv_ref
=
Corr3dMM_gradWeights
(
subsample
=
subsample
)(
conv_ref
=
Corr3dMM_gradWeights
(
subsample
=
subsample
)(
...
@@ -168,15 +168,15 @@ class TestCorr3dMM(unittest.TestCase):
...
@@ -168,15 +168,15 @@ class TestCorr3dMM(unittest.TestCase):
inputs_shape
=
[
inputs_shape
[
i
]
for
i
in
(
0
,
4
,
1
,
2
,
3
)]
inputs_shape
=
[
inputs_shape
[
i
]
for
i
in
(
0
,
4
,
1
,
2
,
3
)]
filters_shape
=
[
filters_shape
[
i
]
for
i
in
(
0
,
4
,
1
,
2
,
3
)]
filters_shape
=
[
filters_shape
[
i
]
for
i
in
(
0
,
4
,
1
,
2
,
3
)]
inputs_val
=
n
umpy
.
random
.
random
(
inputs_shape
)
.
astype
(
config
.
floatX
)
inputs_val
=
n
p
.
random
.
random
(
inputs_shape
)
.
astype
(
config
.
floatX
)
filters_val
=
n
umpy
.
random
.
random
(
filters_shape
)
.
astype
(
config
.
floatX
)
filters_val
=
n
p
.
random
.
random
(
filters_shape
)
.
astype
(
config
.
floatX
)
inputs
=
gpuarray_shared_constructor
(
inputs_val
)
inputs
=
gpuarray_shared_constructor
(
inputs_val
)
filters
=
gpuarray_shared_constructor
(
filters_val
)
filters
=
gpuarray_shared_constructor
(
filters_val
)
bottom_height
=
(
inputs_shape
[
2
]
-
1
)
*
subsample
[
0
]
+
filters_shape
[
2
]
bottom_height
=
(
inputs_shape
[
2
]
-
1
)
*
subsample
[
0
]
+
filters_shape
[
2
]
bottom_width
=
(
inputs_shape
[
3
]
-
1
)
*
subsample
[
1
]
+
filters_shape
[
3
]
bottom_width
=
(
inputs_shape
[
3
]
-
1
)
*
subsample
[
1
]
+
filters_shape
[
3
]
bottom_depth
=
(
inputs_shape
[
4
]
-
1
)
*
subsample
[
2
]
+
filters_shape
[
4
]
bottom_depth
=
(
inputs_shape
[
4
]
-
1
)
*
subsample
[
2
]
+
filters_shape
[
4
]
bottom_shape
=
gpuarray_shared_constructor
(
n
umpy
.
array
([
bottom_height
,
bottom_width
,
bottom_depth
]))
bottom_shape
=
gpuarray_shared_constructor
(
n
p
.
array
([
bottom_height
,
bottom_width
,
bottom_depth
]))
if
(
subsample
==
(
1
,
1
,
1
)):
if
(
subsample
==
(
1
,
1
,
1
)):
conv_ref
=
Corr3dMM_gradInputs
(
subsample
=
subsample
)(
conv_ref
=
Corr3dMM_gradInputs
(
subsample
=
subsample
)(
...
...
theano/gpuarray/tests/test_linalg.py
浏览文件 @
824cb369
from
__future__
import
absolute_import
,
division
,
print_function
from
__future__
import
absolute_import
,
division
,
print_function
import
unittest
import
unittest
import
numpy
import
numpy
as
np
import
theano
import
theano
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
...
@@ -19,8 +19,8 @@ if not cusolver_available:
...
@@ -19,8 +19,8 @@ if not cusolver_available:
class
TestCusolver
(
unittest
.
TestCase
):
class
TestCusolver
(
unittest
.
TestCase
):
def
run_gpu_solve
(
self
,
A_val
,
x_val
,
A_struct
=
None
):
def
run_gpu_solve
(
self
,
A_val
,
x_val
,
A_struct
=
None
):
b_val
=
n
umpy
.
dot
(
A_val
,
x_val
)
b_val
=
n
p
.
dot
(
A_val
,
x_val
)
b_val_trans
=
n
umpy
.
dot
(
A_val
.
T
,
x_val
)
b_val_trans
=
n
p
.
dot
(
A_val
.
T
,
x_val
)
A
=
theano
.
tensor
.
matrix
(
"A"
,
dtype
=
"float32"
)
A
=
theano
.
tensor
.
matrix
(
"A"
,
dtype
=
"float32"
)
b
=
theano
.
tensor
.
matrix
(
"b"
,
dtype
=
"float32"
)
b
=
theano
.
tensor
.
matrix
(
"b"
,
dtype
=
"float32"
)
...
@@ -35,16 +35,16 @@ class TestCusolver(unittest.TestCase):
...
@@ -35,16 +35,16 @@ class TestCusolver(unittest.TestCase):
fn
=
theano
.
function
([
A
,
b
,
b_trans
],
[
solver
,
solver_trans
],
mode
=
mode_with_gpu
)
fn
=
theano
.
function
([
A
,
b
,
b_trans
],
[
solver
,
solver_trans
],
mode
=
mode_with_gpu
)
res
=
fn
(
A_val
,
b_val
,
b_val_trans
)
res
=
fn
(
A_val
,
b_val
,
b_val_trans
)
x_res
=
n
umpy
.
array
(
res
[
0
])
x_res
=
n
p
.
array
(
res
[
0
])
x_res_trans
=
n
umpy
.
array
(
res
[
1
])
x_res_trans
=
n
p
.
array
(
res
[
1
])
utt
.
assert_allclose
(
x_val
,
x_res
)
utt
.
assert_allclose
(
x_val
,
x_res
)
utt
.
assert_allclose
(
x_val
,
x_res_trans
)
utt
.
assert_allclose
(
x_val
,
x_res_trans
)
def
test_diag_solve
(
self
):
def
test_diag_solve
(
self
):
n
umpy
.
random
.
seed
(
1
)
n
p
.
random
.
seed
(
1
)
A_val
=
n
umpy
.
asarray
([[
2
,
0
,
0
],
[
0
,
1
,
0
],
[
0
,
0
,
1
]],
A_val
=
n
p
.
asarray
([[
2
,
0
,
0
],
[
0
,
1
,
0
],
[
0
,
0
,
1
]],
dtype
=
"float32"
)
dtype
=
"float32"
)
x_val
=
n
umpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_val
.
shape
[
1
],
x_val
=
n
p
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_val
.
shape
[
1
],
1
))
.
astype
(
"float32"
)
1
))
.
astype
(
"float32"
)
self
.
run_gpu_solve
(
A_val
,
x_val
)
self
.
run_gpu_solve
(
A_val
,
x_val
)
...
@@ -52,42 +52,42 @@ class TestCusolver(unittest.TestCase):
...
@@ -52,42 +52,42 @@ class TestCusolver(unittest.TestCase):
"""
"""
Test when shape of b (k, m) is such as m > k
Test when shape of b (k, m) is such as m > k
"""
"""
n
umpy
.
random
.
seed
(
1
)
n
p
.
random
.
seed
(
1
)
A_val
=
n
umpy
.
asarray
([[
2
,
0
,
0
],
[
0
,
1
,
0
],
[
0
,
0
,
1
]],
A_val
=
n
p
.
asarray
([[
2
,
0
,
0
],
[
0
,
1
,
0
],
[
0
,
0
,
1
]],
dtype
=
"float32"
)
dtype
=
"float32"
)
x_val
=
n
umpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_val
.
shape
[
1
],
x_val
=
n
p
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_val
.
shape
[
1
],
A_val
.
shape
[
1
]
+
1
))
.
astype
(
"float32"
)
A_val
.
shape
[
1
]
+
1
))
.
astype
(
"float32"
)
self
.
run_gpu_solve
(
A_val
,
x_val
)
self
.
run_gpu_solve
(
A_val
,
x_val
)
def
test_sym_solve
(
self
):
def
test_sym_solve
(
self
):
n
umpy
.
random
.
seed
(
1
)
n
p
.
random
.
seed
(
1
)
A_val
=
n
umpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
5
))
.
astype
(
"float32"
)
A_val
=
n
p
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
5
))
.
astype
(
"float32"
)
A_sym
=
n
umpy
.
dot
(
A_val
,
A_val
.
T
)
A_sym
=
n
p
.
dot
(
A_val
,
A_val
.
T
)
x_val
=
n
umpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_val
.
shape
[
1
],
x_val
=
n
p
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_val
.
shape
[
1
],
1
))
.
astype
(
"float32"
)
1
))
.
astype
(
"float32"
)
self
.
run_gpu_solve
(
A_sym
,
x_val
,
'symmetric'
)
self
.
run_gpu_solve
(
A_sym
,
x_val
,
'symmetric'
)
def
test_orth_solve
(
self
):
def
test_orth_solve
(
self
):
n
umpy
.
random
.
seed
(
1
)
n
p
.
random
.
seed
(
1
)
A_val
=
n
umpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
5
))
.
astype
(
"float32"
)
A_val
=
n
p
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
5
))
.
astype
(
"float32"
)
A_orth
=
n
umpy
.
linalg
.
svd
(
A_val
)[
0
]
A_orth
=
n
p
.
linalg
.
svd
(
A_val
)[
0
]
x_val
=
n
umpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_orth
.
shape
[
1
],
x_val
=
n
p
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_orth
.
shape
[
1
],
1
))
.
astype
(
"float32"
)
1
))
.
astype
(
"float32"
)
self
.
run_gpu_solve
(
A_orth
,
x_val
)
self
.
run_gpu_solve
(
A_orth
,
x_val
)
def
test_uni_rand_solve
(
self
):
def
test_uni_rand_solve
(
self
):
n
umpy
.
random
.
seed
(
1
)
n
p
.
random
.
seed
(
1
)
A_val
=
n
umpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
5
))
.
astype
(
"float32"
)
A_val
=
n
p
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
5
))
.
astype
(
"float32"
)
x_val
=
n
umpy
.
random
.
uniform
(
-
0.4
,
0.4
,
x_val
=
n
p
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_val
.
shape
[
1
],
4
))
.
astype
(
"float32"
)
(
A_val
.
shape
[
1
],
4
))
.
astype
(
"float32"
)
self
.
run_gpu_solve
(
A_val
,
x_val
)
self
.
run_gpu_solve
(
A_val
,
x_val
)
def
test_linalgerrsym_solve
(
self
):
def
test_linalgerrsym_solve
(
self
):
n
umpy
.
random
.
seed
(
1
)
n
p
.
random
.
seed
(
1
)
A_val
=
n
umpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
5
))
.
astype
(
"float32"
)
A_val
=
n
p
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
5
))
.
astype
(
"float32"
)
x_val
=
n
umpy
.
random
.
uniform
(
-
0.4
,
0.4
,
x_val
=
n
p
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_val
.
shape
[
1
],
4
))
.
astype
(
"float32"
)
(
A_val
.
shape
[
1
],
4
))
.
astype
(
"float32"
)
A_val
=
n
umpy
.
dot
(
A_val
.
T
,
A_val
)
A_val
=
n
p
.
dot
(
A_val
.
T
,
A_val
)
# make A singular
# make A singular
A_val
[:,
2
]
=
A_val
[:,
1
]
+
A_val
[:,
3
]
A_val
[:,
2
]
=
A_val
[:,
1
]
+
A_val
[:,
3
]
...
@@ -99,9 +99,9 @@ class TestCusolver(unittest.TestCase):
...
@@ -99,9 +99,9 @@ class TestCusolver(unittest.TestCase):
self
.
assertRaises
(
LinAlgError
,
fn
,
A_val
,
x_val
)
self
.
assertRaises
(
LinAlgError
,
fn
,
A_val
,
x_val
)
def
test_linalgerr_solve
(
self
):
def
test_linalgerr_solve
(
self
):
n
umpy
.
random
.
seed
(
1
)
n
p
.
random
.
seed
(
1
)
A_val
=
n
umpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
5
))
.
astype
(
"float32"
)
A_val
=
n
p
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
5
))
.
astype
(
"float32"
)
x_val
=
n
umpy
.
random
.
uniform
(
-
0.4
,
0.4
,
x_val
=
n
p
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_val
.
shape
[
1
],
4
))
.
astype
(
"float32"
)
(
A_val
.
shape
[
1
],
4
))
.
astype
(
"float32"
)
# make A singular
# make A singular
A_val
[:,
2
]
=
0
A_val
[:,
2
]
=
0
...
...
theano/gpuarray/tests/test_multinomial.py
浏览文件 @
824cb369
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
numpy
import
numpy
as
np
import
unittest
import
unittest
...
@@ -62,10 +62,10 @@ def test_multinomial_large():
...
@@ -62,10 +62,10 @@ def test_multinomial_large():
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialFromUniform
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialFromUniform
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
pval
=
n
umpy
.
arange
(
10000
*
4
,
pval
=
n
p
.
arange
(
10000
*
4
,
dtype
=
'float32'
)
.
reshape
((
10000
,
4
))
+
0.1
dtype
=
'float32'
)
.
reshape
((
10000
,
4
))
+
0.1
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
uval
=
n
umpy
.
ones_like
(
pval
[:,
0
])
*
0.5
uval
=
n
p
.
ones_like
(
pval
[:,
0
])
*
0.5
mval
=
f
(
pval
,
uval
)
mval
=
f
(
pval
,
uval
)
assert
mval
.
shape
==
pval
.
shape
assert
mval
.
shape
==
pval
.
shape
...
@@ -78,7 +78,7 @@ def test_multinomial_large():
...
@@ -78,7 +78,7 @@ def test_multinomial_large():
else
:
else
:
raise
NotImplementedError
(
config
.
cast_policy
)
raise
NotImplementedError
(
config
.
cast_policy
)
utt
.
assert_allclose
(
mval
.
sum
(
axis
=
1
),
2
)
utt
.
assert_allclose
(
mval
.
sum
(
axis
=
1
),
2
)
asdf
=
n
umpy
.
asarray
([
0
,
0
,
2
,
0
])
+
0
*
pval
asdf
=
n
p
.
asarray
([
0
,
0
,
2
,
0
])
+
0
*
pval
utt
.
assert_allclose
(
mval
,
asdf
)
# broadcast over all rows
utt
.
assert_allclose
(
mval
,
asdf
)
# broadcast over all rows
...
@@ -92,9 +92,9 @@ def test_gpu_opt_dtypes():
...
@@ -92,9 +92,9 @@ def test_gpu_opt_dtypes():
f
=
function
([
p
,
u
],
m
,
allow_input_downcast
=
True
,
mode
=
mode_with_gpu
)
f
=
function
([
p
,
u
],
m
,
allow_input_downcast
=
True
,
mode
=
mode_with_gpu
)
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialFromUniform
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialFromUniform
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
pval
=
n
umpy
.
arange
(
10000
*
4
,
dtype
=
'float32'
)
.
reshape
((
10000
,
4
))
+
0.1
pval
=
n
p
.
arange
(
10000
*
4
,
dtype
=
'float32'
)
.
reshape
((
10000
,
4
))
+
0.1
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
uval
=
n
umpy
.
ones_like
(
pval
[:,
0
])
*
0.5
uval
=
n
p
.
ones_like
(
pval
[:,
0
])
*
0.5
samples
=
f
(
pval
,
uval
)
samples
=
f
(
pval
,
uval
)
assert
samples
.
dtype
==
dtype
,
"
%
s !=
%
s"
%
(
samples
.
dtype
,
dtype
)
assert
samples
.
dtype
==
dtype
,
"
%
s !=
%
s"
%
(
samples
.
dtype
,
dtype
)
...
@@ -112,9 +112,9 @@ def test_gpu_opt():
...
@@ -112,9 +112,9 @@ def test_gpu_opt():
f
=
function
([
p
,
u
],
m
,
allow_input_downcast
=
True
,
mode
=
mode_with_gpu
)
f
=
function
([
p
,
u
],
m
,
allow_input_downcast
=
True
,
mode
=
mode_with_gpu
)
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialFromUniform
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialFromUniform
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
pval
=
n
umpy
.
arange
(
10000
*
4
,
dtype
=
'float32'
)
.
reshape
((
10000
,
4
))
+
0.1
pval
=
n
p
.
arange
(
10000
*
4
,
dtype
=
'float32'
)
.
reshape
((
10000
,
4
))
+
0.1
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
uval
=
n
umpy
.
ones_like
(
pval
[:,
0
])
*
0.5
uval
=
n
p
.
ones_like
(
pval
[:,
0
])
*
0.5
f
(
pval
,
uval
)
f
(
pval
,
uval
)
# Test with a row, it was failing in the past.
# Test with a row, it was failing in the past.
...
@@ -125,9 +125,9 @@ def test_gpu_opt():
...
@@ -125,9 +125,9 @@ def test_gpu_opt():
f
=
function
([
r
,
u
],
m
,
allow_input_downcast
=
True
,
mode
=
mode_with_gpu
)
f
=
function
([
r
,
u
],
m
,
allow_input_downcast
=
True
,
mode
=
mode_with_gpu
)
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialFromUniform
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialFromUniform
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
pval
=
n
umpy
.
arange
(
1
*
4
,
dtype
=
'float32'
)
.
reshape
((
1
,
4
))
+
0.1
pval
=
n
p
.
arange
(
1
*
4
,
dtype
=
'float32'
)
.
reshape
((
1
,
4
))
+
0.1
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
uval
=
n
umpy
.
ones_like
(
pval
[:,
0
])
*
0.5
uval
=
n
p
.
ones_like
(
pval
[:,
0
])
*
0.5
f
(
pval
,
uval
)
f
(
pval
,
uval
)
...
@@ -146,15 +146,15 @@ class test_OP_wor(unittest.TestCase):
...
@@ -146,15 +146,15 @@ class test_OP_wor(unittest.TestCase):
n_elements
=
1000
n_elements
=
1000
all_indices
=
range
(
n_elements
)
all_indices
=
range
(
n_elements
)
n
umpy
.
random
.
seed
(
12345
)
n
p
.
random
.
seed
(
12345
)
for
i
in
[
5
,
10
,
50
,
100
,
500
,
n_elements
]:
for
i
in
[
5
,
10
,
50
,
100
,
500
,
n_elements
]:
uni
=
n
umpy
.
random
.
rand
(
i
)
.
astype
(
config
.
floatX
)
uni
=
n
p
.
random
.
rand
(
i
)
.
astype
(
config
.
floatX
)
pvals
=
n
umpy
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
=
n
p
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
/=
pvals
.
sum
(
1
)
pvals
/=
pvals
.
sum
(
1
)
res
=
f
(
pvals
,
uni
,
i
)
res
=
f
(
pvals
,
uni
,
i
)
res
=
n
umpy
.
squeeze
(
res
)
res
=
n
p
.
squeeze
(
res
)
assert
len
(
res
)
==
i
,
res
assert
len
(
res
)
==
i
,
res
assert
n
umpy
.
all
(
numpy
.
in1d
(
numpy
.
unique
(
res
),
all_indices
)),
res
assert
n
p
.
all
(
np
.
in1d
(
np
.
unique
(
res
),
all_indices
)),
res
def
test_fail_select_alot
(
self
):
def
test_fail_select_alot
(
self
):
"""
"""
...
@@ -170,9 +170,9 @@ class test_OP_wor(unittest.TestCase):
...
@@ -170,9 +170,9 @@ class test_OP_wor(unittest.TestCase):
n_elements
=
100
n_elements
=
100
n_selected
=
200
n_selected
=
200
n
umpy
.
random
.
seed
(
12345
)
n
p
.
random
.
seed
(
12345
)
uni
=
n
umpy
.
random
.
rand
(
n_selected
)
.
astype
(
config
.
floatX
)
uni
=
n
p
.
random
.
rand
(
n_selected
)
.
astype
(
config
.
floatX
)
pvals
=
n
umpy
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
=
n
p
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
/=
pvals
.
sum
(
1
)
pvals
/=
pvals
.
sum
(
1
)
self
.
assertRaises
(
ValueError
,
f
,
pvals
,
uni
,
n_selected
)
self
.
assertRaises
(
ValueError
,
f
,
pvals
,
uni
,
n_selected
)
...
@@ -191,18 +191,18 @@ class test_OP_wor(unittest.TestCase):
...
@@ -191,18 +191,18 @@ class test_OP_wor(unittest.TestCase):
n_elements
=
100
n_elements
=
100
n_selected
=
10
n_selected
=
10
mean_rtol
=
0.0005
mean_rtol
=
0.0005
n
umpy
.
random
.
seed
(
12345
)
n
p
.
random
.
seed
(
12345
)
pvals
=
n
umpy
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
=
n
p
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
/=
pvals
.
sum
(
1
)
pvals
/=
pvals
.
sum
(
1
)
avg_pvals
=
n
umpy
.
zeros
((
n_elements
,),
dtype
=
config
.
floatX
)
avg_pvals
=
n
p
.
zeros
((
n_elements
,),
dtype
=
config
.
floatX
)
for
rep
in
range
(
10000
):
for
rep
in
range
(
10000
):
uni
=
n
umpy
.
random
.
rand
(
n_selected
)
.
astype
(
config
.
floatX
)
uni
=
n
p
.
random
.
rand
(
n_selected
)
.
astype
(
config
.
floatX
)
res
=
f
(
pvals
,
uni
,
n_selected
)
res
=
f
(
pvals
,
uni
,
n_selected
)
res
=
n
umpy
.
squeeze
(
res
)
res
=
n
p
.
squeeze
(
res
)
avg_pvals
[
res
]
+=
1
avg_pvals
[
res
]
+=
1
avg_pvals
/=
avg_pvals
.
sum
()
avg_pvals
/=
avg_pvals
.
sum
()
avg_diff
=
n
umpy
.
mean
(
abs
(
avg_pvals
-
pvals
))
avg_diff
=
n
p
.
mean
(
abs
(
avg_pvals
-
pvals
))
assert
avg_diff
<
mean_rtol
,
avg_diff
assert
avg_diff
<
mean_rtol
,
avg_diff
...
@@ -222,14 +222,14 @@ class test_function_wor(unittest.TestCase):
...
@@ -222,14 +222,14 @@ class test_function_wor(unittest.TestCase):
n_elements
=
1000
n_elements
=
1000
all_indices
=
range
(
n_elements
)
all_indices
=
range
(
n_elements
)
n
umpy
.
random
.
seed
(
12345
)
n
p
.
random
.
seed
(
12345
)
for
i
in
[
5
,
10
,
50
,
100
,
500
,
n_elements
]:
for
i
in
[
5
,
10
,
50
,
100
,
500
,
n_elements
]:
pvals
=
n
umpy
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
=
n
p
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
/=
pvals
.
sum
(
1
)
pvals
/=
pvals
.
sum
(
1
)
res
=
f
(
pvals
,
i
)
res
=
f
(
pvals
,
i
)
res
=
n
umpy
.
squeeze
(
res
)
res
=
n
p
.
squeeze
(
res
)
assert
len
(
res
)
==
i
assert
len
(
res
)
==
i
assert
n
umpy
.
all
(
numpy
.
in1d
(
numpy
.
unique
(
res
),
all_indices
)),
res
assert
n
p
.
all
(
np
.
in1d
(
np
.
unique
(
res
),
all_indices
)),
res
def
test_fail_select_alot
(
self
):
def
test_fail_select_alot
(
self
):
"""
"""
...
@@ -246,8 +246,8 @@ class test_function_wor(unittest.TestCase):
...
@@ -246,8 +246,8 @@ class test_function_wor(unittest.TestCase):
n_elements
=
100
n_elements
=
100
n_selected
=
200
n_selected
=
200
n
umpy
.
random
.
seed
(
12345
)
n
p
.
random
.
seed
(
12345
)
pvals
=
n
umpy
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
=
n
p
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
/=
pvals
.
sum
(
1
)
pvals
/=
pvals
.
sum
(
1
)
self
.
assertRaises
(
ValueError
,
f
,
pvals
,
n_selected
)
self
.
assertRaises
(
ValueError
,
f
,
pvals
,
n_selected
)
...
@@ -267,17 +267,17 @@ class test_function_wor(unittest.TestCase):
...
@@ -267,17 +267,17 @@ class test_function_wor(unittest.TestCase):
n_elements
=
100
n_elements
=
100
n_selected
=
10
n_selected
=
10
mean_rtol
=
0.0005
mean_rtol
=
0.0005
n
umpy
.
random
.
seed
(
12345
)
n
p
.
random
.
seed
(
12345
)
pvals
=
n
umpy
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
=
n
p
.
random
.
randint
(
1
,
100
,
(
1
,
n_elements
))
.
astype
(
config
.
floatX
)
pvals
/=
pvals
.
sum
(
1
)
pvals
/=
pvals
.
sum
(
1
)
avg_pvals
=
n
umpy
.
zeros
((
n_elements
,),
dtype
=
config
.
floatX
)
avg_pvals
=
n
p
.
zeros
((
n_elements
,),
dtype
=
config
.
floatX
)
for
rep
in
range
(
10000
):
for
rep
in
range
(
10000
):
res
=
f
(
pvals
,
n_selected
)
res
=
f
(
pvals
,
n_selected
)
res
=
n
umpy
.
squeeze
(
res
)
res
=
n
p
.
squeeze
(
res
)
avg_pvals
[
res
]
+=
1
avg_pvals
[
res
]
+=
1
avg_pvals
/=
avg_pvals
.
sum
()
avg_pvals
/=
avg_pvals
.
sum
()
avg_diff
=
n
umpy
.
mean
(
abs
(
avg_pvals
-
pvals
))
avg_diff
=
n
p
.
mean
(
abs
(
avg_pvals
-
pvals
))
assert
avg_diff
<
mean_rtol
assert
avg_diff
<
mean_rtol
...
@@ -294,9 +294,9 @@ def test_gpu_opt_wor():
...
@@ -294,9 +294,9 @@ def test_gpu_opt_wor():
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialWOReplacementFromUniform
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialWOReplacementFromUniform
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
n_samples
=
3
n_samples
=
3
pval
=
n
umpy
.
arange
(
10000
*
4
,
dtype
=
'float32'
)
.
reshape
((
10000
,
4
))
+
0.1
pval
=
n
p
.
arange
(
10000
*
4
,
dtype
=
'float32'
)
.
reshape
((
10000
,
4
))
+
0.1
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
uval
=
n
umpy
.
ones
(
pval
.
shape
[
0
]
*
n_samples
)
*
0.5
uval
=
n
p
.
ones
(
pval
.
shape
[
0
]
*
n_samples
)
*
0.5
f
(
pval
,
uval
,
n_samples
)
f
(
pval
,
uval
,
n_samples
)
# Test with a row, it was failing in the past.
# Test with a row, it was failing in the past.
...
@@ -307,7 +307,7 @@ def test_gpu_opt_wor():
...
@@ -307,7 +307,7 @@ def test_gpu_opt_wor():
f
=
function
([
r
,
u
,
n
],
m
,
allow_input_downcast
=
True
,
mode
=
mode_with_gpu
)
f
=
function
([
r
,
u
,
n
],
m
,
allow_input_downcast
=
True
,
mode
=
mode_with_gpu
)
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialWOReplacementFromUniform
assert
any
([
type
(
node
.
op
)
is
GPUAMultinomialWOReplacementFromUniform
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
pval
=
n
umpy
.
arange
(
1
*
4
,
dtype
=
'float32'
)
.
reshape
((
1
,
4
))
+
0.1
pval
=
n
p
.
arange
(
1
*
4
,
dtype
=
'float32'
)
.
reshape
((
1
,
4
))
+
0.1
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
pval
=
pval
/
pval
.
sum
(
axis
=
1
)[:,
None
]
uval
=
n
umpy
.
ones_like
(
pval
[:,
0
])
*
0.5
uval
=
n
p
.
ones_like
(
pval
[:,
0
])
*
0.5
f
(
pval
,
uval
,
1
)
f
(
pval
,
uval
,
1
)
theano/gpuarray/tests/test_nerv.py
浏览文件 @
824cb369
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
import
numpy
import
numpy
as
np
from
theano
import
function
from
theano
import
function
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
...
@@ -40,10 +40,10 @@ def test_gemm16_value():
...
@@ -40,10 +40,10 @@ def test_gemm16_value():
f
=
function
([
m
,
m2
],
dot
(
m
,
m2
),
mode
=
mode_with_gpu
)
f
=
function
([
m
,
m2
],
dot
(
m
,
m2
),
mode
=
mode_with_gpu
)
v1
=
n
umpy
.
random
.
random
((
3
,
4
))
.
astype
(
'float16'
)
v1
=
n
p
.
random
.
random
((
3
,
4
))
.
astype
(
'float16'
)
v2
=
n
umpy
.
random
.
random
((
4
,
2
))
.
astype
(
'float16'
)
v2
=
n
p
.
random
.
random
((
4
,
2
))
.
astype
(
'float16'
)
of
=
f
(
v1
,
v2
)
of
=
f
(
v1
,
v2
)
on
=
n
umpy
.
dot
(
v1
,
v2
)
on
=
n
p
.
dot
(
v1
,
v2
)
utt
.
assert_allclose
(
of
,
on
)
utt
.
assert_allclose
(
of
,
on
)
theano/gpuarray/tests/test_nnet.py
浏览文件 @
824cb369
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
numpy
import
numpy
as
np
import
unittest
import
unittest
import
theano
import
theano
...
@@ -46,13 +46,13 @@ def test_GpuCrossentropySoftmaxArgmax1HotWithBias():
...
@@ -46,13 +46,13 @@ def test_GpuCrossentropySoftmaxArgmax1HotWithBias():
# Seed numpy.random with config.unittests.rseed
# Seed numpy.random with config.unittests.rseed
utt
.
seed_rng
()
utt
.
seed_rng
()
xx
=
n
umpy
.
asarray
(
numpy
.
random
.
rand
(
batch_size
,
n_in
),
xx
=
n
p
.
asarray
(
np
.
random
.
rand
(
batch_size
,
n_in
),
dtype
=
numpy
.
float32
)
dtype
=
np
.
float32
)
yy
=
n
umpy
.
ones
((
batch_size
,),
dtype
=
'int32'
)
yy
=
n
p
.
ones
((
batch_size
,),
dtype
=
'int32'
)
b_values
=
n
umpy
.
zeros
((
n_out
,),
dtype
=
'float32'
)
b_values
=
n
p
.
zeros
((
n_out
,),
dtype
=
'float32'
)
W_values
=
n
umpy
.
asarray
(
numpy
.
random
.
rand
(
n_in
,
n_out
),
dtype
=
'float32'
)
W_values
=
n
p
.
asarray
(
np
.
random
.
rand
(
n_in
,
n_out
),
dtype
=
'float32'
)
dot_value
=
n
umpy
.
asarray
(
numpy
.
dot
(
xx
,
W_values
),
dtype
=
'float32'
)
dot_value
=
n
p
.
asarray
(
np
.
dot
(
xx
,
W_values
),
dtype
=
'float32'
)
del
W_values
del
W_values
p_y_given_x
=
T
.
nnet
.
softmax
(
dot_result
+
b
)
p_y_given_x
=
T
.
nnet
.
softmax
(
dot_result
+
b
)
y_pred
=
T
.
argmax
(
p_y_given_x
,
axis
=-
1
)
y_pred
=
T
.
argmax
(
p_y_given_x
,
axis
=-
1
)
...
@@ -97,10 +97,10 @@ def test_GpuCrossentropySoftmax1HotWithBiasDx():
...
@@ -97,10 +97,10 @@ def test_GpuCrossentropySoftmax1HotWithBiasDx():
# Seed numpy.random with config.unittests.rseed
# Seed numpy.random with config.unittests.rseed
utt
.
seed_rng
()
utt
.
seed_rng
()
softmax_output_value
=
n
umpy
.
random
.
rand
(
batch_size
,
softmax_output_value
=
n
p
.
random
.
rand
(
batch_size
,
n_out
)
.
astype
(
'float32'
)
n_out
)
.
astype
(
'float32'
)
dnll_value
=
n
umpy
.
asarray
(
numpy
.
random
.
rand
(
batch_size
),
dtype
=
'float32'
)
dnll_value
=
n
p
.
asarray
(
np
.
random
.
rand
(
batch_size
),
dtype
=
'float32'
)
y_idx_value
=
n
umpy
.
random
.
randint
(
low
=
0
,
high
=
5
,
size
=
batch_size
)
y_idx_value
=
n
p
.
random
.
randint
(
low
=
0
,
high
=
5
,
size
=
batch_size
)
softmax_output
=
T
.
fmatrix
()
softmax_output
=
T
.
fmatrix
()
softmax_output
/=
softmax_output
.
sum
(
axis
=
1
)
.
reshape
(
softmax_output
/=
softmax_output
.
sum
(
axis
=
1
)
.
reshape
(
...
@@ -174,8 +174,8 @@ def softmax_with_bias_unittest_template(dtypeInput, dtypeBias):
...
@@ -174,8 +174,8 @@ def softmax_with_bias_unittest_template(dtypeInput, dtypeBias):
GpuSoftmaxWithBias
)
GpuSoftmaxWithBias
)
def
cmp
(
n
,
m
):
def
cmp
(
n
,
m
):
data
=
n
umpy
.
random
.
uniform
(
1e-7
,
1
,
(
n
,
m
))
.
astype
(
dtype
=
dtypeInput
)
data
=
n
p
.
random
.
uniform
(
1e-7
,
1
,
(
n
,
m
))
.
astype
(
dtype
=
dtypeInput
)
b_data
=
n
umpy
.
random
.
uniform
(
1e-7
,
1
,
(
m
,))
.
astype
(
dtype
=
dtypeBias
)
b_data
=
n
p
.
random
.
uniform
(
1e-7
,
1
,
(
m
,))
.
astype
(
dtype
=
dtypeBias
)
out
=
f
(
data
,
b_data
)
out
=
f
(
data
,
b_data
)
gout
=
f_gpu
(
data
,
b_data
)
gout
=
f_gpu
(
data
,
b_data
)
...
@@ -227,7 +227,7 @@ def softmax_unittest_template(dtypeInput):
...
@@ -227,7 +227,7 @@ def softmax_unittest_template(dtypeInput):
GpuSoftmax
)
GpuSoftmax
)
def
cmp
(
n
,
m
):
def
cmp
(
n
,
m
):
data
=
n
umpy
.
random
.
uniform
(
0
,
1
,
(
n
,
m
))
.
astype
(
dtype
=
dtypeInput
)
data
=
n
p
.
random
.
uniform
(
0
,
1
,
(
n
,
m
))
.
astype
(
dtype
=
dtypeInput
)
out
=
f
(
data
)
out
=
f
(
data
)
gout
=
f_gpu
(
data
)
gout
=
f_gpu
(
data
)
...
@@ -301,7 +301,7 @@ class test_SoftMax(unittest.TestCase):
...
@@ -301,7 +301,7 @@ class test_SoftMax(unittest.TestCase):
return
f
,
f_gpu
return
f
,
f_gpu
def
_cmp
(
self
,
n
,
m
,
f
,
f_gpu
):
def
_cmp
(
self
,
n
,
m
,
f
,
f_gpu
):
data
=
n
umpy
.
arange
(
n
*
m
,
dtype
=
'float32'
)
.
reshape
(
n
,
m
)
data
=
n
p
.
arange
(
n
*
m
,
dtype
=
'float32'
)
.
reshape
(
n
,
m
)
out
=
f
(
data
)
out
=
f
(
data
)
gout
=
f_gpu
(
data
)
gout
=
f_gpu
(
data
)
utt
.
assert_allclose
(
out
,
gout
)
utt
.
assert_allclose
(
out
,
gout
)
...
...
theano/gpuarray/tests/test_opt.py
浏览文件 @
824cb369
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
numpy
import
numpy
as
np
from
nose.tools
import
assert_raises
from
nose.tools
import
assert_raises
import
theano
import
theano
...
@@ -79,13 +79,13 @@ def test_local_gpu_contiguous():
...
@@ -79,13 +79,13 @@ def test_local_gpu_contiguous():
def
test_flatten
():
def
test_flatten
():
m
=
theano
.
tensor
.
fmatrix
()
m
=
theano
.
tensor
.
fmatrix
()
f
=
theano
.
function
([
m
],
m
.
flatten
(),
mode
=
mode_with_gpu
)
f
=
theano
.
function
([
m
],
m
.
flatten
(),
mode
=
mode_with_gpu
)
val
=
n
umpy
.
random
.
rand
(
10
,
11
)
.
astype
(
"float32"
)
val
=
n
p
.
random
.
rand
(
10
,
11
)
.
astype
(
"float32"
)
res
=
f
(
val
)
res
=
f
(
val
)
utt
.
assert_allclose
(
res
,
val
.
flatten
())
utt
.
assert_allclose
(
res
,
val
.
flatten
())
assert
res
.
shape
==
val
.
flatten
()
.
shape
assert
res
.
shape
==
val
.
flatten
()
.
shape
assert
GpuReshape
in
[
type
(
node
.
op
)
assert
GpuReshape
in
[
type
(
node
.
op
)
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
val
=
n
umpy
.
random
.
rand
(
10
,
11
)
.
astype
(
"float32"
)
val
=
n
p
.
random
.
rand
(
10
,
11
)
.
astype
(
"float32"
)
res
=
f
(
val
)
res
=
f
(
val
)
utt
.
assert_allclose
(
res
,
val
.
flatten
())
utt
.
assert_allclose
(
res
,
val
.
flatten
())
assert
res
.
shape
==
val
.
flatten
()
.
shape
assert
res
.
shape
==
val
.
flatten
()
.
shape
...
@@ -93,7 +93,7 @@ def test_flatten():
...
@@ -93,7 +93,7 @@ def test_flatten():
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
f
=
theano
.
function
([
m
],
m
.
flatten
(
ndim
=
2
),
mode
=
mode_with_gpu
)
f
=
theano
.
function
([
m
],
m
.
flatten
(
ndim
=
2
),
mode
=
mode_with_gpu
)
val
=
n
umpy
.
random
.
rand
(
10
,
11
)
.
astype
(
"float32"
)
val
=
n
p
.
random
.
rand
(
10
,
11
)
.
astype
(
"float32"
)
res
=
f
(
val
)
res
=
f
(
val
)
utt
.
assert_allclose
(
res
,
val
)
utt
.
assert_allclose
(
res
,
val
)
assert
res
.
shape
==
val
.
shape
assert
res
.
shape
==
val
.
shape
...
@@ -102,7 +102,7 @@ def test_flatten():
...
@@ -102,7 +102,7 @@ def test_flatten():
m
=
theano
.
tensor
.
tensor3
()
m
=
theano
.
tensor
.
tensor3
()
f
=
theano
.
function
([
m
],
m
.
flatten
(
ndim
=
2
),
mode
=
mode_with_gpu
)
f
=
theano
.
function
([
m
],
m
.
flatten
(
ndim
=
2
),
mode
=
mode_with_gpu
)
val
=
n
umpy
.
random
.
rand
(
10
,
11
,
12
)
.
astype
(
"float32"
)
val
=
n
p
.
random
.
rand
(
10
,
11
,
12
)
.
astype
(
"float32"
)
res
=
f
(
val
)
res
=
f
(
val
)
utt
.
assert_allclose
(
res
,
val
.
reshape
(
10
,
-
1
))
utt
.
assert_allclose
(
res
,
val
.
reshape
(
10
,
-
1
))
assert
res
.
shape
==
val
.
reshape
(
10
,
-
1
)
.
shape
assert
res
.
shape
==
val
.
reshape
(
10
,
-
1
)
.
shape
...
@@ -120,7 +120,7 @@ def test_reduce():
...
@@ -120,7 +120,7 @@ def test_reduce():
f
=
theano
.
function
([
m
],
getattr
(
m
,
method
)(
axis
=
0
,
f
=
theano
.
function
([
m
],
getattr
(
m
,
method
)(
axis
=
0
,
**
param
),
**
param
),
mode
=
mode_with_gpu
)
mode
=
mode_with_gpu
)
val
=
n
umpy
.
random
.
rand
(
10
,
11
)
.
astype
(
"float32"
)
val
=
n
p
.
random
.
rand
(
10
,
11
)
.
astype
(
"float32"
)
res
=
f
(
val
)
res
=
f
(
val
)
utt
.
assert_allclose
(
res
,
getattr
(
val
,
method
)(
axis
=
0
))
utt
.
assert_allclose
(
res
,
getattr
(
val
,
method
)(
axis
=
0
))
assert
res
.
shape
==
(
11
,)
assert
res
.
shape
==
(
11
,)
...
@@ -135,9 +135,9 @@ def test_reduce():
...
@@ -135,9 +135,9 @@ def test_reduce():
def
test_local_gpualloc_memset_0
():
def
test_local_gpualloc_memset_0
():
i
=
theano
.
tensor
.
iscalar
()
i
=
theano
.
tensor
.
iscalar
()
z
=
n
umpy
.
zeros
((
1
,),
dtype
=
'float32'
)
z
=
n
p
.
zeros
((
1
,),
dtype
=
'float32'
)
o
=
n
umpy
.
ones
((
1
,),
dtype
=
'float32'
)
o
=
n
p
.
ones
((
1
,),
dtype
=
'float32'
)
ones
=
n
umpy
.
ones
((
2
,),
dtype
=
'float32'
)
ones
=
n
p
.
ones
((
2
,),
dtype
=
'float32'
)
# Test with 0 from CPU op.
# Test with 0 from CPU op.
# Should not be transfered as the only client is the output
# Should not be transfered as the only client is the output
...
@@ -146,7 +146,7 @@ def test_local_gpualloc_memset_0():
...
@@ -146,7 +146,7 @@ def test_local_gpualloc_memset_0():
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
1
assert
len
(
topo
)
==
1
assert
isinstance
(
topo
[
0
]
.
op
,
theano
.
tensor
.
Alloc
)
assert
isinstance
(
topo
[
0
]
.
op
,
theano
.
tensor
.
Alloc
)
assert
(
n
umpy
.
asarray
(
f
(
6
))
==
0
)
.
all
()
assert
(
n
p
.
asarray
(
f
(
6
))
==
0
)
.
all
()
# Test with 0 from CPU op.
# Test with 0 from CPU op.
# Should be transfered as it is used by another op.
# Should be transfered as it is used by another op.
...
@@ -155,7 +155,7 @@ def test_local_gpualloc_memset_0():
...
@@ -155,7 +155,7 @@ def test_local_gpualloc_memset_0():
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
3
assert
len
(
topo
)
==
3
assert
isinstance
(
topo
[
0
]
.
op
,
GpuAlloc
)
assert
isinstance
(
topo
[
0
]
.
op
,
GpuAlloc
)
assert
(
n
umpy
.
asarray
(
f
(
6
))
==
0
)
.
all
()
assert
(
n
p
.
asarray
(
f
(
6
))
==
0
)
.
all
()
# Test with 0
# Test with 0
a
=
GpuAlloc
(
test_ctx_name
)(
z
,
i
)
a
=
GpuAlloc
(
test_ctx_name
)(
z
,
i
)
...
@@ -163,7 +163,7 @@ def test_local_gpualloc_memset_0():
...
@@ -163,7 +163,7 @@ def test_local_gpualloc_memset_0():
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
1
assert
len
(
topo
)
==
1
assert
isinstance
(
topo
[
0
]
.
op
,
GpuAlloc
)
and
topo
[
0
]
.
op
.
memset_0
assert
isinstance
(
topo
[
0
]
.
op
,
GpuAlloc
)
and
topo
[
0
]
.
op
.
memset_0
assert
(
n
umpy
.
asarray
(
f
(
6
))
==
0
)
.
all
()
assert
(
n
p
.
asarray
(
f
(
6
))
==
0
)
.
all
()
# Test with 1
# Test with 1
a
=
GpuAlloc
(
test_ctx_name
)(
o
,
i
)
a
=
GpuAlloc
(
test_ctx_name
)(
o
,
i
)
...
@@ -172,7 +172,7 @@ def test_local_gpualloc_memset_0():
...
@@ -172,7 +172,7 @@ def test_local_gpualloc_memset_0():
assert
len
(
topo
)
==
1
assert
len
(
topo
)
==
1
assert
isinstance
(
topo
[
0
]
.
op
,
GpuAlloc
)
assert
isinstance
(
topo
[
0
]
.
op
,
GpuAlloc
)
assert
not
topo
[
0
]
.
op
.
memset_0
assert
not
topo
[
0
]
.
op
.
memset_0
assert
(
n
umpy
.
asarray
(
f
(
6
))
==
1
)
.
all
()
assert
(
n
p
.
asarray
(
f
(
6
))
==
1
)
.
all
()
# Test with 1, 1
# Test with 1, 1
a
=
GpuAlloc
(
test_ctx_name
)(
ones
,
i
)
a
=
GpuAlloc
(
test_ctx_name
)(
ones
,
i
)
...
@@ -181,7 +181,7 @@ def test_local_gpualloc_memset_0():
...
@@ -181,7 +181,7 @@ def test_local_gpualloc_memset_0():
assert
len
(
topo
)
==
1
assert
len
(
topo
)
==
1
assert
isinstance
(
topo
[
0
]
.
op
,
GpuAlloc
)
assert
isinstance
(
topo
[
0
]
.
op
,
GpuAlloc
)
assert
not
topo
[
0
]
.
op
.
memset_0
assert
not
topo
[
0
]
.
op
.
memset_0
assert
(
n
umpy
.
asarray
(
f
(
2
))
==
1
)
.
all
()
assert
(
n
p
.
asarray
(
f
(
2
))
==
1
)
.
all
()
def
test_local_gpualloc_empty
():
def
test_local_gpualloc_empty
():
...
@@ -219,7 +219,7 @@ def test_local_gpualloc_empty():
...
@@ -219,7 +219,7 @@ def test_local_gpualloc_empty():
def
test_rebroadcast
():
def
test_rebroadcast
():
d
=
n
umpy
.
random
.
rand
(
10
,
10
)
.
astype
(
'float32'
)
d
=
n
p
.
random
.
rand
(
10
,
10
)
.
astype
(
'float32'
)
v
=
theano
.
tensor
.
fmatrix
()
v
=
theano
.
tensor
.
fmatrix
()
up
=
tensor
.
unbroadcast
(
v
.
sum
()
.
dimshuffle
(
'x'
,
'x'
),
0
,
1
)
up
=
tensor
.
unbroadcast
(
v
.
sum
()
.
dimshuffle
(
'x'
,
'x'
),
0
,
1
)
f
=
theano
.
function
([
v
],
[
up
],
mode
=
mode_with_gpu
)
f
=
theano
.
function
([
v
],
[
up
],
mode
=
mode_with_gpu
)
...
@@ -257,14 +257,14 @@ class test_gpu_ifelse(test_ifelse.test_ifelse):
...
@@ -257,14 +257,14 @@ class test_gpu_ifelse(test_ifelse.test_ifelse):
f
=
theano
.
function
([
x
,
cond
],
f
=
theano
.
function
([
x
,
cond
],
theano
.
ifelse
.
ifelse
(
cond
,
x
.
mean
(),
x
.
sum
()),
theano
.
ifelse
.
ifelse
(
cond
,
x
.
mean
(),
x
.
sum
()),
mode
=
mode_with_gpu
)
mode
=
mode_with_gpu
)
assert
f
(
n
umpy
.
float32
([
1
,
2
,
3
]),
0
)
==
6
assert
f
(
n
p
.
float32
([
1
,
2
,
3
]),
0
)
==
6
x
=
tensor
.
vector
()
x
=
tensor
.
vector
()
cond
=
tensor
.
scalar
()
cond
=
tensor
.
scalar
()
f
=
theano
.
function
([
x
,
cond
],
f
=
theano
.
function
([
x
,
cond
],
theano
.
ifelse
.
ifelse
(
cond
,
x
.
mean
(),
x
.
sum
()),
theano
.
ifelse
.
ifelse
(
cond
,
x
.
mean
(),
x
.
sum
()),
mode
=
mode_with_gpu
)
mode
=
mode_with_gpu
)
assert
f
(
n
umpy
.
float32
([
1
,
2
,
3
]),
0
)
==
6
assert
f
(
n
p
.
float32
([
1
,
2
,
3
]),
0
)
==
6
def
test_print_op
():
def
test_print_op
():
...
@@ -277,7 +277,7 @@ def test_print_op():
...
@@ -277,7 +277,7 @@ def test_print_op():
assert
isinstance
(
topo
[
1
]
.
op
,
theano
.
printing
.
Print
)
assert
isinstance
(
topo
[
1
]
.
op
,
theano
.
printing
.
Print
)
assert
isinstance
(
topo
[
2
]
.
op
,
GpuElemwise
)
assert
isinstance
(
topo
[
2
]
.
op
,
GpuElemwise
)
assert
topo
[
3
]
.
op
==
host_from_gpu
assert
topo
[
3
]
.
op
==
host_from_gpu
f
(
n
umpy
.
random
.
random
((
5
,
5
))
.
astype
(
'float32'
))
f
(
n
p
.
random
.
random
((
5
,
5
))
.
astype
(
'float32'
))
def
test_pdbbreakpoint_op
():
def
test_pdbbreakpoint_op
():
...
@@ -306,7 +306,7 @@ def test_local_gpu_elemwise_careduce():
...
@@ -306,7 +306,7 @@ def test_local_gpu_elemwise_careduce():
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
len
(
topo
)
==
3
assert
len
(
topo
)
==
3
assert
topo
[
1
]
.
op
.
pre_scalar_op
==
theano
.
scalar
.
sqr
assert
topo
[
1
]
.
op
.
pre_scalar_op
==
theano
.
scalar
.
sqr
data
=
n
umpy
.
random
.
rand
(
3
,
4
)
.
astype
(
theano
.
config
.
floatX
)
data
=
n
p
.
random
.
rand
(
3
,
4
)
.
astype
(
theano
.
config
.
floatX
)
utt
.
assert_allclose
(
f
(
data
),
(
data
*
data
)
.
sum
())
utt
.
assert_allclose
(
f
(
data
),
(
data
*
data
)
.
sum
())
o
=
(
x
*
x
)
.
sum
(
axis
=
1
)
o
=
(
x
*
x
)
.
sum
(
axis
=
1
)
...
@@ -328,15 +328,15 @@ def test_local_lift_dot22scalar():
...
@@ -328,15 +328,15 @@ def test_local_lift_dot22scalar():
for
n
in
f_gpu
.
maker
.
fgraph
.
apply_nodes
)
for
n
in
f_gpu
.
maker
.
fgraph
.
apply_nodes
)
assert
any
(
isinstance
(
n
.
op
,
GpuGemm
)
assert
any
(
isinstance
(
n
.
op
,
GpuGemm
)
for
n
in
f_gpu
.
maker
.
fgraph
.
apply_nodes
)
for
n
in
f_gpu
.
maker
.
fgraph
.
apply_nodes
)
x_val
=
n
umpy
.
random
.
random
((
2
,
3
))
.
astype
(
theano
.
config
.
floatX
)
x_val
=
n
p
.
random
.
random
((
2
,
3
))
.
astype
(
theano
.
config
.
floatX
)
y_val
=
n
umpy
.
random
.
random
((
3
,
4
))
.
astype
(
theano
.
config
.
floatX
)
y_val
=
n
p
.
random
.
random
((
3
,
4
))
.
astype
(
theano
.
config
.
floatX
)
a_val
=
0.5
a_val
=
0.5
utt
.
assert_allclose
(
f_cpu
(
x_val
,
y_val
,
a_val
),
f_gpu
(
x_val
,
y_val
,
a_val
))
utt
.
assert_allclose
(
f_cpu
(
x_val
,
y_val
,
a_val
),
f_gpu
(
x_val
,
y_val
,
a_val
))
def
test_local_gpu_subtensor
():
def
test_local_gpu_subtensor
():
# Test shared forced on CPU.
# Test shared forced on CPU.
t
=
tensor
.
_shared
(
n
umpy
.
zeros
(
20
,
"float32"
))
t
=
tensor
.
_shared
(
n
p
.
zeros
(
20
,
"float32"
))
f
=
theano
.
function
([],
t
[
3
:
4
],
mode
=
mode_with_gpu
)
f
=
theano
.
function
([],
t
[
3
:
4
],
mode
=
mode_with_gpu
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
any
([
type
(
node
.
op
)
is
tensor
.
Subtensor
for
node
in
topo
])
assert
any
([
type
(
node
.
op
)
is
tensor
.
Subtensor
for
node
in
topo
])
...
@@ -367,7 +367,7 @@ def test_local_gpu_subtensor():
...
@@ -367,7 +367,7 @@ def test_local_gpu_subtensor():
# Test shared forced on CPU end we do computation on the output of
# Test shared forced on CPU end we do computation on the output of
# the subtensor.
# the subtensor.
t
=
tensor
.
_shared
(
n
umpy
.
zeros
(
20
,
"float32"
))
t
=
tensor
.
_shared
(
n
p
.
zeros
(
20
,
"float32"
))
f
=
theano
.
function
([],
t
[
3
:
4
]
+
1
,
mode
=
mode_with_gpu
)
f
=
theano
.
function
([],
t
[
3
:
4
]
+
1
,
mode
=
mode_with_gpu
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
any
([
type
(
node
.
op
)
is
tensor
.
Subtensor
for
node
in
topo
])
assert
any
([
type
(
node
.
op
)
is
tensor
.
Subtensor
for
node
in
topo
])
...
@@ -386,9 +386,9 @@ def test_local_gpu_elemwise():
...
@@ -386,9 +386,9 @@ def test_local_gpu_elemwise():
b
=
tensor
.
fmatrix
()
b
=
tensor
.
fmatrix
()
c
=
tensor
.
fmatrix
()
c
=
tensor
.
fmatrix
()
a_v
=
(
n
umpy
.
random
.
rand
(
4
,
5
)
*
10
)
.
astype
(
"int8"
)
a_v
=
(
n
p
.
random
.
rand
(
4
,
5
)
*
10
)
.
astype
(
"int8"
)
b_v
=
(
n
umpy
.
random
.
rand
(
4
,
5
)
*
10
)
.
astype
(
"float32"
)
b_v
=
(
n
p
.
random
.
rand
(
4
,
5
)
*
10
)
.
astype
(
"float32"
)
c_v
=
(
n
umpy
.
random
.
rand
(
4
,
5
)
*
10
)
.
astype
(
"float32"
)
c_v
=
(
n
p
.
random
.
rand
(
4
,
5
)
*
10
)
.
astype
(
"float32"
)
# Due to optimization order, this composite is created when all
# Due to optimization order, this composite is created when all
# the op are on the gpu.
# the op are on the gpu.
...
@@ -440,7 +440,7 @@ def test_local_gpu_elemwise():
...
@@ -440,7 +440,7 @@ def test_local_gpu_elemwise():
utt
.
assert_allclose
(
out
[
1
],
a_v
*
c_v
)
utt
.
assert_allclose
(
out
[
1
],
a_v
*
c_v
)
# Test non-contiguous input
# Test non-contiguous input
c
=
gpuarray_shared_constructor
(
n
umpy
.
asarray
(
c_v
,
dtype
=
'float32'
))
c
=
gpuarray_shared_constructor
(
n
p
.
asarray
(
c_v
,
dtype
=
'float32'
))
f
=
theano
.
function
([
a
,
b
],
outs_op
(
a
[::
2
],
b
[::
2
],
c
[::
2
]),
f
=
theano
.
function
([
a
,
b
],
outs_op
(
a
[::
2
],
b
[::
2
],
c
[::
2
]),
mode
=
mode_with_gpu
)
mode
=
mode_with_gpu
)
out
=
f
(
a_v
,
b_v
)
out
=
f
(
a_v
,
b_v
)
...
@@ -462,7 +462,7 @@ def test_local_lift_abstractconv_gpu_shape():
...
@@ -462,7 +462,7 @@ def test_local_lift_abstractconv_gpu_shape():
def
test_local_assert_no_cpu_op
():
def
test_local_assert_no_cpu_op
():
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
m
=
rng
.
uniform
(
-
1
,
1
,
(
10
,
10
))
.
astype
(
"float32"
)
m
=
rng
.
uniform
(
-
1
,
1
,
(
10
,
10
))
.
astype
(
"float32"
)
ms
=
gpuarray_shared_constructor
(
m
,
name
=
"m_shared"
)
ms
=
gpuarray_shared_constructor
(
m
,
name
=
"m_shared"
)
out
=
theano
.
tensor
.
tanh
(
ms
)
.
dot
(
ms
.
T
)
out
=
theano
.
tensor
.
tanh
(
ms
)
.
dot
(
ms
.
T
)
...
@@ -512,6 +512,6 @@ def test_local_lift_solve():
...
@@ -512,6 +512,6 @@ def test_local_lift_solve():
for
n
in
f_gpu
.
maker
.
fgraph
.
apply_nodes
)
for
n
in
f_gpu
.
maker
.
fgraph
.
apply_nodes
)
assert
any
(
isinstance
(
n
.
op
,
GpuCusolverSolve
)
assert
any
(
isinstance
(
n
.
op
,
GpuCusolverSolve
)
for
n
in
f_gpu
.
maker
.
fgraph
.
apply_nodes
)
for
n
in
f_gpu
.
maker
.
fgraph
.
apply_nodes
)
A_val
=
n
umpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
5
))
.
astype
(
"float32"
)
A_val
=
n
p
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
5
))
.
astype
(
"float32"
)
b_val
=
n
umpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
3
))
.
astype
(
"float32"
)
b_val
=
n
p
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
3
))
.
astype
(
"float32"
)
utt
.
assert_allclose
(
f_cpu
(
A_val
,
b_val
),
f_gpu
(
A_val
,
b_val
))
utt
.
assert_allclose
(
f_cpu
(
A_val
,
b_val
),
f_gpu
(
A_val
,
b_val
))
theano/gpuarray/tests/test_pickle.py
浏览文件 @
824cb369
...
@@ -12,7 +12,7 @@ from six import reraise
...
@@ -12,7 +12,7 @@ from six import reraise
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
from
nose.tools
import
assert_raises
from
nose.tools
import
assert_raises
import
numpy
import
numpy
as
np
from
theano.compat
import
PY3
from
theano.compat
import
PY3
from
theano
import
config
from
theano
import
config
...
@@ -75,7 +75,7 @@ def test_unpickle_gpuarray_as_numpy_ndarray_flag2():
...
@@ -75,7 +75,7 @@ def test_unpickle_gpuarray_as_numpy_ndarray_flag2():
reraise
(
SkipTest
,
exc_value
,
exc_trace
)
reraise
(
SkipTest
,
exc_value
,
exc_trace
)
raise
raise
assert
isinstance
(
mat
,
n
umpy
.
ndarray
)
assert
isinstance
(
mat
,
n
p
.
ndarray
)
assert
mat
[
0
]
==
-
42.0
assert
mat
[
0
]
==
-
42.0
finally
:
finally
:
...
...
theano/gpuarray/tests/test_pool.py
浏览文件 @
824cb369
...
@@ -4,7 +4,7 @@ import unittest
...
@@ -4,7 +4,7 @@ import unittest
import
copy
import
copy
import
itertools
import
itertools
import
numpy
import
numpy
as
np
import
theano
import
theano
from
theano
import
gradient
from
theano
import
gradient
from
theano
import
tensor
from
theano
import
tensor
...
@@ -81,7 +81,7 @@ def test_pool2d():
...
@@ -81,7 +81,7 @@ def test_pool2d():
(
3
,
2
,
6
,
6
,
6
,
5
),
(
3
,
2
,
6
,
6
,
6
,
5
),
(
3
,
2
,
6
,
6
,
6
,
5
,
7
),
]
(
3
,
2
,
6
,
6
,
6
,
5
,
7
),
]
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
.
shuffle
(
shps
)
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
.
shuffle
(
shps
)
test_ws
=
(
2
,
2
),
(
3
,
2
),
(
1
,
1
)
test_ws
=
(
2
,
2
),
(
3
,
2
),
(
1
,
1
)
test_st
=
(
2
,
2
),
(
3
,
2
),
(
1
,
1
)
test_st
=
(
2
,
2
),
(
3
,
2
),
(
1
,
1
)
test_mode
=
[
'max'
,
'sum'
,
'average_inc_pad'
,
'average_exc_pad'
]
test_mode
=
[
'max'
,
'sum'
,
'average_inc_pad'
,
'average_exc_pad'
]
...
@@ -113,7 +113,7 @@ def test_pool2d():
...
@@ -113,7 +113,7 @@ def test_pool2d():
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
assert
any
([
isinstance
(
node
.
op
,
Pool
)
assert
any
([
isinstance
(
node
.
op
,
Pool
)
for
node
in
f2
.
maker
.
fgraph
.
toposort
()])
for
node
in
f2
.
maker
.
fgraph
.
toposort
()])
assert
n
umpy
.
allclose
(
f
(),
f2
()),
(
shp
,
ws
,
st
,
pad
,
mode
,
ignore_border
)
assert
n
p
.
allclose
(
f
(),
f2
()),
(
shp
,
ws
,
st
,
pad
,
mode
,
ignore_border
)
a_pooled_grad
=
tensor
.
grad
(
a_pooled
.
sum
(),
a
)
a_pooled_grad
=
tensor
.
grad
(
a_pooled
.
sum
(),
a
)
...
@@ -131,7 +131,7 @@ def test_pool2d():
...
@@ -131,7 +131,7 @@ def test_pool2d():
assert
any
([
isinstance
(
node
.
op
,
gop2
)
assert
any
([
isinstance
(
node
.
op
,
gop2
)
for
node
in
g2
.
maker
.
fgraph
.
toposort
()])
for
node
in
g2
.
maker
.
fgraph
.
toposort
()])
assert
n
umpy
.
allclose
(
g
(),
g2
()),
(
shp
,
ws
,
st
,
pad
,
mode
,
ignore_border
)
assert
n
p
.
allclose
(
g
(),
g2
()),
(
shp
,
ws
,
st
,
pad
,
mode
,
ignore_border
)
# test rop and grad grad for max pooling
# test rop and grad grad for max pooling
# for average pooling grad grad is just average pooling grad
# for average pooling grad grad is just average pooling grad
...
@@ -151,7 +151,7 @@ def test_pool2d():
...
@@ -151,7 +151,7 @@ def test_pool2d():
isinstance
(
node
.
op
,
DownsampleFactorMaxGradGrad
)
isinstance
(
node
.
op
,
DownsampleFactorMaxGradGrad
)
for
node
in
gr2
.
maker
.
fgraph
.
toposort
()
for
node
in
gr2
.
maker
.
fgraph
.
toposort
()
])
])
assert
n
umpy
.
allclose
(
gr
(),
gr2
()),
(
shp
,
ws
,
st
,
pad
,
mode
,
ignore_border
)
assert
n
p
.
allclose
(
gr
(),
gr2
()),
(
shp
,
ws
,
st
,
pad
,
mode
,
ignore_border
)
ggf
=
gradient
.
Lop
(
tensor
.
grad
((
a_pooled
**
2
)
.
sum
(),
a
),
a
,
a
)
ggf
=
gradient
.
Lop
(
tensor
.
grad
((
a_pooled
**
2
)
.
sum
(),
a
),
a
,
a
)
...
@@ -166,7 +166,7 @@ def test_pool2d():
...
@@ -166,7 +166,7 @@ def test_pool2d():
isinstance
(
node
.
op
,
DownsampleFactorMaxGradGrad
)
isinstance
(
node
.
op
,
DownsampleFactorMaxGradGrad
)
for
node
in
gg2
.
maker
.
fgraph
.
toposort
()
for
node
in
gg2
.
maker
.
fgraph
.
toposort
()
])
])
assert
n
umpy
.
allclose
(
gg
(),
gg2
()),
(
shp
,
ws
,
st
,
pad
,
mode
,
ignore_border
)
assert
n
p
.
allclose
(
gg
(),
gg2
()),
(
shp
,
ws
,
st
,
pad
,
mode
,
ignore_border
)
def
test_pool3d
():
def
test_pool3d
():
...
@@ -191,7 +191,7 @@ def test_pool3d():
...
@@ -191,7 +191,7 @@ def test_pool3d():
(
3
,
2
,
6
,
6
,
6
,
5
),
(
3
,
2
,
6
,
6
,
6
,
5
),
(
3
,
2
,
6
,
6
,
6
,
5
,
7
),
]
(
3
,
2
,
6
,
6
,
6
,
5
,
7
),
]
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
.
shuffle
(
shps
)
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
.
shuffle
(
shps
)
test_ws
=
(
2
,
2
,
2
),
(
3
,
2
,
3
),
(
1
,
1
,
1
)
test_ws
=
(
2
,
2
,
2
),
(
3
,
2
,
3
),
(
1
,
1
,
1
)
test_st
=
(
2
,
2
,
2
),
(
2
,
3
,
2
),
(
1
,
1
,
1
)
test_st
=
(
2
,
2
,
2
),
(
2
,
3
,
2
),
(
1
,
1
,
1
)
test_mode
=
[
'max'
,
'sum'
,
'average_inc_pad'
,
'average_exc_pad'
]
test_mode
=
[
'max'
,
'sum'
,
'average_inc_pad'
,
'average_exc_pad'
]
...
@@ -223,7 +223,7 @@ def test_pool3d():
...
@@ -223,7 +223,7 @@ def test_pool3d():
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
assert
any
([
isinstance
(
node
.
op
,
Pool
)
assert
any
([
isinstance
(
node
.
op
,
Pool
)
for
node
in
f2
.
maker
.
fgraph
.
toposort
()])
for
node
in
f2
.
maker
.
fgraph
.
toposort
()])
assert
n
umpy
.
allclose
(
f
(),
f2
()),
(
shp
,
ws
,
st
,
pad
,
mode
,
ignore_border
)
assert
n
p
.
allclose
(
f
(),
f2
()),
(
shp
,
ws
,
st
,
pad
,
mode
,
ignore_border
)
a_pooled_grad
=
tensor
.
grad
(
a_pooled
.
sum
(),
a
)
a_pooled_grad
=
tensor
.
grad
(
a_pooled
.
sum
(),
a
)
...
@@ -241,7 +241,7 @@ def test_pool3d():
...
@@ -241,7 +241,7 @@ def test_pool3d():
assert
any
([
isinstance
(
node
.
op
,
gop2
)
assert
any
([
isinstance
(
node
.
op
,
gop2
)
for
node
in
g2
.
maker
.
fgraph
.
toposort
()])
for
node
in
g2
.
maker
.
fgraph
.
toposort
()])
assert
n
umpy
.
allclose
(
g
(),
g2
()),
(
shp
,
ws
,
st
,
pad
,
mode
,
ignore_border
)
assert
n
p
.
allclose
(
g
(),
g2
()),
(
shp
,
ws
,
st
,
pad
,
mode
,
ignore_border
)
# test rop and grad grad for max pooling
# test rop and grad grad for max pooling
# for average pooling grad grad is just average pooling grad
# for average pooling grad grad is just average pooling grad
...
@@ -261,7 +261,7 @@ def test_pool3d():
...
@@ -261,7 +261,7 @@ def test_pool3d():
isinstance
(
node
.
op
,
DownsampleFactorMaxGradGrad
)
isinstance
(
node
.
op
,
DownsampleFactorMaxGradGrad
)
for
node
in
gr2
.
maker
.
fgraph
.
toposort
()
for
node
in
gr2
.
maker
.
fgraph
.
toposort
()
])
])
assert
n
umpy
.
allclose
(
gr
(),
gr2
()),
(
shp
,
ws
,
st
,
pad
,
mode
,
ignore_border
)
assert
n
p
.
allclose
(
gr
(),
gr2
()),
(
shp
,
ws
,
st
,
pad
,
mode
,
ignore_border
)
ggf
=
gradient
.
Lop
(
tensor
.
grad
((
a_pooled
**
2
)
.
sum
(),
a
),
a
,
a
)
ggf
=
gradient
.
Lop
(
tensor
.
grad
((
a_pooled
**
2
)
.
sum
(),
a
),
a
,
a
)
...
@@ -276,4 +276,4 @@ def test_pool3d():
...
@@ -276,4 +276,4 @@ def test_pool3d():
isinstance
(
node
.
op
,
DownsampleFactorMaxGradGrad
)
isinstance
(
node
.
op
,
DownsampleFactorMaxGradGrad
)
for
node
in
gg2
.
maker
.
fgraph
.
toposort
()
for
node
in
gg2
.
maker
.
fgraph
.
toposort
()
])
])
assert
n
umpy
.
allclose
(
gg
(),
gg2
()),
(
shp
,
ws
,
st
,
pad
,
mode
,
ignore_border
)
assert
n
p
.
allclose
(
gg
(),
gg2
()),
(
shp
,
ws
,
st
,
pad
,
mode
,
ignore_border
)
theano/gpuarray/tests/test_scan.py
浏览文件 @
824cb369
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
from
unittest
import
TestCase
from
unittest
import
TestCase
import
numpy
import
numpy
as
np
from
six.moves
import
xrange
from
six.moves
import
xrange
import
theano
import
theano
...
@@ -43,19 +43,19 @@ class T_Scan(TestCase):
...
@@ -43,19 +43,19 @@ class T_Scan(TestCase):
allow_input_downcast
=
True
,
allow_input_downcast
=
True
,
mode
=
mode
)
mode
=
mode
)
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
v_u
=
rng
.
uniform
(
size
=
(
4
,),
low
=-
5.
,
high
=
5.
)
v_u
=
rng
.
uniform
(
size
=
(
4
,),
low
=-
5.
,
high
=
5.
)
v_x0
=
rng
.
uniform
()
v_x0
=
rng
.
uniform
()
W
=
rng
.
uniform
()
W
=
rng
.
uniform
()
W_in
=
rng
.
uniform
()
W_in
=
rng
.
uniform
()
v_u
=
n
umpy
.
asarray
(
v_u
,
dtype
=
'float32'
)
v_u
=
n
p
.
asarray
(
v_u
,
dtype
=
'float32'
)
v_x0
=
n
umpy
.
asarray
(
v_x0
,
dtype
=
'float32'
)
v_x0
=
n
p
.
asarray
(
v_x0
,
dtype
=
'float32'
)
W
=
n
umpy
.
asarray
(
W
,
dtype
=
'float32'
)
W
=
n
p
.
asarray
(
W
,
dtype
=
'float32'
)
W_in
=
n
umpy
.
asarray
(
W_in
,
dtype
=
'float32'
)
W_in
=
n
p
.
asarray
(
W_in
,
dtype
=
'float32'
)
# compute the output in numpy
# compute the output in numpy
v_out
=
n
umpy
.
zeros
((
4
,))
v_out
=
n
p
.
zeros
((
4
,))
v_out
[
0
]
=
v_u
[
0
]
*
W_in
+
v_x0
*
W
v_out
[
0
]
=
v_u
[
0
]
*
W_in
+
v_x0
*
W
for
step
in
xrange
(
1
,
4
):
for
step
in
xrange
(
1
,
4
):
v_out
[
step
]
=
v_u
[
step
]
*
W_in
+
v_out
[
step
-
1
]
*
W
v_out
[
step
]
=
v_u
[
step
]
*
W_in
+
v_out
[
step
-
1
]
*
W
...
@@ -115,14 +115,14 @@ class T_Scan(TestCase):
...
@@ -115,14 +115,14 @@ class T_Scan(TestCase):
mode
=
mode_with_gpu
)
mode
=
mode_with_gpu
)
# get random initial values
# get random initial values
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
v_u
=
rng
.
uniform
(
size
=
(
4
,),
low
=-
5.
,
high
=
5.
)
v_u
=
rng
.
uniform
(
size
=
(
4
,),
low
=-
5.
,
high
=
5.
)
v_x0
=
rng
.
uniform
()
v_x0
=
rng
.
uniform
()
W
=
rng
.
uniform
()
W
=
rng
.
uniform
()
W_in
=
rng
.
uniform
()
W_in
=
rng
.
uniform
()
# compute the output in numpy
# compute the output in numpy
v_out
=
n
umpy
.
zeros
((
4
,))
v_out
=
n
p
.
zeros
((
4
,))
v_out
[
0
]
=
v_u
[
0
]
*
W_in
+
v_x0
*
W
v_out
[
0
]
=
v_u
[
0
]
*
W_in
+
v_x0
*
W
for
step
in
xrange
(
1
,
4
):
for
step
in
xrange
(
1
,
4
):
v_out
[
step
]
=
v_u
[
step
]
*
W_in
+
v_out
[
step
-
1
]
*
W
v_out
[
step
]
=
v_u
[
step
]
*
W_in
+
v_out
[
step
-
1
]
*
W
...
@@ -177,20 +177,20 @@ class T_Scan(TestCase):
...
@@ -177,20 +177,20 @@ class T_Scan(TestCase):
mode
=
mode_with_gpu
)
mode
=
mode_with_gpu
)
# get random initial values
# get random initial values
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
v_u
=
rng
.
uniform
(
size
=
(
4
,),
low
=-
5.
,
high
=
5.
)
v_u
=
rng
.
uniform
(
size
=
(
4
,),
low
=-
5.
,
high
=
5.
)
v_x0
=
rng
.
uniform
()
v_x0
=
rng
.
uniform
()
W
=
rng
.
uniform
()
W
=
rng
.
uniform
()
W_in
=
rng
.
uniform
()
W_in
=
rng
.
uniform
()
# compute the output in numpy
# compute the output in numpy
v_out1
=
n
umpy
.
zeros
((
4
,))
v_out1
=
n
p
.
zeros
((
4
,))
v_out2
=
n
umpy
.
zeros
((
4
,),
dtype
=
'int64'
)
v_out2
=
n
p
.
zeros
((
4
,),
dtype
=
'int64'
)
v_out1
[
0
]
=
v_u
[
0
]
*
W_in
+
v_x0
*
W
v_out1
[
0
]
=
v_u
[
0
]
*
W_in
+
v_x0
*
W
v_out2
[
0
]
=
v_u
[
0
]
+
v_x0
v_out2
[
0
]
=
v_u
[
0
]
+
v_x0
for
step
in
xrange
(
1
,
4
):
for
step
in
xrange
(
1
,
4
):
v_out1
[
step
]
=
v_u
[
step
]
*
W_in
+
v_out1
[
step
-
1
]
*
W
v_out1
[
step
]
=
v_u
[
step
]
*
W_in
+
v_out1
[
step
-
1
]
*
W
v_out2
[
step
]
=
n
umpy
.
int64
(
v_u
[
step
]
+
v_out1
[
step
-
1
])
v_out2
[
step
]
=
n
p
.
int64
(
v_u
[
step
]
+
v_out1
[
step
-
1
])
theano_out1
,
theano_out2
=
f2
(
v_u
,
v_x0
,
W_in
,
W
)
theano_out1
,
theano_out2
=
f2
(
v_u
,
v_x0
,
W_in
,
W
)
utt
.
assert_allclose
(
theano_out1
,
v_out1
)
utt
.
assert_allclose
(
theano_out1
,
v_out1
)
...
@@ -212,8 +212,8 @@ class T_Scan(TestCase):
...
@@ -212,8 +212,8 @@ class T_Scan(TestCase):
for
node
in
scan_node_topo
])
for
node
in
scan_node_topo
])
def
test_gpu4_gibbs_chain
(
self
):
def
test_gpu4_gibbs_chain
(
self
):
rng
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
v_vsample
=
n
umpy
.
array
(
rng
.
binomial
(
1
,
.
5
,
size
=
(
3
,
20
),),
v_vsample
=
n
p
.
array
(
rng
.
binomial
(
1
,
.
5
,
size
=
(
3
,
20
),),
dtype
=
'float32'
)
dtype
=
'float32'
)
vsample
=
theano
.
shared
(
v_vsample
)
vsample
=
theano
.
shared
(
v_vsample
)
trng
=
theano
.
sandbox
.
rng_mrg
.
MRG_RandomStreams
(
trng
=
theano
.
sandbox
.
rng_mrg
.
MRG_RandomStreams
(
...
...
theano/gpuarray/tests/test_subtensor.py
浏览文件 @
824cb369
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
numpy
import
numpy
as
np
import
unittest
import
unittest
import
theano
import
theano
...
@@ -47,8 +47,8 @@ def test_advinc_subtensor1():
...
@@ -47,8 +47,8 @@ def test_advinc_subtensor1():
# Test the second case in the opt local_gpu_advanced_incsubtensor1
# Test the second case in the opt local_gpu_advanced_incsubtensor1
for
shp
in
[(
3
,
3
),
(
3
,
3
,
3
)]:
for
shp
in
[(
3
,
3
),
(
3
,
3
,
3
)]:
shared
=
gpuarray_shared_constructor
shared
=
gpuarray_shared_constructor
xval
=
n
umpy
.
arange
(
numpy
.
prod
(
shp
),
dtype
=
'float32'
)
.
reshape
(
shp
)
+
1
xval
=
n
p
.
arange
(
np
.
prod
(
shp
),
dtype
=
'float32'
)
.
reshape
(
shp
)
+
1
yval
=
n
umpy
.
empty
((
2
,)
+
shp
[
1
:],
dtype
=
'float32'
)
yval
=
n
p
.
empty
((
2
,)
+
shp
[
1
:],
dtype
=
'float32'
)
yval
[:]
=
10
yval
[:]
=
10
x
=
shared
(
xval
,
name
=
'x'
)
x
=
shared
(
xval
,
name
=
'x'
)
y
=
tensor
.
tensor
(
dtype
=
'float32'
,
y
=
tensor
.
tensor
(
dtype
=
'float32'
,
...
@@ -61,7 +61,7 @@ def test_advinc_subtensor1():
...
@@ -61,7 +61,7 @@ def test_advinc_subtensor1():
rval
=
f
(
yval
)
rval
=
f
(
yval
)
rep
=
xval
.
copy
()
rep
=
xval
.
copy
()
rep
[[
0
,
2
]]
+=
yval
rep
[[
0
,
2
]]
+=
yval
assert
n
umpy
.
allclose
(
rval
,
rep
)
assert
n
p
.
allclose
(
rval
,
rep
)
def
test_advinc_subtensor1_dtype
():
def
test_advinc_subtensor1_dtype
():
...
@@ -69,8 +69,8 @@ def test_advinc_subtensor1_dtype():
...
@@ -69,8 +69,8 @@ def test_advinc_subtensor1_dtype():
shp
=
(
3
,
4
)
shp
=
(
3
,
4
)
for
dtype1
,
dtype2
in
[(
'float32'
,
'int8'
),
(
'float32'
,
'float64'
)]:
for
dtype1
,
dtype2
in
[(
'float32'
,
'int8'
),
(
'float32'
,
'float64'
)]:
shared
=
gpuarray_shared_constructor
shared
=
gpuarray_shared_constructor
xval
=
n
umpy
.
arange
(
numpy
.
prod
(
shp
),
dtype
=
dtype1
)
.
reshape
(
shp
)
+
1
xval
=
n
p
.
arange
(
np
.
prod
(
shp
),
dtype
=
dtype1
)
.
reshape
(
shp
)
+
1
yval
=
n
umpy
.
empty
((
2
,)
+
shp
[
1
:],
dtype
=
dtype2
)
yval
=
n
p
.
empty
((
2
,)
+
shp
[
1
:],
dtype
=
dtype2
)
yval
[:]
=
10
yval
[:]
=
10
x
=
shared
(
xval
,
name
=
'x'
)
x
=
shared
(
xval
,
name
=
'x'
)
y
=
tensor
.
tensor
(
dtype
=
yval
.
dtype
,
y
=
tensor
.
tensor
(
dtype
=
yval
.
dtype
,
...
@@ -83,7 +83,7 @@ def test_advinc_subtensor1_dtype():
...
@@ -83,7 +83,7 @@ def test_advinc_subtensor1_dtype():
rval
=
f
(
yval
)
rval
=
f
(
yval
)
rep
=
xval
.
copy
()
rep
=
xval
.
copy
()
rep
[[
0
,
2
]]
+=
yval
rep
[[
0
,
2
]]
+=
yval
assert
n
umpy
.
allclose
(
rval
,
rep
)
assert
n
p
.
allclose
(
rval
,
rep
)
def
test_advinc_subtensor1_vector_scalar
():
def
test_advinc_subtensor1_vector_scalar
():
...
@@ -91,8 +91,8 @@ def test_advinc_subtensor1_vector_scalar():
...
@@ -91,8 +91,8 @@ def test_advinc_subtensor1_vector_scalar():
shp
=
(
3
,)
shp
=
(
3
,)
for
dtype1
,
dtype2
in
[(
'float32'
,
'int8'
),
(
'float32'
,
'float64'
)]:
for
dtype1
,
dtype2
in
[(
'float32'
,
'int8'
),
(
'float32'
,
'float64'
)]:
shared
=
gpuarray_shared_constructor
shared
=
gpuarray_shared_constructor
xval
=
n
umpy
.
arange
(
numpy
.
prod
(
shp
),
dtype
=
dtype1
)
.
reshape
(
shp
)
+
1
xval
=
n
p
.
arange
(
np
.
prod
(
shp
),
dtype
=
dtype1
)
.
reshape
(
shp
)
+
1
yval
=
n
umpy
.
asarray
(
10
,
dtype
=
dtype2
)
yval
=
n
p
.
asarray
(
10
,
dtype
=
dtype2
)
x
=
shared
(
xval
,
name
=
'x'
)
x
=
shared
(
xval
,
name
=
'x'
)
y
=
tensor
.
tensor
(
dtype
=
yval
.
dtype
,
y
=
tensor
.
tensor
(
dtype
=
yval
.
dtype
,
broadcastable
=
(
False
,)
*
len
(
yval
.
shape
),
broadcastable
=
(
False
,)
*
len
(
yval
.
shape
),
...
@@ -104,14 +104,14 @@ def test_advinc_subtensor1_vector_scalar():
...
@@ -104,14 +104,14 @@ def test_advinc_subtensor1_vector_scalar():
rval
=
f
(
yval
)
rval
=
f
(
yval
)
rep
=
xval
.
copy
()
rep
=
xval
.
copy
()
rep
[[
0
,
2
]]
+=
yval
rep
[[
0
,
2
]]
+=
yval
assert
n
umpy
.
allclose
(
rval
,
rep
)
assert
n
p
.
allclose
(
rval
,
rep
)
def
test_incsub_f16
():
def
test_incsub_f16
():
shp
=
(
3
,
3
)
shp
=
(
3
,
3
)
shared
=
gpuarray_shared_constructor
shared
=
gpuarray_shared_constructor
xval
=
n
umpy
.
arange
(
numpy
.
prod
(
shp
),
dtype
=
'float16'
)
.
reshape
(
shp
)
+
1
xval
=
n
p
.
arange
(
np
.
prod
(
shp
),
dtype
=
'float16'
)
.
reshape
(
shp
)
+
1
yval
=
n
umpy
.
empty
((
2
,)
+
shp
[
1
:],
dtype
=
'float16'
)
yval
=
n
p
.
empty
((
2
,)
+
shp
[
1
:],
dtype
=
'float16'
)
yval
[:]
=
2
yval
[:]
=
2
x
=
shared
(
xval
,
name
=
'x'
)
x
=
shared
(
xval
,
name
=
'x'
)
y
=
tensor
.
tensor
(
dtype
=
'float16'
,
y
=
tensor
.
tensor
(
dtype
=
'float16'
,
...
@@ -124,7 +124,7 @@ def test_incsub_f16():
...
@@ -124,7 +124,7 @@ def test_incsub_f16():
rval
=
f
(
yval
)
rval
=
f
(
yval
)
rep
=
xval
.
copy
()
rep
=
xval
.
copy
()
rep
[[
0
,
2
]]
+=
yval
rep
[[
0
,
2
]]
+=
yval
assert
n
umpy
.
allclose
(
rval
,
rep
)
assert
n
p
.
allclose
(
rval
,
rep
)
expr
=
tensor
.
inc_subtensor
(
x
[
1
:],
y
)
expr
=
tensor
.
inc_subtensor
(
x
[
1
:],
y
)
f
=
theano
.
function
([
y
],
expr
,
mode
=
mode_with_gpu
)
f
=
theano
.
function
([
y
],
expr
,
mode
=
mode_with_gpu
)
...
@@ -133,7 +133,7 @@ def test_incsub_f16():
...
@@ -133,7 +133,7 @@ def test_incsub_f16():
rval
=
f
(
yval
)
rval
=
f
(
yval
)
rep
=
xval
.
copy
()
rep
=
xval
.
copy
()
rep
[
1
:]
+=
yval
rep
[
1
:]
+=
yval
assert
n
umpy
.
allclose
(
rval
,
rep
)
assert
n
p
.
allclose
(
rval
,
rep
)
class
G_advancedsubtensor
(
test_subtensor
.
TestAdvancedSubtensor
):
class
G_advancedsubtensor
(
test_subtensor
.
TestAdvancedSubtensor
):
...
@@ -159,7 +159,7 @@ def test_adv_subtensor():
...
@@ -159,7 +159,7 @@ def test_adv_subtensor():
# Test the advancedsubtensor on gpu.
# Test the advancedsubtensor on gpu.
shp
=
(
2
,
3
,
4
)
shp
=
(
2
,
3
,
4
)
shared
=
gpuarray_shared_constructor
shared
=
gpuarray_shared_constructor
xval
=
n
umpy
.
arange
(
numpy
.
prod
(
shp
),
dtype
=
theano
.
config
.
floatX
)
.
reshape
(
shp
)
xval
=
n
p
.
arange
(
np
.
prod
(
shp
),
dtype
=
theano
.
config
.
floatX
)
.
reshape
(
shp
)
idx1
,
idx2
=
tensor
.
ivectors
(
'idx1'
,
'idx2'
)
idx1
,
idx2
=
tensor
.
ivectors
(
'idx1'
,
'idx2'
)
idxs
=
[
idx1
,
None
,
slice
(
0
,
2
,
1
),
idx2
,
None
]
idxs
=
[
idx1
,
None
,
slice
(
0
,
2
,
1
),
idx2
,
None
]
x
=
shared
(
xval
,
name
=
'x'
)
x
=
shared
(
xval
,
name
=
'x'
)
...
@@ -171,27 +171,27 @@ def test_adv_subtensor():
...
@@ -171,27 +171,27 @@ def test_adv_subtensor():
idx2_val
=
[
0
,
1
]
idx2_val
=
[
0
,
1
]
rval
=
f
(
idx1_val
,
idx2_val
)
rval
=
f
(
idx1_val
,
idx2_val
)
rep
=
xval
[
idx1_val
,
None
,
slice
(
0
,
2
,
1
),
idx2_val
,
None
]
rep
=
xval
[
idx1_val
,
None
,
slice
(
0
,
2
,
1
),
idx2_val
,
None
]
assert
n
umpy
.
allclose
(
rval
,
rep
)
assert
n
p
.
allclose
(
rval
,
rep
)
class
test_gpudiagonal
(
unittest
.
TestCase
):
class
test_gpudiagonal
(
unittest
.
TestCase
):
def
test_matrix
(
self
):
def
test_matrix
(
self
):
x
=
tensor
.
matrix
()
x
=
tensor
.
matrix
()
np_x
=
n
umpy
.
arange
(
77
)
.
reshape
(
7
,
11
)
.
astype
(
theano
.
config
.
floatX
)
np_x
=
n
p
.
arange
(
77
)
.
reshape
(
7
,
11
)
.
astype
(
theano
.
config
.
floatX
)
fn
=
theano
.
function
([
x
],
GpuDiagonal
()(
x
),
mode
=
mode_with_gpu
)
fn
=
theano
.
function
([
x
],
GpuDiagonal
()(
x
),
mode
=
mode_with_gpu
)
assert
n
umpy
.
allclose
(
fn
(
np_x
),
np_x
.
diagonal
())
assert
n
p
.
allclose
(
fn
(
np_x
),
np_x
.
diagonal
())
fn
=
theano
.
function
([
x
],
GpuDiagonal
(
2
)(
x
),
mode
=
mode_with_gpu
)
fn
=
theano
.
function
([
x
],
GpuDiagonal
(
2
)(
x
),
mode
=
mode_with_gpu
)
assert
n
umpy
.
allclose
(
fn
(
np_x
),
np_x
.
diagonal
(
2
))
assert
n
p
.
allclose
(
fn
(
np_x
),
np_x
.
diagonal
(
2
))
fn
=
theano
.
function
([
x
],
GpuDiagonal
(
-
3
)(
x
),
mode
=
mode_with_gpu
)
fn
=
theano
.
function
([
x
],
GpuDiagonal
(
-
3
)(
x
),
mode
=
mode_with_gpu
)
assert
n
umpy
.
allclose
(
fn
(
np_x
),
np_x
.
diagonal
(
-
3
))
assert
n
p
.
allclose
(
fn
(
np_x
),
np_x
.
diagonal
(
-
3
))
def
test_tensor
(
self
):
def
test_tensor
(
self
):
x
=
tensor
.
tensor4
()
x
=
tensor
.
tensor4
()
np_x
=
n
umpy
.
arange
(
30107
)
.
reshape
(
7
,
11
,
17
,
23
)
.
astype
(
theano
.
config
.
floatX
)
np_x
=
n
p
.
arange
(
30107
)
.
reshape
(
7
,
11
,
17
,
23
)
.
astype
(
theano
.
config
.
floatX
)
for
offset
,
axis1
,
axis2
in
[
for
offset
,
axis1
,
axis2
in
[
(
1
,
0
,
1
),
(
-
1
,
0
,
1
),
(
0
,
1
,
0
),
(
-
2
,
1
,
0
),
(
1
,
0
,
1
),
(
-
1
,
0
,
1
),
(
0
,
1
,
0
),
(
-
2
,
1
,
0
),
(
-
3
,
1
,
0
),
(
-
2
,
2
,
0
),
(
3
,
3
,
0
),
(
-
1
,
3
,
2
),
(
-
3
,
1
,
0
),
(
-
2
,
2
,
0
),
(
3
,
3
,
0
),
(
-
1
,
3
,
2
),
(
2
,
2
,
3
),
(
-
1
,
2
,
1
),
(
1
,
3
,
1
),
(
-
1
,
1
,
3
)]:
(
2
,
2
,
3
),
(
-
1
,
2
,
1
),
(
1
,
3
,
1
),
(
-
1
,
1
,
3
)]:
assert
n
umpy
.
allclose
(
assert
n
p
.
allclose
(
GpuDiagonal
(
offset
,
axis1
,
axis2
)(
x
)
.
eval
({
x
:
np_x
}),
GpuDiagonal
(
offset
,
axis1
,
axis2
)(
x
)
.
eval
({
x
:
np_x
}),
np_x
.
diagonal
(
offset
,
axis1
,
axis2
))
np_x
.
diagonal
(
offset
,
axis1
,
axis2
))
theano/gpuarray/tests/test_type.py
浏览文件 @
824cb369
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
os
import
os
import
numpy
import
numpy
as
np
import
theano
import
theano
from
theano.compat
import
PY3
from
theano.compat
import
PY3
...
@@ -33,10 +33,10 @@ def test_values_eq_approx():
...
@@ -33,10 +33,10 @@ def test_values_eq_approx():
a
=
rand_gpuarray
(
20
,
dtype
=
'float32'
)
a
=
rand_gpuarray
(
20
,
dtype
=
'float32'
)
assert
GpuArrayType
.
values_eq_approx
(
a
,
a
)
assert
GpuArrayType
.
values_eq_approx
(
a
,
a
)
b
=
a
.
copy
()
b
=
a
.
copy
()
b
[
0
]
=
n
umpy
.
asarray
(
b
[
0
])
+
1.
b
[
0
]
=
n
p
.
asarray
(
b
[
0
])
+
1.
assert
not
GpuArrayType
.
values_eq_approx
(
a
,
b
)
assert
not
GpuArrayType
.
values_eq_approx
(
a
,
b
)
b
=
a
.
copy
()
b
=
a
.
copy
()
b
[
0
]
=
-
n
umpy
.
asarray
(
b
[
0
])
b
[
0
]
=
-
n
p
.
asarray
(
b
[
0
])
assert
not
GpuArrayType
.
values_eq_approx
(
a
,
b
)
assert
not
GpuArrayType
.
values_eq_approx
(
a
,
b
)
...
@@ -50,7 +50,7 @@ def test_specify_shape():
...
@@ -50,7 +50,7 @@ def test_specify_shape():
def
test_filter_float
():
def
test_filter_float
():
theano
.
compile
.
shared_constructor
(
gpuarray_shared_constructor
)
theano
.
compile
.
shared_constructor
(
gpuarray_shared_constructor
)
try
:
try
:
s
=
theano
.
shared
(
n
umpy
.
array
(
0.0
,
dtype
=
'float32'
),
s
=
theano
.
shared
(
n
p
.
array
(
0.0
,
dtype
=
'float32'
),
target
=
test_ctx_name
)
target
=
test_ctx_name
)
theano
.
function
([],
updates
=
[(
s
,
0.0
)])
theano
.
function
([],
updates
=
[(
s
,
0.0
)])
finally
:
finally
:
...
@@ -73,6 +73,6 @@ def test_unpickle_gpuarray_as_numpy_ndarray_flag0():
...
@@ -73,6 +73,6 @@ def test_unpickle_gpuarray_as_numpy_ndarray_flag0():
u
=
CompatUnpickler
(
fp
)
u
=
CompatUnpickler
(
fp
)
mat
=
u
.
load
()
mat
=
u
.
load
()
assert
isinstance
(
mat
,
pygpu
.
gpuarray
.
GpuArray
)
assert
isinstance
(
mat
,
pygpu
.
gpuarray
.
GpuArray
)
assert
n
umpy
.
asarray
(
mat
)[
0
]
==
-
42.0
assert
n
p
.
asarray
(
mat
)[
0
]
==
-
42.0
finally
:
finally
:
config
.
experimental
.
unpickle_gpu_on_cpu
=
oldflag
config
.
experimental
.
unpickle_gpu_on_cpu
=
oldflag
theano/gpuarray/type.py
浏览文件 @
824cb369
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
numpy
import
numpy
as
np
import
six.moves.copyreg
as
copyreg
import
six.moves.copyreg
as
copyreg
from
six
import
iteritems
from
six
import
iteritems
import
warnings
import
warnings
...
@@ -226,7 +226,7 @@ class GpuArrayType(Type):
...
@@ -226,7 +226,7 @@ class GpuArrayType(Type):
converted_data
=
theano
.
_asarray
(
data
,
self
.
dtype
)
converted_data
=
theano
.
_asarray
(
data
,
self
.
dtype
)
# We use the `values_eq` static function from TensorType
# We use the `values_eq` static function from TensorType
# to handle NaN values.
# to handle NaN values.
if
TensorType
.
values_eq
(
n
umpy
.
asarray
(
data
),
if
TensorType
.
values_eq
(
n
p
.
asarray
(
data
),
converted_data
,
converted_data
,
force_same_dtype
=
False
):
force_same_dtype
=
False
):
data
=
converted_data
data
=
converted_data
...
@@ -293,18 +293,18 @@ class GpuArrayType(Type):
...
@@ -293,18 +293,18 @@ class GpuArrayType(Type):
return
False
return
False
if
force_same_dtype
and
a
.
typecode
!=
b
.
typecode
:
if
force_same_dtype
and
a
.
typecode
!=
b
.
typecode
:
return
False
return
False
a_eq_b
=
n
umpy
.
asarray
(
compare
(
a
,
'=='
,
b
))
a_eq_b
=
n
p
.
asarray
(
compare
(
a
,
'=='
,
b
))
if
a_eq_b
.
all
():
if
a_eq_b
.
all
():
return
True
return
True
# maybe the trouble is that there are NaNs
# maybe the trouble is that there are NaNs
a
=
n
umpy
.
asarray
(
a
)
a
=
n
p
.
asarray
(
a
)
b
=
n
umpy
.
asarray
(
b
)
b
=
n
p
.
asarray
(
b
)
a_missing
=
n
umpy
.
isnan
(
a
)
a_missing
=
n
p
.
isnan
(
a
)
if
a_missing
.
any
():
if
a_missing
.
any
():
b_missing
=
n
umpy
.
isnan
(
b
)
b_missing
=
n
p
.
isnan
(
b
)
return
n
umpy
.
all
(
a_eq_b
+
(
a_missing
==
b_missing
))
return
n
p
.
all
(
a_eq_b
+
(
a_missing
==
b_missing
))
else
:
else
:
return
False
return
False
...
@@ -326,16 +326,16 @@ class GpuArrayType(Type):
...
@@ -326,16 +326,16 @@ class GpuArrayType(Type):
rtol_
=
rtol
rtol_
=
rtol
if
atol
is
not
None
:
if
atol
is
not
None
:
atol_
=
atol
atol_
=
atol
res
=
elemwise2
(
a
,
''
,
b
,
a
,
odtype
=
n
umpy
.
dtype
(
'bool'
),
res
=
elemwise2
(
a
,
''
,
b
,
a
,
odtype
=
n
p
.
dtype
(
'bool'
),
op_tmpl
=
"res = (fabs(a - b) <"
op_tmpl
=
"res = (fabs(a - b) <"
"(
%(atol_)
s +
%(rtol_)
s * fabs(b)))"
%
"(
%(atol_)
s +
%(rtol_)
s * fabs(b)))"
%
locals
())
locals
())
ret
=
n
umpy
.
asarray
(
res
)
.
all
()
ret
=
n
p
.
asarray
(
res
)
.
all
()
if
ret
:
if
ret
:
return
True
return
True
# maybe the trouble is that there are NaNs
# maybe the trouble is that there are NaNs
an
=
n
umpy
.
asarray
(
a
)
an
=
n
p
.
asarray
(
a
)
bn
=
n
umpy
.
asarray
(
b
)
bn
=
n
p
.
asarray
(
b
)
return
tensor
.
TensorType
.
values_eq_approx
(
return
tensor
.
TensorType
.
values_eq_approx
(
an
,
bn
,
allow_remove_inf
=
allow_remove_inf
,
an
,
bn
,
allow_remove_inf
=
allow_remove_inf
,
allow_remove_nan
=
allow_remove_nan
,
rtol
=
rtol
,
atol
=
atol
)
allow_remove_nan
=
allow_remove_nan
,
rtol
=
rtol
,
atol
=
atol
)
...
@@ -408,9 +408,9 @@ class GpuArrayType(Type):
...
@@ -408,9 +408,9 @@ class GpuArrayType(Type):
def
get_size
(
self
,
shape_info
):
def
get_size
(
self
,
shape_info
):
if
shape_info
:
if
shape_info
:
return
n
umpy
.
prod
(
shape_info
)
*
numpy
.
dtype
(
self
.
dtype
)
.
itemsize
return
n
p
.
prod
(
shape_info
)
*
np
.
dtype
(
self
.
dtype
)
.
itemsize
else
:
else
:
return
n
umpy
.
dtype
(
self
.
dtype
)
.
itemsize
return
n
p
.
dtype
(
self
.
dtype
)
.
itemsize
def
c_declare
(
self
,
name
,
sub
,
check_input
=
True
):
def
c_declare
(
self
,
name
,
sub
,
check_input
=
True
):
return
"""
return
"""
...
@@ -470,7 +470,7 @@ class GpuArrayType(Type):
...
@@ -470,7 +470,7 @@ class GpuArrayType(Type):
'<gpuarray_api.h>'
]
'<gpuarray_api.h>'
]
def
c_header_dirs
(
self
):
def
c_header_dirs
(
self
):
return
[
pygpu
.
get_include
(),
n
umpy
.
get_include
()]
return
[
pygpu
.
get_include
(),
n
p
.
get_include
()]
def
c_libraries
(
self
):
def
c_libraries
(
self
):
return
[
'gpuarray'
]
return
[
'gpuarray'
]
...
@@ -509,7 +509,7 @@ class GpuArrayVariable(_operators, Variable):
...
@@ -509,7 +509,7 @@ class GpuArrayVariable(_operators, Variable):
# override the default
# override the default
def
__repr_test_value__
(
self
):
def
__repr_test_value__
(
self
):
return
repr
(
n
umpy
.
array
(
theano
.
gof
.
op
.
get_test_value
(
self
)))
return
repr
(
n
p
.
array
(
theano
.
gof
.
op
.
get_test_value
(
self
)))
GpuArrayType
.
Variable
=
GpuArrayVariable
GpuArrayType
.
Variable
=
GpuArrayVariable
...
@@ -534,13 +534,13 @@ class GpuArrayConstant(_operators, Constant):
...
@@ -534,13 +534,13 @@ class GpuArrayConstant(_operators, Constant):
"""
"""
def
signature
(
self
):
def
signature
(
self
):
return
GpuArraySignature
((
self
.
type
,
n
umpy
.
asarray
(
self
.
data
)))
return
GpuArraySignature
((
self
.
type
,
n
p
.
asarray
(
self
.
data
)))
def
__str__
(
self
):
def
__str__
(
self
):
if
self
.
name
is
not
None
:
if
self
.
name
is
not
None
:
return
self
.
name
return
self
.
name
try
:
try
:
np_data
=
n
umpy
.
asarray
(
self
.
data
)
np_data
=
n
p
.
asarray
(
self
.
data
)
except
gpuarray
.
GpuArrayException
:
except
gpuarray
.
GpuArrayException
:
np_data
=
self
.
data
np_data
=
self
.
data
return
"GpuArrayConstant{
%
s}"
%
np_data
return
"GpuArrayConstant{
%
s}"
%
np_data
...
@@ -568,7 +568,7 @@ class GpuArraySharedVariable(_operators, SharedVariable):
...
@@ -568,7 +568,7 @@ class GpuArraySharedVariable(_operators, SharedVariable):
else
:
else
:
return
self
.
container
.
value
.
copy
()
return
self
.
container
.
value
.
copy
()
else
:
else
:
return
n
umpy
.
asarray
(
self
.
container
.
value
)
return
n
p
.
asarray
(
self
.
container
.
value
)
def
set_value
(
self
,
value
,
borrow
=
False
):
def
set_value
(
self
,
value
,
borrow
=
False
):
if
isinstance
(
value
,
pygpu
.
gpuarray
.
GpuArray
):
if
isinstance
(
value
,
pygpu
.
gpuarray
.
GpuArray
):
...
@@ -601,7 +601,7 @@ def gpuarray_shared_constructor(value, name=None, strict=False,
...
@@ -601,7 +601,7 @@ def gpuarray_shared_constructor(value, name=None, strict=False,
if
target
==
'gpu'
or
target
==
'cpu'
:
if
target
==
'gpu'
or
target
==
'cpu'
:
raise
TypeError
(
'not for me'
)
raise
TypeError
(
'not for me'
)
if
not
isinstance
(
value
,
(
n
umpy
.
ndarray
,
pygpu
.
gpuarray
.
GpuArray
)):
if
not
isinstance
(
value
,
(
n
p
.
ndarray
,
pygpu
.
gpuarray
.
GpuArray
)):
raise
TypeError
(
'ndarray or GpuArray required'
)
raise
TypeError
(
'ndarray or GpuArray required'
)
if
target
is
notset
:
if
target
is
notset
:
...
@@ -809,7 +809,7 @@ copyreg.constructor(GpuArray_unpickler)
...
@@ -809,7 +809,7 @@ copyreg.constructor(GpuArray_unpickler)
def
GpuArray_pickler
(
cnda
):
def
GpuArray_pickler
(
cnda
):
ctx_name
=
_name_for_ctx
(
cnda
.
context
)
ctx_name
=
_name_for_ctx
(
cnda
.
context
)
return
(
GpuArray_unpickler
,
(
n
umpy
.
asarray
(
cnda
),
ctx_name
))
return
(
GpuArray_unpickler
,
(
n
p
.
asarray
(
cnda
),
ctx_name
))
# In case pygpu is not imported.
# In case pygpu is not imported.
if
pygpu
is
not
None
:
if
pygpu
is
not
None
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论