Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
008579b5
提交
008579b5
authored
10月 21, 2020
作者:
Brandon T. Willard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Apply pyupgrade to theano.tensor
上级
4e04febf
全部展开
显示空白字符变更
内嵌
并排
正在显示
25 个修改的文件
包含
113 行增加
和
147 行删除
+113
-147
basic.py
theano/tensor/basic.py
+0
-0
blas.py
theano/tensor/blas.py
+5
-5
blas_c.py
theano/tensor/blas_c.py
+2
-2
blas_headers.py
theano/tensor/blas_headers.py
+1
-1
elemwise.py
theano/tensor/elemwise.py
+22
-34
elemwise_cgen.py
theano/tensor/elemwise_cgen.py
+3
-1
extra_ops.py
theano/tensor/extra_ops.py
+6
-4
io.py
theano/tensor/io.py
+1
-1
abstract_conv.py
theano/tensor/nnet/abstract_conv.py
+0
-0
bn.py
theano/tensor/nnet/bn.py
+1
-1
conv.py
theano/tensor/nnet/conv.py
+3
-3
corr.py
theano/tensor/nnet/corr.py
+8
-14
corr3d.py
theano/tensor/nnet/corr3d.py
+8
-14
nnet.py
theano/tensor/nnet/nnet.py
+1
-1
sigm.py
theano/tensor/nnet/sigm.py
+2
-2
opt.py
theano/tensor/opt.py
+17
-23
raw_random.py
theano/tensor/raw_random.py
+4
-7
shared_randomstreams.py
theano/tensor/shared_randomstreams.py
+1
-1
sharedvar.py
theano/tensor/sharedvar.py
+1
-2
pool.py
theano/tensor/signal/pool.py
+6
-6
sort.py
theano/tensor/sort.py
+2
-2
subtensor.py
theano/tensor/subtensor.py
+10
-13
type.py
theano/tensor/type.py
+4
-2
type_other.py
theano/tensor/type_other.py
+1
-1
var.py
theano/tensor/var.py
+4
-7
没有找到文件。
theano/tensor/basic.py
浏览文件 @
008579b5
差异被折叠。
点击展开。
theano/tensor/blas.py
浏览文件 @
008579b5
...
@@ -477,7 +477,7 @@ def _ldflags(ldflags_str, libs, flags, libs_dir, include_dir):
...
@@ -477,7 +477,7 @@ def _ldflags(ldflags_str, libs, flags, libs_dir, include_dir):
assert
t0
==
"-"
assert
t0
==
"-"
except
Exception
:
except
Exception
:
raise
ValueError
(
raise
ValueError
(
'invalid token "
%
s" in ldflags_str: "
%
s"'
%
(
t
,
ldflags_str
)
'invalid token "
{}" in ldflags_str: "{}"'
.
format
(
t
,
ldflags_str
)
)
)
if
libs_dir
and
t1
==
"L"
:
if
libs_dir
and
t1
==
"L"
:
rval
.
append
(
t
[
2
:])
rval
.
append
(
t
[
2
:])
...
@@ -800,7 +800,7 @@ class GemmRelated(Op):
...
@@ -800,7 +800,7 @@ class GemmRelated(Op):
def
build_gemm_call
(
self
):
def
build_gemm_call
(
self
):
if
hasattr
(
self
,
"inplace"
):
if
hasattr
(
self
,
"inplace"
):
setup_z_Nz_Sz
=
"if(
%
%(params)
s->inplace){
%
s}else{
%
s}"
%
(
setup_z_Nz_Sz
=
"if(
%
(params)
s->inplace){{{}}}else{{{}}}"
.
format
(
self
.
setup_z_Nz_Sz_inplace
,
self
.
setup_z_Nz_Sz_inplace
,
self
.
setup_z_Nz_Sz_outplace
,
self
.
setup_z_Nz_Sz_outplace
,
)
)
...
@@ -880,7 +880,7 @@ class Gemm(GemmRelated):
...
@@ -880,7 +880,7 @@ class Gemm(GemmRelated):
inplace_str
=
"inplace"
inplace_str
=
"inplace"
else
:
else
:
inplace_str
=
"no_inplace"
inplace_str
=
"no_inplace"
return
"
%
s{
%
s}"
%
(
self
.
__class__
.
__name__
,
inplace_str
)
return
"
{}{{{}}}"
.
format
(
self
.
__class__
.
__name__
,
inplace_str
)
def
__setstate__
(
self
,
dct
):
def
__setstate__
(
self
,
dct
):
self
.
__dict__
.
update
(
dct
)
self
.
__dict__
.
update
(
dct
)
...
@@ -1671,7 +1671,7 @@ class Dot22(GemmRelated):
...
@@ -1671,7 +1671,7 @@ class Dot22(GemmRelated):
if
node
.
inputs
[
0
]
.
type
.
dtype
.
startswith
(
"complex"
):
if
node
.
inputs
[
0
]
.
type
.
dtype
.
startswith
(
"complex"
):
raise
MethodNotDefined
(
"
%
s.c_code"
%
self
.
__class__
.
__name__
)
raise
MethodNotDefined
(
"
%
s.c_code"
%
self
.
__class__
.
__name__
)
if
len
(
self
.
c_libraries
())
<=
0
:
if
len
(
self
.
c_libraries
())
<=
0
:
return
super
(
Dot22
,
self
)
.
c_code
(
node
,
name
,
(
_x
,
_y
),
(
_zout
,),
sub
)
return
super
()
.
c_code
(
node
,
name
,
(
_x
,
_y
),
(
_zout
,),
sub
)
full_code
=
self
.
build_gemm_call
()
%
dict
(
locals
(),
**
sub
)
full_code
=
self
.
build_gemm_call
()
%
dict
(
locals
(),
**
sub
)
return
full_code
return
full_code
...
@@ -1941,7 +1941,7 @@ class Dot22Scalar(GemmRelated):
...
@@ -1941,7 +1941,7 @@ class Dot22Scalar(GemmRelated):
if
node
.
inputs
[
0
]
.
type
.
dtype
.
startswith
(
"complex"
):
if
node
.
inputs
[
0
]
.
type
.
dtype
.
startswith
(
"complex"
):
raise
MethodNotDefined
(
"
%
s.c_code"
%
self
.
__class__
.
__name__
)
raise
MethodNotDefined
(
"
%
s.c_code"
%
self
.
__class__
.
__name__
)
if
len
(
self
.
c_libraries
())
<=
0
:
if
len
(
self
.
c_libraries
())
<=
0
:
return
super
(
Dot22Scalar
,
self
)
.
c_code
(
node
,
name
,
(
_x
,
_y
),
(
_zout
,),
sub
)
return
super
()
.
c_code
(
node
,
name
,
(
_x
,
_y
),
(
_zout
,),
sub
)
full_code
=
self
.
build_gemm_call
()
%
dict
(
locals
(),
**
sub
)
full_code
=
self
.
build_gemm_call
()
%
dict
(
locals
(),
**
sub
)
return
full_code
return
full_code
...
...
theano/tensor/blas_c.py
浏览文件 @
008579b5
...
@@ -23,7 +23,7 @@ from theano.tensor.blas import (
...
@@ -23,7 +23,7 @@ from theano.tensor.blas import (
from
theano.tensor.opt
import
in2out
from
theano.tensor.opt
import
in2out
class
BaseBLAS
(
object
)
:
class
BaseBLAS
:
def
c_libraries
(
self
):
def
c_libraries
(
self
):
return
ldflags
()
return
ldflags
()
...
@@ -617,7 +617,7 @@ class CGemv(BaseBLAS, Gemv):
...
@@ -617,7 +617,7 @@ class CGemv(BaseBLAS, Gemv):
)
)
def
__init__
(
self
,
inplace
):
def
__init__
(
self
,
inplace
):
super
(
CGemv
,
self
)
.
__init__
(
inplace
)
super
()
.
__init__
(
inplace
)
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
y
,
alpha
,
A
,
x
,
beta
=
inp
y
,
alpha
,
A
,
x
,
beta
=
inp
...
...
theano/tensor/blas_headers.py
浏览文件 @
008579b5
...
@@ -770,7 +770,7 @@ def blas_header_text():
...
@@ -770,7 +770,7 @@ def blas_header_text():
"precision"
:
"d"
,
"precision"
:
"d"
,
}
}
if
not
common_code
or
not
template_code
:
if
not
common_code
or
not
template_code
:
raise
IO
Error
(
raise
OS
Error
(
"Unable to load NumPy implementation of BLAS functions from C source files."
"Unable to load NumPy implementation of BLAS functions from C source files."
)
)
blas_code
+=
common_code
blas_code
+=
common_code
...
...
theano/tensor/elemwise.py
浏览文件 @
008579b5
from
copy
import
copy
from
copy
import
copy
import
numpy
as
np
import
numpy
as
np
from
six
import
integer_types
import
theano
import
theano
from
theano
import
change_flags
,
gof
,
scalar
from
theano
import
change_flags
,
gof
,
scalar
...
@@ -175,7 +174,7 @@ class DimShuffle(COp):
...
@@ -175,7 +174,7 @@ class DimShuffle(COp):
# isinstance(x, integer_types) returning False for
# isinstance(x, integer_types) returning False for
# numpy integers. See
# numpy integers. See
# <http://projects.scipy.org/numpy/ticket/2235>.
# <http://projects.scipy.org/numpy/ticket/2235>.
if
not
isinstance
(
j
,
(
int
eger_types
,
np
.
integer
)):
if
not
isinstance
(
j
,
(
int
,
np
.
integer
)):
raise
TypeError
(
raise
TypeError
(
"DimShuffle indices must be python ints. "
"DimShuffle indices must be python ints. "
"Got: '
%
s' of type '
%
s'."
,
"Got: '
%
s' of type '
%
s'."
,
...
@@ -232,21 +231,17 @@ class DimShuffle(COp):
...
@@ -232,21 +231,17 @@ class DimShuffle(COp):
if
not
ib
==
self
.
input_broadcastable
:
if
not
ib
==
self
.
input_broadcastable
:
if
len
(
ib
)
!=
len
(
self
.
input_broadcastable
):
if
len
(
ib
)
!=
len
(
self
.
input_broadcastable
):
raise
TypeError
(
raise
TypeError
(
(
"The number of dimensions of the "
"The number of dimensions of the "
"input is incorrect for this op. Expected
%
s, got
%
s."
"input is incorrect for this op. Expected
%
s, got
%
s."
%
(
self
.
input_broadcastable
,
ib
)
%
(
self
.
input_broadcastable
,
ib
)
)
)
)
for
expected
,
b
in
zip
(
self
.
input_broadcastable
,
ib
):
for
expected
,
b
in
zip
(
self
.
input_broadcastable
,
ib
):
if
expected
is
True
and
b
is
False
:
if
expected
is
True
and
b
is
False
:
raise
TypeError
(
raise
TypeError
(
(
"The broadcastable pattern of the "
"The broadcastable pattern of the "
"input is incorrect for this op. Expected
%
s, got
%
s."
"input is incorrect for this op. Expected
%
s, got
%
s."
%
(
self
.
input_broadcastable
,
ib
)
%
(
self
.
input_broadcastable
,
ib
)
)
)
)
# else, expected == b or expected is False and b is True
# else, expected == b or expected is False and b is True
# Both case are good.
# Both case are good.
...
@@ -335,7 +330,7 @@ class DimShufflePrinter:
...
@@ -335,7 +330,7 @@ class DimShufflePrinter:
return
pstate
.
pprinter
.
process
(
r
)
return
pstate
.
pprinter
.
process
(
r
)
if
list
(
new_order
)
==
list
(
reversed
(
range
(
r
.
type
.
ndim
))):
if
list
(
new_order
)
==
list
(
reversed
(
range
(
r
.
type
.
ndim
))):
return
"
%
s.T"
%
pstate
.
pprinter
.
process
(
r
)
return
"
%
s.T"
%
pstate
.
pprinter
.
process
(
r
)
return
"DimShuffle{
%
s}(
%
s)"
%
(
return
"DimShuffle{
{{}}}({})"
.
format
(
", "
.
join
(
map
(
str
,
new_order
)),
", "
.
join
(
map
(
str
,
new_order
)),
pstate
.
pprinter
.
process
(
r
),
pstate
.
pprinter
.
process
(
r
),
)
)
...
@@ -417,13 +412,13 @@ second dimension
...
@@ -417,13 +412,13 @@ second dimension
self
.
name
=
name
self
.
name
=
name
self
.
scalar_op
=
scalar_op
self
.
scalar_op
=
scalar_op
self
.
inplace_pattern
=
inplace_pattern
self
.
inplace_pattern
=
inplace_pattern
self
.
destroy_map
=
dict
((
o
,
[
i
])
for
o
,
i
in
self
.
inplace_pattern
.
items
())
self
.
destroy_map
=
{
o
:
[
i
]
for
o
,
i
in
self
.
inplace_pattern
.
items
()}
if
nfunc_spec
is
None
:
if
nfunc_spec
is
None
:
nfunc_spec
=
getattr
(
scalar_op
,
"nfunc_spec"
,
None
)
nfunc_spec
=
getattr
(
scalar_op
,
"nfunc_spec"
,
None
)
self
.
nfunc_spec
=
nfunc_spec
self
.
nfunc_spec
=
nfunc_spec
self
.
__setstate__
(
self
.
__dict__
)
self
.
__setstate__
(
self
.
__dict__
)
super
(
Elemwise
,
self
)
.
__init__
(
openmp
=
openmp
)
super
()
.
__init__
(
openmp
=
openmp
)
def
__getstate__
(
self
):
def
__getstate__
(
self
):
d
=
copy
(
self
.
__dict__
)
d
=
copy
(
self
.
__dict__
)
...
@@ -433,7 +428,7 @@ second dimension
...
@@ -433,7 +428,7 @@ second dimension
return
d
return
d
def
__setstate__
(
self
,
d
):
def
__setstate__
(
self
,
d
):
super
(
Elemwise
,
self
)
.
__setstate__
(
d
)
super
()
.
__setstate__
(
d
)
self
.
ufunc
=
None
self
.
ufunc
=
None
self
.
nfunc
=
None
self
.
nfunc
=
None
self
.
inplace_pattern
=
frozendict
(
self
.
inplace_pattern
)
self
.
inplace_pattern
=
frozendict
(
self
.
inplace_pattern
)
...
@@ -528,7 +523,7 @@ second dimension
...
@@ -528,7 +523,7 @@ second dimension
if
self
.
inplace_pattern
:
if
self
.
inplace_pattern
:
items
=
list
(
self
.
inplace_pattern
.
items
())
items
=
list
(
self
.
inplace_pattern
.
items
())
items
.
sort
()
items
.
sort
()
return
"Elemwise{
%
s}
%
s"
%
(
self
.
scalar_op
,
str
(
items
))
return
"Elemwise{
{{}}}{}"
.
format
(
self
.
scalar_op
,
str
(
items
))
else
:
else
:
return
"Elemwise{
%
s}"
%
(
self
.
scalar_op
)
return
"Elemwise{
%
s}"
%
(
self
.
scalar_op
)
else
:
else
:
...
@@ -766,7 +761,7 @@ second dimension
...
@@ -766,7 +761,7 @@ second dimension
# ValueError, if the number of inputs to a ufunc is 32 or more.
# ValueError, if the number of inputs to a ufunc is 32 or more.
# In that case, the C version should be used, or Elemwise fusion
# In that case, the C version should be used, or Elemwise fusion
# should be disabled.
# should be disabled.
super
(
Elemwise
,
self
)
.
perform
(
node
,
inputs
,
output_storage
)
super
()
.
perform
(
node
,
inputs
,
output_storage
)
for
dims
in
zip
(
for
dims
in
zip
(
*
[
*
[
...
@@ -933,12 +928,9 @@ second dimension
...
@@ -933,12 +928,9 @@ second dimension
# The destroy map is a map of output indices to input indices
# The destroy map is a map of output indices to input indices
# that overwrite them. We just convert them to the actual
# that overwrite them. We just convert them to the actual
# Variables.
# Variables.
dmap
=
dict
(
dmap
=
{
[
node
.
outputs
[
o
]:
[
node
.
inputs
[
i
]]
for
o
,
i
in
self
.
inplace_pattern
.
items
()
(
node
.
outputs
[
o
],
[
node
.
inputs
[
i
]])
}
for
o
,
i
in
self
.
inplace_pattern
.
items
()
]
)
# dtypes of the inputs
# dtypes of the inputs
idtypes
=
[
input
.
type
.
dtype_specs
()[
1
]
for
input
in
inputs
]
idtypes
=
[
input
.
type
.
dtype_specs
()[
1
]
for
input
in
inputs
]
...
@@ -1091,7 +1083,7 @@ second dimension
...
@@ -1091,7 +1083,7 @@ second dimension
# No loops
# No loops
task_decl
=
""
.
join
(
task_decl
=
""
.
join
(
[
[
"
%
s&
%
s_i = *
%
s_iter;
\n
"
%
(
dtype
,
name
,
name
)
"
{}& {}_i = *{}_iter;
\n
"
.
format
(
dtype
,
name
,
name
)
for
name
,
dtype
in
zip
(
for
name
,
dtype
in
zip
(
inames
+
list
(
real_onames
),
idtypes
+
list
(
real_odtypes
)
inames
+
list
(
real_onames
),
idtypes
+
list
(
real_odtypes
)
)
)
...
@@ -1252,7 +1244,7 @@ second dimension
...
@@ -1252,7 +1244,7 @@ second dimension
getattr
(
self
.
scalar_op
,
"inner_float16"
,
False
)
getattr
(
self
.
scalar_op
,
"inner_float16"
,
False
)
):
):
# Disable C code for float16 vars
# Disable C code for float16 vars
super
(
Elemwise
,
self
)
.
c_code
(
node
,
nodename
,
inames
,
onames
,
sub
)
super
()
.
c_code
(
node
,
nodename
,
inames
,
onames
,
sub
)
code
=
"
\n
"
.
join
(
self
.
_c_all
(
node
,
nodename
,
inames
,
onames
,
sub
))
code
=
"
\n
"
.
join
(
self
.
_c_all
(
node
,
nodename
,
inames
,
onames
,
sub
))
return
code
return
code
...
@@ -1353,7 +1345,7 @@ class CAReduce(Op):
...
@@ -1353,7 +1345,7 @@ class CAReduce(Op):
def
__init__
(
self
,
scalar_op
,
axis
=
None
):
def
__init__
(
self
,
scalar_op
,
axis
=
None
):
if
scalar_op
.
nin
not
in
[
-
1
,
2
]
or
scalar_op
.
nout
!=
1
:
if
scalar_op
.
nin
not
in
[
-
1
,
2
]
or
scalar_op
.
nout
!=
1
:
raise
NotImplementedError
(
raise
NotImplementedError
(
(
"CAReduce only supports binary functions with a single "
"output."
)
"CAReduce only supports binary functions with a single "
"output."
)
)
self
.
scalar_op
=
scalar_op
self
.
scalar_op
=
scalar_op
...
@@ -1362,12 +1354,12 @@ class CAReduce(Op):
...
@@ -1362,12 +1354,12 @@ class CAReduce(Op):
# There is a bug in numpy that results in isinstance(x,
# There is a bug in numpy that results in isinstance(x,
# integer_types) returning False for numpy integers. See
# integer_types) returning False for numpy integers. See
# <http://projects.scipy.org/numpy/ticket/2235>.
# <http://projects.scipy.org/numpy/ticket/2235>.
elif
isinstance
(
axis
,
(
int
eger_types
,
np
.
integer
)):
elif
isinstance
(
axis
,
(
int
,
np
.
integer
)):
self
.
axis
=
(
axis
,)
self
.
axis
=
(
axis
,)
elif
isinstance
(
axis
,
np
.
ndarray
)
and
axis
.
ndim
==
0
:
elif
isinstance
(
axis
,
np
.
ndarray
)
and
axis
.
ndim
==
0
:
self
.
axis
=
(
int
(
axis
),)
self
.
axis
=
(
int
(
axis
),)
else
:
else
:
self
.
axis
=
list
(
set
(
int
(
a
)
for
a
in
axis
)
)
self
.
axis
=
list
(
{
int
(
a
)
for
a
in
axis
}
)
self
.
axis
.
sort
()
self
.
axis
.
sort
()
self
.
axis
=
tuple
(
self
.
axis
)
self
.
axis
=
tuple
(
self
.
axis
)
...
@@ -1408,11 +1400,9 @@ class CAReduce(Op):
...
@@ -1408,11 +1400,9 @@ class CAReduce(Op):
axis
<
0
and
abs
(
axis
)
>
input
.
type
.
ndim
axis
<
0
and
abs
(
axis
)
>
input
.
type
.
ndim
):
):
raise
ValueError
(
raise
ValueError
(
(
"Not enough dimensions on
%
s to reduce on axis
%
s"
"Not enough dimensions on
%
s to reduce on axis
%
s"
%
(
input
,
axis
)
%
(
input
,
axis
)
)
)
)
input
=
as_tensor_variable
(
input
)
input
=
as_tensor_variable
(
input
)
axis
=
self
.
axis
axis
=
self
.
axis
if
axis
is
None
:
if
axis
is
None
:
...
@@ -1452,7 +1442,7 @@ class CAReduce(Op):
...
@@ -1452,7 +1442,7 @@ class CAReduce(Op):
def
__str__
(
self
):
def
__str__
(
self
):
if
self
.
axis
is
not
None
:
if
self
.
axis
is
not
None
:
return
"Reduce{
%
s}{
%
s}"
%
(
return
"Reduce{
{{}}}{{{}}}"
.
format
(
self
.
scalar_op
,
self
.
scalar_op
,
", "
.
join
(
str
(
x
)
for
x
in
self
.
axis
),
", "
.
join
(
str
(
x
)
for
x
in
self
.
axis
),
)
)
...
@@ -1486,12 +1476,10 @@ class CAReduce(Op):
...
@@ -1486,12 +1476,10 @@ class CAReduce(Op):
variable
.
fill
(
self
.
scalar_op
.
identity
)
variable
.
fill
(
self
.
scalar_op
.
identity
)
else
:
else
:
raise
ValueError
(
raise
ValueError
(
(
"Input (
%
s) has zero-size on axis
%
s, but "
"Input (
%
s) has zero-size on axis
%
s, but "
"self.scalar_op (
%
s) has no attribute 'identity'"
"self.scalar_op (
%
s) has no attribute 'identity'"
%
(
variable
,
dimension
,
self
.
scalar_op
)
%
(
variable
,
dimension
,
self
.
scalar_op
)
)
)
)
else
:
else
:
variable
=
self
.
ufunc
.
reduce
(
variable
,
dimension
,
dtype
=
acc_dtype
)
variable
=
self
.
ufunc
.
reduce
(
variable
,
dimension
,
dtype
=
acc_dtype
)
...
@@ -1775,7 +1763,7 @@ class All(CAReduce):
...
@@ -1775,7 +1763,7 @@ class All(CAReduce):
input
=
as_tensor_variable
(
input
)
input
=
as_tensor_variable
(
input
)
if
input
.
dtype
!=
"bool"
:
if
input
.
dtype
!=
"bool"
:
input
=
theano
.
tensor
.
neq
(
input
,
0
)
input
=
theano
.
tensor
.
neq
(
input
,
0
)
ret
=
super
(
All
,
self
)
.
make_node
(
input
)
ret
=
super
()
.
make_node
(
input
)
return
ret
return
ret
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
...
@@ -1808,7 +1796,7 @@ class Any(CAReduce):
...
@@ -1808,7 +1796,7 @@ class Any(CAReduce):
input
=
as_tensor_variable
(
input
)
input
=
as_tensor_variable
(
input
)
if
input
.
dtype
!=
"bool"
:
if
input
.
dtype
!=
"bool"
:
input
=
theano
.
tensor
.
neq
(
input
,
0
)
input
=
theano
.
tensor
.
neq
(
input
,
0
)
ret
=
super
(
Any
,
self
)
.
make_node
(
input
)
ret
=
super
()
.
make_node
(
input
)
return
ret
return
ret
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
...
@@ -1877,7 +1865,7 @@ class CAReduceDtype(CAReduce):
...
@@ -1877,7 +1865,7 @@ class CAReduceDtype(CAReduce):
self
.
acc_dtype
=
acc_dtype
self
.
acc_dtype
=
acc_dtype
def
__setstate__
(
self
,
d
):
def
__setstate__
(
self
,
d
):
super
(
CAReduceDtype
,
self
)
.
__setstate__
(
d
)
super
()
.
__setstate__
(
d
)
if
not
hasattr
(
self
,
"dtype"
):
if
not
hasattr
(
self
,
"dtype"
):
# This is needed as old pickled will crash otherwise.
# This is needed as old pickled will crash otherwise.
# We need to keep the old dtype behavior as the op
# We need to keep the old dtype behavior as the op
...
@@ -1985,7 +1973,7 @@ class CAReduceDtype(CAReduce):
...
@@ -1985,7 +1973,7 @@ class CAReduceDtype(CAReduce):
if
self
.
axis
is
not
None
:
if
self
.
axis
is
not
None
:
axis
=
", "
.
join
(
str
(
x
)
for
x
in
self
.
axis
)
axis
=
", "
.
join
(
str
(
x
)
for
x
in
self
.
axis
)
axis
=
"axis=[
%
s], "
%
axis
axis
=
"axis=[
%
s], "
%
axis
return
"
%
s{
%
sacc_dtype=
%
s}"
%
(
name
,
axis
,
str
(
self
.
acc_dtype
))
return
"
{}{{{}acc_dtype={}}}"
.
format
(
name
,
axis
,
str
(
self
.
acc_dtype
))
class
Sum
(
CAReduceDtype
):
class
Sum
(
CAReduceDtype
):
...
@@ -2038,7 +2026,7 @@ class Sum(CAReduceDtype):
...
@@ -2038,7 +2026,7 @@ class Sum(CAReduceDtype):
if
self
.
axis
is
not
None
:
if
self
.
axis
is
not
None
:
axis
=
", "
.
join
(
str
(
x
)
for
x
in
self
.
axis
)
axis
=
", "
.
join
(
str
(
x
)
for
x
in
self
.
axis
)
axis
=
"axis=[
%
s], "
%
axis
axis
=
"axis=[
%
s], "
%
axis
return
"
%
s{
%
sacc_dtype=
%
s}"
%
(
name
,
axis
,
str
(
self
.
acc_dtype
))
return
"
{}{{{}acc_dtype={}}}"
.
format
(
name
,
axis
,
str
(
self
.
acc_dtype
))
def
L_op
(
self
,
inp
,
out
,
grads
):
def
L_op
(
self
,
inp
,
out
,
grads
):
(
x
,)
=
inp
(
x
,)
=
inp
...
@@ -2093,7 +2081,7 @@ class Prod(CAReduceDtype):
...
@@ -2093,7 +2081,7 @@ class Prod(CAReduceDtype):
self
.
no_zeros_in_input
=
no_zeros_in_input
self
.
no_zeros_in_input
=
no_zeros_in_input
def
__setstate__
(
self
,
dct
):
def
__setstate__
(
self
,
dct
):
super
(
Prod
,
self
)
.
__setstate__
(
dct
)
super
()
.
__setstate__
(
dct
)
# Add default value to be able to reload old pickled objects.
# Add default value to be able to reload old pickled objects.
if
"no_zeros_in_input"
not
in
dct
:
if
"no_zeros_in_input"
not
in
dct
:
self
.
no_zeros_in_input
=
False
self
.
no_zeros_in_input
=
False
...
...
theano/tensor/elemwise_cgen.py
浏览文件 @
008579b5
...
@@ -77,7 +77,9 @@ def make_checks(loop_orders, dtypes, sub):
...
@@ -77,7 +77,9 @@ def make_checks(loop_orders, dtypes, sub):
if
index
!=
"x"
:
if
index
!=
"x"
:
# Initialize the variables associated to the jth loop
# Initialize the variables associated to the jth loop
# jump = stride - adjust
# jump = stride - adjust
jump
=
"(
%
s) - (
%
s)"
%
(
"
%(var)
s_stride
%(index)
s"
%
locals
(),
adjust
)
jump
=
"({}) - ({})"
.
format
(
"
%(var)
s_stride
%(index)
s"
%
locals
(),
adjust
)
init
+=
(
init
+=
(
"""
"""
%(var)
s_n
%(index)
s = PyArray_DIMS(
%(var)
s)[
%(index)
s];
%(var)
s_n
%(index)
s = PyArray_DIMS(
%(var)
s)[
%(index)
s];
...
...
theano/tensor/extra_ops.py
浏览文件 @
008579b5
...
@@ -274,7 +274,7 @@ class CumOp(Op):
...
@@ -274,7 +274,7 @@ class CumOp(Op):
def
__init__
(
self
,
axis
=
None
,
mode
=
"add"
):
def
__init__
(
self
,
axis
=
None
,
mode
=
"add"
):
if
mode
not
in
(
"add"
,
"mul"
):
if
mode
not
in
(
"add"
,
"mul"
):
raise
ValueError
(
'
%
s: Unknown mode "
%
s"'
%
(
type
(
self
)
.
__name__
,
mode
))
raise
ValueError
(
'
{}: Unknown mode "{}"'
.
format
(
type
(
self
)
.
__name__
,
mode
))
self
.
axis
=
axis
self
.
axis
=
axis
self
.
mode
=
mode
self
.
mode
=
mode
...
@@ -287,7 +287,7 @@ class CumOp(Op):
...
@@ -287,7 +287,7 @@ class CumOp(Op):
if
self
.
axis
is
None
:
if
self
.
axis
is
None
:
out_type
=
theano
.
tensor
.
vector
(
dtype
=
x
.
dtype
)
# Flatten
out_type
=
theano
.
tensor
.
vector
(
dtype
=
x
.
dtype
)
# Flatten
elif
self
.
axis
>=
x
.
ndim
or
self
.
axis
<
-
x
.
ndim
:
elif
self
.
axis
>=
x
.
ndim
or
self
.
axis
<
-
x
.
ndim
:
raise
ValueError
(
"axis(={
0
}) out of bounds"
.
format
(
self
.
axis
))
raise
ValueError
(
"axis(={}) out of bounds"
.
format
(
self
.
axis
))
return
theano
.
Apply
(
self
,
[
x
],
[
out_type
])
return
theano
.
Apply
(
self
,
[
x
],
[
out_type
])
...
@@ -327,7 +327,9 @@ class CumOp(Op):
...
@@ -327,7 +327,9 @@ class CumOp(Op):
return
[
cumsum
((
fx
*
gi
)[
reverse_slicing
],
self
.
axis
)[
reverse_slicing
]
/
x
]
return
[
cumsum
((
fx
*
gi
)[
reverse_slicing
],
self
.
axis
)[
reverse_slicing
]
/
x
]
else
:
else
:
raise
NotImplementedError
(
raise
NotImplementedError
(
'
%
s: unknown gradient for mode "
%
s"'
%
(
type
(
self
)
.
__name__
,
self
.
mode
)
'{}: unknown gradient for mode "{}"'
.
format
(
type
(
self
)
.
__name__
,
self
.
mode
)
)
)
def
infer_shape
(
self
,
node
,
shapes
):
def
infer_shape
(
self
,
node
,
shapes
):
...
@@ -391,7 +393,7 @@ class CumOp(Op):
...
@@ -391,7 +393,7 @@ class CumOp(Op):
return
(
8
,)
return
(
8
,)
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s{
%
s,
%
s}"
%
(
self
.
__class__
.
__name__
,
self
.
axis
,
self
.
mode
)
return
"
{}{{{}, {}}}"
.
format
(
self
.
__class__
.
__name__
,
self
.
axis
,
self
.
mode
)
def
cumsum
(
x
,
axis
=
None
):
def
cumsum
(
x
,
axis
=
None
):
...
...
theano/tensor/io.py
浏览文件 @
008579b5
...
@@ -58,7 +58,7 @@ class LoadFromDisk(Op):
...
@@ -58,7 +58,7 @@ class LoadFromDisk(Op):
out
[
0
][
0
]
=
result
out
[
0
][
0
]
=
result
def
__str__
(
self
):
def
__str__
(
self
):
return
"Load{
dtype:
%
s, broadcastable:
%
s, mmep:
%
s}"
%
(
return
"Load{
{dtype: {}, broadcastable: {}, mmep: {}}}"
.
format
(
self
.
dtype
,
self
.
dtype
,
self
.
broadcastable
,
self
.
broadcastable
,
self
.
mmap_mode
,
self
.
mmap_mode
,
...
...
theano/tensor/nnet/abstract_conv.py
浏览文件 @
008579b5
差异被折叠。
点击展开。
theano/tensor/nnet/bn.py
浏览文件 @
008579b5
...
@@ -28,7 +28,7 @@ class BNComposite(Composite):
...
@@ -28,7 +28,7 @@ class BNComposite(Composite):
o
=
add
(
mul
(
true_div
(
sub
(
x
,
mean
),
std
),
gamma
),
beta
)
o
=
add
(
mul
(
true_div
(
sub
(
x
,
mean
),
std
),
gamma
),
beta
)
inputs
=
[
x
,
mean
,
std
,
gamma
,
beta
]
inputs
=
[
x
,
mean
,
std
,
gamma
,
beta
]
outputs
=
[
o
]
outputs
=
[
o
]
super
(
BNComposite
,
self
)
.
__init__
(
inputs
,
outputs
)
super
()
.
__init__
(
inputs
,
outputs
)
def
grad
(
self
,
inps
,
grads
):
def
grad
(
self
,
inps
,
grads
):
x
,
mean
,
std
,
gamma
,
beta
=
inps
x
,
mean
,
std
,
gamma
,
beta
=
inps
...
...
theano/tensor/nnet/conv.py
浏览文件 @
008579b5
...
@@ -488,7 +488,7 @@ class ConvOp(OpenMPOp):
...
@@ -488,7 +488,7 @@ class ConvOp(OpenMPOp):
)
)
# Init the openmp attribute
# Init the openmp attribute
super
(
ConvOp
,
self
)
.
__init__
(
openmp
=
openmp
)
super
()
.
__init__
(
openmp
=
openmp
)
if
not
all_shape
or
self
.
openmp
:
if
not
all_shape
or
self
.
openmp
:
# Only this version is parallelized
# Only this version is parallelized
unroll_patch
=
True
unroll_patch
=
True
...
@@ -687,7 +687,7 @@ class ConvOp(OpenMPOp):
...
@@ -687,7 +687,7 @@ class ConvOp(OpenMPOp):
return
True
return
True
def
__setstate__
(
self
,
d
):
def
__setstate__
(
self
,
d
):
super
(
ConvOp
,
self
)
.
__setstate__
(
d
)
super
()
.
__setstate__
(
d
)
self
.
direction_hint
=
d
.
get
(
"direction_hint"
,
None
)
self
.
direction_hint
=
d
.
get
(
"direction_hint"
,
None
)
self
.
_rehash
()
self
.
_rehash
()
...
@@ -1197,7 +1197,7 @@ using namespace std;
...
@@ -1197,7 +1197,7 @@ using namespace std;
if
theano
.
gof
.
cmodule
.
gcc_version
()
in
[
"4.3.0"
]
and
self
.
kshp
==
(
1
,
1
):
if
theano
.
gof
.
cmodule
.
gcc_version
()
in
[
"4.3.0"
]
and
self
.
kshp
==
(
1
,
1
):
ret
+=
[
"-O2"
]
ret
+=
[
"-O2"
]
# Add the -fopenmp flags
# Add the -fopenmp flags
ret
+=
super
(
ConvOp
,
self
)
.
c_compile_args
()
ret
+=
super
()
.
c_compile_args
()
return
ret
return
ret
...
...
theano/tensor/nnet/corr.py
浏览文件 @
008579b5
import
logging
import
logging
import
os
import
os
from
six
import
integer_types
import
theano
import
theano
from
theano
import
gof
from
theano
import
gof
from
theano.gof.graph
import
Apply
from
theano.gof.graph
import
Apply
...
@@ -86,8 +84,8 @@ class BaseCorrMM(gof.OpenMPOp):
...
@@ -86,8 +84,8 @@ class BaseCorrMM(gof.OpenMPOp):
unshared
=
False
,
unshared
=
False
,
openmp
=
None
,
openmp
=
None
,
):
):
super
(
BaseCorrMM
,
self
)
.
__init__
(
openmp
=
openmp
)
super
()
.
__init__
(
openmp
=
openmp
)
if
isinstance
(
border_mode
,
int
eger_types
):
if
isinstance
(
border_mode
,
int
):
if
border_mode
<
0
:
if
border_mode
<
0
:
raise
ValueError
(
raise
ValueError
(
"invalid border_mode {}, which must be a "
"invalid border_mode {}, which must be a "
...
@@ -175,7 +173,7 @@ class BaseCorrMM(gof.OpenMPOp):
...
@@ -175,7 +173,7 @@ class BaseCorrMM(gof.OpenMPOp):
padW_r
=
property
(
lambda
self
:
self
.
pad
[
1
][
1
])
padW_r
=
property
(
lambda
self
:
self
.
pad
[
1
][
1
])
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s{
%
s,
%
s,
%
s,
%
s
%
s}"
%
(
return
"
{}{{{}, {}, {}, {} {}}}"
.
format
(
self
.
__class__
.
__name__
,
self
.
__class__
.
__name__
,
self
.
border_mode
,
self
.
border_mode
,
str
(
self
.
subsample
),
str
(
self
.
subsample
),
...
@@ -210,7 +208,7 @@ class BaseCorrMM(gof.OpenMPOp):
...
@@ -210,7 +208,7 @@ class BaseCorrMM(gof.OpenMPOp):
def
c_compile_args
(
self
):
def
c_compile_args
(
self
):
compile_args
=
ldflags
(
libs
=
False
,
flags
=
True
)
compile_args
=
ldflags
(
libs
=
False
,
flags
=
True
)
compile_args
+=
super
(
BaseCorrMM
,
self
)
.
c_compile_args
()
compile_args
+=
super
()
.
c_compile_args
()
return
compile_args
return
compile_args
def
c_lib_dirs
(
self
):
def
c_lib_dirs
(
self
):
...
@@ -221,7 +219,7 @@ class BaseCorrMM(gof.OpenMPOp):
...
@@ -221,7 +219,7 @@ class BaseCorrMM(gof.OpenMPOp):
def
c_headers
(
self
):
def
c_headers
(
self
):
headers
=
[
"<stdio.h>"
]
headers
=
[
"<stdio.h>"
]
headers
+=
super
(
BaseCorrMM
,
self
)
.
c_headers
()
headers
+=
super
()
.
c_headers
()
return
headers
return
headers
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
...
@@ -710,7 +708,7 @@ class CorrMM(BaseCorrMM):
...
@@ -710,7 +708,7 @@ class CorrMM(BaseCorrMM):
def
c_code
(
self
,
node
,
nodename
,
inp
,
out_
,
sub
):
def
c_code
(
self
,
node
,
nodename
,
inp
,
out_
,
sub
):
bottom
,
weights
=
inp
bottom
,
weights
=
inp
(
top
,)
=
out_
(
top
,)
=
out_
return
super
(
CorrMM
,
self
)
.
c_code_helper
(
bottom
,
weights
,
top
,
sub
)
return
super
()
.
c_code_helper
(
bottom
,
weights
,
top
,
sub
)
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
bottom
,
weights
=
inp
bottom
,
weights
=
inp
...
@@ -835,9 +833,7 @@ class CorrMM_gradWeights(BaseCorrMM):
...
@@ -835,9 +833,7 @@ class CorrMM_gradWeights(BaseCorrMM):
bottom
,
top
=
inp
[:
2
]
bottom
,
top
=
inp
[:
2
]
height
,
width
=
inp
[
2
:]
or
(
None
,
None
)
height
,
width
=
inp
[
2
:]
or
(
None
,
None
)
(
weights
,)
=
out_
(
weights
,)
=
out_
return
super
(
CorrMM_gradWeights
,
self
)
.
c_code_helper
(
return
super
()
.
c_code_helper
(
bottom
,
weights
,
top
,
sub
,
height
,
width
)
bottom
,
weights
,
top
,
sub
,
height
,
width
)
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
bottom
,
top
=
inp
[:
2
]
bottom
,
top
=
inp
[:
2
]
...
@@ -969,9 +965,7 @@ class CorrMM_gradInputs(BaseCorrMM):
...
@@ -969,9 +965,7 @@ class CorrMM_gradInputs(BaseCorrMM):
weights
,
top
=
inp
[:
2
]
weights
,
top
=
inp
[:
2
]
height
,
width
=
inp
[
2
:]
or
(
None
,
None
)
height
,
width
=
inp
[
2
:]
or
(
None
,
None
)
(
bottom
,)
=
out_
(
bottom
,)
=
out_
return
super
(
CorrMM_gradInputs
,
self
)
.
c_code_helper
(
return
super
()
.
c_code_helper
(
bottom
,
weights
,
top
,
sub
,
height
,
width
)
bottom
,
weights
,
top
,
sub
,
height
,
width
)
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
weights
,
top
=
inp
[:
2
]
weights
,
top
=
inp
[:
2
]
...
...
theano/tensor/nnet/corr3d.py
浏览文件 @
008579b5
import
logging
import
logging
import
os
import
os
from
six
import
integer_types
import
theano
import
theano
from
theano
import
gof
from
theano
import
gof
from
theano.gof.graph
import
Apply
from
theano.gof.graph
import
Apply
...
@@ -77,8 +75,8 @@ class BaseCorr3dMM(gof.OpenMPOp):
...
@@ -77,8 +75,8 @@ class BaseCorr3dMM(gof.OpenMPOp):
openmp
=
None
,
openmp
=
None
,
num_groups
=
1
,
num_groups
=
1
,
):
):
super
(
BaseCorr3dMM
,
self
)
.
__init__
(
openmp
=
openmp
)
super
()
.
__init__
(
openmp
=
openmp
)
if
isinstance
(
border_mode
,
int
eger_types
):
if
isinstance
(
border_mode
,
int
):
if
border_mode
<
0
:
if
border_mode
<
0
:
raise
ValueError
(
raise
ValueError
(
"invalid border_mode {}, which must be a "
"invalid border_mode {}, which must be a "
...
@@ -159,7 +157,7 @@ class BaseCorr3dMM(gof.OpenMPOp):
...
@@ -159,7 +157,7 @@ class BaseCorr3dMM(gof.OpenMPOp):
padD
=
property
(
lambda
self
:
self
.
pad
[
2
])
padD
=
property
(
lambda
self
:
self
.
pad
[
2
])
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s{
%
s,
%
s,
%
s,
%
s}"
%
(
return
"
{}{{{}, {}, {}, {}}}"
.
format
(
self
.
__class__
.
__name__
,
self
.
__class__
.
__name__
,
self
.
border_mode
,
self
.
border_mode
,
str
(
self
.
subsample
),
str
(
self
.
subsample
),
...
@@ -193,7 +191,7 @@ class BaseCorr3dMM(gof.OpenMPOp):
...
@@ -193,7 +191,7 @@ class BaseCorr3dMM(gof.OpenMPOp):
def
c_compile_args
(
self
):
def
c_compile_args
(
self
):
compile_args
=
ldflags
(
libs
=
False
,
flags
=
True
)
compile_args
=
ldflags
(
libs
=
False
,
flags
=
True
)
compile_args
+=
super
(
BaseCorr3dMM
,
self
)
.
c_compile_args
()
compile_args
+=
super
()
.
c_compile_args
()
return
compile_args
return
compile_args
def
c_lib_dirs
(
self
):
def
c_lib_dirs
(
self
):
...
@@ -204,7 +202,7 @@ class BaseCorr3dMM(gof.OpenMPOp):
...
@@ -204,7 +202,7 @@ class BaseCorr3dMM(gof.OpenMPOp):
def
c_headers
(
self
):
def
c_headers
(
self
):
headers
=
[
"<stdio.h>"
]
headers
=
[
"<stdio.h>"
]
headers
+=
super
(
BaseCorr3dMM
,
self
)
.
c_headers
()
headers
+=
super
()
.
c_headers
()
return
headers
return
headers
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
...
@@ -650,7 +648,7 @@ class Corr3dMM(BaseCorr3dMM):
...
@@ -650,7 +648,7 @@ class Corr3dMM(BaseCorr3dMM):
def
c_code
(
self
,
node
,
nodename
,
inp
,
out_
,
sub
):
def
c_code
(
self
,
node
,
nodename
,
inp
,
out_
,
sub
):
bottom
,
weights
=
inp
bottom
,
weights
=
inp
(
top
,)
=
out_
(
top
,)
=
out_
return
super
(
Corr3dMM
,
self
)
.
c_code_helper
(
bottom
,
weights
,
top
,
sub
)
return
super
()
.
c_code_helper
(
bottom
,
weights
,
top
,
sub
)
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
bottom
,
weights
=
inp
bottom
,
weights
=
inp
...
@@ -764,9 +762,7 @@ class Corr3dMMGradWeights(BaseCorr3dMM):
...
@@ -764,9 +762,7 @@ class Corr3dMMGradWeights(BaseCorr3dMM):
bottom
,
top
=
inp
[:
2
]
bottom
,
top
=
inp
[:
2
]
height
,
width
,
depth
=
inp
[
2
:]
or
(
None
,
None
,
None
)
height
,
width
,
depth
=
inp
[
2
:]
or
(
None
,
None
,
None
)
(
weights
,)
=
out_
(
weights
,)
=
out_
return
super
(
Corr3dMMGradWeights
,
self
)
.
c_code_helper
(
return
super
()
.
c_code_helper
(
bottom
,
weights
,
top
,
sub
,
height
,
width
,
depth
)
bottom
,
weights
,
top
,
sub
,
height
,
width
,
depth
)
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
bottom
,
top
=
inp
[:
2
]
bottom
,
top
=
inp
[:
2
]
...
@@ -900,9 +896,7 @@ class Corr3dMMGradInputs(BaseCorr3dMM):
...
@@ -900,9 +896,7 @@ class Corr3dMMGradInputs(BaseCorr3dMM):
weights
,
top
=
inp
[:
2
]
weights
,
top
=
inp
[:
2
]
height
,
width
,
depth
=
inp
[
2
:]
or
(
None
,
None
,
None
)
height
,
width
,
depth
=
inp
[
2
:]
or
(
None
,
None
,
None
)
(
bottom
,)
=
out_
(
bottom
,)
=
out_
return
super
(
Corr3dMMGradInputs
,
self
)
.
c_code_helper
(
return
super
()
.
c_code_helper
(
bottom
,
weights
,
top
,
sub
,
height
,
width
,
depth
)
bottom
,
weights
,
top
,
sub
,
height
,
width
,
depth
)
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
weights
,
top
=
inp
[:
2
]
weights
,
top
=
inp
[:
2
]
...
...
theano/tensor/nnet/nnet.py
浏览文件 @
008579b5
...
@@ -2206,7 +2206,7 @@ class Prepend_scalar_constant_to_each_row(Op):
...
@@ -2206,7 +2206,7 @@ class Prepend_scalar_constant_to_each_row(Op):
self
.
val
=
val
self
.
val
=
val
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s{
%
s}"
%
(
self
.
__class__
.
__name__
,
self
.
val
)
return
"
{}{{{}}}"
.
format
(
self
.
__class__
.
__name__
,
self
.
val
)
def
make_node
(
self
,
mat
):
def
make_node
(
self
,
mat
):
# check type of input
# check type of input
...
...
theano/tensor/nnet/sigm.py
浏览文件 @
008579b5
...
@@ -91,7 +91,7 @@ class ScalarSigmoid(scalar.UnaryScalarOp):
...
@@ -91,7 +91,7 @@ class ScalarSigmoid(scalar.UnaryScalarOp):
raise
NotImplementedError
(
"only floatingpoint is implemented"
)
raise
NotImplementedError
(
"only floatingpoint is implemented"
)
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
v
=
super
(
ScalarSigmoid
,
self
)
.
c_code_cache_version
()
v
=
super
()
.
c_code_cache_version
()
if
v
:
if
v
:
return
(
2
,)
+
v
return
(
2
,)
+
v
else
:
else
:
...
@@ -404,7 +404,7 @@ class ScalarSoftplus(scalar.UnaryScalarOp):
...
@@ -404,7 +404,7 @@ class ScalarSoftplus(scalar.UnaryScalarOp):
raise
NotImplementedError
(
"only floatingpoint is implemented"
)
raise
NotImplementedError
(
"only floatingpoint is implemented"
)
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
v
=
super
(
ScalarSoftplus
,
self
)
.
c_code_cache_version
()
v
=
super
()
.
c_code_cache_version
()
if
v
:
if
v
:
return
(
2
,)
+
v
return
(
2
,)
+
v
else
:
else
:
...
...
theano/tensor/opt.py
浏览文件 @
008579b5
...
@@ -13,7 +13,7 @@ from collections import defaultdict
...
@@ -13,7 +13,7 @@ from collections import defaultdict
from
functools
import
reduce
from
functools
import
reduce
import
numpy
as
np
import
numpy
as
np
from
six
import
StringIO
,
integer_types
from
six
import
StringIO
import
theano
import
theano
import
theano.scalar.basic
as
ts
import
theano.scalar.basic
as
ts
...
@@ -515,7 +515,8 @@ class InplaceElemwiseOptimizer(Optimizer):
...
@@ -515,7 +515,8 @@ class InplaceElemwiseOptimizer(Optimizer):
def
print_summary
(
self
,
stream
=
sys
.
stdout
,
level
=
0
,
depth
=-
1
):
def
print_summary
(
self
,
stream
=
sys
.
stdout
,
level
=
0
,
depth
=-
1
):
print
(
print
(
"
%
s
%
s (
%
s)"
%
((
" "
*
level
),
self
.
__class__
.
__name__
,
self
.
op
),
file
=
stream
"{}{} ({})"
.
format
((
" "
*
level
),
self
.
__class__
.
__name__
,
self
.
op
),
file
=
stream
,
)
)
return
inplace_elemwise_optimizer
return
inplace_elemwise_optimizer
...
@@ -996,7 +997,7 @@ class MakeVectorPrinter:
...
@@ -996,7 +997,7 @@ class MakeVectorPrinter:
tt
.
pprint
.
assign
(
MakeVector
,
MakeVectorPrinter
())
tt
.
pprint
.
assign
(
MakeVector
,
MakeVectorPrinter
())
class
ShapeFeature
(
object
)
:
class
ShapeFeature
:
"""Graph optimizer for removing all calls to shape().
"""Graph optimizer for removing all calls to shape().
This optimizer replaces all Shapes and Subtensors of Shapes with
This optimizer replaces all Shapes and Subtensors of Shapes with
...
@@ -1222,12 +1223,10 @@ class ShapeFeature(object):
...
@@ -1222,12 +1223,10 @@ class ShapeFeature(object):
# don't make the optimizer merge a zillion ones together
# don't make the optimizer merge a zillion ones together
# by always returning the same object to represent 1
# by always returning the same object to represent 1
return
self
.
lscalar_one
return
self
.
lscalar_one
if
type
(
s_i
)
is
float
and
int
(
s_i
)
==
s_i
:
if
isinstance
(
s_i
,
float
)
and
int
(
s_i
)
==
s_i
:
s_i
=
int
(
s_i
)
s_i
=
int
(
s_i
)
if
(
if
isinstance
(
s_i
,
(
np
.
integer
,
int
))
or
(
type
(
s_i
)
in
integer_types
isinstance
(
s_i
,
np
.
ndarray
)
and
s_i
.
ndim
==
0
or
isinstance
(
s_i
,
np
.
integer
)
or
(
isinstance
(
s_i
,
np
.
ndarray
)
and
s_i
.
ndim
==
0
)
):
):
# this shape is a constant
# this shape is a constant
if
s_i
<
0
:
if
s_i
<
0
:
...
@@ -1241,7 +1240,7 @@ class ShapeFeature(object):
...
@@ -1241,7 +1240,7 @@ class ShapeFeature(object):
# message.
# message.
raise
AssertionError
(
msg
)
raise
AssertionError
(
msg
)
return
tt
.
constant
(
s_i
,
dtype
=
"int64"
)
return
tt
.
constant
(
s_i
,
dtype
=
"int64"
)
if
type
(
s_i
)
in
(
tuple
,
list
):
if
isinstance
(
s_i
,
(
tuple
,
list
)
):
# this dimension is the same as many of the inputs
# this dimension is the same as many of the inputs
# which tells us that if one of the inputs is known,
# which tells us that if one of the inputs is known,
# the others all become known.
# the others all become known.
...
@@ -1384,11 +1383,11 @@ class ShapeFeature(object):
...
@@ -1384,11 +1383,11 @@ class ShapeFeature(object):
# - Shape_i(i)(other_r);
# - Shape_i(i)(other_r);
# - Shape_i(i)(r).
# - Shape_i(i)(r).
merged_shape
.
append
(
r_shape
[
i
])
merged_shape
.
append
(
r_shape
[
i
])
elif
isinstance
(
r_shape
[
i
],
(
Constant
,
int
eger_types
)):
elif
isinstance
(
r_shape
[
i
],
(
Constant
,
int
)):
# We do this to call less often ancestors and make
# We do this to call less often ancestors and make
# sure we have the simplest shape possible.
# sure we have the simplest shape possible.
merged_shape
.
append
(
r_shape
[
i
])
merged_shape
.
append
(
r_shape
[
i
])
elif
isinstance
(
other_shape
[
i
],
(
Constant
,
int
eger_types
)):
elif
isinstance
(
other_shape
[
i
],
(
Constant
,
int
)):
# We do this to call less often ancestors and make
# We do this to call less often ancestors and make
# sure we have the simplest shape possible.
# sure we have the simplest shape possible.
merged_shape
.
append
(
other_shape
[
i
])
merged_shape
.
append
(
other_shape
[
i
])
...
@@ -2225,7 +2224,7 @@ def local_subtensor_remove_broadcastable_index(node):
...
@@ -2225,7 +2224,7 @@ def local_subtensor_remove_broadcastable_index(node):
elif
isinstance
(
elem
,
slice
):
elif
isinstance
(
elem
,
slice
):
if
elem
!=
slice
(
None
):
if
elem
!=
slice
(
None
):
return
return
elif
isinstance
(
elem
,
(
int
eger_types
,
np
.
integer
)):
elif
isinstance
(
elem
,
(
int
,
np
.
integer
)):
if
elem
in
[
0
,
-
1
]
and
node
.
inputs
[
0
]
.
broadcastable
[
dim
]:
if
elem
in
[
0
,
-
1
]
and
node
.
inputs
[
0
]
.
broadcastable
[
dim
]:
remove_dim
.
append
(
dim
)
remove_dim
.
append
(
dim
)
else
:
else
:
...
@@ -2277,7 +2276,7 @@ def local_subtensor_make_vector(node):
...
@@ -2277,7 +2276,7 @@ def local_subtensor_make_vector(node):
else
:
else
:
return
return
if
isinstance
(
idx
,
(
int
eger_types
,
np
.
integer
)):
if
isinstance
(
idx
,
(
int
,
np
.
integer
)):
# We don't need to copy over any stack traces here
# We don't need to copy over any stack traces here
return
[
x
.
owner
.
inputs
[
idx
]]
return
[
x
.
owner
.
inputs
[
idx
]]
elif
isinstance
(
idx
,
Variable
):
elif
isinstance
(
idx
,
Variable
):
...
@@ -3014,7 +3013,7 @@ def local_useless_subtensor(node):
...
@@ -3014,7 +3013,7 @@ def local_useless_subtensor(node):
length_pos
=
shape_of
[
node
.
inputs
[
0
]][
pos
]
length_pos
=
shape_of
[
node
.
inputs
[
0
]][
pos
]
if
isinstance
(
idx
.
stop
,
(
int
eger_types
,
np
.
integer
)):
if
isinstance
(
idx
.
stop
,
(
int
,
np
.
integer
)):
length_pos_data
=
sys
.
maxsize
length_pos_data
=
sys
.
maxsize
try
:
try
:
length_pos_data
=
get_scalar_constant_value
(
length_pos_data
=
get_scalar_constant_value
(
...
@@ -3281,13 +3280,11 @@ def merge_two_slices(slice1, len1, slice2, len2):
...
@@ -3281,13 +3280,11 @@ def merge_two_slices(slice1, len1, slice2, len2):
n_val
=
sl1
.
stop
-
1
-
sl2
*
sl1
.
step
n_val
=
sl1
.
stop
-
1
-
sl2
*
sl1
.
step
if
config
.
warn
.
subtensor_merge_bug
:
if
config
.
warn
.
subtensor_merge_bug
:
warnings
.
warning
(
warnings
.
warning
(
(
"Your current code is fine, but Theano versions "
"Your current code is fine, but Theano versions "
"prior to 0.5rc2 might have given an incorrect result. "
"prior to 0.5rc2 might have given an incorrect result. "
"To disable this warning, set the Theano flag "
"To disable this warning, set the Theano flag "
"warn.subtensor_merge_bug to False."
"warn.subtensor_merge_bug to False."
)
)
)
# we need to pick either n_val or p_val and then follow same
# we need to pick either n_val or p_val and then follow same
# steps as above for covering the index error cases
# steps as above for covering the index error cases
val
=
tt
.
switch
(
tt
.
lt
(
reverse1
,
0
),
n_val
,
p_val
)
val
=
tt
.
switch
(
tt
.
lt
(
reverse1
,
0
),
n_val
,
p_val
)
...
@@ -5467,7 +5464,7 @@ class Canonizer(LocalOptimizer):
...
@@ -5467,7 +5464,7 @@ class Canonizer(LocalOptimizer):
return
getattr
(
return
getattr
(
self
,
self
,
"name"
,
"name"
,
"Canonizer(
%
s,
%
s,
%
s)"
%
(
self
.
main
,
self
.
inverse
,
self
.
reciprocal
),
"Canonizer(
{}, {}, {})"
.
format
(
self
.
main
,
self
.
inverse
,
self
.
reciprocal
),
)
)
...
@@ -6125,7 +6122,6 @@ def local_reduce_join(node):
...
@@ -6125,7 +6122,6 @@ def local_reduce_join(node):
if
len
(
reduce_axis
)
!=
1
or
0
not
in
reduce_axis
:
if
len
(
reduce_axis
)
!=
1
or
0
not
in
reduce_axis
:
if
theano
.
config
.
warn
.
reduce_join
:
if
theano
.
config
.
warn
.
reduce_join
:
warnings
.
warning
(
warnings
.
warning
(
(
"Your current code is fine, but Theano versions "
"Your current code is fine, but Theano versions "
"prior to 0.7 (or this development version Sept 2014) "
"prior to 0.7 (or this development version Sept 2014) "
"might have given an incorrect result for this code. "
"might have given an incorrect result for this code. "
...
@@ -6136,7 +6132,6 @@ def local_reduce_join(node):
...
@@ -6136,7 +6132,6 @@ def local_reduce_join(node):
"did not check the reduction axis. So if the "
"did not check the reduction axis. So if the "
"reduction axis was not 0, you got a wrong answer."
"reduction axis was not 0, you got a wrong answer."
)
)
)
return
return
# We add the new check late to don't add extra warning.
# We add the new check late to don't add extra warning.
...
@@ -7049,8 +7044,8 @@ def constant_folding(node):
...
@@ -7049,8 +7044,8 @@ def constant_folding(node):
# The op asks not to be constant folded.
# The op asks not to be constant folded.
return
False
return
False
storage_map
=
dict
([(
i
,
[
i
.
data
])
for
i
in
node
.
inputs
])
storage_map
=
{
i
:
[
i
.
data
]
for
i
in
node
.
inputs
}
compute_map
=
dict
([(
i
,
[
True
])
for
i
in
node
.
inputs
])
compute_map
=
{
i
:
[
True
]
for
i
in
node
.
inputs
}
for
o
in
node
.
outputs
:
for
o
in
node
.
outputs
:
storage_map
[
o
]
=
[
None
]
storage_map
[
o
]
=
[
None
]
compute_map
[
o
]
=
[
False
]
compute_map
[
o
]
=
[
False
]
...
@@ -7578,7 +7573,7 @@ def local_elemwise_fusion_op(op_class, max_input_fct=lambda node: 32, maker=None
...
@@ -7578,7 +7573,7 @@ def local_elemwise_fusion_op(op_class, max_input_fct=lambda node: 32, maker=None
if
(
if
(
i
.
owner
i
.
owner
and
isinstance
(
i
.
owner
.
op
,
op_class
)
and
isinstance
(
i
.
owner
.
op
,
op_class
)
and
len
(
set
([
n
for
n
,
idx
in
i
.
clients
])
)
==
1
and
len
(
{
n
for
n
,
idx
in
i
.
clients
}
)
==
1
and
and
# Do not merge elemwise that don't have the same
# Do not merge elemwise that don't have the same
# broadcastable pattern to don't redo duplicate
# broadcastable pattern to don't redo duplicate
...
@@ -7789,7 +7784,6 @@ class FusionOptimizer(Optimizer):
...
@@ -7789,7 +7784,6 @@ class FusionOptimizer(Optimizer):
nb_replacement
+=
1
nb_replacement
+=
1
except
InconsistencyError
:
except
InconsistencyError
:
nb_inconsistency_replace
+=
1
nb_inconsistency_replace
+=
1
pass
nb_iter
+=
1
nb_iter
+=
1
if
fgraph
.
profile
:
if
fgraph
.
profile
:
...
...
theano/tensor/raw_random.py
浏览文件 @
008579b5
...
@@ -6,7 +6,6 @@ from copy import copy
...
@@ -6,7 +6,6 @@ from copy import copy
from
functools
import
reduce
from
functools
import
reduce
import
numpy
as
np
import
numpy
as
np
from
six
import
string_types
import
theano
import
theano
from
theano
import
gof
,
tensor
from
theano
import
gof
,
tensor
...
@@ -149,7 +148,7 @@ class RandomFunction(gof.Op):
...
@@ -149,7 +148,7 @@ class RandomFunction(gof.Op):
state
=
dct
state
=
dct
fn
,
outtype
,
inplace
,
ndim_added
=
state
fn
,
outtype
,
inplace
,
ndim_added
=
state
self
.
fn
=
fn
self
.
fn
=
fn
if
isinstance
(
fn
,
str
ing_types
):
if
isinstance
(
fn
,
str
):
self
.
exec_fn
=
getattr
(
np
.
random
.
RandomState
,
fn
)
self
.
exec_fn
=
getattr
(
np
.
random
.
RandomState
,
fn
)
else
:
else
:
self
.
exec_fn
=
fn
self
.
exec_fn
=
fn
...
@@ -353,7 +352,7 @@ def _infer_ndim_bcast(ndim, shape, *args):
...
@@ -353,7 +352,7 @@ def _infer_ndim_bcast(ndim, shape, *args):
else
:
else
:
if
s
>=
0
:
if
s
>=
0
:
pre_v_shape
.
append
(
tensor
.
as_tensor_variable
(
s
))
pre_v_shape
.
append
(
tensor
.
as_tensor_variable
(
s
))
bcast
.
append
(
(
s
==
1
)
)
bcast
.
append
(
s
==
1
)
elif
s
==
-
1
:
elif
s
==
-
1
:
n_a_i
=
0
n_a_i
=
0
for
a
in
args
:
for
a
in
args
:
...
@@ -370,12 +369,10 @@ def _infer_ndim_bcast(ndim, shape, *args):
...
@@ -370,12 +369,10 @@ def _infer_ndim_bcast(ndim, shape, *args):
else
:
else
:
if
n_a_i
==
0
:
if
n_a_i
==
0
:
raise
ValueError
(
raise
ValueError
(
(
"Auto-shape of -1 must overlap"
"Auto-shape of -1 must overlap"
"with the shape of one of the broadcastable"
"with the shape of one of the broadcastable"
"inputs"
"inputs"
)
)
)
else
:
else
:
pre_v_shape
.
append
(
tensor
.
as_tensor_variable
(
1
))
pre_v_shape
.
append
(
tensor
.
as_tensor_variable
(
1
))
bcast
.
append
(
True
)
bcast
.
append
(
True
)
...
@@ -393,7 +390,7 @@ def _infer_ndim_bcast(ndim, shape, *args):
...
@@ -393,7 +390,7 @@ def _infer_ndim_bcast(ndim, shape, *args):
# but we need to know ndim
# but we need to know ndim
if
not
args
:
if
not
args
:
raise
TypeError
(
raise
TypeError
(
(
"_infer_ndim_bcast cannot infer shape without"
" either shape or args"
)
"_infer_ndim_bcast cannot infer shape without"
" either shape or args"
)
)
template
=
reduce
(
lambda
a
,
b
:
a
+
b
,
args
)
template
=
reduce
(
lambda
a
,
b
:
a
+
b
,
args
)
v_shape
=
template
.
shape
v_shape
=
template
.
shape
...
@@ -957,7 +954,7 @@ optdb.register(
...
@@ -957,7 +954,7 @@ optdb.register(
)
)
class
RandomStreamsBase
(
object
)
:
class
RandomStreamsBase
:
def
binomial
(
self
,
size
=
None
,
n
=
1
,
p
=
0.5
,
ndim
=
None
,
dtype
=
"int64"
,
prob
=
None
):
def
binomial
(
self
,
size
=
None
,
n
=
1
,
p
=
0.5
,
ndim
=
None
,
dtype
=
"int64"
,
prob
=
None
):
"""
"""
Sample n times with probability of success p for each trial and
Sample n times with probability of success p for each trial and
...
...
theano/tensor/shared_randomstreams.py
浏览文件 @
008579b5
...
@@ -59,7 +59,7 @@ class RandomStreams(raw_random.RandomStreamsBase):
...
@@ -59,7 +59,7 @@ class RandomStreams(raw_random.RandomStreamsBase):
return
list
(
self
.
state_updates
)
return
list
(
self
.
state_updates
)
def
__init__
(
self
,
seed
=
None
):
def
__init__
(
self
,
seed
=
None
):
super
(
RandomStreams
,
self
)
.
__init__
()
super
()
.
__init__
()
# A list of pairs of the form (input_r, output_r). This will be
# A list of pairs of the form (input_r, output_r). This will be
# over-ridden by the module instance to contain stream generators.
# over-ridden by the module instance to contain stream generators.
self
.
state_updates
=
[]
self
.
state_updates
=
[]
...
...
theano/tensor/sharedvar.py
浏览文件 @
008579b5
import
traceback
import
traceback
import
numpy
as
np
import
numpy
as
np
from
six
import
integer_types
import
theano.tensor.basic
import
theano.tensor.basic
from
theano.compile
import
SharedVariable
,
shared_constructor
from
theano.compile
import
SharedVariable
,
shared_constructor
...
@@ -95,7 +94,7 @@ def scalar_constructor(
...
@@ -95,7 +94,7 @@ def scalar_constructor(
if
target
!=
"cpu"
:
if
target
!=
"cpu"
:
raise
TypeError
(
"not for cpu"
)
raise
TypeError
(
"not for cpu"
)
if
not
isinstance
(
value
,
(
np
.
number
,
float
,
int
eger_types
,
complex
)):
if
not
isinstance
(
value
,
(
np
.
number
,
float
,
int
,
complex
)):
raise
TypeError
()
raise
TypeError
()
try
:
try
:
dtype
=
value
.
dtype
dtype
=
value
.
dtype
...
...
theano/tensor/signal/pool.py
浏览文件 @
008579b5
...
@@ -470,7 +470,7 @@ class Pool(OpenMPOp):
...
@@ -470,7 +470,7 @@ class Pool(OpenMPOp):
return
rval
return
rval
def
__init__
(
self
,
ignore_border
=
False
,
mode
=
"max"
,
ndim
=
2
,
openmp
=
None
):
def
__init__
(
self
,
ignore_border
=
False
,
mode
=
"max"
,
ndim
=
2
,
openmp
=
None
):
super
(
Pool
,
self
)
.
__init__
(
openmp
=
openmp
)
super
()
.
__init__
(
openmp
=
openmp
)
self
.
ndim
=
ndim
self
.
ndim
=
ndim
self
.
ignore_border
=
ignore_border
self
.
ignore_border
=
ignore_border
if
mode
==
"max_deterministic"
:
if
mode
==
"max_deterministic"
:
...
@@ -649,7 +649,7 @@ class Pool(OpenMPOp):
...
@@ -649,7 +649,7 @@ class Pool(OpenMPOp):
def
c_headers
(
self
):
def
c_headers
(
self
):
headers
=
[
"<algorithm>"
]
headers
=
[
"<algorithm>"
]
headers
+=
super
(
Pool
,
self
)
.
c_headers
()
headers
+=
super
()
.
c_headers
()
return
headers
return
headers
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
...
@@ -1121,7 +1121,7 @@ class PoolGrad(OpenMPOp):
...
@@ -1121,7 +1121,7 @@ class PoolGrad(OpenMPOp):
" 'average_inc_pad' and 'average_exc_pad'. Got
%
s"
%
mode
" 'average_inc_pad' and 'average_exc_pad'. Got
%
s"
%
mode
)
)
self
.
mode
=
mode
self
.
mode
=
mode
super
(
PoolGrad
,
self
)
.
__init__
(
openmp
=
openmp
)
super
()
.
__init__
(
openmp
=
openmp
)
def
prepare_node
(
self
,
node
,
storage_map
,
compute_map
,
impl
):
def
prepare_node
(
self
,
node
,
storage_map
,
compute_map
,
impl
):
if
len
(
node
.
inputs
)
<
5
:
# 5 for AveragePoolGrad, 6 for MaxPoolGrad
if
len
(
node
.
inputs
)
<
5
:
# 5 for AveragePoolGrad, 6 for MaxPoolGrad
...
@@ -1836,7 +1836,7 @@ class DownsampleFactorMaxGradGrad(OpenMPOp):
...
@@ -1836,7 +1836,7 @@ class DownsampleFactorMaxGradGrad(OpenMPOp):
self
.
ndim
=
ndim
self
.
ndim
=
ndim
self
.
ignore_border
=
ignore_border
self
.
ignore_border
=
ignore_border
self
.
mode
=
mode
self
.
mode
=
mode
super
(
DownsampleFactorMaxGradGrad
,
self
)
.
__init__
(
openmp
=
openmp
)
super
()
.
__init__
(
openmp
=
openmp
)
assert
self
.
mode
==
"max"
assert
self
.
mode
==
"max"
def
make_node
(
self
,
x
,
maxout
,
gz
,
ws
,
stride
=
None
,
pad
=
None
):
def
make_node
(
self
,
x
,
maxout
,
gz
,
ws
,
stride
=
None
,
pad
=
None
):
...
@@ -2172,7 +2172,7 @@ class MaxPoolRop(OpenMPOp):
...
@@ -2172,7 +2172,7 @@ class MaxPoolRop(OpenMPOp):
)
)
def
__init__
(
self
,
ignore_border
=
False
,
mode
=
"max"
,
ndim
=
2
,
openmp
=
None
):
def
__init__
(
self
,
ignore_border
=
False
,
mode
=
"max"
,
ndim
=
2
,
openmp
=
None
):
super
(
MaxPoolRop
,
self
)
.
__init__
(
openmp
=
openmp
)
super
()
.
__init__
(
openmp
=
openmp
)
self
.
ndim
=
ndim
self
.
ndim
=
ndim
self
.
ignore_border
=
ignore_border
self
.
ignore_border
=
ignore_border
self
.
mode
=
mode
self
.
mode
=
mode
...
@@ -2276,7 +2276,7 @@ class MaxPoolRop(OpenMPOp):
...
@@ -2276,7 +2276,7 @@ class MaxPoolRop(OpenMPOp):
def
c_headers
(
self
):
def
c_headers
(
self
):
headers
=
[
"<algorithm>"
]
headers
=
[
"<algorithm>"
]
headers
+=
super
(
MaxPoolRop
,
self
)
.
c_headers
()
headers
+=
super
()
.
c_headers
()
return
headers
return
headers
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
...
...
theano/tensor/sort.py
浏览文件 @
008579b5
...
@@ -33,7 +33,7 @@ class SortOp(Op):
...
@@ -33,7 +33,7 @@ class SortOp(Op):
self
.
order
=
order
self
.
order
=
order
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
__class__
.
__name__
+
"{
%
s,
%
s}"
%
(
self
.
kind
,
str
(
self
.
order
))
return
self
.
__class__
.
__name__
+
"{
{{}, {}}}"
.
format
(
self
.
kind
,
str
(
self
.
order
))
def
make_node
(
self
,
input
,
axis
=-
1
):
def
make_node
(
self
,
input
,
axis
=-
1
):
input
=
theano
.
tensor
.
as_tensor_variable
(
input
)
input
=
theano
.
tensor
.
as_tensor_variable
(
input
)
...
@@ -168,7 +168,7 @@ class ArgSortOp(Op):
...
@@ -168,7 +168,7 @@ class ArgSortOp(Op):
self
.
order
=
order
self
.
order
=
order
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
__class__
.
__name__
+
"{
%
s,
%
s}"
%
(
self
.
kind
,
str
(
self
.
order
))
return
self
.
__class__
.
__name__
+
"{
{{}, {}}}"
.
format
(
self
.
kind
,
str
(
self
.
order
))
def
make_node
(
self
,
input
,
axis
=-
1
):
def
make_node
(
self
,
input
,
axis
=-
1
):
input
=
theano
.
tensor
.
as_tensor_variable
(
input
)
input
=
theano
.
tensor
.
as_tensor_variable
(
input
)
...
...
theano/tensor/subtensor.py
浏览文件 @
008579b5
...
@@ -5,7 +5,6 @@ from itertools import chain, groupby
...
@@ -5,7 +5,6 @@ from itertools import chain, groupby
from
textwrap
import
dedent
from
textwrap
import
dedent
import
numpy
as
np
import
numpy
as
np
from
six
import
integer_types
import
theano
import
theano
from
theano
import
config
,
gof
from
theano
import
config
,
gof
...
@@ -36,8 +35,6 @@ class AdvancedIndexingError(TypeError):
...
@@ -36,8 +35,6 @@ class AdvancedIndexingError(TypeError):
"""
"""
pass
def
as_index_constant
(
a
):
def
as_index_constant
(
a
):
"""Convert Python literals to Theano constants--when possible--in Subtensor arguments.
"""Convert Python literals to Theano constants--when possible--in Subtensor arguments.
...
@@ -52,7 +49,7 @@ def as_index_constant(a):
...
@@ -52,7 +49,7 @@ def as_index_constant(a):
as_index_constant
(
a
.
stop
),
as_index_constant
(
a
.
stop
),
as_index_constant
(
a
.
step
),
as_index_constant
(
a
.
step
),
)
)
elif
isinstance
(
a
,
(
int
eger_types
,
np
.
integer
)):
elif
isinstance
(
a
,
(
int
,
np
.
integer
)):
return
scal
.
ScalarConstant
(
scal
.
int64
,
a
)
return
scal
.
ScalarConstant
(
scal
.
int64
,
a
)
elif
not
isinstance
(
a
,
theano
.
tensor
.
Variable
):
elif
not
isinstance
(
a
,
theano
.
tensor
.
Variable
):
return
theano
.
tensor
.
as_tensor
(
a
)
return
theano
.
tensor
.
as_tensor
(
a
)
...
@@ -537,7 +534,7 @@ class Subtensor(Op):
...
@@ -537,7 +534,7 @@ class Subtensor(Op):
slice_c
=
None
slice_c
=
None
return
slice
(
slice_a
,
slice_b
,
slice_c
)
return
slice
(
slice_a
,
slice_b
,
slice_c
)
elif
isinstance
(
entry
,
(
int
eger_types
,
np
.
integer
)):
elif
isinstance
(
entry
,
(
int
,
np
.
integer
)):
# Disallow the use of python scalars in idx_list
# Disallow the use of python scalars in idx_list
raise
TypeError
(
raise
TypeError
(
"Python scalar in idx_list."
"Please report this error to theano-dev."
"Python scalar in idx_list."
"Please report this error to theano-dev."
...
@@ -662,7 +659,7 @@ class Subtensor(Op):
...
@@ -662,7 +659,7 @@ class Subtensor(Op):
if
start
is
None
:
if
start
is
None
:
start
=
0
start
=
0
if
p
.
stop
is
None
or
(
if
p
.
stop
is
None
or
(
isinstance
(
p
.
stop
,
(
int
eger_types
,
np
.
integer
,
np
.
ndarray
))
isinstance
(
p
.
stop
,
(
int
,
np
.
integer
,
np
.
ndarray
))
and
p
.
stop
>
start
and
p
.
stop
>
start
):
):
broadcastable
.
append
(
True
)
broadcastable
.
append
(
True
)
...
@@ -778,7 +775,7 @@ class Subtensor(Op):
...
@@ -778,7 +775,7 @@ class Subtensor(Op):
indices
.
append
(
self
.
str_from_slice
(
entry
))
indices
.
append
(
self
.
str_from_slice
(
entry
))
else
:
else
:
indices
.
append
(
str
(
entry
))
indices
.
append
(
str
(
entry
))
return
"
%
s{
%
s}"
%
(
self
.
__class__
.
__name__
,
", "
.
join
(
indices
))
return
"
{}{{{}}}"
.
format
(
self
.
__class__
.
__name__
,
", "
.
join
(
indices
))
@staticmethod
@staticmethod
def
default_helper_c_code_args
():
def
default_helper_c_code_args
():
...
@@ -844,7 +841,7 @@ class Subtensor(Op):
...
@@ -844,7 +841,7 @@ class Subtensor(Op):
return
pos
[
1
]
return
pos
[
1
]
def
init_entry
(
entry
,
depth
=
0
):
def
init_entry
(
entry
,
depth
=
0
):
if
isinstance
(
entry
,
(
np
.
integer
,
int
eger_types
)):
if
isinstance
(
entry
,
(
np
.
integer
,
int
)):
init_cmds
.
append
(
"subtensor_spec[
%
i] =
%
i;"
%
(
spec_pos
(),
entry
))
init_cmds
.
append
(
"subtensor_spec[
%
i] =
%
i;"
%
(
spec_pos
(),
entry
))
inc_spec_pos
(
1
)
inc_spec_pos
(
1
)
if
depth
==
0
:
if
depth
==
0
:
...
@@ -1144,7 +1141,7 @@ class SubtensorPrinter:
...
@@ -1144,7 +1141,7 @@ class SubtensorPrinter:
pstate
.
precedence
=
-
1000
pstate
.
precedence
=
-
1000
for
entry
in
idxs
:
for
entry
in
idxs
:
if
isinstance
(
entry
,
int
eger_types
):
if
isinstance
(
entry
,
int
):
sidxs
.
append
(
str
(
entry
))
sidxs
.
append
(
str
(
entry
))
elif
isinstance
(
entry
,
scal
.
Scalar
):
elif
isinstance
(
entry
,
scal
.
Scalar
):
sidxs
.
append
(
pstate
.
pprinter
.
process
(
inputs
.
pop
()))
sidxs
.
append
(
pstate
.
pprinter
.
process
(
inputs
.
pop
()))
...
@@ -1164,7 +1161,7 @@ class SubtensorPrinter:
...
@@ -1164,7 +1161,7 @@ class SubtensorPrinter:
else
:
else
:
msg3
=
":
%
s"
%
entry
.
step
msg3
=
":
%
s"
%
entry
.
step
sidxs
.
append
(
"
%
s:
%
s
%
s"
%
(
msg1
,
msg2
,
msg3
))
sidxs
.
append
(
"
{}:{}{}"
.
format
(
msg1
,
msg2
,
msg3
))
finally
:
finally
:
pstate
.
precedence
=
old_precedence
pstate
.
precedence
=
old_precedence
...
@@ -1173,7 +1170,7 @@ class SubtensorPrinter:
...
@@ -1173,7 +1170,7 @@ class SubtensorPrinter:
sub
=
pstate
.
pprinter
.
process
(
input
,
pstate
)
sub
=
pstate
.
pprinter
.
process
(
input
,
pstate
)
finally
:
finally
:
pstate
.
precedence
=
old_precedence
pstate
.
precedence
=
old_precedence
return
"
%
s[
%
s]"
%
(
sub
,
", "
.
join
(
sidxs
))
return
"
{}[{}]"
.
format
(
sub
,
", "
.
join
(
sidxs
))
else
:
else
:
raise
TypeError
(
"Can only print Subtensor."
)
raise
TypeError
(
"Can only print Subtensor."
)
...
@@ -1464,7 +1461,7 @@ class IncSubtensor(Op):
...
@@ -1464,7 +1461,7 @@ class IncSubtensor(Op):
msg
+=
"Inc"
msg
+=
"Inc"
else
:
else
:
msg
+=
"Set"
msg
+=
"Set"
return
"
%
s{
%
s;
%
s}"
%
(
self
.
__class__
.
__name__
,
msg
,
", "
.
join
(
indices
))
return
"
{}{{{};{}}}"
.
format
(
self
.
__class__
.
__name__
,
msg
,
", "
.
join
(
indices
))
def
make_node
(
self
,
x
,
y
,
*
inputs
):
def
make_node
(
self
,
x
,
y
,
*
inputs
):
"""
"""
...
@@ -2430,7 +2427,7 @@ class AdvancedIncSubtensor(Op):
...
@@ -2430,7 +2427,7 @@ class AdvancedIncSubtensor(Op):
raise
NotImplementedError
(
"In place computation is not"
" implemented"
)
raise
NotImplementedError
(
"In place computation is not"
" implemented"
)
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s{
%
s,
%
s}"
%
(
return
"
{}{{{}, {}}}"
.
format
(
self
.
__class__
.
__name__
,
self
.
__class__
.
__name__
,
"inplace="
+
str
(
self
.
inplace
),
"inplace="
+
str
(
self
.
inplace
),
" set_instead_of_inc="
+
str
(
self
.
set_instead_of_inc
),
" set_instead_of_inc="
+
str
(
self
.
set_instead_of_inc
),
...
...
theano/tensor/type.py
浏览文件 @
008579b5
...
@@ -283,7 +283,9 @@ class TensorType(Type):
...
@@ -283,7 +283,9 @@ class TensorType(Type):
}[
self
.
dtype
]
}[
self
.
dtype
]
except
KeyError
:
except
KeyError
:
raise
TypeError
(
raise
TypeError
(
"Unsupported dtype for
%
s:
%
s"
%
(
self
.
__class__
.
__name__
,
self
.
dtype
)
"Unsupported dtype for {}: {}"
.
format
(
self
.
__class__
.
__name__
,
self
.
dtype
)
)
)
def
to_scalar_type
(
self
):
def
to_scalar_type
(
self
):
...
@@ -391,7 +393,7 @@ class TensorType(Type):
...
@@ -391,7 +393,7 @@ class TensorType(Type):
bcast
=
str
(
b
)
bcast
=
str
(
b
)
else
:
else
:
bcast
=
"
%
iD"
%
len
(
b
)
bcast
=
"
%
iD"
%
len
(
b
)
return
"TensorType(
%
s,
%
s)"
%
(
str
(
self
.
dtype
)
,
bcast
)
return
"TensorType(
{}, {})"
.
format
(
self
.
dtype
,
bcast
)
def
__repr__
(
self
):
def
__repr__
(
self
):
return
str
(
self
)
return
str
(
self
)
...
...
theano/tensor/type_other.py
浏览文件 @
008579b5
...
@@ -94,7 +94,7 @@ class SliceConstant(Constant):
...
@@ -94,7 +94,7 @@ class SliceConstant(Constant):
return
(
SliceConstant
,
self
.
data
.
start
,
self
.
data
.
stop
,
self
.
data
.
step
)
return
(
SliceConstant
,
self
.
data
.
start
,
self
.
data
.
stop
,
self
.
data
.
step
)
def
__str__
(
self
):
def
__str__
(
self
):
return
"
%
s{
%
s,
%
s,
%
s}"
%
(
return
"
{}{{{}, {}, {}}}"
.
format
(
self
.
__class__
.
__name__
,
self
.
__class__
.
__name__
,
self
.
data
.
start
,
self
.
data
.
start
,
self
.
data
.
stop
,
self
.
data
.
stop
,
...
...
theano/tensor/var.py
浏览文件 @
008579b5
...
@@ -4,7 +4,6 @@ import warnings
...
@@ -4,7 +4,6 @@ import warnings
from
collections.abc
import
Iterable
from
collections.abc
import
Iterable
import
numpy
as
np
import
numpy
as
np
from
six
import
integer_types
import
theano
import
theano
from
theano
import
config
from
theano
import
config
...
@@ -15,7 +14,7 @@ from theano.tensor.type import TensorType
...
@@ -15,7 +14,7 @@ from theano.tensor.type import TensorType
from
theano.tensor.utils
import
hash_from_ndarray
from
theano.tensor.utils
import
hash_from_ndarray
class
_tensor_py_operators
(
object
)
:
class
_tensor_py_operators
:
def
__abs__
(
self
):
def
__abs__
(
self
):
return
theano
.
tensor
.
basic
.
abs_
(
self
)
return
theano
.
tensor
.
basic
.
abs_
(
self
)
...
@@ -297,7 +296,7 @@ class _tensor_py_operators(object):
...
@@ -297,7 +296,7 @@ class _tensor_py_operators(object):
"""
"""
if
ndim
is
not
None
:
if
ndim
is
not
None
:
if
not
isinstance
(
ndim
,
int
eger_types
):
if
not
isinstance
(
ndim
,
int
):
raise
ValueError
(
raise
ValueError
(
"Expected ndim to be an integer, is "
+
str
(
type
(
ndim
))
"Expected ndim to be an integer, is "
+
str
(
type
(
ndim
))
)
)
...
@@ -640,12 +639,10 @@ class _tensor_py_operators(object):
...
@@ -640,12 +639,10 @@ class _tensor_py_operators(object):
except
TypeError
:
except
TypeError
:
# This prevents accidental iteration via sum(self)
# This prevents accidental iteration via sum(self)
raise
TypeError
(
raise
TypeError
(
(
"TensorType does not support iteration. "
"TensorType does not support iteration. "
"Maybe you are using builtins.sum instead of "
"Maybe you are using builtins.sum instead of "
"theano.tensor.sum? (Maybe .max?)"
"theano.tensor.sum? (Maybe .max?)"
)
)
)
ndim
=
property
(
lambda
self
:
self
.
type
.
ndim
)
ndim
=
property
(
lambda
self
:
self
.
type
.
ndim
)
"""The rank of this tensor."""
"""The rank of this tensor."""
...
@@ -839,7 +836,7 @@ class TensorVariable(_tensor_py_operators, Variable):
...
@@ -839,7 +836,7 @@ class TensorVariable(_tensor_py_operators, Variable):
"""
"""
def
__init__
(
self
,
type
,
owner
=
None
,
index
=
None
,
name
=
None
):
def
__init__
(
self
,
type
,
owner
=
None
,
index
=
None
,
name
=
None
):
super
(
TensorVariable
,
self
)
.
__init__
(
type
,
owner
=
owner
,
index
=
index
,
name
=
name
)
super
()
.
__init__
(
type
,
owner
=
owner
,
index
=
index
,
name
=
name
)
if
config
.
warn_float64
!=
"ignore"
and
type
.
dtype
==
"float64"
:
if
config
.
warn_float64
!=
"ignore"
and
type
.
dtype
==
"float64"
:
msg
=
(
msg
=
(
"You are creating a TensorVariable "
"You are creating a TensorVariable "
...
@@ -997,7 +994,7 @@ class TensorConstant(_tensor_py_operators, Constant):
...
@@ -997,7 +994,7 @@ class TensorConstant(_tensor_py_operators, Constant):
def
__str__
(
self
):
def
__str__
(
self
):
if
self
.
tag
.
unique_value
is
not
None
:
if
self
.
tag
.
unique_value
is
not
None
:
name
=
"
%
s of
%
s"
%
(
str
(
self
.
data
.
shape
),
str
(
self
.
tag
.
unique_value
))
name
=
"
{} of {}"
.
format
(
str
(
self
.
data
.
shape
),
str
(
self
.
tag
.
unique_value
))
else
:
else
:
name
=
"
%
s"
%
self
.
data
name
=
"
%
s"
%
self
.
data
if
len
(
name
)
>
20
:
if
len
(
name
)
>
20
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论