Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
33a8c9de
提交
33a8c9de
authored
2月 27, 2013
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1253 from delallea/minor
Minor fixes
上级
1e419a5d
08ad8b0d
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
25 行增加
和
32 行删除
+25
-32
__init__.py
theano/compat/__init__.py
+2
-4
pfunc.py
theano/compile/pfunc.py
+0
-1
rng_mrg.py
theano/sandbox/rng_mrg.py
+16
-13
test_basic.py
theano/sparse/tests/test_basic.py
+7
-14
没有找到文件。
theano/compat/__init__.py
浏览文件 @
33a8c9de
...
@@ -10,10 +10,9 @@ if PY3:
...
@@ -10,10 +10,9 @@ if PY3:
from
operator
import
truediv
as
operator_div
from
operator
import
truediv
as
operator_div
# In python 3.x, when an exception is reraised it saves original
# In python 3.x, when an exception is reraised it saves original
# exception in its args, therefore in order to find the actual
# exception in its args, therefore in order to find the actual
# message, we need to unpack arguments recur
c
ively.
# message, we need to unpack arguments recur
s
ively.
def
exc_message
(
e
):
def
exc_message
(
e
):
msg
=
e
.
args
[
0
]
msg
=
e
.
args
[
0
]
if
isinstance
(
msg
,
Exception
):
if
isinstance
(
msg
,
Exception
):
...
@@ -21,7 +20,7 @@ if PY3:
...
@@ -21,7 +20,7 @@ if PY3:
return
msg
return
msg
def
cmp
(
a
,
b
):
def
cmp
(
a
,
b
):
"""Return -1 if x
<y, 0 if x==
y, 1 if x > y."""
"""Return -1 if x
< y, 0 if x ==
y, 1 if x > y."""
return
(
a
>
b
)
-
(
a
<
b
)
return
(
a
>
b
)
-
(
a
<
b
)
all
=
all
all
=
all
...
@@ -36,7 +35,6 @@ else:
...
@@ -36,7 +35,6 @@ else:
from
operator
import
div
as
operator_div
from
operator
import
div
as
operator_div
def
exc_message
(
e
):
def
exc_message
(
e
):
return
e
[
0
]
return
e
[
0
]
...
...
theano/compile/pfunc.py
浏览文件 @
33a8c9de
...
@@ -293,7 +293,6 @@ class Param(object):
...
@@ -293,7 +293,6 @@ class Param(object):
`mutable` flag.
`mutable` flag.
False: do not permit any output to be aliased to the input
False: do not permit any output to be aliased to the input
False: do not permit any output to be aliased to the input
:param strict: False -> function arguments may be copied or cast to match the
:param strict: False -> function arguments may be copied or cast to match the
type required by the parameter `variable`.
type required by the parameter `variable`.
True -> function arguments must exactly match the type
True -> function arguments must exactly match the type
...
...
theano/sandbox/rng_mrg.py
浏览文件 @
33a8c9de
...
@@ -615,7 +615,7 @@ def guess_n_streams(size, warn=True):
...
@@ -615,7 +615,7 @@ def guess_n_streams(size, warn=True):
for
s
in
size
:
for
s
in
size
:
r
*=
s
r
*=
s
if
r
>
6
:
if
r
>
6
:
r
=
r
//
6
# chosen as fastest for rbm_benchmark
r
=
r
//
6
# chosen as fastest for rbm_benchmark
# The purpose of sampling from many streams is to be able to use
# The purpose of sampling from many streams is to be able to use
# the GPU to its full capacity. It just wastes RAM and stream-initialization time to
# the GPU to its full capacity. It just wastes RAM and stream-initialization time to
...
@@ -693,7 +693,7 @@ class MRG_RandomStreams(object):
...
@@ -693,7 +693,7 @@ class MRG_RandomStreams(object):
rval
=
numpy
.
zeros
((
n_streams
,
6
),
dtype
=
'int32'
)
rval
=
numpy
.
zeros
((
n_streams
,
6
),
dtype
=
'int32'
)
rval
[
0
]
=
self
.
rstate
rval
[
0
]
=
self
.
rstate
for
i
in
xrange
(
1
,
n_streams
):
for
i
in
xrange
(
1
,
n_streams
):
rval
[
i
]
=
ff_2p72
(
rval
[
i
-
1
])
rval
[
i
]
=
ff_2p72
(
rval
[
i
-
1
])
if
inc_rstate
:
if
inc_rstate
:
self
.
inc_rstate
()
self
.
inc_rstate
()
return
rval
return
rval
...
@@ -741,8 +741,8 @@ class MRG_RandomStreams(object):
...
@@ -741,8 +741,8 @@ class MRG_RandomStreams(object):
if
isinstance
(
size
,
tuple
):
if
isinstance
(
size
,
tuple
):
msg
=
"size must be a tuple of int or a Theano variable"
msg
=
"size must be a tuple of int or a Theano variable"
assert
all
([
isinstance
(
i
,
(
numpy
.
integer
,
int
))
or
isinstance
(
i
,
Variable
)
assert
all
([
isinstance
(
i
,
(
numpy
.
integer
,
int
,
Variable
)
)
for
i
in
size
]),
msg
for
i
in
size
]),
msg
if
any
([
isinstance
(
i
,
(
numpy
.
integer
,
int
))
and
i
<=
0
for
i
in
size
]):
if
any
([
isinstance
(
i
,
(
numpy
.
integer
,
int
))
and
i
<=
0
for
i
in
size
]):
raise
ValueError
(
raise
ValueError
(
"The specified size contains a dimension with value <= 0"
,
"The specified size contains a dimension with value <= 0"
,
...
@@ -750,12 +750,12 @@ class MRG_RandomStreams(object):
...
@@ -750,12 +750,12 @@ class MRG_RandomStreams(object):
else
:
else
:
msg
=
"size must be a tuple of int or a Theano variable"
msg
=
"size must be a tuple of int or a Theano variable"
assert
isinstance
(
size
,
Variable
)
and
size
.
ndim
==
1
,
msg
assert
isinstance
(
size
,
Variable
)
and
size
.
ndim
==
1
,
msg
if
nstreams
is
None
:
if
nstreams
is
None
:
nstreams
=
self
.
n_streams
(
size
)
nstreams
=
self
.
n_streams
(
size
)
if
self
.
use_cuda
and
dtype
==
'float32'
:
if
self
.
use_cuda
and
dtype
==
'float32'
:
rstates
=
self
.
get_substream_rstates
(
nstreams
)
rstates
=
self
.
get_substream_rstates
(
nstreams
)
rstates
=
rstates
.
flatten
()
rstates
=
rstates
.
flatten
()
# HACK - we use fact that int32 and float32 have same size to
# HACK - we use fact that int32 and float32 have same size to
...
@@ -779,10 +779,12 @@ class MRG_RandomStreams(object):
...
@@ -779,10 +779,12 @@ class MRG_RandomStreams(object):
node_rstate
=
shared
(
self
.
get_substream_rstates
(
nstreams
))
node_rstate
=
shared
(
self
.
get_substream_rstates
(
nstreams
))
u
=
self
.
pretty_return
(
node_rstate
,
u
=
self
.
pretty_return
(
node_rstate
,
*
mrg_uniform
.
new
(
node_rstate
,
ndim
,
dtype
,
size
))
*
mrg_uniform
.
new
(
node_rstate
,
ndim
,
dtype
,
size
))
r
=
u
*
(
high
-
low
)
+
low
r
=
u
*
(
high
-
low
)
+
low
if
u
.
type
.
broadcastable
!=
r
.
type
.
broadcastable
:
if
u
.
type
.
broadcastable
!=
r
.
type
.
broadcastable
:
raise
NotImplementedError
(
'Increase the size to match the broadcasting pattern of `low` and `high` arguments'
)
raise
NotImplementedError
(
'Increase the size to match the broadcasting pattern of '
'`low` and `high` arguments'
)
assert
r
.
dtype
==
dtype
assert
r
.
dtype
==
dtype
return
r
return
r
...
@@ -836,9 +838,9 @@ class MRG_RandomStreams(object):
...
@@ -836,9 +838,9 @@ class MRG_RandomStreams(object):
"MRG_RandomStreams.multinomial, which does not use "
"MRG_RandomStreams.multinomial, which does not use "
"the ndim argument."
)
"the ndim argument."
)
ndim
,
size
,
bcast
=
raw_random
.
_infer_ndim_bcast
(
ndim
,
size
,
bcast
=
raw_random
.
_infer_ndim_bcast
(
ndim
,
size
,
pvals
[:,
0
])
ndim
,
size
,
pvals
[:,
0
])
assert
ndim
==
1
assert
ndim
==
1
bcast
=
bcast
+
(
pvals
.
type
.
broadcastable
[
-
1
],)
bcast
=
bcast
+
(
pvals
.
type
.
broadcastable
[
-
1
],)
unis
=
self
.
uniform
(
size
=
size
,
ndim
=
1
,
nstreams
=
nstreams
)
unis
=
self
.
uniform
(
size
=
size
,
ndim
=
1
,
nstreams
=
nstreams
)
op
=
multinomial
.
MultinomialFromUniform
(
dtype
)
op
=
multinomial
.
MultinomialFromUniform
(
dtype
)
return
op
(
pvals
,
unis
)
return
op
(
pvals
,
unis
)
...
@@ -882,7 +884,7 @@ class MRG_RandomStreams(object):
...
@@ -882,7 +884,7 @@ class MRG_RandomStreams(object):
evened
=
True
evened
=
True
else
:
else
:
#if even, don't change, if odd, +1
#if even, don't change, if odd, +1
n_samples
=
prod
(
size
)
+
(
prod
(
size
)
%
2
)
n_samples
=
prod
(
size
)
+
(
prod
(
size
)
%
2
)
flattened
=
self
.
uniform
(
size
=
(
n_samples
,),
dtype
=
dtype
,
flattened
=
self
.
uniform
(
size
=
(
n_samples
,),
dtype
=
dtype
,
nstreams
=
nstreams
)
nstreams
=
nstreams
)
...
@@ -902,7 +904,7 @@ class MRG_RandomStreams(object):
...
@@ -902,7 +904,7 @@ class MRG_RandomStreams(object):
# so trying this instead
# so trying this instead
first_half
=
sqrt_ln_U1
*
cos
(
numpy
.
array
(
2.0
*
numpy
.
pi
,
dtype
=
dtype
)
*
U2
)
first_half
=
sqrt_ln_U1
*
cos
(
numpy
.
array
(
2.0
*
numpy
.
pi
,
dtype
=
dtype
)
*
U2
)
second_half
=
sqrt_ln_U1
*
sin
(
numpy
.
array
(
2.0
*
numpy
.
pi
,
dtype
=
dtype
)
*
U2
)
second_half
=
sqrt_ln_U1
*
sin
(
numpy
.
array
(
2.0
*
numpy
.
pi
,
dtype
=
dtype
)
*
U2
)
normal_samples
=
join
(
0
,
first_half
,
second_half
)
normal_samples
=
join
(
0
,
first_half
,
second_half
)
final_samples
=
None
final_samples
=
None
...
@@ -921,6 +923,7 @@ class MRG_RandomStreams(object):
...
@@ -921,6 +923,7 @@ class MRG_RandomStreams(object):
assert
final_samples
.
dtype
==
dtype
assert
final_samples
.
dtype
==
dtype
return
final_samples
return
final_samples
@local_optimizer
([
None
])
@local_optimizer
([
None
])
def
mrg_random_make_inplace
(
node
):
def
mrg_random_make_inplace
(
node
):
op
=
node
.
op
op
=
node
.
op
...
...
theano/sparse/tests/test_basic.py
浏览文件 @
33a8c9de
...
@@ -1773,20 +1773,13 @@ class Remove0Tester(utt.InferShapeTester):
...
@@ -1773,20 +1773,13 @@ class Remove0Tester(utt.InferShapeTester):
if
theano
.
config
.
mode
not
in
[
'FAST_COMPILE'
]:
if
theano
.
config
.
mode
not
in
[
'FAST_COMPILE'
]:
# list of apply nodes in the optimized graph.
# list of apply nodes in the optimized graph.
nodes
=
f
.
maker
.
fgraph
.
toposort
()
nodes
=
f
.
maker
.
fgraph
.
toposort
()
v
=
[
True
for
node
in
nodes
]
# Check there isn't any Remove0 instance not inplace.
# In python 3, list comprehention variables do not leak
assert
not
any
([
isinstance
(
node
.
op
,
Remove0
)
and
# in the outside scope, so we bind node varible below
not
node
.
op
.
inplace
for
node
in
nodes
]),
(
# to make the code behave the same under all
'Inplace optimization should have been applied'
)
# versions. However, the logic here does not look
# Check there is at least one Remove0 inplace.
# right: the length of v is always the same as that of
assert
any
([
isinstance
(
node
.
op
,
Remove0
)
and
node
.
op
.
inplace
# nodes and the only result of the assert is to check
for
node
in
nodes
])
# that nodes is not empty. The intent was probably to
# keep if clause inside the [] and check every node.
node
=
nodes
[
-
1
]
if
isinstance
(
node
.
op
,
Remove0
)
and
node
.
op
.
inplace
:
assert
len
(
v
),
\
'Inplacing optimization should have been applied.'
# checking
# checking
# makes sense to change its name
# makes sense to change its name
target
=
mat
target
=
mat
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论