Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
fe11af02
提交
fe11af02
authored
2月 04, 2010
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Minor changes in documentation formatting, comment debug prints.
上级
c5204d53
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
24 行增加
和
20 行删除
+24
-20
raw_random.py
theano/tensor/raw_random.py
+24
-20
没有找到文件。
theano/tensor/raw_random.py
浏览文件 @
fe11af02
...
@@ -106,32 +106,36 @@ class RandomFunction(gof.Op):
...
@@ -106,32 +106,36 @@ class RandomFunction(gof.Op):
def
make_node
(
self
,
r
,
shape
,
*
args
):
def
make_node
(
self
,
r
,
shape
,
*
args
):
"""
"""
:param r: a numpy.RandomState instance, or a Variable of Type RandomStateType that will
:param r: a numpy.RandomState instance, or a Variable of Type
contain a RandomState instance.
RandomStateType that will contain a RandomState instance.
:param shape: an lvector with a shape defining how many samples to draw.
:param shape: an lvector with a shape defining how many samples
In the case of scalar distributions, it is the shape of the tensor output by this Op.
to draw. In the case of scalar distributions, it is the shape
In that case, at runtime, the value associated with this lvector must have a length
of the tensor output by this Op. In that case, at runtime, the
equal to the number of dimensions promised by `self.outtype`.
value associated with this lvector must have a length equal to
In general, the number of output dimenstions is equal to
the number of dimensions promised by `self.outtype`.
len(self.outtype)+self.ndim_added.
In a more general case, the number of output dimensions,
len(self.outtype), is equal to len(shape)+self.ndim_added.
:param args: the values associated with these variables will be passed to the RandomState
The special case where len(shape) == 0 means that the smallest
function during perform as extra "*args"-style arguments. These should be castable to
shape compatible with the argument's shape will be used.
variables of Type TensorType.
:param args: the values associated with these variables will
be passed to the RandomState function during perform as extra
"*args"-style arguments. These should be castable to variables
of Type TensorType.
:rtype: Apply
:rtype: Apply
:return: Apply with two outputs. The first output is a gof.generic Variable from which
:return: Apply with two outputs. The first output is a
to draw further random numbers. The second output is the outtype() instance holding
gof.generic Variable from which to draw further random numbers.
the random draw.
The second output is the outtype() instance holding the random
draw.
"""
"""
if
shape
==
()
or
shape
==
[]:
if
shape
==
()
or
shape
==
[]:
shape
=
tensor
.
lvector
()
shape
=
tensor
.
lvector
()
else
:
else
:
shape
=
tensor
.
as_tensor_variable
(
shape
,
ndim
=
1
)
shape
=
tensor
.
as_tensor_variable
(
shape
,
ndim
=
1
)
#print 'SHAPE TYPE', shape.type, tensor.lvector
assert
shape
.
type
.
ndim
==
1
assert
shape
.
type
.
ndim
==
1
assert
(
shape
.
type
.
dtype
==
'int64'
)
or
(
shape
.
type
.
dtype
==
'int32'
)
assert
(
shape
.
type
.
dtype
==
'int64'
)
or
(
shape
.
type
.
dtype
==
'int32'
)
if
not
isinstance
(
r
.
type
,
RandomStateType
):
if
not
isinstance
(
r
.
type
,
RandomStateType
):
...
@@ -211,7 +215,7 @@ def _infer_ndim(ndim, shape, *args):
...
@@ -211,7 +215,7 @@ def _infer_ndim(ndim, shape, *args):
# The shape will be computed at runtime, but we need to know ndim
# The shape will be computed at runtime, but we need to know ndim
v_shape
=
tensor
.
constant
([],
dtype
=
'int64'
)
v_shape
=
tensor
.
constant
([],
dtype
=
'int64'
)
if
ndim
is
None
:
if
ndim
is
None
:
ndim
=
args_dim
ndim
=
args_
n
dim
else
:
else
:
v_shape
=
tensor
.
as_tensor_variable
(
shape
)
v_shape
=
tensor
.
as_tensor_variable
(
shape
)
...
@@ -316,7 +320,7 @@ def permutation_helper(random_state, n, shape):
...
@@ -316,7 +320,7 @@ def permutation_helper(random_state, n, shape):
for
i
in
numpy
.
ndindex
(
*
shape
):
for
i
in
numpy
.
ndindex
(
*
shape
):
out
[
i
]
=
random_state
.
permutation
(
n
)
out
[
i
]
=
random_state
.
permutation
(
n
)
print
'RETURNING'
,
out
.
shape
#
print 'RETURNING', out.shape
return
out
return
out
def
permutation
(
random_state
,
size
=
None
,
n
=
1
,
ndim
=
None
):
def
permutation
(
random_state
,
size
=
None
,
n
=
1
,
ndim
=
None
):
...
@@ -333,7 +337,7 @@ def permutation(random_state, size=None, n=1, ndim=None):
...
@@ -333,7 +337,7 @@ def permutation(random_state, size=None, n=1, ndim=None):
Note that the output will then be of dimension ndim+1.
Note that the output will then be of dimension ndim+1.
"""
"""
ndim
,
size
=
_infer_ndim
(
ndim
,
size
)
ndim
,
size
=
_infer_ndim
(
ndim
,
size
)
print
"NDIM"
,
ndim
,
size
#
print "NDIM", ndim, size
op
=
RandomFunction
(
permutation_helper
,
op
=
RandomFunction
(
permutation_helper
,
tensor
.
TensorType
(
dtype
=
'int64'
,
broadcastable
=
(
False
,)
*
(
ndim
+
1
)),
tensor
.
TensorType
(
dtype
=
'int64'
,
broadcastable
=
(
False
,)
*
(
ndim
+
1
)),
ndim_added
=
1
)
ndim_added
=
1
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论