Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e96f06da
提交
e96f06da
authored
10月 21, 2020
作者:
Brandon T. Willard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Apply pyupgrade to theano.sandbox
上级
2b658090
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
20 行增加
和
29 行删除
+20
-29
ops.py
theano/sandbox/linalg/ops.py
+3
-5
minimal.py
theano/sandbox/minimal.py
+1
-1
multinomial.py
theano/sandbox/multinomial.py
+3
-3
rng_mrg.py
theano/sandbox/rng_mrg.py
+13
-20
没有找到文件。
theano/sandbox/linalg/ops.py
浏览文件 @
e96f06da
import
logging
from
six
import
integer_types
import
theano.tensor
from
theano
import
tensor
from
theano.gof
import
Apply
,
Op
,
local_optimizer
...
...
@@ -84,7 +82,7 @@ def remove_hint_nodes(node):
return
node
.
inputs
class
HintsFeature
(
object
)
:
class
HintsFeature
:
"""
FunctionGraph Feature to track matrix properties.
...
...
@@ -120,7 +118,7 @@ class HintsFeature(object):
"""
def
add_hint
(
self
,
r
,
k
,
v
):
logger
.
debug
(
"adding hint;
%
s,
%
s,
%
s"
%
(
r
,
k
,
v
))
logger
.
debug
(
"adding hint;
{}, {}, {}"
.
format
(
r
,
k
,
v
))
self
.
hints
[
r
][
k
]
=
v
def
ensure_init_r
(
self
,
r
):
...
...
@@ -378,7 +376,7 @@ def spectral_radius_bound(X, log2_exponent):
"""
if
X
.
type
.
ndim
!=
2
:
raise
TypeError
(
"spectral_radius_bound requires a matrix argument"
,
X
)
if
not
isinstance
(
log2_exponent
,
int
eger_types
):
if
not
isinstance
(
log2_exponent
,
int
):
raise
TypeError
(
"spectral_radius_bound requires an integer exponent"
,
log2_exponent
)
...
...
theano/sandbox/minimal.py
浏览文件 @
e96f06da
...
...
@@ -20,7 +20,7 @@ class Minimal(gof.Op):
# - If they do not, then you should not use them in
# __eq__ and __hash__
super
(
Minimal
,
self
)
.
__init__
()
super
()
.
__init__
()
def
make_node
(
self
,
*
args
):
# HERE `args` must be THEANO VARIABLES
...
...
theano/sandbox/multinomial.py
浏览文件 @
e96f06da
...
...
@@ -22,7 +22,7 @@ class MultinomialFromUniform(Op):
self
.
odtype
=
odtype
def
__str__
(
self
):
return
"
%
s{
%
s}"
%
(
self
.
__class__
.
__name__
,
self
.
odtype
)
return
"
{}{{{}}}"
.
format
(
self
.
__class__
.
__name__
,
self
.
odtype
)
def
__setstate__
(
self
,
dct
):
self
.
__dict__
.
update
(
dct
)
...
...
@@ -230,7 +230,7 @@ class ChoiceFromUniform(MultinomialFromUniform):
def
__init__
(
self
,
odtype
,
replace
=
False
,
*
args
,
**
kwargs
):
self
.
replace
=
replace
super
(
ChoiceFromUniform
,
self
)
.
__init__
(
odtype
=
odtype
,
*
args
,
**
kwargs
)
super
()
.
__init__
(
odtype
=
odtype
,
*
args
,
**
kwargs
)
def
__setstate__
(
self
,
state
):
self
.
__dict__
.
update
(
state
)
...
...
@@ -442,4 +442,4 @@ class MultinomialWOReplacementFromUniform(ChoiceFromUniform):
DeprecationWarning
,
stacklevel
=
2
,
)
super
(
MultinomialWOReplacementFromUniform
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
super
()
.
__init__
(
*
args
,
**
kwargs
)
theano/sandbox/rng_mrg.py
浏览文件 @
e96f06da
...
...
@@ -16,7 +16,6 @@ P. L'Ecuyer and R. Simard and E. Jack Chen and W. David Kelton, An Object-Orient
import
warnings
import
numpy
as
np
from
six
import
integer_types
,
string_types
import
theano
from
theano
import
Apply
,
Op
,
Variable
,
config
,
function
,
gradient
,
shared
,
tensor
...
...
@@ -348,7 +347,7 @@ class mrg_uniform_base(Op):
s
=
"inplace"
else
:
s
=
"no_inplace"
return
self
.
__class__
.
__name__
+
"{
%
s,
%
s}"
%
(
self
.
output_type
,
s
)
return
self
.
__class__
.
__name__
+
"{
{{},{}}}"
.
format
(
self
.
output_type
,
s
)
def
grad
(
self
,
inputs
,
ograd
):
return
[
...
...
@@ -532,7 +531,7 @@ class mrg_uniform(mrg_uniform_base):
assert
isinstance
(
node
.
inputs
[
0
]
.
type
,
TensorType
)
if
self
.
output_type
.
dtype
==
"float16"
:
# C code is not tested, fall back to Python
super
(
mrg_uniform
,
self
)
.
c_code
(
node
,
name
,
inp
,
out
,
sub
)
super
()
.
c_code
(
node
,
name
,
inp
,
out
,
sub
)
return
"""
//////// <code generated by mrg_uniform>
npy_int64 odims_i;
...
...
@@ -672,9 +671,7 @@ def guess_n_streams(size, warn=False):
# TODO: a smart way of choosing the number of streams, see #612.
# Note that this code was moved out of `MRG_RandomStreams` so that it can
# be easily accessed from tests, where we want to disable the warning.
if
isinstance
(
size
,
(
tuple
,
list
))
and
all
(
[
isinstance
(
i
,
integer_types
)
for
i
in
size
]
):
if
isinstance
(
size
,
(
tuple
,
list
))
and
all
([
isinstance
(
i
,
int
)
for
i
in
size
]):
# We can make a guess.
r
=
1
for
s
in
size
:
...
...
@@ -704,7 +701,7 @@ def guess_n_streams(size, warn=False):
return
60
*
256
class
MRG_RandomStreams
(
object
)
:
class
MRG_RandomStreams
:
"""
Module component with similar interface to numpy.random
(numpy.random.RandomState).
...
...
@@ -730,7 +727,7 @@ class MRG_RandomStreams(object):
# by this RandomStreams.
self
.
state_updates
=
[]
super
(
MRG_RandomStreams
,
self
)
.
__init__
()
super
()
.
__init__
()
# Needed to reset the streams.
self
.
default_instance_seed
=
seed
...
...
@@ -739,7 +736,7 @@ class MRG_RandomStreams(object):
def
set_rstate
(
self
,
seed
):
# TODO : need description for method, parameter
if
isinstance
(
seed
,
int
eger_types
):
if
isinstance
(
seed
,
int
):
if
seed
==
0
:
raise
ValueError
(
"seed should not be 0"
,
seed
)
elif
seed
>=
M2
:
...
...
@@ -810,7 +807,7 @@ class MRG_RandomStreams(object):
and they are spaced by 2**72 samples.
"""
assert
isinstance
(
dtype
,
str
ing_types
)
assert
isinstance
(
dtype
,
str
)
assert
n_streams
<
2
**
72
assert
n_streams
>
0
rval
=
np
.
zeros
((
n_streams
,
6
),
dtype
=
"int32"
)
...
...
@@ -896,12 +893,8 @@ class MRG_RandomStreams(object):
if
isinstance
(
size
,
tuple
):
msg
=
"size must be a tuple of int or a Theano variable"
assert
all
(
[
isinstance
(
i
,
(
np
.
integer
,
integer_types
,
Variable
))
for
i
in
size
]
),
msg
if
any
(
[
isinstance
(
i
,
(
np
.
integer
,
integer_types
))
and
i
<=
0
for
i
in
size
]
):
assert
all
([
isinstance
(
i
,
(
np
.
integer
,
int
,
Variable
))
for
i
in
size
]),
msg
if
any
([
isinstance
(
i
,
(
np
.
integer
,
int
))
and
i
<=
0
for
i
in
size
]):
raise
ValueError
(
"The specified size contains a dimension with value <= 0"
,
size
)
...
...
@@ -994,7 +987,7 @@ class MRG_RandomStreams(object):
pvals
=
as_tensor_variable
(
pvals
)
pvals
=
undefined_grad
(
pvals
)
if
size
is
not
None
:
if
any
([
isinstance
(
i
,
int
eger_types
)
and
i
<=
0
for
i
in
size
]):
if
any
([
isinstance
(
i
,
int
)
and
i
<=
0
for
i
in
size
]):
raise
ValueError
(
"The specified size contains a dimension with value <= 0"
,
size
)
...
...
@@ -1017,7 +1010,7 @@ class MRG_RandomStreams(object):
return
op
(
pvals
,
unis
,
n_samples
)
else
:
raise
NotImplementedError
(
(
"MRG_RandomStreams.multinomial only"
" implemented for pvals.ndim = 2"
)
"MRG_RandomStreams.multinomial only"
" implemented for pvals.ndim = 2"
)
def
choice
(
...
...
@@ -1326,7 +1319,7 @@ def _check_size(size):
raise
ValueError
(
"Theano variable must have 1 dimension to be a valid size."
,
size
)
elif
isinstance
(
size
,
(
np
.
integer
,
int
eger_types
)):
elif
isinstance
(
size
,
(
np
.
integer
,
int
)):
return
tensor
.
constant
([
size
],
ndim
=
1
)
elif
not
isinstance
(
size
,
(
tuple
,
list
)):
raise
ValueError
(
"Size must be a int, tuple, list or Theano variable."
,
size
)
...
...
@@ -1336,7 +1329,7 @@ def _check_size(size):
if
isinstance
(
i
,
theano
.
Variable
):
if
i
.
ndim
!=
0
:
raise
ValueError
(
"Non-scalar Theano variable in size"
,
size
,
i
)
elif
isinstance
(
i
,
(
np
.
integer
,
int
eger_types
)):
elif
isinstance
(
i
,
(
np
.
integer
,
int
)):
if
i
<=
0
:
raise
ValueError
(
"Non-positive dimensions not allowed in size."
,
size
,
i
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论