Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
930ef0c4
提交
930ef0c4
authored
6月 29, 2015
作者:
Iban Harlouchet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Flake8 for tensor/basic.py
上级
3cacf1f7
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
44 行增加
和
46 行删除
+44
-46
basic.py
theano/tensor/basic.py
+44
-45
test_flake8.py
theano/tests/test_flake8.py
+0
-1
没有找到文件。
theano/tensor/basic.py
浏览文件 @
930ef0c4
"""A `Type` and `Op` classes to work with numpy.ndarrays symbolically."""
"""A `Type` and `Op` classes to work with numpy.ndarrays symbolically."""
__docformat__
=
"restructuredtext en"
import
sys
import
sys
import
warnings
import
warnings
...
@@ -29,7 +27,6 @@ from theano.printing import pprint, min_informative_str
...
@@ -29,7 +27,6 @@ from theano.printing import pprint, min_informative_str
# For history
# For history
from
theano.compile
import
Rebroadcast
,
Shape
,
shape
from
theano.compile
import
Rebroadcast
,
Shape
,
shape
# We use these exceptions as well.
# We use these exceptions as well.
import
theano.scalar.sharedvar
import
theano.scalar.sharedvar
from
theano.gradient
import
grad_undefined
from
theano.gradient
import
grad_undefined
...
@@ -42,6 +39,8 @@ from theano.tensor.elemwise import Elemwise, DimShuffle, CAReduce, Sum
...
@@ -42,6 +39,8 @@ from theano.tensor.elemwise import Elemwise, DimShuffle, CAReduce, Sum
import
logging
import
logging
_logger
=
logging
.
getLogger
(
"theano.tensor.basic"
)
_logger
=
logging
.
getLogger
(
"theano.tensor.basic"
)
__docformat__
=
"restructuredtext en"
# This is needed as we will hide it later
# This is needed as we will hide it later
python_complex
=
complex
python_complex
=
complex
python_any
=
any
python_any
=
any
...
@@ -620,8 +619,8 @@ def get_scalar_constant_value(orig_v, elemwise=True,
...
@@ -620,8 +619,8 @@ def get_scalar_constant_value(orig_v, elemwise=True,
ret
=
[[
None
]]
ret
=
[[
None
]]
v
.
owner
.
op
.
perform
(
v
.
owner
,
const
,
ret
)
v
.
owner
.
op
.
perform
(
v
.
owner
,
const
,
ret
)
return
ret
[
0
][
0
]
return
ret
[
0
][
0
]
elif
(
isinstance
(
v
.
owner
.
op
,
theano
.
tensor
.
subtensor
.
Subtensor
)
elif
(
isinstance
(
v
.
owner
.
op
,
theano
.
tensor
.
subtensor
.
Subtensor
)
and
and
v
.
ndim
==
0
):
v
.
ndim
==
0
):
if
isinstance
(
v
.
owner
.
inputs
[
0
],
TensorConstant
):
if
isinstance
(
v
.
owner
.
inputs
[
0
],
TensorConstant
):
cdata
=
tuple
(
v
.
owner
.
op
.
get_constant_idx
(
v
.
owner
.
inputs
))
cdata
=
tuple
(
v
.
owner
.
op
.
get_constant_idx
(
v
.
owner
.
inputs
))
try
:
try
:
...
@@ -1090,7 +1089,7 @@ scalar_from_tensor = ScalarFromTensor()
...
@@ -1090,7 +1089,7 @@ scalar_from_tensor = ScalarFromTensor()
# to be removed as we get the epydoc routine-documenting thing going
# to be removed as we get the epydoc routine-documenting thing going
#-JB 20080924
#
-JB 20080924
def
_conversion
(
real_value
,
name
):
def
_conversion
(
real_value
,
name
):
__oplist_tag
(
real_value
,
'casting'
)
__oplist_tag
(
real_value
,
'casting'
)
real_value
.
__module__
=
'tensor.basic'
real_value
.
__module__
=
'tensor.basic'
...
@@ -1235,8 +1234,8 @@ class MaxAndArgmax(Op):
...
@@ -1235,8 +1234,8 @@ class MaxAndArgmax(Op):
raise
TypeError
(
raise
TypeError
(
"MaxAndArgmax needs a constant axis. Got
%
s"
%
axis
)
"MaxAndArgmax needs a constant axis. Got
%
s"
%
axis
)
else
:
else
:
assert
(
axis
.
dtype
.
startswith
(
"int"
)
assert
(
axis
.
dtype
.
startswith
(
"int"
)
or
or
axis
.
dtype
.
startswith
(
"uint"
))
axis
.
dtype
.
startswith
(
"uint"
))
axis
=
int
(
axis
.
data
)
axis
=
int
(
axis
.
data
)
# we make the axis all positive to make the infer_shape work
# we make the axis all positive to make the infer_shape work
# with negative axis
# with negative axis
...
@@ -1373,13 +1372,13 @@ class MaxAndArgmax(Op):
...
@@ -1373,13 +1372,13 @@ class MaxAndArgmax(Op):
# Lebesgue measure, the result may be interpreted as weak gradient.
# Lebesgue measure, the result may be interpreted as weak gradient.
# @note: This function should work correctly for L{vector}s.
# @note: This function should work correctly for L{vector}s.
#
(x, y), (gz, gw)
#
(x, y), (gz, gw)
#
gz*dz/dx + gw*dw/dx, gz*dz/dy + gw*dw/dy
#
gz*dz/dx + gw*dw/dx, gz*dz/dy + gw*dw/dy
#
gMax * dMax/dx + gArgMax * dArgMax/dx,
#
gMax * dMax/dx + gArgMax * dArgMax/dx,
#
gMax * dMax/daxis + gArgMax * dArgMax/daxis
#
gMax * dMax/daxis + gArgMax * dArgMax/daxis
#
g_max has one less dimension than x, so you need to complete
#
g_max has one less dimension than x, so you need to complete
#
g_max to x's shape when axis=0 the broadcasting mechanism
#
g_max to x's shape when axis=0 the broadcasting mechanism
#
does it automatically
#
does it automatically
x
,
axis
=
inp
x
,
axis
=
inp
g_max
,
g_max_idx
=
grads
g_max
,
g_max_idx
=
grads
...
@@ -2078,7 +2077,7 @@ def chi2sf(x, k):
...
@@ -2078,7 +2077,7 @@ def chi2sf(x, k):
# numpy.real(float32) return a view on the inputs.
# numpy.real(float32) return a view on the inputs.
#@_scal_elemwise_with_nfunc('real', 1, 1)
#
@_scal_elemwise_with_nfunc('real', 1, 1)
@_scal_elemwise
@_scal_elemwise
def
real
(
z
):
def
real
(
z
):
"""Return real component of complex-valued tensor `z`"""
"""Return real component of complex-valued tensor `z`"""
...
@@ -2116,7 +2115,7 @@ def complex_from_polar(abs, angle):
...
@@ -2116,7 +2115,7 @@ def complex_from_polar(abs, angle):
# fill, _fill_inplace = _elemwise(scal.second, 'fill',
# fill, _fill_inplace = _elemwise(scal.second, 'fill',
#
"""fill WRITEME (elemwise)""")
#
"""fill WRITEME (elemwise)""")
@_scal_elemwise
@_scal_elemwise
def
second
(
a
,
b
):
def
second
(
a
,
b
):
"""Create a matrix by filling the shape of a with b"""
"""Create a matrix by filling the shape of a with b"""
...
@@ -3540,8 +3539,8 @@ class Join(Op):
...
@@ -3540,8 +3539,8 @@ class Join(Op):
dtypes
=
[
x
.
type
.
dtype
for
x
in
as_tensor_variable_args
]
dtypes
=
[
x
.
type
.
dtype
for
x
in
as_tensor_variable_args
]
out_dtype
=
scal
.
upcast
(
*
dtypes
)
out_dtype
=
scal
.
upcast
(
*
dtypes
)
output_maker
=
lambda
bcastable
:
tensor
(
dtype
=
out_dtype
,
def
output_maker
(
bcastable
):
broadcastable
=
bcastable
)
return
tensor
(
dtype
=
out_dtype
,
broadcastable
=
bcastable
)
return
self
.
_make_node_internal
(
return
self
.
_make_node_internal
(
axis
,
tensors
,
as_tensor_variable_args
,
output_maker
)
axis
,
tensors
,
as_tensor_variable_args
,
output_maker
)
...
@@ -4361,8 +4360,7 @@ class Tile(Op):
...
@@ -4361,8 +4360,7 @@ class Tile(Op):
def
make_node
(
self
,
x
,
reps
):
def
make_node
(
self
,
x
,
reps
):
warnings
.
warn
((
warnings
.
warn
((
"Tile op is deprecated, use tile function instead."
),
"Tile op is deprecated, use tile function instead."
),
stacklevel
=
3
)
stacklevel
=
3
)
x
=
as_tensor_variable
(
x
)
x
=
as_tensor_variable
(
x
)
reps
=
as_tensor_variable
(
reps
)
reps
=
as_tensor_variable
(
reps
)
return
gof
.
Apply
(
self
,
[
x
,
reps
],
[
tensor
(
x
.
type
.
dtype
,
[
False
]
*
return
gof
.
Apply
(
self
,
[
x
,
reps
],
[
tensor
(
x
.
type
.
dtype
,
[
False
]
*
...
@@ -4427,8 +4425,9 @@ def tile(x, reps, ndim=None):
...
@@ -4427,8 +4425,9 @@ def tile(x, reps, ndim=None):
except
TypeError
:
except
TypeError
:
raise
ValueError
(
"reps must be iterable"
)
raise
ValueError
(
"reps must be iterable"
)
if
not
numpy
.
all
([
isinstance
(
r
,
integer_types
)
or
if
not
numpy
.
all
([
isinstance
(
r
,
integer_types
)
or
(
isinstance
(
r
,
TensorVariable
)
and
(
isinstance
(
r
,
TensorVariable
)
and
r
.
dtype
in
[
"int8"
,
"int16"
,
"int32"
,
"int64"
])
for
r
in
reps
]):
r
.
dtype
in
[
"int8"
,
"int16"
,
"int32"
,
"int64"
])
for
r
in
reps
]):
raise
ValueError
(
"elements of reps must be scalars of integer dtype"
)
raise
ValueError
(
"elements of reps must be scalars of integer dtype"
)
elif
len
(
reps
)
!=
x
.
ndim
:
elif
len
(
reps
)
!=
x
.
ndim
:
raise
ValueError
(
"len(reps) != x.ndim not currently supported"
)
raise
ValueError
(
"len(reps) != x.ndim not currently supported"
)
...
@@ -4442,10 +4441,10 @@ def tile(x, reps, ndim=None):
...
@@ -4442,10 +4441,10 @@ def tile(x, reps, ndim=None):
shape
=
[
x
.
shape
[
i
]
for
i
in
xrange
(
ndim
)]
shape
=
[
x
.
shape
[
i
]
for
i
in
xrange
(
ndim
)]
alloc_shape
=
reps
+
shape
alloc_shape
=
reps
+
shape
y
=
alloc
(
x
,
*
alloc_shape
)
y
=
alloc
(
x
,
*
alloc_shape
)
shuffle_ind
=
numpy
.
arange
(
ndim
*
2
)
.
reshape
(
2
,
ndim
)
shuffle_ind
=
numpy
.
arange
(
ndim
*
2
)
.
reshape
(
2
,
ndim
)
shuffle_ind
=
shuffle_ind
.
transpose
()
.
flatten
()
shuffle_ind
=
shuffle_ind
.
transpose
()
.
flatten
()
y
=
y
.
dimshuffle
(
*
shuffle_ind
)
y
=
y
.
dimshuffle
(
*
shuffle_ind
)
new_shapes
=
[
sh
*
reps
[
i
]
for
i
,
sh
in
enumerate
(
shape
)]
new_shapes
=
[
sh
*
reps
[
i
]
for
i
,
sh
in
enumerate
(
shape
)]
y
=
y
.
reshape
(
new_shapes
)
y
=
y
.
reshape
(
new_shapes
)
return
y
return
y
...
@@ -4493,12 +4492,12 @@ class ARange(Op):
...
@@ -4493,12 +4492,12 @@ class ARange(Op):
def
upcast
(
var
):
def
upcast
(
var
):
if
(
'int'
in
var
.
dtype
and
if
(
'int'
in
var
.
dtype
and
# We do not want to cast uint64 to int64 as this can
# We do not want to cast uint64 to int64 as this can
# loose information. If we upcast uint64 with int64,
# loose information. If we upcast uint64 with int64,
# this give float64. This is safer then checking for
# this give float64. This is safer then checking for
# uint64 in case we support [u]int128 or other in the
# uint64 in case we support [u]int128 or other in the
# future.
# future.
scal
.
upcast
(
var
.
dtype
,
'int64'
)
==
'int64'
):
scal
.
upcast
(
var
.
dtype
,
'int64'
)
==
'int64'
):
return
cast
(
var
,
'int64'
)
return
cast
(
var
,
'int64'
)
return
var
return
var
...
@@ -4512,8 +4511,8 @@ class ARange(Op):
...
@@ -4512,8 +4511,8 @@ class ARange(Op):
else
:
else
:
stop
=
upcast
(
stop
)
stop
=
upcast
(
stop
)
start
=
upcast
(
start
)
start
=
upcast
(
start
)
return
[(
maximum
(
cast
(
ceil
(
cast
((
stop
-
start
),
'float64'
)
return
[(
maximum
(
cast
(
ceil
(
cast
((
stop
-
start
),
'float64'
)
/
step
),
/
step
),
'int64'
),
0
),)]
'int64'
),
0
),)]
def
perform
(
self
,
node
,
inp
,
out_
):
def
perform
(
self
,
node
,
inp
,
out_
):
start
,
stop
,
step
=
inp
start
,
stop
,
step
=
inp
...
@@ -4742,8 +4741,8 @@ class PermuteRowElements(Op):
...
@@ -4742,8 +4741,8 @@ class PermuteRowElements(Op):
# the gradient over these axes, but keep the dimension (as
# the gradient over these axes, but keep the dimension (as
# broadcastable)
# broadcastable)
broadcasted_dims
=
[
dim
for
dim
in
xrange
(
gz
.
type
.
ndim
)
broadcasted_dims
=
[
dim
for
dim
in
xrange
(
gz
.
type
.
ndim
)
if
x
.
type
.
broadcastable
[
dim
]
if
x
.
type
.
broadcastable
[
dim
]
and
and
not
gz
.
type
.
broadcastable
[
dim
]]
not
gz
.
type
.
broadcastable
[
dim
]]
gx
=
Sum
(
axis
=
broadcasted_dims
)(
gx
)
gx
=
Sum
(
axis
=
broadcasted_dims
)(
gx
)
# Sum(...) removed the dimensions in broadcasted_dims,
# Sum(...) removed the dimensions in broadcasted_dims,
...
@@ -4876,17 +4875,17 @@ class Dot(Op):
...
@@ -4876,17 +4875,17 @@ class Dot(Op):
xgrad
=
gz
*
y
xgrad
=
gz
*
y
ygrad
=
gz
*
x
ygrad
=
gz
*
x
#x is vector, y is matrix, grad is vector
#
x is vector, y is matrix, grad is vector
elif
xdim
==
1
and
ydim
==
2
:
elif
xdim
==
1
and
ydim
==
2
:
xgrad
=
dot
(
gz
,
y
.
T
)
xgrad
=
dot
(
gz
,
y
.
T
)
ygrad
=
outer
(
x
.
T
,
gz
)
ygrad
=
outer
(
x
.
T
,
gz
)
#x is matrix, y is vector, grad is vector
#
x is matrix, y is vector, grad is vector
elif
xdim
==
2
and
ydim
==
1
:
elif
xdim
==
2
and
ydim
==
1
:
xgrad
=
outer
(
gz
,
y
.
T
)
xgrad
=
outer
(
gz
,
y
.
T
)
ygrad
=
dot
(
x
.
T
,
gz
)
ygrad
=
dot
(
x
.
T
,
gz
)
#x is matrix, y is matrix, grad is matrix
#
x is matrix, y is matrix, grad is matrix
elif
xdim
==
ydim
==
2
:
elif
xdim
==
ydim
==
2
:
xgrad
=
dot
(
gz
,
y
.
T
)
xgrad
=
dot
(
gz
,
y
.
T
)
ygrad
=
dot
(
x
.
T
,
gz
)
ygrad
=
dot
(
x
.
T
,
gz
)
...
@@ -4958,8 +4957,8 @@ class Dot(Op):
...
@@ -4958,8 +4957,8 @@ class Dot(Op):
if
eval_point_values
[
i
]
is
not
None
and
\
if
eval_point_values
[
i
]
is
not
None
and
\
input_values
[
i
]
.
shape
!=
eval_point_values
[
i
]
.
shape
:
input_values
[
i
]
.
shape
!=
eval_point_values
[
i
]
.
shape
:
raise
ValueError
(
raise
ValueError
(
'input '
+
str
(
i
)
+
' and eval_point '
+
str
(
i
)
'input '
+
str
(
i
)
+
' and eval_point '
+
str
(
i
)
+
+
' to Dot.R_op should have the same shape, but '
' to Dot.R_op should have the same shape, but '
'their shapes are
%
s and
%
s, respectively'
%
(
'their shapes are
%
s and
%
s, respectively'
%
(
str
(
input_values
[
i
]
.
shape
),
str
(
input_values
[
i
]
.
shape
),
str
(
eval_point_values
[
i
]
.
shape
)))
str
(
eval_point_values
[
i
]
.
shape
)))
...
@@ -5230,8 +5229,8 @@ def tensordot(a, b, axes=2):
...
@@ -5230,8 +5229,8 @@ def tensordot(a, b, axes=2):
'equal to b.ndim (b.ndim=
%
i, max(axes[1])=
%
i).'
%
'equal to b.ndim (b.ndim=
%
i, max(axes[1])=
%
i).'
%
(
b
.
ndim
,
numpy
.
max
(
numpy
.
array
(
b_axes
))))
(
b
.
ndim
,
numpy
.
max
(
numpy
.
array
(
b_axes
))))
a_order
=
(
tuple
(
x
for
x
in
tuple
(
xrange
(
a
.
ndim
))
if
x
not
in
a_axes
)
a_order
=
(
tuple
(
x
for
x
in
tuple
(
xrange
(
a
.
ndim
))
if
x
not
in
a_axes
)
+
+
a_axes
)
a_axes
)
b_order
=
(
b_axes
+
tuple
(
x
b_order
=
(
b_axes
+
tuple
(
x
for
x
in
tuple
(
xrange
(
b
.
ndim
))
for
x
in
tuple
(
xrange
(
b
.
ndim
))
if
x
not
in
b_axes
))
if
x
not
in
b_axes
))
...
@@ -5528,8 +5527,8 @@ class Choose(Op):
...
@@ -5528,8 +5527,8 @@ class Choose(Op):
# dimensions for the output
# dimensions for the output
l
=
[]
l
=
[]
for
sh1
,
sh2
,
b1
in
zip
(
shapes
[
0
],
for
sh1
,
sh2
,
b1
in
zip
(
shapes
[
0
],
shapes
[
1
][
1
:],
shapes
[
1
][
1
:],
node
.
inputs
[
0
]
.
broadcastable
):
node
.
inputs
[
0
]
.
broadcastable
):
if
b1
:
if
b1
:
l
.
append
(
sh2
)
l
.
append
(
sh2
)
else
:
else
:
...
@@ -5635,7 +5634,7 @@ class AllocEmpty(gof.Op):
...
@@ -5635,7 +5634,7 @@ class AllocEmpty(gof.Op):
out
[
0
]
=
numpy
.
empty
(
sh
,
dtype
=
self
.
dtype
)
out
[
0
]
=
numpy
.
empty
(
sh
,
dtype
=
self
.
dtype
)
def
c_code
(
self
,
node
,
name
,
inputs
,
out_
,
sub
):
def
c_code
(
self
,
node
,
name
,
inputs
,
out_
,
sub
):
dtype
=
"NPY_"
+
self
.
dtype
.
upper
()
dtype
=
"NPY_"
+
self
.
dtype
.
upper
()
out
,
=
out_
out
,
=
out_
fail
=
sub
[
'fail'
]
fail
=
sub
[
'fail'
]
shps
=
inputs
shps
=
inputs
...
...
theano/tests/test_flake8.py
浏览文件 @
930ef0c4
...
@@ -69,7 +69,6 @@ whitelist_flake8 = [
...
@@ -69,7 +69,6 @@ whitelist_flake8 = [
"tensor/elemwise_cgen.py"
,
"tensor/elemwise_cgen.py"
,
"tensor/raw_random.py"
,
"tensor/raw_random.py"
,
"tensor/blas_scipy.py"
,
"tensor/blas_scipy.py"
,
"tensor/basic.py"
,
"tensor/tests/test_subtensor.py"
,
"tensor/tests/test_subtensor.py"
,
"tensor/tests/test_utils.py"
,
"tensor/tests/test_utils.py"
,
"tensor/tests/test_nlinalg.py"
,
"tensor/tests/test_nlinalg.py"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论