Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1f34a482
提交
1f34a482
authored
3月 29, 2017
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove tentacles in tensor.
上级
1b22389f
全部展开
显示空白字符变更
内嵌
并排
正在显示
14 个修改的文件
包含
74 行增加
和
157 行删除
+74
-157
test_others.py
theano/gpuarray/tests/test_others.py
+9
-3
test_type.py
theano/gpuarray/tests/test_type.py
+40
-0
basic.py
theano/tensor/basic.py
+0
-16
blas.py
theano/tensor/blas.py
+1
-1
elemwise.py
theano/tensor/elemwise.py
+0
-1
Conv3D.py
theano/tensor/nnet/Conv3D.py
+1
-4
conv.py
theano/tensor/nnet/conv.py
+0
-5
conv3d2d.py
theano/tensor/nnet/conv3d2d.py
+2
-65
test_conv3d2d.py
theano/tensor/nnet/tests/test_conv3d2d.py
+6
-22
subtensor.py
theano/tensor/subtensor.py
+2
-2
shape_opt_cycle.pkl
theano/tensor/tests/shape_opt_cycle.pkl
+0
-0
test_opt.py
theano/tensor/tests/test_opt.py
+0
-0
test_sharedvar.py
theano/tensor/tests/test_sharedvar.py
+10
-34
type.py
theano/tensor/type.py
+3
-4
没有找到文件。
theano/gpuarray/tests/test_others.py
浏览文件 @
1f34a482
from
.config
import
test_ctx_name
from
.config
import
test_ctx_name
,
mode_with_gpu
from
..type
import
get_context
,
GpuArrayType
,
GpuArraySharedVariable
from
..type
import
(
get_context
,
GpuArrayType
,
GpuArraySharedVariable
,
gpuarray_shared_constructor
)
import
pygpu
import
pygpu
import
numpy
as
np
import
numpy
as
np
from
theano.misc.tests.test_may_share_memory
import
may_share_memory_core
from
theano.misc.tests.test_may_share_memory
import
may_share_memory_core
from
theano.misc.pkl_utils
import
dump
,
load
from
theano.misc.pkl_utils
import
dump
,
load
from
theano.tensor.tests.test_opt
import
test_fusion
as
t_fusion
class
test_fusion
(
t_fusion
):
mode
=
mode_with_gpu
shared
=
gpuarray_shared_constructor
def
test_may_share_memory
():
def
test_may_share_memory
():
ctx
=
get_context
(
test_ctx_name
)
ctx
=
get_context
(
test_ctx_name
)
...
...
theano/gpuarray/tests/test_type.py
浏览文件 @
1f34a482
...
@@ -9,6 +9,8 @@ from theano import config
...
@@ -9,6 +9,8 @@ from theano import config
from
theano.compile
import
DeepCopyOp
from
theano.compile
import
DeepCopyOp
from
theano.misc.pkl_utils
import
CompatUnpickler
from
theano.misc.pkl_utils
import
CompatUnpickler
from
theano.tensor.tests.test_sharedvar
import
makeSharedTester
from
.config
import
test_ctx_name
from
.config
import
test_ctx_name
from
.test_basic_ops
import
rand_gpuarray
from
.test_basic_ops
import
rand_gpuarray
from
..type
import
GpuArrayType
,
gpuarray_shared_constructor
from
..type
import
GpuArrayType
,
gpuarray_shared_constructor
...
@@ -76,3 +78,41 @@ def test_unpickle_gpuarray_as_numpy_ndarray_flag0():
...
@@ -76,3 +78,41 @@ def test_unpickle_gpuarray_as_numpy_ndarray_flag0():
assert
np
.
asarray
(
mat
)[
0
]
==
-
42.0
assert
np
.
asarray
(
mat
)[
0
]
==
-
42.0
finally
:
finally
:
config
.
experimental
.
unpickle_gpu_on_cpu
=
oldflag
config
.
experimental
.
unpickle_gpu_on_cpu
=
oldflag
test_shared_options
=
makeSharedTester
(
shared_constructor_
=
gpuarray_shared_constructor
,
dtype_
=
theano
.
config
.
floatX
,
get_value_borrow_true_alias_
=
True
,
shared_borrow_true_alias_
=
True
,
set_value_borrow_true_alias_
=
True
,
set_value_inplace_
=
True
,
set_cast_value_inplace_
=
False
,
shared_constructor_accept_ndarray_
=
True
,
internal_type_
=
lambda
v
:
pygpu
.
array
(
v
,
context
=
get_context
(
test_ctx_name
),
cls
=
pygpu
.
_array
.
ndgpuarray
),
test_internal_type_
=
lambda
a
:
isinstance
(
a
,
pygpu
.
gpuarray
.
GpuArray
),
theano_fct_
=
theano
.
tensor
.
exp
,
ref_fct_
=
numpy
.
exp
,
cast_value_
=
lambda
v
:
pygpu
.
asarray
(
v
,
context
=
get_context
(
test_ctx_name
),
cls
=
pygpu
.
_array
.
ndgpuarray
),
name
=
'test_shared_options'
)
test_shared_options2
=
makeSharedTester
(
shared_constructor_
=
gpuarray_shared_constructor
dtype_
=
theano
.
config
.
floatX
,
get_value_borrow_true_alias_
=
False
,
shared_borrow_true_alias_
=
False
,
set_value_borrow_true_alias_
=
False
,
set_value_inplace_
=
True
,
set_cast_value_inplace_
=
True
,
shared_constructor_accept_ndarray_
=
True
,
internal_type_
=
lambda
v
:
pygpu
.
array
(
v
,
context
=
get_context
(
test_ctx_name
),
cls
=
pygpu
.
_array
.
ndgpuarray
),
test_internal_type_
=
lambda
a
:
isinstance
(
a
,
pygpu
.
gpuarray
.
GpuArray
),
theano_fct_
=
theano
.
tensor
.
exp
,
ref_fct_
=
numpy
.
exp
,
cast_value_
=
lambda
v
:
pygpu
.
asarray
(
v
,
context
=
get_context
(
test_ctx_name
),
cls
=
pygpu
.
_array
.
ndgpuarray
),
name
=
'test_shared_options2'
)
theano/tensor/basic.py
浏览文件 @
1f34a482
...
@@ -107,22 +107,6 @@ def __oplist_tag(thing, tag):
...
@@ -107,22 +107,6 @@ def __oplist_tag(thing, tag):
thing
.
__oplist_tags
=
tags
thing
.
__oplist_tags
=
tags
if
0
:
# this starts to feel like we're enumerating all the types
# the one place where this is used we should also allow for sparse
# variables
# - JB 20100226
def
as_cuda_or_tensor_variable
(
x
,
name
=
None
,
ndim
=
None
):
"""
Do the same as_tensor_variable,
but do not transfer the value on the gpu.
"""
if
hasattr
(
x
,
'_as_CudaNdarrayVariable'
):
# TODO: pass name and ndim arguments
return
x
.
_as_CudaNdarrayVariable
()
return
as_tensor_variable
(
x
,
name
,
ndim
)
def
as_tensor_variable
(
x
,
name
=
None
,
ndim
=
None
):
def
as_tensor_variable
(
x
,
name
=
None
,
ndim
=
None
):
"""Return `x`, transformed into a `TensorType`.
"""Return `x`, transformed into a `TensorType`.
...
...
theano/tensor/blas.py
浏览文件 @
1f34a482
...
@@ -15,7 +15,7 @@ There are four kinds of BLAS Ops in Theano:
...
@@ -15,7 +15,7 @@ There are four kinds of BLAS Ops in Theano:
- Python implementations (this file)
- Python implementations (this file)
- SciPy-based (blas_scipy)
- SciPy-based (blas_scipy)
- C-based (blas_c)
- C-based (blas_c)
-
CUDA-based (theano.sandbox.cuda.blas
)
-
GPU-based (theano.gpuarray
)
Notes
Notes
-----
-----
...
...
theano/tensor/elemwise.py
浏览文件 @
1f34a482
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
sys
from
copy
import
copy
from
copy
import
copy
import
numpy
as
np
import
numpy
as
np
...
...
theano/tensor/nnet/Conv3D.py
浏览文件 @
1f34a482
...
@@ -573,10 +573,7 @@ def conv3D(V, W, b, d):
...
@@ -573,10 +573,7 @@ def conv3D(V, W, b, d):
The order of dimensions does not correspond to the one in `conv2d`.
The order of dimensions does not correspond to the one in `conv2d`.
This is for optimization.
This is for optimization.
The GPU implementation is very slow. You should use
Please use nnet.conv3d instead of this for a faster GPU implementation.
:func:`conv3d2d <theano.tensor.nnet.conv3d2d.conv3d>` or
:func:`conv3d_fft <theano.sandbox.cuda.fftconv.conv3d_fft>` for a
GPU graph instead.
See Also
See Also
--------
--------
...
...
theano/tensor/nnet/conv.py
浏览文件 @
1f34a482
...
@@ -903,7 +903,6 @@ class ConvOp(OpenMPOp):
...
@@ -903,7 +903,6 @@ class ConvOp(OpenMPOp):
newin
=
inputs
.
dimshuffle
((
1
,
0
,
2
,
3
))
newin
=
inputs
.
dimshuffle
((
1
,
0
,
2
,
3
))
newgz
=
gz
.
dimshuffle
((
1
,
0
,
2
,
3
))
newgz
=
gz
.
dimshuffle
((
1
,
0
,
2
,
3
))
un_p
=
self
.
unroll_patch
if
self
.
out_mode
==
'valid'
:
if
self
.
out_mode
==
'valid'
:
(
img
,
filters
)
=
(
newin
,
newgz
)
(
img
,
filters
)
=
(
newin
,
newgz
)
kshp_logical
=
self
.
fulloutshp
kshp_logical
=
self
.
fulloutshp
...
@@ -912,8 +911,6 @@ class ConvOp(OpenMPOp):
...
@@ -912,8 +911,6 @@ class ConvOp(OpenMPOp):
(
bsize
,
nkern
)
=
(
self
.
imshp
[
0
],
self
.
nkern
)
(
bsize
,
nkern
)
=
(
self
.
imshp
[
0
],
self
.
nkern
)
imshp
=
(
self
.
bsize
,
self
.
imshp
[
1
],
self
.
imshp
[
2
])
imshp
=
(
self
.
bsize
,
self
.
imshp
[
1
],
self
.
imshp
[
2
])
kshp
=
self
.
outshp
kshp
=
self
.
outshp
un_b
=
self
.
unroll_batch
un_k
=
self
.
unroll_kern
elif
self
.
out_mode
==
'full'
:
elif
self
.
out_mode
==
'full'
:
(
img
,
filters
)
=
(
newgz
,
newin
)
(
img
,
filters
)
=
(
newgz
,
newin
)
kshp_logical
=
None
kshp_logical
=
None
...
@@ -924,8 +921,6 @@ class ConvOp(OpenMPOp):
...
@@ -924,8 +921,6 @@ class ConvOp(OpenMPOp):
(
bsize
,
nkern
)
=
(
self
.
nkern
,
self
.
imshp
[
0
])
(
bsize
,
nkern
)
=
(
self
.
nkern
,
self
.
imshp
[
0
])
imshp
=
(
self
.
bsize
,
self
.
outshp
[
0
],
self
.
outshp
[
1
])
imshp
=
(
self
.
bsize
,
self
.
outshp
[
0
],
self
.
outshp
[
1
])
kshp
=
self
.
imshp
[
1
:]
kshp
=
self
.
imshp
[
1
:]
un_b
=
self
.
unroll_kern
un_k
=
self
.
unroll_batch
else
:
else
:
raise
NotImplementedError
(
raise
NotImplementedError
(
'Only [full,valid] modes are currently supported.'
)
'Only [full,valid] modes are currently supported.'
)
...
...
theano/tensor/nnet/conv3d2d.py
浏览文件 @
1f34a482
...
@@ -4,7 +4,6 @@ from theano.gradient import DisconnectedType
...
@@ -4,7 +4,6 @@ from theano.gradient import DisconnectedType
from
theano.gof
import
Op
,
Apply
,
TopoOptimizer
from
theano.gof
import
Op
,
Apply
,
TopoOptimizer
from
theano.gof.opt
import
copy_stack_trace
from
theano.gof.opt
import
copy_stack_trace
from
theano
import
tensor
from
theano
import
tensor
import
theano.sandbox.cuda
as
cuda
def
get_diagonal_subtensor_view
(
x
,
i0
,
i1
):
def
get_diagonal_subtensor_view
(
x
,
i0
,
i1
):
...
@@ -16,7 +15,7 @@ def get_diagonal_subtensor_view(x, i0, i1):
...
@@ -16,7 +15,7 @@ def get_diagonal_subtensor_view(x, i0, i1):
It returns a partial view of x, not a partial copy.
It returns a partial view of x, not a partial copy.
"""
"""
# We have to cast i0 and i0 to int because python
2.4 (and maybe later)
# We have to cast i0 and i0 to int because python
# do not support indexing with 0-dim, 'int*' ndarrays.
# do not support indexing with 0-dim, 'int*' ndarrays.
i0
=
int
(
i0
)
i0
=
int
(
i0
)
i1
=
int
(
i1
)
i1
=
int
(
i1
)
...
@@ -198,8 +197,7 @@ def conv3d(signals, filters,
...
@@ -198,8 +197,7 @@ def conv3d(signals, filters,
Another way to define signals: (batch, time, in channel, row, column)
Another way to define signals: (batch, time, in channel, row, column)
Another way to define filters: (out channel,time,in channel, row, column)
Another way to define filters: (out channel,time,in channel, row, column)
For the GPU, you can use this implementation or
For the GPU, use nnet.conv3d.
:func:`conv3d_fft <theano.sandbox.cuda.fftconv.conv3d_fft>`.
See Also
See Also
--------
--------
...
@@ -295,67 +293,6 @@ def conv3d(signals, filters,
...
@@ -295,67 +293,6 @@ def conv3d(signals, filters,
return
out_5d
return
out_5d
def
make_gpu_optimizer
(
op
,
to_gpu
):
"""
This function create optimizer that move some inputs to the GPU
for op that work on both CPU and GPU.
The op object is created by calling op(), so good default value
are needed.
We suppose the same op work with CPU and GPU inputs.
Parameters
----------
op
The op that support GPU inputs.
to_gpu
A list of op inputs that are moved to the GPU.
"""
@theano.gof.local_optimizer
([
op
,
cuda
.
gpu_from_host
])
def
local_to_gpu
(
node
):
"""
op(host_from_gpu()) -> host_from_gpu(op)
gpu_from_host(op) -> op(gpu_from_host)
"""
if
isinstance
(
node
.
op
,
op
):
# op(host_from_gpu()) -> host_from_gpu(op)
# If any of the input that go on the GPU are on the GPU,
# move the op to the gpu.
if
any
(
node
.
inputs
[
idx
]
.
owner
and
isinstance
(
node
.
inputs
[
idx
]
.
owner
.
op
,
cuda
.
HostFromGpu
)
for
idx
in
to_gpu
):
new_inp
=
list
(
node
.
inputs
)
for
idx
in
to_gpu
:
new_inp
[
idx
]
=
cuda
.
gpu_from_host
(
new_inp
[
idx
])
result_node
=
op
()(
*
new_inp
)
copy_stack_trace
(
node
.
outputs
[
0
],
result_node
)
transfer_node
=
result_node
.
transfer
(
'cpu'
)
copy_stack_trace
(
node
.
outputs
[
0
],
transfer_node
)
return
[
transfer_node
]
if
node
.
op
==
cuda
.
gpu_from_host
:
# gpu_from_host(op) -> op(gpu_from_host)
host_input
=
node
.
inputs
[
0
]
if
host_input
.
owner
and
isinstance
(
host_input
.
owner
.
op
,
op
):
op_node
=
host_input
.
owner
new_inp
=
list
(
op_node
.
inputs
)
for
idx
in
to_gpu
:
new_inp
[
idx
]
=
cuda
.
gpu_from_host
(
new_inp
[
idx
])
new_node
=
op
()(
*
new_inp
)
copy_stack_trace
(
host_input
,
new_node
)
return
[
new_node
]
return
False
local_to_gpu
.
__name__
=
"local_to_gpu_"
+
op
.
__name__
cuda
.
opt
.
register_opt
()(
local_to_gpu
)
if
cuda
.
cuda_available
:
make_gpu_optimizer
(
DiagonalSubtensor
,
[
0
])
make_gpu_optimizer
(
IncDiagonalSubtensor
,
[
0
,
3
])
@theano.gof.local_optimizer
([
DiagonalSubtensor
,
IncDiagonalSubtensor
])
@theano.gof.local_optimizer
([
DiagonalSubtensor
,
IncDiagonalSubtensor
])
def
local_inplace_DiagonalSubtensor
(
node
):
def
local_inplace_DiagonalSubtensor
(
node
):
"""Also work for IncDiagonalSubtensor."""
"""Also work for IncDiagonalSubtensor."""
...
...
theano/tensor/nnet/tests/test_conv3d2d.py
浏览文件 @
1f34a482
...
@@ -16,12 +16,6 @@ from theano.tensor.nnet.conv3d2d import conv3d, get_diagonal_subtensor_view, Dia
...
@@ -16,12 +16,6 @@ from theano.tensor.nnet.conv3d2d import conv3d, get_diagonal_subtensor_view, Dia
import
theano.tests.unittest_tools
as
utt
import
theano.tests.unittest_tools
as
utt
if
theano
.
config
.
mode
==
'FAST_COMPILE'
:
mode_without_gpu
=
theano
.
compile
.
mode
.
get_mode
(
'FAST_RUN'
)
.
excluding
(
'gpu'
)
else
:
mode_without_gpu
=
theano
.
compile
.
mode
.
get_default_mode
()
.
excluding
(
'gpu'
)
def
test_get_diagonal_subtensor_view
(
wrap
=
lambda
a
:
a
):
def
test_get_diagonal_subtensor_view
(
wrap
=
lambda
a
:
a
):
x
=
numpy
.
arange
(
20
)
.
reshape
(
5
,
4
)
.
astype
(
'float32'
)
x
=
numpy
.
arange
(
20
)
.
reshape
(
5
,
4
)
.
astype
(
'float32'
)
x
=
wrap
(
x
)
x
=
wrap
(
x
)
...
@@ -106,17 +100,11 @@ def check_diagonal_subtensor_view_traces(fn):
...
@@ -106,17 +100,11 @@ def check_diagonal_subtensor_view_traces(fn):
@parameterized.expand
((
'valid'
,
'full'
,
'half'
),
utt
.
custom_name_func
)
@parameterized.expand
((
'valid'
,
'full'
,
'half'
),
utt
.
custom_name_func
)
def
test_conv3d
(
border_mode
):
def
test_conv3d
(
border_mode
):
check_conv3d
(
border_mode
=
border_mode
,
mode
=
mode_without_gpu
,
shared
=
theano
.
tensor
.
_shared
)
# This function will also be used in theano/sandbox/cuda/tests/test_tensor_op.py,
# which is not possible if it is decorated by @parameterized.expand
def
check_conv3d
(
border_mode
,
mode
=
mode_without_gpu
,
shared
=
theano
.
tensor
.
_shared
):
if
ndimage
is
None
or
not
theano
.
config
.
cxx
:
if
ndimage
is
None
or
not
theano
.
config
.
cxx
:
raise
SkipTest
(
"conv3d2d tests need SciPy and a c++ compiler"
)
raise
SkipTest
(
"conv3d2d tests need SciPy and a c++ compiler"
)
shared
=
theano
.
tensor
.
_shared
Ns
,
Ts
,
C
,
Hs
,
Ws
=
3
,
10
,
3
,
32
,
32
Ns
,
Ts
,
C
,
Hs
,
Ws
=
3
,
10
,
3
,
32
,
32
Nf
,
Tf
,
C
,
Hf
,
Wf
=
32
,
5
,
3
,
5
,
5
Nf
,
Tf
,
C
,
Hf
,
Wf
=
32
,
5
,
3
,
5
,
5
...
@@ -137,8 +125,7 @@ def check_conv3d(border_mode, mode=mode_without_gpu, shared=theano.tensor._share
...
@@ -137,8 +125,7 @@ def check_conv3d(border_mode, mode=mode_without_gpu, shared=theano.tensor._share
border_mode
=
border_mode
)
border_mode
=
border_mode
)
newconv3d
=
theano
.
function
([],
[],
newconv3d
=
theano
.
function
([],
[],
updates
=
{
s_output
:
out
},
updates
=
{
s_output
:
out
})
mode
=
mode
)
check_diagonal_subtensor_view_traces
(
newconv3d
)
check_diagonal_subtensor_view_traces
(
newconv3d
)
t0
=
time
.
time
()
t0
=
time
.
time
()
...
@@ -149,7 +136,6 @@ def check_conv3d(border_mode, mode=mode_without_gpu, shared=theano.tensor._share
...
@@ -149,7 +136,6 @@ def check_conv3d(border_mode, mode=mode_without_gpu, shared=theano.tensor._share
gnewconv3d
=
theano
.
function
([],
[],
gnewconv3d
=
theano
.
function
([],
[],
updates
=
[(
s_filters
,
gfilters
),
updates
=
[(
s_filters
,
gfilters
),
(
s_signals
,
gsignals
)],
(
s_signals
,
gsignals
)],
mode
=
mode
,
name
=
'grad'
)
name
=
'grad'
)
check_diagonal_subtensor_view_traces
(
gnewconv3d
)
check_diagonal_subtensor_view_traces
(
gnewconv3d
)
...
@@ -163,7 +149,7 @@ def check_conv3d(border_mode, mode=mode_without_gpu, shared=theano.tensor._share
...
@@ -163,7 +149,7 @@ def check_conv3d(border_mode, mode=mode_without_gpu, shared=theano.tensor._share
signals
=
numpy
.
random
.
rand
(
Ns
,
Ts
,
C
,
Hs
,
Ws
)
.
astype
(
'float32'
)
signals
=
numpy
.
random
.
rand
(
Ns
,
Ts
,
C
,
Hs
,
Ws
)
.
astype
(
'float32'
)
filters
=
numpy
.
random
.
rand
(
Nf
,
Tf
,
C
,
Hf
,
Wf
)
.
astype
(
'float32'
)
filters
=
numpy
.
random
.
rand
(
Nf
,
Tf
,
C
,
Hf
,
Wf
)
.
astype
(
'float32'
)
utt
.
verify_grad
(
lambda
s
,
f
:
conv3d
(
s
,
f
,
border_mode
=
border_mode
),
utt
.
verify_grad
(
lambda
s
,
f
:
conv3d
(
s
,
f
,
border_mode
=
border_mode
),
[
signals
,
filters
],
eps
=
1e-1
,
mode
=
mode
)
[
signals
,
filters
],
eps
=
1e-1
)
# Additional Test that covers the case of patched implementation for filter with Tf=1
# Additional Test that covers the case of patched implementation for filter with Tf=1
Ns
,
Ts
,
C
,
Hs
,
Ws
=
3
,
10
,
3
,
32
,
32
Ns
,
Ts
,
C
,
Hs
,
Ws
=
3
,
10
,
3
,
32
,
32
...
@@ -186,8 +172,7 @@ def check_conv3d(border_mode, mode=mode_without_gpu, shared=theano.tensor._share
...
@@ -186,8 +172,7 @@ def check_conv3d(border_mode, mode=mode_without_gpu, shared=theano.tensor._share
border_mode
=
border_mode
)
border_mode
=
border_mode
)
newconv3d
=
theano
.
function
([],
[],
newconv3d
=
theano
.
function
([],
[],
updates
=
{
s_output
:
out
},
updates
=
{
s_output
:
out
})
mode
=
mode
)
t0
=
time
.
time
()
t0
=
time
.
time
()
newconv3d
()
newconv3d
()
...
@@ -197,7 +182,6 @@ def check_conv3d(border_mode, mode=mode_without_gpu, shared=theano.tensor._share
...
@@ -197,7 +182,6 @@ def check_conv3d(border_mode, mode=mode_without_gpu, shared=theano.tensor._share
gnewconv3d
=
theano
.
function
([],
[],
gnewconv3d
=
theano
.
function
([],
[],
updates
=
[(
s_filters
,
gfilters
),
updates
=
[(
s_filters
,
gfilters
),
(
s_signals
,
gsignals
)],
(
s_signals
,
gsignals
)],
mode
=
mode
,
name
=
'grad'
)
name
=
'grad'
)
t0
=
time
.
time
()
t0
=
time
.
time
()
...
@@ -210,4 +194,4 @@ def check_conv3d(border_mode, mode=mode_without_gpu, shared=theano.tensor._share
...
@@ -210,4 +194,4 @@ def check_conv3d(border_mode, mode=mode_without_gpu, shared=theano.tensor._share
signals
=
numpy
.
random
.
rand
(
Ns
,
Ts
,
C
,
Hs
,
Ws
)
.
astype
(
'float32'
)
signals
=
numpy
.
random
.
rand
(
Ns
,
Ts
,
C
,
Hs
,
Ws
)
.
astype
(
'float32'
)
filters
=
numpy
.
random
.
rand
(
Nf
,
Tf
,
C
,
Hf
,
Wf
)
.
astype
(
'float32'
)
filters
=
numpy
.
random
.
rand
(
Nf
,
Tf
,
C
,
Hf
,
Wf
)
.
astype
(
'float32'
)
utt
.
verify_grad
(
lambda
s
,
f
:
conv3d
(
s
,
f
,
border_mode
=
border_mode
),
utt
.
verify_grad
(
lambda
s
,
f
:
conv3d
(
s
,
f
,
border_mode
=
border_mode
),
[
signals
,
filters
],
eps
=
1e-1
,
mode
=
mode
)
[
signals
,
filters
],
eps
=
1e-1
)
theano/tensor/subtensor.py
浏览文件 @
1f34a482
...
@@ -640,7 +640,7 @@ class Subtensor(Op):
...
@@ -640,7 +640,7 @@ class Subtensor(Op):
strides_mul
=
None
):
strides_mul
=
None
):
"""
"""
The parameters c_prefix are there to allow reusing this
The parameters c_prefix are there to allow reusing this
function on PyArray and
CudaNda
rray object.
function on PyArray and
GpuA
rray object.
This fct take as input the x.
This fct take as input the x.
...
@@ -1373,7 +1373,7 @@ class IncSubtensor(Op):
...
@@ -1373,7 +1373,7 @@ class IncSubtensor(Op):
# but subclasses may override the helper methods
# but subclasses may override the helper methods
# to change the particulars, e.g. GpuIncSubtensor
# to change the particulars, e.g. GpuIncSubtensor
# turns the view/copy operations on numpy arrays
# turns the view/copy operations on numpy arrays
# into the same operations on
cuda
arrays.
# into the same operations on
gpu
arrays.
self
.
do_type_checking
(
node
)
self
.
do_type_checking
(
node
)
...
...
theano/tensor/tests/shape_opt_cycle.pkl
deleted
100644 → 0
浏览文件 @
1b22389f
File deleted
theano/tensor/tests/test_opt.py
浏览文件 @
1f34a482
差异被折叠。
点击展开。
theano/tensor/tests/test_sharedvar.py
浏览文件 @
1f34a482
...
@@ -25,7 +25,6 @@ def makeSharedTester(shared_constructor_,
...
@@ -25,7 +25,6 @@ def makeSharedTester(shared_constructor_,
theano_fct_
,
theano_fct_
,
ref_fct_
,
ref_fct_
,
cast_value_
=
np
.
asarray
,
cast_value_
=
np
.
asarray
,
op_by_matrix_
=
False
,
name
=
None
,
name
=
None
,
):
):
"""
"""
...
@@ -49,7 +48,6 @@ def makeSharedTester(shared_constructor_,
...
@@ -49,7 +48,6 @@ def makeSharedTester(shared_constructor_,
:param theano_fct_: A theano op that will be used to do some computation on the shared variable
:param theano_fct_: A theano op that will be used to do some computation on the shared variable
:param ref_fct_: A reference function that should return the same value as the theano_fct_
:param ref_fct_: A reference function that should return the same value as the theano_fct_
:param cast_value_: A callable that cast an ndarray into the internal shared variable representation
:param cast_value_: A callable that cast an ndarray into the internal shared variable representation
:param op_by_matrix_: When we do inplace operation on the an internal type object, should we do it with a scalar or a matrix of the same value.
:param name: This string is used to set the returned class' __name__
:param name: This string is used to set the returned class' __name__
attribute. This is needed for nosetests to properly tag the
attribute. This is needed for nosetests to properly tag the
test with its correct name, rather than use the generic
test with its correct name, rather than use the generic
...
@@ -75,7 +73,6 @@ def makeSharedTester(shared_constructor_,
...
@@ -75,7 +73,6 @@ def makeSharedTester(shared_constructor_,
set_cast_value_inplace
=
set_cast_value_inplace_
set_cast_value_inplace
=
set_cast_value_inplace_
shared_constructor_accept_ndarray
=
shared_constructor_accept_ndarray_
shared_constructor_accept_ndarray
=
shared_constructor_accept_ndarray_
cast_value
=
staticmethod
(
cast_value_
)
cast_value
=
staticmethod
(
cast_value_
)
op_by_matrix
=
op_by_matrix_
def
test_shared_dont_alias
(
self
):
def
test_shared_dont_alias
(
self
):
dtype
=
self
.
dtype
dtype
=
self
.
dtype
...
@@ -96,11 +93,7 @@ def makeSharedTester(shared_constructor_,
...
@@ -96,11 +93,7 @@ def makeSharedTester(shared_constructor_,
assert
np
.
allclose
(
self
.
ref_fct
(
x
),
total_val
)
assert
np
.
allclose
(
self
.
ref_fct
(
x
),
total_val
)
values_to_div
=
.
5
x
/=
.
5
if
self
.
op_by_matrix
:
values_to_div
=
self
.
internal_type
(
np
.
ones
(
x
.
shape
,
dtype
=
dtype
)
/
2
)
# supported for cudandarray, but not ndarray.
assert
self
.
test_internal_type
(
values_to_div
)
x
/=
values_to_div
total_val_2
=
total_func
()
total_val_2
=
total_func
()
# value used to construct should not alias with internal
# value used to construct should not alias with internal
...
@@ -108,7 +101,7 @@ def makeSharedTester(shared_constructor_,
...
@@ -108,7 +101,7 @@ def makeSharedTester(shared_constructor_,
x
=
x_shared
.
get_value
(
borrow
=
False
)
x
=
x_shared
.
get_value
(
borrow
=
False
)
x
/=
values_to_div
x
/=
.
5
total_val_3
=
total_func
()
total_val_3
=
total_func
()
...
@@ -117,7 +110,7 @@ def makeSharedTester(shared_constructor_,
...
@@ -117,7 +110,7 @@ def makeSharedTester(shared_constructor_,
# in this case we can alias
# in this case we can alias
x
=
x_shared
.
get_value
(
borrow
=
True
)
x
=
x_shared
.
get_value
(
borrow
=
True
)
x
/=
values_to_div
x
/=
.
5
# this is not required by the contract but it is a feature we've
# this is not required by the contract but it is a feature we've
# implemented for some type of SharedVariable.
# implemented for some type of SharedVariable.
...
@@ -189,12 +182,7 @@ def makeSharedTester(shared_constructor_,
...
@@ -189,12 +182,7 @@ def makeSharedTester(shared_constructor_,
x
=
x_shared
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)
x
=
x_shared
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)
assert
self
.
test_internal_type
(
x
)
assert
self
.
test_internal_type
(
x
)
values_to_div
=
.
5
x
/=
.
5
if
self
.
op_by_matrix
:
# supported for cudandarray, but not ndarray.
values_to_div
=
self
.
internal_type
(
np
.
ones
(
x
.
shape
,
dtype
=
dtype
)
/
2
)
x
/=
values_to_div
# supported by ndarray and CudaNdarray
# this is not required by the contract but it is a feature we can
# this is not required by the contract but it is a feature we can
# implement for some type of SharedVariable.
# implement for some type of SharedVariable.
...
@@ -203,7 +191,7 @@ def makeSharedTester(shared_constructor_,
...
@@ -203,7 +191,7 @@ def makeSharedTester(shared_constructor_,
x
=
x_shared
.
get_value
(
borrow
=
False
,
return_internal_type
=
True
)
x
=
x_shared
.
get_value
(
borrow
=
False
,
return_internal_type
=
True
)
assert
self
.
test_internal_type
(
x
)
assert
self
.
test_internal_type
(
x
)
assert
x
is
not
x_shared
.
container
.
value
assert
x
is
not
x_shared
.
container
.
value
x
/=
values_to_div
# supported by ndarray and CudaNdarray
x
/=
.
5
# this is required by the contract
# this is required by the contract
assert
not
np
.
allclose
(
self
.
ref_fct
(
x
),
total_func
())
assert
not
np
.
allclose
(
self
.
ref_fct
(
x
),
total_func
())
...
@@ -244,16 +232,10 @@ def makeSharedTester(shared_constructor_,
...
@@ -244,16 +232,10 @@ def makeSharedTester(shared_constructor_,
total_func
=
theano
.
function
([],
total
)
total_func
=
theano
.
function
([],
total
)
total_func
()
total_func
()
values_to_div
=
.
5
if
self
.
op_by_matrix
:
# supported for cudandarray, but not ndarray.
values_to_div
=
self
.
internal_type
(
np
.
ones
(
x
.
shape
,
dtype
=
dtype
)
/
2
)
assert
self
.
test_internal_type
(
values_to_div
)
# test if that theano shared variable optimize set_value(borrow=True)
# test if that theano shared variable optimize set_value(borrow=True)
get_x
=
x_shared
.
get_value
(
borrow
=
True
)
get_x
=
x_shared
.
get_value
(
borrow
=
True
)
assert
get_x
is
not
x_orig
# borrow=False to shared_constructor
assert
get_x
is
not
x_orig
# borrow=False to shared_constructor
get_x
/=
values_to_div
get_x
/=
.
5
x_shared
.
set_value
(
get_x
,
borrow
=
True
)
x_shared
.
set_value
(
get_x
,
borrow
=
True
)
x
=
x_shared
.
get_value
(
borrow
=
True
)
x
=
x_shared
.
get_value
(
borrow
=
True
)
if
self
.
set_value_borrow_true_alias
:
if
self
.
set_value_borrow_true_alias
:
...
@@ -267,7 +249,7 @@ def makeSharedTester(shared_constructor_,
...
@@ -267,7 +249,7 @@ def makeSharedTester(shared_constructor_,
assert
get_x
is
not
x_orig
# borrow=False to shared_constructor
assert
get_x
is
not
x_orig
# borrow=False to shared_constructor
assert
self
.
test_internal_type
(
get_x
)
assert
self
.
test_internal_type
(
get_x
)
get_x
/=
values_to_div
# supported by ndarray and CudaNdarray
get_x
/=
.
5
assert
self
.
test_internal_type
(
get_x
)
assert
self
.
test_internal_type
(
get_x
)
x_shared
.
set_value
(
get_x
,
borrow
=
True
)
x_shared
.
set_value
(
get_x
,
borrow
=
True
)
x
=
x_shared
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)
x
=
x_shared
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)
...
@@ -295,12 +277,7 @@ def makeSharedTester(shared_constructor_,
...
@@ -295,12 +277,7 @@ def makeSharedTester(shared_constructor_,
assert
np
.
allclose
(
self
.
ref_fct
(
x
),
total_val
)
assert
np
.
allclose
(
self
.
ref_fct
(
x
),
total_val
)
values_to_div
=
.
5
x
/=
.
5
if
self
.
op_by_matrix
:
# supported for cudandarray, but not ndarray.
values_to_div
=
self
.
internal_type
(
np
.
ones
(
x
.
shape
,
dtype
=
dtype
)
/
2
)
assert
self
.
test_internal_type
(
values_to_div
)
x
/=
values_to_div
# not required by the contract but it is a feature we've implemented
# not required by the contract but it is a feature we've implemented
if
self
.
shared_borrow_true_alias
:
if
self
.
shared_borrow_true_alias
:
...
@@ -345,9 +322,9 @@ def makeSharedTester(shared_constructor_,
...
@@ -345,9 +322,9 @@ def makeSharedTester(shared_constructor_,
if
x
.
__class__
.
__name__
!=
'csr_matrix'
:
if
x
.
__class__
.
__name__
!=
'csr_matrix'
:
# sparse matrix don't support inplace affectation
# sparse matrix don't support inplace affectation
nd
+=
1
nd
+=
1
# THIS DON't DO WHAT WE EXPECT the contain of a is not updated for CudaNdarray, but it is for ndarray
# THIS DOENS'T DO WHAT WE EXPECT the content of a is
# not updated for GpuArray, but it is for ndarray
x_shared
.
get_value
(
borrow
=
True
)[:]
=
nd
x_shared
.
get_value
(
borrow
=
True
)[:]
=
nd
#assert (np.asarray(x_shared.get_value(borrow=True))!=nd).all()
assert
may_share_memory
(
old_data
,
x_shared
.
container
.
storage
[
0
])
assert
may_share_memory
(
old_data
,
x_shared
.
container
.
storage
[
0
])
x_shared
.
get_value
(
borrow
=
True
)
x_shared
.
get_value
(
borrow
=
True
)
...
@@ -617,7 +594,6 @@ test_shared_options = makeSharedTester(
...
@@ -617,7 +594,6 @@ test_shared_options = makeSharedTester(
theano_fct_
=
lambda
a
:
a
*
2
,
theano_fct_
=
lambda
a
:
a
*
2
,
ref_fct_
=
lambda
a
:
np
.
asarray
((
a
*
2
)),
ref_fct_
=
lambda
a
:
np
.
asarray
((
a
*
2
)),
cast_value_
=
np
.
asarray
,
cast_value_
=
np
.
asarray
,
op_by_matrix_
=
False
,
name
=
'test_shared_options'
)
name
=
'test_shared_options'
)
...
...
theano/tensor/type.py
浏览文件 @
1f34a482
...
@@ -203,10 +203,9 @@ class TensorType(Type):
...
@@ -203,10 +203,9 @@ class TensorType(Type):
"""
"""
Convert a symbolic Variable into a TensorType, if compatible.
Convert a symbolic Variable into a TensorType, if compatible.
For the moment, only a TensorType, GpuArrayType and
For the moment, only a TensorType and GpuArrayType will be
CudaNdarrayType will be
converted, provided they have the same number of dimensions
converted, provided they have the same number of dimensions and
and dtype and have "compatible" broadcastable pattern.
dtype and have "compatible" broadcastable pattern.
"""
"""
if
hasattr
(
other
,
'_as_TensorVariable'
):
if
hasattr
(
other
,
'_as_TensorVariable'
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论