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 个修改的文件
包含
110 行增加
和
132 行删除
+110
-132
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
+0
-0
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
+30
-36
raw_random.py
theano/tensor/raw_random.py
+7
-10
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
+7
-10
没有找到文件。
theano/tensor/basic.py
浏览文件 @
008579b5
差异被折叠。
点击展开。
theano/tensor/blas.py
浏览文件 @
008579b5
...
...
@@ -477,7 +477,7 @@ def _ldflags(ldflags_str, libs, flags, libs_dir, include_dir):
assert
t0
==
"-"
except
Exception
:
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"
:
rval
.
append
(
t
[
2
:])
...
...
@@ -800,7 +800,7 @@ class GemmRelated(Op):
def
build_gemm_call
(
self
):
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_outplace
,
)
...
...
@@ -880,7 +880,7 @@ class Gemm(GemmRelated):
inplace_str
=
"inplace"
else
:
inplace_str
=
"no_inplace"
return
"
%
s{
%
s}"
%
(
self
.
__class__
.
__name__
,
inplace_str
)
return
"
{}{{{}}}"
.
format
(
self
.
__class__
.
__name__
,
inplace_str
)
def
__setstate__
(
self
,
dct
):
self
.
__dict__
.
update
(
dct
)
...
...
@@ -1671,7 +1671,7 @@ class Dot22(GemmRelated):
if
node
.
inputs
[
0
]
.
type
.
dtype
.
startswith
(
"complex"
):
raise
MethodNotDefined
(
"
%
s.c_code"
%
self
.
__class__
.
__name__
)
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
)
return
full_code
...
...
@@ -1941,7 +1941,7 @@ class Dot22Scalar(GemmRelated):
if
node
.
inputs
[
0
]
.
type
.
dtype
.
startswith
(
"complex"
):
raise
MethodNotDefined
(
"
%
s.c_code"
%
self
.
__class__
.
__name__
)
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
)
return
full_code
...
...
theano/tensor/blas_c.py
浏览文件 @
008579b5
...
...
@@ -23,7 +23,7 @@ from theano.tensor.blas import (
from
theano.tensor.opt
import
in2out
class
BaseBLAS
(
object
)
:
class
BaseBLAS
:
def
c_libraries
(
self
):
return
ldflags
()
...
...
@@ -617,7 +617,7 @@ class CGemv(BaseBLAS, Gemv):
)
def
__init__
(
self
,
inplace
):
super
(
CGemv
,
self
)
.
__init__
(
inplace
)
super
()
.
__init__
(
inplace
)
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
y
,
alpha
,
A
,
x
,
beta
=
inp
...
...
theano/tensor/blas_headers.py
浏览文件 @
008579b5
...
...
@@ -770,7 +770,7 @@ def blas_header_text():
"precision"
:
"d"
,
}
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."
)
blas_code
+=
common_code
...
...
theano/tensor/elemwise.py
浏览文件 @
008579b5
差异被折叠。
点击展开。
theano/tensor/elemwise_cgen.py
浏览文件 @
008579b5
...
...
@@ -77,7 +77,9 @@ def make_checks(loop_orders, dtypes, sub):
if
index
!=
"x"
:
# Initialize the variables associated to the jth loop
# jump = stride - adjust
jump
=
"(
%
s) - (
%
s)"
%
(
"
%(var)
s_stride
%(index)
s"
%
locals
(),
adjust
)
jump
=
"({}) - ({})"
.
format
(
"
%(var)
s_stride
%(index)
s"
%
locals
(),
adjust
)
init
+=
(
"""
%(var)
s_n
%(index)
s = PyArray_DIMS(
%(var)
s)[
%(index)
s];
...
...
theano/tensor/extra_ops.py
浏览文件 @
008579b5
...
...
@@ -274,7 +274,7 @@ class CumOp(Op):
def
__init__
(
self
,
axis
=
None
,
mode
=
"add"
):
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
.
mode
=
mode
...
...
@@ -287,7 +287,7 @@ class CumOp(Op):
if
self
.
axis
is
None
:
out_type
=
theano
.
tensor
.
vector
(
dtype
=
x
.
dtype
)
# Flatten
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
])
...
...
@@ -327,7 +327,9 @@ class CumOp(Op):
return
[
cumsum
((
fx
*
gi
)[
reverse_slicing
],
self
.
axis
)[
reverse_slicing
]
/
x
]
else
:
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
):
...
...
@@ -391,7 +393,7 @@ class CumOp(Op):
return
(
8
,)
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
):
...
...
theano/tensor/io.py
浏览文件 @
008579b5
...
...
@@ -58,7 +58,7 @@ class LoadFromDisk(Op):
out
[
0
][
0
]
=
result
def
__str__
(
self
):
return
"Load{
dtype:
%
s, broadcastable:
%
s, mmep:
%
s}"
%
(
return
"Load{
{dtype: {}, broadcastable: {}, mmep: {}}}"
.
format
(
self
.
dtype
,
self
.
broadcastable
,
self
.
mmap_mode
,
...
...
theano/tensor/nnet/abstract_conv.py
浏览文件 @
008579b5
差异被折叠。
点击展开。
theano/tensor/nnet/bn.py
浏览文件 @
008579b5
...
...
@@ -28,7 +28,7 @@ class BNComposite(Composite):
o
=
add
(
mul
(
true_div
(
sub
(
x
,
mean
),
std
),
gamma
),
beta
)
inputs
=
[
x
,
mean
,
std
,
gamma
,
beta
]
outputs
=
[
o
]
super
(
BNComposite
,
self
)
.
__init__
(
inputs
,
outputs
)
super
()
.
__init__
(
inputs
,
outputs
)
def
grad
(
self
,
inps
,
grads
):
x
,
mean
,
std
,
gamma
,
beta
=
inps
...
...
theano/tensor/nnet/conv.py
浏览文件 @
008579b5
...
...
@@ -488,7 +488,7 @@ class ConvOp(OpenMPOp):
)
# Init the openmp attribute
super
(
ConvOp
,
self
)
.
__init__
(
openmp
=
openmp
)
super
()
.
__init__
(
openmp
=
openmp
)
if
not
all_shape
or
self
.
openmp
:
# Only this version is parallelized
unroll_patch
=
True
...
...
@@ -687,7 +687,7 @@ class ConvOp(OpenMPOp):
return
True
def
__setstate__
(
self
,
d
):
super
(
ConvOp
,
self
)
.
__setstate__
(
d
)
super
()
.
__setstate__
(
d
)
self
.
direction_hint
=
d
.
get
(
"direction_hint"
,
None
)
self
.
_rehash
()
...
...
@@ -1197,7 +1197,7 @@ using namespace std;
if
theano
.
gof
.
cmodule
.
gcc_version
()
in
[
"4.3.0"
]
and
self
.
kshp
==
(
1
,
1
):
ret
+=
[
"-O2"
]
# Add the -fopenmp flags
ret
+=
super
(
ConvOp
,
self
)
.
c_compile_args
()
ret
+=
super
()
.
c_compile_args
()
return
ret
...
...
theano/tensor/nnet/corr.py
浏览文件 @
008579b5
import
logging
import
os
from
six
import
integer_types
import
theano
from
theano
import
gof
from
theano.gof.graph
import
Apply
...
...
@@ -86,8 +84,8 @@ class BaseCorrMM(gof.OpenMPOp):
unshared
=
False
,
openmp
=
None
,
):
super
(
BaseCorrMM
,
self
)
.
__init__
(
openmp
=
openmp
)
if
isinstance
(
border_mode
,
int
eger_types
):
super
()
.
__init__
(
openmp
=
openmp
)
if
isinstance
(
border_mode
,
int
):
if
border_mode
<
0
:
raise
ValueError
(
"invalid border_mode {}, which must be a "
...
...
@@ -175,7 +173,7 @@ class BaseCorrMM(gof.OpenMPOp):
padW_r
=
property
(
lambda
self
:
self
.
pad
[
1
][
1
])
def
__str__
(
self
):
return
"
%
s{
%
s,
%
s,
%
s,
%
s
%
s}"
%
(
return
"
{}{{{}, {}, {}, {} {}}}"
.
format
(
self
.
__class__
.
__name__
,
self
.
border_mode
,
str
(
self
.
subsample
),
...
...
@@ -210,7 +208,7 @@ class BaseCorrMM(gof.OpenMPOp):
def
c_compile_args
(
self
):
compile_args
=
ldflags
(
libs
=
False
,
flags
=
True
)
compile_args
+=
super
(
BaseCorrMM
,
self
)
.
c_compile_args
()
compile_args
+=
super
()
.
c_compile_args
()
return
compile_args
def
c_lib_dirs
(
self
):
...
...
@@ -221,7 +219,7 @@ class BaseCorrMM(gof.OpenMPOp):
def
c_headers
(
self
):
headers
=
[
"<stdio.h>"
]
headers
+=
super
(
BaseCorrMM
,
self
)
.
c_headers
()
headers
+=
super
()
.
c_headers
()
return
headers
def
c_code_cache_version
(
self
):
...
...
@@ -710,7 +708,7 @@ class CorrMM(BaseCorrMM):
def
c_code
(
self
,
node
,
nodename
,
inp
,
out_
,
sub
):
bottom
,
weights
=
inp
(
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
):
bottom
,
weights
=
inp
...
...
@@ -835,9 +833,7 @@ class CorrMM_gradWeights(BaseCorrMM):
bottom
,
top
=
inp
[:
2
]
height
,
width
=
inp
[
2
:]
or
(
None
,
None
)
(
weights
,)
=
out_
return
super
(
CorrMM_gradWeights
,
self
)
.
c_code_helper
(
bottom
,
weights
,
top
,
sub
,
height
,
width
)
return
super
()
.
c_code_helper
(
bottom
,
weights
,
top
,
sub
,
height
,
width
)
def
grad
(
self
,
inp
,
grads
):
bottom
,
top
=
inp
[:
2
]
...
...
@@ -969,9 +965,7 @@ class CorrMM_gradInputs(BaseCorrMM):
weights
,
top
=
inp
[:
2
]
height
,
width
=
inp
[
2
:]
or
(
None
,
None
)
(
bottom
,)
=
out_
return
super
(
CorrMM_gradInputs
,
self
)
.
c_code_helper
(
bottom
,
weights
,
top
,
sub
,
height
,
width
)
return
super
()
.
c_code_helper
(
bottom
,
weights
,
top
,
sub
,
height
,
width
)
def
grad
(
self
,
inp
,
grads
):
weights
,
top
=
inp
[:
2
]
...
...
theano/tensor/nnet/corr3d.py
浏览文件 @
008579b5
import
logging
import
os
from
six
import
integer_types
import
theano
from
theano
import
gof
from
theano.gof.graph
import
Apply
...
...
@@ -77,8 +75,8 @@ class BaseCorr3dMM(gof.OpenMPOp):
openmp
=
None
,
num_groups
=
1
,
):
super
(
BaseCorr3dMM
,
self
)
.
__init__
(
openmp
=
openmp
)
if
isinstance
(
border_mode
,
int
eger_types
):
super
()
.
__init__
(
openmp
=
openmp
)
if
isinstance
(
border_mode
,
int
):
if
border_mode
<
0
:
raise
ValueError
(
"invalid border_mode {}, which must be a "
...
...
@@ -159,7 +157,7 @@ class BaseCorr3dMM(gof.OpenMPOp):
padD
=
property
(
lambda
self
:
self
.
pad
[
2
])
def
__str__
(
self
):
return
"
%
s{
%
s,
%
s,
%
s,
%
s}"
%
(
return
"
{}{{{}, {}, {}, {}}}"
.
format
(
self
.
__class__
.
__name__
,
self
.
border_mode
,
str
(
self
.
subsample
),
...
...
@@ -193,7 +191,7 @@ class BaseCorr3dMM(gof.OpenMPOp):
def
c_compile_args
(
self
):
compile_args
=
ldflags
(
libs
=
False
,
flags
=
True
)
compile_args
+=
super
(
BaseCorr3dMM
,
self
)
.
c_compile_args
()
compile_args
+=
super
()
.
c_compile_args
()
return
compile_args
def
c_lib_dirs
(
self
):
...
...
@@ -204,7 +202,7 @@ class BaseCorr3dMM(gof.OpenMPOp):
def
c_headers
(
self
):
headers
=
[
"<stdio.h>"
]
headers
+=
super
(
BaseCorr3dMM
,
self
)
.
c_headers
()
headers
+=
super
()
.
c_headers
()
return
headers
def
c_code_cache_version
(
self
):
...
...
@@ -650,7 +648,7 @@ class Corr3dMM(BaseCorr3dMM):
def
c_code
(
self
,
node
,
nodename
,
inp
,
out_
,
sub
):
bottom
,
weights
=
inp
(
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
):
bottom
,
weights
=
inp
...
...
@@ -764,9 +762,7 @@ class Corr3dMMGradWeights(BaseCorr3dMM):
bottom
,
top
=
inp
[:
2
]
height
,
width
,
depth
=
inp
[
2
:]
or
(
None
,
None
,
None
)
(
weights
,)
=
out_
return
super
(
Corr3dMMGradWeights
,
self
)
.
c_code_helper
(
bottom
,
weights
,
top
,
sub
,
height
,
width
,
depth
)
return
super
()
.
c_code_helper
(
bottom
,
weights
,
top
,
sub
,
height
,
width
,
depth
)
def
grad
(
self
,
inp
,
grads
):
bottom
,
top
=
inp
[:
2
]
...
...
@@ -900,9 +896,7 @@ class Corr3dMMGradInputs(BaseCorr3dMM):
weights
,
top
=
inp
[:
2
]
height
,
width
,
depth
=
inp
[
2
:]
or
(
None
,
None
,
None
)
(
bottom
,)
=
out_
return
super
(
Corr3dMMGradInputs
,
self
)
.
c_code_helper
(
bottom
,
weights
,
top
,
sub
,
height
,
width
,
depth
)
return
super
()
.
c_code_helper
(
bottom
,
weights
,
top
,
sub
,
height
,
width
,
depth
)
def
grad
(
self
,
inp
,
grads
):
weights
,
top
=
inp
[:
2
]
...
...
theano/tensor/nnet/nnet.py
浏览文件 @
008579b5
...
...
@@ -2206,7 +2206,7 @@ class Prepend_scalar_constant_to_each_row(Op):
self
.
val
=
val
def
__str__
(
self
):
return
"
%
s{
%
s}"
%
(
self
.
__class__
.
__name__
,
self
.
val
)
return
"
{}{{{}}}"
.
format
(
self
.
__class__
.
__name__
,
self
.
val
)
def
make_node
(
self
,
mat
):
# check type of input
...
...
theano/tensor/nnet/sigm.py
浏览文件 @
008579b5
...
...
@@ -91,7 +91,7 @@ class ScalarSigmoid(scalar.UnaryScalarOp):
raise
NotImplementedError
(
"only floatingpoint is implemented"
)
def
c_code_cache_version
(
self
):
v
=
super
(
ScalarSigmoid
,
self
)
.
c_code_cache_version
()
v
=
super
()
.
c_code_cache_version
()
if
v
:
return
(
2
,)
+
v
else
:
...
...
@@ -404,7 +404,7 @@ class ScalarSoftplus(scalar.UnaryScalarOp):
raise
NotImplementedError
(
"only floatingpoint is implemented"
)
def
c_code_cache_version
(
self
):
v
=
super
(
ScalarSoftplus
,
self
)
.
c_code_cache_version
()
v
=
super
()
.
c_code_cache_version
()
if
v
:
return
(
2
,)
+
v
else
:
...
...
theano/tensor/opt.py
浏览文件 @
008579b5
...
...
@@ -13,7 +13,7 @@ from collections import defaultdict
from
functools
import
reduce
import
numpy
as
np
from
six
import
StringIO
,
integer_types
from
six
import
StringIO
import
theano
import
theano.scalar.basic
as
ts
...
...
@@ -515,7 +515,8 @@ class InplaceElemwiseOptimizer(Optimizer):
def
print_summary
(
self
,
stream
=
sys
.
stdout
,
level
=
0
,
depth
=-
1
):
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
...
...
@@ -996,7 +997,7 @@ class MakeVectorPrinter:
tt
.
pprint
.
assign
(
MakeVector
,
MakeVectorPrinter
())
class
ShapeFeature
(
object
)
:
class
ShapeFeature
:
"""Graph optimizer for removing all calls to shape().
This optimizer replaces all Shapes and Subtensors of Shapes with
...
...
@@ -1222,12 +1223,10 @@ class ShapeFeature(object):
# don't make the optimizer merge a zillion ones together
# by always returning the same object to represent 1
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
)
if
(
type
(
s_i
)
in
integer_types
or
isinstance
(
s_i
,
np
.
integer
)
or
(
isinstance
(
s_i
,
np
.
ndarray
)
and
s_i
.
ndim
==
0
)
if
isinstance
(
s_i
,
(
np
.
integer
,
int
))
or
(
isinstance
(
s_i
,
np
.
ndarray
)
and
s_i
.
ndim
==
0
):
# this shape is a constant
if
s_i
<
0
:
...
...
@@ -1241,7 +1240,7 @@ class ShapeFeature(object):
# message.
raise
AssertionError
(
msg
)
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
# which tells us that if one of the inputs is known,
# the others all become known.
...
...
@@ -1384,11 +1383,11 @@ class ShapeFeature(object):
# - Shape_i(i)(other_r);
# - Shape_i(i)(r).
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
# sure we have the simplest shape possible.
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
# sure we have the simplest shape possible.
merged_shape
.
append
(
other_shape
[
i
])
...
...
@@ -2225,7 +2224,7 @@ def local_subtensor_remove_broadcastable_index(node):
elif
isinstance
(
elem
,
slice
):
if
elem
!=
slice
(
None
):
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
]:
remove_dim
.
append
(
dim
)
else
:
...
...
@@ -2277,7 +2276,7 @@ def local_subtensor_make_vector(node):
else
:
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
return
[
x
.
owner
.
inputs
[
idx
]]
elif
isinstance
(
idx
,
Variable
):
...
...
@@ -3014,7 +3013,7 @@ def local_useless_subtensor(node):
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
try
:
length_pos_data
=
get_scalar_constant_value
(
...
...
@@ -3281,12 +3280,10 @@ def merge_two_slices(slice1, len1, slice2, len2):
n_val
=
sl1
.
stop
-
1
-
sl2
*
sl1
.
step
if
config
.
warn
.
subtensor_merge_bug
:
warnings
.
warning
(
(
"Your current code is fine, but Theano versions "
"prior to 0.5rc2 might have given an incorrect result. "
"To disable this warning, set the Theano flag "
"warn.subtensor_merge_bug to False."
)
"Your current code is fine, but Theano versions "
"prior to 0.5rc2 might have given an incorrect result. "
"To disable this warning, set the Theano flag "
"warn.subtensor_merge_bug to False."
)
# we need to pick either n_val or p_val and then follow same
# steps as above for covering the index error cases
...
...
@@ -5467,7 +5464,7 @@ class Canonizer(LocalOptimizer):
return
getattr
(
self
,
"name"
,
"Canonizer(
%
s,
%
s,
%
s)"
%
(
self
.
main
,
self
.
inverse
,
self
.
reciprocal
),
"Canonizer(
{}, {}, {})"
.
format
(
self
.
main
,
self
.
inverse
,
self
.
reciprocal
),
)
...
...
@@ -6125,17 +6122,15 @@ def local_reduce_join(node):
if
len
(
reduce_axis
)
!=
1
or
0
not
in
reduce_axis
:
if
theano
.
config
.
warn
.
reduce_join
:
warnings
.
warning
(
(
"Your current code is fine, but Theano versions "
"prior to 0.7 (or this development version Sept 2014) "
"might have given an incorrect result for this code. "
"To disable this warning, set the Theano flag "
"warn.reduce_join to False. The problem was an "
"optimization, that modified the pattern "
'"Reduce{scalar.op}(Join(axis=0, a, b), axis=0)", '
"did not check the reduction axis. So if the "
"reduction axis was not 0, you got a wrong answer."
)
"Your current code is fine, but Theano versions "
"prior to 0.7 (or this development version Sept 2014) "
"might have given an incorrect result for this code. "
"To disable this warning, set the Theano flag "
"warn.reduce_join to False. The problem was an "
"optimization, that modified the pattern "
'"Reduce{scalar.op}(Join(axis=0, a, b), axis=0)", '
"did not check the reduction axis. So if the "
"reduction axis was not 0, you got a wrong answer."
)
return
...
...
@@ -7049,8 +7044,8 @@ def constant_folding(node):
# The op asks not to be constant folded.
return
False
storage_map
=
dict
([(
i
,
[
i
.
data
])
for
i
in
node
.
inputs
])
compute_map
=
dict
([(
i
,
[
True
])
for
i
in
node
.
inputs
])
storage_map
=
{
i
:
[
i
.
data
]
for
i
in
node
.
inputs
}
compute_map
=
{
i
:
[
True
]
for
i
in
node
.
inputs
}
for
o
in
node
.
outputs
:
storage_map
[
o
]
=
[
None
]
compute_map
[
o
]
=
[
False
]
...
...
@@ -7578,7 +7573,7 @@ def local_elemwise_fusion_op(op_class, max_input_fct=lambda node: 32, maker=None
if
(
i
.
owner
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
# Do not merge elemwise that don't have the same
# broadcastable pattern to don't redo duplicate
...
...
@@ -7789,7 +7784,6 @@ class FusionOptimizer(Optimizer):
nb_replacement
+=
1
except
InconsistencyError
:
nb_inconsistency_replace
+=
1
pass
nb_iter
+=
1
if
fgraph
.
profile
:
...
...
theano/tensor/raw_random.py
浏览文件 @
008579b5
...
...
@@ -6,7 +6,6 @@ from copy import copy
from
functools
import
reduce
import
numpy
as
np
from
six
import
string_types
import
theano
from
theano
import
gof
,
tensor
...
...
@@ -149,7 +148,7 @@ class RandomFunction(gof.Op):
state
=
dct
fn
,
outtype
,
inplace
,
ndim_added
=
state
self
.
fn
=
fn
if
isinstance
(
fn
,
str
ing_types
):
if
isinstance
(
fn
,
str
):
self
.
exec_fn
=
getattr
(
np
.
random
.
RandomState
,
fn
)
else
:
self
.
exec_fn
=
fn
...
...
@@ -353,7 +352,7 @@ def _infer_ndim_bcast(ndim, shape, *args):
else
:
if
s
>=
0
:
pre_v_shape
.
append
(
tensor
.
as_tensor_variable
(
s
))
bcast
.
append
(
(
s
==
1
)
)
bcast
.
append
(
s
==
1
)
elif
s
==
-
1
:
n_a_i
=
0
for
a
in
args
:
...
...
@@ -370,11 +369,9 @@ def _infer_ndim_bcast(ndim, shape, *args):
else
:
if
n_a_i
==
0
:
raise
ValueError
(
(
"Auto-shape of -1 must overlap"
"with the shape of one of the broadcastable"
"inputs"
)
"Auto-shape of -1 must overlap"
"with the shape of one of the broadcastable"
"inputs"
)
else
:
pre_v_shape
.
append
(
tensor
.
as_tensor_variable
(
1
))
...
...
@@ -393,7 +390,7 @@ def _infer_ndim_bcast(ndim, shape, *args):
# but we need to know ndim
if
not
args
:
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
)
v_shape
=
template
.
shape
...
...
@@ -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
):
"""
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):
return
list
(
self
.
state_updates
)
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
# over-ridden by the module instance to contain stream generators.
self
.
state_updates
=
[]
...
...
theano/tensor/sharedvar.py
浏览文件 @
008579b5
import
traceback
import
numpy
as
np
from
six
import
integer_types
import
theano.tensor.basic
from
theano.compile
import
SharedVariable
,
shared_constructor
...
...
@@ -95,7 +94,7 @@ def scalar_constructor(
if
target
!=
"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
()
try
:
dtype
=
value
.
dtype
...
...
theano/tensor/signal/pool.py
浏览文件 @
008579b5
...
...
@@ -470,7 +470,7 @@ class Pool(OpenMPOp):
return
rval
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
.
ignore_border
=
ignore_border
if
mode
==
"max_deterministic"
:
...
...
@@ -649,7 +649,7 @@ class Pool(OpenMPOp):
def
c_headers
(
self
):
headers
=
[
"<algorithm>"
]
headers
+=
super
(
Pool
,
self
)
.
c_headers
()
headers
+=
super
()
.
c_headers
()
return
headers
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
...
...
@@ -1121,7 +1121,7 @@ class PoolGrad(OpenMPOp):
" 'average_inc_pad' and 'average_exc_pad'. Got
%
s"
%
mode
)
self
.
mode
=
mode
super
(
PoolGrad
,
self
)
.
__init__
(
openmp
=
openmp
)
super
()
.
__init__
(
openmp
=
openmp
)
def
prepare_node
(
self
,
node
,
storage_map
,
compute_map
,
impl
):
if
len
(
node
.
inputs
)
<
5
:
# 5 for AveragePoolGrad, 6 for MaxPoolGrad
...
...
@@ -1836,7 +1836,7 @@ class DownsampleFactorMaxGradGrad(OpenMPOp):
self
.
ndim
=
ndim
self
.
ignore_border
=
ignore_border
self
.
mode
=
mode
super
(
DownsampleFactorMaxGradGrad
,
self
)
.
__init__
(
openmp
=
openmp
)
super
()
.
__init__
(
openmp
=
openmp
)
assert
self
.
mode
==
"max"
def
make_node
(
self
,
x
,
maxout
,
gz
,
ws
,
stride
=
None
,
pad
=
None
):
...
...
@@ -2172,7 +2172,7 @@ class MaxPoolRop(OpenMPOp):
)
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
.
ignore_border
=
ignore_border
self
.
mode
=
mode
...
...
@@ -2276,7 +2276,7 @@ class MaxPoolRop(OpenMPOp):
def
c_headers
(
self
):
headers
=
[
"<algorithm>"
]
headers
+=
super
(
MaxPoolRop
,
self
)
.
c_headers
()
headers
+=
super
()
.
c_headers
()
return
headers
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
...
...
theano/tensor/sort.py
浏览文件 @
008579b5
...
...
@@ -33,7 +33,7 @@ class SortOp(Op):
self
.
order
=
order
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
):
input
=
theano
.
tensor
.
as_tensor_variable
(
input
)
...
...
@@ -168,7 +168,7 @@ class ArgSortOp(Op):
self
.
order
=
order
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
):
input
=
theano
.
tensor
.
as_tensor_variable
(
input
)
...
...
theano/tensor/subtensor.py
浏览文件 @
008579b5
...
...
@@ -5,7 +5,6 @@ from itertools import chain, groupby
from
textwrap
import
dedent
import
numpy
as
np
from
six
import
integer_types
import
theano
from
theano
import
config
,
gof
...
...
@@ -36,8 +35,6 @@ class AdvancedIndexingError(TypeError):
"""
pass
def
as_index_constant
(
a
):
"""Convert Python literals to Theano constants--when possible--in Subtensor arguments.
...
...
@@ -52,7 +49,7 @@ def as_index_constant(a):
as_index_constant
(
a
.
stop
),
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
)
elif
not
isinstance
(
a
,
theano
.
tensor
.
Variable
):
return
theano
.
tensor
.
as_tensor
(
a
)
...
...
@@ -537,7 +534,7 @@ class Subtensor(Op):
slice_c
=
None
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
raise
TypeError
(
"Python scalar in idx_list."
"Please report this error to theano-dev."
...
...
@@ -662,7 +659,7 @@ class Subtensor(Op):
if
start
is
None
:
start
=
0
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
):
broadcastable
.
append
(
True
)
...
...
@@ -778,7 +775,7 @@ class Subtensor(Op):
indices
.
append
(
self
.
str_from_slice
(
entry
))
else
:
indices
.
append
(
str
(
entry
))
return
"
%
s{
%
s}"
%
(
self
.
__class__
.
__name__
,
", "
.
join
(
indices
))
return
"
{}{{{}}}"
.
format
(
self
.
__class__
.
__name__
,
", "
.
join
(
indices
))
@staticmethod
def
default_helper_c_code_args
():
...
...
@@ -844,7 +841,7 @@ class Subtensor(Op):
return
pos
[
1
]
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
))
inc_spec_pos
(
1
)
if
depth
==
0
:
...
...
@@ -1144,7 +1141,7 @@ class SubtensorPrinter:
pstate
.
precedence
=
-
1000
for
entry
in
idxs
:
if
isinstance
(
entry
,
int
eger_types
):
if
isinstance
(
entry
,
int
):
sidxs
.
append
(
str
(
entry
))
elif
isinstance
(
entry
,
scal
.
Scalar
):
sidxs
.
append
(
pstate
.
pprinter
.
process
(
inputs
.
pop
()))
...
...
@@ -1164,7 +1161,7 @@ class SubtensorPrinter:
else
:
msg3
=
":
%
s"
%
entry
.
step
sidxs
.
append
(
"
%
s:
%
s
%
s"
%
(
msg1
,
msg2
,
msg3
))
sidxs
.
append
(
"
{}:{}{}"
.
format
(
msg1
,
msg2
,
msg3
))
finally
:
pstate
.
precedence
=
old_precedence
...
...
@@ -1173,7 +1170,7 @@ class SubtensorPrinter:
sub
=
pstate
.
pprinter
.
process
(
input
,
pstate
)
finally
:
pstate
.
precedence
=
old_precedence
return
"
%
s[
%
s]"
%
(
sub
,
", "
.
join
(
sidxs
))
return
"
{}[{}]"
.
format
(
sub
,
", "
.
join
(
sidxs
))
else
:
raise
TypeError
(
"Can only print Subtensor."
)
...
...
@@ -1464,7 +1461,7 @@ class IncSubtensor(Op):
msg
+=
"Inc"
else
:
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
):
"""
...
...
@@ -2430,7 +2427,7 @@ class AdvancedIncSubtensor(Op):
raise
NotImplementedError
(
"In place computation is not"
" implemented"
)
def
__str__
(
self
):
return
"
%
s{
%
s,
%
s}"
%
(
return
"
{}{{{}, {}}}"
.
format
(
self
.
__class__
.
__name__
,
"inplace="
+
str
(
self
.
inplace
),
" set_instead_of_inc="
+
str
(
self
.
set_instead_of_inc
),
...
...
theano/tensor/type.py
浏览文件 @
008579b5
...
...
@@ -283,7 +283,9 @@ class TensorType(Type):
}[
self
.
dtype
]
except
KeyError
:
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
):
...
...
@@ -391,7 +393,7 @@ class TensorType(Type):
bcast
=
str
(
b
)
else
:
bcast
=
"
%
iD"
%
len
(
b
)
return
"TensorType(
%
s,
%
s)"
%
(
str
(
self
.
dtype
)
,
bcast
)
return
"TensorType(
{}, {})"
.
format
(
self
.
dtype
,
bcast
)
def
__repr__
(
self
):
return
str
(
self
)
...
...
theano/tensor/type_other.py
浏览文件 @
008579b5
...
...
@@ -94,7 +94,7 @@ class SliceConstant(Constant):
return
(
SliceConstant
,
self
.
data
.
start
,
self
.
data
.
stop
,
self
.
data
.
step
)
def
__str__
(
self
):
return
"
%
s{
%
s,
%
s,
%
s}"
%
(
return
"
{}{{{}, {}, {}}}"
.
format
(
self
.
__class__
.
__name__
,
self
.
data
.
start
,
self
.
data
.
stop
,
...
...
theano/tensor/var.py
浏览文件 @
008579b5
...
...
@@ -4,7 +4,6 @@ import warnings
from
collections.abc
import
Iterable
import
numpy
as
np
from
six
import
integer_types
import
theano
from
theano
import
config
...
...
@@ -15,7 +14,7 @@ from theano.tensor.type import TensorType
from
theano.tensor.utils
import
hash_from_ndarray
class
_tensor_py_operators
(
object
)
:
class
_tensor_py_operators
:
def
__abs__
(
self
):
return
theano
.
tensor
.
basic
.
abs_
(
self
)
...
...
@@ -297,7 +296,7 @@ class _tensor_py_operators(object):
"""
if
ndim
is
not
None
:
if
not
isinstance
(
ndim
,
int
eger_types
):
if
not
isinstance
(
ndim
,
int
):
raise
ValueError
(
"Expected ndim to be an integer, is "
+
str
(
type
(
ndim
))
)
...
...
@@ -640,11 +639,9 @@ class _tensor_py_operators(object):
except
TypeError
:
# This prevents accidental iteration via sum(self)
raise
TypeError
(
(
"TensorType does not support iteration. "
"Maybe you are using builtins.sum instead of "
"theano.tensor.sum? (Maybe .max?)"
)
"TensorType does not support iteration. "
"Maybe you are using builtins.sum instead of "
"theano.tensor.sum? (Maybe .max?)"
)
ndim
=
property
(
lambda
self
:
self
.
type
.
ndim
)
...
...
@@ -839,7 +836,7 @@ class TensorVariable(_tensor_py_operators, Variable):
"""
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"
:
msg
=
(
"You are creating a TensorVariable "
...
...
@@ -997,7 +994,7 @@ class TensorConstant(_tensor_py_operators, Constant):
def
__str__
(
self
):
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
:
name
=
"
%
s"
%
self
.
data
if
len
(
name
)
>
20
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论