Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f4e3b36f
提交
f4e3b36f
authored
4月 24, 2014
作者:
Frederic
提交者:
Yann N. Dauphin
4月 25, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
some pep8
上级
8babd051
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
32 行增加
和
27 行删除
+32
-27
rng_mrg.py
theano/sandbox/rng_mrg.py
+32
-27
没有找到文件。
theano/sandbox/rng_mrg.py
浏览文件 @
f4e3b36f
...
@@ -42,7 +42,7 @@ def multMatVect(v, A, m1, B, m2):
...
@@ -42,7 +42,7 @@ def multMatVect(v, A, m1, B, m2):
Note: The parameters of dot_modulo are passed implicitly because passing
Note: The parameters of dot_modulo are passed implicitly because passing
them explicitly takes more time then running the function's C-code.
them explicitly takes more time then running the function's C-code.
"""
"""
if
multMatVect
.
dot_modulo
==
None
:
if
multMatVect
.
dot_modulo
is
None
:
A_sym
=
tensor
.
lmatrix
(
'A'
)
A_sym
=
tensor
.
lmatrix
(
'A'
)
s_sym
=
tensor
.
ivector
(
's'
)
s_sym
=
tensor
.
ivector
(
's'
)
m_sym
=
tensor
.
iscalar
(
'm'
)
m_sym
=
tensor
.
iscalar
(
'm'
)
...
@@ -187,42 +187,41 @@ def mrg_next_value(rstate, new_rstate):
...
@@ -187,42 +187,41 @@ def mrg_next_value(rstate, new_rstate):
x11
,
x12
,
x13
,
x21
,
x22
,
x23
=
rstate
x11
,
x12
,
x13
,
x21
,
x22
,
x23
=
rstate
assert
type
(
x11
)
==
numpy
.
int32
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)]
i0
,
i7
,
i9
,
i15
,
i16
,
i22
,
i24
=
np_int32_vals
i0
,
i7
,
i9
,
i15
,
i16
,
i22
,
i24
=
np_int32_vals
#first component
#first component
y1
=
(((
x12
&
MASK12
)
<<
i22
)
+
(
x12
>>
i9
)
+
y1
=
(((
x12
&
MASK12
)
<<
i22
)
+
(
x12
>>
i9
)
+
((
x13
&
MASK13
)
<<
i7
)
+
(
x13
>>
i24
))
((
x13
&
MASK13
)
<<
i7
)
+
(
x13
>>
i24
))
assert
type
(
y1
)
==
numpy
.
int32
assert
type
(
y1
)
==
numpy
.
int32
if
(
y1
<
0
or
y1
>=
M1
):
#
must also check overflow
if
(
y1
<
0
or
y1
>=
M1
):
#
must also check overflow
y1
-=
M1
;
y1
-=
M1
y1
+=
x13
;
y1
+=
x13
if
(
y1
<
0
or
y1
>=
M1
):
if
(
y1
<
0
or
y1
>=
M1
):
y1
-=
M1
;
y1
-=
M1
x13
=
x12
;
x13
=
x12
x12
=
x11
;
x12
=
x11
x11
=
y1
;
x11
=
y1
#second component
#second component
y1
=
((
x21
&
MASK2
)
<<
i15
)
+
(
MULT2
*
(
x21
>>
i16
))
;
y1
=
((
x21
&
MASK2
)
<<
i15
)
+
(
MULT2
*
(
x21
>>
i16
))
assert
type
(
y1
)
==
numpy
.
int32
assert
type
(
y1
)
==
numpy
.
int32
if
(
y1
<
0
or
y1
>=
M2
):
if
(
y1
<
0
or
y1
>=
M2
):
y1
-=
M2
;
y1
-=
M2
y2
=
((
x23
&
MASK2
)
<<
i15
)
+
(
MULT2
*
(
x23
>>
i16
))
;
y2
=
((
x23
&
MASK2
)
<<
i15
)
+
(
MULT2
*
(
x23
>>
i16
))
assert
type
(
y2
)
==
numpy
.
int32
assert
type
(
y2
)
==
numpy
.
int32
if
(
y2
<
0
or
y2
>=
M2
):
if
(
y2
<
0
or
y2
>=
M2
):
y2
-=
M2
;
y2
-=
M2
y2
+=
x23
;
y2
+=
x23
if
(
y2
<
0
or
y2
>=
M2
):
if
(
y2
<
0
or
y2
>=
M2
):
y2
-=
M2
;
y2
-=
M2
y2
+=
y1
;
y2
+=
y1
if
(
y2
<
0
or
y2
>=
M2
):
if
(
y2
<
0
or
y2
>=
M2
):
y2
-=
M2
;
y2
-=
M2
x23
=
x22
;
x23
=
x22
x22
=
x21
;
x22
=
x21
x21
=
y2
;
x21
=
y2
# Must never return either 0 or M1+1
# Must never return either 0 or M1+1
new_rstate
[
...
]
=
[
x11
,
x12
,
x13
,
x21
,
x22
,
x23
]
new_rstate
[
...
]
=
[
x11
,
x12
,
x13
,
x21
,
x22
,
x23
]
...
@@ -237,9 +236,9 @@ class mrg_uniform_base(Op):
...
@@ -237,9 +236,9 @@ class mrg_uniform_base(Op):
def
__init__
(
self
,
output_type
,
inplace
=
False
):
def
__init__
(
self
,
output_type
,
inplace
=
False
):
Op
.
__init__
(
self
)
Op
.
__init__
(
self
)
self
.
output_type
=
output_type
self
.
output_type
=
output_type
self
.
inplace
=
inplace
self
.
inplace
=
inplace
if
inplace
:
if
inplace
:
self
.
destroy_map
=
{
0
:[
0
]}
self
.
destroy_map
=
{
0
:
[
0
]}
self
.
warned_numpy_version
=
False
self
.
warned_numpy_version
=
False
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
...
@@ -291,8 +290,12 @@ class mrg_uniform(mrg_uniform_base):
...
@@ -291,8 +290,12 @@ class mrg_uniform(mrg_uniform_base):
rstate
,
size
=
inp
rstate
,
size
=
inp
o_rstate
,
o_sample
=
out
o_rstate
,
o_sample
=
out
numpy_version
=
numpy
.
__version__
.
split
(
'.'
)
numpy_version
=
numpy
.
__version__
.
split
(
'.'
)
if
not
self
.
warned_numpy_version
and
int
(
numpy_version
[
0
])
<=
1
and
int
(
numpy_version
[
1
])
<
3
:
print
"Warning: you must use numpy version 1.3.0 or higher with the python version of this op. Otherwise numpy leak memory."
if
(
not
self
.
warned_numpy_version
and
int
(
numpy_version
[
0
])
<=
1
and
int
(
numpy_version
[
1
])
<
3
):
print
"Warning: you must use numpy version 1.3.0 or higher with the python version of this op. Otherwise numpy leak memory. and numpy"
self
.
warned_numpy_version
=
True
self
.
warned_numpy_version
=
True
n_elements
=
1
n_elements
=
1
...
@@ -317,8 +320,9 @@ class mrg_uniform(mrg_uniform_base):
...
@@ -317,8 +320,9 @@ class mrg_uniform(mrg_uniform_base):
finally
:
finally
:
numpy
.
seterr
(
**
err_orig
)
numpy
.
seterr
(
**
err_orig
)
o_rstate
[
0
]
=
node
.
outputs
[
0
]
.
type
.
filter
(
rstate
)
# send to GPU if necessary
# send to GPU if necessary
o_sample
[
0
]
=
node
.
outputs
[
1
]
.
type
.
filter
(
rval
.
reshape
(
size
))
# send to GPU if necessary
o_rstate
[
0
]
=
node
.
outputs
[
0
]
.
type
.
filter
(
rstate
)
o_sample
[
0
]
=
node
.
outputs
[
1
]
.
type
.
filter
(
rval
.
reshape
(
size
))
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
rstate
,
size
=
inp
rstate
,
size
=
inp
...
@@ -1083,7 +1087,8 @@ class MRG_RandomStreams(object):
...
@@ -1083,7 +1087,8 @@ class MRG_RandomStreams(object):
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
,
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"
,
size
)
size
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论