Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6c1db380
提交
6c1db380
authored
3月 25, 2017
作者:
amrithasuresh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Updated numpy as np
上级
3fe88147
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
22 行增加
和
22 行删除
+22
-22
nlinalg.py
theano/tensor/nlinalg.py
+22
-22
没有找到文件。
theano/tensor/nlinalg.py
浏览文件 @
6c1db380
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import, print_function, division
import
logging
import
logging
import
warnings
import
warnings
import
numpy
import
numpy
as
np
as
np
as
np
as
np
from
six.moves
import
xrange
from
six.moves
import
xrange
import
theano
import
theano
...
@@ -44,7 +44,7 @@ class MatrixPinv(Op):
...
@@ -44,7 +44,7 @@ class MatrixPinv(Op):
def
perform
(
self
,
node
,
inputs
,
outputs
):
def
perform
(
self
,
node
,
inputs
,
outputs
):
(
x
,)
=
inputs
(
x
,)
=
inputs
(
z
,)
=
outputs
(
z
,)
=
outputs
z
[
0
]
=
n
umpy
.
linalg
.
pinv
(
x
)
.
astype
(
x
.
dtype
)
z
[
0
]
=
n
p
.
linalg
.
pinv
(
x
)
.
astype
(
x
.
dtype
)
pinv
=
MatrixPinv
()
pinv
=
MatrixPinv
()
...
@@ -76,7 +76,7 @@ class MatrixInverse(Op):
...
@@ -76,7 +76,7 @@ class MatrixInverse(Op):
def
perform
(
self
,
node
,
inputs
,
outputs
):
def
perform
(
self
,
node
,
inputs
,
outputs
):
(
x
,)
=
inputs
(
x
,)
=
inputs
(
z
,)
=
outputs
(
z
,)
=
outputs
z
[
0
]
=
n
umpy
.
linalg
.
inv
(
x
)
.
astype
(
x
.
dtype
)
z
[
0
]
=
n
p
.
linalg
.
inv
(
x
)
.
astype
(
x
.
dtype
)
def
grad
(
self
,
inputs
,
g_outputs
):
def
grad
(
self
,
inputs
,
g_outputs
):
r"""The gradient function should return
r"""The gradient function should return
...
@@ -162,7 +162,7 @@ class AllocDiag(Op):
...
@@ -162,7 +162,7 @@ class AllocDiag(Op):
(
z
,)
=
outputs
(
z
,)
=
outputs
if
x
.
ndim
!=
1
:
if
x
.
ndim
!=
1
:
raise
TypeError
(
x
)
raise
TypeError
(
x
)
z
[
0
]
=
n
umpy
.
diag
(
x
)
z
[
0
]
=
n
p
.
diag
(
x
)
def
infer_shape
(
self
,
node
,
shapes
):
def
infer_shape
(
self
,
node
,
shapes
):
x_s
,
=
shapes
x_s
,
=
shapes
...
@@ -289,7 +289,7 @@ class Det(Op):
...
@@ -289,7 +289,7 @@ class Det(Op):
(
x
,)
=
inputs
(
x
,)
=
inputs
(
z
,)
=
outputs
(
z
,)
=
outputs
try
:
try
:
z
[
0
]
=
n
umpy
.
asarray
(
numpy
.
linalg
.
det
(
x
),
dtype
=
x
.
dtype
)
z
[
0
]
=
n
p
.
asarray
(
np
.
linalg
.
det
(
x
),
dtype
=
x
.
dtype
)
except
Exception
:
except
Exception
:
print
(
'Failed to compute determinant'
,
x
)
print
(
'Failed to compute determinant'
,
x
)
raise
raise
...
@@ -313,7 +313,7 @@ class Eig(Op):
...
@@ -313,7 +313,7 @@ class Eig(Op):
"""
"""
_numop
=
staticmethod
(
n
umpy
.
linalg
.
eig
)
_numop
=
staticmethod
(
n
p
.
linalg
.
eig
)
__props__
=
()
__props__
=
()
def
make_node
(
self
,
x
):
def
make_node
(
self
,
x
):
...
@@ -341,7 +341,7 @@ class Eigh(Eig):
...
@@ -341,7 +341,7 @@ class Eigh(Eig):
"""
"""
_numop
=
staticmethod
(
n
umpy
.
linalg
.
eigh
)
_numop
=
staticmethod
(
n
p
.
linalg
.
eigh
)
__props__
=
(
'UPLO'
,)
__props__
=
(
'UPLO'
,)
def
__init__
(
self
,
UPLO
=
'L'
):
def
__init__
(
self
,
UPLO
=
'L'
):
...
@@ -356,7 +356,7 @@ class Eigh(Eig):
...
@@ -356,7 +356,7 @@ class Eigh(Eig):
# LAPACK. Rather than trying to reproduce the (rather
# LAPACK. Rather than trying to reproduce the (rather
# involved) logic, we just probe linalg.eigh with a trivial
# involved) logic, we just probe linalg.eigh with a trivial
# input.
# input.
w_dtype
=
self
.
_numop
([[
n
umpy
.
dtype
(
x
.
dtype
)
.
type
()]])[
0
]
.
dtype
.
name
w_dtype
=
self
.
_numop
([[
n
p
.
dtype
(
x
.
dtype
)
.
type
()]])[
0
]
.
dtype
.
name
w
=
theano
.
tensor
.
vector
(
dtype
=
w_dtype
)
w
=
theano
.
tensor
.
vector
(
dtype
=
w_dtype
)
v
=
theano
.
tensor
.
matrix
(
dtype
=
x
.
dtype
)
v
=
theano
.
tensor
.
matrix
(
dtype
=
x
.
dtype
)
return
Apply
(
self
,
[
x
],
[
w
,
v
])
return
Apply
(
self
,
[
x
],
[
w
,
v
])
...
@@ -419,11 +419,11 @@ class EighGrad(Op):
...
@@ -419,11 +419,11 @@ class EighGrad(Op):
assert
UPLO
in
[
'L'
,
'U'
]
assert
UPLO
in
[
'L'
,
'U'
]
self
.
UPLO
=
UPLO
self
.
UPLO
=
UPLO
if
UPLO
==
'L'
:
if
UPLO
==
'L'
:
self
.
tri0
=
n
umpy
.
tril
self
.
tri0
=
n
p
.
tril
self
.
tri1
=
lambda
a
:
n
umpy
.
triu
(
a
,
1
)
self
.
tri1
=
lambda
a
:
n
p
.
triu
(
a
,
1
)
else
:
else
:
self
.
tri0
=
n
umpy
.
triu
self
.
tri0
=
n
p
.
triu
self
.
tri1
=
lambda
a
:
n
umpy
.
tril
(
a
,
-
1
)
self
.
tri1
=
lambda
a
:
n
p
.
tril
(
a
,
-
1
)
def
make_node
(
self
,
x
,
w
,
v
,
gw
,
gv
):
def
make_node
(
self
,
x
,
w
,
v
,
gw
,
gv
):
x
,
w
,
v
,
gw
,
gv
=
map
(
as_tensor_variable
,
(
x
,
w
,
v
,
gw
,
gv
))
x
,
w
,
v
,
gw
,
gv
=
map
(
as_tensor_variable
,
(
x
,
w
,
v
,
gw
,
gv
))
...
@@ -445,7 +445,7 @@ class EighGrad(Op):
...
@@ -445,7 +445,7 @@ class EighGrad(Op):
"""
"""
x
,
w
,
v
,
W
,
V
=
inputs
x
,
w
,
v
,
W
,
V
=
inputs
N
=
x
.
shape
[
0
]
N
=
x
.
shape
[
0
]
outer
=
n
umpy
.
outer
outer
=
n
p
.
outer
def
G
(
n
):
def
G
(
n
):
return
sum
(
v
[:,
m
]
*
V
.
T
[
n
]
.
dot
(
v
[:,
m
])
/
(
w
[
n
]
-
w
[
m
])
return
sum
(
v
[:,
m
]
*
V
.
T
[
n
]
.
dot
(
v
[:,
m
])
/
(
w
[
n
]
-
w
[
m
])
...
@@ -466,7 +466,7 @@ class EighGrad(Op):
...
@@ -466,7 +466,7 @@ class EighGrad(Op):
# Make sure we return the right dtype even if NumPy performed
# Make sure we return the right dtype even if NumPy performed
# upcasting in self.tri0.
# upcasting in self.tri0.
outputs
[
0
][
0
]
=
n
umpy
.
asarray
(
out
,
dtype
=
node
.
outputs
[
0
]
.
dtype
)
outputs
[
0
][
0
]
=
n
p
.
asarray
(
out
,
dtype
=
node
.
outputs
[
0
]
.
dtype
)
def
infer_shape
(
self
,
node
,
shapes
):
def
infer_shape
(
self
,
node
,
shapes
):
return
[
shapes
[
0
]]
return
[
shapes
[
0
]]
...
@@ -486,7 +486,7 @@ class QRFull(Op):
...
@@ -486,7 +486,7 @@ class QRFull(Op):
"""
"""
_numop
=
staticmethod
(
n
umpy
.
linalg
.
qr
)
_numop
=
staticmethod
(
n
p
.
linalg
.
qr
)
__props__
=
(
'mode'
,)
__props__
=
(
'mode'
,)
def
__init__
(
self
,
mode
):
def
__init__
(
self
,
mode
):
...
@@ -519,7 +519,7 @@ class QRIncomplete(Op):
...
@@ -519,7 +519,7 @@ class QRIncomplete(Op):
"""
"""
_numop
=
staticmethod
(
n
umpy
.
linalg
.
qr
)
_numop
=
staticmethod
(
n
p
.
linalg
.
qr
)
__props__
=
(
'mode'
,)
__props__
=
(
'mode'
,)
def
__init__
(
self
,
mode
):
def
__init__
(
self
,
mode
):
...
@@ -583,7 +583,7 @@ def qr(a, mode="reduced"):
...
@@ -583,7 +583,7 @@ def qr(a, mode="reduced"):
"""
"""
x
=
[[
2
,
1
],
[
3
,
4
]]
x
=
[[
2
,
1
],
[
3
,
4
]]
if
isinstance
(
n
umpy
.
linalg
.
qr
(
x
,
mode
),
tuple
):
if
isinstance
(
n
p
.
linalg
.
qr
(
x
,
mode
),
tuple
):
return
QRFull
(
mode
)(
a
)
return
QRFull
(
mode
)(
a
)
else
:
else
:
return
QRIncomplete
(
mode
)(
a
)
return
QRIncomplete
(
mode
)(
a
)
...
@@ -606,7 +606,7 @@ class SVD(Op):
...
@@ -606,7 +606,7 @@ class SVD(Op):
"""
"""
# See doc in the docstring of the function just after this class.
# See doc in the docstring of the function just after this class.
_numop
=
staticmethod
(
n
umpy
.
linalg
.
svd
)
_numop
=
staticmethod
(
n
p
.
linalg
.
svd
)
__props__
=
(
'full_matrices'
,
'compute_uv'
)
__props__
=
(
'full_matrices'
,
'compute_uv'
)
def
__init__
(
self
,
full_matrices
=
True
,
compute_uv
=
True
):
def
__init__
(
self
,
full_matrices
=
True
,
compute_uv
=
True
):
...
@@ -666,10 +666,10 @@ class lstsq(Op):
...
@@ -666,10 +666,10 @@ class lstsq(Op):
theano
.
tensor
.
lscalar
(),
theano
.
tensor
.
dvector
()])
theano
.
tensor
.
lscalar
(),
theano
.
tensor
.
dvector
()])
def
perform
(
self
,
node
,
inputs
,
outputs
):
def
perform
(
self
,
node
,
inputs
,
outputs
):
zz
=
n
umpy
.
linalg
.
lstsq
(
inputs
[
0
],
inputs
[
1
],
inputs
[
2
])
zz
=
n
p
.
linalg
.
lstsq
(
inputs
[
0
],
inputs
[
1
],
inputs
[
2
])
outputs
[
0
][
0
]
=
zz
[
0
]
outputs
[
0
][
0
]
=
zz
[
0
]
outputs
[
1
][
0
]
=
zz
[
1
]
outputs
[
1
][
0
]
=
zz
[
1
]
outputs
[
2
][
0
]
=
n
umpy
.
array
(
zz
[
2
])
outputs
[
2
][
0
]
=
n
p
.
array
(
zz
[
2
])
outputs
[
3
][
0
]
=
zz
[
3
]
outputs
[
3
][
0
]
=
zz
[
3
]
...
@@ -730,7 +730,7 @@ class TensorInv(Op):
...
@@ -730,7 +730,7 @@ class TensorInv(Op):
Class wrapper for tensorinv() function;
Class wrapper for tensorinv() function;
Theano utilization of numpy.linalg.tensorinv;
Theano utilization of numpy.linalg.tensorinv;
"""
"""
_numop
=
staticmethod
(
n
umpy
.
linalg
.
tensorinv
)
_numop
=
staticmethod
(
n
p
.
linalg
.
tensorinv
)
__props__
=
(
'ind'
,)
__props__
=
(
'ind'
,)
def
__init__
(
self
,
ind
=
2
):
def
__init__
(
self
,
ind
=
2
):
...
@@ -790,7 +790,7 @@ class TensorSolve(Op):
...
@@ -790,7 +790,7 @@ class TensorSolve(Op):
Class wrapper for tensorsolve function.
Class wrapper for tensorsolve function.
"""
"""
_numop
=
staticmethod
(
n
umpy
.
linalg
.
tensorsolve
)
_numop
=
staticmethod
(
n
p
.
linalg
.
tensorsolve
)
__props__
=
(
'axes'
,
)
__props__
=
(
'axes'
,
)
def
__init__
(
self
,
axes
=
None
):
def
__init__
(
self
,
axes
=
None
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论