Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
61493b72
提交
61493b72
authored
5月 11, 2011
作者:
Olivier Delalleau
浏览文件
操作
浏览文件
下载
差异文件
Merged
上级
b065fdc4
80e32e42
隐藏空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
66 行增加
和
27 行删除
+66
-27
neighbours.py
theano/sandbox/neighbours.py
+3
-3
rng_mrg.py
theano/sandbox/rng_mrg.py
+5
-5
basic.py
theano/scalar/basic.py
+6
-1
test_basic.py
theano/scalar/tests/test_basic.py
+3
-3
basic.py
theano/tensor/basic.py
+8
-4
Conv3D.py
theano/tensor/nnet/Conv3D.py
+3
-3
opt.py
theano/tensor/opt.py
+18
-3
test_basic.py
theano/tensor/tests/test_basic.py
+2
-2
test_opt.py
theano/tensor/tests/test_opt.py
+5
-2
test_tutorial.py
theano/tests/test_tutorial.py
+13
-1
没有找到文件。
theano/sandbox/neighbours.py
浏览文件 @
61493b72
...
@@ -246,13 +246,13 @@ def neibs2images(neibs, neib_shape, original_shape, mode='valid'):
...
@@ -246,13 +246,13 @@ def neibs2images(neibs, neib_shape, original_shape, mode='valid'):
neib_shape
=
T
.
as_tensor_variable
(
neib_shape
)
neib_shape
=
T
.
as_tensor_variable
(
neib_shape
)
original_shape
=
T
.
as_tensor_variable
(
original_shape
)
original_shape
=
T
.
as_tensor_variable
(
original_shape
)
new_neib_shape
=
T
.
stack
(
original_shape
[
-
1
]
/
neib_shape
[
1
],
neib_shape
[
1
]
)
new_neib_shape
=
T
.
stack
(
original_shape
[
-
1
]
//
neib_shape
[
1
],
neib_shape
[
1
]
)
output_2d
=
images2neibs
(
neibs
.
dimshuffle
(
'x'
,
'x'
,
0
,
1
),
new_neib_shape
,
mode
=
mode
)
output_2d
=
images2neibs
(
neibs
.
dimshuffle
(
'x'
,
'x'
,
0
,
1
),
new_neib_shape
,
mode
=
mode
)
if
mode
==
'ignore_borders'
:
if
mode
==
'ignore_borders'
:
valid_shape
=
list
(
original_shape
)
valid_shape
=
list
(
original_shape
)
valid_shape
[
2
]
=
valid_shape
[
2
]
/
neib_shape
[
0
]
*
neib_shape
[
0
]
valid_shape
[
2
]
=
(
valid_shape
[
2
]
//
neib_shape
[
0
])
*
neib_shape
[
0
]
valid_shape
[
3
]
=
valid_shape
[
3
]
/
neib_shape
[
1
]
*
neib_shape
[
1
]
valid_shape
[
3
]
=
(
valid_shape
[
3
]
//
neib_shape
[
1
])
*
neib_shape
[
1
]
output_4d
=
output_2d
.
reshape
(
valid_shape
)
output_4d
=
output_2d
.
reshape
(
valid_shape
)
#padding the borders with zeros
#padding the borders with zeros
for
d
in
[
2
,
3
]:
for
d
in
[
2
,
3
]:
...
...
theano/sandbox/rng_mrg.py
浏览文件 @
61493b72
...
@@ -263,7 +263,7 @@ class mrg_uniform(mrg_uniform_base):
...
@@ -263,7 +263,7 @@ class mrg_uniform(mrg_uniform_base):
if (
%(size)
s->dimensions[0] !=
%(ndim)
s)
if (
%(size)
s->dimensions[0] !=
%(ndim)
s)
{
{
PyErr_Format(PyExc_ValueError, "size must have length
%%
i (not
%%
i)",
PyErr_Format(PyExc_ValueError, "size must have length
%%
i (not
%%
i)",
%(ndim)
s,
%(size)
s->dimensions[0]
);
%(ndim)
s,
int(
%(size)
s->dimensions[0])
);
%(fail)
s
%(fail)
s
}
}
if (
%(size)
s->descr->type_num != PyArray_INT32)
if (
%(size)
s->descr->type_num != PyArray_INT32)
...
@@ -789,11 +789,11 @@ class MRG_RandomStreams(object):
...
@@ -789,11 +789,11 @@ class MRG_RandomStreams(object):
flattened
=
self
.
uniform
(
size
=
(
n_samples
,),
dtype
=
dtype
)
flattened
=
self
.
uniform
(
size
=
(
n_samples
,),
dtype
=
dtype
)
if
constant
:
if
constant
:
U1
=
flattened
[:
n_samples
/
2
]
U1
=
flattened
[:
n_samples
//
2
]
U2
=
flattened
[
n_samples
/
2
:]
U2
=
flattened
[
n_samples
//
2
:]
else
:
else
:
U1
=
flattened
[:
prod
(
flattened
.
shape
)
/
2
]
U1
=
flattened
[:
prod
(
flattened
.
shape
)
//
2
]
U2
=
flattened
[
prod
(
flattened
.
shape
)
/
2
:]
U2
=
flattened
[
prod
(
flattened
.
shape
)
//
2
:]
#normal_samples = zeros_like(flattened)
#normal_samples = zeros_like(flattened)
sqrt_ln_U1
=
sqrt
(
-
2.0
*
log
(
U1
))
sqrt_ln_U1
=
sqrt
(
-
2.0
*
log
(
U1
))
...
...
theano/scalar/basic.py
浏览文件 @
61493b72
...
@@ -27,6 +27,11 @@ builtin_int = int
...
@@ -27,6 +27,11 @@ builtin_int = int
builtin_float
=
float
builtin_float
=
float
class
IntegerDivisionError
(
Exception
):
"""Raised if someone tries to divide integers with '/' instead of '//'."""
pass
def
upcast
(
dtype
,
*
dtypes
):
def
upcast
(
dtype
,
*
dtypes
):
# Should we try to keep float32 instead of float64? This is used so that
# Should we try to keep float32 instead of float64? This is used so that
# for instance mixing int64 with float32 yields float32 instead of float64.
# for instance mixing int64 with float32 yields float32 instead of float64.
...
@@ -1028,7 +1033,7 @@ def div_proxy(x, y):
...
@@ -1028,7 +1033,7 @@ def div_proxy(x, y):
# Following discussion on theano-dev ("Inconsistent behavior in integer
# Following discussion on theano-dev ("Inconsistent behavior in integer
# division"), we will change the semantics of "/" on integer types in
# division"), we will change the semantics of "/" on integer types in
# Theano 0.4. Until then, it is forbidden to use "/" on integers.
# Theano 0.4. Until then, it is forbidden to use "/" on integers.
raise
NotImplemented
Error
(
raise
IntegerDivision
Error
(
"Dividing two integers with '/' is forbidden until Theano v0.4"
"Dividing two integers with '/' is forbidden until Theano v0.4"
" is released (where the result will be a floating point "
" is released (where the result will be a floating point "
"number). In the meantime, please either use '//' for integer "
"number). In the meantime, please either use '//' for integer "
...
...
theano/scalar/tests/test_basic.py
浏览文件 @
61493b72
...
@@ -182,9 +182,9 @@ class test_div(unittest.TestCase):
...
@@ -182,9 +182,9 @@ class test_div(unittest.TestCase):
d
=
float64
()
d
=
float64
()
f
=
float32
()
f
=
float32
()
print
(
a
/
b
)
.
owner
.
op
print
(
a
/
/
b
)
.
owner
.
op
assert
isinstance
((
a
/
b
)
.
owner
.
op
,
IntDiv
)
assert
isinstance
((
a
/
/
b
)
.
owner
.
op
,
IntDiv
)
assert
isinstance
((
b
/
a
)
.
owner
.
op
,
IntDiv
)
assert
isinstance
((
b
/
/
a
)
.
owner
.
op
,
IntDiv
)
assert
isinstance
((
b
/
d
)
.
owner
.
op
,
TrueDiv
)
assert
isinstance
((
b
/
d
)
.
owner
.
op
,
TrueDiv
)
assert
isinstance
((
b
/
f
)
.
owner
.
op
,
TrueDiv
)
assert
isinstance
((
b
/
f
)
.
owner
.
op
,
TrueDiv
)
assert
isinstance
((
f
/
a
)
.
owner
.
op
,
TrueDiv
)
assert
isinstance
((
f
/
a
)
.
owner
.
op
,
TrueDiv
)
...
...
theano/tensor/basic.py
浏览文件 @
61493b72
...
@@ -7,6 +7,7 @@ import sys # for sys.maxint
...
@@ -7,6 +7,7 @@ import sys # for sys.maxint
from
theano.configparser
import
config
,
AddConfigVar
,
BoolParam
from
theano.configparser
import
config
,
AddConfigVar
,
BoolParam
import
traceback
#for overriding Op.__call__
import
traceback
#for overriding Op.__call__
import
warnings
import
warnings
from
itertools
import
izip
import
numpy
,
theano
import
numpy
,
theano
#from copy import copy as python_copy
#from copy import copy as python_copy
...
@@ -23,6 +24,9 @@ from theano.gof.python25 import partial, any, all
...
@@ -23,6 +24,9 @@ from theano.gof.python25 import partial, any, all
from
theano
import
compile
,
printing
from
theano
import
compile
,
printing
from
theano.printing
import
pprint
from
theano.printing
import
pprint
# We use this exception as well.
from
theano.scalar
import
IntegerDivisionError
### set up the external interface
### set up the external interface
from
elemwise
import
Elemwise
,
DimShuffle
,
CAReduce
,
Sum
from
elemwise
import
Elemwise
,
DimShuffle
,
CAReduce
,
Sum
...
@@ -1138,7 +1142,7 @@ class _tensor_py_operators:
...
@@ -1138,7 +1142,7 @@ class _tensor_py_operators:
def
__div__
(
self
,
other
):
def
__div__
(
self
,
other
):
try
:
try
:
return
div_proxy
(
self
,
other
)
return
div_proxy
(
self
,
other
)
except
NotImplemented
Error
:
except
IntegerDivision
Error
:
# This is to raise the exception that occurs when trying to divide
# This is to raise the exception that occurs when trying to divide
# two integer arrays (currently forbidden).
# two integer arrays (currently forbidden).
raise
raise
...
@@ -2579,7 +2583,7 @@ def div_proxy(x, y):
...
@@ -2579,7 +2583,7 @@ def div_proxy(x, y):
if
(
as_tensor_variable
(
x
)
.
dtype
in
discrete_dtypes
and
if
(
as_tensor_variable
(
x
)
.
dtype
in
discrete_dtypes
and
as_tensor_variable
(
y
)
.
dtype
in
discrete_dtypes
):
as_tensor_variable
(
y
)
.
dtype
in
discrete_dtypes
):
# See the same in scalar/basic.py
# See the same in scalar/basic.py
raise
NotImplemented
Error
(
raise
IntegerDivision
Error
(
"Dividing two integer arrays with '/' is forbidden until "
"Dividing two integer arrays with '/' is forbidden until "
"Theano v0.4 is released (where the result will be a floating "
"Theano v0.4 is released (where the result will be a floating "
"point number). In the meantime, please either use '//' for "
"point number). In the meantime, please either use '//' for "
...
@@ -2921,7 +2925,7 @@ class Subtensor(Op):
...
@@ -2921,7 +2925,7 @@ class Subtensor(Op):
padded
=
(
actual_idx_list
+
padded
=
(
actual_idx_list
+
[
slice
(
None
,
None
,
None
)]
*
(
len
(
xshp
)
-
len
(
self
.
idx_list
)))
[
slice
(
None
,
None
,
None
)]
*
(
len
(
xshp
)
-
len
(
self
.
idx_list
)))
i
=
0
i
=
0
for
idx
,
xl
in
zip
(
padded
,
xshp
):
for
idx
,
xl
in
i
zip
(
padded
,
xshp
):
if
isinstance
(
idx
,
slice
):
if
isinstance
(
idx
,
slice
):
# If it is the default (None, None, None) slice, or a variant,
# If it is the default (None, None, None) slice, or a variant,
# the shape will be xl
# the shape will be xl
...
@@ -2931,7 +2935,7 @@ class Subtensor(Op):
...
@@ -2931,7 +2935,7 @@ class Subtensor(Op):
outshp
.
append
(
xl
)
outshp
.
append
(
xl
)
else
:
else
:
cnf
=
get_canonical_form_slice
(
idx
,
xl
)
cnf
=
get_canonical_form_slice
(
idx
,
xl
)
length
=
(
cnf
[
0
]
.
stop
-
cnf
[
0
]
.
start
-
1
)
/
cnf
[
0
]
.
step
+
1
length
=
(
cnf
[
0
]
.
stop
-
cnf
[
0
]
.
start
-
1
)
//
cnf
[
0
]
.
step
+
1
length
=
switch
(
lt
(
length
,
0
),
0
,
length
)
length
=
switch
(
lt
(
length
,
0
),
0
,
length
)
outshp
.
append
(
length
)
outshp
.
append
(
length
)
i
+=
1
i
+=
1
...
...
theano/tensor/nnet/Conv3D.py
浏览文件 @
61493b72
...
@@ -135,9 +135,9 @@ class Conv3D(theano.Op):
...
@@ -135,9 +135,9 @@ class Conv3D(theano.Op):
vidDur
=
V_shape
[
3
]
vidDur
=
V_shape
[
3
]
filterDur
=
W_shape
[
3
]
filterDur
=
W_shape
[
3
]
output_height
=
T
.
floor
(
(
vidHeight
-
filterHeight
)
/
dr
)
+
1
output_height
=
T
.
floor
(
(
vidHeight
-
filterHeight
)
//
dr
)
+
1
output_width
=
T
.
floor
(
(
vidWidth
-
filterWidth
)
/
dc
)
+
1
output_width
=
T
.
floor
(
(
vidWidth
-
filterWidth
)
//
dc
)
+
1
output_dur
=
T
.
floor
(
(
vidDur
-
filterDur
)
/
dt
)
+
1
output_dur
=
T
.
floor
(
(
vidDur
-
filterDur
)
//
dt
)
+
1
rval
=
(
batch_size
,
output_height
,
output_width
,
output_dur
,
output_channels
)
rval
=
(
batch_size
,
output_height
,
output_width
,
output_dur
,
output_channels
)
...
...
theano/tensor/opt.py
浏览文件 @
61493b72
...
@@ -32,6 +32,12 @@ from basic import get_constant_value
...
@@ -32,6 +32,12 @@ from basic import get_constant_value
# Utilities
# Utilities
class
ShapeError
(
Exception
):
"""Raised when the shape cannot be computed."""
pass
def
out2in
(
*
local_opts
):
def
out2in
(
*
local_opts
):
"""WRITEME """
"""WRITEME """
return
opt
.
TopoOptimizer
(
opt
.
LocalOptGroup
(
*
local_opts
),
return
opt
.
TopoOptimizer
(
opt
.
LocalOptGroup
(
*
local_opts
),
...
@@ -528,7 +534,7 @@ class ShapeFeature(object):
...
@@ -528,7 +534,7 @@ class ShapeFeature(object):
the cost of many Ops accurately, and generate c-code that is specific [e.g. unrolled] to
the cost of many Ops accurately, and generate c-code that is specific [e.g. unrolled] to
particular sizes.
particular sizes.
I
f you can determine the shape only in some case, return NotImplementedError when you can't
I
n cases where you cannot figure out the shape, raise a ShapeError.
.. note::
.. note::
...
@@ -714,13 +720,22 @@ class ShapeFeature(object):
...
@@ -714,13 +720,22 @@ class ShapeFeature(object):
try
:
try
:
o_shapes
=
shape_infer
(
node
,
[
self
.
shape_of
[
r
]
for
r
in
node
.
inputs
])
o_shapes
=
shape_infer
(
node
,
[
self
.
shape_of
[
r
]
for
r
in
node
.
inputs
])
except
NotImplemented
Error
:
except
Shape
Error
:
o_shapes
=
self
.
default_infer_shape
(
node
,
[
self
.
shape_of
[
r
]
for
r
in
node
.
inputs
])
o_shapes
=
self
.
default_infer_shape
(
node
,
[
self
.
shape_of
[
r
]
for
r
in
node
.
inputs
])
except
NotImplementedError
,
e
:
raise
NotImplementedError
(
'Code called by infer_shape failed raising a '
'NotImplementedError. Raising NotImplementedError to '
'indicate that a shape cannot be computed is no longer '
'supported, and one should now use tensor.opt.ShapeError '
'instead. The original exception message is:
%
s'
%
e
)
except
Exception
,
e
:
except
Exception
,
e
:
_logger
.
error
(
'Failed to infer_shape from Op
%
s (i_shapes=
%
s):
%
s
%
s'
%
(
node
.
op
,
_logger
.
error
(
'Failed to infer_shape from Op
%
s (i_shapes=
%
s):
%
s
%
s'
%
(
node
.
op
,
[
self
.
shape_of
[
r
]
for
r
in
node
.
inputs
],
[
self
.
shape_of
[
r
]
for
r
in
node
.
inputs
],
type
(
e
),
str
(
e
)))
type
(
e
),
str
(
e
)))
o_shapes
=
self
.
default_infer_shape
(
node
,
[
self
.
shape_of
[
r
]
for
r
in
node
.
inputs
])
# We raise the exception to make sure the user knows something bad
# is going on.
raise
# this is packed information
# this is packed information
# an element of o_shapes is either None or a tuple
# an element of o_shapes is either None or a tuple
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
61493b72
...
@@ -2734,9 +2734,9 @@ class T_divimpl(unittest.TestCase):
...
@@ -2734,9 +2734,9 @@ class T_divimpl(unittest.TestCase):
(
5.0
/
11.0
))
(
5.0
/
11.0
))
assert
numpy
.
allclose
(
function
([
i
,
ii
,
d
,
f
,
c
],
f
/
i
)(
5
,
3
,
7.0
,
11.0
,
numpy
.
complex
(
5
,
3
)),
assert
numpy
.
allclose
(
function
([
i
,
ii
,
d
,
f
,
c
],
f
/
i
)(
5
,
3
,
7.0
,
11.0
,
numpy
.
complex
(
5
,
3
)),
(
11.0
/
5.0
))
(
11.0
/
5.0
))
assert
numpy
.
allclose
(
function
([
i
,
ii
,
d
,
f
,
c
],
i
/
ii
)(
5
,
3
,
7.0
,
11.0
,
numpy
.
complex
(
5
,
3
)),
assert
numpy
.
allclose
(
function
([
i
,
ii
,
d
,
f
,
c
],
i
/
/
ii
)(
5
,
3
,
7.0
,
11.0
,
numpy
.
complex
(
5
,
3
)),
(
5
/
3
))
(
5
/
3
))
assert
numpy
.
allclose
(
function
([
i
,
ii
,
d
,
f
,
c
],
ii
/
i
)(
5
,
3
,
7.0
,
11.0
,
numpy
.
complex
(
5
,
3
)),
assert
numpy
.
allclose
(
function
([
i
,
ii
,
d
,
f
,
c
],
ii
/
/
i
)(
5
,
3
,
7.0
,
11.0
,
numpy
.
complex
(
5
,
3
)),
(
3
/
5
))
(
3
/
5
))
assert
numpy
.
allclose
(
function
([
i
,
ii
,
d
,
f
,
c
],
true_div
(
i
,
ii
))(
5
,
3
,
7.0
,
11.0
,
numpy
.
complex
(
5
,
3
)),
assert
numpy
.
allclose
(
function
([
i
,
ii
,
d
,
f
,
c
],
true_div
(
i
,
ii
))(
5
,
3
,
7.0
,
11.0
,
numpy
.
complex
(
5
,
3
)),
(
5.
/
3.
))
(
5.
/
3.
))
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
61493b72
...
@@ -647,10 +647,13 @@ def test_local_merge_abs():
...
@@ -647,10 +647,13 @@ def test_local_merge_abs():
def
test_mixeddiv
():
def
test_mixeddiv
():
"""Test that int division
is preserved
"""
"""Test that int division
raises an exception.
"""
i
=
iscalar
()
i
=
iscalar
()
d
=
dscalar
()
d
=
dscalar
()
assert
0
==
function
([
i
,
d
],
d
*
(
i
/
(
i
+
1
)))(
3
,
1.0
)
try
:
0
==
function
([
i
,
d
],
d
*
(
i
/
(
i
+
1
)))(
3
,
1.0
)
except
theano
.
scalar
.
IntegerDivisionError
:
pass
def
test_const_type_in_mul_canonizer
():
def
test_const_type_in_mul_canonizer
():
input
=
dmatrix
()
input
=
dmatrix
()
...
...
theano/tests/test_tutorial.py
浏览文件 @
61493b72
""" test code snippet in the Theano tutorials.
""" test code snippet in the Theano tutorials.
"""
"""
import
unittest
import
os
,
unittest
import
theano
import
theano
import
theano.tensor
as
T
import
theano.tensor
as
T
from
theano
import
function
from
theano
import
function
...
@@ -722,6 +722,15 @@ class T_loading_and_saving(unittest.TestCase):
...
@@ -722,6 +722,15 @@ class T_loading_and_saving(unittest.TestCase):
mode_instance
=
theano
.
compile
.
mode
.
get_mode
(
None
)
mode_instance
=
theano
.
compile
.
mode
.
get_mode
(
None
)
if
not
isinstance
(
mode_instance
,
theano
.
compile
.
debugmode
.
DebugMode
):
if
not
isinstance
(
mode_instance
,
theano
.
compile
.
debugmode
.
DebugMode
):
if
os
.
path
.
exists
(
'obj.save'
)
or
os
.
path
.
exists
(
'objects.save'
):
# We do not want to delete these files silently, in case for
# some reason they would be something else than test-generated
# files.
# Ideally we would save those files in a temporary directory...
raise
AssertionError
(
'Please get rid of files obj.save and '
'objects.save in directory
%
s'
%
os
.
getcwd
())
f
=
file
(
'obj.save'
,
'wb'
)
f
=
file
(
'obj.save'
,
'wb'
)
cPickle
.
dump
(
my_obj
,
f
,
protocol
=
cPickle
.
HIGHEST_PROTOCOL
)
cPickle
.
dump
(
my_obj
,
f
,
protocol
=
cPickle
.
HIGHEST_PROTOCOL
)
f
.
close
()
f
.
close
()
...
@@ -746,6 +755,9 @@ class T_loading_and_saving(unittest.TestCase):
...
@@ -746,6 +755,9 @@ class T_loading_and_saving(unittest.TestCase):
loaded_objects
.
append
(
cPickle
.
load
(
f
))
loaded_objects
.
append
(
cPickle
.
load
(
f
))
f
.
close
()
f
.
close
()
# Cleanup created files.
os
.
remove
(
'obj.save'
)
os
.
remove
(
'objects.save'
)
class
T_modes
(
unittest
.
TestCase
):
class
T_modes
(
unittest
.
TestCase
):
## All tests here belog to
## All tests here belog to
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论