Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6b7ac951
提交
6b7ac951
authored
10月 04, 2014
作者:
Dustin Webb
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added code to calculate new shape when '-1' is provided as a value for a dimension.
上级
52ea2d0c
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
41 行增加
和
0 行删除
+41
-0
basic_ops.py
theano/sandbox/cuda/basic_ops.py
+24
-0
test_basic_ops.py
theano/sandbox/cuda/tests/test_basic_ops.py
+17
-0
没有找到文件。
theano/sandbox/cuda/basic_ops.py
浏览文件 @
6b7ac951
...
@@ -2313,6 +2313,30 @@ class GpuReshape(tensor.Reshape, GpuOp):
...
@@ -2313,6 +2313,30 @@ class GpuReshape(tensor.Reshape, GpuOp):
raise
ValueError
(
'shape argument to Reshape.perform'
raise
ValueError
(
'shape argument to Reshape.perform'
' has incorrect length
%
i'
' has incorrect length
%
i'
', should be
%
i'
%
(
len
(
shp
),
self
.
ndim
),
shp
)
', should be
%
i'
%
(
len
(
shp
),
self
.
ndim
),
shp
)
m1_idx
=
-
1
if
shp
.
prod
()
!=
x
.
size
:
# We need to do check here to raise the same error as NumPy.
# We should make pygpu do the same.
ss
=
1
nb_m1
=
0
for
idx
,
i
in
enumerate
(
shp
):
if
i
==
-
1
:
nb_m1
+=
1
m1_idx
=
idx
else
:
ss
*=
i
if
nb_m1
>
1
:
raise
ValueError
(
"Only one -1 is accepted in the new shape"
)
elif
nb_m1
==
1
:
if
(
x
.
size
%
ss
)
!=
0
:
raise
ValueError
(
"When using -1 in new shape, the computed new shape must be an multiple of the original shape."
)
else
:
raise
ValueError
(
"total size of new array must be unchanged"
)
if
m1_idx
!=
-
1
:
shp
[
m1_idx
]
=
x
.
size
/
(
-
1
*
shp
.
prod
())
out
[
0
]
=
x
.
reshape
(
tuple
(
shp
))
out
[
0
]
=
x
.
reshape
(
tuple
(
shp
))
...
...
theano/sandbox/cuda/tests/test_basic_ops.py
浏览文件 @
6b7ac951
...
@@ -10,6 +10,7 @@ import theano.tensor as T
...
@@ -10,6 +10,7 @@ import theano.tensor as T
# Skip test if cuda_ndarray is not available.
# Skip test if cuda_ndarray is not available.
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
from
nose.tools
import
assert_raises
import
theano.sandbox.cuda
as
cuda_ndarray
import
theano.sandbox.cuda
as
cuda_ndarray
if
cuda_ndarray
.
cuda_available
==
False
:
if
cuda_ndarray
.
cuda_available
==
False
:
raise
SkipTest
(
'Optional package cuda disabled'
)
raise
SkipTest
(
'Optional package cuda disabled'
)
...
@@ -336,6 +337,22 @@ def test_reshape():
...
@@ -336,6 +337,22 @@ def test_reshape():
return
T
.
Reshape
(
2
)(
v
,
theano
.
_asarray
([
2
,
3
],
dtype
=
'int32'
))
return
T
.
Reshape
(
2
)(
v
,
theano
.
_asarray
([
2
,
3
],
dtype
=
'int32'
))
utt
.
verify_grad
(
just_vals
,
[
a_val
])
utt
.
verify_grad
(
just_vals
,
[
a_val
])
# Test for appropriate handling of -1 indices
x
=
T
.
tensor3
(
'x'
)
f_reshp
=
theano
.
function
([
x
],
x
.
reshape
((
-
1
,
1
,
1
)),
mode
=
mode_with_gpu
)
y
=
f_reshp
(
numpy
.
array
([[[
1
,
0
],
[
0
,
1
]],
[[
0
,
1
],
[
1
,
0
]]],
dtype
=
'float32'
)
)
assert
y
.
shape
==
(
8
,
1
,
1
)
assert_raises
(
ValueError
,
f_reshp
=
theano
.
function
(
[
x
],
x
.
reshape
((
-
1
,
-
1
,
1
)),
mode
=
mode_with_gpu
)
)
def
test_elemwise_empty
():
def
test_elemwise_empty
():
#test with 0 element
#test with 0 element
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论