Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e9e77d60
提交
e9e77d60
authored
12月 27, 2011
作者:
James Bergstra
提交者:
Frederic
1月 23, 2012
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adding tests for CGemv
上级
9045925f
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
139 行增加
和
5 行删除
+139
-5
test_blas_c.py
theano/tensor/tests/test_blas_c.py
+139
-5
没有找到文件。
theano/tensor/tests/test_blas_c.py
浏览文件 @
e9e77d60
...
...
@@ -2,17 +2,26 @@ import sys
import
numpy
import
theano
import
theano.tensor
as
tensor
from
theano.tensor.blas_c
import
CGer
from
theano.tensor.blas_scipy
import
ScipyGer
from
theano.tensor.blas
import
Ger
from
test_blas
import
TestCase
,
TestOptimizationMixin
,
gemm_no_inplace
from
theano.tensor.blas_c
import
CGemv
from
theano.tensor.blas_scipy
import
ScipyGer
from
theano.tensor.blas
import
Gemv
from
theano.tests
import
unittest_tools
from
theano.tests.unittest_tools
import
TestOptimizationMixin
from
test_blas
import
TestCase
from
test_blas
import
BaseGemv
class
TestCGer
(
TestCase
,
TestOptimizationMixin
):
def
setUp
(
self
):
def
setUp
(
self
,
dtype
=
'float64'
):
self
.
dtype
=
dtype
self
.
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'fast_run'
)
dtype
=
self
.
dtype
=
'float64'
# optimization isn't dtype-dependent
self
.
A
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
(
False
,
False
))
self
.
a
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
())
self
.
x
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
(
False
,))
...
...
@@ -20,8 +29,6 @@ class TestCGer(TestCase, TestOptimizationMixin):
self
.
Aval
=
numpy
.
ones
((
2
,
3
),
dtype
=
dtype
)
self
.
xval
=
numpy
.
asarray
([
1
,
2
],
dtype
=
dtype
)
self
.
yval
=
numpy
.
asarray
([
1.5
,
2.7
,
3.9
],
dtype
=
dtype
)
if
not
theano
.
tensor
.
blas_scipy
.
optimizations_enabled
:
self
.
SkipTest
()
def
function
(
self
,
inputs
,
outputs
):
return
theano
.
function
(
inputs
,
outputs
,
...
...
@@ -59,6 +66,18 @@ class TestCGer(TestCase, TestOptimizationMixin):
self
.
assertFunctionContains
(
f
,
CGer
(
destructive
=
True
))
f
(
self
.
xval
,
self
.
yval
)
#DebugMode tests correctness
def
test_optimization_pipeline_float
(
self
):
self
.
setUp
(
'float32'
)
f
=
self
.
function
([
self
.
x
,
self
.
y
],
tensor
.
outer
(
self
.
x
,
self
.
y
))
self
.
assertFunctionContains
(
f
,
CGer
(
destructive
=
True
))
f
(
self
.
xval
,
self
.
yval
)
#DebugMode tests correctness
def
test_int_fails
(
self
):
self
.
setUp
(
'int32'
)
f
=
self
.
function
([
self
.
x
,
self
.
y
],
tensor
.
outer
(
self
.
x
,
self
.
y
))
self
.
assertFunctionContains0
(
f
,
CGer
(
destructive
=
True
))
self
.
assertFunctionContains0
(
f
,
CGer
(
destructive
=
False
))
def
test_A_plus_outer
(
self
):
f
=
self
.
function
([
self
.
A
,
self
.
x
,
self
.
y
],
self
.
A
+
tensor
.
outer
(
self
.
x
,
self
.
y
))
...
...
@@ -71,3 +90,118 @@ class TestCGer(TestCase, TestOptimizationMixin):
self
.
assertFunctionContains
(
f
,
CGer
(
destructive
=
False
))
self
.
run_f
(
f
)
#DebugMode tests correctness
class
TestCGemv
(
TestCase
,
TestOptimizationMixin
):
def
setUp
(
self
,
dtype
=
'float64'
):
self
.
dtype
=
dtype
self
.
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'fast_run'
)
# matrix
self
.
A
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
(
False
,
False
))
self
.
Aval
=
numpy
.
ones
((
2
,
3
),
dtype
=
dtype
)
# vector
self
.
x
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
(
False
,))
self
.
y
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
(
False
,))
self
.
xval
=
numpy
.
asarray
([
1
,
2
],
dtype
=
dtype
)
self
.
yval
=
numpy
.
asarray
([
1.5
,
2.7
,
3.9
],
dtype
=
dtype
)
# scalar
self
.
a
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
())
def
test_optimizations_vm
(
self
):
''' Test vector dot matrix '''
f
=
theano
.
function
([
self
.
x
,
self
.
A
],
theano
.
dot
(
self
.
x
,
self
.
A
),
mode
=
self
.
mode
)
# Assert that the dot was optimized somehow
self
.
assertFunctionContains0
(
f
,
tensor
.
dot
)
self
.
assertFunctionContains1
(
f
,
CGemv
(
True
))
# Assert they produce the same output
assert
numpy
.
allclose
(
f
(
self
.
xval
,
self
.
Aval
),
numpy
.
dot
(
self
.
xval
,
self
.
Aval
))
def
test_optimizations_mv
(
self
):
''' Test matrix dot vector '''
f
=
theano
.
function
([
self
.
A
,
self
.
y
],
theano
.
dot
(
self
.
A
,
self
.
y
),
mode
=
self
.
mode
)
# Assert that the dot was optimized somehow
self
.
assertFunctionContains0
(
f
,
tensor
.
dot
)
self
.
assertFunctionContains1
(
f
,
CGemv
(
True
))
# Assert they produce the same output
assert
numpy
.
allclose
(
f
(
self
.
Aval
,
self
.
yval
),
numpy
.
dot
(
self
.
Aval
,
self
.
yval
))
def
t_gemv1
(
self
,
m_shp
):
''' test vector2 + dot(matrix, vector1) '''
rng
=
numpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
v1
=
theano
.
shared
(
numpy
.
array
(
rng
.
uniform
(
size
=
(
m_shp
[
1
],)),
dtype
=
'float32'
))
v2_orig
=
numpy
.
array
(
rng
.
uniform
(
size
=
(
m_shp
[
0
],)),
dtype
=
'float32'
)
v2
=
theano
.
shared
(
v2_orig
)
m
=
theano
.
shared
(
numpy
.
array
(
rng
.
uniform
(
size
=
m_shp
),
dtype
=
'float32'
))
f
=
theano
.
function
([],
v2
+
tensor
.
dot
(
m
,
v1
),
mode
=
self
.
mode
)
# Assert they produce the same output
assert
numpy
.
allclose
(
f
(),
numpy
.
dot
(
m
.
get_value
(),
v1
.
get_value
())
+
v2_orig
)
topo
=
[
n
.
op
for
n
in
f
.
maker
.
env
.
toposort
()]
assert
topo
==
[
CGemv
(
inplace
=
False
)],
topo
#test the inplace version
f
=
theano
.
function
([],
[],
updates
=
{
v2
:
v2
+
theano
.
dot
(
m
,
v1
)},
mode
=
self
.
mode
)
# Assert they produce the same output
f
()
assert
numpy
.
allclose
(
v2
.
get_value
(),
numpy
.
dot
(
m
.
get_value
(),
v1
.
get_value
())
+
v2_orig
)
topo
=
[
n
.
op
for
n
in
f
.
maker
.
env
.
toposort
()]
assert
topo
==
[
CGemv
(
inplace
=
True
)]
def
test_gemv1
(
self
):
self
.
t_gemv1
((
3
,
2
))
self
.
t_gemv1
((
0
,
2
))
self
.
t_gemv1
((
3
,
0
))
self
.
t_gemv1
((
0
,
0
))
def
test_gemv_dimensions
(
self
,
dtype
=
'float32'
):
alpha
=
theano
.
shared
(
theano
.
_asarray
(
1.0
,
dtype
=
dtype
),
name
=
'alpha'
)
beta
=
theano
.
shared
(
theano
.
_asarray
(
1.0
,
dtype
=
dtype
),
name
=
'beta'
)
z
=
beta
*
self
.
y
+
alpha
*
tensor
.
dot
(
self
.
A
,
self
.
x
)
f
=
theano
.
function
([
self
.
A
,
self
.
x
,
self
.
y
],
z
,
mode
=
self
.
mode
)
# Matrix value
A_val
=
numpy
.
ones
((
5
,
3
),
dtype
=
dtype
)
# Different vector length
ones_3
=
numpy
.
ones
(
3
,
dtype
=
dtype
)
ones_4
=
numpy
.
ones
(
4
,
dtype
=
dtype
)
ones_5
=
numpy
.
ones
(
5
,
dtype
=
dtype
)
ones_6
=
numpy
.
ones
(
6
,
dtype
=
dtype
)
f
(
A_val
,
ones_3
,
ones_5
)
self
.
assertRaises
(
ValueError
,
f
,
A_val
,
ones_4
,
ones_5
)
self
.
assertRaises
(
ValueError
,
f
,
A_val
,
ones_3
,
ones_6
)
self
.
assertRaises
(
ValueError
,
f
,
A_val
,
ones_4
,
ones_6
)
class
TestCGemvFloat32
(
TestCase
,
BaseGemv
,
TestOptimizationMixin
):
dtype
=
'float32'
gemv
=
CGemv
(
inplace
=
False
)
gemv_inplace
=
CGemv
(
inplace
=
True
)
class
TestCGemvFloat64
(
TestCase
,
BaseGemv
,
TestOptimizationMixin
):
dtype
=
'float64'
gemv
=
CGemv
(
inplace
=
False
)
gemv_inplace
=
CGemv
(
inplace
=
True
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论