Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6905a821
提交
6905a821
authored
10月 01, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
差异文件
merge
上级
122f8d1e
40356219
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
72 行增加
和
34 行删除
+72
-34
pfunc.py
theano/compile/sandbox/pfunc.py
+1
-1
cmodule.py
theano/gof/cmodule.py
+5
-2
compilelock.py
theano/gof/compilelock.py
+17
-4
conv.py
theano/sandbox/conv.py
+14
-2
test_conv.py
theano/sandbox/test_conv.py
+16
-22
basic.py
theano/tensor/basic.py
+6
-1
test_opt.py
theano/tensor/tests/test_opt.py
+13
-2
没有找到文件。
theano/compile/sandbox/pfunc.py
浏览文件 @
6905a821
...
...
@@ -148,7 +148,7 @@ def _pfunc_param_to_in(param):
mutable
=
param
.
mutable
,
strict
=
param
.
strict
,
implicit
=
param
.
implicit
)
raise
NotImplementedError
()
raise
NotImplementedError
(
'Unknown parameter type:
%
s'
%
type
(
param
)
)
def
iter_over_pairs
(
pairs
):
...
...
theano/gof/cmodule.py
浏览文件 @
6905a821
...
...
@@ -583,14 +583,17 @@ def gcc_module_compile_str(module_name, src_code, location=None, include_dirs=[]
:returns: dynamically-imported python module of the compiled code.
"""
#TODO:
don't t
o the dlimport in this function
#TODO:
Do not d
o the dlimport in this function
if
preargs
is
None
:
preargs
=
[]
else
:
preargs
=
list
(
preargs
)
preargs
.
append
(
'-fPIC'
)
if
sys
.
platform
!=
'win32'
:
# Under Windows it looks like fPIC is useless. Compiler warning:
# '-fPIC ignored for target (all code is position independent)'
preargs
.
append
(
'-fPIC'
)
no_opt
=
False
include_dirs
=
std_include_dirs
()
+
include_dirs
...
...
theano/gof/compilelock.py
浏览文件 @
6905a821
...
...
@@ -3,6 +3,17 @@
import
compiledir
import
os
,
random
,
time
import
logging
_logger
=
logging
.
getLogger
(
"theano.gof.compilelock"
)
_logger
.
setLevel
(
logging
.
INFO
)
# INFO will show the the messages "Refreshing lock" message
def
info
(
*
args
):
_logger
.
info
(
' '
.
join
(
str
(
a
)
for
a
in
args
))
def
debug
(
*
args
):
_logger
.
debug
(
' '
.
join
(
str
(
a
)
for
a
in
args
))
def
warning
(
*
args
):
_logger
.
warning
(
' '
.
join
(
str
(
a
)
for
a
in
args
))
def
error
(
*
args
):
_logger
.
error
(
' '
.
join
(
str
(
a
)
for
a
in
args
))
# In seconds, time that a process will wait before deciding to override an
# existing lock. An override only happens when the existing lock is held by
...
...
@@ -51,8 +62,9 @@ def get_lock():
# our lock after their 'timeout_before_override' timeout period.
now
=
time
.
time
()
if
now
-
get_lock
.
start_time
>
refresh_every
:
print
'Refreshing lock'
refresh_lock
(
os
.
path
.
join
(
get_lock
.
lock_dir
,
'lock'
))
lockpath
=
os
.
path
.
join
(
get_lock
.
lock_dir
,
'lock'
)
info
(
'Refreshing lock'
,
lockpath
)
refresh_lock
(
lockpath
)
get_lock
.
start_time
=
now
get_lock
.
n_lock
+=
1
...
...
@@ -151,8 +163,9 @@ def lock(tmp_dir, timeout=120, min_wait=5, max_wait=10, verbosity=1):
time_start
=
time
.
time
()
no_display
=
(
verbosity
==
0
)
if
not
no_display
:
print
'Waiting for existing lock by
%
s (I am
%
s)'
%
(
read_owner
,
my_pid
)
info
(
'Waiting for existing lock by
%
s (I am
%
s)'
%
(
read_owner
,
my_pid
))
info
(
"To manually release the lock, delete"
,
lock_file
)
if
verbosity
<=
1
:
no_display
=
True
time
.
sleep
(
random
.
uniform
(
min_wait
,
max_wait
))
...
...
theano/sandbox/conv.py
浏览文件 @
6905a821
...
...
@@ -253,7 +253,8 @@ class ConvOp(Op):
#The copy make that we return an object with the same stride as the c version.
#The copy don't affect the performence during our experience as in that case we
#execute the c version which is much faster.
zz
=
zz
[:,:,
0
::
self
.
dx
,
0
::
self
.
dy
]
.
copy
()
if
self
.
dx
>
1
or
self
.
dy
>
1
:
zz
=
zz
[:,:,
0
::
self
.
dx
,
0
::
self
.
dy
]
.
copy
()
#print 'zz (%s)'%str((self.dx, self.dy)), zz
z
[
0
]
=
zz
...
...
@@ -438,6 +439,18 @@ using namespace std;
def
convolve2
(
kerns
,
kshp
,
nkern
,
images
,
imshp
,
bsize
,
step
=
(
1
,
1
),
bias
=
None
,
mode
=
'valid'
,
**
d
):
"""
param kerns: kernel tensor
param kshp: tuple(kern row, kern wid)
param nkern: int the number of kernel
param images:image tensor
param imshp: tuple([stack size,] image row, image wid)
param bsize: batch size
param step: subsampling to apply to the output tuple(row, wid)
param bias: if True, will add a bias
param mode: 'valid' or 'full'
return: tuple(theano graph with the output of ConvOp flattened to 2 dimensions, ?)
"""
#TODO: remove the bias argument from this function because convolution has nothing to do with a bias
# if imshp, is a tuple, images contains one input dimension
...
...
@@ -461,7 +474,6 @@ def convolve2(kerns, kshp, nkern, images, imshp, bsize, step=(1,1),
rval
=
tensor
.
flatten
(
convout
,
2
)
return
rval
,
N
.
hstack
((
nkern
,
convop
.
outshp
))
_conv_op_code_a
=
"""
const int mode=
%(mode)
s;
int typenum=0, typenum_f=0;
...
...
theano/sandbox/test_conv.py
浏览文件 @
6905a821
...
...
@@ -434,13 +434,13 @@ class TestConvOp(unittest.TestCase):
print
' TEST ConvOp.grad'
print
'*************************************************'
nkern
=
4
bsize
=
3
nkern
=
3
bsize
=
2
types
=
[
"float32"
,
"float64"
]
kshps
=
[(
3
,
4
)]
imshps
=
[(
2
,
8
,
7
)]
kshps
=
[(
2
,
3
)]
imshps
=
[(
2
,
3
,
4
)]
modes
=
[
'valid'
,
'full'
]
unroll
=
[(
0
,
0
),(
1
,
1
),(
1
,
4
),(
3
,
1
),(
3
,
4
)]
unroll
=
[(
0
,
0
),(
1
,
1
),(
2
,
3
)]
ssizes
=
[(
1
,
1
),(
2
,
2
)]
for
typ
in
types
:
...
...
@@ -449,18 +449,16 @@ class TestConvOp(unittest.TestCase):
for
mode
in
modes
:
for
imshp
in
imshps
:
visdim
=
1
if
len
(
imshp
)
!=
3
else
imshp
[
0
]
imgvals
=
N
.
array
(
N
.
random
.
random
(
N
.
hstack
((
bsize
,
imshp
))),
dtype
=
imgs
.
dtype
)
for
kshp
in
kshps
:
t
=
numpy
.
array
([
imshp
[
1
]
-
kshp
[
0
],
imshp
[
2
]
-
kshp
[
1
]])
kernvals
=
N
.
array
(
N
.
random
.
rand
(
nkern
,
visdim
,
kshp
[
0
],
kshp
[
1
]),
dtype
=
kerns
.
dtype
)
# 'full' mode should support kernels bigger than the input
if
mode
==
'valid'
and
(
t
<
0
)
.
any
():
continue
for
un_b
,
un_k
in
unroll
:
for
ss
in
ssizes
:
imgvals
=
N
.
array
(
N
.
random
.
random
(
N
.
hstack
((
bsize
,
imshp
))),
dtype
=
imgs
.
dtype
)
kernvals
=
N
.
array
(
N
.
random
.
rand
(
nkern
,
visdim
,
kshp
[
0
],
kshp
[
1
]),
dtype
=
kerns
.
dtype
)
print
'test_ConvOpGrad'
print
'mode type:'
,
mode
,
typ
print
'imshp:'
,
imshp
...
...
@@ -472,19 +470,15 @@ class TestConvOp(unittest.TestCase):
print
'nkern:'
,
4
def
test_i
(
imgs
):
out
,
outshp
=
convolve2
(
kernvals
,
kshp
,
nkern
,
imgs
,
imshp
,
bsize
,
mode
=
mode
,
step
=
ss
,
unroll_batch
=
un_b
,
unroll_kern
=
un_k
)
return
out
convop
=
ConvOp
(
imshp
,
kshp
,
nkern
,
bsize
,
ss
[
0
],
ss
[
1
],
output_mode
=
mode
,
unroll_batch
=
un_b
,
unroll_kern
=
un_k
)
return
convop
(
imgs
,
kernvals
)
def
test_k
(
kerns
):
out
,
outshp
=
convolve2
(
kerns
,
kshp
,
nkern
,
imgvals
,
imshp
,
bsize
,
mode
=
mode
,
step
=
ss
,
unroll_batch
=
un_b
,
unroll_kern
=
un_k
)
return
out
convop
=
ConvOp
(
imshp
,
kshp
,
nkern
,
bsize
,
ss
[
0
],
ss
[
1
],
output_mode
=
mode
,
unroll_batch
=
un_b
,
unroll_kern
=
un_k
)
return
convop
(
imgvals
,
kerns
)
#TODO the tolerance needed to pass is very high for float32(0.17). Is this acceptable? Expected?
utt
.
verify_grad
(
test_i
,
[
imgvals
],
cast_to_output_type
=
True
,
...
...
theano/tensor/basic.py
浏览文件 @
6905a821
...
...
@@ -2891,12 +2891,17 @@ def verify_grad(op, pt, n_tests=2, rng=None, eps=None, tol=None, mode=None, cast
the given tolerance.
:param op: something that behaves like an Op instance with a single output
(can be a python function combining multiple ops)
(can be a python function combining multiple ops
, but see note below
)
:param pt: the list of numpy.ndarrays to use as inputs to the op
:param n_tests: number of times to run the test
:param rng: random number generator from which to draw random samples
:param eps: stepsize used in the Finite Difference Method (Default None is type-dependent)
:param tol: relative tolerance used as threshold for gradient comparison
:note: WARNING to unit-test writers: if `op` is a function that builds a graph,
try to make it a SMALL graph. Often verify grad is run in
debug mode, which can be very slow if it has to verify a lot
of intermediate computations.
"""
pt
=
[
numpy
.
array
(
p
)
for
p
in
pt
]
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
6905a821
...
...
@@ -13,8 +13,7 @@ from theano import pprint
import
numpy
#import scalar_opt
from
theano.compile.debugmode
import
DebugMode
from
theano
import
function
from
theano
import
function
,
compile
def
inputs
(
xbc
=
(
0
,
0
),
ybc
=
(
0
,
0
),
zbc
=
(
0
,
0
)):
...
...
@@ -182,6 +181,18 @@ class test_canonize(unittest.TestCase):
gof
.
TopoOptimizer
(
gof
.
LocalOptGroup
(
local_fill_cut
,
local_fill_lift
),
order
=
'out_to_in'
)
.
optimize
(
g
)
print
pprint
(
g
.
outputs
[
0
])
def
test_elemwise_multiple_inputs_optimisation
(
self
):
"""
verify that the Canonizer merge sequential Elemwise({mul,add})
"""
x
,
y
,
z
=
matrices
(
'xyz'
)
for
g
,
n
in
[
(
x
+
y
+
z
,
1
),
(
x
*
y
*
z
,
1
),
(
x
*
y
*
(
x
+
y
+
z
),
2
),
]:
f
=
compile
.
function
([
x
,
y
,
z
],
g
,
mode
=
compile
.
Mode
(
optimizer
=
'fast_run'
))
assert
(
len
(
f
.
maker
.
env
.
toposort
())
==
n
)
def
test_mixeddiv
():
"""Test that int division is preserved"""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论