Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
45a84389
提交
45a84389
authored
4月 10, 2015
作者:
abergeron
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2746 from nouiz/shared
fix gh-855.
上级
893a4549
24cedf24
显示空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
47 行增加
和
38 行删除
+47
-38
test_vm.py
theano/gof/tests/test_vm.py
+25
-30
test_basic_ops.py
theano/sandbox/cuda/tests/test_basic_ops.py
+1
-1
test_basic_ops.py
theano/sandbox/gpuarray/tests/test_basic_ops.py
+5
-1
sharedvar.py
theano/tensor/sharedvar.py
+6
-1
sort.py
theano/tensor/sort.py
+1
-1
test_sharedvar.py
theano/tensor/tests/test_sharedvar.py
+6
-0
test_flake8.py
theano/tests/test_flake8.py
+0
-1
test_rop.py
theano/tests/test_rop.py
+3
-3
没有找到文件。
theano/gof/tests/test_vm.py
浏览文件 @
45a84389
...
@@ -2,17 +2,12 @@ import gc
...
@@ -2,17 +2,12 @@ import gc
import
sys
import
sys
import
time
import
time
import
unittest
import
unittest
try
:
import
line_profiler
except
ImportError
:
pass
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
import
numpy
import
numpy
from
theano
import
function
from
theano
import
function
from
theano.gof
import
vm
from
theano.gof
import
vm
from
theano.gof
import
link
from
theano.gof
import
OpWiseCLinker
from
theano.gof
import
OpWiseCLinker
from
theano.compile
import
Mode
from
theano.compile
import
Mode
...
@@ -43,7 +38,8 @@ class TestCallbacks(unittest.TestCase):
...
@@ -43,7 +38,8 @@ class TestCallbacks(unittest.TestCase):
f
(
1
,
2
,
3
)
f
(
1
,
2
,
3
)
assert
sum
(
self
.
n_callbacks
.
values
())
==
len
(
f
.
maker
.
fgraph
.
toposort
())
assert
sum
(
self
.
n_callbacks
.
values
())
==
len
(
f
.
maker
.
fgraph
.
toposort
())
f
(
1
,
2
,
3
)
f
(
1
,
2
,
3
)
assert
sum
(
self
.
n_callbacks
.
values
())
==
len
(
f
.
maker
.
fgraph
.
toposort
())
*
2
assert
(
sum
(
self
.
n_callbacks
.
values
())
==
len
(
f
.
maker
.
fgraph
.
toposort
())
*
2
)
def
test_callback_with_ifelse
(
self
):
def
test_callback_with_ifelse
(
self
):
a
,
b
,
c
=
tensor
.
scalars
(
'abc'
)
a
,
b
,
c
=
tensor
.
scalars
(
'abc'
)
...
@@ -89,7 +85,7 @@ def test_speed():
...
@@ -89,7 +85,7 @@ def test_speed():
print
"
%
s takes
%
f s/Kop"
%
(
print
"
%
s takes
%
f s/Kop"
%
(
'numpy'
,
'numpy'
,
(
1000
*
(
t_b
-
t_a
)
/
(
steps_b
-
steps_a
)))
(
1000
*
(
t_b
-
t_a
)
/
(
steps_b
-
steps_a
)))
def
time_linker
(
name
,
linker
):
def
time_linker
(
name
,
linker
):
steps_a
=
5
steps_a
=
5
...
@@ -99,13 +95,9 @@ def test_speed():
...
@@ -99,13 +95,9 @@ def test_speed():
b
=
build_graph
(
x
,
steps_b
)
b
=
build_graph
(
x
,
steps_b
)
f_a
=
function
([
x
],
a
,
f_a
=
function
([
x
],
a
,
mode
=
Mode
(
optimizer
=
None
,
linker
=
linker
()),
mode
=
Mode
(
optimizer
=
None
,
linker
=
linker
()))
#profile='f_a speed test %s'%name,
)
f_b
=
function
([
x
],
b
,
f_b
=
function
([
x
],
b
,
mode
=
Mode
(
optimizer
=
None
,
linker
=
linker
()),
mode
=
Mode
(
optimizer
=
None
,
linker
=
linker
()))
#profile='f_b speed test %s'%name,
)
f_a
([
2.0
,
3.0
])
f_a
([
2.0
,
3.0
])
t0
=
time
.
time
()
t0
=
time
.
time
()
...
@@ -151,14 +143,10 @@ def test_speed_lazy():
...
@@ -151,14 +143,10 @@ def test_speed_lazy():
f_a
=
function
([
x
],
a
,
f_a
=
function
([
x
],
a
,
mode
=
Mode
(
optimizer
=
None
,
mode
=
Mode
(
optimizer
=
None
,
linker
=
linker
()),
linker
=
linker
()))
#profile='f_a lazy ifelse %s'%name,
)
f_b
=
function
([
x
],
b
,
f_b
=
function
([
x
],
b
,
mode
=
Mode
(
optimizer
=
None
,
mode
=
Mode
(
optimizer
=
None
,
linker
=
linker
()),
linker
=
linker
()))
#profile='f_b lazy ifelse %s'%name,
)
f_a
([
2.0
])
f_a
([
2.0
])
t0
=
time
.
time
()
t0
=
time
.
time
()
...
@@ -220,6 +208,7 @@ if run_memory_usage_tests:
...
@@ -220,6 +208,7 @@ if run_memory_usage_tests:
c
=
sys
.
getrefcount
(
n
)
c
=
sys
.
getrefcount
(
n
)
a
=
cuda
.
CudaNdarray
(
n
)
a
=
cuda
.
CudaNdarray
(
n
)
assert
c
==
sys
.
getrefcount
(
n
)
assert
c
==
sys
.
getrefcount
(
n
)
del
a
if
not
i
%
1000
:
if
not
i
%
1000
:
print
'.'
,
print
'.'
,
print
gc
.
collect
(),
print
gc
.
collect
(),
...
@@ -258,20 +247,20 @@ if run_memory_usage_tests:
...
@@ -258,20 +247,20 @@ if run_memory_usage_tests:
def
build_graph
(
x
,
depth
=
5
):
def
build_graph
(
x
,
depth
=
5
):
z
=
x
z
=
x
for
d
in
range
(
depth
):
for
d
in
range
(
depth
):
z
=
ifelse
(
z
>
0
,
-
z
,
z
)
z
=
ifelse
(
z
.
mean
()
>
0.5
,
-
z
,
z
)
return
z
return
z
def
time_linker
(
name
,
linker
):
def
time_linker
(
name
,
linker
):
steps_a
=
10
steps_a
=
10
x
=
tensor
.
vector
()
x
=
tensor
.
d
vector
()
a
=
build_graph
(
x
,
steps_a
)
a
=
build_graph
(
x
,
steps_a
)
f_a
=
function
([
x
],
a
,
f_a
=
function
([
x
],
a
,
mode
=
Mode
(
optimizer
=
None
,
mode
=
Mode
(
optimizer
=
None
,
linker
=
linker
()))
linker
=
linker
()))
inp
=
numpy
.
random
.
rand
(
1000000
)
for
i
in
xrange
(
100
000
):
for
i
in
xrange
(
100
):
f_a
(
[
2.0
]
)
f_a
(
inp
)
if
0
:
# this doesn't seem to work, prints 0 for everything
if
0
:
# this doesn't seem to work, prints 0 for everything
import
resource
import
resource
pre
=
resource
.
getrusage
(
resource
.
RUSAGE_SELF
)
pre
=
resource
.
getrusage
(
resource
.
RUSAGE_SELF
)
...
@@ -279,9 +268,12 @@ if run_memory_usage_tests:
...
@@ -279,9 +268,12 @@ if run_memory_usage_tests:
print
pre
.
ru_ixrss
,
post
.
ru_ixrss
print
pre
.
ru_ixrss
,
post
.
ru_ixrss
print
pre
.
ru_idrss
,
post
.
ru_idrss
print
pre
.
ru_idrss
,
post
.
ru_idrss
print
pre
.
ru_maxrss
,
post
.
ru_maxrss
print
pre
.
ru_maxrss
,
post
.
ru_maxrss
print
1
time_linker
(
'vmLinker_C'
,
time_linker
(
'vmLinker_C'
,
lambda
:
vm
.
VM_Linker
(
allow_gc
=
False
,
use_cloop
=
True
))
lambda
:
vm
.
VM_Linker
(
allow_gc
=
False
,
use_cloop
=
True
))
print
2
time_linker
(
'vmLinker'
,
lambda
:
vm
.
VM_Linker
(
allow_gc
=
False
,
use_cloop
=
False
))
def
test_no_leak_many_call_nonlazy
():
def
test_no_leak_many_call_nonlazy
():
# Verify no memory leaks when calling a function a lot of times
# Verify no memory leaks when calling a function a lot of times
...
@@ -297,18 +289,21 @@ if run_memory_usage_tests:
...
@@ -297,18 +289,21 @@ if run_memory_usage_tests:
def
time_linker
(
name
,
linker
):
def
time_linker
(
name
,
linker
):
steps_a
=
10
steps_a
=
10
x
=
tensor
.
vector
()
x
=
tensor
.
d
vector
()
a
=
build_graph
(
x
,
steps_a
)
a
=
build_graph
(
x
,
steps_a
)
f_a
=
function
([
x
],
a
,
f_a
=
function
([
x
],
a
,
mode
=
Mode
(
optimizer
=
None
,
mode
=
Mode
(
optimizer
=
None
,
linker
=
linker
()))
linker
=
linker
()))
inp
=
numpy
.
random
.
rand
(
1000000
)
for
i
in
xrange
(
500
000
):
for
i
in
xrange
(
500
):
f_a
(
[
2.0
]
)
f_a
(
inp
)
print
1
time_linker
(
'vmLinker_C'
,
time_linker
(
'vmLinker_C'
,
lambda
:
vm
.
VM_Linker
(
allow_gc
=
False
,
use_cloop
=
True
))
lambda
:
vm
.
VM_Linker
(
allow_gc
=
False
,
use_cloop
=
True
))
print
2
time_linker
(
'vmLinker'
,
lambda
:
vm
.
VM_Linker
(
allow_gc
=
False
,
use_cloop
=
False
))
class
RunOnce
(
theano
.
Op
):
class
RunOnce
(
theano
.
Op
):
...
...
theano/sandbox/cuda/tests/test_basic_ops.py
浏览文件 @
45a84389
...
@@ -878,7 +878,7 @@ def test_gpujoin_assert_cndas():
...
@@ -878,7 +878,7 @@ def test_gpujoin_assert_cndas():
c
=
cuda
.
basic_ops
.
gpu_join
(
1
,
a
)
c
=
cuda
.
basic_ops
.
gpu_join
(
1
,
a
)
# can't "assert False" here, as we want the assertion
# can't "assert False" here, as we want the assertion
# error from gpu_join
# error from gpu_join
except
Assertion
Error
:
except
Type
Error
:
assert
True
assert
True
return
return
...
...
theano/sandbox/gpuarray/tests/test_basic_ops.py
浏览文件 @
45a84389
...
@@ -42,6 +42,7 @@ from ..basic_ops import (
...
@@ -42,6 +42,7 @@ from ..basic_ops import (
gpu_alloc
,
GpuAlloc
,
gpu_alloc
,
GpuAlloc
,
gpu_from_cuda
,
gpu_from_cuda
,
cuda_from_gpu
,
HostFromGpu
,
cuda_from_gpu
,
HostFromGpu
,
GpuContiguous
,
GpuFromHost
,
GpuReshape
,
GpuFromHost
,
GpuReshape
,
gpu_join
,
GpuJoin
,
GpuSplit
,
GpuEye
,
gpu_contiguous
)
gpu_join
,
GpuJoin
,
GpuSplit
,
GpuEye
,
gpu_contiguous
)
from
..subtensor
import
GpuSubtensor
from
..subtensor
import
GpuSubtensor
...
@@ -332,10 +333,13 @@ def test_gpu_contiguous():
...
@@ -332,10 +333,13 @@ def test_gpu_contiguous():
a
=
T
.
fmatrix
(
'a'
)
a
=
T
.
fmatrix
(
'a'
)
i
=
T
.
iscalar
(
'i'
)
i
=
T
.
iscalar
(
'i'
)
a_val
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
4
,
5
),
dtype
=
'float32'
)
a_val
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
4
,
5
),
dtype
=
'float32'
)
f
=
theano
.
function
([
a
,
i
],
gpu_contiguous
(
a
[::
i
]),
# The reshape is needed otherwise we make the subtensor on the CPU
# to transfer less data.
f
=
theano
.
function
([
a
,
i
],
gpu_contiguous
(
a
.
reshape
((
5
,
4
))[::
i
]),
mode
=
mode_with_gpu
)
mode
=
mode_with_gpu
)
topo
=
f
.
maker
.
fgraph
.
toposort
()
topo
=
f
.
maker
.
fgraph
.
toposort
()
assert
any
([
isinstance
(
node
.
op
,
GpuSubtensor
)
for
node
in
topo
])
assert
any
([
isinstance
(
node
.
op
,
GpuSubtensor
)
for
node
in
topo
])
assert
any
([
isinstance
(
node
.
op
,
GpuContiguous
)
for
node
in
topo
])
assert
f
(
a_val
,
1
)
.
flags
.
c_contiguous
assert
f
(
a_val
,
1
)
.
flags
.
c_contiguous
assert
f
(
a_val
,
2
)
.
flags
.
c_contiguous
assert
f
(
a_val
,
2
)
.
flags
.
c_contiguous
assert
f
(
a_val
,
2
)
.
flags
.
c_contiguous
assert
f
(
a_val
,
2
)
.
flags
.
c_contiguous
...
...
theano/tensor/sharedvar.py
浏览文件 @
45a84389
...
@@ -59,11 +59,16 @@ class ScalarSharedVariable(_tensor_py_operators, SharedVariable):
...
@@ -59,11 +59,16 @@ class ScalarSharedVariable(_tensor_py_operators, SharedVariable):
@shared_constructor
@shared_constructor
def
scalar_constructor
(
value
,
name
=
None
,
strict
=
False
,
allow_downcast
=
None
):
def
scalar_constructor
(
value
,
name
=
None
,
strict
=
False
,
allow_downcast
=
None
,
borrow
=
False
):
"""SharedVariable constructor for scalar values. Default: int64 or float64.
"""SharedVariable constructor for scalar values. Default: int64 or float64.
:note: We implement this using 0-d tensors for now.
:note: We implement this using 0-d tensors for now.
:note: We ignore the borrow parameter as we convert ``value`` to an
ndarray (this is a new object). This respects the semantic of
borrow, as it is a hint to Theano that we can reuse it.
"""
"""
if
not
isinstance
(
value
,
(
numpy
.
number
,
float
,
int
,
complex
)):
if
not
isinstance
(
value
,
(
numpy
.
number
,
float
,
int
,
complex
)):
raise
TypeError
()
raise
TypeError
()
...
...
theano/tensor/sort.py
浏览文件 @
45a84389
...
@@ -61,7 +61,7 @@ class SortOp(theano.Op):
...
@@ -61,7 +61,7 @@ class SortOp(theano.Op):
inp_grad
=
theano
.
gradient
.
grad_not_implemented
(
inp_grad
=
theano
.
gradient
.
grad_not_implemented
(
self
,
0
,
axis
,
self
,
0
,
axis
,
"Currently, we only implement the gradient on sort for vector"
"Currently, we only implement the gradient on sort for vector"
" and matrix (and axis is None)"
)
" and matrix (and axis is None
or 0
)"
)
if
a
.
ndim
==
1
:
if
a
.
ndim
==
1
:
idx
=
argsort
(
*
inputs
,
kind
=
self
.
kind
,
order
=
self
.
order
)
idx
=
argsort
(
*
inputs
,
kind
=
self
.
kind
,
order
=
self
.
order
)
# rev_idx = numpy.where(idx[None, :]==numpy.arange(5)[:,None])[1]
# rev_idx = numpy.where(idx[None, :]==numpy.arange(5)[:,None])[1]
...
...
theano/tensor/tests/test_sharedvar.py
浏览文件 @
45a84389
...
@@ -617,3 +617,9 @@ test_shared_options = makeSharedTester(
...
@@ -617,3 +617,9 @@ test_shared_options = makeSharedTester(
cast_value_
=
numpy
.
asarray
,
cast_value_
=
numpy
.
asarray
,
op_by_matrix_
=
False
,
op_by_matrix_
=
False
,
name
=
'test_shared_options'
)
name
=
'test_shared_options'
)
def
test_scalar_shared_options
():
# Simple test to make sure we do not loose that fonctionality.
theano
.
shared
(
value
=
0.
,
name
=
'lk'
,
borrow
=
True
)
theano
.
shared
(
value
=
numpy
.
float32
(
0.
),
name
=
'lk'
,
borrow
=
True
)
theano/tests/test_flake8.py
浏览文件 @
45a84389
...
@@ -320,7 +320,6 @@ whitelist_flake8 = [
...
@@ -320,7 +320,6 @@ whitelist_flake8 = [
"gof/tests/test_destroyhandler.py"
,
"gof/tests/test_destroyhandler.py"
,
"gof/tests/test_opt.py"
,
"gof/tests/test_opt.py"
,
"gof/tests/test_lazy.py"
,
"gof/tests/test_lazy.py"
,
"gof/tests/test_vm.py"
,
"gof/tests/test_toolbox.py"
,
"gof/tests/test_toolbox.py"
,
"gof/tests/test_link.py"
,
"gof/tests/test_link.py"
,
"gof/tests/test_fg.py"
,
"gof/tests/test_fg.py"
,
...
...
theano/tests/test_rop.py
浏览文件 @
45a84389
...
@@ -68,11 +68,11 @@ class RopLop_checker(unittest.TestCase):
...
@@ -68,11 +68,11 @@ class RopLop_checker(unittest.TestCase):
self
.
x
=
tensor
.
vector
(
'x'
)
self
.
x
=
tensor
.
vector
(
'x'
)
self
.
v
=
tensor
.
vector
(
'v'
)
self
.
v
=
tensor
.
vector
(
'v'
)
self
.
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
self
.
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
self
.
in_shape
=
(
5
+
self
.
rng
.
randint
(
3
0
),)
self
.
in_shape
=
(
5
+
self
.
rng
.
randint
(
3
),)
self
.
mx
=
tensor
.
matrix
(
'mx'
)
self
.
mx
=
tensor
.
matrix
(
'mx'
)
self
.
mv
=
tensor
.
matrix
(
'mv'
)
self
.
mv
=
tensor
.
matrix
(
'mv'
)
self
.
mat_in_shape
=
(
5
+
self
.
rng
.
randint
(
3
0
),
self
.
mat_in_shape
=
(
5
+
self
.
rng
.
randint
(
3
),
5
+
self
.
rng
.
randint
(
3
0
))
5
+
self
.
rng
.
randint
(
3
))
def
check_nondiff_rop
(
self
,
y
):
def
check_nondiff_rop
(
self
,
y
):
""" If your op is not differentiable(so you can't define Rop)
""" If your op is not differentiable(so you can't define Rop)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论