Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4c70aa6c
提交
4c70aa6c
authored
8月 06, 2012
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Don't auto matically unbroadcast in CudaNdarrayType.filter_variable
This is a revert from what was done in the trunk. This also give better error message.
上级
111c6604
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
46 行增加
和
17 行删除
+46
-17
test_var.py
theano/sandbox/cuda/tests/test_var.py
+37
-8
type.py
theano/sandbox/cuda/type.py
+9
-9
没有找到文件。
theano/sandbox/cuda/tests/test_var.py
浏览文件 @
4c70aa6c
...
@@ -5,12 +5,9 @@ from nose.plugins.skip import SkipTest
...
@@ -5,12 +5,9 @@ from nose.plugins.skip import SkipTest
import
theano
import
theano
from
theano
import
tensor
from
theano
import
tensor
from
theano
import
sparse
from
theano.tensor
import
TensorType
from
theano.tests
import
unittest_tools
as
utt
from
theano.sandbox.cuda.var
import
float32_shared_constructor
as
f32sc
from
theano.sandbox.cuda.var
import
float32_shared_constructor
as
f32sc
from
theano.sandbox.cuda
import
CudaNdarrayType
,
cuda_available
from
theano.sandbox.cuda
import
CudaNdarrayType
,
cuda_available
import
theano.sandbox.cuda
as
cuda
# Skip test if cuda_ndarray is not available.
# Skip test if cuda_ndarray is not available.
if
cuda_available
==
False
:
if
cuda_available
==
False
:
raise
SkipTest
(
'Optional package cuda disabled'
)
raise
SkipTest
(
'Optional package cuda disabled'
)
...
@@ -66,6 +63,10 @@ class T_updates(unittest.TestCase):
...
@@ -66,6 +63,10 @@ class T_updates(unittest.TestCase):
f
=
theano
.
function
([],
y
,
updates
=
{
x
:
x
+
1
})
f
=
theano
.
function
([],
y
,
updates
=
{
x
:
x
+
1
})
f
()
f
()
# Test that we can update with a CudaVariable
f
=
theano
.
function
([],
y
,
updates
=
{
x
:
cuda
.
gpu_from_host
(
x
+
1
)})
f
()
def
test_2
(
self
):
def
test_2
(
self
):
# This test case uses code mentionned in #698
# This test case uses code mentionned in #698
data
=
numpy
.
random
.
rand
(
10
,
10
)
.
astype
(
'float32'
)
data
=
numpy
.
random
.
rand
(
10
,
10
)
.
astype
(
'float32'
)
...
@@ -79,14 +80,42 @@ class T_updates(unittest.TestCase):
...
@@ -79,14 +80,42 @@ class T_updates(unittest.TestCase):
updates
=
output_updates
,
givens
=
output_givens
)
updates
=
output_updates
,
givens
=
output_givens
)
output_func
()
output_func
()
def
test_3
(
self
):
def
test_err_ndim
(
self
):
# Test that broadcastable dimensions don't screw up
# Test that we raise a good error message when we don't
# update expressions.
# same the same number of dimensions.
data
=
numpy
.
random
.
rand
(
10
,
10
)
.
astype
(
'float32'
)
output_var
=
f32sc
(
name
=
"output"
,
value
=
data
)
# the update_var has type matrix, and the update expression
# is a broadcasted scalar, and that should be allowed.
self
.
assertRaises
(
TypeError
,
theano
.
function
,
inputs
=
[],
outputs
=
[],
updates
=
{
output_var
:
output_var
.
sum
()})
def
test_err_broadcast
(
self
):
# Test that we raise a good error message when we don't
# same the same number of dimensions.
data
=
numpy
.
random
.
rand
(
10
,
10
)
.
astype
(
'float32'
)
data
=
numpy
.
random
.
rand
(
10
,
10
)
.
astype
(
'float32'
)
output_var
=
f32sc
(
name
=
"output"
,
value
=
data
)
output_var
=
f32sc
(
name
=
"output"
,
value
=
data
)
# the update_var has type matrix, and the update expression
# the update_var has type matrix, and the update expression
# is a broadcasted scalar, and that should be allowed.
# is a broadcasted scalar, and that should be allowed.
self
.
assertRaises
(
TypeError
,
theano
.
function
,
inputs
=
[],
outputs
=
[],
updates
=
{
output_var
:
output_var
.
sum
()
.
dimshuffle
(
'x'
,
'x'
)})
def
test_broadcast
(
self
):
# Test that we can rebroadcast
data
=
numpy
.
random
.
rand
(
10
,
10
)
.
astype
(
'float32'
)
output_var
=
f32sc
(
name
=
"output"
,
value
=
data
)
up
=
tensor
.
unbroadcast
(
output_var
.
sum
()
.
dimshuffle
(
'x'
,
'x'
),
0
,
1
)
output_func
=
theano
.
function
(
inputs
=
[],
outputs
=
[],
updates
=
{
output_var
:
up
})
output_func
()
up
=
tensor
.
patternbroadcast
(
output_var
.
sum
()
.
dimshuffle
(
'x'
,
'x'
),
output_var
.
type
.
broadcastable
)
output_func
=
theano
.
function
(
inputs
=
[],
outputs
=
[],
output_func
=
theano
.
function
(
inputs
=
[],
outputs
=
[],
updates
=
{
output_var
:
output_var
.
sum
()
.
dimshuffle
(
'x'
,
'x'
)
})
updates
=
{
output_var
:
up
})
output_func
()
output_func
()
theano/sandbox/cuda/type.py
浏览文件 @
4c70aa6c
...
@@ -130,20 +130,20 @@ class CudaNdarrayType(Type):
...
@@ -130,20 +130,20 @@ class CudaNdarrayType(Type):
if
other
.
type
==
self
:
if
other
.
type
==
self
:
return
other
return
other
if
not
isinstance
(
other
.
type
,
tensor
.
TensorType
):
if
not
isinstance
(
other
.
type
,
(
tensor
.
TensorType
,
CudaNdarrayType
)
):
raise
TypeError
(
'Incompatible type'
,
(
self
,
other
.
type
))
raise
TypeError
(
'Incompatible type'
,
(
self
,
other
.
type
))
if
(
other
.
type
.
dtype
!=
self
.
dtype
):
if
(
other
.
type
.
dtype
!=
self
.
dtype
):
raise
TypeError
(
'Incompatible dtype'
,
(
self
.
dtype
,
raise
TypeError
(
'Incompatible dtype'
,
(
self
.
dtype
,
other
.
type
.
dtype
))
other
.
type
.
dtype
))
if
numpy
.
any
([
bi
and
not
obi
if
other
.
type
.
ndim
!=
self
.
ndim
:
for
obi
,
bi
in
zip
(
raise
TypeError
(
'Incompatible number of dimensions.'
other
.
type
.
broadcastable
,
' Expected
%
d, got
%
d.'
%
(
self
.
ndim
,
other
.
ndim
))
self
.
broadcastable
)]):
raise
TypeError
(
'Incompatible broadcastable'
,
(
self
.
broadcastable
,
other
.
type
.
broadcastable
))
if
other
.
type
.
broadcastable
!=
self
.
broadcastable
:
if
other
.
type
.
broadcastable
!=
self
.
broadcastable
:
rebroadcast
=
tensor
.
Rebroadcast
(
*
enumerate
(
self
.
broadcastable
))
raise
TypeError
(
'Incompatible broadcastable dimensions.'
other
=
rebroadcast
(
other
)
' Expected
%
s, got
%
s.'
%
(
str
(
other
.
type
.
broadcastable
),
str
(
self
.
broadcastable
)))
return
theano
.
sandbox
.
cuda
.
basic_ops
.
GpuFromHost
()(
other
)
return
theano
.
sandbox
.
cuda
.
basic_ops
.
GpuFromHost
()(
other
)
@staticmethod
@staticmethod
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论