Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3720fc99
提交
3720fc99
authored
12月 14, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
following review fix some comments to respect pep8.
上级
f8e25def
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
33 行增加
和
33 行删除
+33
-33
test_basic.py
theano/tensor/tests/test_basic.py
+33
-33
没有找到文件。
theano/tensor/tests/test_basic.py
浏览文件 @
3720fc99
...
@@ -3027,7 +3027,7 @@ class test_tensordot(unittest.TestCase):
...
@@ -3027,7 +3027,7 @@ class test_tensordot(unittest.TestCase):
def
test0
(
self
):
def
test0
(
self
):
#
t
est vector-vector
#
T
est vector-vector
avec
=
vector
()
avec
=
vector
()
bvec
=
vector
()
bvec
=
vector
()
axes
=
((
0
,),(
0
,))
axes
=
((
0
,),(
0
,))
...
@@ -3039,7 +3039,7 @@ class test_tensordot(unittest.TestCase):
...
@@ -3039,7 +3039,7 @@ class test_tensordot(unittest.TestCase):
f1
(
aval
,
bval
))
f1
(
aval
,
bval
))
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
#
t
est matrix-vector
#
T
est matrix-vector
bmat
=
matrix
()
bmat
=
matrix
()
axes
=
((
0
,),(
1
,))
axes
=
((
0
,),(
1
,))
c
=
tensordot
(
avec
,
bmat
,
axes
)
c
=
tensordot
(
avec
,
bmat
,
axes
)
...
@@ -3050,7 +3050,7 @@ class test_tensordot(unittest.TestCase):
...
@@ -3050,7 +3050,7 @@ class test_tensordot(unittest.TestCase):
f2
(
aval
,
bval
)))
f2
(
aval
,
bval
)))
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
#
t
est matrix-matrix
#
T
est matrix-matrix
amat
=
matrix
()
amat
=
matrix
()
axes
=
((
1
,),(
0
,))
axes
=
((
1
,),(
0
,))
c
=
tensordot
(
amat
,
bmat
,
axes
)
c
=
tensordot
(
amat
,
bmat
,
axes
)
...
@@ -3061,7 +3061,7 @@ class test_tensordot(unittest.TestCase):
...
@@ -3061,7 +3061,7 @@ class test_tensordot(unittest.TestCase):
f3
(
aval
,
bval
)))
f3
(
aval
,
bval
)))
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
#
t
est ndarray-matrix, sum over one dim of matrix
#
T
est ndarray-matrix, sum over one dim of matrix
atens
=
tensor4
()
atens
=
tensor4
()
axes
=
((
2
,),(
1
,))
axes
=
((
2
,),(
1
,))
c
=
tensordot
(
atens
,
bmat
,
axes
)
c
=
tensordot
(
atens
,
bmat
,
axes
)
...
@@ -3072,7 +3072,7 @@ class test_tensordot(unittest.TestCase):
...
@@ -3072,7 +3072,7 @@ class test_tensordot(unittest.TestCase):
f4
(
aval
,
bval
)))
f4
(
aval
,
bval
)))
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
#
t
est ndarray-ndarray
#
T
est ndarray-ndarray
atens
=
tensor4
()
atens
=
tensor4
()
btens
=
tensor3
()
btens
=
tensor3
()
axes
=
((
1
,
3
),(
0
,
2
))
axes
=
((
1
,
3
),(
0
,
2
))
...
@@ -3096,35 +3096,35 @@ class test_tensordot(unittest.TestCase):
...
@@ -3096,35 +3096,35 @@ class test_tensordot(unittest.TestCase):
bmat
=
matrix
()
bmat
=
matrix
()
bvec
=
vector
()
bvec
=
vector
()
#
t
est invalid length for axes
#
T
est invalid length for axes
try
:
try
:
c
=
tensordot
(
amat
,
bmat
,
(
0
,
1
,
2
))
c
=
tensordot
(
amat
,
bmat
,
(
0
,
1
,
2
))
assert
False
assert
False
except
ValueError
:
except
ValueError
:
pass
pass
#
t
est axes of uneven length
#
T
est axes of uneven length
try
:
try
:
c
=
tensordot
(
amat
,
bmat
,
((
0
,
1
),(
0
)))
c
=
tensordot
(
amat
,
bmat
,
((
0
,
1
),(
0
)))
assert
False
assert
False
except
ValueError
:
except
ValueError
:
pass
pass
#
t
est invalid len(axes) given inputs are matrices
#
T
est invalid len(axes) given inputs are matrices
try
:
try
:
c
=
tensordot
(
amat
,
bmat
,
((
0
,
1
,
2
),(
0
,
1
,
2
)))
c
=
tensordot
(
amat
,
bmat
,
((
0
,
1
,
2
),(
0
,
1
,
2
)))
assert
False
assert
False
except
ValueError
:
except
ValueError
:
pass
pass
#
t
est invalid axes[1] given that y is a vector
#
T
est invalid axes[1] given that y is a vector
try
:
try
:
c
=
tensordot
(
amat
,
bvec
,
(
0
,
1
))
c
=
tensordot
(
amat
,
bvec
,
(
0
,
1
))
assert
False
assert
False
except
ValueError
:
except
ValueError
:
pass
pass
#
t
est invalid scalar axes given inputs are matrices
#
T
est invalid scalar axes given inputs are matrices
try
:
try
:
c
=
tensordot
(
amat
,
bvec
,
2
)
c
=
tensordot
(
amat
,
bvec
,
2
)
assert
False
assert
False
...
@@ -3133,7 +3133,7 @@ class test_tensordot(unittest.TestCase):
...
@@ -3133,7 +3133,7 @@ class test_tensordot(unittest.TestCase):
def
test_weird_valid_axes
(
self
):
def
test_weird_valid_axes
(
self
):
#
t
est matrix-matrix
#
T
est matrix-matrix
amat
=
matrix
()
amat
=
matrix
()
bmat
=
matrix
()
bmat
=
matrix
()
for
axes
in
0
,
(
1
,
0
),
[
1
,
0
],
(
1
,(
0
,)),
((
1
,),
0
),
([
1
],[
0
]):
for
axes
in
0
,
(
1
,
0
),
[
1
,
0
],
(
1
,(
0
,)),
((
1
,),
0
),
([
1
],[
0
]):
...
@@ -3146,9 +3146,9 @@ class test_tensordot(unittest.TestCase):
...
@@ -3146,9 +3146,9 @@ class test_tensordot(unittest.TestCase):
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
def
test_scalar_axes
(
self
):
def
test_scalar_axes
(
self
):
#
t
est matrix-matrix
#
T
est matrix-matrix
amat
=
fmatrix
()
amat
=
fmatrix
()
bmat
=
dmatrix
()
#
w
e let at float64 to test mix of float32 and float64.
bmat
=
dmatrix
()
#
W
e let at float64 to test mix of float32 and float64.
axes
=
1
axes
=
1
aval
=
self
.
rand
(
4
,
5
)
.
astype
(
'float32'
)
aval
=
self
.
rand
(
4
,
5
)
.
astype
(
'float32'
)
bval
=
numpy
.
random
.
rand
(
5
,
3
)
bval
=
numpy
.
random
.
rand
(
5
,
3
)
...
@@ -3158,7 +3158,7 @@ class test_tensordot(unittest.TestCase):
...
@@ -3158,7 +3158,7 @@ class test_tensordot(unittest.TestCase):
f3
(
aval
,
bval
)))
f3
(
aval
,
bval
)))
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
#
t
est tensor-tensor
#
T
est tensor-tensor
amat
=
tensor3
()
amat
=
tensor3
()
bmat
=
tensor3
()
bmat
=
tensor3
()
axes
=
2
axes
=
2
...
@@ -3171,7 +3171,7 @@ class test_tensordot(unittest.TestCase):
...
@@ -3171,7 +3171,7 @@ class test_tensordot(unittest.TestCase):
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
def
test_scalar0
(
self
):
def
test_scalar0
(
self
):
#
t
est tensor-tensor
#
T
est tensor-tensor
amat
=
matrix
()
amat
=
matrix
()
bmat
=
matrix
()
bmat
=
matrix
()
axes
=
0
axes
=
0
...
@@ -3184,7 +3184,7 @@ class test_tensordot(unittest.TestCase):
...
@@ -3184,7 +3184,7 @@ class test_tensordot(unittest.TestCase):
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
utt
.
verify_grad
(
TensorDot
(
axes
),
[
aval
,
bval
])
def
test_tensordot_grad
(
self
):
def
test_tensordot_grad
(
self
):
#We test it manually as we recreate the op in the make_node
#
We test it manually as we recreate the op in the make_node
amat
=
matrix
()
amat
=
matrix
()
bmat
=
matrix
()
bmat
=
matrix
()
...
@@ -3278,8 +3278,8 @@ def test_default_state():
...
@@ -3278,8 +3278,8 @@ def test_default_state():
def
test_autocast
():
def
test_autocast
():
orig_autocast
=
autocast_float
.
dtypes
orig_autocast
=
autocast_float
.
dtypes
#
t
est that autocast_float_as sets the autocast dtype correctly
#
T
est that autocast_float_as sets the autocast dtype correctly
try
:
#ghetto 2.4 version of with
try
:
#
ghetto 2.4 version of with
ac
=
autocast_float_as
(
'float32'
)
ac
=
autocast_float_as
(
'float32'
)
ac
.
__enter__
()
ac
.
__enter__
()
assert
autocast_float
.
dtypes
==
(
'float32'
,)
assert
autocast_float
.
dtypes
==
(
'float32'
,)
...
@@ -3293,12 +3293,12 @@ def test_autocast():
...
@@ -3293,12 +3293,12 @@ def test_autocast():
finally
:
finally
:
ac
.
__exit__
()
ac
.
__exit__
()
assert
autocast_float
.
dtypes
==
orig_autocast
assert
autocast_float
.
dtypes
==
orig_autocast
#
t
est that we can set it back to something, and nest it
#
T
est that we can set it back to something, and nest it
try
:
#ghetto 2.4 version of with
try
:
#
ghetto 2.4 version of with
ac
=
autocast_float_as
(
'float32'
)
ac
=
autocast_float_as
(
'float32'
)
ac
.
__enter__
()
ac
.
__enter__
()
assert
autocast_float
.
dtypes
==
(
'float32'
,)
assert
autocast_float
.
dtypes
==
(
'float32'
,)
try
:
#ghetto 2.4 version of with
try
:
#
ghetto 2.4 version of with
ac2
=
autocast_float_as
(
'float64'
)
ac2
=
autocast_float_as
(
'float64'
)
ac2
.
__enter__
()
ac2
.
__enter__
()
assert
autocast_float
.
dtypes
==
(
'float64'
,)
assert
autocast_float
.
dtypes
==
(
'float64'
,)
...
@@ -3309,8 +3309,8 @@ def test_autocast():
...
@@ -3309,8 +3309,8 @@ def test_autocast():
ac
.
__exit__
()
ac
.
__exit__
()
assert
autocast_float
.
dtypes
==
orig_autocast
assert
autocast_float
.
dtypes
==
orig_autocast
#
t
est that the autocasting dtype is used correctly in expression-building
#
T
est that the autocasting dtype is used correctly in expression-building
try
:
#ghetto 2.4 version of with
try
:
#
ghetto 2.4 version of with
ac
=
autocast_float_as
(
'float32'
)
ac
=
autocast_float_as
(
'float32'
)
ac
.
__enter__
()
ac
.
__enter__
()
assert
(
dvector
()
+
1.1
)
.
dtype
==
'float64'
assert
(
dvector
()
+
1.1
)
.
dtype
==
'float64'
...
@@ -3323,8 +3323,8 @@ def test_autocast():
...
@@ -3323,8 +3323,8 @@ def test_autocast():
finally
:
finally
:
ac
.
__exit__
()
ac
.
__exit__
()
#
t
est that the autocasting dtype is used correctly in expression-building
#
T
est that the autocasting dtype is used correctly in expression-building
try
:
#ghetto 2.4 version of with
try
:
#
ghetto 2.4 version of with
ac
=
autocast_float_as
(
'float64'
)
ac
=
autocast_float_as
(
'float64'
)
ac
.
__enter__
()
ac
.
__enter__
()
assert
(
dvector
()
+
1.1
)
.
dtype
==
'float64'
assert
(
dvector
()
+
1.1
)
.
dtype
==
'float64'
...
@@ -3338,8 +3338,8 @@ def test_autocast():
...
@@ -3338,8 +3338,8 @@ def test_autocast():
finally
:
finally
:
ac
.
__exit__
()
ac
.
__exit__
()
#
t
est that the autocasting dtype is used correctly in expression-building
#
T
est that the autocasting dtype is used correctly in expression-building
try
:
#ghetto 2.4 version of with
try
:
#
ghetto 2.4 version of with
ac
=
autocast_float_as
(
'float32'
,
'float64'
)
ac
=
autocast_float_as
(
'float32'
,
'float64'
)
ac
.
__enter__
()
ac
.
__enter__
()
assert
(
dvector
()
+
1.1
)
.
dtype
==
'float64'
assert
(
dvector
()
+
1.1
)
.
dtype
==
'float64'
...
@@ -3358,7 +3358,7 @@ def test_autocast():
...
@@ -3358,7 +3358,7 @@ def test_autocast():
assert
(
ivector
()
+
numpy
.
int8
(
1
))
.
dtype
==
'int32'
assert
(
ivector
()
+
numpy
.
int8
(
1
))
.
dtype
==
'int32'
assert
(
wvector
()
+
numpy
.
int8
(
1
))
.
dtype
==
'int16'
assert
(
wvector
()
+
numpy
.
int8
(
1
))
.
dtype
==
'int16'
assert
(
bvector
()
+
numpy
.
int8
(
1
))
.
dtype
==
'int8'
assert
(
bvector
()
+
numpy
.
int8
(
1
))
.
dtype
==
'int8'
try
:
#ghetto 2.4 version of with
try
:
#
ghetto 2.4 version of with
ac2
=
autocast_float_as
(
'float64'
)
ac2
=
autocast_float_as
(
'float64'
)
ac2
.
__enter__
()
ac2
.
__enter__
()
assert
(
fvector
()
+
1.0
)
.
dtype
==
'float64'
assert
(
fvector
()
+
1.0
)
.
dtype
==
'float64'
...
@@ -3406,11 +3406,11 @@ class test_broadcast(unittest.TestCase):
...
@@ -3406,11 +3406,11 @@ class test_broadcast(unittest.TestCase):
assert
unbroadcast
(
addbroadcast
(
x
,
1
),
1
)
is
x
assert
unbroadcast
(
addbroadcast
(
x
,
1
),
1
)
is
x
assert
addbroadcast
(
unbroadcast
(
x
,
1
),
1
)
is
not
x
assert
addbroadcast
(
unbroadcast
(
x
,
1
),
1
)
is
not
x
#
t
he first broadcast is remove the broadcast, so the second
#
T
he first broadcast is remove the broadcast, so the second
#should not make one
#
should not make one
assert
unbroadcast
(
unbroadcast
(
x
,
0
),
0
)
.
owner
.
inputs
[
0
]
is
x
assert
unbroadcast
(
unbroadcast
(
x
,
0
),
0
)
.
owner
.
inputs
[
0
]
is
x
#
t
est that consecutive Rebroadcast op are fused
#
T
est that consecutive Rebroadcast op are fused
x
=
TensorType
(
dtype
=
'float64'
,
broadcastable
=
(
True
,
True
))()
x
=
TensorType
(
dtype
=
'float64'
,
broadcastable
=
(
True
,
True
))()
assert
unbroadcast
(
unbroadcast
(
x
,
1
),
0
)
.
owner
.
inputs
[
0
]
is
x
assert
unbroadcast
(
unbroadcast
(
x
,
1
),
0
)
.
owner
.
inputs
[
0
]
is
x
assert
addbroadcast
(
unbroadcast
(
x
,
1
),
0
)
.
owner
.
inputs
[
0
]
is
x
assert
addbroadcast
(
unbroadcast
(
x
,
1
),
0
)
.
owner
.
inputs
[
0
]
is
x
...
@@ -3462,8 +3462,8 @@ def test_unalign():
...
@@ -3462,8 +3462,8 @@ def test_unalign():
av
,
bv
=
tensor
.
vectors
(
'ab'
)
av
,
bv
=
tensor
.
vectors
(
'ab'
)
f
=
theano
.
function
([
av
,
bv
],
2
*
av
+
3
*
bv
)
f
=
theano
.
function
([
av
,
bv
],
2
*
av
+
3
*
bv
)
f
.
maker
.
env
.
toposort
()
f
.
maker
.
env
.
toposort
()
#FAST_COMPILE use the python code that support unaligned data
#
FAST_COMPILE use the python code that support unaligned data
#The DebugMode make a copy of the inputs, so they will be aligned.
#
The DebugMode make a copy of the inputs, so they will be aligned.
should_raise
=
theano
.
config
.
mode
not
in
[
"FAST_COMPILE"
,
"DebugMode"
,
"DEBUG_MODE"
]
should_raise
=
theano
.
config
.
mode
not
in
[
"FAST_COMPILE"
,
"DebugMode"
,
"DEBUG_MODE"
]
try
:
try
:
out_theano
=
f
(
a
,
b
)
out_theano
=
f
(
a
,
b
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论