Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4c87b1b3
提交
4c87b1b3
authored
4月 11, 2017
作者:
Thomas George
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
addressed @notoraptor comments
上级
ace491ba
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
11 行增加
和
15 行删除
+11
-15
linalg.py
theano/gpuarray/linalg.py
+0
-3
opt.py
theano/gpuarray/opt.py
+1
-1
test_linalg.py
theano/gpuarray/tests/test_linalg.py
+8
-9
test_opt.py
theano/gpuarray/tests/test_opt.py
+2
-2
没有找到文件。
theano/gpuarray/linalg.py
浏览文件 @
4c87b1b3
...
@@ -8,9 +8,6 @@ from theano import Op
...
@@ -8,9 +8,6 @@ from theano import Op
from
theano.gpuarray
import
basic_ops
,
GpuArrayType
from
theano.gpuarray
import
basic_ops
,
GpuArrayType
from
pygpu.gpuarray
import
GpuKernel
,
GpuArray
from
string
import
Template
import
numpy
as
np
import
numpy
as
np
from
numpy.linalg.linalg
import
LinAlgError
from
numpy.linalg.linalg
import
LinAlgError
...
...
theano/gpuarray/opt.py
浏览文件 @
4c87b1b3
...
@@ -1975,7 +1975,7 @@ def local_gpu_solve(op, context_name, inputs, outputs):
...
@@ -1975,7 +1975,7 @@ def local_gpu_solve(op, context_name, inputs, outputs):
def
local_gpu_cholesky
(
op
,
context_name
,
inputs
,
outputs
):
def
local_gpu_cholesky
(
op
,
context_name
,
inputs
,
outputs
):
if
not
cusolver_available
:
if
not
cusolver_available
:
return
return
return
GpuCholesky
()
return
GpuCholesky
(
lower
=
op
.
lower
,
inplace
=
op
.
destructive
)
# Do not register in fast_run or fast_compile.
# Do not register in fast_run or fast_compile.
# It will be added to fast_run if the GPU is enabled.
# It will be added to fast_run if the GPU is enabled.
...
...
theano/gpuarray/tests/test_linalg.py
浏览文件 @
4c87b1b3
...
@@ -120,14 +120,14 @@ class TestGpuCholesky(unittest.TestCase):
...
@@ -120,14 +120,14 @@ class TestGpuCholesky(unittest.TestCase):
utt
.
seed_rng
()
utt
.
seed_rng
()
def
get_gpu_cholesky_func
(
self
,
lower
=
True
,
inplace
=
False
):
def
get_gpu_cholesky_func
(
self
,
lower
=
True
,
inplace
=
False
):
# Helper function to compile function from GPU Cholesky op.
# Helper function to compile function from GPU Cholesky op.
A
=
theano
.
tensor
.
matrix
(
"A"
,
dtype
=
"float32"
)
A
=
theano
.
tensor
.
matrix
(
"A"
,
dtype
=
"float32"
)
cholesky_op
=
GpuCholesky
(
lower
=
lower
,
inplace
=
inplace
)
cholesky_op
=
GpuCholesky
(
lower
=
lower
,
inplace
=
inplace
)
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_np
(
self
,
A_val
,
lower
=
True
,
inplace
=
False
):
def
compare_gpu_cholesky_to_np
(
self
,
A_val
,
lower
=
True
,
inplace
=
False
):
# Helper function to compare op output to np.cholesky output.
# Helper function to compare op output to np.cholesky output.
chol_A_val
=
np
.
linalg
.
cholesky
(
A_val
)
chol_A_val
=
np
.
linalg
.
cholesky
(
A_val
)
if
not
lower
:
if
not
lower
:
chol_A_val
=
chol_A_val
.
T
chol_A_val
=
chol_A_val
.
T
...
@@ -137,27 +137,27 @@ class TestGpuCholesky(unittest.TestCase):
...
@@ -137,27 +137,27 @@ class TestGpuCholesky(unittest.TestCase):
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
=
np
.
random
.
normal
(
size
=
(
3
,
2
))
.
astype
(
"float32"
)
A_val
=
np
.
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
)
def
test_invalid_input_fail_vector
(
self
):
def
test_invalid_input_fail_vector
(
self
):
# Invalid Cholesky input test with vector as input.
# Invalid Cholesky input test with vector as input.
def
invalid_input_func
():
def
invalid_input_func
():
A
=
theano
.
tensor
.
vector
(
"A"
,
dtype
=
"float32"
)
A
=
theano
.
tensor
.
vector
(
"A"
,
dtype
=
"float32"
)
GpuCholesky
(
lower
=
True
,
inplace
=
False
)(
A
)
GpuCholesky
(
lower
=
True
,
inplace
=
False
)(
A
)
self
.
assertRaises
(
AssertionError
,
invalid_input_func
)
self
.
assertRaises
(
AssertionError
,
invalid_input_func
)
def
test_invalid_input_fail_tensor3
(
self
):
def
test_invalid_input_fail_tensor3
(
self
):
# Invalid Cholesky input test with 3D tensor as input.
# Invalid Cholesky input test with 3D tensor as input.
def
invalid_input_func
():
def
invalid_input_func
():
A
=
theano
.
tensor
.
tensor3
(
"A"
,
dtype
=
"float32"
)
A
=
theano
.
tensor
.
tensor3
(
"A"
,
dtype
=
"float32"
)
GpuCholesky
(
lower
=
True
,
inplace
=
False
)(
A
)
GpuCholesky
(
lower
=
True
,
inplace
=
False
)(
A
)
self
.
assertRaises
(
AssertionError
,
invalid_input_func
)
self
.
assertRaises
(
AssertionError
,
invalid_input_func
)
def
test_diag_chol
(
self
):
def
test_diag_chol
(
self
):
# Diagonal matrix input Cholesky test.
# Diagonal matrix input Cholesky test.
for
lower
in
[
True
,
False
]:
for
lower
in
[
True
,
False
]:
for
inplace
in
[
True
,
False
]:
for
inplace
in
[
True
,
False
]:
# make sure all diagonal elements are positive so positive-definite
# make sure all diagonal elements are positive so positive-definite
...
@@ -165,7 +165,7 @@ class TestGpuCholesky(unittest.TestCase):
...
@@ -165,7 +165,7 @@ class TestGpuCholesky(unittest.TestCase):
self
.
compare_gpu_cholesky_to_np
(
A_val
,
lower
=
lower
,
inplace
=
inplace
)
self
.
compare_gpu_cholesky_to_np
(
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
=
np
.
random
.
normal
(
size
=
(
3
,
3
))
.
astype
(
"float32"
)
M_val
=
np
.
random
.
normal
(
size
=
(
3
,
3
))
.
astype
(
"float32"
)
...
@@ -185,10 +185,9 @@ class TestGpuCholesky(unittest.TestCase):
...
@@ -185,10 +185,9 @@ class TestGpuCholesky(unittest.TestCase):
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
=
np
.
random
.
normal
(
size
=
(
3
,
3
))
.
astype
(
"float32"
)
M_val
=
np
.
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
)
self
.
assertRaises
(
LinAlgError
,
fn
,
A_val
)
self
.
assertRaises
(
LinAlgError
,
fn
,
A_val
)
theano/gpuarray/tests/test_opt.py
浏览文件 @
4c87b1b3
...
@@ -573,7 +573,7 @@ def test_local_lift_solve():
...
@@ -573,7 +573,7 @@ def test_local_lift_solve():
A
=
tensor
.
fmatrix
()
A
=
tensor
.
fmatrix
()
b
=
tensor
.
fmatrix
()
b
=
tensor
.
fmatrix
()
o
=
slinalg
.
solve
(
A
,
b
)
o
=
slinalg
.
solve
(
A
,
b
)
f_cpu
=
theano
.
function
([
A
,
b
],
o
)
f_cpu
=
theano
.
function
([
A
,
b
],
o
,
mode_without_gpu
)
f_gpu
=
theano
.
function
([
A
,
b
],
o
,
mode
=
mode_with_gpu
)
f_gpu
=
theano
.
function
([
A
,
b
],
o
,
mode
=
mode_with_gpu
)
assert
not
any
(
isinstance
(
n
.
op
,
slinalg
.
Solve
)
assert
not
any
(
isinstance
(
n
.
op
,
slinalg
.
Solve
)
for
n
in
f_gpu
.
maker
.
fgraph
.
apply_nodes
)
for
n
in
f_gpu
.
maker
.
fgraph
.
apply_nodes
)
...
@@ -589,7 +589,7 @@ def test_local_lift_cholesky():
...
@@ -589,7 +589,7 @@ def test_local_lift_cholesky():
raise
SkipTest
(
'No cuSolver'
)
raise
SkipTest
(
'No cuSolver'
)
A
=
tensor
.
fmatrix
()
A
=
tensor
.
fmatrix
()
o
=
slinalg
.
cholesky
(
A
)
o
=
slinalg
.
cholesky
(
A
)
f_cpu
=
theano
.
function
([
A
],
o
)
f_cpu
=
theano
.
function
([
A
],
o
,
mode
=
mode_without_gpu
)
f_gpu
=
theano
.
function
([
A
],
o
,
mode
=
mode_with_gpu
)
f_gpu
=
theano
.
function
([
A
],
o
,
mode
=
mode_with_gpu
)
assert
not
any
(
isinstance
(
n
.
op
,
slinalg
.
Cholesky
)
assert
not
any
(
isinstance
(
n
.
op
,
slinalg
.
Cholesky
)
for
n
in
f_gpu
.
maker
.
fgraph
.
apply_nodes
)
for
n
in
f_gpu
.
maker
.
fgraph
.
apply_nodes
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论