Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
82901783
提交
82901783
authored
1月 25, 2017
作者:
Simon Lefrancois
提交者:
GitHub
1月 25, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5421 from tfjgeorge/cusolver
Cusolver using Cholesky decomposition for symmetric matrices
上级
d5520e81
1b81f81e
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
56 行增加
和
7 行删除
+56
-7
linalg.py
theano/gpuarray/linalg.py
+0
-0
test_linalg.py
theano/gpuarray/tests/test_linalg.py
+56
-7
没有找到文件。
theano/gpuarray/linalg.py
浏览文件 @
82901783
差异被折叠。
点击展开。
theano/gpuarray/tests/test_linalg.py
浏览文件 @
82901783
...
@@ -7,6 +7,8 @@ import theano
...
@@ -7,6 +7,8 @@ import theano
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
from
.config
import
mode_with_gpu
from
.config
import
mode_with_gpu
from
numpy.linalg.linalg
import
LinAlgError
# Skip tests if cuda_ndarray is not available.
# Skip tests if cuda_ndarray is not available.
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
from
theano.gpuarray.linalg
import
(
cusolver_available
,
gpu_solve
)
from
theano.gpuarray.linalg
import
(
cusolver_available
,
gpu_solve
)
...
@@ -16,7 +18,7 @@ if not cusolver_available:
...
@@ -16,7 +18,7 @@ if not cusolver_available:
class
TestCusolver
(
unittest
.
TestCase
):
class
TestCusolver
(
unittest
.
TestCase
):
def
run_gpu_solve
(
self
,
A_val
,
x_val
):
def
run_gpu_solve
(
self
,
A_val
,
x_val
,
A_struct
=
None
):
b_val
=
numpy
.
dot
(
A_val
,
x_val
)
b_val
=
numpy
.
dot
(
A_val
,
x_val
)
b_val_trans
=
numpy
.
dot
(
A_val
.
T
,
x_val
)
b_val_trans
=
numpy
.
dot
(
A_val
.
T
,
x_val
)
...
@@ -24,14 +26,19 @@ class TestCusolver(unittest.TestCase):
...
@@ -24,14 +26,19 @@ class TestCusolver(unittest.TestCase):
b
=
theano
.
tensor
.
matrix
(
"b"
,
dtype
=
"float32"
)
b
=
theano
.
tensor
.
matrix
(
"b"
,
dtype
=
"float32"
)
b_trans
=
theano
.
tensor
.
matrix
(
"b"
,
dtype
=
"float32"
)
b_trans
=
theano
.
tensor
.
matrix
(
"b"
,
dtype
=
"float32"
)
solver
=
gpu_solve
(
A
,
b
)
if
A_struct
is
None
:
solver_trans
=
gpu_solve
(
A
,
b_trans
,
trans
=
'T'
)
solver
=
gpu_solve
(
A
,
b
)
solver_trans
=
gpu_solve
(
A
,
b_trans
,
trans
=
'T'
)
else
:
solver
=
gpu_solve
(
A
,
b
,
A_struct
)
solver_trans
=
gpu_solve
(
A
,
b_trans
,
A_struct
,
trans
=
'T'
)
fn
=
theano
.
function
([
A
,
b
,
b_trans
],
[
solver
,
solver_trans
],
mode
=
mode_with_gpu
)
fn
=
theano
.
function
([
A
,
b
,
b_trans
],
[
solver
,
solver_trans
],
mode
=
mode_with_gpu
)
res
=
fn
(
A_val
,
b_val
,
b_val_trans
)
res
=
fn
(
A_val
,
b_val
,
b_val_trans
)
x_res
=
numpy
.
array
(
res
[
0
])
x_res
=
numpy
.
array
(
res
[
0
])
x_res_trans
=
numpy
.
array
(
res
[
1
])
x_res_trans
=
numpy
.
array
(
res
[
1
])
utt
.
assert_allclose
(
x_
res
,
x_val
)
utt
.
assert_allclose
(
x_
val
,
x_res
)
utt
.
assert_allclose
(
x_
res_trans
,
x_val
)
utt
.
assert_allclose
(
x_
val
,
x_res_trans
)
def
test_diag_solve
(
self
):
def
test_diag_solve
(
self
):
numpy
.
random
.
seed
(
1
)
numpy
.
random
.
seed
(
1
)
...
@@ -41,13 +48,24 @@ class TestCusolver(unittest.TestCase):
...
@@ -41,13 +48,24 @@ class TestCusolver(unittest.TestCase):
1
))
.
astype
(
"float32"
)
1
))
.
astype
(
"float32"
)
self
.
run_gpu_solve
(
A_val
,
x_val
)
self
.
run_gpu_solve
(
A_val
,
x_val
)
def
test_bshape_solve
(
self
):
"""
Test when shape of b (k, m) is such as m > k
"""
numpy
.
random
.
seed
(
1
)
A_val
=
numpy
.
asarray
([[
2
,
0
,
0
],
[
0
,
1
,
0
],
[
0
,
0
,
1
]],
dtype
=
"float32"
)
x_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_val
.
shape
[
1
],
A_val
.
shape
[
1
]
+
1
))
.
astype
(
"float32"
)
self
.
run_gpu_solve
(
A_val
,
x_val
)
def
test_sym_solve
(
self
):
def
test_sym_solve
(
self
):
numpy
.
random
.
seed
(
1
)
numpy
.
random
.
seed
(
1
)
A_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
5
))
.
astype
(
"float32"
)
A_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
5
))
.
astype
(
"float32"
)
A_sym
=
(
A_val
+
A_val
.
T
)
/
2.0
A_sym
=
numpy
.
dot
(
A_val
,
A_val
.
T
)
x_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_val
.
shape
[
1
],
x_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_val
.
shape
[
1
],
1
))
.
astype
(
"float32"
)
1
))
.
astype
(
"float32"
)
self
.
run_gpu_solve
(
A_sym
,
x_val
)
self
.
run_gpu_solve
(
A_sym
,
x_val
,
'symmetric'
)
def
test_orth_solve
(
self
):
def
test_orth_solve
(
self
):
numpy
.
random
.
seed
(
1
)
numpy
.
random
.
seed
(
1
)
...
@@ -63,3 +81,34 @@ class TestCusolver(unittest.TestCase):
...
@@ -63,3 +81,34 @@ class TestCusolver(unittest.TestCase):
x_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
x_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_val
.
shape
[
1
],
4
))
.
astype
(
"float32"
)
(
A_val
.
shape
[
1
],
4
))
.
astype
(
"float32"
)
self
.
run_gpu_solve
(
A_val
,
x_val
)
self
.
run_gpu_solve
(
A_val
,
x_val
)
def
test_linalgerrsym_solve
(
self
):
numpy
.
random
.
seed
(
1
)
A_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
5
))
.
astype
(
"float32"
)
x_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_val
.
shape
[
1
],
4
))
.
astype
(
"float32"
)
A_val
=
numpy
.
dot
(
A_val
.
T
,
A_val
)
# make A singular
A_val
[:,
2
]
=
A_val
[:,
1
]
+
A_val
[:,
3
]
A
=
theano
.
tensor
.
matrix
(
"A"
,
dtype
=
"float32"
)
b
=
theano
.
tensor
.
matrix
(
"b"
,
dtype
=
"float32"
)
solver
=
gpu_solve
(
A
,
b
,
'symmetric'
)
fn
=
theano
.
function
([
A
,
b
],
[
solver
],
mode
=
mode_with_gpu
)
self
.
assertRaises
(
LinAlgError
,
fn
,
A_val
,
x_val
)
def
test_linalgerr_solve
(
self
):
numpy
.
random
.
seed
(
1
)
A_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
5
,
5
))
.
astype
(
"float32"
)
x_val
=
numpy
.
random
.
uniform
(
-
0.4
,
0.4
,
(
A_val
.
shape
[
1
],
4
))
.
astype
(
"float32"
)
# make A singular
A_val
[:,
2
]
=
0
A
=
theano
.
tensor
.
matrix
(
"A"
,
dtype
=
"float32"
)
b
=
theano
.
tensor
.
matrix
(
"b"
,
dtype
=
"float32"
)
solver
=
gpu_solve
(
A
,
b
,
trans
=
'T'
)
fn
=
theano
.
function
([
A
,
b
],
[
solver
],
mode
=
mode_with_gpu
)
self
.
assertRaises
(
LinAlgError
,
fn
,
A_val
,
x_val
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论