Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4fef5a6e
提交
4fef5a6e
authored
11月 29, 2011
作者:
Guillaume Desjardins
提交者:
Frederic
11月 30, 2011
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reformatted docstrings and spaces between funcs.
上级
d50c1eba
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
9 行增加
和
6 行删除
+9
-6
ops.py
theano/sandbox/linalg/ops.py
+9
-6
没有找到文件。
theano/sandbox/linalg/ops.py
浏览文件 @
4fef5a6e
...
@@ -561,7 +561,7 @@ solve = Solve() # general solve
...
@@ -561,7 +561,7 @@ solve = Solve() # general solve
#TODO: Optimizations to replace multiplication by matrix inverse with solve() Op (still unwritten)
#TODO: Optimizations to replace multiplication by matrix inverse with solve() Op (still unwritten)
class
ExtractDiag
(
Op
):
class
ExtractDiag
(
Op
):
""" Return the diagonal of a matrix """
""" Return the diagonal of a matrix
.
"""
def
__init__
(
self
,
view
=
False
):
def
__init__
(
self
,
view
=
False
):
self
.
view
=
view
self
.
view
=
view
if
self
.
view
:
if
self
.
view
:
...
@@ -580,13 +580,13 @@ class ExtractDiag(Op):
...
@@ -580,13 +580,13 @@ class ExtractDiag(Op):
return
Apply
(
self
,
[
x
],
[
tensor
.
vector
(
dtype
=
x
.
type
.
dtype
)])
return
Apply
(
self
,
[
x
],
[
tensor
.
vector
(
dtype
=
x
.
type
.
dtype
)])
def
perform
(
self
,
node
,
ins
,
outs
):
def
perform
(
self
,
node
,
ins
,
outs
):
""" For some reason numpy.diag(x) is really slow, so we implemented our own """
""" For some reason numpy.diag(x) is really slow, so we implemented our own
.
"""
x
,
=
ins
x
,
=
ins
z
,
=
outs
z
,
=
outs
# zero-dimensional matrices ...
# zero-dimensional matrices ...
if
x
.
shape
[
0
]
==
0
or
x
.
shape
[
1
]
==
0
:
if
x
.
shape
[
0
]
==
0
or
x
.
shape
[
1
]
==
0
:
z
[
0
]
=
x
z
[
0
]
=
numpy
.
zeros
(
0
)
return
return
if
x
.
shape
[
0
]
<
x
.
shape
[
1
]:
if
x
.
shape
[
0
]
<
x
.
shape
[
1
]:
...
@@ -606,7 +606,7 @@ class ExtractDiag(Op):
...
@@ -606,7 +606,7 @@ class ExtractDiag(Op):
def
grad
(
self
,
inputs
,
g_outputs
):
def
grad
(
self
,
inputs
,
g_outputs
):
x
=
tensor
.
zeros_like
(
inputs
[
0
])
x
=
tensor
.
zeros_like
(
inputs
[
0
])
xdiag
=
alloc_diag
(
g_outputs
[
0
])
xdiag
=
alloc_diag
(
g_outputs
[
0
])
return
[
tensor
.
set_subtensor
(
x
[:
xdiag
.
shape
[
0
],
:
xdiag
.
shape
[
1
]],
xdiag
,
inplace
=
True
)]
return
[
tensor
.
set_subtensor
(
x
[:
xdiag
.
shape
[
0
],
:
xdiag
.
shape
[
1
]],
xdiag
)]
def
infer_shape
(
self
,
node
,
shapes
):
def
infer_shape
(
self
,
node
,
shapes
):
x_s
,
=
shapes
x_s
,
=
shapes
...
@@ -616,6 +616,7 @@ class ExtractDiag(Op):
...
@@ -616,6 +616,7 @@ class ExtractDiag(Op):
extract_diag
=
ExtractDiag
()
extract_diag
=
ExtractDiag
()
#TODO: optimization to insert ExtractDiag with view=True
#TODO: optimization to insert ExtractDiag with view=True
class
AllocDiag
(
Op
):
class
AllocDiag
(
Op
):
"""
"""
Allocates a square matrix with the given vector as its diagonal.
Allocates a square matrix with the given vector as its diagonal.
...
@@ -646,9 +647,10 @@ class AllocDiag(Op):
...
@@ -646,9 +647,10 @@ class AllocDiag(Op):
alloc_diag
=
AllocDiag
()
alloc_diag
=
AllocDiag
()
def
diag
(
x
):
"""Numpy-compatibility method
def
diag
(
x
):
"""
Numpy-compatibility method
If `x` is a matrix, return its diagonal.
If `x` is a matrix, return its diagonal.
If `x` is a vector return a matrix with it as its diagonal.
If `x` is a vector return a matrix with it as its diagonal.
...
@@ -662,6 +664,7 @@ def diag(x):
...
@@ -662,6 +664,7 @@ def diag(x):
else
:
else
:
raise
TypeError
(
'diag requires vector or matrix argument'
,
x
)
raise
TypeError
(
'diag requires vector or matrix argument'
,
x
)
class
Det
(
Op
):
class
Det
(
Op
):
"""Matrix determinant
"""Matrix determinant
Input should be a square matrix
Input should be a square matrix
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论