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
import
logging
import
warnings
import
numpy
import
numpy
as
np
as
np
as
np
as
np
from
six.moves
import
xrange
import
theano
...
...
@@ -44,7 +44,7 @@ class MatrixPinv(Op):
def
perform
(
self
,
node
,
inputs
,
outputs
):
(
x
,)
=
inputs
(
z
,)
=
outputs
z
[
0
]
=
n
umpy
.
linalg
.
pinv
(
x
)
.
astype
(
x
.
dtype
)
z
[
0
]
=
n
p
.
linalg
.
pinv
(
x
)
.
astype
(
x
.
dtype
)
pinv
=
MatrixPinv
()
...
...
@@ -76,7 +76,7 @@ class MatrixInverse(Op):
def
perform
(
self
,
node
,
inputs
,
outputs
):
(
x
,)
=
inputs
(
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
):
r"""The gradient function should return
...
...
@@ -162,7 +162,7 @@ class AllocDiag(Op):
(
z
,)
=
outputs
if
x
.
ndim
!=
1
:
raise
TypeError
(
x
)
z
[
0
]
=
n
umpy
.
diag
(
x
)
z
[
0
]
=
n
p
.
diag
(
x
)
def
infer_shape
(
self
,
node
,
shapes
):
x_s
,
=
shapes
...
...
@@ -289,7 +289,7 @@ class Det(Op):
(
x
,)
=
inputs
(
z
,)
=
outputs
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
:
print
(
'Failed to compute determinant'
,
x
)
raise
...
...
@@ -313,7 +313,7 @@ class Eig(Op):
"""
_numop
=
staticmethod
(
n
umpy
.
linalg
.
eig
)
_numop
=
staticmethod
(
n
p
.
linalg
.
eig
)
__props__
=
()
def
make_node
(
self
,
x
):
...
...
@@ -341,7 +341,7 @@ class Eigh(Eig):
"""
_numop
=
staticmethod
(
n
umpy
.
linalg
.
eigh
)
_numop
=
staticmethod
(
n
p
.
linalg
.
eigh
)
__props__
=
(
'UPLO'
,)
def
__init__
(
self
,
UPLO
=
'L'
):
...
...
@@ -356,7 +356,7 @@ class Eigh(Eig):
# LAPACK. Rather than trying to reproduce the (rather
# involved) logic, we just probe linalg.eigh with a trivial
# 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
)
v
=
theano
.
tensor
.
matrix
(
dtype
=
x
.
dtype
)
return
Apply
(
self
,
[
x
],
[
w
,
v
])
...
...
@@ -419,11 +419,11 @@ class EighGrad(Op):
assert
UPLO
in
[
'L'
,
'U'
]
self
.
UPLO
=
UPLO
if
UPLO
==
'L'
:
self
.
tri0
=
n
umpy
.
tril
self
.
tri1
=
lambda
a
:
n
umpy
.
triu
(
a
,
1
)
self
.
tri0
=
n
p
.
tril
self
.
tri1
=
lambda
a
:
n
p
.
triu
(
a
,
1
)
else
:
self
.
tri0
=
n
umpy
.
triu
self
.
tri1
=
lambda
a
:
n
umpy
.
tril
(
a
,
-
1
)
self
.
tri0
=
n
p
.
triu
self
.
tri1
=
lambda
a
:
n
p
.
tril
(
a
,
-
1
)
def
make_node
(
self
,
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):
"""
x
,
w
,
v
,
W
,
V
=
inputs
N
=
x
.
shape
[
0
]
outer
=
n
umpy
.
outer
outer
=
n
p
.
outer
def
G
(
n
):
return
sum
(
v
[:,
m
]
*
V
.
T
[
n
]
.
dot
(
v
[:,
m
])
/
(
w
[
n
]
-
w
[
m
])
...
...
@@ -466,7 +466,7 @@ class EighGrad(Op):
# Make sure we return the right dtype even if NumPy performed
# 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
):
return
[
shapes
[
0
]]
...
...
@@ -486,7 +486,7 @@ class QRFull(Op):
"""
_numop
=
staticmethod
(
n
umpy
.
linalg
.
qr
)
_numop
=
staticmethod
(
n
p
.
linalg
.
qr
)
__props__
=
(
'mode'
,)
def
__init__
(
self
,
mode
):
...
...
@@ -519,7 +519,7 @@ class QRIncomplete(Op):
"""
_numop
=
staticmethod
(
n
umpy
.
linalg
.
qr
)
_numop
=
staticmethod
(
n
p
.
linalg
.
qr
)
__props__
=
(
'mode'
,)
def
__init__
(
self
,
mode
):
...
...
@@ -583,7 +583,7 @@ def qr(a, mode="reduced"):
"""
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
)
else
:
return
QRIncomplete
(
mode
)(
a
)
...
...
@@ -606,7 +606,7 @@ class SVD(Op):
"""
# 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'
)
def
__init__
(
self
,
full_matrices
=
True
,
compute_uv
=
True
):
...
...
@@ -666,10 +666,10 @@ class lstsq(Op):
theano
.
tensor
.
lscalar
(),
theano
.
tensor
.
dvector
()])
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
[
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
]
...
...
@@ -730,7 +730,7 @@ class TensorInv(Op):
Class wrapper for tensorinv() function;
Theano utilization of numpy.linalg.tensorinv;
"""
_numop
=
staticmethod
(
n
umpy
.
linalg
.
tensorinv
)
_numop
=
staticmethod
(
n
p
.
linalg
.
tensorinv
)
__props__
=
(
'ind'
,)
def
__init__
(
self
,
ind
=
2
):
...
...
@@ -790,7 +790,7 @@ class TensorSolve(Op):
Class wrapper for tensorsolve function.
"""
_numop
=
staticmethod
(
n
umpy
.
linalg
.
tensorsolve
)
_numop
=
staticmethod
(
n
p
.
linalg
.
tensorsolve
)
__props__
=
(
'axes'
,
)
def
__init__
(
self
,
axes
=
None
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论