Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9045925f
提交
9045925f
authored
12月 27, 2011
作者:
James Bergstra
提交者:
Frederic
1月 23, 2012
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor test_blas for test_blas_c
上级
e18787c3
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
49 行增加
和
56 行删除
+49
-56
test_blas.py
theano/tensor/tests/test_blas.py
+24
-56
unittest_tools.py
theano/tests/unittest_tools.py
+25
-0
没有找到文件。
theano/tensor/tests/test_blas.py
浏览文件 @
9045925f
...
@@ -1018,6 +1018,8 @@ def matrixmultiply(a, b):
...
@@ -1018,6 +1018,8 @@ def matrixmultiply(a, b):
class
BaseGemv
(
object
):
class
BaseGemv
(
object
):
mode
=
mode_blas_opt
# can be overridden with self.mode
def
get_data
(
self
,
x_stride
=
1
,
y_stride
=
1
):
def
get_data
(
self
,
x_stride
=
1
,
y_stride
=
1
):
rng
=
numpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
mult
=
array
(
1
,
dtype
=
self
.
dtype
)
mult
=
array
(
1
,
dtype
=
self
.
dtype
)
...
@@ -1036,10 +1038,10 @@ class BaseGemv(object):
...
@@ -1036,10 +1038,10 @@ class BaseGemv(object):
oy
=
alpha
*
T
.
dot
(
a
,
x
)
+
beta
*
y
oy
=
alpha
*
T
.
dot
(
a
,
x
)
+
beta
*
y
oy_func
=
theano
.
function
([],
oy
,
mode
=
mode_blas_opt
)
oy_func
=
theano
.
function
([],
oy
,
mode
=
self
.
mode
)
topo
=
oy_func
.
maker
.
env
.
toposort
()
topo
=
oy_func
.
maker
.
env
.
toposort
()
assert
sum
([
isinstance
(
node
.
op
,
theano
.
tensor
.
blas
.
Gemv
)
for
node
in
topo
])
==
1
self
.
assertFunctionContains1
(
oy_func
,
self
.
gemv
)
oy_val
=
oy_func
()
oy_val
=
oy_func
()
...
@@ -1056,22 +1058,9 @@ class BaseGemv(object):
...
@@ -1056,22 +1058,9 @@ class BaseGemv(object):
oy
=
T
.
dot
(
a
,
x
)
oy
=
T
.
dot
(
a
,
x
)
oy_func
=
theano
.
function
([],
oy
,
mode
=
mode_blas_opt
)
oy_func
=
theano
.
function
([],
oy
,
mode
=
self
.
mode
)
topo
=
oy_func
.
maker
.
env
.
toposort
()
self
.
assertFunctionContains1
(
oy_func
,
self
.
gemv_inplace
)
# The only op in the graph is a dot.
# In the gemm case, we create a dot22 for that case
# There is no dot21.
# Creating one is not useful as this is not faster(in fact it would be slower!
# as more code would be in python, numpy.dot will call gemv itself)
# See ticket 594
"""
>>> t0=time.time();x=scipy.linalg.blas.fblas.dgemv(1,a.T,b,1,z.T);t1=time.time();print t1-t0
0.00192999839783
>>> t0=time.time();x=numpy.dot(a,b);t1=time.time();print t1-t0
0.00158381462097
"""
assert
sum
([
isinstance
(
node
.
op
,
theano
.
tensor
.
blas
.
Gemv
)
for
node
in
topo
])
==
0
oy_v
=
oy_func
()
oy_v
=
oy_func
()
assert_array_almost_equal
(
desired_oy
,
oy_v
)
assert_array_almost_equal
(
desired_oy
,
oy_v
)
...
@@ -1086,10 +1075,9 @@ class BaseGemv(object):
...
@@ -1086,10 +1075,9 @@ class BaseGemv(object):
oy
=
alpha
*
T
.
dot
(
a
.
T
,
x
)
+
beta
*
y
oy
=
alpha
*
T
.
dot
(
a
.
T
,
x
)
+
beta
*
y
oy_func
=
theano
.
function
([],
oy
,
mode
=
mode_blas_opt
)
oy_func
=
theano
.
function
([],
oy
,
mode
=
self
.
mode
)
topo
=
oy_func
.
maker
.
env
.
toposort
()
self
.
assertFunctionContains1
(
oy_func
,
self
.
gemv
)
assert
sum
([
isinstance
(
node
.
op
,
theano
.
tensor
.
blas
.
Gemv
)
for
node
in
topo
])
==
1
oy_v
=
oy_func
()
oy_v
=
oy_func
()
assert_array_almost_equal
(
desired_oy
,
oy_v
)
assert_array_almost_equal
(
desired_oy
,
oy_v
)
...
@@ -1103,10 +1091,9 @@ class BaseGemv(object):
...
@@ -1103,10 +1091,9 @@ class BaseGemv(object):
oy
=
alpha
*
T
.
dot
(
a
,
x
[::
2
])
+
beta
*
y
oy
=
alpha
*
T
.
dot
(
a
,
x
[::
2
])
+
beta
*
y
oy_func
=
theano
.
function
([],
oy
,
mode
=
mode_blas_opt
)
oy_func
=
theano
.
function
([],
oy
,
mode
=
self
.
mode
)
topo
=
oy_func
.
maker
.
env
.
toposort
()
self
.
assertFunctionContains1
(
oy_func
,
self
.
gemv
)
assert
sum
([
isinstance
(
node
.
op
,
theano
.
tensor
.
blas
.
Gemv
)
for
node
in
topo
])
==
1
oy_v
=
oy_func
()
oy_v
=
oy_func
()
assert_array_almost_equal
(
desired_oy
,
oy_v
)
assert_array_almost_equal
(
desired_oy
,
oy_v
)
...
@@ -1120,10 +1107,9 @@ class BaseGemv(object):
...
@@ -1120,10 +1107,9 @@ class BaseGemv(object):
oy
=
alpha
*
T
.
dot
(
a
.
T
,
x
[::
2
])
+
beta
*
y
oy
=
alpha
*
T
.
dot
(
a
.
T
,
x
[::
2
])
+
beta
*
y
oy_func
=
theano
.
function
([],
oy
,
mode
=
mode_blas_opt
)
oy_func
=
theano
.
function
([],
oy
,
mode
=
self
.
mode
)
topo
=
oy_func
.
maker
.
env
.
toposort
()
self
.
assertFunctionContains1
(
oy_func
,
self
.
gemv
)
assert
sum
([
isinstance
(
node
.
op
,
theano
.
tensor
.
blas
.
Gemv
)
for
node
in
topo
])
==
1
oy_v
=
oy_func
()
oy_v
=
oy_func
()
assert_array_almost_equal
(
desired_oy
,
oy_v
)
assert_array_almost_equal
(
desired_oy
,
oy_v
)
...
@@ -1137,10 +1123,9 @@ class BaseGemv(object):
...
@@ -1137,10 +1123,9 @@ class BaseGemv(object):
oy
=
alpha
*
T
.
dot
(
a
,
x
)
+
beta
*
y
[::
2
]
oy
=
alpha
*
T
.
dot
(
a
,
x
)
+
beta
*
y
[::
2
]
oy_func
=
theano
.
function
([],
oy
,
mode
=
mode_blas_opt
)
oy_func
=
theano
.
function
([],
oy
,
mode
=
self
.
mode
)
topo
=
oy_func
.
maker
.
env
.
toposort
()
self
.
assertFunctionContains1
(
oy_func
,
self
.
gemv
)
assert
sum
([
isinstance
(
node
.
op
,
theano
.
tensor
.
blas
.
Gemv
)
for
node
in
topo
])
==
1
oy_v
=
oy_func
()
oy_v
=
oy_func
()
assert_array_almost_equal
(
desired_oy
,
oy_v
)
assert_array_almost_equal
(
desired_oy
,
oy_v
)
...
@@ -1154,21 +1139,24 @@ class BaseGemv(object):
...
@@ -1154,21 +1139,24 @@ class BaseGemv(object):
oy
=
alpha
*
T
.
dot
(
a
.
T
,
x
)
+
beta
*
y
[::
2
]
oy
=
alpha
*
T
.
dot
(
a
.
T
,
x
)
+
beta
*
y
[::
2
]
oy_func
=
theano
.
function
([],
oy
,
mode
=
mode_blas_opt
)
oy_func
=
theano
.
function
([],
oy
,
mode
=
self
.
mode
)
topo
=
oy_func
.
maker
.
env
.
toposort
()
self
.
assertFunctionContains1
(
oy_func
,
self
.
gemv
)
assert
sum
([
isinstance
(
node
.
op
,
theano
.
tensor
.
blas
.
Gemv
)
for
node
in
topo
])
==
1
oy_v
=
oy_func
()
oy_v
=
oy_func
()
assert_array_almost_equal
(
desired_oy
,
oy_v
)
assert_array_almost_equal
(
desired_oy
,
oy_v
)
class
TestSgemv
(
TestCase
,
BaseGemv
,
unittest_tools
.
TestOptimizationMixin
):
class
TestSgemv
(
TestCase
,
BaseGemv
):
dtype
=
float32
dtype
=
float32
gemv
=
theano
.
tensor
.
blas
.
gemv_no_inplace
gemv_inplace
=
theano
.
tensor
.
blas
.
gemv_inplace
class
TestDgemv
(
TestCase
,
BaseGemv
):
class
TestDgemv
(
TestCase
,
BaseGemv
,
unittest_tools
.
TestOptimizationMixin
):
dtype
=
float64
dtype
=
float64
gemv
=
theano
.
tensor
.
blas
.
gemv_no_inplace
gemv_inplace
=
theano
.
tensor
.
blas
.
gemv_inplace
#The optimization to put Gemv don't work for complex type for now.
#The optimization to put Gemv don't work for complex type for now.
# See ticket 653.
# See ticket 653.
...
@@ -1373,27 +1361,7 @@ class TestGer_make_thunk(TestCase):
...
@@ -1373,27 +1361,7 @@ class TestGer_make_thunk(TestCase):
def
test_c128_1_9
(
self
):
return
self
.
given_dtype
(
'complex128'
,
1
,
9
)
def
test_c128_1_9
(
self
):
return
self
.
given_dtype
(
'complex128'
,
1
,
9
)
# TODO: Refactor and add to this base class as we refactor test code.
class
TestGer_local_gemm_to_ger
(
TestCase
,
unittest_tools
.
TestOptimizationMixin
):
class
TestOptimizationMixin
(
object
):
def
assertFunctionContains
(
self
,
f
,
op
,
min
=
1
,
max
=
sys
.
maxint
):
toposort
=
f
.
maker
.
env
.
toposort
()
matches
=
[
node
for
node
in
toposort
if
node
.
op
==
op
]
assert
(
min
<=
len
(
matches
)
<=
max
),
toposort
def
assertFunctionContains0
(
self
,
f
,
op
):
return
self
.
assertFunctionContains
(
f
,
op
,
min
=
0
,
max
=
0
)
def
assertFunctionContains1
(
self
,
f
,
op
):
return
self
.
assertFunctionContains
(
f
,
op
,
min
=
1
,
max
=
1
)
def
assertFunctionContainsN
(
self
,
f
,
op
,
N
):
return
self
.
assertFunctionContains
(
f
,
op
,
min
=
N
,
max
=
N
)
def
SkipTest
(
self
):
raise
Exception
(
'how do I skip this test properly?'
)
class
TestGer_local_gemm_to_ger
(
TestCase
,
TestOptimizationMixin
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'fast_run'
)
self
.
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'fast_run'
)
...
...
theano/tests/unittest_tools.py
浏览文件 @
9045925f
...
@@ -5,11 +5,13 @@ import numpy
...
@@ -5,11 +5,13 @@ import numpy
import
theano.tensor
as
T
import
theano.tensor
as
T
from
theano.configparser
import
config
,
AddConfigVar
,
StrParam
from
theano.configparser
import
config
,
AddConfigVar
,
StrParam
AddConfigVar
(
'unittests.rseed'
,
AddConfigVar
(
'unittests.rseed'
,
"Seed to use for randomized unit tests. Special value 'random' means using a seed of None."
,
"Seed to use for randomized unit tests. Special value 'random' means using a seed of None."
,
StrParam
(
666
),
StrParam
(
666
),
in_c_key
=
False
)
in_c_key
=
False
)
def
fetch_seed
(
pseed
=
None
):
def
fetch_seed
(
pseed
=
None
):
"""
"""
Returns the seed to use for running the unit tests.
Returns the seed to use for running the unit tests.
...
@@ -38,6 +40,7 @@ def fetch_seed(pseed=None):
...
@@ -38,6 +40,7 @@ def fetch_seed(pseed=None):
return
seed
return
seed
def
seed_rng
(
pseed
=
None
):
def
seed_rng
(
pseed
=
None
):
"""
"""
Seeds numpy's random number generator with the value returned by fetch_seed.
Seeds numpy's random number generator with the value returned by fetch_seed.
...
@@ -51,6 +54,7 @@ def seed_rng(pseed=None):
...
@@ -51,6 +54,7 @@ def seed_rng(pseed=None):
numpy
.
random
.
seed
(
seed
)
numpy
.
random
.
seed
(
seed
)
return
seed
return
seed
def
verify_grad
(
op
,
pt
,
n_tests
=
2
,
rng
=
None
,
*
args
,
**
kwargs
):
def
verify_grad
(
op
,
pt
,
n_tests
=
2
,
rng
=
None
,
*
args
,
**
kwargs
):
"""
"""
Wrapper for tensor/basic.py:verify_grad
Wrapper for tensor/basic.py:verify_grad
...
@@ -72,3 +76,24 @@ def verify_grad(op, pt, n_tests=2, rng=None, *args, **kwargs):
...
@@ -72,3 +76,24 @@ def verify_grad(op, pt, n_tests=2, rng=None, *args, **kwargs):
# raise
# raise
#
#
verify_grad
.
E_grad
=
T
.
verify_grad
.
E_grad
verify_grad
.
E_grad
=
T
.
verify_grad
.
E_grad
class
TestOptimizationMixin
(
object
):
def
assertFunctionContains
(
self
,
f
,
op
,
min
=
1
,
max
=
sys
.
maxint
):
toposort
=
f
.
maker
.
env
.
toposort
()
matches
=
[
node
for
node
in
toposort
if
node
.
op
==
op
]
assert
(
min
<=
len
(
matches
)
<=
max
),
toposort
def
assertFunctionContains0
(
self
,
f
,
op
):
return
self
.
assertFunctionContains
(
f
,
op
,
min
=
0
,
max
=
0
)
def
assertFunctionContains1
(
self
,
f
,
op
):
return
self
.
assertFunctionContains
(
f
,
op
,
min
=
1
,
max
=
1
)
def
assertFunctionContainsN
(
self
,
f
,
op
,
N
):
return
self
.
assertFunctionContains
(
f
,
op
,
min
=
N
,
max
=
N
)
def
SkipTest
(
self
):
raise
Exception
(
'how do I skip this test properly?'
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论