Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f48aba1d
提交
f48aba1d
authored
3月 19, 2008
作者:
bergstrj@iro.umontreal.ca
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added tests for merge
上级
e20cf954
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
149 行增加
和
167 行删除
+149
-167
_test_base_tensor.py
_test_base_tensor.py
+4
-0
_test_ops.py
_test_ops.py
+0
-166
_test_tensor.py
_test_tensor.py
+145
-1
没有找到文件。
_test_base_tensor.py
浏览文件 @
f48aba1d
...
@@ -2,6 +2,8 @@ from base_tensor import *
...
@@ -2,6 +2,8 @@ from base_tensor import *
import
unittest
import
unittest
from
copy
import
copy
from
copy
import
copy
from
compile
import
Function
import
gof
def
_tensor
(
data
,
broadcastable
=
None
,
role
=
None
,
name
=
None
):
def
_tensor
(
data
,
broadcastable
=
None
,
role
=
None
,
name
=
None
):
"""Return a BaseTensor containing given data"""
"""Return a BaseTensor containing given data"""
...
@@ -50,6 +52,8 @@ class T_tensor(unittest.TestCase):
...
@@ -50,6 +52,8 @@ class T_tensor(unittest.TestCase):
self
.
failUnless
(
t
.
dtype
==
'complex64'
)
self
.
failUnless
(
t
.
dtype
==
'complex64'
)
self
.
failUnless
(
t
.
broadcastable
==
(
0
,
0
))
self
.
failUnless
(
t
.
broadcastable
==
(
0
,
0
))
self
.
failUnless
(
isinstance
(
t
.
data
,
numpy
.
ndarray
))
self
.
failUnless
(
isinstance
(
t
.
data
,
numpy
.
ndarray
))
f
=
Function
([
t
],
[
t
],
linker_cls
=
gof
.
CLinker
)
self
.
failUnless
(
numpy
.
all
(
t
.
data
==
f
(
t
.
data
)))
def
test_data_normal
(
self
):
#test that assigning to .data works when it should
def
test_data_normal
(
self
):
#test that assigning to .data works when it should
t
=
_tensor
(
numpy
.
ones
((
5
,
1
),
dtype
=
'complex64'
),
broadcastable
=
0
)
t
=
_tensor
(
numpy
.
ones
((
5
,
1
),
dtype
=
'complex64'
),
broadcastable
=
0
)
o27
=
numpy
.
ones
((
2
,
7
))
o27
=
numpy
.
ones
((
2
,
7
))
...
...
_test_ops.py
浏览文件 @
f48aba1d
...
@@ -217,172 +217,6 @@ class gemm(omega_op):
...
@@ -217,172 +217,6 @@ class gemm(omega_op):
'(_b->descr->type_num == PyArray_FLOAT) ? (REAL)(((float*)_b->data)[0]) : (REAL)(((double*)_b->data)[0])'
)
'(_b->descr->type_num == PyArray_FLOAT) ? (REAL)(((float*)_b->data)[0]) : (REAL)(((double*)_b->data)[0])'
)
class
_testCase_transpose
(
unittest
.
TestCase
):
def
setUp
(
self
):
build_eval_mode
()
def
tearDown
(
self
):
pop_mode
()
def
test_1d_alias
(
self
):
a
=
numpy
.
ones
(
10
)
ta
=
transpose
(
a
)
self
.
failUnless
(
ta
.
data
.
shape
==
a
.
shape
)
self
.
failUnless
(
numpy
.
all
(
ta
.
data
==
a
))
a
[
3
]
*=
-
1.0
self
.
failUnless
(
numpy
.
all
(
ta
.
data
==
a
))
def
test_1d_copy
(
self
):
a
=
numpy
.
ones
(
10
)
ta
=
transpose_copy
(
a
)
self
.
failUnless
(
ta
.
data
.
shape
==
a
.
shape
)
self
.
failUnless
(
numpy
.
all
(
ta
.
data
==
a
))
a
[
3
]
*=
-
1.0
self
.
failIf
(
numpy
.
all
(
ta
.
data
==
a
))
def
test_2d_alias
(
self
):
a
=
numpy
.
ones
((
10
,
3
))
ta
=
transpose
(
a
)
self
.
failUnless
(
ta
.
data
.
shape
==
(
3
,
10
))
def
test_3d_alias
(
self
):
a
=
numpy
.
ones
((
10
,
3
,
5
))
ta
=
transpose
(
a
)
self
.
failUnless
(
ta
.
data
.
shape
==
(
5
,
3
,
10
))
a
[
9
,
0
,
0
]
=
5.0
self
.
failUnless
(
ta
.
data
[
0
,
0
,
9
]
==
5.0
)
def
test_3d_copy
(
self
):
a
=
numpy
.
ones
((
10
,
3
,
5
))
ta
=
transpose_copy
(
a
)
self
.
failUnless
(
ta
.
data
.
shape
==
(
5
,
3
,
10
))
a
[
9
,
0
,
0
]
=
5.0
self
.
failUnless
(
ta
.
data
[
0
,
0
,
9
]
==
1.0
)
class
_testCase_power
(
unittest
.
TestCase
):
def
setUp
(
self
):
build_eval_mode
()
numpy
.
random
.
seed
(
44
)
def
tearDown
(
self
):
pop_mode
()
def
test1
(
self
):
r
=
numpy
.
random
.
rand
(
50
)
exp_r
=
exp
(
r
)
self
.
failUnless
(
exp_r
.
__array__
()
.
__class__
is
numpy
.
ndarray
)
def
test_0
(
self
):
r
=
numpy
.
random
.
rand
(
50
)
exp_r
=
exp
(
r
)
n_exp_r
=
numpy
.
exp
(
r
)
self
.
failUnless
(
_approx_eq
(
exp_r
,
n_exp_r
),
(
exp_r
,
exp_r
.
data
,
n_exp_r
,
numpy
.
max
(
numpy
.
abs
(
n_exp_r
.
__sub__
(
exp_r
.
__array__
())))))
log_exp_r
=
log
(
exp_r
)
self
.
failUnless
(
_approx_eq
(
log_exp_r
,
r
),
log_exp_r
)
def
test_1
(
self
):
r
=
numpy
.
random
.
rand
(
50
)
r2
=
pow
(
r
,
2
)
self
.
failUnless
(
_approx_eq
(
r2
,
r
*
r
))
class
_testCase_slicing
(
unittest
.
TestCase
):
def
setUp
(
self
):
build_eval_mode
()
def
tearDown
(
self
):
pop_mode
()
def
test_getitem0
(
self
):
a
=
numpy
.
ones
((
4
,
4
))
wa1
=
wrap
(
a
)[:,
1
]
try
:
err
=
wa1
+
a
except
ValueError
,
e
:
self
.
failUnless
(
str
(
e
)
==
\
'The dimensions of the inputs do not match.'
,
'Wrong ValueError'
)
return
self
.
fail
(
'add should not have succeeded'
)
def
test_getitem1
(
self
):
a
=
numpy
.
ones
((
4
,
4
))
wa1
=
wrap
(
a
)[
1
]
self
.
failUnless
(
wa1
.
data
.
shape
==
(
4
,))
def
test_getslice_0d_all
(
self
):
"""Test getslice does not work on 0d array """
a
=
numpy
.
ones
(())
try
:
wa1
=
wrap
(
a
)[:]
except
IndexError
,
e
:
self
.
failUnless
(
str
(
e
)
==
"0-d arrays can't be indexed."
)
return
self
.
fail
()
def
test_getslice_1d_all
(
self
):
"""Test getslice on 1d array"""
a
=
numpy
.
ones
(
4
)
wa1
=
wrap
(
a
)[:]
self
.
failUnless
(
wa1
.
data
.
shape
==
(
4
,),
'wrong shape'
)
self
.
failUnless
(
numpy
.
all
(
wa1
.
data
==
a
),
'unequal value'
)
a
[
1
]
=
3.4
self
.
failUnless
(
wa1
.
data
[
1
]
==
3.4
,
'not a view'
)
try
:
wa1
[
2
]
=
2.5
except
TypeError
,
e
:
self
.
failUnless
(
"object does not support item assignment"
in
str
(
e
))
return
self
.
fail
()
def
test_getslice_3d_all
(
self
):
"""Test getslice on 3d array"""
a
=
numpy
.
ones
((
4
,
5
,
6
))
wa1
=
wrap
(
a
)[:]
self
.
failUnless
(
wa1
.
data
.
shape
==
(
4
,
5
,
6
),
'wrong shape'
)
self
.
failUnless
(
numpy
.
all
(
wa1
.
data
==
a
),
'unequal value'
)
a
[
1
,
1
,
1
]
=
3.4
self
.
failUnless
(
wa1
.
data
[
1
,
1
,
1
]
==
3.4
,
'not a view'
)
def
test_getslice_1d_some
(
self
):
"""Test getslice on 1d array"""
a
=
numpy
.
ones
(
5
)
wa1
=
wrap
(
a
)[
1
:
3
]
a
[
2
]
=
5.0
a
[
3
]
=
2.5
self
.
failUnless
(
wa1
.
data
.
shape
==
(
2
,))
self
.
failUnless
(
a
[
1
]
==
wa1
.
data
[
0
])
self
.
failUnless
(
a
[
2
]
==
wa1
.
data
[
1
])
def
test_getslice_1d_step
(
self
):
"""Test getslice on 1d array"""
a
=
numpy
.
ones
(
8
)
wa1
=
wrap
(
a
)[
0
:
8
:
2
]
for
i
in
xrange
(
8
):
a
[
i
]
=
i
self
.
failUnless
(
wa1
.
shape
==
(
4
,))
for
i
in
xrange
(
4
):
self
.
failUnless
(
a
[
i
*
2
]
==
wa1
.
data
[
i
])
def
test_getslice_3d_float
(
self
):
"""Test getslice on 3d array"""
a
=
numpy
.
asarray
(
range
(
4
*
5
*
6
))
a
.
resize
((
4
,
5
,
6
))
wa1
=
wrap
(
a
)[
1
:
3
]
self
.
failUnless
(
wa1
.
shape
==
(
2
,
5
,
6
))
self
.
failUnless
(
numpy
.
all
(
a
[
1
:
3
]
==
wa1
.
data
))
a
[
1
]
*=
-
1.0
self
.
failUnless
(
numpy
.
all
(
a
[
1
:
3
]
==
wa1
.
data
))
def
test_getslice_3d_one
(
self
):
"""Test getslice on 3d array"""
a
=
numpy
.
asarray
(
range
(
4
*
5
*
6
))
a
.
resize
((
4
,
5
,
6
))
wa
=
wrap
(
a
)
wa_123
=
wa
[
1
,
2
,
3
]
self
.
failUnless
(
wa_123
.
shape
==
(),
wa_123
.
shape
)
...
...
_test_tensor.py
浏览文件 @
f48aba1d
...
@@ -3,7 +3,7 @@ import tensor # for hidden symbols
...
@@ -3,7 +3,7 @@ import tensor # for hidden symbols
import
unittest
import
unittest
from
copy
import
copy
from
copy
import
copy
from
compile
import
Function
from
compile
import
Function
,
eval_outputs
import
gradient
import
gradient
import
gof
,
gof
.
graph
import
gof
,
gof
.
graph
...
@@ -68,6 +68,150 @@ def check_eq2_c(self, inputs, output, args_in, arg_out):
...
@@ -68,6 +68,150 @@ def check_eq2_c(self, inputs, output, args_in, arg_out):
self
.
failUnless
(
numpy
.
all
(
val
==
arg_out
),
(
val
,
arg_out
))
self
.
failUnless
(
numpy
.
all
(
val
==
arg_out
),
(
val
,
arg_out
))
class
T_transpose
(
unittest
.
TestCase
):
def
test0
(
self
):
n
=
tinit
(
numpy
.
ones
(()))
t
=
transpose
(
n
)
self
.
failUnless
(
t
.
owner
.
__class__
is
Transpose
)
f
=
Function
([
n
],
[
t
])
tval
=
f
(
n
.
data
)
self
.
failUnless
(
tval
.
shape
==
n
.
data
.
shape
)
#test aliasing
tval
+=
55.0
self
.
failUnless
(
n
.
data
==
56.0
)
def
test1
(
self
):
n
=
tinit
(
numpy
.
ones
(
5
))
t
=
transpose
(
n
)
self
.
failUnless
(
t
.
owner
.
__class__
is
Transpose
)
f
=
Function
([
n
],
[
t
])
tval
=
f
(
n
.
data
)
self
.
failUnless
(
tval
.
shape
==
n
.
data
.
shape
)
#test aliasing
tval
+=
55.0
self
.
failUnless
(
n
.
data
[
0
]
==
56.0
)
def
test2
(
self
):
n
=
tinit
(
numpy
.
ones
((
5
,
3
)))
t
=
transpose
(
n
)
self
.
failUnless
(
t
.
owner
.
__class__
is
Transpose
)
f
=
Function
([
n
],
[
t
])
tval
=
f
(
n
.
data
)
self
.
failUnless
(
tval
.
shape
==
(
3
,
5
))
#test aliasing
tval
+=
55.0
self
.
failUnless
(
n
.
data
[
0
,
0
]
==
56.0
)
def
test3
(
self
):
n
=
tinit
(
numpy
.
ones
((
5
,
3
,
2
)))
t
=
transpose
(
n
)
self
.
failUnless
(
t
.
owner
.
__class__
is
Transpose
)
f
=
Function
([
n
],
[
t
])
tval
=
f
(
n
.
data
)
self
.
failUnless
(
tval
.
shape
==
(
2
,
3
,
5
))
#test aliasing
tval
+=
55.0
self
.
failUnless
(
n
.
data
[
0
,
0
,
0
]
==
56.0
)
class
T_subtensor
(
unittest
.
TestCase
):
def
test0_err_invalid
(
self
):
#it is impossible to retrieve a view of a 0-d tensor
n
=
tinit
(
numpy
.
ones
(()))
try
:
t
=
n
[
0
]
self
.
fail
()
except
ValueError
,
e
:
self
.
failUnless
(
e
[
0
]
is
Subtensor
.
e_invalid
)
def
test1_err_bounds
(
self
):
n
=
tinit
(
numpy
.
ones
(
3
))
t
=
n
[
7
]
self
.
failUnless
(
t
.
owner
.
__class__
is
Subtensor
)
try
:
tval
=
eval_outputs
([
t
])
except
Exception
,
e
:
if
e
[
0
]
!=
'index out of bounds'
:
raise
def
test1_ok_range_finite
(
self
):
n
=
tinit
(
numpy
.
ones
(
3
)
*
5
)
t
=
n
[
0
:
2
]
self
.
failUnless
(
t
.
owner
.
__class__
is
Subtensor
)
tval
=
eval_outputs
([
t
])
self
.
failUnless
(
tval
.
shape
==
(
2
,))
self
.
failUnless
(
tval
[
1
]
==
5.0
)
def
test2_ok_range_finite
(
self
):
n
=
tinit
(
numpy
.
ones
((
3
,
4
))
*
5
)
t
=
n
[
0
:
2
,
3
]
self
.
failUnless
(
t
.
owner
.
__class__
is
Subtensor
)
tval
=
eval_outputs
([
t
])
self
.
failUnless
(
tval
.
shape
==
(
2
,))
self
.
failUnless
(
tval
[
1
]
==
5.0
)
if
0
:
def
test1_err_invalid
(
self
):
n
=
tinit
(
numpy
.
ones
(
1
))
try
:
t
=
n
[
0
,
0
]
self
.
fail
()
except
ValueError
,
e
:
self
.
failUnless
(
e
[
0
]
is
Subtensor
.
e_invalid
)
def
test1_ok_elem
(
self
):
n
=
tinit
(
numpy
.
ones
(
1
)
*
5
)
t
=
n
[
0
]
self
.
failUnless
(
t
.
owner
.
__class__
is
Subtensor
)
tval
=
eval_outputs
([
t
])
self
.
failUnless
(
tval
.
shape
==
(
1
,))
self
.
failUnless
(
tval
[
0
]
==
5.0
)
def
test1_ok_range_infinite
(
self
):
n
=
tinit
(
numpy
.
ones
(
3
)
*
5
)
t
=
n
[
1
:]
self
.
failUnless
(
t
.
owner
.
__class__
is
Subtensor
)
tval
=
eval_outputs
([
t
])
self
.
failUnless
(
tval
.
shape
==
(
2
,))
self
.
failUnless
(
tval
[
1
]
==
5.0
)
def
test1_ok_strided
(
self
):
n
=
tinit
(
numpy
.
ones
(
5
)
*
5
)
t
=
n
[
1
::
2
]
self
.
failUnless
(
t
.
owner
.
__class__
is
Subtensor
)
tval
=
eval_outputs
([
t
])
self
.
failUnless
(
tval
.
shape
==
(
3
,))
self
.
failUnless
(
tval
[
1
]
==
5.0
)
tval
=
eval_outputs
([
n
[
1
:
-
1
:
2
]])
self
.
failUnless
(
tval
.
shape
==
(
3
,))
self
.
failUnless
(
tval
[
1
]
==
5.0
)
def
test2
(
self
):
raise
NotImplementedError
()
#remember to bring back the rest of tests
if
0
:
def
test2_err_bounds0
(
self
):
raise
NotImplementedError
()
def
test2_err_bounds1
(
self
):
raise
NotImplementedError
()
def
test2_ok_elem
(
self
):
raise
NotImplementedError
()
def
test2_ok_row
(
self
):
raise
NotImplementedError
()
def
test2_ok_col
(
self
):
raise
NotImplementedError
()
def
test2_ok_rows_finite
(
self
):
raise
NotImplementedError
()
def
test2_ok_cols_infinite
(
self
):
raise
NotImplementedError
()
def
test2_ok_strided
(
self
):
raise
NotImplementedError
()
def
test3_ok_mat
(
self
):
raise
NotImplementedError
()
class
T_add
(
unittest
.
TestCase
):
def
test_complex128
(
self
):
a
=
tinit
(
numpy
.
ones
(
3
,
dtype
=
'complex128'
))
b
=
tinit
(
numpy
.
ones
(
3
,
dtype
=
'complex128'
))
f
=
Function
([
a
,
b
],
[
a
+
b
],
linker_cls
=
gof
.
CLinker
)
self
.
failUnless
(
numpy
.
all
((
numpy
.
ones
(
3
,
dtype
=
'complex128'
)
*
2
)
==
f
(
a
.
data
,
b
.
data
)))
class
T_abs
(
unittest
.
TestCase
):
class
T_abs
(
unittest
.
TestCase
):
def
test_impl
(
self
):
def
test_impl
(
self
):
t
=
tinit
(
1.0
)
t
=
tinit
(
1.0
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论