Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
419768e7
提交
419768e7
authored
10月 08, 2014
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow permutation to return just one permutation.
fix gh-2158
上级
9da67d20
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
27 行增加
和
2 行删除
+27
-2
raw_random.py
theano/tensor/raw_random.py
+13
-1
test_raw_random.py
theano/tensor/tests/test_raw_random.py
+14
-1
没有找到文件。
theano/tensor/raw_random.py
浏览文件 @
419768e7
...
@@ -183,7 +183,11 @@ class RandomFunction(gof.Op):
...
@@ -183,7 +183,11 @@ class RandomFunction(gof.Op):
draw.
draw.
"""
"""
shape
=
tensor
.
as_tensor_variable
(
shape
,
ndim
=
1
)
shape_
=
tensor
.
as_tensor_variable
(
shape
,
ndim
=
1
)
if
shape
==
():
shape
=
shape_
.
astype
(
'int32'
)
else
:
shape
=
shape_
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
):
...
@@ -700,6 +704,14 @@ def permutation(random_state, size=None, n=1, ndim=None, dtype='int64'):
...
@@ -700,6 +704,14 @@ def permutation(random_state, size=None, n=1, ndim=None, dtype='int64'):
:note:
:note:
Note that the output will then be of dimension ndim+1.
Note that the output will then be of dimension ndim+1.
"""
"""
if
size
is
None
or
size
==
():
if
not
(
ndim
is
None
or
ndim
==
1
):
raise
TypeError
(
"You asked for just one permutation but asked for more then 1 dimensions."
)
ndim
=
1
size
=
()
bcast
=
()
else
:
ndim
,
size
,
bcast
=
_infer_ndim_bcast
(
ndim
,
size
)
ndim
,
size
,
bcast
=
_infer_ndim_bcast
(
ndim
,
size
)
#print "NDIM", ndim, size
#print "NDIM", ndim, size
op
=
RandomFunction
(
permutation_helper
,
op
=
RandomFunction
(
permutation_helper
,
...
...
theano/tensor/tests/test_raw_random.py
浏览文件 @
419768e7
...
@@ -230,7 +230,7 @@ class T_random_function(utt.InferShapeTester):
...
@@ -230,7 +230,7 @@ class T_random_function(utt.InferShapeTester):
rng_R
=
random_state_type
()
rng_R
=
random_state_type
()
# No shape, no args -> TypeError
# No shape, no args -> TypeError
self
.
assertRaises
(
TypeError
,
p
ermutati
on
,
rng_R
,
size
=
None
,
ndim
=
2
)
self
.
assertRaises
(
TypeError
,
p
oiss
on
,
rng_R
,
size
=
None
,
ndim
=
2
)
def
test_random_function_ndim_added
(
self
):
def
test_random_function_ndim_added
(
self
):
"""Test that random_function helper function accepts ndim_added as
"""Test that random_function helper function accepts ndim_added as
...
@@ -561,6 +561,19 @@ class T_random_function(utt.InferShapeTester):
...
@@ -561,6 +561,19 @@ class T_random_function(utt.InferShapeTester):
self
.
assertTrue
(
numpy
.
all
(
val0
==
numpy_val0
))
self
.
assertTrue
(
numpy
.
all
(
val0
==
numpy_val0
))
self
.
assertTrue
(
numpy
.
all
(
val1
==
numpy_val1
))
self
.
assertTrue
(
numpy
.
all
(
val1
==
numpy_val1
))
# Test that we can generate a list: have size=None or ().
for
ndim
in
[
1
,
None
]:
post_r
,
out
=
permutation
(
rng_R
,
n
=
10
,
size
=
None
,
ndim
=
ndim
)
inp
=
compile
.
In
(
rng_R
,
value
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
()),
update
=
post_r
,
mutable
=
True
)
f
=
theano
.
function
([
inp
],
out
)
o
=
f
()
assert
o
.
shape
==
(
10
,)
assert
(
numpy
.
sort
(
o
)
==
numpy
.
arange
(
10
))
.
all
()
# Wrong number of dimensions asked
self
.
assertRaises
(
TypeError
,
permutation
,
rng_R
,
size
=
None
,
ndim
=
2
)
def
test_multinomial
(
self
):
def
test_multinomial
(
self
):
"""Test that raw_random.multinomial generates the same
"""Test that raw_random.multinomial generates the same
results as numpy."""
results as numpy."""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论