Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
85b28c25
提交
85b28c25
authored
3月 17, 2011
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rng_mrg - use numpy.seterr to suppress overflow warnings
上级
9f5955d0
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
61 行增加
和
53 行删除
+61
-53
rng_mrg.py
theano/sandbox/rng_mrg.py
+61
-53
没有找到文件。
theano/sandbox/rng_mrg.py
浏览文件 @
85b28c25
...
...
@@ -31,11 +31,15 @@ def mulmod(a, b, c, m):
def
matVecModM
(
A
,
s
,
m
):
# return (A * s) % m
x
=
numpy
.
zeros_like
(
s
)
for
i
in
xrange
(
len
(
x
)):
for
j
in
xrange
(
len
(
s
)):
x
[
i
]
=
mulmod
(
A
[
i
][
j
],
s
[
j
],
x
[
i
],
m
)
return
x
err_orig
=
numpy
.
seterr
(
over
=
'ignore'
)
try
:
x
=
numpy
.
zeros_like
(
s
)
for
i
in
xrange
(
len
(
x
)):
for
j
in
xrange
(
len
(
s
)):
x
[
i
]
=
mulmod
(
A
[
i
][
j
],
s
[
j
],
x
[
i
],
m
)
return
x
finally
:
numpy
.
seterr
(
**
err_orig
)
def
multMatVect
(
v
,
A
,
m1
,
B
,
m2
):
#multiply the first half of v by A with a modulo of m1
...
...
@@ -81,54 +85,58 @@ def ff_2p72(rstate):
return
multMatVect
(
rstate
,
A1p72
,
M1
,
A2p72
,
M2
)
def
mrg_next_value
(
rstate
,
new_rstate
):
x11
,
x12
,
x13
,
x21
,
x22
,
x23
=
rstate
assert
type
(
x11
)
==
numpy
.
int32
i0
,
i7
,
i9
,
i15
,
i16
,
i22
,
i24
=
[
numpy
.
int32
(
i
)
for
i
in
(
0
,
7
,
9
,
15
,
16
,
22
,
24
)]
#first component
y1
=
(((
x12
&
MASK12
)
<<
i22
)
+
(
x12
>>
i9
)
+
((
x13
&
MASK13
)
<<
i7
)
+
(
x13
>>
i24
))
assert
type
(
y1
)
==
numpy
.
int32
if
(
y1
<
0
or
y1
>=
M1
):
#must also check overflow
y1
-=
M1
;
y1
+=
x13
;
if
(
y1
<
0
or
y1
>=
M1
):
y1
-=
M1
;
x13
=
x12
;
x12
=
x11
;
x11
=
y1
;
#second component
y1
=
((
x21
&
MASK2
)
<<
i15
)
+
(
MULT2
*
(
x21
>>
i16
));
assert
type
(
y1
)
==
numpy
.
int32
if
(
y1
<
0
or
y1
>=
M2
):
y1
-=
M2
;
y2
=
((
x23
&
MASK2
)
<<
i15
)
+
(
MULT2
*
(
x23
>>
i16
));
assert
type
(
y2
)
==
numpy
.
int32
if
(
y2
<
0
or
y2
>=
M2
):
y2
-=
M2
;
y2
+=
x23
;
if
(
y2
<
0
or
y2
>=
M2
):
y2
-=
M2
;
y2
+=
y1
;
if
(
y2
<
0
or
y2
>=
M2
):
y2
-=
M2
;
x23
=
x22
;
x22
=
x21
;
x21
=
y2
;
# Must never return either 0 or M1+1
new_rstate
[
...
]
=
[
x11
,
x12
,
x13
,
x21
,
x22
,
x23
]
assert
new_rstate
.
dtype
==
numpy
.
int32
if
(
x11
<=
x21
):
return
(
x11
-
x21
+
M1
)
*
NORM
else
:
return
(
x11
-
x21
)
*
NORM
err_orig
=
numpy
.
seterr
(
over
=
'ignore'
)
try
:
x11
,
x12
,
x13
,
x21
,
x22
,
x23
=
rstate
assert
type
(
x11
)
==
numpy
.
int32
i0
,
i7
,
i9
,
i15
,
i16
,
i22
,
i24
=
[
numpy
.
int32
(
i
)
for
i
in
(
0
,
7
,
9
,
15
,
16
,
22
,
24
)]
#first component
y1
=
(((
x12
&
MASK12
)
<<
i22
)
+
(
x12
>>
i9
)
+
((
x13
&
MASK13
)
<<
i7
)
+
(
x13
>>
i24
))
assert
type
(
y1
)
==
numpy
.
int32
if
(
y1
<
0
or
y1
>=
M1
):
#must also check overflow
y1
-=
M1
;
y1
+=
x13
;
if
(
y1
<
0
or
y1
>=
M1
):
y1
-=
M1
;
x13
=
x12
;
x12
=
x11
;
x11
=
y1
;
#second component
y1
=
((
x21
&
MASK2
)
<<
i15
)
+
(
MULT2
*
(
x21
>>
i16
));
assert
type
(
y1
)
==
numpy
.
int32
if
(
y1
<
0
or
y1
>=
M2
):
y1
-=
M2
;
y2
=
((
x23
&
MASK2
)
<<
i15
)
+
(
MULT2
*
(
x23
>>
i16
));
assert
type
(
y2
)
==
numpy
.
int32
if
(
y2
<
0
or
y2
>=
M2
):
y2
-=
M2
;
y2
+=
x23
;
if
(
y2
<
0
or
y2
>=
M2
):
y2
-=
M2
;
y2
+=
y1
;
if
(
y2
<
0
or
y2
>=
M2
):
y2
-=
M2
;
x23
=
x22
;
x22
=
x21
;
x21
=
y2
;
# Must never return either 0 or M1+1
new_rstate
[
...
]
=
[
x11
,
x12
,
x13
,
x21
,
x22
,
x23
]
assert
new_rstate
.
dtype
==
numpy
.
int32
if
(
x11
<=
x21
):
return
(
x11
-
x21
+
M1
)
*
NORM
else
:
return
(
x11
-
x21
)
*
NORM
finally
:
numpy
.
seterr
(
**
err_orig
)
class
mrg_uniform_base
(
Op
):
def
__init__
(
self
,
output_type
,
inplace
=
False
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论