Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d1ac0913
提交
d1ac0913
authored
8月 06, 2012
作者:
lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #830 from nouiz/update_broadcast
Update broadcast
上级
a7f94e0d
de99fce8
隐藏空白字符变更
内嵌
并排
正在显示
12 个修改的文件
包含
90 行增加
和
35 行删除
+90
-35
MANIFEST.in
MANIFEST.in
+1
-2
install.txt
doc/install.txt
+1
-1
pfunc.py
theano/compile/pfunc.py
+19
-11
test_pfunc.py
theano/compile/tests/test_pfunc.py
+10
-0
check_whitespace.py
theano/misc/hooks/check_whitespace.py
+2
-1
nose_pr.py
theano/misc/nose_pr.py
+1
-1
test_var.py
theano/sandbox/cuda/tests/test_var.py
+37
-8
type.py
theano/sandbox/cuda/type.py
+9
-9
test_kron.py
theano/sandbox/linalg/tests/test_kron.py
+5
-2
test_opt.py
theano/sparse/tests/test_opt.py
+1
-0
test_utils.py
theano/sparse/tests/test_utils.py
+1
-0
basic.py
theano/tensor/basic.py
+3
-0
没有找到文件。
MANIFEST.in
浏览文件 @
d1ac0913
...
...
@@ -2,8 +2,7 @@ global-include *.txt
global-include *.cu
global-include *.cuh
global-include *.sh
recursive-include docs *.png *.gp
include distribute_setup.py
recursive-include docs
include bin/theano-cache
include bin/theano-nose
include bin/theano-test
doc/install.txt
浏览文件 @
d1ac0913
...
...
@@ -131,7 +131,7 @@ to your machine, you can install to an alternate prefix using
.. code-block:: bash
pip install Theano --install-option='--prefix=~/.local
pip install Theano --install-option='--prefix=~/.local
'
e.g. using ``--install-option='--prefix=~/.local'`` on Python 2.4 would
install Theano into ``.local/lib/python2.4/site-packages`` inside your home
...
...
theano/compile/pfunc.py
浏览文件 @
d1ac0913
...
...
@@ -198,17 +198,25 @@ def rebuild_collect_shared(outputs,
(
store_into
,
update_d
[
store_into
]))
# filter_variable ensure smooth conversion of cpu/gpu Types
update_val
=
store_into
.
type
.
filter_variable
(
update_val
)
if
update_val
.
type
!=
store_into
.
type
:
err_msg
=
(
'an update must have the same type as the '
'original shared variable(dest, dest.type, '
'update_val, update_val.type)'
)
err_arg
=
(
store_into
,
store_into
.
type
,
update_val
,
update_val
.
type
)
raise
TypeError
(
err_msg
,
err_arg
)
try
:
update_val
=
store_into
.
type
.
filter_variable
(
update_val
)
except
TypeError
,
e
:
err_msg
=
(
'An update must have the same type as the'
' original shared variable (shared_var=
%
s,'
' shared_var.type=
%
s,'
' update_val=
%
s, update_val.type=
%
s).'
%
(
store_into
,
store_into
.
type
,
update_val
,
update_val
.
type
))
err_sug
=
(
'If the difference is related to the broadcast pattern,'
' you can call the'
' tensor.unbroadcast(var, axis_to_unbroadcast[, ...])'
' function to remove broadcastable dimensions.'
)
raise
TypeError
(
err_msg
,
err_sug
)
assert
update_val
.
type
==
store_into
.
type
update_d
[
store_into
]
=
update_val
update_expr
.
append
((
store_into
,
update_val
))
...
...
theano/compile/tests/test_pfunc.py
浏览文件 @
d1ac0913
...
...
@@ -335,6 +335,16 @@ class Test_pfunc(unittest.TestCase):
inc_by_y
()
self
.
assertTrue
(
x
.
get_value
()
==
1
)
def
test_update_err_broadcast
(
self
):
# Test that broadcastable dimensions raise error
data
=
numpy
.
random
.
rand
(
10
,
10
)
.
astype
(
'float32'
)
output_var
=
shared
(
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
()
.
dimshuffle
(
'x'
,
'x'
)})
def
test_duplicate_updates
(
self
):
x
,
y
=
dmatrices
(
'x'
,
'y'
)
z
=
shared
(
numpy
.
ones
((
2
,
3
)))
...
...
theano/misc/hooks/check_whitespace.py
浏览文件 @
d1ac0913
...
...
@@ -88,8 +88,9 @@ def run_mercurial_command(hg_command):
hg_command_tuple
.
insert
(
0
,
hg_executable
)
try
:
hg_subprocess
=
Popen
(
hg_command_tuple
,
stdout
=
PIPE
,
stderr
=
PIPE
)
except
OSError
:
except
OSError
,
e
:
print
>>
sys
.
stderr
,
"Can't find the hg executable!"
print
e
sys
.
exit
(
1
)
hg_out
,
hg_err
=
hg_subprocess
.
communicate
()
...
...
theano/misc/nose_pr.py
浏览文件 @
d1ac0913
...
...
@@ -58,7 +58,7 @@ def setup():
try
:
os
.
mkdir
(
basedir
)
except
OSError
as
e
:
except
OSError
,
e
:
if
e
.
errno
!=
errno
.
EEXIST
:
raise
os
.
chdir
(
basedir
)
...
...
theano/sandbox/cuda/tests/test_var.py
浏览文件 @
d1ac0913
...
...
@@ -5,12 +5,9 @@ from nose.plugins.skip import SkipTest
import
theano
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
import
CudaNdarrayType
,
cuda_available
import
theano.sandbox.cuda
as
cuda
# Skip test if cuda_ndarray is not available.
if
cuda_available
==
False
:
raise
SkipTest
(
'Optional package cuda disabled'
)
...
...
@@ -66,6 +63,10 @@ class T_updates(unittest.TestCase):
f
=
theano
.
function
([],
y
,
updates
=
{
x
:
x
+
1
})
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
):
# This test case uses code mentionned in #698
data
=
numpy
.
random
.
rand
(
10
,
10
)
.
astype
(
'float32'
)
...
...
@@ -79,14 +80,42 @@ class T_updates(unittest.TestCase):
updates
=
output_updates
,
givens
=
output_givens
)
output_func
()
def
test_3
(
self
):
# Test that broadcastable dimensions don't screw up
# update expressions.
def
test_err_ndim
(
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'
)
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'
)
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
()
.
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
=
[],
updates
=
{
output_var
:
output_var
.
sum
()
.
dimshuffle
(
'x'
,
'x'
)
})
updates
=
{
output_var
:
up
})
output_func
()
theano/sandbox/cuda/type.py
浏览文件 @
d1ac0913
...
...
@@ -130,20 +130,20 @@ class CudaNdarrayType(Type):
if
other
.
type
==
self
:
return
other
if
not
isinstance
(
other
.
type
,
tensor
.
TensorType
):
if
not
isinstance
(
other
.
type
,
(
tensor
.
TensorType
,
CudaNdarrayType
)
):
raise
TypeError
(
'Incompatible type'
,
(
self
,
other
.
type
))
if
(
other
.
type
.
dtype
!=
self
.
dtype
):
raise
TypeError
(
'Incompatible dtype'
,
(
self
.
dtype
,
other
.
type
.
dtype
))
if
numpy
.
any
([
bi
and
not
obi
for
obi
,
bi
in
zip
(
other
.
type
.
broadcastable
,
self
.
broadcastable
)]):
raise
TypeError
(
'Incompatible broadcastable'
,
(
self
.
broadcastable
,
other
.
type
.
broadcastable
))
if
other
.
type
.
ndim
!=
self
.
ndim
:
raise
TypeError
(
'Incompatible number of dimensions.'
' Expected
%
d, got
%
d.'
%
(
self
.
ndim
,
other
.
ndim
))
if
other
.
type
.
broadcastable
!=
self
.
broadcastable
:
rebroadcast
=
tensor
.
Rebroadcast
(
*
enumerate
(
self
.
broadcastable
))
other
=
rebroadcast
(
other
)
raise
TypeError
(
'Incompatible broadcastable dimensions.'
' Expected
%
s, got
%
s.'
%
(
str
(
other
.
type
.
broadcastable
),
str
(
self
.
broadcastable
)))
return
theano
.
sandbox
.
cuda
.
basic_ops
.
GpuFromHost
()(
other
)
@staticmethod
...
...
theano/sandbox/linalg/tests/test_kron.py
浏览文件 @
d1ac0913
from
nose.plugins.skip
import
SkipTest
import
numpy
from
theano
import
tensor
,
function
from
theano.tests
import
unittest_tools
as
utt
from
theano.sandbox.linalg.kron
import
Kron
,
kron
...
...
@@ -9,6 +11,9 @@ try:
except
ImportError
:
imported_scipy
=
False
if
not
imported_scipy
:
raise
SkipTest
(
'Kron Op need the scipy package to be installed'
)
class
TestKron
(
utt
.
InferShapeTester
):
...
...
@@ -20,8 +25,6 @@ class TestKron(utt.InferShapeTester):
self
.
op
=
kron
def
test_perform
(
self
):
assert
imported_scipy
,
(
"Scipy not available. Scipy is needed for TestKron"
)
x
=
tensor
.
dmatrix
()
y
=
tensor
.
dmatrix
()
f
=
function
([
x
,
y
],
kron
(
x
,
y
))
...
...
theano/sparse/tests/test_opt.py
浏览文件 @
d1ac0913
from
nose.plugins.skip
import
SkipTest
import
numpy
try
:
import
scipy.sparse
as
sp
...
...
theano/sparse/tests/test_utils.py
浏览文件 @
d1ac0913
from
nose.plugins.skip
import
SkipTest
import
numpy
import
theano.sparse
...
...
theano/tensor/basic.py
浏览文件 @
d1ac0913
...
...
@@ -4655,6 +4655,9 @@ class Rebroadcast(Op):
def
__init__
(
self
,
*
axis
):
self
.
axis
=
dict
(
axis
)
for
axis
,
broad
in
self
.
axis
.
iteritems
():
assert
isinstance
(
axis
,
(
numpy
.
integer
,
int
)),
(
"Rebroadcast need integers axis. Got "
,
axis
)
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
and
self
.
axis
==
other
.
axis
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论