Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c89e1bc2
提交
c89e1bc2
authored
7月 16, 2015
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3107 from harlouci/flake8_v3
Flake8 tensor
上级
de826376
cceee86e
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
72 行增加
和
93 行删除
+72
-93
test_linalg.py
theano/sandbox/linalg/tests/test_linalg.py
+10
-0
blas.py
theano/tensor/blas.py
+0
-0
blas_c.py
theano/tensor/blas_c.py
+7
-9
blas_scipy.py
theano/tensor/blas_scipy.py
+11
-11
elemwise_cgen.py
theano/tensor/elemwise_cgen.py
+23
-30
extra_ops.py
theano/tensor/extra_ops.py
+1
-0
fourier.py
theano/tensor/fourier.py
+6
-5
nlinalg.py
theano/tensor/nlinalg.py
+10
-25
opt_uncanonicalize.py
theano/tensor/opt_uncanonicalize.py
+4
-3
type.py
theano/tensor/type.py
+0
-0
test_flake8.py
theano/tests/test_flake8.py
+0
-10
没有找到文件。
theano/sandbox/linalg/tests/test_linalg.py
浏览文件 @
c89e1bc2
...
@@ -174,3 +174,13 @@ def test_tag_solve_triangular():
...
@@ -174,3 +174,13 @@ def test_tag_solve_triangular():
for
node
in
f
.
maker
.
fgraph
.
toposort
():
for
node
in
f
.
maker
.
fgraph
.
toposort
():
if
isinstance
(
node
.
op
,
Solve
):
if
isinstance
(
node
.
op
,
Solve
):
assert
node
.
op
.
A_structure
==
'upper_triangular'
assert
node
.
op
.
A_structure
==
'upper_triangular'
def
test_matrix_inverse_solve
():
if
not
imported_scipy
:
raise
SkipTest
(
"Scipy needed for the Solve op."
)
A
=
theano
.
tensor
.
dmatrix
(
'A'
)
b
=
theano
.
tensor
.
dmatrix
(
'b'
)
node
=
matrix_inverse
(
A
)
.
dot
(
b
)
.
owner
[
out
]
=
inv_as_solve
.
transform
(
node
)
assert
isinstance
(
out
.
owner
.
op
,
Solve
)
theano/tensor/blas.py
浏览文件 @
c89e1bc2
差异被折叠。
点击展开。
theano/tensor/blas_c.py
浏览文件 @
c89e1bc2
...
@@ -4,8 +4,7 @@ from theano import config
...
@@ -4,8 +4,7 @@ from theano import config
from
theano.tensor.opt
import
in2out
from
theano.tensor.opt
import
in2out
from
theano.tensor.blas
import
ldflags
,
blas_header_text
,
blas_header_version
from
theano.tensor.blas
import
ldflags
,
blas_header_text
,
blas_header_version
from
theano.tensor.blas
import
(
from
theano.tensor.blas
import
blas_optdb
,
optdb
,
local_optimizer
blas_optdb
,
optdb
,
local_optimizer
,
EquilibriumOptimizer
)
from
theano.tensor.blas
import
Ger
,
ger
,
ger_destructive
from
theano.tensor.blas
import
Ger
,
ger
,
ger_destructive
from
theano.tensor.blas
import
Gemv
,
gemv_inplace
,
gemv_no_inplace
from
theano.tensor.blas
import
Gemv
,
gemv_inplace
,
gemv_no_inplace
from
theano.tensor
import
basic
as
T
from
theano.tensor
import
basic
as
T
...
@@ -268,7 +267,7 @@ def ger_c_code(A, a, x, y, Z, destructive, fail):
...
@@ -268,7 +267,7 @@ def ger_c_code(A, a, x, y, Z, destructive, fail):
(double*)x_data, &Sx,
(double*)x_data, &Sx,
(double*)y_data, &Sy,
(double*)y_data, &Sy,
(double*)(PyArray_DATA(
%(Z)
s)), &Sz1);
(double*)(PyArray_DATA(
%(Z)
s)), &Sz1);
}
}
else {
else {
...
@@ -610,7 +609,7 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail,
...
@@ -610,7 +609,7 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail,
// so Sx1 == 1 is required for safety.
// so Sx1 == 1 is required for safety.
if (Nx0 == 1 && Sx1 == 1)
if (Nx0 == 1 && Sx1 == 1)
{
{
zz_data[0] = fbeta*zz_data[0] + alpha*sdot_(&Nx1,
zz_data[0] = fbeta*zz_data[0] + alpha*sdot_(&Nx1,
(float*)(PyArray_DATA(
%(xx)
s)), &Sx1,
(float*)(PyArray_DATA(
%(xx)
s)), &Sx1,
(float*)yy_data, &Sy);
(float*)yy_data, &Sy);
}
}
...
@@ -633,7 +632,7 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail,
...
@@ -633,7 +632,7 @@ def gemv_c_code(aa, xx, yy, zz, alpha, beta, destructive, fail,
// so Sx1 == 1 is required for safety.
// so Sx1 == 1 is required for safety.
if (Nx0 == 1 && Sx1 == 1)
if (Nx0 == 1 && Sx1 == 1)
{
{
zz_data[0] = dbeta*zz_data[0] + alpha*ddot_(&Nx1,
zz_data[0] = dbeta*zz_data[0] + alpha*ddot_(&Nx1,
(double*)(PyArray_DATA(
%(xx)
s)), &Sx1,
(double*)(PyArray_DATA(
%(xx)
s)), &Sx1,
(double*)yy_data, &Sy);
(double*)yy_data, &Sy);
}
}
...
@@ -732,8 +731,7 @@ def check_force_gemv_init():
...
@@ -732,8 +731,7 @@ def check_force_gemv_init():
gemv_no_inplace
(
aa
,
1.
,
xx
,
yy
,
0.
),
gemv_no_inplace
(
aa
,
1.
,
xx
,
yy
,
0.
),
theano
.
compile
.
Mode
(
optimizer
=
'fast_compile'
)
.
excluding
(
'gpu'
,
theano
.
compile
.
Mode
(
optimizer
=
'fast_compile'
)
.
excluding
(
'gpu'
,
'gpuarray'
),
'gpuarray'
),
profile
=
False
profile
=
False
)
)
finally
:
finally
:
theano
.
config
.
compute_test_value
=
tv
theano
.
config
.
compute_test_value
=
tv
theano
.
config
.
compute_test_value_opt
=
tvo
theano
.
config
.
compute_test_value_opt
=
tvo
...
@@ -742,11 +740,11 @@ def check_force_gemv_init():
...
@@ -742,11 +740,11 @@ def check_force_gemv_init():
# then we want gemv_c_code to initiliaze the memory to 0 so that we
# then we want gemv_c_code to initiliaze the memory to 0 so that we
# don't inadvertantly introduce NaNs to the users data.
# don't inadvertantly introduce NaNs to the users data.
aa_data
=
numpy
.
array
(
aa_data
=
numpy
.
array
(
float
(
'NaN'
)
*
numpy
.
ones
((
2
,)),
float
(
'NaN'
)
*
numpy
.
ones
((
2
,)),
dtype
=
theano
.
config
.
floatX
dtype
=
theano
.
config
.
floatX
)
)
yy_data
=
numpy
.
array
(
yy_data
=
numpy
.
array
(
numpy
.
ones
((
2
,))
*
2
,
numpy
.
ones
((
2
,))
*
2
,
dtype
=
theano
.
config
.
floatX
dtype
=
theano
.
config
.
floatX
)
)
xx_data
=
numpy
.
array
(
xx_data
=
numpy
.
array
(
...
...
theano/tensor/blas_scipy.py
浏览文件 @
c89e1bc2
...
@@ -12,11 +12,11 @@ from theano.tensor.opt import in2out
...
@@ -12,11 +12,11 @@ from theano.tensor.opt import in2out
if
have_fblas
:
if
have_fblas
:
from
theano.tensor.blas
import
fblas
from
theano.tensor.blas
import
fblas
_blas_ger_fns
=
{
_blas_ger_fns
=
{
numpy
.
dtype
(
'float32'
):
fblas
.
sger
,
numpy
.
dtype
(
'float32'
):
fblas
.
sger
,
numpy
.
dtype
(
'float64'
):
fblas
.
dger
,
numpy
.
dtype
(
'float64'
):
fblas
.
dger
,
numpy
.
dtype
(
'complex64'
):
fblas
.
cgeru
,
numpy
.
dtype
(
'complex64'
):
fblas
.
cgeru
,
numpy
.
dtype
(
'complex128'
):
fblas
.
zgeru
,
numpy
.
dtype
(
'complex128'
):
fblas
.
zgeru
,
}
}
class
ScipyGer
(
Ger
):
class
ScipyGer
(
Ger
):
...
@@ -47,10 +47,10 @@ class ScipyGer(Ger):
...
@@ -47,10 +47,10 @@ class ScipyGer(Ger):
A
=
A
.
copy
()
A
=
A
.
copy
()
elif
A
.
flags
[
'C_CONTIGUOUS'
]:
elif
A
.
flags
[
'C_CONTIGUOUS'
]:
A
=
local_ger
(
calpha
[
0
],
cy
[
0
],
cx
[
0
],
a
=
A
.
T
,
A
=
local_ger
(
calpha
[
0
],
cy
[
0
],
cx
[
0
],
a
=
A
.
T
,
overwrite_a
=
int
(
self
.
destructive
))
.
T
overwrite_a
=
int
(
self
.
destructive
))
.
T
else
:
else
:
A
=
local_ger
(
calpha
[
0
],
cx
[
0
],
cy
[
0
],
a
=
A
,
A
=
local_ger
(
calpha
[
0
],
cx
[
0
],
cy
[
0
],
a
=
A
,
overwrite_a
=
int
(
self
.
destructive
))
overwrite_a
=
int
(
self
.
destructive
))
cZ
[
0
]
=
A
cZ
[
0
]
=
A
for
o
in
node_output_compute
:
for
o
in
node_output_compute
:
o
[
0
]
=
True
o
[
0
]
=
True
...
@@ -87,10 +87,10 @@ if have_fblas:
...
@@ -87,10 +87,10 @@ if have_fblas:
# precedence. Once the original Ger is replaced, then these optimizations
# precedence. Once the original Ger is replaced, then these optimizations
# have no effect.
# have no effect.
blas_optdb
.
register
(
'scipy_blas'
,
blas_optdb
.
register
(
'scipy_blas'
,
use_scipy_blas
,
use_scipy_blas
,
100
,
'fast_run'
)
100
,
'fast_run'
)
# this matches the InplaceBlasOpt defined in blas.py
# this matches the InplaceBlasOpt defined in blas.py
optdb
.
register
(
'make_scipy_blas_destructive'
,
optdb
.
register
(
'make_scipy_blas_destructive'
,
make_scipy_blas_destructive
,
make_scipy_blas_destructive
,
70.0
,
'fast_run'
,
'inplace'
)
70.0
,
'fast_run'
,
'inplace'
)
theano/tensor/elemwise_cgen.py
浏览文件 @
c89e1bc2
...
@@ -276,7 +276,7 @@ def make_reordered_loop(init_loop_orders, olv_index, dtypes, inner_task, sub, op
...
@@ -276,7 +276,7 @@ def make_reordered_loop(init_loop_orders, olv_index, dtypes, inner_task, sub, op
if
index
!=
'x'
:
if
index
!=
'x'
:
order_loops
+=
"""
order_loops
+=
"""
%(ovar)
s_loops_it->first = abs(PyArray_STRIDES(
%(ovar)
s)[
%(index)
i]);
%(ovar)
s_loops_it->first = abs(PyArray_STRIDES(
%(ovar)
s)[
%(index)
i]);
"""
%
locals
()
"""
%
locals
()
else
:
else
:
# Stride is 0 when dimension is broadcastable
# Stride is 0 when dimension is broadcastable
order_loops
+=
"""
order_loops
+=
"""
...
@@ -311,15 +311,13 @@ def make_reordered_loop(init_loop_orders, olv_index, dtypes, inner_task, sub, op
...
@@ -311,15 +311,13 @@ def make_reordered_loop(init_loop_orders, olv_index, dtypes, inner_task, sub, op
total
=
"
%(var)
s_n
%(candidate)
s"
%
locals
()
total
=
"
%(var)
s_n
%(candidate)
s"
%
locals
()
break
break
else
:
else
:
total
=
'1'
;
total
=
'1'
totals
.
append
(
total
)
totals
.
append
(
total
)
declare_totals
=
"""
declare_totals
=
"""
int init_totals[
%(nnested)
s] = {
%(totals)
s};
int init_totals[
%(nnested)
s] = {
%(totals)
s};
"""
%
dict
(
"""
%
dict
(
nnested
=
nnested
,
nnested
=
nnested
,
totals
=
', '
.
join
(
totals
))
totals
=
', '
.
join
(
totals
)
)
# Sort totals to match the new order that was computed by sorting
# Sort totals to match the new order that was computed by sorting
# the loop vector. One integer variable per loop is declared.
# the loop vector. One integer variable per loop is declared.
...
@@ -355,13 +353,11 @@ def make_reordered_loop(init_loop_orders, olv_index, dtypes, inner_task, sub, op
...
@@ -355,13 +353,11 @@ def make_reordered_loop(init_loop_orders, olv_index, dtypes, inner_task, sub, op
declare_strides
=
"""
declare_strides
=
"""
int init_strides[
%(nvars)
i][
%(nnested)
i] = {
int init_strides[
%(nvars)
i][
%(nnested)
i] = {
%(strides)
s
%(strides)
s
};"""
%
dict
(
};"""
%
dict
(
nvars
=
nvars
,
nvars
=
nvars
,
nnested
=
nnested
,
nnested
=
nnested
,
strides
=
',
\n
'
.
join
(
', '
.
join
(
get_loop_strides
(
lo
,
i
))
strides
=
',
\n
'
.
join
(
for
i
,
lo
in
enumerate
(
init_loop_orders
)
', '
.
join
(
get_loop_strides
(
lo
,
i
))
if
len
(
lo
)
>
0
))
for
i
,
lo
in
enumerate
(
init_loop_orders
)
if
len
(
lo
)
>
0
))
# Declare (sorted) stride and for each variable
# Declare (sorted) stride and for each variable
# we iterate from innermost loop to outermost loop
# we iterate from innermost loop to outermost loop
...
@@ -385,9 +381,9 @@ def make_reordered_loop(init_loop_orders, olv_index, dtypes, inner_task, sub, op
...
@@ -385,9 +381,9 @@ def make_reordered_loop(init_loop_orders, olv_index, dtypes, inner_task, sub, op
declare_iter
+=
"
%(var)
s_iter = (
%(dtype)
s*)(PyArray_DATA(
%(var)
s));
\n
"
%
locals
()
declare_iter
+=
"
%(var)
s_iter = (
%(dtype)
s*)(PyArray_DATA(
%(var)
s));
\n
"
%
locals
()
pointer_update
=
''
pointer_update
=
''
for
j
,
dtype
in
enumerate
(
dtypes
):
for
j
,
dtype
in
enumerate
(
dtypes
):
var
=
sub
[
"lv
%
i"
%
j
]
var
=
sub
[
"lv
%
i"
%
j
]
pointer_update
+=
"
%(dtype)
s &
%(var)
s_i = * (
%(var)
s_iter"
%
locals
()
pointer_update
+=
"
%(dtype)
s &
%(var)
s_i = * (
%(var)
s_iter"
%
locals
()
tot_jump
=
''
tot_jump
=
''
for
i
in
reversed
(
range
(
nnested
)):
for
i
in
reversed
(
range
(
nnested
)):
iterv
=
'ITER_
%
i'
%
i
iterv
=
'ITER_
%
i'
%
i
...
@@ -401,7 +397,7 @@ def make_reordered_loop(init_loop_orders, olv_index, dtypes, inner_task, sub, op
...
@@ -401,7 +397,7 @@ def make_reordered_loop(init_loop_orders, olv_index, dtypes, inner_task, sub, op
update
=
''
update
=
''
forloop
=
''
forloop
=
''
# The pointers are defined only in the most inner loop
# The pointers are defined only in the most inner loop
if
i
==
nnested
-
1
:
if
i
==
nnested
-
1
:
update
=
pointer_update
update
=
pointer_update
if
i
==
0
:
if
i
==
0
:
if
openmp
:
if
openmp
:
...
@@ -413,19 +409,17 @@ def make_reordered_loop(init_loop_orders, olv_index, dtypes, inner_task, sub, op
...
@@ -413,19 +409,17 @@ def make_reordered_loop(init_loop_orders, olv_index, dtypes, inner_task, sub, op
%(forloop)
s
%(forloop)
s
{ // begin loop
%(i)
i
{ // begin loop
%(i)
i
%(update)
s
%(update)
s
%(loop)
s
%(loop)
s
} // end loop
%(i)
i
} // end loop
%(i)
i
"""
%
locals
()
"""
%
locals
()
return
'
\n
'
.
join
([
return
'
\n
'
.
join
([
'{'
,
'{'
,
order_loops
,
order_loops
,
declare_totals
,
declare_totals
,
declare_strides
,
declare_strides
,
declare_iter
,
declare_iter
,
loop
,
loop
,
'}
\n
'
])
'}
\n
'
,
])
# print make_declare(((0, 1, 2, 3), ('x', 1, 0, 3), ('x', 'x', 'x', 0)),
# print make_declare(((0, 1, 2, 3), ('x', 1, 0, 3), ('x', 'x', 'x', 0)),
# ('double', 'int', 'float'),
# ('double', 'int', 'float'),
...
@@ -451,16 +445,16 @@ def make_reordered_loop(init_loop_orders, olv_index, dtypes, inner_task, sub, op
...
@@ -451,16 +445,16 @@ def make_reordered_loop(init_loop_orders, olv_index, dtypes, inner_task, sub, op
##################
##################
#
## DimShuffle ##
#
#
DimShuffle
#
##################
##################
#################
#################
#
## Broadcast ##
#
#
Broadcast
#
#################
#################
################
################
#
## CAReduce ##
#
#
CAReduce
#
################
################
...
@@ -527,4 +521,3 @@ def make_loop_careduce(loop_orders, dtypes, loop_tasks, sub):
...
@@ -527,4 +521,3 @@ def make_loop_careduce(loop_orders, dtypes, loop_tasks, sub):
s
+=
loop_tasks
[
-
1
]
s
+=
loop_tasks
[
-
1
]
return
"{
%
s}"
%
s
return
"{
%
s}"
%
s
theano/tensor/extra_ops.py
浏览文件 @
c89e1bc2
...
@@ -5,6 +5,7 @@ from six.moves import xrange
...
@@ -5,6 +5,7 @@ from six.moves import xrange
import
theano
import
theano
from
theano.tensor
import
basic
from
theano.tensor
import
basic
from
theano.tensor
import
nlinalg
# noqa
from
theano
import
gof
,
scalar
from
theano
import
gof
,
scalar
from
theano.gradient
import
DisconnectedType
from
theano.gradient
import
DisconnectedType
tensor
=
basic
tensor
=
basic
...
...
theano/tensor/fourier.py
浏览文件 @
c89e1bc2
...
@@ -62,7 +62,7 @@ class Fourier(gof.Op):
...
@@ -62,7 +62,7 @@ class Fourier(gof.Op):
(
axis
.
data
<
0
or
axis
.
data
>
a
.
ndim
-
1
)):
(
axis
.
data
<
0
or
axis
.
data
>
a
.
ndim
-
1
)):
raise
TypeError
(
'
%
s: index of the transformed axis must be'
raise
TypeError
(
'
%
s: index of the transformed axis must be'
' a scalar not smaller than 0 and smaller than'
' a scalar not smaller than 0 and smaller than'
' dimension of array'
%
self
.
__class__
.
__name__
)
' dimension of array'
%
self
.
__class__
.
__name__
)
if
n
is
None
:
if
n
is
None
:
n
=
a
.
shape
[
axis
]
n
=
a
.
shape
[
axis
]
n
=
tensor
.
as_tensor_variable
(
n
)
n
=
tensor
.
as_tensor_variable
(
n
)
...
@@ -78,7 +78,7 @@ class Fourier(gof.Op):
...
@@ -78,7 +78,7 @@ class Fourier(gof.Op):
' strictly positive scalar'
' strictly positive scalar'
%
self
.
__class__
.
__name__
)
%
self
.
__class__
.
__name__
)
return
gof
.
Apply
(
self
,
[
a
,
n
,
axis
],
[
tensor
.
TensorType
(
'complex128'
,
return
gof
.
Apply
(
self
,
[
a
,
n
,
axis
],
[
tensor
.
TensorType
(
'complex128'
,
a
.
type
.
broadcastable
)()])
a
.
type
.
broadcastable
)()])
def
infer_shape
(
self
,
node
,
in_shapes
):
def
infer_shape
(
self
,
node
,
in_shapes
):
shape_a
=
in_shapes
[
0
]
shape_a
=
in_shapes
[
0
]
...
@@ -87,8 +87,8 @@ class Fourier(gof.Op):
...
@@ -87,8 +87,8 @@ class Fourier(gof.Op):
if
len
(
shape_a
)
==
1
:
if
len
(
shape_a
)
==
1
:
return
[(
n
,)]
return
[(
n
,)]
elif
isinstance
(
axis
,
tensor
.
TensorConstant
):
elif
isinstance
(
axis
,
tensor
.
TensorConstant
):
out_shape
=
list
(
shape_a
[
0
:
axis
.
data
.
item
()])
+
[
n
]
+
\
out_shape
=
(
list
(
shape_a
[
0
:
axis
.
data
.
item
()])
+
[
n
]
+
list
(
shape_a
[
axis
.
data
+
1
:]
)
list
(
shape_a
[
axis
.
data
+
1
:])
)
else
:
else
:
l
=
len
(
shape_a
)
l
=
len
(
shape_a
)
shape_a
=
tensor
.
stack
(
*
shape_a
)
shape_a
=
tensor
.
stack
(
*
shape_a
)
...
@@ -136,7 +136,8 @@ class Fourier(gof.Op):
...
@@ -136,7 +136,8 @@ class Fourier(gof.Op):
flip_shape
=
list
(
numpy
.
arange
(
0
,
a
.
ndim
)[::
-
1
])
flip_shape
=
list
(
numpy
.
arange
(
0
,
a
.
ndim
)[::
-
1
])
res
=
res
.
dimshuffle
(
flip_shape
)
res
=
res
.
dimshuffle
(
flip_shape
)
res
=
tensor
.
switch
(
tensor
.
lt
(
n
,
tensor
.
shape
(
a
)[
axis
]),
res
=
tensor
.
switch
(
tensor
.
lt
(
n
,
tensor
.
shape
(
a
)[
axis
]),
tensor
.
set_subtensor
(
res
[
n
::,
],
0
,
False
,
False
),
res
)
tensor
.
set_subtensor
(
res
[
n
::,
],
0
,
False
,
False
),
res
)
res
=
res
.
dimshuffle
(
flip_shape
)
res
=
res
.
dimshuffle
(
flip_shape
)
# insures that gradient shape conforms to input shape:
# insures that gradient shape conforms to input shape:
...
...
theano/tensor/nlinalg.py
浏览文件 @
c89e1bc2
from
__future__
import
print_function
from
__future__
import
print_function
import
logging
import
logging
import
theano
logger
=
logging
.
getLogger
(
__name__
)
import
numpy
import
numpy
from
six.moves
import
xrange
from
six.moves
import
xrange
import
theano
from
theano.tensor
import
as_tensor_variable
from
theano.gof
import
Op
,
Apply
from
theano.gof
import
Op
,
Apply
from
theano.tensor
import
as_tensor_variable
,
dot
,
DimShuffle
,
Dot
from
theano.tensor.blas
import
Dot22
from
theano.tensor.opt
import
(
register_stabilize
,
register_specialize
,
register_canonicalize
)
from
theano.gof
import
local_optimizer
from
theano.gof.opt
import
Optimizer
from
theano.gradient
import
DisconnectedType
from
theano.gradient
import
DisconnectedType
from
theano.tensor
import
basic
as
tensor
from
theano.tensor
import
basic
as
tensor
logger
=
logging
.
getLogger
(
__name__
)
class
MatrixPinv
(
Op
):
class
MatrixPinv
(
Op
):
"""Computes the pseudo-inverse of a matrix :math:`A`.
"""Computes the pseudo-inverse of a matrix :math:`A`.
...
@@ -427,8 +423,10 @@ class EighGrad(Op):
...
@@ -427,8 +423,10 @@ class EighGrad(Op):
N
=
x
.
shape
[
0
]
N
=
x
.
shape
[
0
]
outer
=
numpy
.
outer
outer
=
numpy
.
outer
G
=
lambda
n
:
sum
(
v
[:,
m
]
*
V
.
T
[
n
]
.
dot
(
v
[:,
m
])
/
(
w
[
n
]
-
w
[
m
])
def
G
(
n
):
for
m
in
xrange
(
N
)
if
m
!=
n
)
return
sum
(
v
[:,
m
]
*
V
.
T
[
n
]
.
dot
(
v
[:,
m
])
/
(
w
[
n
]
-
w
[
m
])
for
m
in
xrange
(
N
)
if
m
!=
n
)
g
=
sum
(
outer
(
v
[:,
n
],
v
[:,
n
]
*
W
[
n
]
+
G
(
n
))
g
=
sum
(
outer
(
v
[:,
n
],
v
[:,
n
]
*
W
[
n
]
+
G
(
n
))
for
n
in
xrange
(
N
))
for
n
in
xrange
(
N
))
...
@@ -641,16 +639,6 @@ def svd(a, full_matrices=1, compute_uv=1):
...
@@ -641,16 +639,6 @@ def svd(a, full_matrices=1, compute_uv=1):
return
SVD
(
full_matrices
,
compute_uv
)(
a
)
return
SVD
(
full_matrices
,
compute_uv
)(
a
)
def
test_matrix_inverse_solve
():
if
not
imported_scipy
:
raise
SkipTest
(
"Scipy needed for the Solve op."
)
A
=
theano
.
tensor
.
dmatrix
(
'A'
)
b
=
theano
.
tensor
.
dmatrix
(
'b'
)
node
=
matrix_inverse
(
A
)
.
dot
(
b
)
.
owner
[
out
]
=
inv_as_solve
.
transform
(
node
)
assert
isinstance
(
out
.
owner
.
op
,
Solve
)
class
lstsq
(
Op
):
class
lstsq
(
Op
):
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
return
type
(
self
)
==
type
(
other
)
...
@@ -670,9 +658,6 @@ class lstsq(Op):
...
@@ -670,9 +658,6 @@ class lstsq(Op):
theano
.
tensor
.
lscalar
(),
theano
.
tensor
.
dvector
()])
theano
.
tensor
.
lscalar
(),
theano
.
tensor
.
dvector
()])
def
perform
(
self
,
node
,
inputs
,
outputs
):
def
perform
(
self
,
node
,
inputs
,
outputs
):
x
=
inputs
[
0
]
y
=
inputs
[
1
]
rcond
=
inputs
[
2
]
zz
=
numpy
.
linalg
.
lstsq
(
inputs
[
0
],
inputs
[
1
],
inputs
[
2
])
zz
=
numpy
.
linalg
.
lstsq
(
inputs
[
0
],
inputs
[
1
],
inputs
[
2
])
outputs
[
0
][
0
]
=
zz
[
0
]
outputs
[
0
][
0
]
=
zz
[
0
]
outputs
[
1
][
0
]
=
zz
[
1
]
outputs
[
1
][
0
]
=
zz
[
1
]
...
@@ -703,7 +688,7 @@ def norm(x, ord):
...
@@ -703,7 +688,7 @@ def norm(x, ord):
return
x
[
x
.
nonzero
()]
.
shape
[
0
]
return
x
[
x
.
nonzero
()]
.
shape
[
0
]
else
:
else
:
try
:
try
:
z
=
tensor
.
sum
(
abs
(
x
**
ord
))
**
(
1.
/
ord
)
z
=
tensor
.
sum
(
abs
(
x
**
ord
))
**
(
1.
/
ord
)
except
TypeError
:
except
TypeError
:
raise
ValueError
(
"Invalid norm order for vectors."
)
raise
ValueError
(
"Invalid norm order for vectors."
)
return
z
return
z
...
...
theano/tensor/opt_uncanonicalize.py
浏览文件 @
c89e1bc2
...
@@ -33,7 +33,6 @@ supposed to be canonical.
...
@@ -33,7 +33,6 @@ supposed to be canonical.
# TODO: intelligent merge for mul/add
# TODO: intelligent merge for mul/add
# TODO: 0*x -> 0
# TODO: 0*x -> 0
import
logging
import
logging
_logger
=
logging
.
getLogger
(
'theano.tensor.opt'
)
from
theano
import
gof
from
theano
import
gof
from
theano.tensor.elemwise
import
CAReduce
from
theano.tensor.elemwise
import
CAReduce
...
@@ -44,6 +43,8 @@ from theano.tensor.basic import (get_scalar_constant_value,
...
@@ -44,6 +43,8 @@ from theano.tensor.basic import (get_scalar_constant_value,
from
theano.tensor.opt
import
register_uncanonicalize
from
theano.tensor.opt
import
register_uncanonicalize
from
theano
import
scalar
as
scal
from
theano
import
scalar
as
scal
_logger
=
logging
.
getLogger
(
'theano.tensor.opt'
)
@register_uncanonicalize
@register_uncanonicalize
@gof.local_optimizer
([
T
.
_max_and_argmax
])
@gof.local_optimizer
([
T
.
_max_and_argmax
])
...
@@ -81,8 +82,8 @@ def local_max_to_min(node):
...
@@ -81,8 +82,8 @@ def local_max_to_min(node):
if
node
.
op
==
T
.
neg
and
node
.
inputs
[
0
]
.
owner
:
if
node
.
op
==
T
.
neg
and
node
.
inputs
[
0
]
.
owner
:
max
=
node
.
inputs
[
0
]
max
=
node
.
inputs
[
0
]
if
(
max
.
owner
and
if
(
max
.
owner
and
isinstance
(
max
.
owner
.
op
,
CAReduce
)
isinstance
(
max
.
owner
.
op
,
CAReduce
)
and
and
max
.
owner
.
op
.
scalar_op
==
scal
.
maximum
):
max
.
owner
.
op
.
scalar_op
==
scal
.
maximum
):
neg
=
max
.
owner
.
inputs
[
0
]
neg
=
max
.
owner
.
inputs
[
0
]
if
neg
.
owner
and
neg
.
owner
.
op
==
T
.
neg
:
if
neg
.
owner
and
neg
.
owner
.
op
==
T
.
neg
:
return
[
CAReduce
(
scal
.
minimum
,
return
[
CAReduce
(
scal
.
minimum
,
...
...
theano/tensor/type.py
浏览文件 @
c89e1bc2
差异被折叠。
点击展开。
theano/tests/test_flake8.py
浏览文件 @
c89e1bc2
...
@@ -57,17 +57,7 @@ whitelist_flake8 = [
...
@@ -57,17 +57,7 @@ whitelist_flake8 = [
"typed_list/tests/test_type.py"
,
"typed_list/tests/test_type.py"
,
"typed_list/tests/test_opt.py"
,
"typed_list/tests/test_opt.py"
,
"typed_list/tests/test_basic.py"
,
"typed_list/tests/test_basic.py"
,
"tensor/blas_headers.py"
,
"tensor/type.py"
,
"tensor/fourier.py"
,
"tensor/__init__.py"
,
"tensor/__init__.py"
,
"tensor/opt_uncanonicalize.py"
,
"tensor/blas.py"
,
"tensor/extra_ops.py"
,
"tensor/nlinalg.py"
,
"tensor/blas_c.py"
,
"tensor/elemwise_cgen.py"
,
"tensor/blas_scipy.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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论