Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
a5eb2288
提交
a5eb2288
authored
8月 10, 2015
作者:
Iban Harlouchet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
numpydoc for theano/sandbox/cuda/rng_curand.py
上级
909aa3d7
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
52 行增加
和
21 行删除
+52
-21
rng_curand.py
theano/sandbox/cuda/rng_curand.py
+52
-21
没有找到文件。
theano/sandbox/cuda/rng_curand.py
浏览文件 @
a5eb2288
"""
"""
Define CURAND_RandomStreams - backed by CURAND
Define CURAND_RandomStreams - backed by CURAND.
"""
"""
__authors__
=
"James Bergstra"
__authors__
=
"James Bergstra"
...
@@ -20,7 +21,8 @@ config = theano.config
...
@@ -20,7 +21,8 @@ config = theano.config
class
CURAND_Base
(
GpuOp
):
class
CURAND_Base
(
GpuOp
):
""" Base class for a random number generator implemented in CURAND.
"""
Base class for a random number generator implemented in CURAND.
The random number generator itself is an opaque reference managed by
The random number generator itself is an opaque reference managed by
CURAND. This Op uses a generic-typed shared variable to point to a CObject
CURAND. This Op uses a generic-typed shared variable to point to a CObject
...
@@ -30,18 +32,23 @@ class CURAND_Base(GpuOp):
...
@@ -30,18 +32,23 @@ class CURAND_Base(GpuOp):
The actual random number generator is allocated from the seed, on the first
The actual random number generator is allocated from the seed, on the first
call to allocate random numbers (see c_code).
call to allocate random numbers (see c_code).
:note:
Parameters
One caveat is that the random number state is simply not serializable.
----------
Consequently, attempts to serialize functions compiled with these
output_type
random numbers will fail.
A theano type (e.g. tensor.fvector).
seed: int
destructive
True or False (on the generator)
Notes
-----
One caveat is that the random number state is simply not serializable.
Consequently, attempts to serialize functions compiled with these
random numbers will fail.
"""
"""
def
__init__
(
self
,
output_type
,
seed
,
destructive
):
def
__init__
(
self
,
output_type
,
seed
,
destructive
):
"""
output_type: a theano type (e.g. tensor.fvector)
seed: integer
destructive: True or False (on the generator)
"""
theano
.
gof
.
Op
.
__init__
(
self
)
theano
.
gof
.
Op
.
__init__
(
self
)
self
.
destructive
=
destructive
self
.
destructive
=
destructive
self
.
seed
=
seed
self
.
seed
=
seed
...
@@ -51,11 +58,17 @@ class CURAND_Base(GpuOp):
...
@@ -51,11 +58,17 @@ class CURAND_Base(GpuOp):
assert
output_type
.
dtype
==
"float32"
assert
output_type
.
dtype
==
"float32"
def
as_destructive
(
self
):
def
as_destructive
(
self
):
"""Return an destructive version of self"""
"""
Return an destructive version of self.
"""
return
self
.
__class__
(
self
.
output_type
,
self
.
seed
,
destructive
=
True
)
return
self
.
__class__
(
self
.
output_type
,
self
.
seed
,
destructive
=
True
)
def
_config
(
self
):
def
_config
(
self
):
"""Return a tuple of attributes that define the Op"""
"""
Return a tuple of attributes that define the Op.
"""
return
(
return
(
self
.
destructive
,
self
.
destructive
,
self
.
output_type
,
self
.
output_type
,
...
@@ -81,7 +94,7 @@ class CURAND_Base(GpuOp):
...
@@ -81,7 +94,7 @@ class CURAND_Base(GpuOp):
"""
"""
Return a symbolic sample from generator.
Return a symbolic sample from generator.
cls dictates the random variable (e.g. uniform, normal)
cls dictates the random variable (e.g. uniform, normal)
.
"""
"""
v_size
=
theano
.
tensor
.
as_tensor_variable
(
size
)
v_size
=
theano
.
tensor
.
as_tensor_variable
(
size
)
...
@@ -237,8 +250,11 @@ class CURAND_Base(GpuOp):
...
@@ -237,8 +250,11 @@ class CURAND_Base(GpuOp):
class
CURAND_Normal
(
CURAND_Base
):
class
CURAND_Normal
(
CURAND_Base
):
"""Op to draw normal numbers using CURAND
"""
"""
Op to draw normal numbers using CURAND.
"""
def
_curand_call_str
(
self
,
**
kwargs
):
def
_curand_call_str
(
self
,
**
kwargs
):
return
"""curandGenerateNormal(*gen,
return
"""curandGenerateNormal(*gen,
CudaNdarray_DEV_DATA(
%(o_sample)
s),
CudaNdarray_DEV_DATA(
%(o_sample)
s),
...
@@ -248,8 +264,11 @@ class CURAND_Normal(CURAND_Base):
...
@@ -248,8 +264,11 @@ class CURAND_Normal(CURAND_Base):
class
CURAND_Uniform
(
CURAND_Base
):
class
CURAND_Uniform
(
CURAND_Base
):
"""Op to draw uniform numbers using CURAND
"""
"""
Op to draw uniform numbers using CURAND.
"""
def
_curand_call_str
(
self
,
**
kwargs
):
def
_curand_call_str
(
self
,
**
kwargs
):
return
""" curandGenerateUniform(*gen,
return
""" curandGenerateUniform(*gen,
CudaNdarray_DEV_DATA(
%(o_sample)
s),
CudaNdarray_DEV_DATA(
%(o_sample)
s),
...
@@ -262,24 +281,31 @@ class CURAND_RandomStreams(object):
...
@@ -262,24 +281,31 @@ class CURAND_RandomStreams(object):
RandomStreams instance that creates CURAND-based random variables.
RandomStreams instance that creates CURAND-based random variables.
One caveat is that generators are not serializable.
One caveat is that generators are not serializable.
Parameters
----------
seed : int
"""
"""
def
__init__
(
self
,
seed
):
def
__init__
(
self
,
seed
):
""" seed: int
"""
self
.
_start_seed
=
seed
self
.
_start_seed
=
seed
self
.
_cur_seed
=
seed
self
.
_cur_seed
=
seed
self
.
_has_lost_states
=
False
# True if self.state_updates incomplete
self
.
_has_lost_states
=
False
# True if self.state_updates incomplete
self
.
state_updates
=
[]
self
.
state_updates
=
[]
def
updates
(
self
):
def
updates
(
self
):
"""List of all (old, new) generator update pairs created by this
"""
List of all (old, new) generator update pairs created by this
instance.
instance.
"""
"""
return
list
(
self
.
state_updates
)
return
list
(
self
.
state_updates
)
def
next_seed
(
self
):
def
next_seed
(
self
):
"""Return a unique seed for initializing a random variable.
"""
Return a unique seed for initializing a random variable.
"""
"""
self
.
_cur_seed
+=
1
self
.
_cur_seed
+=
1
return
self
.
_cur_seed
-
1
return
self
.
_cur_seed
-
1
...
@@ -295,6 +321,7 @@ class CURAND_RandomStreams(object):
...
@@ -295,6 +321,7 @@ class CURAND_RandomStreams(object):
dtype
=
config
.
floatX
):
dtype
=
config
.
floatX
):
"""
"""
Return symbolic tensor of uniform numbers.
Return symbolic tensor of uniform numbers.
"""
"""
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"
...
@@ -321,8 +348,12 @@ class CURAND_RandomStreams(object):
...
@@ -321,8 +348,12 @@ class CURAND_RandomStreams(object):
"""
"""
Return symbolic tensor of normally-distributed numbers.
Return symbolic tensor of normally-distributed numbers.
:param: size: Can be a list of integer or Theano variable(ex: the shape
Parameters
----------
size
Can be a list of integer or Theano variable (ex: the shape
of other Theano Variable)
of other Theano Variable)
"""
"""
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"
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论