Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
bc6ceb89
提交
bc6ceb89
authored
4月 07, 2017
作者:
Thomas George
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
changed numpy to np
上级
9036e6dd
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
12 行增加
和
12 行删除
+12
-12
test_linalg.py
theano/gpuarray/tests/test_linalg.py
+12
-12
没有找到文件。
theano/gpuarray/tests/test_linalg.py
浏览文件 @
bc6ceb89
...
@@ -126,19 +126,19 @@ class TestGpuCholesky(unittest.TestCase):
...
@@ -126,19 +126,19 @@ class TestGpuCholesky(unittest.TestCase):
chol_A
=
cholesky_op
(
A
)
chol_A
=
cholesky_op
(
A
)
return
theano
.
function
([
A
],
chol_A
,
accept_inplace
=
inplace
,
mode
=
mode_with_gpu
)
return
theano
.
function
([
A
],
chol_A
,
accept_inplace
=
inplace
,
mode
=
mode_with_gpu
)
def
compare_gpu_cholesky_to_n
umpy
(
self
,
A_val
,
lower
=
True
,
inplace
=
False
):
def
compare_gpu_cholesky_to_n
p
(
self
,
A_val
,
lower
=
True
,
inplace
=
False
):
# Helper function to compare op output to n
umpy
.cholesky output.
# Helper function to compare op output to n
p
.cholesky output.
chol_A_val
=
n
umpy
.
linalg
.
cholesky
(
A_val
)
chol_A_val
=
n
p
.
linalg
.
cholesky
(
A_val
)
if
not
lower
:
if
not
lower
:
chol_A_val
=
chol_A_val
.
T
chol_A_val
=
chol_A_val
.
T
fn
=
self
.
get_gpu_cholesky_func
(
lower
,
inplace
)
fn
=
self
.
get_gpu_cholesky_func
(
lower
,
inplace
)
res
=
fn
(
A_val
)
res
=
fn
(
A_val
)
chol_A_res
=
n
umpy
.
array
(
res
)
chol_A_res
=
n
p
.
array
(
res
)
utt
.
assert_allclose
(
chol_A_res
,
chol_A_val
)
utt
.
assert_allclose
(
chol_A_res
,
chol_A_val
)
def
test_invalid_input_fail_non_square
(
self
):
def
test_invalid_input_fail_non_square
(
self
):
# Invalid Cholesky input test with non-square matrix as input.
# Invalid Cholesky input test with non-square matrix as input.
A_val
=
n
umpy
.
random
.
normal
(
size
=
(
3
,
2
))
.
astype
(
"float32"
)
A_val
=
n
p
.
random
.
normal
(
size
=
(
3
,
2
))
.
astype
(
"float32"
)
fn
=
self
.
get_gpu_cholesky_func
(
True
,
False
)
fn
=
self
.
get_gpu_cholesky_func
(
True
,
False
)
self
.
assertRaises
(
ValueError
,
fn
,
A_val
)
self
.
assertRaises
(
ValueError
,
fn
,
A_val
)
...
@@ -161,32 +161,32 @@ class TestGpuCholesky(unittest.TestCase):
...
@@ -161,32 +161,32 @@ class TestGpuCholesky(unittest.TestCase):
# make sure all diagonal elements are positive so positive-definite
# make sure all diagonal elements are positive so positive-definite
for
lower
in
[
True
,
False
]:
for
lower
in
[
True
,
False
]:
for
inplace
in
[
True
,
False
]:
for
inplace
in
[
True
,
False
]:
A_val
=
n
umpy
.
diag
(
numpy
.
random
.
uniform
(
size
=
5
)
.
astype
(
"float32"
)
+
1
)
A_val
=
n
p
.
diag
(
np
.
random
.
uniform
(
size
=
5
)
.
astype
(
"float32"
)
+
1
)
self
.
compare_gpu_cholesky_to_n
umpy
(
A_val
,
lower
=
lower
,
inplace
=
inplace
)
self
.
compare_gpu_cholesky_to_n
p
(
A_val
,
lower
=
lower
,
inplace
=
inplace
)
def
test_dense_chol_lower
(
self
):
def
test_dense_chol_lower
(
self
):
# Dense matrix input lower-triangular Cholesky test.
# Dense matrix input lower-triangular Cholesky test.
for
lower
in
[
True
,
False
]:
for
lower
in
[
True
,
False
]:
for
inplace
in
[
True
,
False
]:
for
inplace
in
[
True
,
False
]:
M_val
=
n
umpy
.
random
.
normal
(
size
=
(
3
,
3
))
.
astype
(
"float32"
)
M_val
=
n
p
.
random
.
normal
(
size
=
(
3
,
3
))
.
astype
(
"float32"
)
# A = M.dot(M) will be positive definite for all non-singular M
# A = M.dot(M) will be positive definite for all non-singular M
A_val
=
M_val
.
dot
(
M_val
.
T
)
A_val
=
M_val
.
dot
(
M_val
.
T
)
self
.
compare_gpu_cholesky_to_n
umpy
(
A_val
,
lower
=
lower
,
inplace
=
inplace
)
self
.
compare_gpu_cholesky_to_n
p
(
A_val
,
lower
=
lower
,
inplace
=
inplace
)
def
test_invalid_input_fail_non_symmetric
(
self
):
def
test_invalid_input_fail_non_symmetric
(
self
):
# Invalid Cholesky input test with non-symmetric input.
# Invalid Cholesky input test with non-symmetric input.
# (Non-symmetric real input must also be non-positive definite).
# (Non-symmetric real input must also be non-positive definite).
A_val
=
None
A_val
=
None
while
True
:
while
True
:
A_val
=
n
umpy
.
random
.
normal
(
size
=
(
3
,
3
))
.
astype
(
"float32"
)
A_val
=
n
p
.
random
.
normal
(
size
=
(
3
,
3
))
.
astype
(
"float32"
)
if
not
n
umpy
.
allclose
(
A_val
,
A_val
.
T
):
if
not
n
p
.
allclose
(
A_val
,
A_val
.
T
):
break
break
fn
=
self
.
get_gpu_cholesky_func
(
True
,
False
)
fn
=
self
.
get_gpu_cholesky_func
(
True
,
False
)
self
.
assertRaises
(
LinAlgError
,
fn
,
A_val
)
self
.
assertRaises
(
LinAlgError
,
fn
,
A_val
)
def
test_invalid_input_fail_negative_definite
(
self
):
def
test_invalid_input_fail_negative_definite
(
self
):
# Invalid Cholesky input test with negative-definite input.
# Invalid Cholesky input test with negative-definite input.
M_val
=
n
umpy
.
random
.
normal
(
size
=
(
3
,
3
))
.
astype
(
"float32"
)
M_val
=
n
p
.
random
.
normal
(
size
=
(
3
,
3
))
.
astype
(
"float32"
)
# A = -M.dot(M) will be negative definite for all non-singular M
# A = -M.dot(M) will be negative definite for all non-singular M
A_val
=
-
M_val
.
dot
(
M_val
.
T
)
A_val
=
-
M_val
.
dot
(
M_val
.
T
)
fn
=
self
.
get_gpu_cholesky_func
(
True
,
False
)
fn
=
self
.
get_gpu_cholesky_func
(
True
,
False
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论