Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2c9fa876
提交
2c9fa876
authored
3月 29, 2012
作者:
lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #573 from delallea/minor
Minor stuff (PEP8 and typos mostly)
上级
d2240bdd
cdd84aa4
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
71 行增加
和
51 行删除
+71
-51
NEWS.txt
NEWS.txt
+4
-4
config.txt
doc/library/config.txt
+8
-8
debugmode.py
theano/compile/debugmode.py
+1
-1
cmodule.py
theano/gof/cmodule.py
+1
-1
unify.py
theano/gof/unify.py
+1
-1
basic.py
theano/sparse/basic.py
+11
-6
basic.py
theano/tensor/basic.py
+45
-30
没有找到文件。
NEWS.txt
浏览文件 @
2c9fa876
...
@@ -27,9 +27,9 @@ Interface changes
...
@@ -27,9 +27,9 @@ Interface changes
instance, function([x, y], [y]). You can use the kwarg
instance, function([x, y], [y]). You can use the kwarg
``on_unused_input={'raise', 'warn', 'ignore'}`` to control this.
``on_unused_input={'raise', 'warn', 'ignore'}`` to control this.
(Pascal L.)
(Pascal L.)
* tensor.alloc() now raise an error during graph build time
* tensor.alloc() now raise
s
an error during graph build time
when we try to create less dimensions th
e
n the number of dimensions
when we try to create less dimensions th
a
n the number of dimensions
the provi
e
ded value have. In the past, the error was at run time.
the provided value have. In the past, the error was at run time.
(Frederic B.)
(Frederic B.)
New Features
New Features
...
@@ -48,7 +48,7 @@ New Features
...
@@ -48,7 +48,7 @@ New Features
contains dimensions with bad value like 0. (Frédéric B. reported by Ian G.)
contains dimensions with bad value like 0. (Frédéric B. reported by Ian G.)
Sparse
Sparse
* Implement theano.sparse.mul(sparse1, sparse2) when both input don't
* Implement theano.sparse.mul(sparse1, sparse2) when both input
s
don't
have the same sparsity pattern. (Frederic B.)
have the same sparsity pattern. (Frederic B.)
Sparse Sandbox graduate
Sparse Sandbox graduate
...
...
doc/library/config.txt
浏览文件 @
2c9fa876
...
@@ -519,8 +519,8 @@ import theano and print the config variable, as in:
...
@@ -519,8 +519,8 @@ import theano and print the config variable, as in:
Bool value, default: False
Bool value, default: False
Should
all SeqOptimizer object print the time taked
by each of its
Should
each SeqOptimizer object print the time taken
by each of its
optimizer. Each SeqOptimizer print something like this:
optimizer. Each SeqOptimizer print
s
something like this:
SeqOptimizer gpu_opt time 0.014s for 8/9 nodes before/after optimization
SeqOptimizer gpu_opt time 0.014s for 8/9 nodes before/after optimization
[(0.0004410743713378906, ('InputToGpuOptimizer',
[(0.0004410743713378906, ('InputToGpuOptimizer',
...
@@ -529,11 +529,11 @@ import theano and print the config variable, as in:
...
@@ -529,11 +529,11 @@ import theano and print the config variable, as in:
(0.012573957443237305, ('gpu_local_optimizations',
(0.012573957443237305, ('gpu_local_optimizations',
'EquilibriumOptimizer'))]
'EquilibriumOptimizer'))]
This print the name of the SeqOptimizer (gpu_opt), the number of
This print
s
the name of the SeqOptimizer (gpu_opt), the number of
Apply node in the graph before (8) and after (9)
Apply node
s
in the graph before (8) and after (9)
optimizations. Then a list of tuple
with 1 tuple by
optimization
optimizations. Then a list of tuple
s with 1 tuple per
optimization
in this SeqOptimizer. The first element of the tuple is the time
in this SeqOptimizer. The first element of the tuple is the time
by this optimization and then it is a tuple with the name of the
taken
by this optimization and then it is a tuple with the name of the
optimization and this class. This list is sorted from the sub
optimization and this class. This list is sorted from the sub
optimization that take
the most time to the optimization that take
optimization that take
s the most time to the optimization that takes
the le
ss
time.
the le
ast
time.
theano/compile/debugmode.py
浏览文件 @
2c9fa876
...
@@ -1064,7 +1064,7 @@ def _get_preallocated_maps(node, thunk, prealloc_modes, def_val,
...
@@ -1064,7 +1064,7 @@ def _get_preallocated_maps(node, thunk, prealloc_modes, def_val,
del
f_cont_outputs
del
f_cont_outputs
# We assume that the different outputs of a same Op will behave
# We assume that the different outputs of a same Op will behave
# independ
a
ntly, and there is no need to test over all combinations
# independ
e
ntly, and there is no need to test over all combinations
# of outputs (the time taken is prohibitive).
# of outputs (the time taken is prohibitive).
max_ndim
=
0
max_ndim
=
0
for
r
in
node
.
outputs
:
for
r
in
node
.
outputs
:
...
...
theano/gof/cmodule.py
浏览文件 @
2c9fa876
...
@@ -1431,7 +1431,7 @@ class GCC_compiler(object):
...
@@ -1431,7 +1431,7 @@ class GCC_compiler(object):
preargs
.
append
(
'-fPIC'
)
preargs
.
append
(
'-fPIC'
)
if
sys
.
platform
==
'win32'
and
local_bitwidth
()
==
64
:
if
sys
.
platform
==
'win32'
and
local_bitwidth
()
==
64
:
# Under 64-bit
s w
indows installation, sys.platform is 'win32'.
# Under 64-bit
W
indows installation, sys.platform is 'win32'.
# We need to define MS_WIN64 for the preprocessor to be able to
# We need to define MS_WIN64 for the preprocessor to be able to
# link with libpython.
# link with libpython.
preargs
.
append
(
'-DMS_WIN64'
)
preargs
.
append
(
'-DMS_WIN64'
)
...
...
theano/gof/unify.py
浏览文件 @
2c9fa876
...
@@ -95,7 +95,7 @@ class Unification:
...
@@ -95,7 +95,7 @@ class Unification:
def
__init__
(
self
,
inplace
=
False
):
def
__init__
(
self
,
inplace
=
False
):
"""
"""
If inplace is False, the merge method will return a new Unification
If inplace is False, the merge method will return a new Unification
that is independ
a
nt from the previous one (which allows backtracking).
that is independ
e
nt from the previous one (which allows backtracking).
"""
"""
self
.
unif
=
{}
self
.
unif
=
{}
self
.
inplace
=
inplace
self
.
inplace
=
inplace
...
...
theano/sparse/basic.py
浏览文件 @
2c9fa876
...
@@ -147,14 +147,17 @@ def verify_grad_sparse(op, pt, structured=False, *args, **kwargs):
...
@@ -147,14 +147,17 @@ def verify_grad_sparse(op, pt, structured=False, *args, **kwargs):
Converts sparse variables back and forth.
Converts sparse variables back and forth.
"""
"""
conv_none
=
lambda
x
:
x
conv_none
=
lambda
x
:
x
def
conv_csr
(
ind
,
indptr
,
shp
):
def
conv_csr
(
ind
,
indptr
,
shp
):
def
f
(
spdata
):
def
f
(
spdata
):
return
CSR
(
spdata
,
ind
,
indptr
,
shp
)
return
CSR
(
spdata
,
ind
,
indptr
,
shp
)
return
f
return
f
def
conv_csc
(
ind
,
indptr
,
shp
):
def
conv_csc
(
ind
,
indptr
,
shp
):
def
f
(
spdata
):
def
f
(
spdata
):
return
CSC
(
spdata
,
ind
,
indptr
,
shp
)
return
CSC
(
spdata
,
ind
,
indptr
,
shp
)
return
f
return
f
iconv
=
[]
iconv
=
[]
dpt
=
[]
dpt
=
[]
...
@@ -189,10 +192,12 @@ def verify_grad_sparse(op, pt, structured=False, *args, **kwargs):
...
@@ -189,10 +192,12 @@ def verify_grad_sparse(op, pt, structured=False, *args, **kwargs):
oconv
=
DenseFromSparse
(
structured
=
structured
)
oconv
=
DenseFromSparse
(
structured
=
structured
)
else
:
else
:
oconv
=
conv_none
oconv
=
conv_none
def
conv_op
(
*
inputs
):
def
conv_op
(
*
inputs
):
ipt
=
[
conv
(
i
)
for
i
,
conv
in
zip
(
inputs
,
iconv
)]
ipt
=
[
conv
(
i
)
for
i
,
conv
in
zip
(
inputs
,
iconv
)]
out
=
op
(
*
ipt
)
out
=
op
(
*
ipt
)
return
oconv
(
out
)
return
oconv
(
out
)
return
utt
.
verify_grad
(
conv_op
,
dpt
,
*
args
,
**
kwargs
)
return
utt
.
verify_grad
(
conv_op
,
dpt
,
*
args
,
**
kwargs
)
verify_grad_sparse
.
E_grad
=
utt
.
verify_grad
.
E_grad
verify_grad_sparse
.
E_grad
=
utt
.
verify_grad
.
E_grad
...
@@ -746,7 +751,7 @@ class DenseFromSparse(gof.op.Op):
...
@@ -746,7 +751,7 @@ class DenseFromSparse(gof.op.Op):
(
self
.
sparse_grad
==
other
.
sparse_grad
)
(
self
.
sparse_grad
==
other
.
sparse_grad
)
def
__hash__
(
self
):
def
__hash__
(
self
):
return
hash
(
type
(
self
))
^
hash
(
self
.
sparse_grad
)
return
hash
(
type
(
self
))
^
hash
(
self
.
sparse_grad
)
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s{structured_grad=
%
s}"
%
(
return
"
%
s{structured_grad=
%
s}"
%
(
...
@@ -1180,8 +1185,8 @@ class MulSS(gof.op.Op):
...
@@ -1180,8 +1185,8 @@ class MulSS(gof.op.Op):
assert
_is_sparse
(
x
)
and
_is_sparse
(
y
)
assert
_is_sparse
(
x
)
and
_is_sparse
(
y
)
assert
len
(
x
.
shape
)
==
2
assert
len
(
x
.
shape
)
==
2
assert
y
.
shape
==
x
.
shape
assert
y
.
shape
==
x
.
shape
# This call the element-wise multiple
# This call
s
the element-wise multiple
# x * y call dot...
# x * y call
s
dot...
out
[
0
]
=
x
.
multiply
(
y
)
out
[
0
]
=
x
.
multiply
(
y
)
def
grad
(
self
,
(
x
,
y
),
(
gz
,)):
def
grad
(
self
,
(
x
,
y
),
(
gz
,)):
...
...
theano/tensor/basic.py
浏览文件 @
2c9fa876
...
@@ -515,8 +515,8 @@ def get_constant_value(v):
...
@@ -515,8 +515,8 @@ def get_constant_value(v):
# TODO: implement the case where we take a scalar in a matrix
# TODO: implement the case where we take a scalar in a matrix
assert
len
(
v
.
owner
.
op
.
idx_list
)
==
v
.
owner
.
inputs
[
0
]
.
ndim
assert
len
(
v
.
owner
.
op
.
idx_list
)
==
v
.
owner
.
inputs
[
0
]
.
ndim
#
Needed to make better graph in this test.
#
Needed to make better graph in this test in theano/tensor/tests:
#
theano/tensor/tests/
test_sharedvar.py:test_shared_options.test_specify_shape_partial
#
test_sharedvar.py:test_shared_options.test_specify_shape_partial
if
(
v
.
owner
.
inputs
[
0
]
.
owner
and
if
(
v
.
owner
.
inputs
[
0
]
.
owner
and
isinstance
(
v
.
owner
.
inputs
[
0
]
.
owner
.
op
,
Join
)
and
isinstance
(
v
.
owner
.
inputs
[
0
]
.
owner
.
op
,
Join
)
and
# Ensure the Join is joining only scalar variables (so that
# Ensure the Join is joining only scalar variables (so that
...
@@ -956,9 +956,9 @@ class TensorType(Type):
...
@@ -956,9 +956,9 @@ class TensorType(Type):
return
"""
return
"""
%(name)
s = NULL;
%(name)
s = NULL;
if (py_
%(name)
s == Py_None) {
if (py_
%(name)
s == Py_None) {
// We can either fail here or set
%(name)
s to NULL and rely on Ops
using
// We can either fail here or set
%(name)
s to NULL and rely on Ops
//
tensors to handle the NULL case, but if they fail to do so they'll end up
//
using tensors to handle the NULL case, but if they fail to do so
// with nasty segfaults, so this is public service.
//
they'll end up
with nasty segfaults, so this is public service.
PyErr_SetString(PyExc_ValueError, "expected an ndarray, not None");
PyErr_SetString(PyExc_ValueError, "expected an ndarray, not None");
%(fail)
s
%(fail)
s
}
}
...
@@ -966,15 +966,19 @@ class TensorType(Type):
...
@@ -966,15 +966,19 @@ class TensorType(Type):
PyErr_SetString(PyExc_ValueError, "expected an ndarray");
PyErr_SetString(PyExc_ValueError, "expected an ndarray");
%(fail)
s
%(fail)
s
}
}
type_num_
%(name)
s = ((PyArrayObject*)py_
%(name)
s)->descr->type_num; //we expect
%(type_num)
s
// We expect
%(type_num)
s
type_num_
%(name)
s = ((PyArrayObject*)py_
%(name)
s)->descr->type_num;
if (!PyArray_ISALIGNED(py_
%(name)
s)) {
if (!PyArray_ISALIGNED(py_
%(name)
s)) {
PyErr_Format(PyExc_NotImplementedError,
PyErr_Format(PyExc_NotImplementedError,
"expected an aligned array of type
%%
d (
%(type_num)
s), got non-aligned array of type
%%
d",
"expected an aligned array of type
%%
d "
"(
%(type_num)
s), got non-aligned array of type
%%
d",
%(type_num)
s, type_num_
%(name)
s);
%(type_num)
s, type_num_
%(name)
s);
%(fail)
s
%(fail)
s
}
}
if (type_num_
%(name)
s !=
%(type_num)
s) {
if (type_num_
%(name)
s !=
%(type_num)
s) {
PyErr_Format(PyExc_ValueError, "expected type_num
%%
d (
%(type_num)
s) got
%%
d",
%(type_num)
s, type_num_
%(name)
s);
PyErr_Format(PyExc_ValueError,
"expected type_num
%%
d (
%(type_num)
s) got
%%
d",
%(type_num)
s, type_num_
%(name)
s);
%(fail)
s
%(fail)
s
}
}
%(name)
s = (PyArrayObject*)(py_
%(name)
s);
%(name)
s = (PyArrayObject*)(py_
%(name)
s);
...
@@ -2713,12 +2717,12 @@ if 0:
...
@@ -2713,12 +2717,12 @@ if 0:
## TODO (DOCUMENT AND WRITE TESTS) OR DELETE
## TODO (DOCUMENT AND WRITE TESTS) OR DELETE
class
Filler
(
gof
.
Op
):
class
Filler
(
gof
.
Op
):
"""WRITEME"""
"""WRITEME"""
def
__init__
(
self
,
value
,
ndim
,
dtype
=
'float64'
):
def
__init__
(
self
,
value
,
ndim
,
dtype
=
'float64'
):
self
.
value
=
value
self
.
value
=
value
self
.
ndim
=
ndim
self
.
ndim
=
ndim
self
.
dtype
=
dtype
self
.
dtype
=
dtype
self
.
type
=
TensorType
(
dtype
=
dtype
,
self
.
type
=
TensorType
(
dtype
=
dtype
,
broadcastable
=
(
False
,)
*
ndim
)
broadcastable
=
(
False
,)
*
ndim
)
def
make_node
(
self
,
dims
):
def
make_node
(
self
,
dims
):
dims
=
as_tensor_variable
(
dims
)
dims
=
as_tensor_variable
(
dims
)
...
@@ -2728,21 +2732,22 @@ if 0:
...
@@ -2728,21 +2732,22 @@ if 0:
dims
,
=
inp
dims
,
=
inp
out
,
=
out_
out
,
=
out_
if
out
[
0
]
is
not
None
:
if
out
[
0
]
is
not
None
:
out
[
0
]
.
resize
(
dims
,
refcheck
=
0
)
out
[
0
]
.
resize
(
dims
,
refcheck
=
0
)
out
[
0
]
.
fill
(
self
.
value
)
out
[
0
]
.
fill
(
self
.
value
)
else
:
else
:
if
self
.
value
==
0
:
if
self
.
value
==
0
:
out
[
0
]
=
numpy
.
zeros
(
dims
,
dtype
=
self
.
dtype
)
out
[
0
]
=
numpy
.
zeros
(
dims
,
dtype
=
self
.
dtype
)
elif
self
.
value
==
1
:
elif
self
.
value
==
1
:
out
[
0
]
=
numpy
.
ones
(
dims
,
dtype
=
self
.
dtype
)
out
[
0
]
=
numpy
.
ones
(
dims
,
dtype
=
self
.
dtype
)
else
:
else
:
out
[
0
]
=
numpy
.
ones
(
dims
,
dtype
=
self
.
dtype
)
*
self
.
value
out
[
0
]
=
numpy
.
ones
(
dims
,
dtype
=
self
.
dtype
)
*
self
.
value
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
return
None
,
return
None
,
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
and
self
.
ndim
==
other
.
ndim
and
self
.
dtype
==
other
.
dtype
return
(
type
(
self
)
==
type
(
other
)
and
self
.
ndim
==
other
.
ndim
and
self
.
dtype
==
other
.
dtype
)
def
__hash__
(
self
):
def
__hash__
(
self
):
return
hash
(
self
.
ndim
)
^
hash
(
self
.
dtype
)
return
hash
(
self
.
ndim
)
^
hash
(
self
.
dtype
)
...
@@ -2765,8 +2770,14 @@ if 0:
...
@@ -2765,8 +2770,14 @@ if 0:
"""WRITEME"""
"""WRITEME"""
return
Ones
(
0
)([])
return
Ones
(
0
)([])
pprint
.
assign
(
lambda
pstate
,
r
:
r
.
owner
and
isinstance
(
r
.
owner
.
op
,
Filler
)
and
r
.
owner
.
op
.
value
==
0
,
printing
.
FunctionPrinter
(
'zeros'
))
pprint
.
assign
(
lambda
pstate
,
r
:
r
.
owner
and
pprint
.
assign
(
lambda
pstate
,
r
:
r
.
owner
and
isinstance
(
r
.
owner
.
op
,
Filler
)
and
r
.
owner
.
op
.
value
==
1
,
printing
.
FunctionPrinter
(
'ones'
))
isinstance
(
r
.
owner
.
op
,
Filler
)
and
r
.
owner
.
op
.
value
==
0
,
printing
.
FunctionPrinter
(
'zeros'
))
pprint
.
assign
(
lambda
pstate
,
r
:
r
.
owner
and
isinstance
(
r
.
owner
.
op
,
Filler
)
and
r
.
owner
.
op
.
value
==
1
,
printing
.
FunctionPrinter
(
'ones'
))
class
Alloc
(
gof
.
Op
):
class
Alloc
(
gof
.
Op
):
...
@@ -2802,8 +2813,8 @@ class Alloc(gof.Op):
...
@@ -2802,8 +2813,8 @@ class Alloc(gof.Op):
sh
=
[
as_tensor_variable
(
s
)
for
s
in
shape
]
sh
=
[
as_tensor_variable
(
s
)
for
s
in
shape
]
bcast
=
[]
bcast
=
[]
if
v
.
ndim
>
len
(
sh
):
if
v
.
ndim
>
len
(
sh
):
raise
TypeError
(
"
Alloc value to use have
more dimensions"
raise
TypeError
(
"
The Alloc value to use has
more dimensions"
" th
e
n the specified dimensions"
,
" th
a
n the specified dimensions"
,
v
.
ndim
,
len
(
sh
))
v
.
ndim
,
len
(
sh
))
for
i
,
s
in
enumerate
(
sh
):
for
i
,
s
in
enumerate
(
sh
):
if
s
.
type
.
dtype
[:
3
]
not
in
(
'int'
,
'uin'
):
if
s
.
type
.
dtype
[:
3
]
not
in
(
'int'
,
'uin'
):
...
@@ -3106,17 +3117,19 @@ if 0:
...
@@ -3106,17 +3117,19 @@ if 0:
assert
repeats
.
type
==
iscalar
assert
repeats
.
type
==
iscalar
assert
axis
.
type
==
iscalar
assert
axis
.
type
==
iscalar
broadcastable
=
[]
broadcastable
=
[]
for
i
,
x
in
enumerate
(
input
.
broadcastable
):
for
i
,
x
in
enumerate
(
input
.
broadcastable
):
if
i
==
axis
:
if
i
==
axis
:
broadcastable
+=
[
False
]
broadcastable
+=
[
False
]
else
:
else
:
broadcastable
+=
[
x
]
broadcastable
+=
[
x
]
type
=
TensorType
(
dtype
=
input
.
type
.
dtype
,
broadcastable
=
\
type
=
TensorType
(
dtype
=
input
.
type
.
dtype
,
broadcastable
)
broadcastable
=
broadcastable
)
#backport
#backport
#type = TensorType(dtype = input.type.dtype,
#type = TensorType(dtype=input.type.dtype,
# broadcastable = [False if i==axis else x for i, x in enumerate(input.broadcastable)])
# broadcastable=[
# False if i==axis else x
# for i, x in enumerate(input.broadcastable)])
return
gof
.
Apply
(
self
,
[
inputs
,
repeats
,
axis
],
[
type
()])
return
gof
.
Apply
(
self
,
[
inputs
,
repeats
,
axis
],
[
type
()])
def
perform
(
self
,
node
,
inp
,
out_
):
def
perform
(
self
,
node
,
inp
,
out_
):
...
@@ -3807,7 +3820,8 @@ class Subtensor(Op):
...
@@ -3807,7 +3820,8 @@ class Subtensor(Op):
if (!step)
if (!step)
{
{
Py_DECREF(xview);
Py_DECREF(xview);
PyErr_Format(PyExc_ValueError, "slice step cannot be zero");
PyErr_Format(PyExc_ValueError,
"slice step cannot be zero");
%(fail)
s;
%(fail)
s;
}
}
...
@@ -4209,7 +4223,8 @@ class IncSubtensor(Op):
...
@@ -4209,7 +4223,8 @@ class IncSubtensor(Op):
else
else
{
{
if (
%(z)
s) Py_DECREF(
%(z)
s);
if (
%(z)
s) Py_DECREF(
%(z)
s);
%(z)
s = (PyArrayObject*)PyArray_FromAny(py_
%(x)
s, NULL, 0, 0, NPY_ENSURECOPY, NULL);
%(z)
s = (PyArrayObject*)PyArray_FromAny(py_
%(x)
s, NULL, 0, 0,
NPY_ENSURECOPY, NULL);
}
}
"""
%
locals
()
"""
%
locals
()
...
@@ -5532,8 +5547,8 @@ def inverse_permutation(perm):
...
@@ -5532,8 +5547,8 @@ def inverse_permutation(perm):
# Advanced indexing
# Advanced indexing
#########################
#########################
#
#
# Should reproduce numpy's behaviour:
# Should reproduce numpy's behaviour
, see url
:
#
http://
docs.scipy.org/doc/numpy/reference/arrays.indexing.html#advanced-indexing
# docs.scipy.org/doc/numpy/reference/arrays.indexing.html#advanced-indexing
class
AdvancedSubtensor1
(
Op
):
class
AdvancedSubtensor1
(
Op
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论