Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ea0717ee
提交
ea0717ee
authored
2月 27, 2013
作者:
Olivier Delalleau
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
PEP8 and a minor code simplification
上级
4f4265ff
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
14 行增加
和
13 行删除
+14
-13
__init__.py
theano/compat/__init__.py
+0
-2
rng_mrg.py
theano/sandbox/rng_mrg.py
+14
-11
没有找到文件。
theano/compat/__init__.py
浏览文件 @
ea0717ee
...
...
@@ -10,7 +10,6 @@ if PY3:
from
operator
import
truediv
as
operator_div
# In python 3.x, when an exception is reraised it saves original
# exception in its args, therefore in order to find the actual
# message, we need to unpack arguments recursively.
...
...
@@ -36,7 +35,6 @@ else:
from
operator
import
div
as
operator_div
def
exc_message
(
e
):
return
e
[
0
]
...
...
theano/sandbox/rng_mrg.py
浏览文件 @
ea0717ee
...
...
@@ -693,7 +693,7 @@ class MRG_RandomStreams(object):
rval
=
numpy
.
zeros
((
n_streams
,
6
),
dtype
=
'int32'
)
rval
[
0
]
=
self
.
rstate
for
i
in
xrange
(
1
,
n_streams
):
rval
[
i
]
=
ff_2p72
(
rval
[
i
-
1
])
rval
[
i
]
=
ff_2p72
(
rval
[
i
-
1
])
if
inc_rstate
:
self
.
inc_rstate
()
return
rval
...
...
@@ -741,7 +741,7 @@ class MRG_RandomStreams(object):
if
isinstance
(
size
,
tuple
):
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
if
any
([
isinstance
(
i
,
(
numpy
.
integer
,
int
))
and
i
<=
0
for
i
in
size
]):
raise
ValueError
(
...
...
@@ -750,12 +750,12 @@ class MRG_RandomStreams(object):
else
:
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
:
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
=
rstates
.
flatten
()
# HACK - we use fact that int32 and float32 have same size to
...
...
@@ -779,10 +779,12 @@ class MRG_RandomStreams(object):
node_rstate
=
shared
(
self
.
get_substream_rstates
(
nstreams
))
u
=
self
.
pretty_return
(
node_rstate
,
*
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
:
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
return
r
...
...
@@ -836,9 +838,9 @@ class MRG_RandomStreams(object):
"MRG_RandomStreams.multinomial, which does not use "
"the ndim argument."
)
ndim
,
size
,
bcast
=
raw_random
.
_infer_ndim_bcast
(
ndim
,
size
,
pvals
[:,
0
])
assert
ndim
==
1
bcast
=
bcast
+
(
pvals
.
type
.
broadcastable
[
-
1
],)
ndim
,
size
,
pvals
[:,
0
])
assert
ndim
==
1
bcast
=
bcast
+
(
pvals
.
type
.
broadcastable
[
-
1
],)
unis
=
self
.
uniform
(
size
=
size
,
ndim
=
1
,
nstreams
=
nstreams
)
op
=
multinomial
.
MultinomialFromUniform
(
dtype
)
return
op
(
pvals
,
unis
)
...
...
@@ -882,7 +884,7 @@ class MRG_RandomStreams(object):
evened
=
True
else
:
#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
,
nstreams
=
nstreams
)
...
...
@@ -902,7 +904,7 @@ class MRG_RandomStreams(object):
# so trying this instead
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
)
final_samples
=
None
...
...
@@ -921,6 +923,7 @@ class MRG_RandomStreams(object):
assert
final_samples
.
dtype
==
dtype
return
final_samples
@local_optimizer
([
None
])
def
mrg_random_make_inplace
(
node
):
op
=
node
.
op
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论