Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0b8c20d7
提交
0b8c20d7
authored
3月 26, 2012
作者:
Olivier Delalleau
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #569 from nouiz/blas
Blas
上级
3c9177df
6e39a60b
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
44 行增加
和
23 行删除
+44
-23
test_blas.py
theano/tensor/tests/test_blas.py
+0
-0
test_blas_c.py
theano/tensor/tests/test_blas_c.py
+44
-23
没有找到文件。
theano/tensor/tests/test_blas.py
浏览文件 @
0b8c20d7
差异被折叠。
点击展开。
theano/tensor/tests/test_blas_c.py
浏览文件 @
0b8c20d7
...
@@ -2,6 +2,8 @@ import sys
...
@@ -2,6 +2,8 @@ import sys
import
numpy
import
numpy
from
unittest
import
TestCase
from
unittest
import
TestCase
from
nose.plugins.skip
import
SkipTest
import
theano
import
theano
import
theano.tensor
as
tensor
import
theano.tensor
as
tensor
...
@@ -25,15 +27,19 @@ mode_blas_opt = theano.compile.get_default_mode().including(
...
@@ -25,15 +27,19 @@ mode_blas_opt = theano.compile.get_default_mode().including(
class
TestCGer
(
TestCase
,
TestOptimizationMixin
):
class
TestCGer
(
TestCase
,
TestOptimizationMixin
):
def
setUp
(
self
,
dtype
=
'float64'
):
def
setUp
(
self
,
dtype
=
'float64'
):
if
theano
.
config
.
blas
.
ldflags
==
""
:
raise
SkipTest
(
"This test is useful only when Theano"
" is directly linked to blas."
)
self
.
dtype
=
dtype
self
.
dtype
=
dtype
self
.
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'fast_run'
)
self
.
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'fast_run'
)
self
.
A
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
(
False
,
False
))
self
.
A
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
(
False
,
False
))
self
.
a
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
())
self
.
a
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
())
self
.
x
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
(
False
,))
self
.
x
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
(
False
,))
self
.
y
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
(
False
,))
self
.
y
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
(
False
,))
self
.
Aval
=
numpy
.
ones
((
2
,
3
),
dtype
=
dtype
)
self
.
Aval
=
numpy
.
ones
((
2
,
3
),
dtype
=
dtype
)
self
.
xval
=
numpy
.
asarray
([
1
,
2
],
dtype
=
dtype
)
self
.
xval
=
numpy
.
asarray
([
1
,
2
],
dtype
=
dtype
)
self
.
yval
=
numpy
.
asarray
([
1.5
,
2.7
,
3.9
],
dtype
=
dtype
)
self
.
yval
=
numpy
.
asarray
([
1.5
,
2.7
,
3.9
],
dtype
=
dtype
)
def
function
(
self
,
inputs
,
outputs
):
def
function
(
self
,
inputs
,
outputs
):
return
theano
.
function
(
inputs
,
outputs
,
return
theano
.
function
(
inputs
,
outputs
,
...
@@ -70,13 +76,13 @@ class TestCGer(TestCase, TestOptimizationMixin):
...
@@ -70,13 +76,13 @@ class TestCGer(TestCase, TestOptimizationMixin):
def
test_optimization_pipeline
(
self
):
def
test_optimization_pipeline
(
self
):
f
=
self
.
function
([
self
.
x
,
self
.
y
],
tensor
.
outer
(
self
.
x
,
self
.
y
))
f
=
self
.
function
([
self
.
x
,
self
.
y
],
tensor
.
outer
(
self
.
x
,
self
.
y
))
self
.
assertFunctionContains
(
f
,
CGer
(
destructive
=
True
))
self
.
assertFunctionContains
(
f
,
CGer
(
destructive
=
True
))
f
(
self
.
xval
,
self
.
yval
)
#DebugMode tests correctness
f
(
self
.
xval
,
self
.
yval
)
#
DebugMode tests correctness
def
test_optimization_pipeline_float
(
self
):
def
test_optimization_pipeline_float
(
self
):
self
.
setUp
(
'float32'
)
self
.
setUp
(
'float32'
)
f
=
self
.
function
([
self
.
x
,
self
.
y
],
tensor
.
outer
(
self
.
x
,
self
.
y
))
f
=
self
.
function
([
self
.
x
,
self
.
y
],
tensor
.
outer
(
self
.
x
,
self
.
y
))
self
.
assertFunctionContains
(
f
,
CGer
(
destructive
=
True
))
self
.
assertFunctionContains
(
f
,
CGer
(
destructive
=
True
))
f
(
self
.
xval
,
self
.
yval
)
#DebugMode tests correctness
f
(
self
.
xval
,
self
.
yval
)
#
DebugMode tests correctness
def
test_int_fails
(
self
):
def
test_int_fails
(
self
):
self
.
setUp
(
'int32'
)
self
.
setUp
(
'int32'
)
...
@@ -88,34 +94,37 @@ class TestCGer(TestCase, TestOptimizationMixin):
...
@@ -88,34 +94,37 @@ class TestCGer(TestCase, TestOptimizationMixin):
f
=
self
.
function
([
self
.
A
,
self
.
x
,
self
.
y
],
f
=
self
.
function
([
self
.
A
,
self
.
x
,
self
.
y
],
self
.
A
+
tensor
.
outer
(
self
.
x
,
self
.
y
))
self
.
A
+
tensor
.
outer
(
self
.
x
,
self
.
y
))
self
.
assertFunctionContains
(
f
,
CGer
(
destructive
=
False
))
self
.
assertFunctionContains
(
f
,
CGer
(
destructive
=
False
))
self
.
run_f
(
f
)
#
DebugMode tests correctness
self
.
run_f
(
f
)
#
DebugMode tests correctness
def
test_A_plus_scaled_outer
(
self
):
def
test_A_plus_scaled_outer
(
self
):
f
=
self
.
function
([
self
.
A
,
self
.
x
,
self
.
y
],
f
=
self
.
function
([
self
.
A
,
self
.
x
,
self
.
y
],
self
.
A
+
0.1
*
tensor
.
outer
(
self
.
x
,
self
.
y
))
self
.
A
+
0.1
*
tensor
.
outer
(
self
.
x
,
self
.
y
))
self
.
assertFunctionContains
(
f
,
CGer
(
destructive
=
False
))
self
.
assertFunctionContains
(
f
,
CGer
(
destructive
=
False
))
self
.
run_f
(
f
)
#
DebugMode tests correctness
self
.
run_f
(
f
)
#
DebugMode tests correctness
class
TestCGemv
(
TestCase
,
TestOptimizationMixin
):
class
TestCGemv
(
TestCase
,
TestOptimizationMixin
):
"""
"""Tests of CGemv specifically.
Tests of CGemv specifically.
Generic tests of Gemv-compatibility, including both dtypes are
done below in TestCGemvFloat32 and TestCGemvFloat64
Generic tests of Gemv-compatibility, including both dtypes are done below in
TestCGemvFloat32 and TestCGemvFloat64
"""
"""
def
setUp
(
self
,
dtype
=
'float64'
):
def
setUp
(
self
,
dtype
=
'float64'
):
if
theano
.
config
.
blas
.
ldflags
==
""
:
raise
SkipTest
(
"This test is useful only when Theano"
" is directly linked to blas."
)
self
.
dtype
=
dtype
self
.
dtype
=
dtype
self
.
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'fast_run'
)
self
.
mode
=
theano
.
compile
.
get_default_mode
()
.
including
(
'fast_run'
)
# matrix
# matrix
self
.
A
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
(
False
,
False
))
self
.
A
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
(
False
,
False
))
self
.
Aval
=
numpy
.
ones
((
2
,
3
),
dtype
=
dtype
)
self
.
Aval
=
numpy
.
ones
((
2
,
3
),
dtype
=
dtype
)
# vector
# vector
self
.
x
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
(
False
,))
self
.
x
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
(
False
,))
self
.
y
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
(
False
,))
self
.
y
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
(
False
,))
self
.
xval
=
numpy
.
asarray
([
1
,
2
],
dtype
=
dtype
)
self
.
xval
=
numpy
.
asarray
([
1
,
2
],
dtype
=
dtype
)
self
.
yval
=
numpy
.
asarray
([
1.5
,
2.7
,
3.9
],
dtype
=
dtype
)
self
.
yval
=
numpy
.
asarray
([
1.5
,
2.7
,
3.9
],
dtype
=
dtype
)
# scalar
# scalar
self
.
a
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
())
self
.
a
=
tensor
.
tensor
(
dtype
=
dtype
,
broadcastable
=
())
...
@@ -155,14 +164,15 @@ class TestCGemv(TestCase, TestOptimizationMixin):
...
@@ -155,14 +164,15 @@ class TestCGemv(TestCase, TestOptimizationMixin):
assert
numpy
.
allclose
(
f
(
self
.
Aval
[::
-
1
,
::
-
1
],
self
.
yval
),
assert
numpy
.
allclose
(
f
(
self
.
Aval
[::
-
1
,
::
-
1
],
self
.
yval
),
numpy
.
dot
(
self
.
Aval
[::
-
1
,
::
-
1
],
self
.
yval
))
numpy
.
dot
(
self
.
Aval
[::
-
1
,
::
-
1
],
self
.
yval
))
def
t_gemv1
(
self
,
m_shp
):
def
t_gemv1
(
self
,
m_shp
):
''' test vector2 + dot(matrix, vector1) '''
''' test vector2 + dot(matrix, vector1) '''
rng
=
numpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
unittest_tools
.
fetch_seed
())
v1
=
theano
.
shared
(
numpy
.
array
(
rng
.
uniform
(
size
=
(
m_shp
[
1
],)),
dtype
=
'float32'
))
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_orig
=
numpy
.
array
(
rng
.
uniform
(
size
=
(
m_shp
[
0
],)),
dtype
=
'float32'
)
v2
=
theano
.
shared
(
v2_orig
)
v2
=
theano
.
shared
(
v2_orig
)
m
=
theano
.
shared
(
numpy
.
array
(
rng
.
uniform
(
size
=
m_shp
),
dtype
=
'float32'
))
m
=
theano
.
shared
(
numpy
.
array
(
rng
.
uniform
(
size
=
m_shp
),
dtype
=
'float32'
))
f
=
theano
.
function
([],
v2
+
tensor
.
dot
(
m
,
v1
),
f
=
theano
.
function
([],
v2
+
tensor
.
dot
(
m
,
v1
),
mode
=
self
.
mode
)
mode
=
self
.
mode
)
...
@@ -175,7 +185,7 @@ class TestCGemv(TestCase, TestOptimizationMixin):
...
@@ -175,7 +185,7 @@ class TestCGemv(TestCase, TestOptimizationMixin):
#test the inplace version
#test the inplace version
g
=
theano
.
function
([],
[],
g
=
theano
.
function
([],
[],
updates
=
{
v2
:
v2
+
theano
.
dot
(
m
,
v1
)},
updates
=
{
v2
:
v2
+
theano
.
dot
(
m
,
v1
)},
mode
=
self
.
mode
)
mode
=
self
.
mode
)
# Assert they produce the same output
# Assert they produce the same output
...
@@ -197,10 +207,10 @@ class TestCGemv(TestCase, TestOptimizationMixin):
...
@@ -197,10 +207,10 @@ class TestCGemv(TestCase, TestOptimizationMixin):
numpy
.
dot
(
m
.
get_value
(),
v1
.
get_value
())
+
v2_orig
)
numpy
.
dot
(
m
.
get_value
(),
v1
.
get_value
())
+
v2_orig
)
def
test_gemv1
(
self
):
def
test_gemv1
(
self
):
self
.
t_gemv1
((
3
,
2
))
self
.
t_gemv1
((
3
,
2
))
self
.
t_gemv1
((
0
,
2
))
self
.
t_gemv1
((
0
,
2
))
self
.
t_gemv1
((
3
,
0
))
self
.
t_gemv1
((
3
,
0
))
self
.
t_gemv1
((
0
,
0
))
self
.
t_gemv1
((
0
,
0
))
def
test_gemv_dimensions
(
self
,
dtype
=
'float32'
):
def
test_gemv_dimensions
(
self
,
dtype
=
'float32'
):
alpha
=
theano
.
shared
(
theano
.
_asarray
(
1.0
,
dtype
=
dtype
),
alpha
=
theano
.
shared
(
theano
.
_asarray
(
1.0
,
dtype
=
dtype
),
...
@@ -213,7 +223,7 @@ class TestCGemv(TestCase, TestOptimizationMixin):
...
@@ -213,7 +223,7 @@ class TestCGemv(TestCase, TestOptimizationMixin):
mode
=
self
.
mode
)
mode
=
self
.
mode
)
# Matrix value
# Matrix value
A_val
=
numpy
.
ones
((
5
,
3
),
dtype
=
dtype
)
A_val
=
numpy
.
ones
((
5
,
3
),
dtype
=
dtype
)
# Different vector length
# Different vector length
ones_3
=
numpy
.
ones
(
3
,
dtype
=
dtype
)
ones_3
=
numpy
.
ones
(
3
,
dtype
=
dtype
)
ones_4
=
numpy
.
ones
(
4
,
dtype
=
dtype
)
ones_4
=
numpy
.
ones
(
4
,
dtype
=
dtype
)
...
@@ -233,6 +243,11 @@ class TestCGemvFloat32(TestCase, BaseGemv, TestOptimizationMixin):
...
@@ -233,6 +243,11 @@ class TestCGemvFloat32(TestCase, BaseGemv, TestOptimizationMixin):
gemv
=
CGemv
(
inplace
=
False
)
gemv
=
CGemv
(
inplace
=
False
)
gemv_inplace
=
CGemv
(
inplace
=
True
)
gemv_inplace
=
CGemv
(
inplace
=
True
)
def
setUp
(
self
):
if
theano
.
config
.
blas
.
ldflags
==
""
:
raise
SkipTest
(
"This test is useful only when Theano"
" is directly linked to blas."
)
class
TestCGemvFloat64
(
TestCase
,
BaseGemv
,
TestOptimizationMixin
):
class
TestCGemvFloat64
(
TestCase
,
BaseGemv
,
TestOptimizationMixin
):
mode
=
mode_blas_opt
mode
=
mode_blas_opt
...
@@ -240,5 +255,11 @@ class TestCGemvFloat64(TestCase, BaseGemv, TestOptimizationMixin):
...
@@ -240,5 +255,11 @@ class TestCGemvFloat64(TestCase, BaseGemv, TestOptimizationMixin):
gemv
=
CGemv
(
inplace
=
False
)
gemv
=
CGemv
(
inplace
=
False
)
gemv_inplace
=
CGemv
(
inplace
=
True
)
gemv_inplace
=
CGemv
(
inplace
=
True
)
def
setUp
(
self
):
if
theano
.
config
.
blas
.
ldflags
==
""
:
raise
SkipTest
(
"This test is useful only when Theano"
" is directly linked to blas."
)
class
TestBlasStridesC
(
TestBlasStrides
):
class
TestBlasStridesC
(
TestBlasStrides
):
mode
=
mode_blas_opt
mode
=
mode_blas_opt
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论